Merge of default to reflection branch - need to work on improving annotations with arrays reflection
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 03 Feb 2013 07:48:42 +0100
branchreflection
changeset 64877735e75d6dc
parent 266 2e2e6f946208
parent 636 8d0be6a9a809
child 649 4b16b7e23cab
Merge of default to reflection branch - need to work on improving annotations with arrays
emul/src/main/java/java/io/ByteArrayInputStream.java
emul/src/main/java/java/io/Closeable.java
emul/src/main/java/java/io/DataInput.java
emul/src/main/java/java/io/DataInputStream.java
emul/src/main/java/java/io/EOFException.java
emul/src/main/java/java/io/FilterInputStream.java
emul/src/main/java/java/io/IOException.java
emul/src/main/java/java/io/InputStream.java
emul/src/main/java/java/io/PushbackInputStream.java
emul/src/main/java/java/io/Serializable.java
emul/src/main/java/java/io/UTFDataFormatException.java
emul/src/main/java/java/io/UnsupportedEncodingException.java
emul/src/main/java/java/lang/AbstractStringBuilder.java
emul/src/main/java/java/lang/Appendable.java
emul/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java
emul/src/main/java/java/lang/AssertionError.java
emul/src/main/java/java/lang/AutoCloseable.java
emul/src/main/java/java/lang/Boolean.java
emul/src/main/java/java/lang/Byte.java
emul/src/main/java/java/lang/CharSequence.java
emul/src/main/java/java/lang/Character.java
emul/src/main/java/java/lang/Class.java
emul/src/main/java/java/lang/ClassCastException.java
emul/src/main/java/java/lang/ClassFormatError.java
emul/src/main/java/java/lang/ClassLoader.java
emul/src/main/java/java/lang/ClassNotFoundException.java
emul/src/main/java/java/lang/CloneNotSupportedException.java
emul/src/main/java/java/lang/Comparable.java
emul/src/main/java/java/lang/Deprecated.java
emul/src/main/java/java/lang/Double.java
emul/src/main/java/java/lang/Enum.java
emul/src/main/java/java/lang/Error.java
emul/src/main/java/java/lang/Exception.java
emul/src/main/java/java/lang/Float.java
emul/src/main/java/java/lang/IllegalAccessException.java
emul/src/main/java/java/lang/IllegalArgumentException.java
emul/src/main/java/java/lang/IllegalStateException.java
emul/src/main/java/java/lang/IndexOutOfBoundsException.java
emul/src/main/java/java/lang/InstantiationException.java
emul/src/main/java/java/lang/Integer.java
emul/src/main/java/java/lang/InterruptedException.java
emul/src/main/java/java/lang/LinkageError.java
emul/src/main/java/java/lang/Long.java
emul/src/main/java/java/lang/Math.java
emul/src/main/java/java/lang/NullPointerException.java
emul/src/main/java/java/lang/Number.java
emul/src/main/java/java/lang/NumberFormatException.java
emul/src/main/java/java/lang/Object.java
emul/src/main/java/java/lang/OutOfMemoryError.java
emul/src/main/java/java/lang/ReflectiveOperationException.java
emul/src/main/java/java/lang/RuntimeException.java
emul/src/main/java/java/lang/SecurityException.java
emul/src/main/java/java/lang/Short.java
emul/src/main/java/java/lang/StackTraceElement.java
emul/src/main/java/java/lang/String.java
emul/src/main/java/java/lang/StringBuffer.java
emul/src/main/java/java/lang/StringBuilder.java
emul/src/main/java/java/lang/StringIndexOutOfBoundsException.java
emul/src/main/java/java/lang/Throwable.java
emul/src/main/java/java/lang/VirtualMachineError.java
emul/src/main/java/java/lang/annotation/Annotation.java
emul/src/main/java/java/lang/annotation/Documented.java
emul/src/main/java/java/lang/annotation/ElementType.java
emul/src/main/java/java/lang/annotation/Retention.java
emul/src/main/java/java/lang/annotation/RetentionPolicy.java
emul/src/main/java/java/lang/annotation/Target.java
emul/src/main/java/java/lang/annotation/UnsupportedOperationException.java
emul/src/main/java/java/lang/reflect/AccessibleObject.java
emul/src/main/java/java/lang/reflect/AnnotatedElement.java
emul/src/main/java/java/lang/reflect/Field.java
emul/src/main/java/java/lang/reflect/GenericDeclaration.java
emul/src/main/java/java/lang/reflect/InvocationTargetException.java
emul/src/main/java/java/lang/reflect/Member.java
emul/src/main/java/java/lang/reflect/Method.java
emul/src/main/java/java/lang/reflect/Modifier.java
emul/src/main/java/java/lang/reflect/Type.java
emul/src/main/java/java/lang/reflect/TypeVariable.java
emul/src/main/java/java/lang/reflect/package-info.java
emul/src/main/java/java/net/MalformedURLException.java
emul/src/main/java/java/net/URL.java
emul/src/main/java/java/util/Comparator.java
emul/src/main/java/java/util/Enumeration.java
emul/src/main/java/java/util/NoSuchElementException.java
emul/src/main/java/org/apidesign/bck2brwsr/emul/AnnotationImpl.java
emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/OnClick.java
javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java
javaquery/demo-calculator/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml
vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java
vm/src/test/java/org/apidesign/vm4brwsr/VMLazy.java
     1.1 --- a/.hgtags	Wed Dec 05 10:03:58 2012 +0100
     1.2 +++ b/.hgtags	Sun Feb 03 07:48:42 2013 +0100
     1.3 @@ -1,9 +1,1 @@
     1.4  0a115f1c6f3c70458fc479ae82b4d7fcdeb7e95a jdk7-b147_base
     1.5 -5ab1f0890a42d7b5d73adde545d5cadd9b99e2d1 reflectionOnClasses
     1.6 -5ab1f0890a42d7b5d73adde545d5cadd9b99e2d1 reflectionOnClasses
     1.7 -d0013f44e9b11093be3337ae11692f25c1e52de6 reflectionOnClasses
     1.8 -d0013f44e9b11093be3337ae11692f25c1e52de6 d0013f44e9b1
     1.9 -d0013f44e9b11093be3337ae11692f25c1e52de6 d0013f44e9b1
    1.10 -0000000000000000000000000000000000000000 d0013f44e9b1
    1.11 -d0013f44e9b11093be3337ae11692f25c1e52de6 reflectionOnClasses
    1.12 -d0013f44e9b11093be3337ae11692f25c1e52de6 reflectionOnClasses
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/benchmarks/matrix-multiplication/pom.xml	Sun Feb 03 07:48:42 2013 +0100
     2.3 @@ -0,0 +1,56 @@
     2.4 +<?xml version="1.0"?>
     2.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     2.6 +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     2.7 +  <modelVersion>4.0.0</modelVersion>
     2.8 +
     2.9 +  <groupId>org.apidesign.bck2brwsr</groupId>
    2.10 +  <artifactId>matrix.multiplication</artifactId>
    2.11 +  <version>0.3-SNAPSHOT</version>
    2.12 +  <packaging>jar</packaging>
    2.13 +
    2.14 +  <name>Matrix multiplication</name>
    2.15 +
    2.16 +  <properties>
    2.17 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    2.18 +  </properties>
    2.19 +
    2.20 +  <build>
    2.21 +      <plugins>
    2.22 +          <plugin>
    2.23 +            <groupId>org.apache.maven.plugins</groupId>
    2.24 +            <artifactId>maven-compiler-plugin</artifactId>
    2.25 +            <version>2.3.2</version>
    2.26 +            <configuration>
    2.27 +               <source>1.7</source>
    2.28 +               <target>1.7</target>
    2.29 +            </configuration>
    2.30 +          </plugin>
    2.31 +      </plugins>
    2.32 +  </build>
    2.33 +  
    2.34 +  <dependencies>
    2.35 +    <dependency>
    2.36 +      <groupId>org.apidesign.bck2brwsr</groupId>
    2.37 +      <artifactId>emul.mini</artifactId>
    2.38 +      <version>0.3-SNAPSHOT</version>
    2.39 +    </dependency>
    2.40 +    <dependency>
    2.41 +      <groupId>org.testng</groupId>
    2.42 +      <artifactId>testng</artifactId>
    2.43 +      <version>6.5.2</version>
    2.44 +      <scope>test</scope>
    2.45 +      <exclusions>
    2.46 +        <exclusion>
    2.47 +          <artifactId>junit</artifactId>
    2.48 +          <groupId>junit</groupId>
    2.49 +        </exclusion>
    2.50 +      </exclusions>
    2.51 +    </dependency>
    2.52 +    <dependency>
    2.53 +      <groupId>org.apidesign.bck2brwsr</groupId>
    2.54 +      <artifactId>vmtest</artifactId>
    2.55 +      <version>0.3-SNAPSHOT</version>
    2.56 +      <scope>test</scope>
    2.57 +    </dependency>
    2.58 +  </dependencies>
    2.59 +</project>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/benchmarks/matrix-multiplication/src/main/java/org/apidesign/benchmark/matrixmul/Matrix.java	Sun Feb 03 07:48:42 2013 +0100
     3.3 @@ -0,0 +1,108 @@
     3.4 +/**
     3.5 + * Back 2 Browser Bytecode Translator
     3.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     3.7 + *
     3.8 + * This program is free software: you can redistribute it and/or modify
     3.9 + * it under the terms of the GNU General Public License as published by
    3.10 + * the Free Software Foundation, version 2 of the License.
    3.11 + *
    3.12 + * This program is distributed in the hope that it will be useful,
    3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.15 + * GNU General Public License for more details.
    3.16 + *
    3.17 + * You should have received a copy of the GNU General Public License
    3.18 + * along with this program. Look for COPYING file in the top folder.
    3.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    3.20 + */
    3.21 +package org.apidesign.benchmark.matrixmul;
    3.22 +
    3.23 +import java.io.IOException;
    3.24 +import java.util.Arrays;
    3.25 +
    3.26 +public class Matrix {
    3.27 +    private final int rank;
    3.28 +    private final float data[][];
    3.29 +    
    3.30 +    public Matrix(int r) {
    3.31 +        this(r, new float[r][r]);
    3.32 +    }
    3.33 +    
    3.34 +    private Matrix(int r, float[][] data) {
    3.35 +        this.rank = r;
    3.36 +        this.data = data;
    3.37 +    }
    3.38 +    
    3.39 +    public void setElement(int i, int j, float value) {
    3.40 +        data[i][j] = value;
    3.41 +    }
    3.42 +    public float getElement(int i, int j) {
    3.43 +        return data[i][j];
    3.44 +    }
    3.45 +    
    3.46 +    public void generateData() {
    3.47 +        //final Random rand = new Random();
    3.48 +        //final int x = 10;
    3.49 +        for (int i = 0; i < rank; i++) {
    3.50 +            for (int j = 0; j < rank; j++) {
    3.51 +                data[i][j] = 1 / (1 + i + j);
    3.52 +            }
    3.53 +        }
    3.54 +    }
    3.55 +
    3.56 +    public Matrix multiply(Matrix m) {
    3.57 +        if (rank != m.rank) {
    3.58 +            throw new IllegalArgumentException("Rank doesn't match");
    3.59 +        }
    3.60 +        
    3.61 +        final float res[][] = new float[rank][rank];
    3.62 +        for (int i = 0; i < rank; i++) {
    3.63 +            for (int j = 0; j < rank; j++) {
    3.64 +                float ij = 0;
    3.65 +                for (int q = 0; q < rank; q++) {
    3.66 +                    ij += data[i][q] * m.data[q][j];
    3.67 +                }
    3.68 +                res[i][j] = ij;
    3.69 +            }
    3.70 +        }
    3.71 +        return new Matrix(rank, res);
    3.72 +    }
    3.73 +    
    3.74 +    public void printOn(Appendable s) throws IOException {
    3.75 +        for (int i = 0; i < rank; i++) {
    3.76 +            String sep = "";
    3.77 +            for (int j = 0; j < rank; j++) {
    3.78 +                s.append(sep + data[i][j]);
    3.79 +                sep = " ";
    3.80 +            }
    3.81 +            s.append("\n");
    3.82 +        }
    3.83 +    }
    3.84 +
    3.85 +    @Override
    3.86 +    public boolean equals(Object obj) {
    3.87 +        if (obj instanceof Matrix) {
    3.88 +            Matrix snd = (Matrix)obj;
    3.89 +            if (snd.rank != rank) {
    3.90 +                return false;
    3.91 +            }
    3.92 +            for (int i = 0; i < rank; i++) {
    3.93 +                for (int j = 0; j < rank; j++) {
    3.94 +                    if (data[i][j] != snd.data[i][j]) {
    3.95 +                        return false;
    3.96 +                    }
    3.97 +                }
    3.98 +            }
    3.99 +            return true;
   3.100 +        }
   3.101 +        return false;
   3.102 +    }
   3.103 +
   3.104 +    @Override
   3.105 +    public int hashCode() {
   3.106 +        int hash = 3;
   3.107 +        hash = 97 * hash + this.rank;
   3.108 +        hash = 97 * hash + Arrays.deepHashCode(this.data);
   3.109 +        return hash;
   3.110 +    }
   3.111 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/benchmarks/matrix-multiplication/src/test/java/org/apidesign/benchmark/matrixmul/MatrixTest.java	Sun Feb 03 07:48:42 2013 +0100
     4.3 @@ -0,0 +1,57 @@
     4.4 +/**
     4.5 + * Back 2 Browser Bytecode Translator
     4.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4.7 + *
     4.8 + * This program is free software: you can redistribute it and/or modify
     4.9 + * it under the terms of the GNU General Public License as published by
    4.10 + * the Free Software Foundation, version 2 of the License.
    4.11 + *
    4.12 + * This program is distributed in the hope that it will be useful,
    4.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.15 + * GNU General Public License for more details.
    4.16 + *
    4.17 + * You should have received a copy of the GNU General Public License
    4.18 + * along with this program. Look for COPYING file in the top folder.
    4.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    4.20 + */
    4.21 +package org.apidesign.benchmark.matrixmul;
    4.22 +
    4.23 +import java.io.IOException;
    4.24 +import org.apidesign.bck2brwsr.vmtest.Compare;
    4.25 +import org.apidesign.bck2brwsr.vmtest.VMTest;
    4.26 +import org.testng.annotations.Factory;
    4.27 +
    4.28 +/**
    4.29 + *
    4.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    4.31 + */
    4.32 +public class MatrixTest {
    4.33 +    public MatrixTest() {
    4.34 +    }
    4.35 +
    4.36 +    @Compare(scripting = false) 
    4.37 +    public String tenThousandIterations() throws IOException {
    4.38 +    
    4.39 +        Matrix m1 = new Matrix(5);
    4.40 +        Matrix m2 = new Matrix(5);
    4.41 +        
    4.42 +        m1.generateData();
    4.43 +        m2.generateData();
    4.44 +        
    4.45 +        Matrix res = null;
    4.46 +        for (int i = 0; i < 10000; i++) {
    4.47 +            res = m1.multiply(m2);
    4.48 +            m1 = res;
    4.49 +        }
    4.50 +        
    4.51 +        StringBuilder sb = new StringBuilder();
    4.52 +        res.printOn(sb);
    4.53 +        return sb.toString();
    4.54 +    }
    4.55 +    
    4.56 +    @Factory
    4.57 +    public static Object[] create() {
    4.58 +        return VMTest.create(MatrixTest.class);
    4.59 +    }
    4.60 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/benchmarks/pom.xml	Sun Feb 03 07:48:42 2013 +0100
     5.3 @@ -0,0 +1,17 @@
     5.4 +<?xml version="1.0" encoding="UTF-8"?>
     5.5 +<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">
     5.6 +  <modelVersion>4.0.0</modelVersion>
     5.7 +  <parent>
     5.8 +    <artifactId>bck2brwsr</artifactId>
     5.9 +    <groupId>org.apidesign</groupId>
    5.10 +    <version>0.3-SNAPSHOT</version>
    5.11 +  </parent>
    5.12 +  <groupId>org.apidesign.bck2brwsr</groupId>
    5.13 +  <artifactId>benchmarks</artifactId>
    5.14 +  <version>0.3-SNAPSHOT</version>
    5.15 +  <packaging>pom</packaging>
    5.16 +  <name>Performance benchmarks</name>
    5.17 +  <modules>
    5.18 +    <module>matrix-multiplication</module>
    5.19 +  </modules>
    5.20 +</project>
     6.1 --- a/core/pom.xml	Wed Dec 05 10:03:58 2012 +0100
     6.2 +++ b/core/pom.xml	Sun Feb 03 07:48:42 2013 +0100
     6.3 @@ -19,8 +19,8 @@
     6.4                  <artifactId>maven-compiler-plugin</artifactId>
     6.5                  <version>2.3.2</version>
     6.6                  <configuration>
     6.7 -                    <source>1.6</source>
     6.8 -                    <target>1.6</target>
     6.9 +                    <source>1.7</source>
    6.10 +                    <target>1.7</target>
    6.11                  </configuration>
    6.12              </plugin>
    6.13          </plugins>
    6.14 @@ -35,6 +35,10 @@
    6.15        <version>3.8.1</version>
    6.16        <scope>test</scope>
    6.17      </dependency>
    6.18 +    <dependency>
    6.19 +      <groupId>org.netbeans.api</groupId>
    6.20 +      <artifactId>org-openide-util-lookup</artifactId>
    6.21 +    </dependency>
    6.22    </dependencies>
    6.23      <description>Contains esential annotations for associating JavaScript code with
    6.24  methods and classes.</description>
     7.1 --- a/core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptPrototype.java	Wed Dec 05 10:03:58 2012 +0100
     7.2 +++ b/core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptPrototype.java	Sun Feb 03 07:48:42 2013 +0100
     7.3 @@ -29,10 +29,13 @@
     7.4  @Target({ ElementType.TYPE })
     7.5  public @interface JavaScriptPrototype {
     7.6      /** Expression that identifies the function where all methods
     7.7 -     * should be added into.
     7.8 +     * should be added into. If this attribute is unspecified
     7.9 +     * all methods are added to the same object specified by
    7.10 +     * {@link #prototype()}.
    7.11 +     * 
    7.12       * @return name of function to contain methods found in given class
    7.13       */
    7.14 -    String container();
    7.15 +    String container() default "";
    7.16      /** Expression that defines the way to construct prototype for this
    7.17       * class.
    7.18       * @return expression to construct prototype
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/core/src/main/java/org/apidesign/bck2brwsr/core/impl/JavaScriptProcesor.java	Sun Feb 03 07:48:42 2013 +0100
     8.3 @@ -0,0 +1,94 @@
     8.4 +/**
     8.5 + * Back 2 Browser Bytecode Translator
     8.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     8.7 + *
     8.8 + * This program is free software: you can redistribute it and/or modify
     8.9 + * it under the terms of the GNU General Public License as published by
    8.10 + * the Free Software Foundation, version 2 of the License.
    8.11 + *
    8.12 + * This program is distributed in the hope that it will be useful,
    8.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.15 + * GNU General Public License for more details.
    8.16 + *
    8.17 + * You should have received a copy of the GNU General Public License
    8.18 + * along with this program. Look for COPYING file in the top folder.
    8.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    8.20 + */
    8.21 +package org.apidesign.bck2brwsr.core.impl;
    8.22 +
    8.23 +import java.util.Collections;
    8.24 +import java.util.HashSet;
    8.25 +import java.util.List;
    8.26 +import java.util.Set;
    8.27 +import javax.annotation.processing.AbstractProcessor;
    8.28 +import javax.annotation.processing.Completion;
    8.29 +import javax.annotation.processing.Completions;
    8.30 +import javax.annotation.processing.Processor;
    8.31 +import javax.annotation.processing.RoundEnvironment;
    8.32 +import javax.lang.model.element.AnnotationMirror;
    8.33 +import javax.lang.model.element.Element;
    8.34 +import javax.lang.model.element.ElementKind;
    8.35 +import javax.lang.model.element.ExecutableElement;
    8.36 +import javax.lang.model.element.TypeElement;
    8.37 +import javax.lang.model.element.VariableElement;
    8.38 +import javax.tools.Diagnostic;
    8.39 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
    8.40 +import org.openide.util.lookup.ServiceProvider;
    8.41 +
    8.42 +/**
    8.43 + *
    8.44 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    8.45 + */
    8.46 +@ServiceProvider(service = Processor.class)
    8.47 +public final class JavaScriptProcesor extends AbstractProcessor {
    8.48 +    @Override
    8.49 +    public Set<String> getSupportedAnnotationTypes() {
    8.50 +        Set<String> set = new HashSet<>();
    8.51 +        set.add(JavaScriptBody.class.getName());
    8.52 +        return set;
    8.53 +    }
    8.54 +    
    8.55 +    @Override
    8.56 +    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    8.57 +        for (Element e : roundEnv.getElementsAnnotatedWith(JavaScriptBody.class)) {
    8.58 +            if (e.getKind() != ElementKind.METHOD && e.getKind() != ElementKind.CONSTRUCTOR) {
    8.59 +                continue;
    8.60 +            }
    8.61 +            ExecutableElement ee = (ExecutableElement)e;
    8.62 +            List<? extends VariableElement> params = ee.getParameters();
    8.63 +            
    8.64 +            JavaScriptBody jsb = e.getAnnotation(JavaScriptBody.class);
    8.65 +            if (jsb == null) {
    8.66 +                continue;
    8.67 +            }
    8.68 +            String[] arr = jsb.args();
    8.69 +            if (params.size() != arr.length) {
    8.70 +                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Number of args arguments does not match real arguments!", e);
    8.71 +            }
    8.72 +        }
    8.73 +        return true;
    8.74 +    }
    8.75 +
    8.76 +    @Override
    8.77 +    public Iterable<? extends Completion> getCompletions(Element e, 
    8.78 +        AnnotationMirror annotation, ExecutableElement member, String userText
    8.79 +    ) {
    8.80 +        StringBuilder sb = new StringBuilder();
    8.81 +        if (e.getKind() == ElementKind.METHOD && member.getSimpleName().contentEquals("args")) {
    8.82 +            ExecutableElement ee = (ExecutableElement) e;
    8.83 +            String sep = "";
    8.84 +            sb.append("{ ");
    8.85 +            for (VariableElement ve : ee.getParameters()) {
    8.86 +                sb.append(sep).append('"').append(ve.getSimpleName())
    8.87 +                    .append('"');
    8.88 +                sep = ", ";
    8.89 +            }
    8.90 +            sb.append(" }");
    8.91 +            return Collections.nCopies(1, Completions.of(sb.toString()));
    8.92 +        }
    8.93 +        return null;
    8.94 +    }
    8.95 +
    8.96 +    
    8.97 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/dew/nbactions.xml	Sun Feb 03 07:48:42 2013 +0100
     9.3 @@ -0,0 +1,52 @@
     9.4 +<?xml version="1.0" encoding="UTF-8"?>
     9.5 +<!--
     9.6 +
     9.7 +    Back 2 Browser Bytecode Translator
     9.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     9.9 +
    9.10 +    This program is free software: you can redistribute it and/or modify
    9.11 +    it under the terms of the GNU General Public License as published by
    9.12 +    the Free Software Foundation, version 2 of the License.
    9.13 +
    9.14 +    This program is distributed in the hope that it will be useful,
    9.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.17 +    GNU General Public License for more details.
    9.18 +
    9.19 +    You should have received a copy of the GNU General Public License
    9.20 +    along with this program. Look for COPYING file in the top folder.
    9.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
    9.22 +
    9.23 +-->
    9.24 +<actions>
    9.25 +        <action>
    9.26 +            <actionName>run</actionName>
    9.27 +            <goals>
    9.28 +                <goal>process-classes</goal>
    9.29 +                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
    9.30 +            </goals>
    9.31 +        </action>
    9.32 +        <action>
    9.33 +            <actionName>debug</actionName>
    9.34 +            <goals>
    9.35 +                <goal>process-classes</goal>
    9.36 +                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
    9.37 +            </goals>
    9.38 +            <properties>
    9.39 +                <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath org.apidesign.bck2brwsr.dew.Dew</exec.args>
    9.40 +                <exec.executable>java</exec.executable>
    9.41 +                <jpda.listen>true</jpda.listen>
    9.42 +            </properties>
    9.43 +        </action>
    9.44 +        <action>
    9.45 +            <actionName>profile</actionName>
    9.46 +            <goals>
    9.47 +                <goal>process-classes</goal>
    9.48 +                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
    9.49 +            </goals>
    9.50 +            <properties>
    9.51 +                <exec.args>${profiler.args} -classpath %classpath org.apidesign.bck2brwsr.dew.Dew</exec.args>
    9.52 +                <exec.executable>${profiler.java}</exec.executable>
    9.53 +            </properties>
    9.54 +        </action>
    9.55 +    </actions>
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/dew/pom.xml	Sun Feb 03 07:48:42 2013 +0100
    10.3 @@ -0,0 +1,84 @@
    10.4 +<?xml version="1.0"?>
    10.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"
    10.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    10.7 +  <modelVersion>4.0.0</modelVersion>
    10.8 +  <parent>
    10.9 +    <groupId>org.apidesign</groupId>
   10.10 +    <artifactId>bck2brwsr</artifactId>
   10.11 +    <version>0.3-SNAPSHOT</version>
   10.12 +  </parent>
   10.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
   10.14 +  <artifactId>dew</artifactId>
   10.15 +  <version>0.3-SNAPSHOT</version>
   10.16 +  <name>Development Environment for Web</name>
   10.17 +  <url>http://maven.apache.org</url>
   10.18 +    <build>
   10.19 +        <plugins>
   10.20 +            <plugin>
   10.21 +                <groupId>org.apache.maven.plugins</groupId>
   10.22 +                <artifactId>maven-compiler-plugin</artifactId>
   10.23 +                <version>2.3.2</version>
   10.24 +                <configuration>
   10.25 +                    <source>1.7</source>
   10.26 +                    <target>1.7</target>
   10.27 +                </configuration>
   10.28 +            </plugin>
   10.29 +            <plugin>
   10.30 +                <groupId>org.codehaus.mojo</groupId>
   10.31 +                <artifactId>exec-maven-plugin</artifactId>
   10.32 +                <version>1.2.1</version>
   10.33 +                <executions>
   10.34 +                    <execution>
   10.35 +                        <goals>
   10.36 +                            <goal>exec</goal>
   10.37 +                        </goals>
   10.38 +                    </execution>
   10.39 +                </executions>
   10.40 +                <configuration>
   10.41 +                    <executable>java</executable>
   10.42 +                     <arguments>
   10.43 +                        <argument>-classpath</argument>
   10.44 +                        <classpath/>
   10.45 +                        <argument>org.apidesign.bck2brwsr.dew.Dew</argument>
   10.46 +                    </arguments>
   10.47 +                </configuration>
   10.48 +            </plugin>
   10.49 +        </plugins>
   10.50 +    </build>
   10.51 +    <properties>
   10.52 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   10.53 +  </properties>
   10.54 +  <dependencies>
   10.55 +    <dependency>
   10.56 +      <groupId>org.glassfish.grizzly</groupId>
   10.57 +      <artifactId>grizzly-http-server</artifactId>
   10.58 +      <version>2.2.19</version>
   10.59 +    </dependency>
   10.60 +    <dependency>
   10.61 +      <groupId>${project.groupId}</groupId>
   10.62 +      <artifactId>vm4brwsr</artifactId>
   10.63 +      <version>${project.version}</version>
   10.64 +    </dependency>
   10.65 +    <dependency>
   10.66 +      <groupId>org.json</groupId>
   10.67 +      <artifactId>json</artifactId>
   10.68 +      <version>20090211</version>
   10.69 +    </dependency>
   10.70 +    <dependency>
   10.71 +      <groupId>org.testng</groupId>
   10.72 +      <artifactId>testng</artifactId>
   10.73 +      <scope>test</scope>
   10.74 +      <exclusions>
   10.75 +        <exclusion>
   10.76 +          <artifactId>junit</artifactId>
   10.77 +          <groupId>junit</groupId>
   10.78 +        </exclusion>
   10.79 +      </exclusions>
   10.80 +    </dependency>
   10.81 +    <dependency>
   10.82 +      <groupId>${project.groupId}</groupId>
   10.83 +      <artifactId>javaquery.api</artifactId>
   10.84 +      <version>${project.version}</version>
   10.85 +    </dependency>
   10.86 +  </dependencies>
   10.87 +</project>
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/dew/src/main/java/org/apidesign/bck2brwsr/dew/Compile.java	Sun Feb 03 07:48:42 2013 +0100
    11.3 @@ -0,0 +1,203 @@
    11.4 +/**
    11.5 + * Back 2 Browser Bytecode Translator
    11.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    11.7 + *
    11.8 + * This program is free software: you can redistribute it and/or modify
    11.9 + * it under the terms of the GNU General Public License as published by
   11.10 + * the Free Software Foundation, version 2 of the License.
   11.11 + *
   11.12 + * This program is distributed in the hope that it will be useful,
   11.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.15 + * GNU General Public License for more details.
   11.16 + *
   11.17 + * You should have received a copy of the GNU General Public License
   11.18 + * along with this program. Look for COPYING file in the top folder.
   11.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   11.20 + */
   11.21 +package org.apidesign.bck2brwsr.dew;
   11.22 +
   11.23 +import java.io.ByteArrayInputStream;
   11.24 +import java.io.ByteArrayOutputStream;
   11.25 +import java.io.IOException;
   11.26 +import java.io.InputStream;
   11.27 +import java.io.OutputStream;
   11.28 +import java.net.URI;
   11.29 +import java.net.URISyntaxException;
   11.30 +import java.util.ArrayList;
   11.31 +import java.util.Arrays;
   11.32 +import java.util.HashMap;
   11.33 +import java.util.List;
   11.34 +import java.util.Map;
   11.35 +import java.util.regex.Matcher;
   11.36 +import java.util.regex.Pattern;
   11.37 +import javax.tools.Diagnostic;
   11.38 +import javax.tools.DiagnosticListener;
   11.39 +import javax.tools.FileObject;
   11.40 +import javax.tools.ForwardingJavaFileManager;
   11.41 +import javax.tools.JavaFileManager;
   11.42 +import javax.tools.JavaFileObject;
   11.43 +import javax.tools.JavaFileObject.Kind;
   11.44 +import javax.tools.SimpleJavaFileObject;
   11.45 +import javax.tools.StandardJavaFileManager;
   11.46 +import javax.tools.StandardLocation;
   11.47 +import javax.tools.ToolProvider;
   11.48 +
   11.49 +/**
   11.50 + *
   11.51 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   11.52 + */
   11.53 +final class Compile implements DiagnosticListener<JavaFileObject> {
   11.54 +    private final List<Diagnostic<? extends JavaFileObject>> errors = new ArrayList<>();
   11.55 +    private final Map<String, byte[]> classes;
   11.56 +    private final String pkg;
   11.57 +    private final String cls;
   11.58 +    private final String html;
   11.59 +
   11.60 +    private Compile(String html, String code) throws IOException {
   11.61 +        this.pkg = findPkg(code);
   11.62 +        this.cls = findCls(code);
   11.63 +        this.html = html;
   11.64 +        classes = compile(html, code);
   11.65 +    }
   11.66 +
   11.67 +    /** Performs compilation of given HTML page and associated Java code
   11.68 +     */
   11.69 +    public static Compile create(String html, String code) throws IOException {
   11.70 +        return new Compile(html, code);
   11.71 +    }
   11.72 +    
   11.73 +    /** Checks for given class among compiled resources */
   11.74 +    public byte[] get(String res) {
   11.75 +        return classes.get(res);
   11.76 +    }
   11.77 +    
   11.78 +    /** Obtains errors created during compilation.
   11.79 +     */
   11.80 +    public List<Diagnostic<? extends JavaFileObject>> getErrors() {
   11.81 +        List<Diagnostic<? extends JavaFileObject>> err = new ArrayList<>();
   11.82 +        for (Diagnostic<? extends JavaFileObject> diagnostic : errors) {
   11.83 +            if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
   11.84 +                err.add(diagnostic);
   11.85 +            }
   11.86 +        }
   11.87 +        return err;
   11.88 +    }
   11.89 +    
   11.90 +    private Map<String, byte[]> compile(final String html, final String code) throws IOException {
   11.91 +        StandardJavaFileManager sjfm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(this, null, null);
   11.92 +
   11.93 +        final Map<String, ByteArrayOutputStream> class2BAOS = new HashMap<>();
   11.94 +
   11.95 +        JavaFileObject file = new SimpleJavaFileObject(URI.create("mem://mem"), Kind.SOURCE) {
   11.96 +            @Override
   11.97 +            public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
   11.98 +                return code;
   11.99 +            }
  11.100 +        };
  11.101 +        final JavaFileObject htmlFile = new SimpleJavaFileObject(URI.create("mem://mem2"), Kind.OTHER) {
  11.102 +            @Override
  11.103 +            public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
  11.104 +                return html;
  11.105 +            }
  11.106 +
  11.107 +            @Override
  11.108 +            public InputStream openInputStream() throws IOException {
  11.109 +                return new ByteArrayInputStream(html.getBytes());
  11.110 +            }
  11.111 +        };
  11.112 +        
  11.113 +        final URI scratch;
  11.114 +        try {
  11.115 +            scratch = new URI("mem://mem3");
  11.116 +        } catch (URISyntaxException ex) {
  11.117 +            throw new IOException(ex);
  11.118 +        }
  11.119 +        
  11.120 +        JavaFileManager jfm = new ForwardingJavaFileManager<JavaFileManager>(sjfm) {
  11.121 +            @Override
  11.122 +            public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException {
  11.123 +                if (kind  == Kind.CLASS) {
  11.124 +                    final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  11.125 +
  11.126 +                    class2BAOS.put(className.replace('.', '/') + ".class", buffer);
  11.127 +                    return new SimpleJavaFileObject(sibling.toUri(), kind) {
  11.128 +                        @Override
  11.129 +                        public OutputStream openOutputStream() throws IOException {
  11.130 +                            return buffer;
  11.131 +                        }
  11.132 +                    };
  11.133 +                }
  11.134 +                
  11.135 +                if (kind == Kind.SOURCE) {
  11.136 +                    return new SimpleJavaFileObject(scratch/*sibling.toUri()*/, kind) {
  11.137 +                        private final ByteArrayOutputStream data = new ByteArrayOutputStream();
  11.138 +                        @Override
  11.139 +                        public OutputStream openOutputStream() throws IOException {
  11.140 +                            return data;
  11.141 +                        }
  11.142 +
  11.143 +                        @Override
  11.144 +                        public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
  11.145 +                            data.close();
  11.146 +                            return new String(data.toByteArray());
  11.147 +                        }
  11.148 +                    };
  11.149 +                }
  11.150 +                
  11.151 +                throw new IllegalStateException();
  11.152 +            }
  11.153 +
  11.154 +            @Override
  11.155 +            public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException {
  11.156 +                if (location == StandardLocation.SOURCE_PATH) {
  11.157 +                    if (packageName.equals(pkg)) {
  11.158 +                        return htmlFile;
  11.159 +                    }
  11.160 +                }
  11.161 +                
  11.162 +                return null;
  11.163 +            }
  11.164 +            
  11.165 +        };
  11.166 +
  11.167 +        ToolProvider.getSystemJavaCompiler().getTask(null, jfm, this, /*XXX:*/Arrays.asList("-source", "1.7", "-target", "1.7"), null, Arrays.asList(file)).call();
  11.168 +
  11.169 +        Map<String, byte[]> result = new HashMap<>();
  11.170 +
  11.171 +        for (Map.Entry<String, ByteArrayOutputStream> e : class2BAOS.entrySet()) {
  11.172 +            result.put(e.getKey(), e.getValue().toByteArray());
  11.173 +        }
  11.174 +
  11.175 +        return result;
  11.176 +    }
  11.177 +
  11.178 +
  11.179 +    @Override
  11.180 +    public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
  11.181 +        errors.add(diagnostic);
  11.182 +    }
  11.183 +    private static String findPkg(String java) throws IOException {
  11.184 +        Pattern p = Pattern.compile("package\\p{javaWhitespace}*([\\p{Alnum}\\.]+)\\p{javaWhitespace}*;", Pattern.MULTILINE);
  11.185 +        Matcher m = p.matcher(java);
  11.186 +        if (!m.find()) {
  11.187 +            throw new IOException("Can't find package declaration in the java file");
  11.188 +        }
  11.189 +        String pkg = m.group(1);
  11.190 +        return pkg;
  11.191 +    }
  11.192 +    private static String findCls(String java) throws IOException {
  11.193 +        Pattern p = Pattern.compile("class\\p{javaWhitespace}*([\\p{Alnum}\\.]+)\\p{javaWhitespace}", Pattern.MULTILINE);
  11.194 +        Matcher m = p.matcher(java);
  11.195 +        if (!m.find()) {
  11.196 +            throw new IOException("Can't find package declaration in the java file");
  11.197 +        }
  11.198 +        String cls = m.group(1);
  11.199 +        return cls;
  11.200 +    }
  11.201 +
  11.202 +    String getHtml() {
  11.203 +        String fqn = "'" + pkg + '.' + cls + "'";
  11.204 +        return html.replace("'${fqn}'", fqn);
  11.205 +    }
  11.206 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/dew/src/main/java/org/apidesign/bck2brwsr/dew/Dew.java	Sun Feb 03 07:48:42 2013 +0100
    12.3 @@ -0,0 +1,136 @@
    12.4 +/**
    12.5 + * Back 2 Browser Bytecode Translator
    12.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    12.7 + *
    12.8 + * This program is free software: you can redistribute it and/or modify
    12.9 + * it under the terms of the GNU General Public License as published by
   12.10 + * the Free Software Foundation, version 2 of the License.
   12.11 + *
   12.12 + * This program is distributed in the hope that it will be useful,
   12.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.15 + * GNU General Public License for more details.
   12.16 + *
   12.17 + * You should have received a copy of the GNU General Public License
   12.18 + * along with this program. Look for COPYING file in the top folder.
   12.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   12.20 + */
   12.21 +package org.apidesign.bck2brwsr.dew;
   12.22 +
   12.23 +import java.io.ByteArrayInputStream;
   12.24 +import java.io.IOException;
   12.25 +import java.io.InputStream;
   12.26 +import java.io.InputStreamReader;
   12.27 +import java.io.OutputStream;
   12.28 +import java.util.List;
   12.29 +import java.util.Locale;
   12.30 +import javax.tools.Diagnostic;
   12.31 +import javax.tools.JavaFileObject;
   12.32 +import org.apidesign.vm4brwsr.Bck2Brwsr;
   12.33 +import org.glassfish.grizzly.http.Method;
   12.34 +import org.glassfish.grizzly.http.server.HttpHandler;
   12.35 +import org.glassfish.grizzly.http.server.HttpServer;
   12.36 +import org.glassfish.grizzly.http.server.Request;
   12.37 +import org.glassfish.grizzly.http.server.Response;
   12.38 +import org.glassfish.grizzly.http.util.HttpStatus;
   12.39 +import org.json.JSONArray;
   12.40 +import org.json.JSONObject;
   12.41 +import org.json.JSONTokener;
   12.42 +
   12.43 +/**
   12.44 + *
   12.45 + * @author phrebejk
   12.46 + */
   12.47 +final class Dew extends HttpHandler implements Bck2Brwsr.Resources {
   12.48 +    private Compile data;
   12.49 +
   12.50 +    public static void main(String... args) throws Exception {
   12.51 +        DewLauncher l = new DewLauncher(null);
   12.52 +        l.addClassLoader(DewLauncher.class.getClassLoader());
   12.53 +        final Dew dew = new Dew();
   12.54 +        HttpServer s = l.initServer(dew);
   12.55 +        s.getServerConfiguration().addHttpHandler(dew, "/dew/");
   12.56 +        l.launchServerAndBrwsr(s, "/dew/");
   12.57 +        System.in.read();
   12.58 +    }
   12.59 +    
   12.60 +    @Override
   12.61 +    public void service(Request request, Response response) throws Exception {
   12.62 +        
   12.63 +        if ( request.getMethod() == Method.POST ) {
   12.64 +            InputStream is = request.getInputStream();
   12.65 +            JSONTokener tok = new JSONTokener(new InputStreamReader(is));
   12.66 +            JSONObject obj = new JSONObject(tok);
   12.67 +            String tmpHtml = obj.getString("html");
   12.68 +            String tmpJava = obj.getString("java");
   12.69 +            
   12.70 +            Compile res = Compile.create(tmpHtml, tmpJava);
   12.71 +            List<Diagnostic<? extends JavaFileObject>> err = res.getErrors();
   12.72 +            if (err.isEmpty()) {
   12.73 +                data = res;
   12.74 +                response.getOutputStream().write("[]".getBytes());
   12.75 +                response.setStatus(HttpStatus.OK_200);
   12.76 +            } else {
   12.77 +                
   12.78 +                JSONArray errors = new JSONArray();
   12.79 +                
   12.80 +                for (Diagnostic<? extends JavaFileObject> d : err) {
   12.81 +                    JSONObject e = new JSONObject();
   12.82 +                    e.put("col", d.getColumnNumber());
   12.83 +                    e.put("line", d.getLineNumber());
   12.84 +                    e.put("kind", d.getKind().toString());
   12.85 +                    e.put("msg", d.getMessage(Locale.ENGLISH));
   12.86 +                    errors.put(e);
   12.87 +                }
   12.88 +                
   12.89 +                errors.write(response.getWriter());                
   12.90 +                response.setStatus(HttpStatus.PRECONDITION_FAILED_412);
   12.91 +            }
   12.92 +            
   12.93 +            return;
   12.94 +        }
   12.95 +        
   12.96 +        String r = request.getHttpHandlerPath();
   12.97 +        if (r == null || r.equals("/")) {
   12.98 +            r = "index.html";
   12.99 +        }
  12.100 +        if (r.equals("/result.html")) {
  12.101 +            response.setContentType("text/html");
  12.102 +            response.getOutputBuffer().write(data.getHtml());
  12.103 +            response.setStatus(HttpStatus.OK_200);
  12.104 +            return;
  12.105 +        }
  12.106 +        
  12.107 +        if (r.startsWith("/")) {
  12.108 +            r = r.substring(1);
  12.109 +        }
  12.110 +        
  12.111 +        if (r.endsWith(".html") || r.endsWith(".xhtml")) {
  12.112 +            response.setContentType("text/html");
  12.113 +        }
  12.114 +        OutputStream os = response.getOutputStream();
  12.115 +        try (InputStream is = Dew.class.getResourceAsStream(r) ) {
  12.116 +            copyStream(is, os, request.getRequestURL().toString() );
  12.117 +        } catch (IOException ex) {
  12.118 +            response.setDetailMessage(ex.getLocalizedMessage());
  12.119 +            response.setError();
  12.120 +            response.setStatus(404);
  12.121 +        }
  12.122 +    }
  12.123 +    
  12.124 +    static void copyStream(InputStream is, OutputStream os, String baseURL) throws IOException {
  12.125 +        for (;;) {
  12.126 +            int ch = is.read();
  12.127 +            if (ch == -1) {
  12.128 +                break;
  12.129 +            }
  12.130 +            os.write(ch);            
  12.131 +        }
  12.132 +    }
  12.133 +
  12.134 +    @Override
  12.135 +    public InputStream get(String r) throws IOException {
  12.136 +        byte[] arr = data == null ? null : data.get(r);
  12.137 +        return arr == null ? null : new ByteArrayInputStream(arr);
  12.138 +    }
  12.139 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/dew/src/main/java/org/apidesign/bck2brwsr/dew/DewLauncher.java	Sun Feb 03 07:48:42 2013 +0100
    13.3 @@ -0,0 +1,203 @@
    13.4 +/**
    13.5 + * Back 2 Browser Bytecode Translator
    13.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    13.7 + *
    13.8 + * This program is free software: you can redistribute it and/or modify
    13.9 + * it under the terms of the GNU General Public License as published by
   13.10 + * the Free Software Foundation, version 2 of the License.
   13.11 + *
   13.12 + * This program is distributed in the hope that it will be useful,
   13.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13.15 + * GNU General Public License for more details.
   13.16 + *
   13.17 + * You should have received a copy of the GNU General Public License
   13.18 + * along with this program. Look for COPYING file in the top folder.
   13.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   13.20 + */
   13.21 +package org.apidesign.bck2brwsr.dew;
   13.22 +
   13.23 +import java.io.IOException;
   13.24 +import java.io.InputStream;
   13.25 +import java.io.Writer;
   13.26 +import java.net.URI;
   13.27 +import java.net.URISyntaxException;
   13.28 +import java.net.URL;
   13.29 +import java.util.Arrays;
   13.30 +import java.util.Enumeration;
   13.31 +import java.util.LinkedHashSet;
   13.32 +import java.util.Set;
   13.33 +import java.util.logging.Level;
   13.34 +import java.util.logging.Logger;
   13.35 +import org.apidesign.vm4brwsr.Bck2Brwsr;
   13.36 +import org.glassfish.grizzly.PortRange;
   13.37 +import org.glassfish.grizzly.http.server.HttpHandler;
   13.38 +import org.glassfish.grizzly.http.server.HttpServer;
   13.39 +import org.glassfish.grizzly.http.server.NetworkListener;
   13.40 +import org.glassfish.grizzly.http.server.Request;
   13.41 +import org.glassfish.grizzly.http.server.Response;
   13.42 +import org.glassfish.grizzly.http.server.ServerConfiguration;
   13.43 +
   13.44 +/**
   13.45 + * Lightweight server to launch dew - the Development Environment for Web.
   13.46 + */
   13.47 +final class DewLauncher {
   13.48 +    private static final Logger LOG = Logger.getLogger(DewLauncher.class.getName());
   13.49 +    private Set<ClassLoader> loaders = new LinkedHashSet<>();
   13.50 +    private Set<Bck2Brwsr.Resources> xRes = new LinkedHashSet<>();
   13.51 +    private final Res resources = new Res();
   13.52 +    private final String cmd;
   13.53 +
   13.54 +    public DewLauncher(String cmd) {
   13.55 +        this.cmd = cmd;
   13.56 +    }
   13.57 +    
   13.58 +    public void addClassLoader(ClassLoader url) {
   13.59 +        this.loaders.add(url);
   13.60 +    }
   13.61 +
   13.62 +    final HttpServer initServer(Bck2Brwsr.Resources... extraResources) throws IOException {
   13.63 +        xRes.addAll(Arrays.asList(extraResources));
   13.64 +        
   13.65 +        HttpServer s = HttpServer.createSimpleServer(".", new PortRange(8080, 65535));
   13.66 +
   13.67 +        final ServerConfiguration conf = s.getServerConfiguration();
   13.68 +        conf.addHttpHandler(new VM(resources), "/bck2brwsr.js");
   13.69 +        conf.addHttpHandler(new VMInit(), "/vm.js");
   13.70 +        conf.addHttpHandler(new Classes(resources), "/classes/");
   13.71 +        return s;
   13.72 +    }
   13.73 +    
   13.74 +    final Object[] launchServerAndBrwsr(HttpServer server, final String page) throws IOException, URISyntaxException, InterruptedException {
   13.75 +        server.start();
   13.76 +        NetworkListener listener = server.getListeners().iterator().next();
   13.77 +        int port = listener.getPort();
   13.78 +        
   13.79 +        URI uri = new URI("http://localhost:" + port + page);
   13.80 +        LOG.log(Level.INFO, "Showing {0}", uri);
   13.81 +        if (cmd == null) {
   13.82 +            try {
   13.83 +                LOG.log(Level.INFO, "Trying Desktop.browse on {0} {2} by {1}", new Object[] {
   13.84 +                    System.getProperty("java.vm.name"),
   13.85 +                    System.getProperty("java.vm.vendor"),
   13.86 +                    System.getProperty("java.vm.version"),
   13.87 +                });
   13.88 +                java.awt.Desktop.getDesktop().browse(uri);
   13.89 +                LOG.log(Level.INFO, "Desktop.browse successfully finished");
   13.90 +                return null;
   13.91 +            } catch (UnsupportedOperationException ex) {
   13.92 +                LOG.log(Level.INFO, "Desktop.browse not supported: {0}", ex.getMessage());
   13.93 +                LOG.log(Level.FINE, null, ex);
   13.94 +            }
   13.95 +        }
   13.96 +        {
   13.97 +            String cmdName = cmd == null ? "xdg-open" : cmd;
   13.98 +            String[] cmdArr = { 
   13.99 +                cmdName, uri.toString()
  13.100 +            };
  13.101 +            LOG.log(Level.INFO, "Launching {0}", Arrays.toString(cmdArr));
  13.102 +            final Process process = Runtime.getRuntime().exec(cmdArr);
  13.103 +            return new Object[] { process, null };
  13.104 +        }
  13.105 +    }
  13.106 +
  13.107 +    private class Res implements Bck2Brwsr.Resources {
  13.108 +        @Override
  13.109 +        public InputStream get(String resource) throws IOException {
  13.110 +            for (ClassLoader l : loaders) {
  13.111 +                URL u = null;
  13.112 +                Enumeration<URL> en = l.getResources(resource);
  13.113 +                while (en.hasMoreElements()) {
  13.114 +                    u = en.nextElement();
  13.115 +                }
  13.116 +                if (u != null) {
  13.117 +                    return u.openStream();
  13.118 +                }
  13.119 +            }
  13.120 +            for (Bck2Brwsr.Resources r : xRes) {
  13.121 +                InputStream is = r.get(resource);
  13.122 +                if (is != null) {
  13.123 +                    return is;
  13.124 +                }
  13.125 +            }
  13.126 +            throw new IOException("Can't find " + resource);
  13.127 +        }
  13.128 +    }
  13.129 +
  13.130 +    private static class VM extends HttpHandler {
  13.131 +        private final String bck2brwsr;
  13.132 +
  13.133 +        public VM(Res loader) throws IOException {
  13.134 +            StringBuilder sb = new StringBuilder();
  13.135 +            Bck2Brwsr.generate(sb, loader);
  13.136 +            this.bck2brwsr = sb.toString();
  13.137 +        }
  13.138 +
  13.139 +        @Override
  13.140 +        public void service(Request request, Response response) throws Exception {
  13.141 +            response.setCharacterEncoding("UTF-8");
  13.142 +            response.setContentType("text/javascript");
  13.143 +            response.getWriter().write(bck2brwsr);
  13.144 +        }
  13.145 +    }
  13.146 +    private static class VMInit extends HttpHandler {
  13.147 +        public VMInit() {
  13.148 +        }
  13.149 +
  13.150 +        @Override
  13.151 +        public void service(Request request, Response response) throws Exception {
  13.152 +            response.setCharacterEncoding("UTF-8");
  13.153 +            response.setContentType("text/javascript");
  13.154 +            response.getWriter().append(
  13.155 +                "function ldCls(res) {\n"
  13.156 +                + "  var request = new XMLHttpRequest();\n"
  13.157 +                + "  request.open('GET', '/classes/' + res, false);\n"
  13.158 +                + "  request.send();\n"
  13.159 +                + "  var arr = eval('(' + request.responseText + ')');\n"
  13.160 +                + "  return arr;\n"
  13.161 +                + "}\n"
  13.162 +                + "var vm = new bck2brwsr(ldCls);\n");
  13.163 +        }
  13.164 +    }
  13.165 +
  13.166 +    private static class Classes extends HttpHandler {
  13.167 +        private final Res loader;
  13.168 +
  13.169 +        public Classes(Res loader) {
  13.170 +            this.loader = loader;
  13.171 +        }
  13.172 +
  13.173 +        @Override
  13.174 +        public void service(Request request, Response response) throws Exception {
  13.175 +            String res = request.getHttpHandlerPath();
  13.176 +            if (res.startsWith("/")) {
  13.177 +                res = res.substring(1);
  13.178 +            }
  13.179 +            try (InputStream is = loader.get(res)) {
  13.180 +                response.setContentType("text/javascript");
  13.181 +                Writer w = response.getWriter();
  13.182 +                w.append("[");
  13.183 +                for (int i = 0;; i++) {
  13.184 +                    int b = is.read();
  13.185 +                    if (b == -1) {
  13.186 +                        break;
  13.187 +                    }
  13.188 +                    if (i > 0) {
  13.189 +                        w.append(", ");
  13.190 +                    }
  13.191 +                    if (i % 20 == 0) {
  13.192 +                        w.write("\n");
  13.193 +                    }
  13.194 +                    if (b > 127) {
  13.195 +                        b = b - 256;
  13.196 +                    }
  13.197 +                    w.append(Integer.toString(b));
  13.198 +                }
  13.199 +                w.append("\n]");
  13.200 +            } catch (IOException ex) {
  13.201 +                response.setError();
  13.202 +                response.setDetailMessage(ex.getMessage());
  13.203 +            }
  13.204 +        }
  13.205 +    }
  13.206 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/css/app.css	Sun Feb 03 07:48:42 2013 +0100
    14.3 @@ -0,0 +1,54 @@
    14.4 +/* app css stylesheet */
    14.5 +.code-editor, .mono-font, .CodeMirror {
    14.6 +    font-family: "Inconsolata","Monaco","Consolas","Andale Mono","Bitstream Vera Sans Mono","Courier New",Courier,monospace;
    14.7 +    font-size: 13px;
    14.8 +    line-height: 15px;
    14.9 +}
   14.10 +
   14.11 +.CodeMirror {                    
   14.12 +    border: 1px solid #d9edf7;      
   14.13 +    height: 300px;
   14.14 +}
   14.15 +      
   14.16 +.CodeMirror-scroll {
   14.17 +    overflow-y: auto;
   14.18 +    overflow-x: auto;
   14.19 +}
   14.20 +
   14.21 +.error-hover:hover {
   14.22 +    text-decoration: underline;
   14.23 +    cursor: pointer;
   14.24 +} 
   14.25 +
   14.26 +.ic-html5 {
   14.27 +  display: inline-block;  
   14.28 +  height: 20px;
   14.29 +  width: 20px;
   14.30 +  vertical-align: text-bottom;
   14.31 +  background-repeat: no-repeat;  
   14.32 +  background-image: url("../img/html5.png");  
   14.33 +}
   14.34 +
   14.35 +.ic-java {
   14.36 +  display: inline-block;  
   14.37 +  height: 20px;
   14.38 +  width: 20px;
   14.39 +  vertical-align: text-bottom;
   14.40 +  background-repeat: no-repeat;  
   14.41 +  background-image: url("../img/java.png"); 
   14.42 + 
   14.43 +}
   14.44 +
   14.45 +.issues {    
   14.46 +    width: 16px;
   14.47 +}
   14.48 +
   14.49 +.issue { 
   14.50 +    height: 16px;
   14.51 +    width: 16px;
   14.52 +    vertical-align: middle;
   14.53 +    background-repeat: no-repeat;  
   14.54 +    background-image: url("../img/error.png"); 
   14.55 +    /* color: #822; */
   14.56 +}
   14.57 +
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/css/bootstrap-combined.min.css	Sun Feb 03 07:48:42 2013 +0100
    15.3 @@ -0,0 +1,18 @@
    15.4 +/*!
    15.5 + * Bootstrap v2.2.2
    15.6 + *
    15.7 + * Copyright 2012 Twitter, Inc
    15.8 + * Licensed under the Apache License v2.0
    15.9 + * http://www.apache.org/licenses/LICENSE-2.0
   15.10 + *
   15.11 + * Designed and built with all the love in the world @twitter by @mdo and @fat.
   15.12 + */article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block}audio,canvas,video{display:inline-block;*display:inline;*zoom:1}audio:not([controls]){display:none}html{font-size:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}a:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}a:hover,a:active{outline:0}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{width:auto\9;height:auto;max-width:100%;vertical-align:middle;border:0;-ms-interpolation-mode:bicubic}#map_canvas img,.google-maps img{max-width:none}button,input,select,textarea{margin:0;font-size:100%;vertical-align:middle}button,input{*overflow:visible;line-height:normal}button::-moz-focus-inner,input::-moz-focus-inner{padding:0;border:0}button,html input[type="button"],input[type="reset"],input[type="submit"]{cursor:pointer;-webkit-appearance:button}label,select,button,input[type="button"],input[type="reset"],input[type="submit"],input[type="radio"],input[type="checkbox"]{cursor:pointer}input[type="search"]{-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;-webkit-appearance:textfield}input[type="search"]::-webkit-search-decoration,input[type="search"]::-webkit-search-cancel-button{-webkit-appearance:none}textarea{overflow:auto;vertical-align:top}@media print{*{color:#000!important;text-shadow:none!important;background:transparent!important;box-shadow:none!important}a,a:visited{text-decoration:underline}a[href]:after{content:" (" attr(href) ")"}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100%!important}@page{margin:.5cm}p,h2,h3{orphans:3;widows:3}h2,h3{page-break-after:avoid}}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;line-height:0;content:""}.clearfix:after{clear:both}.hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.input-block-level{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}body{margin:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;line-height:20px;color:#333;background-color:#fff}a{color:#08c;text-decoration:none}a:hover{color:#005580;text-decoration:underline}.img-rounded{-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.img-polaroid{padding:4px;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.1);-moz-box-shadow:0 1px 3px rgba(0,0,0,0.1);box-shadow:0 1px 3px rgba(0,0,0,0.1)}.img-circle{-webkit-border-radius:500px;-moz-border-radius:500px;border-radius:500px}.row{margin-left:-20px;*zoom:1}.row:before,.row:after{display:table;line-height:0;content:""}.row:after{clear:both}[class*="span"]{float:left;min-height:1px;margin-left:20px}.container,.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:940px}.span12{width:940px}.span11{width:860px}.span10{width:780px}.span9{width:700px}.span8{width:620px}.span7{width:540px}.span6{width:460px}.span5{width:380px}.span4{width:300px}.span3{width:220px}.span2{width:140px}.span1{width:60px}.offset12{margin-left:980px}.offset11{margin-left:900px}.offset10{margin-left:820px}.offset9{margin-left:740px}.offset8{margin-left:660px}.offset7{margin-left:580px}.offset6{margin-left:500px}.offset5{margin-left:420px}.offset4{margin-left:340px}.offset3{margin-left:260px}.offset2{margin-left:180px}.offset1{margin-left:100px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;line-height:0;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:30px;margin-left:2.127659574468085%;*margin-left:2.074468085106383%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .controls-row [class*="span"]+[class*="span"]{margin-left:2.127659574468085%}.row-fluid .span12{width:100%;*width:99.94680851063829%}.row-fluid .span11{width:91.48936170212765%;*width:91.43617021276594%}.row-fluid .span10{width:82.97872340425532%;*width:82.92553191489361%}.row-fluid .span9{width:74.46808510638297%;*width:74.41489361702126%}.row-fluid .span8{width:65.95744680851064%;*width:65.90425531914893%}.row-fluid .span7{width:57.44680851063829%;*width:57.39361702127659%}.row-fluid .span6{width:48.93617021276595%;*width:48.88297872340425%}.row-fluid .span5{width:40.42553191489362%;*width:40.37234042553192%}.row-fluid .span4{width:31.914893617021278%;*width:31.861702127659576%}.row-fluid .span3{width:23.404255319148934%;*width:23.351063829787233%}.row-fluid .span2{width:14.893617021276595%;*width:14.840425531914894%}.row-fluid .span1{width:6.382978723404255%;*width:6.329787234042553%}.row-fluid .offset12{margin-left:104.25531914893617%;*margin-left:104.14893617021275%}.row-fluid .offset12:first-child{margin-left:102.12765957446808%;*margin-left:102.02127659574467%}.row-fluid .offset11{margin-left:95.74468085106382%;*margin-left:95.6382978723404%}.row-fluid .offset11:first-child{margin-left:93.61702127659574%;*margin-left:93.51063829787232%}.row-fluid .offset10{margin-left:87.23404255319149%;*margin-left:87.12765957446807%}.row-fluid .offset10:first-child{margin-left:85.1063829787234%;*margin-left:84.99999999999999%}.row-fluid .offset9{margin-left:78.72340425531914%;*margin-left:78.61702127659572%}.row-fluid .offset9:first-child{margin-left:76.59574468085106%;*margin-left:76.48936170212764%}.row-fluid .offset8{margin-left:70.2127659574468%;*margin-left:70.10638297872339%}.row-fluid .offset8:first-child{margin-left:68.08510638297872%;*margin-left:67.9787234042553%}.row-fluid .offset7{margin-left:61.70212765957446%;*margin-left:61.59574468085106%}.row-fluid .offset7:first-child{margin-left:59.574468085106375%;*margin-left:59.46808510638297%}.row-fluid .offset6{margin-left:53.191489361702125%;*margin-left:53.085106382978715%}.row-fluid .offset6:first-child{margin-left:51.063829787234035%;*margin-left:50.95744680851063%}.row-fluid .offset5{margin-left:44.68085106382979%;*margin-left:44.57446808510638%}.row-fluid .offset5:first-child{margin-left:42.5531914893617%;*margin-left:42.4468085106383%}.row-fluid .offset4{margin-left:36.170212765957444%;*margin-left:36.06382978723405%}.row-fluid .offset4:first-child{margin-left:34.04255319148936%;*margin-left:33.93617021276596%}.row-fluid .offset3{margin-left:27.659574468085104%;*margin-left:27.5531914893617%}.row-fluid .offset3:first-child{margin-left:25.53191489361702%;*margin-left:25.425531914893618%}.row-fluid .offset2{margin-left:19.148936170212764%;*margin-left:19.04255319148936%}.row-fluid .offset2:first-child{margin-left:17.02127659574468%;*margin-left:16.914893617021278%}.row-fluid .offset1{margin-left:10.638297872340425%;*margin-left:10.53191489361702%}.row-fluid .offset1:first-child{margin-left:8.51063829787234%;*margin-left:8.404255319148938%}[class*="span"].hide,.row-fluid [class*="span"].hide{display:none}[class*="span"].pull-right,.row-fluid [class*="span"].pull-right{float:right}.container{margin-right:auto;margin-left:auto;*zoom:1}.container:before,.container:after{display:table;line-height:0;content:""}.container:after{clear:both}.container-fluid{padding-right:20px;padding-left:20px;*zoom:1}.container-fluid:before,.container-fluid:after{display:table;line-height:0;content:""}.container-fluid:after{clear:both}p{margin:0 0 10px}.lead{margin-bottom:20px;font-size:21px;font-weight:200;line-height:30px}small{font-size:85%}strong{font-weight:bold}em{font-style:italic}cite{font-style:normal}.muted{color:#999}a.muted:hover{color:#808080}.text-warning{color:#c09853}a.text-warning:hover{color:#a47e3c}.text-error{color:#b94a48}a.text-error:hover{color:#953b39}.text-info{color:#3a87ad}a.text-info:hover{color:#2d6987}.text-success{color:#468847}a.text-success:hover{color:#356635}h1,h2,h3,h4,h5,h6{margin:10px 0;font-family:inherit;font-weight:bold;line-height:20px;color:inherit;text-rendering:optimizelegibility}h1 small,h2 small,h3 small,h4 small,h5 small,h6 small{font-weight:normal;line-height:1;color:#999}h1,h2,h3{line-height:40px}h1{font-size:38.5px}h2{font-size:31.5px}h3{font-size:24.5px}h4{font-size:17.5px}h5{font-size:14px}h6{font-size:11.9px}h1 small{font-size:24.5px}h2 small{font-size:17.5px}h3 small{font-size:14px}h4 small{font-size:14px}.page-header{padding-bottom:9px;margin:20px 0 30px;border-bottom:1px solid #eee}ul,ol{padding:0;margin:0 0 10px 25px}ul ul,ul ol,ol ol,ol ul{margin-bottom:0}li{line-height:20px}ul.unstyled,ol.unstyled{margin-left:0;list-style:none}ul.inline,ol.inline{margin-left:0;list-style:none}ul.inline>li,ol.inline>li{display:inline-block;padding-right:5px;padding-left:5px}dl{margin-bottom:20px}dt,dd{line-height:20px}dt{font-weight:bold}dd{margin-left:10px}.dl-horizontal{*zoom:1}.dl-horizontal:before,.dl-horizontal:after{display:table;line-height:0;content:""}.dl-horizontal:after{clear:both}.dl-horizontal dt{float:left;width:160px;overflow:hidden;clear:left;text-align:right;text-overflow:ellipsis;white-space:nowrap}.dl-horizontal dd{margin-left:180px}hr{margin:20px 0;border:0;border-top:1px solid #eee;border-bottom:1px solid #fff}abbr[title],abbr[data-original-title]{cursor:help;border-bottom:1px dotted #999}abbr.initialism{font-size:90%;text-transform:uppercase}blockquote{padding:0 0 0 15px;margin:0 0 20px;border-left:5px solid #eee}blockquote p{margin-bottom:0;font-size:16px;font-weight:300;line-height:25px}blockquote small{display:block;line-height:20px;color:#999}blockquote small:before{content:'\2014 \00A0'}blockquote.pull-right{float:right;padding-right:15px;padding-left:0;border-right:5px solid #eee;border-left:0}blockquote.pull-right p,blockquote.pull-right small{text-align:right}blockquote.pull-right small:before{content:''}blockquote.pull-right small:after{content:'\00A0 \2014'}q:before,q:after,blockquote:before,blockquote:after{content:""}address{display:block;margin-bottom:20px;font-style:normal;line-height:20px}code,pre{padding:0 3px 2px;font-family:Monaco,Menlo,Consolas,"Courier New",monospace;font-size:12px;color:#333;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}code{padding:2px 4px;color:#d14;white-space:nowrap;background-color:#f7f7f9;border:1px solid #e1e1e8}pre{display:block;padding:9.5px;margin:0 0 10px;font-size:13px;line-height:20px;word-break:break-all;word-wrap:break-word;white-space:pre;white-space:pre-wrap;background-color:#f5f5f5;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.15);-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}pre.prettyprint{margin-bottom:20px}pre code{padding:0;color:inherit;white-space:pre;white-space:pre-wrap;background-color:transparent;border:0}.pre-scrollable{max-height:340px;overflow-y:scroll}form{margin:0 0 20px}fieldset{padding:0;margin:0;border:0}legend{display:block;width:100%;padding:0;margin-bottom:20px;font-size:21px;line-height:40px;color:#333;border:0;border-bottom:1px solid #e5e5e5}legend small{font-size:15px;color:#999}label,input,button,select,textarea{font-size:14px;font-weight:normal;line-height:20px}input,button,select,textarea{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif}label{display:block;margin-bottom:5px}select,textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{display:inline-block;height:20px;padding:4px 6px;margin-bottom:10px;font-size:14px;line-height:20px;color:#555;vertical-align:middle;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}input,textarea,.uneditable-input{width:206px}textarea{height:auto}textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{background-color:#fff;border:1px solid #ccc;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border linear .2s,box-shadow linear .2s;-moz-transition:border linear .2s,box-shadow linear .2s;-o-transition:border linear .2s,box-shadow linear .2s;transition:border linear .2s,box-shadow linear .2s}textarea:focus,input[type="text"]:focus,input[type="password"]:focus,input[type="datetime"]:focus,input[type="datetime-local"]:focus,input[type="date"]:focus,input[type="month"]:focus,input[type="time"]:focus,input[type="week"]:focus,input[type="number"]:focus,input[type="email"]:focus,input[type="url"]:focus,input[type="search"]:focus,input[type="tel"]:focus,input[type="color"]:focus,.uneditable-input:focus{border-color:rgba(82,168,236,0.8);outline:0;outline:thin dotted \9;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6)}input[type="radio"],input[type="checkbox"]{margin:4px 0 0;margin-top:1px \9;*margin-top:0;line-height:normal}input[type="file"],input[type="image"],input[type="submit"],input[type="reset"],input[type="button"],input[type="radio"],input[type="checkbox"]{width:auto}select,input[type="file"]{height:30px;*margin-top:4px;line-height:30px}select{width:220px;background-color:#fff;border:1px solid #ccc}select[multiple],select[size]{height:auto}select:focus,input[type="file"]:focus,input[type="radio"]:focus,input[type="checkbox"]:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.uneditable-input,.uneditable-textarea{color:#999;cursor:not-allowed;background-color:#fcfcfc;border-color:#ccc;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.025);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.025);box-shadow:inset 0 1px 2px rgba(0,0,0,0.025)}.uneditable-input{overflow:hidden;white-space:nowrap}.uneditable-textarea{width:auto;height:auto}input:-moz-placeholder,textarea:-moz-placeholder{color:#999}input:-ms-input-placeholder,textarea:-ms-input-placeholder{color:#999}input::-webkit-input-placeholder,textarea::-webkit-input-placeholder{color:#999}.radio,.checkbox{min-height:20px;padding-left:20px}.radio input[type="radio"],.checkbox input[type="checkbox"]{float:left;margin-left:-20px}.controls>.radio:first-child,.controls>.checkbox:first-child{padding-top:5px}.radio.inline,.checkbox.inline{display:inline-block;padding-top:5px;margin-bottom:0;vertical-align:middle}.radio.inline+.radio.inline,.checkbox.inline+.checkbox.inline{margin-left:10px}.input-mini{width:60px}.input-small{width:90px}.input-medium{width:150px}.input-large{width:210px}.input-xlarge{width:270px}.input-xxlarge{width:530px}input[class*="span"],select[class*="span"],textarea[class*="span"],.uneditable-input[class*="span"],.row-fluid input[class*="span"],.row-fluid select[class*="span"],.row-fluid textarea[class*="span"],.row-fluid .uneditable-input[class*="span"]{float:none;margin-left:0}.input-append input[class*="span"],.input-append .uneditable-input[class*="span"],.input-prepend input[class*="span"],.input-prepend .uneditable-input[class*="span"],.row-fluid input[class*="span"],.row-fluid select[class*="span"],.row-fluid textarea[class*="span"],.row-fluid .uneditable-input[class*="span"],.row-fluid .input-prepend [class*="span"],.row-fluid .input-append [class*="span"]{display:inline-block}input,textarea,.uneditable-input{margin-left:0}.controls-row [class*="span"]+[class*="span"]{margin-left:20px}input.span12,textarea.span12,.uneditable-input.span12{width:926px}input.span11,textarea.span11,.uneditable-input.span11{width:846px}input.span10,textarea.span10,.uneditable-input.span10{width:766px}input.span9,textarea.span9,.uneditable-input.span9{width:686px}input.span8,textarea.span8,.uneditable-input.span8{width:606px}input.span7,textarea.span7,.uneditable-input.span7{width:526px}input.span6,textarea.span6,.uneditable-input.span6{width:446px}input.span5,textarea.span5,.uneditable-input.span5{width:366px}input.span4,textarea.span4,.uneditable-input.span4{width:286px}input.span3,textarea.span3,.uneditable-input.span3{width:206px}input.span2,textarea.span2,.uneditable-input.span2{width:126px}input.span1,textarea.span1,.uneditable-input.span1{width:46px}.controls-row{*zoom:1}.controls-row:before,.controls-row:after{display:table;line-height:0;content:""}.controls-row:after{clear:both}.controls-row [class*="span"],.row-fluid .controls-row [class*="span"]{float:left}.controls-row .checkbox[class*="span"],.controls-row .radio[class*="span"]{padding-top:5px}input[disabled],select[disabled],textarea[disabled],input[readonly],select[readonly],textarea[readonly]{cursor:not-allowed;background-color:#eee}input[type="radio"][disabled],input[type="checkbox"][disabled],input[type="radio"][readonly],input[type="checkbox"][readonly]{background-color:transparent}.control-group.warning .control-label,.control-group.warning .help-block,.control-group.warning .help-inline{color:#c09853}.control-group.warning .checkbox,.control-group.warning .radio,.control-group.warning input,.control-group.warning select,.control-group.warning textarea{color:#c09853}.control-group.warning input,.control-group.warning select,.control-group.warning textarea{border-color:#c09853;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.warning input:focus,.control-group.warning select:focus,.control-group.warning textarea:focus{border-color:#a47e3c;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e}.control-group.warning .input-prepend .add-on,.control-group.warning .input-append .add-on{color:#c09853;background-color:#fcf8e3;border-color:#c09853}.control-group.error .control-label,.control-group.error .help-block,.control-group.error .help-inline{color:#b94a48}.control-group.error .checkbox,.control-group.error .radio,.control-group.error input,.control-group.error select,.control-group.error textarea{color:#b94a48}.control-group.error input,.control-group.error select,.control-group.error textarea{border-color:#b94a48;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.error input:focus,.control-group.error select:focus,.control-group.error textarea:focus{border-color:#953b39;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #d59392;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #d59392;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #d59392}.control-group.error .input-prepend .add-on,.control-group.error .input-append .add-on{color:#b94a48;background-color:#f2dede;border-color:#b94a48}.control-group.success .control-label,.control-group.success .help-block,.control-group.success .help-inline{color:#468847}.control-group.success .checkbox,.control-group.success .radio,.control-group.success input,.control-group.success select,.control-group.success textarea{color:#468847}.control-group.success input,.control-group.success select,.control-group.success textarea{border-color:#468847;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.success input:focus,.control-group.success select:focus,.control-group.success textarea:focus{border-color:#356635;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7aba7b;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7aba7b;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7aba7b}.control-group.success .input-prepend .add-on,.control-group.success .input-append .add-on{color:#468847;background-color:#dff0d8;border-color:#468847}.control-group.info .control-label,.control-group.info .help-block,.control-group.info .help-inline{color:#3a87ad}.control-group.info .checkbox,.control-group.info .radio,.control-group.info input,.control-group.info select,.control-group.info textarea{color:#3a87ad}.control-group.info input,.control-group.info select,.control-group.info textarea{border-color:#3a87ad;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.info input:focus,.control-group.info select:focus,.control-group.info textarea:focus{border-color:#2d6987;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7ab5d3;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7ab5d3;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7ab5d3}.control-group.info .input-prepend .add-on,.control-group.info .input-append .add-on{color:#3a87ad;background-color:#d9edf7;border-color:#3a87ad}input:focus:invalid,textarea:focus:invalid,select:focus:invalid{color:#b94a48;border-color:#ee5f5b}input:focus:invalid:focus,textarea:focus:invalid:focus,select:focus:invalid:focus{border-color:#e9322d;-webkit-box-shadow:0 0 6px #f8b9b7;-moz-box-shadow:0 0 6px #f8b9b7;box-shadow:0 0 6px #f8b9b7}.form-actions{padding:19px 20px 20px;margin-top:20px;margin-bottom:20px;background-color:#f5f5f5;border-top:1px solid #e5e5e5;*zoom:1}.form-actions:before,.form-actions:after{display:table;line-height:0;content:""}.form-actions:after{clear:both}.help-block,.help-inline{color:#595959}.help-block{display:block;margin-bottom:10px}.help-inline{display:inline-block;*display:inline;padding-left:5px;vertical-align:middle;*zoom:1}.input-append,.input-prepend{margin-bottom:5px;font-size:0;white-space:nowrap}.input-append input,.input-prepend input,.input-append select,.input-prepend select,.input-append .uneditable-input,.input-prepend .uneditable-input,.input-append .dropdown-menu,.input-prepend .dropdown-menu{font-size:14px}.input-append input,.input-prepend input,.input-append select,.input-prepend select,.input-append .uneditable-input,.input-prepend .uneditable-input{position:relative;margin-bottom:0;*margin-left:0;vertical-align:top;-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-append input:focus,.input-prepend input:focus,.input-append select:focus,.input-prepend select:focus,.input-append .uneditable-input:focus,.input-prepend .uneditable-input:focus{z-index:2}.input-append .add-on,.input-prepend .add-on{display:inline-block;width:auto;height:20px;min-width:16px;padding:4px 5px;font-size:14px;font-weight:normal;line-height:20px;text-align:center;text-shadow:0 1px 0 #fff;background-color:#eee;border:1px solid #ccc}.input-append .add-on,.input-prepend .add-on,.input-append .btn,.input-prepend .btn,.input-append .btn-group>.dropdown-toggle,.input-prepend .btn-group>.dropdown-toggle{vertical-align:top;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.input-append .active,.input-prepend .active{background-color:#a9dba9;border-color:#46a546}.input-prepend .add-on,.input-prepend .btn{margin-right:-1px}.input-prepend .add-on:first-child,.input-prepend .btn:first-child{-webkit-border-radius:4px 0 0 4px;-moz-border-radius:4px 0 0 4px;border-radius:4px 0 0 4px}.input-append input,.input-append select,.input-append .uneditable-input{-webkit-border-radius:4px 0 0 4px;-moz-border-radius:4px 0 0 4px;border-radius:4px 0 0 4px}.input-append input+.btn-group .btn:last-child,.input-append select+.btn-group .btn:last-child,.input-append .uneditable-input+.btn-group .btn:last-child{-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-append .add-on,.input-append .btn,.input-append .btn-group{margin-left:-1px}.input-append .add-on:last-child,.input-append .btn:last-child,.input-append .btn-group:last-child>.dropdown-toggle{-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-prepend.input-append input,.input-prepend.input-append select,.input-prepend.input-append .uneditable-input{-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.input-prepend.input-append input+.btn-group .btn,.input-prepend.input-append select+.btn-group .btn,.input-prepend.input-append .uneditable-input+.btn-group .btn{-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-prepend.input-append .add-on:first-child,.input-prepend.input-append .btn:first-child{margin-right:-1px;-webkit-border-radius:4px 0 0 4px;-moz-border-radius:4px 0 0 4px;border-radius:4px 0 0 4px}.input-prepend.input-append .add-on:last-child,.input-prepend.input-append .btn:last-child{margin-left:-1px;-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-prepend.input-append .btn-group:first-child{margin-left:0}input.search-query{padding-right:14px;padding-right:4px \9;padding-left:14px;padding-left:4px \9;margin-bottom:0;-webkit-border-radius:15px;-moz-border-radius:15px;border-radius:15px}.form-search .input-append .search-query,.form-search .input-prepend .search-query{-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.form-search .input-append .search-query{-webkit-border-radius:14px 0 0 14px;-moz-border-radius:14px 0 0 14px;border-radius:14px 0 0 14px}.form-search .input-append .btn{-webkit-border-radius:0 14px 14px 0;-moz-border-radius:0 14px 14px 0;border-radius:0 14px 14px 0}.form-search .input-prepend .search-query{-webkit-border-radius:0 14px 14px 0;-moz-border-radius:0 14px 14px 0;border-radius:0 14px 14px 0}.form-search .input-prepend .btn{-webkit-border-radius:14px 0 0 14px;-moz-border-radius:14px 0 0 14px;border-radius:14px 0 0 14px}.form-search input,.form-inline input,.form-horizontal input,.form-search textarea,.form-inline textarea,.form-horizontal textarea,.form-search select,.form-inline select,.form-horizontal select,.form-search .help-inline,.form-inline .help-inline,.form-horizontal .help-inline,.form-search .uneditable-input,.form-inline .uneditable-input,.form-horizontal .uneditable-input,.form-search .input-prepend,.form-inline .input-prepend,.form-horizontal .input-prepend,.form-search .input-append,.form-inline .input-append,.form-horizontal .input-append{display:inline-block;*display:inline;margin-bottom:0;vertical-align:middle;*zoom:1}.form-search .hide,.form-inline .hide,.form-horizontal .hide{display:none}.form-search label,.form-inline label,.form-search .btn-group,.form-inline .btn-group{display:inline-block}.form-search .input-append,.form-inline .input-append,.form-search .input-prepend,.form-inline .input-prepend{margin-bottom:0}.form-search .radio,.form-search .checkbox,.form-inline .radio,.form-inline .checkbox{padding-left:0;margin-bottom:0;vertical-align:middle}.form-search .radio input[type="radio"],.form-search .checkbox input[type="checkbox"],.form-inline .radio input[type="radio"],.form-inline .checkbox input[type="checkbox"]{float:left;margin-right:3px;margin-left:0}.control-group{margin-bottom:10px}legend+.control-group{margin-top:20px;-webkit-margin-top-collapse:separate}.form-horizontal .control-group{margin-bottom:20px;*zoom:1}.form-horizontal .control-group:before,.form-horizontal .control-group:after{display:table;line-height:0;content:""}.form-horizontal .control-group:after{clear:both}.form-horizontal .control-label{float:left;width:160px;padding-top:5px;text-align:right}.form-horizontal .controls{*display:inline-block;*padding-left:20px;margin-left:180px;*margin-left:0}.form-horizontal .controls:first-child{*padding-left:180px}.form-horizontal .help-block{margin-bottom:0}.form-horizontal input+.help-block,.form-horizontal select+.help-block,.form-horizontal textarea+.help-block,.form-horizontal .uneditable-input+.help-block,.form-horizontal .input-prepend+.help-block,.form-horizontal .input-append+.help-block{margin-top:10px}.form-horizontal .form-actions{padding-left:180px}table{max-width:100%;background-color:transparent;border-collapse:collapse;border-spacing:0}.table{width:100%;margin-bottom:20px}.table th,.table td{padding:8px;line-height:20px;text-align:left;vertical-align:top;border-top:1px solid #ddd}.table th{font-weight:bold}.table thead th{vertical-align:bottom}.table caption+thead tr:first-child th,.table caption+thead tr:first-child td,.table colgroup+thead tr:first-child th,.table colgroup+thead tr:first-child td,.table thead:first-child tr:first-child th,.table thead:first-child tr:first-child td{border-top:0}.table tbody+tbody{border-top:2px solid #ddd}.table .table{background-color:#fff}.table-condensed th,.table-condensed td{padding:4px 5px}.table-bordered{border:1px solid #ddd;border-collapse:separate;*border-collapse:collapse;border-left:0;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.table-bordered th,.table-bordered td{border-left:1px solid #ddd}.table-bordered caption+thead tr:first-child th,.table-bordered caption+tbody tr:first-child th,.table-bordered caption+tbody tr:first-child td,.table-bordered colgroup+thead tr:first-child th,.table-bordered colgroup+tbody tr:first-child th,.table-bordered colgroup+tbody tr:first-child td,.table-bordered thead:first-child tr:first-child th,.table-bordered tbody:first-child tr:first-child th,.table-bordered tbody:first-child tr:first-child td{border-top:0}.table-bordered thead:first-child tr:first-child>th:first-child,.table-bordered tbody:first-child tr:first-child>td:first-child{-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-topleft:4px}.table-bordered thead:first-child tr:first-child>th:last-child,.table-bordered tbody:first-child tr:first-child>td:last-child{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-moz-border-radius-topright:4px}.table-bordered thead:last-child tr:last-child>th:first-child,.table-bordered tbody:last-child tr:last-child>td:first-child,.table-bordered tfoot:last-child tr:last-child>td:first-child{-webkit-border-bottom-left-radius:4px;border-bottom-left-radius:4px;-moz-border-radius-bottomleft:4px}.table-bordered thead:last-child tr:last-child>th:last-child,.table-bordered tbody:last-child tr:last-child>td:last-child,.table-bordered tfoot:last-child tr:last-child>td:last-child{-webkit-border-bottom-right-radius:4px;border-bottom-right-radius:4px;-moz-border-radius-bottomright:4px}.table-bordered tfoot+tbody:last-child tr:last-child td:first-child{-webkit-border-bottom-left-radius:0;border-bottom-left-radius:0;-moz-border-radius-bottomleft:0}.table-bordered tfoot+tbody:last-child tr:last-child td:last-child{-webkit-border-bottom-right-radius:0;border-bottom-right-radius:0;-moz-border-radius-bottomright:0}.table-bordered caption+thead tr:first-child th:first-child,.table-bordered caption+tbody tr:first-child td:first-child,.table-bordered colgroup+thead tr:first-child th:first-child,.table-bordered colgroup+tbody tr:first-child td:first-child{-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-topleft:4px}.table-bordered caption+thead tr:first-child th:last-child,.table-bordered caption+tbody tr:first-child td:last-child,.table-bordered colgroup+thead tr:first-child th:last-child,.table-bordered colgroup+tbody tr:first-child td:last-child{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-moz-border-radius-topright:4px}.table-striped tbody>tr:nth-child(odd)>td,.table-striped tbody>tr:nth-child(odd)>th{background-color:#f9f9f9}.table-hover tbody tr:hover td,.table-hover tbody tr:hover th{background-color:#f5f5f5}table td[class*="span"],table th[class*="span"],.row-fluid table td[class*="span"],.row-fluid table th[class*="span"]{display:table-cell;float:none;margin-left:0}.table td.span1,.table th.span1{float:none;width:44px;margin-left:0}.table td.span2,.table th.span2{float:none;width:124px;margin-left:0}.table td.span3,.table th.span3{float:none;width:204px;margin-left:0}.table td.span4,.table th.span4{float:none;width:284px;margin-left:0}.table td.span5,.table th.span5{float:none;width:364px;margin-left:0}.table td.span6,.table th.span6{float:none;width:444px;margin-left:0}.table td.span7,.table th.span7{float:none;width:524px;margin-left:0}.table td.span8,.table th.span8{float:none;width:604px;margin-left:0}.table td.span9,.table th.span9{float:none;width:684px;margin-left:0}.table td.span10,.table th.span10{float:none;width:764px;margin-left:0}.table td.span11,.table th.span11{float:none;width:844px;margin-left:0}.table td.span12,.table th.span12{float:none;width:924px;margin-left:0}.table tbody tr.success td{background-color:#dff0d8}.table tbody tr.error td{background-color:#f2dede}.table tbody tr.warning td{background-color:#fcf8e3}.table tbody tr.info td{background-color:#d9edf7}.table-hover tbody tr.success:hover td{background-color:#d0e9c6}.table-hover tbody tr.error:hover td{background-color:#ebcccc}.table-hover tbody tr.warning:hover td{background-color:#faf2cc}.table-hover tbody tr.info:hover td{background-color:#c4e3f3}[class^="icon-"],[class*=" icon-"]{display:inline-block;width:14px;height:14px;margin-top:1px;*margin-right:.3em;line-height:14px;vertical-align:text-top;background-image:url("../img/glyphicons-halflings.png");background-position:14px 14px;background-repeat:no-repeat}.icon-white,.nav-pills>.active>a>[class^="icon-"],.nav-pills>.active>a>[class*=" icon-"],.nav-list>.active>a>[class^="icon-"],.nav-list>.active>a>[class*=" icon-"],.navbar-inverse .nav>.active>a>[class^="icon-"],.navbar-inverse .nav>.active>a>[class*=" icon-"],.dropdown-menu>li>a:hover>[class^="icon-"],.dropdown-menu>li>a:hover>[class*=" icon-"],.dropdown-menu>.active>a>[class^="icon-"],.dropdown-menu>.active>a>[class*=" icon-"],.dropdown-submenu:hover>a>[class^="icon-"],.dropdown-submenu:hover>a>[class*=" icon-"]{background-image:url("../img/glyphicons-halflings-white.png")}.icon-glass{background-position:0 0}.icon-music{background-position:-24px 0}.icon-search{background-position:-48px 0}.icon-envelope{background-position:-72px 0}.icon-heart{background-position:-96px 0}.icon-star{background-position:-120px 0}.icon-star-empty{background-position:-144px 0}.icon-user{background-position:-168px 0}.icon-film{background-position:-192px 0}.icon-th-large{background-position:-216px 0}.icon-th{background-position:-240px 0}.icon-th-list{background-position:-264px 0}.icon-ok{background-position:-288px 0}.icon-remove{background-position:-312px 0}.icon-zoom-in{background-position:-336px 0}.icon-zoom-out{background-position:-360px 0}.icon-off{background-position:-384px 0}.icon-signal{background-position:-408px 0}.icon-cog{background-position:-432px 0}.icon-trash{background-position:-456px 0}.icon-home{background-position:0 -24px}.icon-file{background-position:-24px -24px}.icon-time{background-position:-48px -24px}.icon-road{background-position:-72px -24px}.icon-download-alt{background-position:-96px -24px}.icon-download{background-position:-120px -24px}.icon-upload{background-position:-144px -24px}.icon-inbox{background-position:-168px -24px}.icon-play-circle{background-position:-192px -24px}.icon-repeat{background-position:-216px -24px}.icon-refresh{background-position:-240px -24px}.icon-list-alt{background-position:-264px -24px}.icon-lock{background-position:-287px -24px}.icon-flag{background-position:-312px -24px}.icon-headphones{background-position:-336px -24px}.icon-volume-off{background-position:-360px -24px}.icon-volume-down{background-position:-384px -24px}.icon-volume-up{background-position:-408px -24px}.icon-qrcode{background-position:-432px -24px}.icon-barcode{background-position:-456px -24px}.icon-tag{background-position:0 -48px}.icon-tags{background-position:-25px -48px}.icon-book{background-position:-48px -48px}.icon-bookmark{background-position:-72px -48px}.icon-print{background-position:-96px -48px}.icon-camera{background-position:-120px -48px}.icon-font{background-position:-144px -48px}.icon-bold{background-position:-167px -48px}.icon-italic{background-position:-192px -48px}.icon-text-height{background-position:-216px -48px}.icon-text-width{background-position:-240px -48px}.icon-align-left{background-position:-264px -48px}.icon-align-center{background-position:-288px -48px}.icon-align-right{background-position:-312px -48px}.icon-align-justify{background-position:-336px -48px}.icon-list{background-position:-360px -48px}.icon-indent-left{background-position:-384px -48px}.icon-indent-right{background-position:-408px -48px}.icon-facetime-video{background-position:-432px -48px}.icon-picture{background-position:-456px -48px}.icon-pencil{background-position:0 -72px}.icon-map-marker{background-position:-24px -72px}.icon-adjust{background-position:-48px -72px}.icon-tint{background-position:-72px -72px}.icon-edit{background-position:-96px -72px}.icon-share{background-position:-120px -72px}.icon-check{background-position:-144px -72px}.icon-move{background-position:-168px -72px}.icon-step-backward{background-position:-192px -72px}.icon-fast-backward{background-position:-216px -72px}.icon-backward{background-position:-240px -72px}.icon-play{background-position:-264px -72px}.icon-pause{background-position:-288px -72px}.icon-stop{background-position:-312px -72px}.icon-forward{background-position:-336px -72px}.icon-fast-forward{background-position:-360px -72px}.icon-step-forward{background-position:-384px -72px}.icon-eject{background-position:-408px -72px}.icon-chevron-left{background-position:-432px -72px}.icon-chevron-right{background-position:-456px -72px}.icon-plus-sign{background-position:0 -96px}.icon-minus-sign{background-position:-24px -96px}.icon-remove-sign{background-position:-48px -96px}.icon-ok-sign{background-position:-72px -96px}.icon-question-sign{background-position:-96px -96px}.icon-info-sign{background-position:-120px -96px}.icon-screenshot{background-position:-144px -96px}.icon-remove-circle{background-position:-168px -96px}.icon-ok-circle{background-position:-192px -96px}.icon-ban-circle{background-position:-216px -96px}.icon-arrow-left{background-position:-240px -96px}.icon-arrow-right{background-position:-264px -96px}.icon-arrow-up{background-position:-289px -96px}.icon-arrow-down{background-position:-312px -96px}.icon-share-alt{background-position:-336px -96px}.icon-resize-full{background-position:-360px -96px}.icon-resize-small{background-position:-384px -96px}.icon-plus{background-position:-408px -96px}.icon-minus{background-position:-433px -96px}.icon-asterisk{background-position:-456px -96px}.icon-exclamation-sign{background-position:0 -120px}.icon-gift{background-position:-24px -120px}.icon-leaf{background-position:-48px -120px}.icon-fire{background-position:-72px -120px}.icon-eye-open{background-position:-96px -120px}.icon-eye-close{background-position:-120px -120px}.icon-warning-sign{background-position:-144px -120px}.icon-plane{background-position:-168px -120px}.icon-calendar{background-position:-192px -120px}.icon-random{width:16px;background-position:-216px -120px}.icon-comment{background-position:-240px -120px}.icon-magnet{background-position:-264px -120px}.icon-chevron-up{background-position:-288px -120px}.icon-chevron-down{background-position:-313px -119px}.icon-retweet{background-position:-336px -120px}.icon-shopping-cart{background-position:-360px -120px}.icon-folder-close{background-position:-384px -120px}.icon-folder-open{width:16px;background-position:-408px -120px}.icon-resize-vertical{background-position:-432px -119px}.icon-resize-horizontal{background-position:-456px -118px}.icon-hdd{background-position:0 -144px}.icon-bullhorn{background-position:-24px -144px}.icon-bell{background-position:-48px -144px}.icon-certificate{background-position:-72px -144px}.icon-thumbs-up{background-position:-96px -144px}.icon-thumbs-down{background-position:-120px -144px}.icon-hand-right{background-position:-144px -144px}.icon-hand-left{background-position:-168px -144px}.icon-hand-up{background-position:-192px -144px}.icon-hand-down{background-position:-216px -144px}.icon-circle-arrow-right{background-position:-240px -144px}.icon-circle-arrow-left{background-position:-264px -144px}.icon-circle-arrow-up{background-position:-288px -144px}.icon-circle-arrow-down{background-position:-312px -144px}.icon-globe{background-position:-336px -144px}.icon-wrench{background-position:-360px -144px}.icon-tasks{background-position:-384px -144px}.icon-filter{background-position:-408px -144px}.icon-briefcase{background-position:-432px -144px}.icon-fullscreen{background-position:-456px -144px}.dropup,.dropdown{position:relative}.dropdown-toggle{*margin-bottom:-3px}.dropdown-toggle:active,.open .dropdown-toggle{outline:0}.caret{display:inline-block;width:0;height:0;vertical-align:top;border-top:4px solid #000;border-right:4px solid transparent;border-left:4px solid transparent;content:""}.dropdown .caret{margin-top:8px;margin-left:2px}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;list-style:none;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);*border-right-width:2px;*border-bottom-width:2px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;-webkit-box-shadow:0 5px 10px rgba(0,0,0,0.2);-moz-box-shadow:0 5px 10px rgba(0,0,0,0.2);box-shadow:0 5px 10px rgba(0,0,0,0.2);-webkit-background-clip:padding-box;-moz-background-clip:padding;background-clip:padding-box}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{*width:100%;height:1px;margin:9px 1px;*margin:-5px 0 5px;overflow:hidden;background-color:#e5e5e5;border-bottom:1px solid #fff}.dropdown-menu li>a{display:block;padding:3px 20px;clear:both;font-weight:normal;line-height:20px;color:#333;white-space:nowrap}.dropdown-menu li>a:hover,.dropdown-menu li>a:focus,.dropdown-submenu:hover>a{color:#fff;text-decoration:none;background-color:#0081c2;background-image:-moz-linear-gradient(top,#08c,#0077b3);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#0077b3));background-image:-webkit-linear-gradient(top,#08c,#0077b3);background-image:-o-linear-gradient(top,#08c,#0077b3);background-image:linear-gradient(to bottom,#08c,#0077b3);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc',endColorstr='#ff0077b3',GradientType=0)}.dropdown-menu .active>a,.dropdown-menu .active>a:hover{color:#fff;text-decoration:none;background-color:#0081c2;background-image:-moz-linear-gradient(top,#08c,#0077b3);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#0077b3));background-image:-webkit-linear-gradient(top,#08c,#0077b3);background-image:-o-linear-gradient(top,#08c,#0077b3);background-image:linear-gradient(to bottom,#08c,#0077b3);background-repeat:repeat-x;outline:0;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc',endColorstr='#ff0077b3',GradientType=0)}.dropdown-menu .disabled>a,.dropdown-menu .disabled>a:hover{color:#999}.dropdown-menu .disabled>a:hover{text-decoration:none;cursor:default;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.open{*z-index:1000}.open>.dropdown-menu{display:block}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{border-top:0;border-bottom:4px solid #000;content:""}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:1px}.dropdown-submenu{position:relative}.dropdown-submenu>.dropdown-menu{top:0;left:100%;margin-top:-6px;margin-left:-1px;-webkit-border-radius:0 6px 6px 6px;-moz-border-radius:0 6px 6px 6px;border-radius:0 6px 6px 6px}.dropdown-submenu:hover>.dropdown-menu{display:block}.dropup .dropdown-submenu>.dropdown-menu{top:auto;bottom:0;margin-top:0;margin-bottom:-2px;-webkit-border-radius:5px 5px 5px 0;-moz-border-radius:5px 5px 5px 0;border-radius:5px 5px 5px 0}.dropdown-submenu>a:after{display:block;float:right;width:0;height:0;margin-top:5px;margin-right:-10px;border-color:transparent;border-left-color:#ccc;border-style:solid;border-width:5px 0 5px 5px;content:" "}.dropdown-submenu:hover>a:after{border-left-color:#fff}.dropdown-submenu.pull-left{float:none}.dropdown-submenu.pull-left>.dropdown-menu{left:-100%;margin-left:10px;-webkit-border-radius:6px 0 6px 6px;-moz-border-radius:6px 0 6px 6px;border-radius:6px 0 6px 6px}.dropdown .dropdown-menu .nav-header{padding-right:20px;padding-left:20px}.typeahead{z-index:1051;margin-top:2px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.well{min-height:20px;padding:19px;margin-bottom:20px;background-color:#f5f5f5;border:1px solid #e3e3e3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.05);box-shadow:inset 0 1px 1px rgba(0,0,0,0.05)}.well blockquote{border-color:#ddd;border-color:rgba(0,0,0,0.15)}.well-large{padding:24px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.well-small{padding:9px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.fade{opacity:0;-webkit-transition:opacity .15s linear;-moz-transition:opacity .15s linear;-o-transition:opacity .15s linear;transition:opacity .15s linear}.fade.in{opacity:1}.collapse{position:relative;height:0;overflow:hidden;-webkit-transition:height .35s ease;-moz-transition:height .35s ease;-o-transition:height .35s ease;transition:height .35s ease}.collapse.in{height:auto}.close{float:right;font-size:20px;font-weight:bold;line-height:20px;color:#000;text-shadow:0 1px 0 #fff;opacity:.2;filter:alpha(opacity=20)}.close:hover{color:#000;text-decoration:none;cursor:pointer;opacity:.4;filter:alpha(opacity=40)}button.close{padding:0;cursor:pointer;background:transparent;border:0;-webkit-appearance:none}.btn{display:inline-block;*display:inline;padding:4px 12px;margin-bottom:0;*margin-left:.3em;font-size:14px;line-height:20px;color:#333;text-align:center;text-shadow:0 1px 1px rgba(255,255,255,0.75);vertical-align:middle;cursor:pointer;background-color:#f5f5f5;*background-color:#e6e6e6;background-image:-moz-linear-gradient(top,#fff,#e6e6e6);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6));background-image:-webkit-linear-gradient(top,#fff,#e6e6e6);background-image:-o-linear-gradient(top,#fff,#e6e6e6);background-image:linear-gradient(to bottom,#fff,#e6e6e6);background-repeat:repeat-x;border:1px solid #bbb;*border:0;border-color:#e6e6e6 #e6e6e6 #bfbfbf;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);border-bottom-color:#a2a2a2;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff',endColorstr='#ffe6e6e6',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);*zoom:1;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05)}.btn:hover,.btn:active,.btn.active,.btn.disabled,.btn[disabled]{color:#333;background-color:#e6e6e6;*background-color:#d9d9d9}.btn:active,.btn.active{background-color:#ccc \9}.btn:first-child{*margin-left:0}.btn:hover{color:#333;text-decoration:none;background-position:0 -15px;-webkit-transition:background-position .1s linear;-moz-transition:background-position .1s linear;-o-transition:background-position .1s linear;transition:background-position .1s linear}.btn:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.btn.active,.btn:active{background-image:none;outline:0;-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05)}.btn.disabled,.btn[disabled]{cursor:default;background-image:none;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.btn-large{padding:11px 19px;font-size:17.5px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.btn-large [class^="icon-"],.btn-large [class*=" icon-"]{margin-top:4px}.btn-small{padding:2px 10px;font-size:11.9px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-small [class^="icon-"],.btn-small [class*=" icon-"]{margin-top:0}.btn-mini [class^="icon-"],.btn-mini [class*=" icon-"]{margin-top:-1px}.btn-mini{padding:0 6px;font-size:10.5px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-block{display:block;width:100%;padding-right:0;padding-left:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.btn-block+.btn-block{margin-top:5px}input[type="submit"].btn-block,input[type="reset"].btn-block,input[type="button"].btn-block{width:100%}.btn-primary.active,.btn-warning.active,.btn-danger.active,.btn-success.active,.btn-info.active,.btn-inverse.active{color:rgba(255,255,255,0.75)}.btn{border-color:#c5c5c5;border-color:rgba(0,0,0,0.15) rgba(0,0,0,0.15) rgba(0,0,0,0.25)}.btn-primary{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#006dcc;*background-color:#04c;background-image:-moz-linear-gradient(top,#08c,#04c);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#04c));background-image:-webkit-linear-gradient(top,#08c,#04c);background-image:-o-linear-gradient(top,#08c,#04c);background-image:linear-gradient(to bottom,#08c,#04c);background-repeat:repeat-x;border-color:#04c #04c #002a80;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc',endColorstr='#ff0044cc',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-primary:hover,.btn-primary:active,.btn-primary.active,.btn-primary.disabled,.btn-primary[disabled]{color:#fff;background-color:#04c;*background-color:#003bb3}.btn-primary:active,.btn-primary.active{background-color:#039 \9}.btn-warning{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#faa732;*background-color:#f89406;background-image:-moz-linear-gradient(top,#fbb450,#f89406);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fbb450),to(#f89406));background-image:-webkit-linear-gradient(top,#fbb450,#f89406);background-image:-o-linear-gradient(top,#fbb450,#f89406);background-image:linear-gradient(to bottom,#fbb450,#f89406);background-repeat:repeat-x;border-color:#f89406 #f89406 #ad6704;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffbb450',endColorstr='#fff89406',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-warning:hover,.btn-warning:active,.btn-warning.active,.btn-warning.disabled,.btn-warning[disabled]{color:#fff;background-color:#f89406;*background-color:#df8505}.btn-warning:active,.btn-warning.active{background-color:#c67605 \9}.btn-danger{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#da4f49;*background-color:#bd362f;background-image:-moz-linear-gradient(top,#ee5f5b,#bd362f);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#bd362f));background-image:-webkit-linear-gradient(top,#ee5f5b,#bd362f);background-image:-o-linear-gradient(top,#ee5f5b,#bd362f);background-image:linear-gradient(to bottom,#ee5f5b,#bd362f);background-repeat:repeat-x;border-color:#bd362f #bd362f #802420;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffee5f5b',endColorstr='#ffbd362f',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-danger:hover,.btn-danger:active,.btn-danger.active,.btn-danger.disabled,.btn-danger[disabled]{color:#fff;background-color:#bd362f;*background-color:#a9302a}.btn-danger:active,.btn-danger.active{background-color:#942a25 \9}.btn-success{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#5bb75b;*background-color:#51a351;background-image:-moz-linear-gradient(top,#62c462,#51a351);background-image:-webkit-gradient(linear,0 0,0 100%,from(#62c462),to(#51a351));background-image:-webkit-linear-gradient(top,#62c462,#51a351);background-image:-o-linear-gradient(top,#62c462,#51a351);background-image:linear-gradient(to bottom,#62c462,#51a351);background-repeat:repeat-x;border-color:#51a351 #51a351 #387038;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff62c462',endColorstr='#ff51a351',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-success:hover,.btn-success:active,.btn-success.active,.btn-success.disabled,.btn-success[disabled]{color:#fff;background-color:#51a351;*background-color:#499249}.btn-success:active,.btn-success.active{background-color:#408140 \9}.btn-info{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#49afcd;*background-color:#2f96b4;background-image:-moz-linear-gradient(top,#5bc0de,#2f96b4);background-image:-webkit-gradient(linear,0 0,0 100%,from(#5bc0de),to(#2f96b4));background-image:-webkit-linear-gradient(top,#5bc0de,#2f96b4);background-image:-o-linear-gradient(top,#5bc0de,#2f96b4);background-image:linear-gradient(to bottom,#5bc0de,#2f96b4);background-repeat:repeat-x;border-color:#2f96b4 #2f96b4 #1f6377;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de',endColorstr='#ff2f96b4',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-info:hover,.btn-info:active,.btn-info.active,.btn-info.disabled,.btn-info[disabled]{color:#fff;background-color:#2f96b4;*background-color:#2a85a0}.btn-info:active,.btn-info.active{background-color:#24748c \9}.btn-inverse{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#363636;*background-color:#222;background-image:-moz-linear-gradient(top,#444,#222);background-image:-webkit-gradient(linear,0 0,0 100%,from(#444),to(#222));background-image:-webkit-linear-gradient(top,#444,#222);background-image:-o-linear-gradient(top,#444,#222);background-image:linear-gradient(to bottom,#444,#222);background-repeat:repeat-x;border-color:#222 #222 #000;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff444444',endColorstr='#ff222222',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-inverse:hover,.btn-inverse:active,.btn-inverse.active,.btn-inverse.disabled,.btn-inverse[disabled]{color:#fff;background-color:#222;*background-color:#151515}.btn-inverse:active,.btn-inverse.active{background-color:#080808 \9}button.btn,input[type="submit"].btn{*padding-top:3px;*padding-bottom:3px}button.btn::-moz-focus-inner,input[type="submit"].btn::-moz-focus-inner{padding:0;border:0}button.btn.btn-large,input[type="submit"].btn.btn-large{*padding-top:7px;*padding-bottom:7px}button.btn.btn-small,input[type="submit"].btn.btn-small{*padding-top:3px;*padding-bottom:3px}button.btn.btn-mini,input[type="submit"].btn.btn-mini{*padding-top:1px;*padding-bottom:1px}.btn-link,.btn-link:active,.btn-link[disabled]{background-color:transparent;background-image:none;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.btn-link{color:#08c;cursor:pointer;border-color:transparent;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.btn-link:hover{color:#005580;text-decoration:underline;background-color:transparent}.btn-link[disabled]:hover{color:#333;text-decoration:none}.btn-group{position:relative;display:inline-block;*display:inline;*margin-left:.3em;font-size:0;white-space:nowrap;vertical-align:middle;*zoom:1}.btn-group:first-child{*margin-left:0}.btn-group+.btn-group{margin-left:5px}.btn-toolbar{margin-top:10px;margin-bottom:10px;font-size:0}.btn-toolbar>.btn+.btn,.btn-toolbar>.btn-group+.btn,.btn-toolbar>.btn+.btn-group{margin-left:5px}.btn-group>.btn{position:relative;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.btn-group>.btn+.btn{margin-left:-1px}.btn-group>.btn,.btn-group>.dropdown-menu,.btn-group>.popover{font-size:14px}.btn-group>.btn-mini{font-size:10.5px}.btn-group>.btn-small{font-size:11.9px}.btn-group>.btn-large{font-size:17.5px}.btn-group>.btn:first-child{margin-left:0;-webkit-border-bottom-left-radius:4px;border-bottom-left-radius:4px;-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-bottomleft:4px;-moz-border-radius-topleft:4px}.btn-group>.btn:last-child,.btn-group>.dropdown-toggle{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-webkit-border-bottom-right-radius:4px;border-bottom-right-radius:4px;-moz-border-radius-topright:4px;-moz-border-radius-bottomright:4px}.btn-group>.btn.large:first-child{margin-left:0;-webkit-border-bottom-left-radius:6px;border-bottom-left-radius:6px;-webkit-border-top-left-radius:6px;border-top-left-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-topleft:6px}.btn-group>.btn.large:last-child,.btn-group>.large.dropdown-toggle{-webkit-border-top-right-radius:6px;border-top-right-radius:6px;-webkit-border-bottom-right-radius:6px;border-bottom-right-radius:6px;-moz-border-radius-topright:6px;-moz-border-radius-bottomright:6px}.btn-group>.btn:hover,.btn-group>.btn:focus,.btn-group>.btn:active,.btn-group>.btn.active{z-index:2}.btn-group .dropdown-toggle:active,.btn-group.open .dropdown-toggle{outline:0}.btn-group>.btn+.dropdown-toggle{*padding-top:5px;padding-right:8px;*padding-bottom:5px;padding-left:8px;-webkit-box-shadow:inset 1px 0 0 rgba(255,255,255,0.125),inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 1px 0 0 rgba(255,255,255,0.125),inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 1px 0 0 rgba(255,255,255,0.125),inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05)}.btn-group>.btn-mini+.dropdown-toggle{*padding-top:2px;padding-right:5px;*padding-bottom:2px;padding-left:5px}.btn-group>.btn-small+.dropdown-toggle{*padding-top:5px;*padding-bottom:4px}.btn-group>.btn-large+.dropdown-toggle{*padding-top:7px;padding-right:12px;*padding-bottom:7px;padding-left:12px}.btn-group.open .dropdown-toggle{background-image:none;-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05)}.btn-group.open .btn.dropdown-toggle{background-color:#e6e6e6}.btn-group.open .btn-primary.dropdown-toggle{background-color:#04c}.btn-group.open .btn-warning.dropdown-toggle{background-color:#f89406}.btn-group.open .btn-danger.dropdown-toggle{background-color:#bd362f}.btn-group.open .btn-success.dropdown-toggle{background-color:#51a351}.btn-group.open .btn-info.dropdown-toggle{background-color:#2f96b4}.btn-group.open .btn-inverse.dropdown-toggle{background-color:#222}.btn .caret{margin-top:8px;margin-left:0}.btn-mini .caret,.btn-small .caret,.btn-large .caret{margin-top:6px}.btn-large .caret{border-top-width:5px;border-right-width:5px;border-left-width:5px}.dropup .btn-large .caret{border-bottom-width:5px}.btn-primary .caret,.btn-warning .caret,.btn-danger .caret,.btn-info .caret,.btn-success .caret,.btn-inverse .caret{border-top-color:#fff;border-bottom-color:#fff}.btn-group-vertical{display:inline-block;*display:inline;*zoom:1}.btn-group-vertical>.btn{display:block;float:none;max-width:100%;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.btn-group-vertical>.btn+.btn{margin-top:-1px;margin-left:0}.btn-group-vertical>.btn:first-child{-webkit-border-radius:4px 4px 0 0;-moz-border-radius:4px 4px 0 0;border-radius:4px 4px 0 0}.btn-group-vertical>.btn:last-child{-webkit-border-radius:0 0 4px 4px;-moz-border-radius:0 0 4px 4px;border-radius:0 0 4px 4px}.btn-group-vertical>.btn-large:first-child{-webkit-border-radius:6px 6px 0 0;-moz-border-radius:6px 6px 0 0;border-radius:6px 6px 0 0}.btn-group-vertical>.btn-large:last-child{-webkit-border-radius:0 0 6px 6px;-moz-border-radius:0 0 6px 6px;border-radius:0 0 6px 6px}.alert{padding:8px 35px 8px 14px;margin-bottom:20px;text-shadow:0 1px 0 rgba(255,255,255,0.5);background-color:#fcf8e3;border:1px solid #fbeed5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.alert,.alert h4{color:#c09853}.alert h4{margin:0}.alert .close{position:relative;top:-2px;right:-21px;line-height:20px}.alert-success{color:#468847;background-color:#dff0d8;border-color:#d6e9c6}.alert-success h4{color:#468847}.alert-danger,.alert-error{color:#b94a48;background-color:#f2dede;border-color:#eed3d7}.alert-danger h4,.alert-error h4{color:#b94a48}.alert-info{color:#3a87ad;background-color:#d9edf7;border-color:#bce8f1}.alert-info h4{color:#3a87ad}.alert-block{padding-top:14px;padding-bottom:14px}.alert-block>p,.alert-block>ul{margin-bottom:0}.alert-block p+p{margin-top:5px}.nav{margin-bottom:20px;margin-left:0;list-style:none}.nav>li>a{display:block}.nav>li>a:hover{text-decoration:none;background-color:#eee}.nav>li>a>img{max-width:none}.nav>.pull-right{float:right}.nav-header{display:block;padding:3px 15px;font-size:11px;font-weight:bold;line-height:20px;color:#999;text-shadow:0 1px 0 rgba(255,255,255,0.5);text-transform:uppercase}.nav li+.nav-header{margin-top:9px}.nav-list{padding-right:15px;padding-left:15px;margin-bottom:0}.nav-list>li>a,.nav-list .nav-header{margin-right:-15px;margin-left:-15px;text-shadow:0 1px 0 rgba(255,255,255,0.5)}.nav-list>li>a{padding:3px 15px}.nav-list>.active>a,.nav-list>.active>a:hover{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.2);background-color:#08c}.nav-list [class^="icon-"],.nav-list [class*=" icon-"]{margin-right:2px}.nav-list .divider{*width:100%;height:1px;margin:9px 1px;*margin:-5px 0 5px;overflow:hidden;background-color:#e5e5e5;border-bottom:1px solid #fff}.nav-tabs,.nav-pills{*zoom:1}.nav-tabs:before,.nav-pills:before,.nav-tabs:after,.nav-pills:after{display:table;line-height:0;content:""}.nav-tabs:after,.nav-pills:after{clear:both}.nav-tabs>li,.nav-pills>li{float:left}.nav-tabs>li>a,.nav-pills>li>a{padding-right:12px;padding-left:12px;margin-right:2px;line-height:14px}.nav-tabs{border-bottom:1px solid #ddd}.nav-tabs>li{margin-bottom:-1px}.nav-tabs>li>a{padding-top:8px;padding-bottom:8px;line-height:20px;border:1px solid transparent;-webkit-border-radius:4px 4px 0 0;-moz-border-radius:4px 4px 0 0;border-radius:4px 4px 0 0}.nav-tabs>li>a:hover{border-color:#eee #eee #ddd}.nav-tabs>.active>a,.nav-tabs>.active>a:hover{color:#555;cursor:default;background-color:#fff;border:1px solid #ddd;border-bottom-color:transparent}.nav-pills>li>a{padding-top:8px;padding-bottom:8px;margin-top:2px;margin-bottom:2px;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.nav-pills>.active>a,.nav-pills>.active>a:hover{color:#fff;background-color:#08c}.nav-stacked>li{float:none}.nav-stacked>li>a{margin-right:0}.nav-tabs.nav-stacked{border-bottom:0}.nav-tabs.nav-stacked>li>a{border:1px solid #ddd;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.nav-tabs.nav-stacked>li:first-child>a{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-topright:4px;-moz-border-radius-topleft:4px}.nav-tabs.nav-stacked>li:last-child>a{-webkit-border-bottom-right-radius:4px;border-bottom-right-radius:4px;-webkit-border-bottom-left-radius:4px;border-bottom-left-radius:4px;-moz-border-radius-bottomright:4px;-moz-border-radius-bottomleft:4px}.nav-tabs.nav-stacked>li>a:hover{z-index:2;border-color:#ddd}.nav-pills.nav-stacked>li>a{margin-bottom:3px}.nav-pills.nav-stacked>li:last-child>a{margin-bottom:1px}.nav-tabs .dropdown-menu{-webkit-border-radius:0 0 6px 6px;-moz-border-radius:0 0 6px 6px;border-radius:0 0 6px 6px}.nav-pills .dropdown-menu{-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.nav .dropdown-toggle .caret{margin-top:6px;border-top-color:#08c;border-bottom-color:#08c}.nav .dropdown-toggle:hover .caret{border-top-color:#005580;border-bottom-color:#005580}.nav-tabs .dropdown-toggle .caret{margin-top:8px}.nav .active .dropdown-toggle .caret{border-top-color:#fff;border-bottom-color:#fff}.nav-tabs .active .dropdown-toggle .caret{border-top-color:#555;border-bottom-color:#555}.nav>.dropdown.active>a:hover{cursor:pointer}.nav-tabs .open .dropdown-toggle,.nav-pills .open .dropdown-toggle,.nav>li.dropdown.open.active>a:hover{color:#fff;background-color:#999;border-color:#999}.nav li.dropdown.open .caret,.nav li.dropdown.open.active .caret,.nav li.dropdown.open a:hover .caret{border-top-color:#fff;border-bottom-color:#fff;opacity:1;filter:alpha(opacity=100)}.tabs-stacked .open>a:hover{border-color:#999}.tabbable{*zoom:1}.tabbable:before,.tabbable:after{display:table;line-height:0;content:""}.tabbable:after{clear:both}.tab-content{overflow:auto}.tabs-below>.nav-tabs,.tabs-right>.nav-tabs,.tabs-left>.nav-tabs{border-bottom:0}.tab-content>.tab-pane,.pill-content>.pill-pane{display:none}.tab-content>.active,.pill-content>.active{display:block}.tabs-below>.nav-tabs{border-top:1px solid #ddd}.tabs-below>.nav-tabs>li{margin-top:-1px;margin-bottom:0}.tabs-below>.nav-tabs>li>a{-webkit-border-radius:0 0 4px 4px;-moz-border-radius:0 0 4px 4px;border-radius:0 0 4px 4px}.tabs-below>.nav-tabs>li>a:hover{border-top-color:#ddd;border-bottom-color:transparent}.tabs-below>.nav-tabs>.active>a,.tabs-below>.nav-tabs>.active>a:hover{border-color:transparent #ddd #ddd #ddd}.tabs-left>.nav-tabs>li,.tabs-right>.nav-tabs>li{float:none}.tabs-left>.nav-tabs>li>a,.tabs-right>.nav-tabs>li>a{min-width:74px;margin-right:0;margin-bottom:3px}.tabs-left>.nav-tabs{float:left;margin-right:19px;border-right:1px solid #ddd}.tabs-left>.nav-tabs>li>a{margin-right:-1px;-webkit-border-radius:4px 0 0 4px;-moz-border-radius:4px 0 0 4px;border-radius:4px 0 0 4px}.tabs-left>.nav-tabs>li>a:hover{border-color:#eee #ddd #eee #eee}.tabs-left>.nav-tabs .active>a,.tabs-left>.nav-tabs .active>a:hover{border-color:#ddd transparent #ddd #ddd;*border-right-color:#fff}.tabs-right>.nav-tabs{float:right;margin-left:19px;border-left:1px solid #ddd}.tabs-right>.nav-tabs>li>a{margin-left:-1px;-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.tabs-right>.nav-tabs>li>a:hover{border-color:#eee #eee #eee #ddd}.tabs-right>.nav-tabs .active>a,.tabs-right>.nav-tabs .active>a:hover{border-color:#ddd #ddd #ddd transparent;*border-left-color:#fff}.nav>.disabled>a{color:#999}.nav>.disabled>a:hover{text-decoration:none;cursor:default;background-color:transparent}.navbar{*position:relative;*z-index:2;margin-bottom:20px;overflow:visible}.navbar-inner{min-height:40px;padding-right:20px;padding-left:20px;background-color:#fafafa;background-image:-moz-linear-gradient(top,#fff,#f2f2f2);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#f2f2f2));background-image:-webkit-linear-gradient(top,#fff,#f2f2f2);background-image:-o-linear-gradient(top,#fff,#f2f2f2);background-image:linear-gradient(to bottom,#fff,#f2f2f2);background-repeat:repeat-x;border:1px solid #d4d4d4;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff',endColorstr='#fff2f2f2',GradientType=0);*zoom:1;-webkit-box-shadow:0 1px 4px rgba(0,0,0,0.065);-moz-box-shadow:0 1px 4px rgba(0,0,0,0.065);box-shadow:0 1px 4px rgba(0,0,0,0.065)}.navbar-inner:before,.navbar-inner:after{display:table;line-height:0;content:""}.navbar-inner:after{clear:both}.navbar .container{width:auto}.nav-collapse.collapse{height:auto;overflow:visible}.navbar .brand{display:block;float:left;padding:10px 20px 10px;margin-left:-20px;font-size:20px;font-weight:200;color:#777;text-shadow:0 1px 0 #fff}.navbar .brand:hover{text-decoration:none}.navbar-text{margin-bottom:0;line-height:40px;color:#777}.navbar-link{color:#777}.navbar-link:hover{color:#333}.navbar .divider-vertical{height:40px;margin:0 9px;border-right:1px solid #fff;border-left:1px solid #f2f2f2}.navbar .btn,.navbar .btn-group{margin-top:5px}.navbar .btn-group .btn,.navbar .input-prepend .btn,.navbar .input-append .btn{margin-top:0}.navbar-form{margin-bottom:0;*zoom:1}.navbar-form:before,.navbar-form:after{display:table;line-height:0;content:""}.navbar-form:after{clear:both}.navbar-form input,.navbar-form select,.navbar-form .radio,.navbar-form .checkbox{margin-top:5px}.navbar-form input,.navbar-form select,.navbar-form .btn{display:inline-block;margin-bottom:0}.navbar-form input[type="image"],.navbar-form input[type="checkbox"],.navbar-form input[type="radio"]{margin-top:3px}.navbar-form .input-append,.navbar-form .input-prepend{margin-top:5px;white-space:nowrap}.navbar-form .input-append input,.navbar-form .input-prepend input{margin-top:0}.navbar-search{position:relative;float:left;margin-top:5px;margin-bottom:0}.navbar-search .search-query{padding:4px 14px;margin-bottom:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;font-weight:normal;line-height:1;-webkit-border-radius:15px;-moz-border-radius:15px;border-radius:15px}.navbar-static-top{position:static;margin-bottom:0}.navbar-static-top .navbar-inner{-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.navbar-fixed-top,.navbar-fixed-bottom{position:fixed;right:0;left:0;z-index:1030;margin-bottom:0}.navbar-fixed-top .navbar-inner,.navbar-static-top .navbar-inner{border-width:0 0 1px}.navbar-fixed-bottom .navbar-inner{border-width:1px 0 0}.navbar-fixed-top .navbar-inner,.navbar-fixed-bottom .navbar-inner{padding-right:0;padding-left:0;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:940px}.navbar-fixed-top{top:0}.navbar-fixed-top .navbar-inner,.navbar-static-top .navbar-inner{-webkit-box-shadow:0 1px 10px rgba(0,0,0,0.1);-moz-box-shadow:0 1px 10px rgba(0,0,0,0.1);box-shadow:0 1px 10px rgba(0,0,0,0.1)}.navbar-fixed-bottom{bottom:0}.navbar-fixed-bottom .navbar-inner{-webkit-box-shadow:0 -1px 10px rgba(0,0,0,0.1);-moz-box-shadow:0 -1px 10px rgba(0,0,0,0.1);box-shadow:0 -1px 10px rgba(0,0,0,0.1)}.navbar .nav{position:relative;left:0;display:block;float:left;margin:0 10px 0 0}.navbar .nav.pull-right{float:right;margin-right:0}.navbar .nav>li{float:left}.navbar .nav>li>a{float:none;padding:10px 15px 10px;color:#777;text-decoration:none;text-shadow:0 1px 0 #fff}.navbar .nav .dropdown-toggle .caret{margin-top:8px}.navbar .nav>li>a:focus,.navbar .nav>li>a:hover{color:#333;text-decoration:none;background-color:transparent}.navbar .nav>.active>a,.navbar .nav>.active>a:hover,.navbar .nav>.active>a:focus{color:#555;text-decoration:none;background-color:#e5e5e5;-webkit-box-shadow:inset 0 3px 8px rgba(0,0,0,0.125);-moz-box-shadow:inset 0 3px 8px rgba(0,0,0,0.125);box-shadow:inset 0 3px 8px rgba(0,0,0,0.125)}.navbar .btn-navbar{display:none;float:right;padding:7px 10px;margin-right:5px;margin-left:5px;color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#ededed;*background-color:#e5e5e5;background-image:-moz-linear-gradient(top,#f2f2f2,#e5e5e5);background-image:-webkit-gradient(linear,0 0,0 100%,from(#f2f2f2),to(#e5e5e5));background-image:-webkit-linear-gradient(top,#f2f2f2,#e5e5e5);background-image:-o-linear-gradient(top,#f2f2f2,#e5e5e5);background-image:linear-gradient(to bottom,#f2f2f2,#e5e5e5);background-repeat:repeat-x;border-color:#e5e5e5 #e5e5e5 #bfbfbf;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2f2f2',endColorstr='#ffe5e5e5',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.075);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.075);box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.075)}.navbar .btn-navbar:hover,.navbar .btn-navbar:active,.navbar .btn-navbar.active,.navbar .btn-navbar.disabled,.navbar .btn-navbar[disabled]{color:#fff;background-color:#e5e5e5;*background-color:#d9d9d9}.navbar .btn-navbar:active,.navbar .btn-navbar.active{background-color:#ccc \9}.navbar .btn-navbar .icon-bar{display:block;width:18px;height:2px;background-color:#f5f5f5;-webkit-border-radius:1px;-moz-border-radius:1px;border-radius:1px;-webkit-box-shadow:0 1px 0 rgba(0,0,0,0.25);-moz-box-shadow:0 1px 0 rgba(0,0,0,0.25);box-shadow:0 1px 0 rgba(0,0,0,0.25)}.btn-navbar .icon-bar+.icon-bar{margin-top:3px}.navbar .nav>li>.dropdown-menu:before{position:absolute;top:-7px;left:9px;display:inline-block;border-right:7px solid transparent;border-bottom:7px solid #ccc;border-left:7px solid transparent;border-bottom-color:rgba(0,0,0,0.2);content:''}.navbar .nav>li>.dropdown-menu:after{position:absolute;top:-6px;left:10px;display:inline-block;border-right:6px solid transparent;border-bottom:6px solid #fff;border-left:6px solid transparent;content:''}.navbar-fixed-bottom .nav>li>.dropdown-menu:before{top:auto;bottom:-7px;border-top:7px solid #ccc;border-bottom:0;border-top-color:rgba(0,0,0,0.2)}.navbar-fixed-bottom .nav>li>.dropdown-menu:after{top:auto;bottom:-6px;border-top:6px solid #fff;border-bottom:0}.navbar .nav li.dropdown>a:hover .caret{border-top-color:#555;border-bottom-color:#555}.navbar .nav li.dropdown.open>.dropdown-toggle,.navbar .nav li.dropdown.active>.dropdown-toggle,.navbar .nav li.dropdown.open.active>.dropdown-toggle{color:#555;background-color:#e5e5e5}.navbar .nav li.dropdown>.dropdown-toggle .caret{border-top-color:#777;border-bottom-color:#777}.navbar .nav li.dropdown.open>.dropdown-toggle .caret,.navbar .nav li.dropdown.active>.dropdown-toggle .caret,.navbar .nav li.dropdown.open.active>.dropdown-toggle .caret{border-top-color:#555;border-bottom-color:#555}.navbar .pull-right>li>.dropdown-menu,.navbar .nav>li>.dropdown-menu.pull-right{right:0;left:auto}.navbar .pull-right>li>.dropdown-menu:before,.navbar .nav>li>.dropdown-menu.pull-right:before{right:12px;left:auto}.navbar .pull-right>li>.dropdown-menu:after,.navbar .nav>li>.dropdown-menu.pull-right:after{right:13px;left:auto}.navbar .pull-right>li>.dropdown-menu .dropdown-menu,.navbar .nav>li>.dropdown-menu.pull-right .dropdown-menu{right:100%;left:auto;margin-right:-1px;margin-left:0;-webkit-border-radius:6px 0 6px 6px;-moz-border-radius:6px 0 6px 6px;border-radius:6px 0 6px 6px}.navbar-inverse .navbar-inner{background-color:#1b1b1b;background-image:-moz-linear-gradient(top,#222,#111);background-image:-webkit-gradient(linear,0 0,0 100%,from(#222),to(#111));background-image:-webkit-linear-gradient(top,#222,#111);background-image:-o-linear-gradient(top,#222,#111);background-image:linear-gradient(to bottom,#222,#111);background-repeat:repeat-x;border-color:#252525;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff222222',endColorstr='#ff111111',GradientType=0)}.navbar-inverse .brand,.navbar-inverse .nav>li>a{color:#999;text-shadow:0 -1px 0 rgba(0,0,0,0.25)}.navbar-inverse .brand:hover,.navbar-inverse .nav>li>a:hover{color:#fff}.navbar-inverse .brand{color:#999}.navbar-inverse .navbar-text{color:#999}.navbar-inverse .nav>li>a:focus,.navbar-inverse .nav>li>a:hover{color:#fff;background-color:transparent}.navbar-inverse .nav .active>a,.navbar-inverse .nav .active>a:hover,.navbar-inverse .nav .active>a:focus{color:#fff;background-color:#111}.navbar-inverse .navbar-link{color:#999}.navbar-inverse .navbar-link:hover{color:#fff}.navbar-inverse .divider-vertical{border-right-color:#222;border-left-color:#111}.navbar-inverse .nav li.dropdown.open>.dropdown-toggle,.navbar-inverse .nav li.dropdown.active>.dropdown-toggle,.navbar-inverse .nav li.dropdown.open.active>.dropdown-toggle{color:#fff;background-color:#111}.navbar-inverse .nav li.dropdown>a:hover .caret{border-top-color:#fff;border-bottom-color:#fff}.navbar-inverse .nav li.dropdown>.dropdown-toggle .caret{border-top-color:#999;border-bottom-color:#999}.navbar-inverse .nav li.dropdown.open>.dropdown-toggle .caret,.navbar-inverse .nav li.dropdown.active>.dropdown-toggle .caret,.navbar-inverse .nav li.dropdown.open.active>.dropdown-toggle .caret{border-top-color:#fff;border-bottom-color:#fff}.navbar-inverse .navbar-search .search-query{color:#fff;background-color:#515151;border-color:#111;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1),0 1px 0 rgba(255,255,255,0.15);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1),0 1px 0 rgba(255,255,255,0.15);box-shadow:inset 0 1px 2px rgba(0,0,0,0.1),0 1px 0 rgba(255,255,255,0.15);-webkit-transition:none;-moz-transition:none;-o-transition:none;transition:none}.navbar-inverse .navbar-search .search-query:-moz-placeholder{color:#ccc}.navbar-inverse .navbar-search .search-query:-ms-input-placeholder{color:#ccc}.navbar-inverse .navbar-search .search-query::-webkit-input-placeholder{color:#ccc}.navbar-inverse .navbar-search .search-query:focus,.navbar-inverse .navbar-search .search-query.focused{padding:5px 15px;color:#333;text-shadow:0 1px 0 #fff;background-color:#fff;border:0;outline:0;-webkit-box-shadow:0 0 3px rgba(0,0,0,0.15);-moz-box-shadow:0 0 3px rgba(0,0,0,0.15);box-shadow:0 0 3px rgba(0,0,0,0.15)}.navbar-inverse .btn-navbar{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#0e0e0e;*background-color:#040404;background-image:-moz-linear-gradient(top,#151515,#040404);background-image:-webkit-gradient(linear,0 0,0 100%,from(#151515),to(#040404));background-image:-webkit-linear-gradient(top,#151515,#040404);background-image:-o-linear-gradient(top,#151515,#040404);background-image:linear-gradient(to bottom,#151515,#040404);background-repeat:repeat-x;border-color:#040404 #040404 #000;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff151515',endColorstr='#ff040404',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.navbar-inverse .btn-navbar:hover,.navbar-inverse .btn-navbar:active,.navbar-inverse .btn-navbar.active,.navbar-inverse .btn-navbar.disabled,.navbar-inverse .btn-navbar[disabled]{color:#fff;background-color:#040404;*background-color:#000}.navbar-inverse .btn-navbar:active,.navbar-inverse .btn-navbar.active{background-color:#000 \9}.breadcrumb{padding:8px 15px;margin:0 0 20px;list-style:none;background-color:#f5f5f5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.breadcrumb>li{display:inline-block;*display:inline;text-shadow:0 1px 0 #fff;*zoom:1}.breadcrumb>li>.divider{padding:0 5px;color:#ccc}.breadcrumb>.active{color:#999}.pagination{margin:20px 0}.pagination ul{display:inline-block;*display:inline;margin-bottom:0;margin-left:0;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;*zoom:1;-webkit-box-shadow:0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:0 1px 2px rgba(0,0,0,0.05);box-shadow:0 1px 2px rgba(0,0,0,0.05)}.pagination ul>li{display:inline}.pagination ul>li>a,.pagination ul>li>span{float:left;padding:4px 12px;line-height:20px;text-decoration:none;background-color:#fff;border:1px solid #ddd;border-left-width:0}.pagination ul>li>a:hover,.pagination ul>.active>a,.pagination ul>.active>span{background-color:#f5f5f5}.pagination ul>.active>a,.pagination ul>.active>span{color:#999;cursor:default}.pagination ul>.disabled>span,.pagination ul>.disabled>a,.pagination ul>.disabled>a:hover{color:#999;cursor:default;background-color:transparent}.pagination ul>li:first-child>a,.pagination ul>li:first-child>span{border-left-width:1px;-webkit-border-bottom-left-radius:4px;border-bottom-left-radius:4px;-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-bottomleft:4px;-moz-border-radius-topleft:4px}.pagination ul>li:last-child>a,.pagination ul>li:last-child>span{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-webkit-border-bottom-right-radius:4px;border-bottom-right-radius:4px;-moz-border-radius-topright:4px;-moz-border-radius-bottomright:4px}.pagination-centered{text-align:center}.pagination-right{text-align:right}.pagination-large ul>li>a,.pagination-large ul>li>span{padding:11px 19px;font-size:17.5px}.pagination-large ul>li:first-child>a,.pagination-large ul>li:first-child>span{-webkit-border-bottom-left-radius:6px;border-bottom-left-radius:6px;-webkit-border-top-left-radius:6px;border-top-left-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-topleft:6px}.pagination-large ul>li:last-child>a,.pagination-large ul>li:last-child>span{-webkit-border-top-right-radius:6px;border-top-right-radius:6px;-webkit-border-bottom-right-radius:6px;border-bottom-right-radius:6px;-moz-border-radius-topright:6px;-moz-border-radius-bottomright:6px}.pagination-mini ul>li:first-child>a,.pagination-small ul>li:first-child>a,.pagination-mini ul>li:first-child>span,.pagination-small ul>li:first-child>span{-webkit-border-bottom-left-radius:3px;border-bottom-left-radius:3px;-webkit-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-bottomleft:3px;-moz-border-radius-topleft:3px}.pagination-mini ul>li:last-child>a,.pagination-small ul>li:last-child>a,.pagination-mini ul>li:last-child>span,.pagination-small ul>li:last-child>span{-webkit-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-border-bottom-right-radius:3px;border-bottom-right-radius:3px;-moz-border-radius-topright:3px;-moz-border-radius-bottomright:3px}.pagination-small ul>li>a,.pagination-small ul>li>span{padding:2px 10px;font-size:11.9px}.pagination-mini ul>li>a,.pagination-mini ul>li>span{padding:0 6px;font-size:10.5px}.pager{margin:20px 0;text-align:center;list-style:none;*zoom:1}.pager:before,.pager:after{display:table;line-height:0;content:""}.pager:after{clear:both}.pager li{display:inline}.pager li>a,.pager li>span{display:inline-block;padding:5px 14px;background-color:#fff;border:1px solid #ddd;-webkit-border-radius:15px;-moz-border-radius:15px;border-radius:15px}.pager li>a:hover{text-decoration:none;background-color:#f5f5f5}.pager .next>a,.pager .next>span{float:right}.pager .previous>a,.pager .previous>span{float:left}.pager .disabled>a,.pager .disabled>a:hover,.pager .disabled>span{color:#999;cursor:default;background-color:#fff}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1040;background-color:#000}.modal-backdrop.fade{opacity:0}.modal-backdrop,.modal-backdrop.fade.in{opacity:.8;filter:alpha(opacity=80)}.modal{position:fixed;top:10%;left:50%;z-index:1050;width:560px;margin-left:-280px;background-color:#fff;border:1px solid #999;border:1px solid rgba(0,0,0,0.3);*border:1px solid #999;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;outline:0;-webkit-box-shadow:0 3px 7px rgba(0,0,0,0.3);-moz-box-shadow:0 3px 7px rgba(0,0,0,0.3);box-shadow:0 3px 7px rgba(0,0,0,0.3);-webkit-background-clip:padding-box;-moz-background-clip:padding-box;background-clip:padding-box}.modal.fade{top:-25%;-webkit-transition:opacity .3s linear,top .3s ease-out;-moz-transition:opacity .3s linear,top .3s ease-out;-o-transition:opacity .3s linear,top .3s ease-out;transition:opacity .3s linear,top .3s ease-out}.modal.fade.in{top:10%}.modal-header{padding:9px 15px;border-bottom:1px solid #eee}.modal-header .close{margin-top:2px}.modal-header h3{margin:0;line-height:30px}.modal-body{position:relative;max-height:400px;padding:15px;overflow-y:auto}.modal-form{margin-bottom:0}.modal-footer{padding:14px 15px 15px;margin-bottom:0;text-align:right;background-color:#f5f5f5;border-top:1px solid #ddd;-webkit-border-radius:0 0 6px 6px;-moz-border-radius:0 0 6px 6px;border-radius:0 0 6px 6px;*zoom:1;-webkit-box-shadow:inset 0 1px 0 #fff;-moz-box-shadow:inset 0 1px 0 #fff;box-shadow:inset 0 1px 0 #fff}.modal-footer:before,.modal-footer:after{display:table;line-height:0;content:""}.modal-footer:after{clear:both}.modal-footer .btn+.btn{margin-bottom:0;margin-left:5px}.modal-footer .btn-group .btn+.btn{margin-left:-1px}.modal-footer .btn-block+.btn-block{margin-left:0}.tooltip{position:absolute;z-index:1030;display:block;padding:5px;font-size:11px;opacity:0;filter:alpha(opacity=0);visibility:visible}.tooltip.in{opacity:.8;filter:alpha(opacity=80)}.tooltip.top{margin-top:-3px}.tooltip.right{margin-left:3px}.tooltip.bottom{margin-top:3px}.tooltip.left{margin-left:-3px}.tooltip-inner{max-width:200px;padding:3px 8px;color:#fff;text-align:center;text-decoration:none;background-color:#000;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.tooltip-arrow{position:absolute;width:0;height:0;border-color:transparent;border-style:solid}.tooltip.top .tooltip-arrow{bottom:0;left:50%;margin-left:-5px;border-top-color:#000;border-width:5px 5px 0}.tooltip.right .tooltip-arrow{top:50%;left:0;margin-top:-5px;border-right-color:#000;border-width:5px 5px 5px 0}.tooltip.left .tooltip-arrow{top:50%;right:0;margin-top:-5px;border-left-color:#000;border-width:5px 0 5px 5px}.tooltip.bottom .tooltip-arrow{top:0;left:50%;margin-left:-5px;border-bottom-color:#000;border-width:0 5px 5px}.popover{position:absolute;top:0;left:0;z-index:1010;display:none;width:236px;padding:1px;text-align:left;white-space:normal;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;-webkit-box-shadow:0 5px 10px rgba(0,0,0,0.2);-moz-box-shadow:0 5px 10px rgba(0,0,0,0.2);box-shadow:0 5px 10px rgba(0,0,0,0.2);-webkit-background-clip:padding-box;-moz-background-clip:padding;background-clip:padding-box}.popover.top{margin-top:-10px}.popover.right{margin-left:10px}.popover.bottom{margin-top:10px}.popover.left{margin-left:-10px}.popover-title{padding:8px 14px;margin:0;font-size:14px;font-weight:normal;line-height:18px;background-color:#f7f7f7;border-bottom:1px solid #ebebeb;-webkit-border-radius:5px 5px 0 0;-moz-border-radius:5px 5px 0 0;border-radius:5px 5px 0 0}.popover-content{padding:9px 14px}.popover .arrow,.popover .arrow:after{position:absolute;display:block;width:0;height:0;border-color:transparent;border-style:solid}.popover .arrow{border-width:11px}.popover .arrow:after{border-width:10px;content:""}.popover.top .arrow{bottom:-11px;left:50%;margin-left:-11px;border-top-color:#999;border-top-color:rgba(0,0,0,0.25);border-bottom-width:0}.popover.top .arrow:after{bottom:1px;margin-left:-10px;border-top-color:#fff;border-bottom-width:0}.popover.right .arrow{top:50%;left:-11px;margin-top:-11px;border-right-color:#999;border-right-color:rgba(0,0,0,0.25);border-left-width:0}.popover.right .arrow:after{bottom:-10px;left:1px;border-right-color:#fff;border-left-width:0}.popover.bottom .arrow{top:-11px;left:50%;margin-left:-11px;border-bottom-color:#999;border-bottom-color:rgba(0,0,0,0.25);border-top-width:0}.popover.bottom .arrow:after{top:1px;margin-left:-10px;border-bottom-color:#fff;border-top-width:0}.popover.left .arrow{top:50%;right:-11px;margin-top:-11px;border-left-color:#999;border-left-color:rgba(0,0,0,0.25);border-right-width:0}.popover.left .arrow:after{right:1px;bottom:-10px;border-left-color:#fff;border-right-width:0}.thumbnails{margin-left:-20px;list-style:none;*zoom:1}.thumbnails:before,.thumbnails:after{display:table;line-height:0;content:""}.thumbnails:after{clear:both}.row-fluid .thumbnails{margin-left:0}.thumbnails>li{float:left;margin-bottom:20px;margin-left:20px}.thumbnail{display:block;padding:4px;line-height:20px;border:1px solid #ddd;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.055);-moz-box-shadow:0 1px 3px rgba(0,0,0,0.055);box-shadow:0 1px 3px rgba(0,0,0,0.055);-webkit-transition:all .2s ease-in-out;-moz-transition:all .2s ease-in-out;-o-transition:all .2s ease-in-out;transition:all .2s ease-in-out}a.thumbnail:hover{border-color:#08c;-webkit-box-shadow:0 1px 4px rgba(0,105,214,0.25);-moz-box-shadow:0 1px 4px rgba(0,105,214,0.25);box-shadow:0 1px 4px rgba(0,105,214,0.25)}.thumbnail>img{display:block;max-width:100%;margin-right:auto;margin-left:auto}.thumbnail .caption{padding:9px;color:#555}.media,.media-body{overflow:hidden;*overflow:visible;zoom:1}.media,.media .media{margin-top:15px}.media:first-child{margin-top:0}.media-object{display:block}.media-heading{margin:0 0 5px}.media .pull-left{margin-right:10px}.media .pull-right{margin-left:10px}.media-list{margin-left:0;list-style:none}.label,.badge{display:inline-block;padding:2px 4px;font-size:11.844px;font-weight:bold;line-height:14px;color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);white-space:nowrap;vertical-align:baseline;background-color:#999}.label{-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.badge{padding-right:9px;padding-left:9px;-webkit-border-radius:9px;-moz-border-radius:9px;border-radius:9px}.label:empty,.badge:empty{display:none}a.label:hover,a.badge:hover{color:#fff;text-decoration:none;cursor:pointer}.label-important,.badge-important{background-color:#b94a48}.label-important[href],.badge-important[href]{background-color:#953b39}.label-warning,.badge-warning{background-color:#f89406}.label-warning[href],.badge-warning[href]{background-color:#c67605}.label-success,.badge-success{background-color:#468847}.label-success[href],.badge-success[href]{background-color:#356635}.label-info,.badge-info{background-color:#3a87ad}.label-info[href],.badge-info[href]{background-color:#2d6987}.label-inverse,.badge-inverse{background-color:#333}.label-inverse[href],.badge-inverse[href]{background-color:#1a1a1a}.btn .label,.btn .badge{position:relative;top:-1px}.btn-mini .label,.btn-mini .badge{top:0}@-webkit-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-moz-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-ms-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-o-keyframes progress-bar-stripes{from{background-position:0 0}to{background-position:40px 0}}@keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}.progress{height:20px;margin-bottom:20px;overflow:hidden;background-color:#f7f7f7;background-image:-moz-linear-gradient(top,#f5f5f5,#f9f9f9);background-image:-webkit-gradient(linear,0 0,0 100%,from(#f5f5f5),to(#f9f9f9));background-image:-webkit-linear-gradient(top,#f5f5f5,#f9f9f9);background-image:-o-linear-gradient(top,#f5f5f5,#f9f9f9);background-image:linear-gradient(to bottom,#f5f5f5,#f9f9f9);background-repeat:repeat-x;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5',endColorstr='#fff9f9f9',GradientType=0);-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1);box-shadow:inset 0 1px 2px rgba(0,0,0,0.1)}.progress .bar{float:left;width:0;height:100%;font-size:12px;color:#fff;text-align:center;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#0e90d2;background-image:-moz-linear-gradient(top,#149bdf,#0480be);background-image:-webkit-gradient(linear,0 0,0 100%,from(#149bdf),to(#0480be));background-image:-webkit-linear-gradient(top,#149bdf,#0480be);background-image:-o-linear-gradient(top,#149bdf,#0480be);background-image:linear-gradient(to bottom,#149bdf,#0480be);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff149bdf',endColorstr='#ff0480be',GradientType=0);-webkit-box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);-moz-box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;-webkit-transition:width .6s ease;-moz-transition:width .6s ease;-o-transition:width .6s ease;transition:width .6s ease}.progress .bar+.bar{-webkit-box-shadow:inset 1px 0 0 rgba(0,0,0,0.15),inset 0 -1px 0 rgba(0,0,0,0.15);-moz-box-shadow:inset 1px 0 0 rgba(0,0,0,0.15),inset 0 -1px 0 rgba(0,0,0,0.15);box-shadow:inset 1px 0 0 rgba(0,0,0,0.15),inset 0 -1px 0 rgba(0,0,0,0.15)}.progress-striped .bar{background-color:#149bdf;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);-webkit-background-size:40px 40px;-moz-background-size:40px 40px;-o-background-size:40px 40px;background-size:40px 40px}.progress.active .bar{-webkit-animation:progress-bar-stripes 2s linear infinite;-moz-animation:progress-bar-stripes 2s linear infinite;-ms-animation:progress-bar-stripes 2s linear infinite;-o-animation:progress-bar-stripes 2s linear infinite;animation:progress-bar-stripes 2s linear infinite}.progress-danger .bar,.progress .bar-danger{background-color:#dd514c;background-image:-moz-linear-gradient(top,#ee5f5b,#c43c35);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#c43c35));background-image:-webkit-linear-gradient(top,#ee5f5b,#c43c35);background-image:-o-linear-gradient(top,#ee5f5b,#c43c35);background-image:linear-gradient(to bottom,#ee5f5b,#c43c35);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffee5f5b',endColorstr='#ffc43c35',GradientType=0)}.progress-danger.progress-striped .bar,.progress-striped .bar-danger{background-color:#ee5f5b;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-success .bar,.progress .bar-success{background-color:#5eb95e;background-image:-moz-linear-gradient(top,#62c462,#57a957);background-image:-webkit-gradient(linear,0 0,0 100%,from(#62c462),to(#57a957));background-image:-webkit-linear-gradient(top,#62c462,#57a957);background-image:-o-linear-gradient(top,#62c462,#57a957);background-image:linear-gradient(to bottom,#62c462,#57a957);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff62c462',endColorstr='#ff57a957',GradientType=0)}.progress-success.progress-striped .bar,.progress-striped .bar-success{background-color:#62c462;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-info .bar,.progress .bar-info{background-color:#4bb1cf;background-image:-moz-linear-gradient(top,#5bc0de,#339bb9);background-image:-webkit-gradient(linear,0 0,0 100%,from(#5bc0de),to(#339bb9));background-image:-webkit-linear-gradient(top,#5bc0de,#339bb9);background-image:-o-linear-gradient(top,#5bc0de,#339bb9);background-image:linear-gradient(to bottom,#5bc0de,#339bb9);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de',endColorstr='#ff339bb9',GradientType=0)}.progress-info.progress-striped .bar,.progress-striped .bar-info{background-color:#5bc0de;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-warning .bar,.progress .bar-warning{background-color:#faa732;background-image:-moz-linear-gradient(top,#fbb450,#f89406);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fbb450),to(#f89406));background-image:-webkit-linear-gradient(top,#fbb450,#f89406);background-image:-o-linear-gradient(top,#fbb450,#f89406);background-image:linear-gradient(to bottom,#fbb450,#f89406);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffbb450',endColorstr='#fff89406',GradientType=0)}.progress-warning.progress-striped .bar,.progress-striped .bar-warning{background-color:#fbb450;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.accordion{margin-bottom:20px}.accordion-group{margin-bottom:2px;border:1px solid #e5e5e5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.accordion-heading{border-bottom:0}.accordion-heading .accordion-toggle{display:block;padding:8px 15px}.accordion-toggle{cursor:pointer}.accordion-inner{padding:9px 15px;border-top:1px solid #e5e5e5}.carousel{position:relative;margin-bottom:20px;line-height:1}.carousel-inner{position:relative;width:100%;overflow:hidden}.carousel-inner>.item{position:relative;display:none;-webkit-transition:.6s ease-in-out left;-moz-transition:.6s ease-in-out left;-o-transition:.6s ease-in-out left;transition:.6s ease-in-out left}.carousel-inner>.item>img{display:block;line-height:1}.carousel-inner>.active,.carousel-inner>.next,.carousel-inner>.prev{display:block}.carousel-inner>.active{left:0}.carousel-inner>.next,.carousel-inner>.prev{position:absolute;top:0;width:100%}.carousel-inner>.next{left:100%}.carousel-inner>.prev{left:-100%}.carousel-inner>.next.left,.carousel-inner>.prev.right{left:0}.carousel-inner>.active.left{left:-100%}.carousel-inner>.active.right{left:100%}.carousel-control{position:absolute;top:40%;left:15px;width:40px;height:40px;margin-top:-20px;font-size:60px;font-weight:100;line-height:30px;color:#fff;text-align:center;background:#222;border:3px solid #fff;-webkit-border-radius:23px;-moz-border-radius:23px;border-radius:23px;opacity:.5;filter:alpha(opacity=50)}.carousel-control.right{right:15px;left:auto}.carousel-control:hover{color:#fff;text-decoration:none;opacity:.9;filter:alpha(opacity=90)}.carousel-caption{position:absolute;right:0;bottom:0;left:0;padding:15px;background:#333;background:rgba(0,0,0,0.75)}.carousel-caption h4,.carousel-caption p{line-height:20px;color:#fff}.carousel-caption h4{margin:0 0 5px}.carousel-caption p{margin-bottom:0}.hero-unit{padding:60px;margin-bottom:30px;font-size:18px;font-weight:200;line-height:30px;color:inherit;background-color:#eee;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.hero-unit h1{margin-bottom:0;font-size:60px;line-height:1;letter-spacing:-1px;color:inherit}.hero-unit li{line-height:30px}.pull-right{float:right}.pull-left{float:left}.hide{display:none}.show{display:block}.invisible{visibility:hidden}.affix{position:fixed}
   15.13 +/*!
   15.14 + * Bootstrap Responsive v2.2.2
   15.15 + *
   15.16 + * Copyright 2012 Twitter, Inc
   15.17 + * Licensed under the Apache License v2.0
   15.18 + * http://www.apache.org/licenses/LICENSE-2.0
   15.19 + *
   15.20 + * Designed and built with all the love in the world @twitter by @mdo and @fat.
   15.21 + */@-ms-viewport{width:device-width}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;line-height:0;content:""}.clearfix:after{clear:both}.hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.input-block-level{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.hidden{display:none;visibility:hidden}.visible-phone{display:none!important}.visible-tablet{display:none!important}.hidden-desktop{display:none!important}.visible-desktop{display:inherit!important}@media(min-width:768px) and (max-width:979px){.hidden-desktop{display:inherit!important}.visible-desktop{display:none!important}.visible-tablet{display:inherit!important}.hidden-tablet{display:none!important}}@media(max-width:767px){.hidden-desktop{display:inherit!important}.visible-desktop{display:none!important}.visible-phone{display:inherit!important}.hidden-phone{display:none!important}}@media(min-width:1200px){.row{margin-left:-30px;*zoom:1}.row:before,.row:after{display:table;line-height:0;content:""}.row:after{clear:both}[class*="span"]{float:left;min-height:1px;margin-left:30px}.container,.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:1170px}.span12{width:1170px}.span11{width:1070px}.span10{width:970px}.span9{width:870px}.span8{width:770px}.span7{width:670px}.span6{width:570px}.span5{width:470px}.span4{width:370px}.span3{width:270px}.span2{width:170px}.span1{width:70px}.offset12{margin-left:1230px}.offset11{margin-left:1130px}.offset10{margin-left:1030px}.offset9{margin-left:930px}.offset8{margin-left:830px}.offset7{margin-left:730px}.offset6{margin-left:630px}.offset5{margin-left:530px}.offset4{margin-left:430px}.offset3{margin-left:330px}.offset2{margin-left:230px}.offset1{margin-left:130px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;line-height:0;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:30px;margin-left:2.564102564102564%;*margin-left:2.5109110747408616%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .controls-row [class*="span"]+[class*="span"]{margin-left:2.564102564102564%}.row-fluid .span12{width:100%;*width:99.94680851063829%}.row-fluid .span11{width:91.45299145299145%;*width:91.39979996362975%}.row-fluid .span10{width:82.90598290598291%;*width:82.8527914166212%}.row-fluid .span9{width:74.35897435897436%;*width:74.30578286961266%}.row-fluid .span8{width:65.81196581196582%;*width:65.75877432260411%}.row-fluid .span7{width:57.26495726495726%;*width:57.21176577559556%}.row-fluid .span6{width:48.717948717948715%;*width:48.664757228587014%}.row-fluid .span5{width:40.17094017094017%;*width:40.11774868157847%}.row-fluid .span4{width:31.623931623931625%;*width:31.570740134569924%}.row-fluid .span3{width:23.076923076923077%;*width:23.023731587561375%}.row-fluid .span2{width:14.52991452991453%;*width:14.476723040552828%}.row-fluid .span1{width:5.982905982905983%;*width:5.929714493544281%}.row-fluid .offset12{margin-left:105.12820512820512%;*margin-left:105.02182214948171%}.row-fluid .offset12:first-child{margin-left:102.56410256410257%;*margin-left:102.45771958537915%}.row-fluid .offset11{margin-left:96.58119658119658%;*margin-left:96.47481360247316%}.row-fluid .offset11:first-child{margin-left:94.01709401709402%;*margin-left:93.91071103837061%}.row-fluid .offset10{margin-left:88.03418803418803%;*margin-left:87.92780505546462%}.row-fluid .offset10:first-child{margin-left:85.47008547008548%;*margin-left:85.36370249136206%}.row-fluid .offset9{margin-left:79.48717948717949%;*margin-left:79.38079650845607%}.row-fluid .offset9:first-child{margin-left:76.92307692307693%;*margin-left:76.81669394435352%}.row-fluid .offset8{margin-left:70.94017094017094%;*margin-left:70.83378796144753%}.row-fluid .offset8:first-child{margin-left:68.37606837606839%;*margin-left:68.26968539734497%}.row-fluid .offset7{margin-left:62.393162393162385%;*margin-left:62.28677941443899%}.row-fluid .offset7:first-child{margin-left:59.82905982905982%;*margin-left:59.72267685033642%}.row-fluid .offset6{margin-left:53.84615384615384%;*margin-left:53.739770867430444%}.row-fluid .offset6:first-child{margin-left:51.28205128205128%;*margin-left:51.175668303327875%}.row-fluid .offset5{margin-left:45.299145299145295%;*margin-left:45.1927623204219%}.row-fluid .offset5:first-child{margin-left:42.73504273504273%;*margin-left:42.62865975631933%}.row-fluid .offset4{margin-left:36.75213675213675%;*margin-left:36.645753773413354%}.row-fluid .offset4:first-child{margin-left:34.18803418803419%;*margin-left:34.081651209310785%}.row-fluid .offset3{margin-left:28.205128205128204%;*margin-left:28.0987452264048%}.row-fluid .offset3:first-child{margin-left:25.641025641025642%;*margin-left:25.53464266230224%}.row-fluid .offset2{margin-left:19.65811965811966%;*margin-left:19.551736679396257%}.row-fluid .offset2:first-child{margin-left:17.094017094017094%;*margin-left:16.98763411529369%}.row-fluid .offset1{margin-left:11.11111111111111%;*margin-left:11.004728132387708%}.row-fluid .offset1:first-child{margin-left:8.547008547008547%;*margin-left:8.440625568285142%}input,textarea,.uneditable-input{margin-left:0}.controls-row [class*="span"]+[class*="span"]{margin-left:30px}input.span12,textarea.span12,.uneditable-input.span12{width:1156px}input.span11,textarea.span11,.uneditable-input.span11{width:1056px}input.span10,textarea.span10,.uneditable-input.span10{width:956px}input.span9,textarea.span9,.uneditable-input.span9{width:856px}input.span8,textarea.span8,.uneditable-input.span8{width:756px}input.span7,textarea.span7,.uneditable-input.span7{width:656px}input.span6,textarea.span6,.uneditable-input.span6{width:556px}input.span5,textarea.span5,.uneditable-input.span5{width:456px}input.span4,textarea.span4,.uneditable-input.span4{width:356px}input.span3,textarea.span3,.uneditable-input.span3{width:256px}input.span2,textarea.span2,.uneditable-input.span2{width:156px}input.span1,textarea.span1,.uneditable-input.span1{width:56px}.thumbnails{margin-left:-30px}.thumbnails>li{margin-left:30px}.row-fluid .thumbnails{margin-left:0}}@media(min-width:768px) and (max-width:979px){.row{margin-left:-20px;*zoom:1}.row:before,.row:after{display:table;line-height:0;content:""}.row:after{clear:both}[class*="span"]{float:left;min-height:1px;margin-left:20px}.container,.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:724px}.span12{width:724px}.span11{width:662px}.span10{width:600px}.span9{width:538px}.span8{width:476px}.span7{width:414px}.span6{width:352px}.span5{width:290px}.span4{width:228px}.span3{width:166px}.span2{width:104px}.span1{width:42px}.offset12{margin-left:764px}.offset11{margin-left:702px}.offset10{margin-left:640px}.offset9{margin-left:578px}.offset8{margin-left:516px}.offset7{margin-left:454px}.offset6{margin-left:392px}.offset5{margin-left:330px}.offset4{margin-left:268px}.offset3{margin-left:206px}.offset2{margin-left:144px}.offset1{margin-left:82px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;line-height:0;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:30px;margin-left:2.7624309392265194%;*margin-left:2.709239449864817%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .controls-row [class*="span"]+[class*="span"]{margin-left:2.7624309392265194%}.row-fluid .span12{width:100%;*width:99.94680851063829%}.row-fluid .span11{width:91.43646408839778%;*width:91.38327259903608%}.row-fluid .span10{width:82.87292817679558%;*width:82.81973668743387%}.row-fluid .span9{width:74.30939226519337%;*width:74.25620077583166%}.row-fluid .span8{width:65.74585635359117%;*width:65.69266486422946%}.row-fluid .span7{width:57.18232044198895%;*width:57.12912895262725%}.row-fluid .span6{width:48.61878453038674%;*width:48.56559304102504%}.row-fluid .span5{width:40.05524861878453%;*width:40.00205712942283%}.row-fluid .span4{width:31.491712707182323%;*width:31.43852121782062%}.row-fluid .span3{width:22.92817679558011%;*width:22.87498530621841%}.row-fluid .span2{width:14.3646408839779%;*width:14.311449394616199%}.row-fluid .span1{width:5.801104972375691%;*width:5.747913483013988%}.row-fluid .offset12{margin-left:105.52486187845304%;*margin-left:105.41847889972962%}.row-fluid .offset12:first-child{margin-left:102.76243093922652%;*margin-left:102.6560479605031%}.row-fluid .offset11{margin-left:96.96132596685082%;*margin-left:96.8549429881274%}.row-fluid .offset11:first-child{margin-left:94.1988950276243%;*margin-left:94.09251204890089%}.row-fluid .offset10{margin-left:88.39779005524862%;*margin-left:88.2914070765252%}.row-fluid .offset10:first-child{margin-left:85.6353591160221%;*margin-left:85.52897613729868%}.row-fluid .offset9{margin-left:79.8342541436464%;*margin-left:79.72787116492299%}.row-fluid .offset9:first-child{margin-left:77.07182320441989%;*margin-left:76.96544022569647%}.row-fluid .offset8{margin-left:71.2707182320442%;*margin-left:71.16433525332079%}.row-fluid .offset8:first-child{margin-left:68.50828729281768%;*margin-left:68.40190431409427%}.row-fluid .offset7{margin-left:62.70718232044199%;*margin-left:62.600799341718584%}.row-fluid .offset7:first-child{margin-left:59.94475138121547%;*margin-left:59.838368402492065%}.row-fluid .offset6{margin-left:54.14364640883978%;*margin-left:54.037263430116376%}.row-fluid .offset6:first-child{margin-left:51.38121546961326%;*margin-left:51.27483249088986%}.row-fluid .offset5{margin-left:45.58011049723757%;*margin-left:45.47372751851417%}.row-fluid .offset5:first-child{margin-left:42.81767955801105%;*margin-left:42.71129657928765%}.row-fluid .offset4{margin-left:37.01657458563536%;*margin-left:36.91019160691196%}.row-fluid .offset4:first-child{margin-left:34.25414364640884%;*margin-left:34.14776066768544%}.row-fluid .offset3{margin-left:28.45303867403315%;*margin-left:28.346655695309746%}.row-fluid .offset3:first-child{margin-left:25.69060773480663%;*margin-left:25.584224756083227%}.row-fluid .offset2{margin-left:19.88950276243094%;*margin-left:19.783119783707537%}.row-fluid .offset2:first-child{margin-left:17.12707182320442%;*margin-left:17.02068884448102%}.row-fluid .offset1{margin-left:11.32596685082873%;*margin-left:11.219583872105325%}.row-fluid .offset1:first-child{margin-left:8.56353591160221%;*margin-left:8.457152932878806%}input,textarea,.uneditable-input{margin-left:0}.controls-row [class*="span"]+[class*="span"]{margin-left:20px}input.span12,textarea.span12,.uneditable-input.span12{width:710px}input.span11,textarea.span11,.uneditable-input.span11{width:648px}input.span10,textarea.span10,.uneditable-input.span10{width:586px}input.span9,textarea.span9,.uneditable-input.span9{width:524px}input.span8,textarea.span8,.uneditable-input.span8{width:462px}input.span7,textarea.span7,.uneditable-input.span7{width:400px}input.span6,textarea.span6,.uneditable-input.span6{width:338px}input.span5,textarea.span5,.uneditable-input.span5{width:276px}input.span4,textarea.span4,.uneditable-input.span4{width:214px}input.span3,textarea.span3,.uneditable-input.span3{width:152px}input.span2,textarea.span2,.uneditable-input.span2{width:90px}input.span1,textarea.span1,.uneditable-input.span1{width:28px}}@media(max-width:767px){body{padding-right:20px;padding-left:20px}.navbar-fixed-top,.navbar-fixed-bottom,.navbar-static-top{margin-right:-20px;margin-left:-20px}.container-fluid{padding:0}.dl-horizontal dt{float:none;width:auto;clear:none;text-align:left}.dl-horizontal dd{margin-left:0}.container{width:auto}.row-fluid{width:100%}.row,.thumbnails{margin-left:0}.thumbnails>li{float:none;margin-left:0}[class*="span"],.uneditable-input[class*="span"],.row-fluid [class*="span"]{display:block;float:none;width:100%;margin-left:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.span12,.row-fluid .span12{width:100%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="offset"]:first-child{margin-left:0}.input-large,.input-xlarge,.input-xxlarge,input[class*="span"],select[class*="span"],textarea[class*="span"],.uneditable-input{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.input-prepend input,.input-append input,.input-prepend input[class*="span"],.input-append input[class*="span"]{display:inline-block;width:auto}.controls-row [class*="span"]+[class*="span"]{margin-left:0}.modal{position:fixed;top:20px;right:20px;left:20px;width:auto;margin:0}.modal.fade{top:-100px}.modal.fade.in{top:20px}}@media(max-width:480px){.nav-collapse{-webkit-transform:translate3d(0,0,0)}.page-header h1 small{display:block;line-height:20px}input[type="checkbox"],input[type="radio"]{border:1px solid #ccc}.form-horizontal .control-label{float:none;width:auto;padding-top:0;text-align:left}.form-horizontal .controls{margin-left:0}.form-horizontal .control-list{padding-top:0}.form-horizontal .form-actions{padding-right:10px;padding-left:10px}.media .pull-left,.media .pull-right{display:block;float:none;margin-bottom:10px}.media-object{margin-right:0;margin-left:0}.modal{top:10px;right:10px;left:10px}.modal-header .close{padding:10px;margin:-10px}.carousel-caption{position:static}}@media(max-width:979px){body{padding-top:0}.navbar-fixed-top,.navbar-fixed-bottom{position:static}.navbar-fixed-top{margin-bottom:20px}.navbar-fixed-bottom{margin-top:20px}.navbar-fixed-top .navbar-inner,.navbar-fixed-bottom .navbar-inner{padding:5px}.navbar .container{width:auto;padding:0}.navbar .brand{padding-right:10px;padding-left:10px;margin:0 0 0 -5px}.nav-collapse{clear:both}.nav-collapse .nav{float:none;margin:0 0 10px}.nav-collapse .nav>li{float:none}.nav-collapse .nav>li>a{margin-bottom:2px}.nav-collapse .nav>.divider-vertical{display:none}.nav-collapse .nav .nav-header{color:#777;text-shadow:none}.nav-collapse .nav>li>a,.nav-collapse .dropdown-menu a{padding:9px 15px;font-weight:bold;color:#777;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.nav-collapse .btn{padding:4px 10px 4px;font-weight:normal;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.nav-collapse .dropdown-menu li+li a{margin-bottom:2px}.nav-collapse .nav>li>a:hover,.nav-collapse .dropdown-menu a:hover{background-color:#f2f2f2}.navbar-inverse .nav-collapse .nav>li>a,.navbar-inverse .nav-collapse .dropdown-menu a{color:#999}.navbar-inverse .nav-collapse .nav>li>a:hover,.navbar-inverse .nav-collapse .dropdown-menu a:hover{background-color:#111}.nav-collapse.in .btn-group{padding:0;margin-top:5px}.nav-collapse .dropdown-menu{position:static;top:auto;left:auto;display:none;float:none;max-width:none;padding:0;margin:0 15px;background-color:transparent;border:0;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.nav-collapse .open>.dropdown-menu{display:block}.nav-collapse .dropdown-menu:before,.nav-collapse .dropdown-menu:after{display:none}.nav-collapse .dropdown-menu .divider{display:none}.nav-collapse .nav>li>.dropdown-menu:before,.nav-collapse .nav>li>.dropdown-menu:after{display:none}.nav-collapse .navbar-form,.nav-collapse .navbar-search{float:none;padding:10px 15px;margin:10px 0;border-top:1px solid #f2f2f2;border-bottom:1px solid #f2f2f2;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1);box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1)}.navbar-inverse .nav-collapse .navbar-form,.navbar-inverse .nav-collapse .navbar-search{border-top-color:#111;border-bottom-color:#111}.navbar .nav-collapse .nav.pull-right{float:none;margin-left:0}.nav-collapse,.nav-collapse.collapse{height:0;overflow:hidden}.navbar .btn-navbar{display:block}.navbar-static .navbar-inner{padding-right:10px;padding-left:10px}}@media(min-width:980px){.nav-collapse.collapse{height:auto!important;overflow:visible!important}}
    16.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/error.png has changed
    17.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/glyphicons-halflings-white.png has changed
    18.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/glyphicons-halflings.png has changed
    19.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/html5.png has changed
    20.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/java.png has changed
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/index.html	Sun Feb 03 07:48:42 2013 +0100
    21.3 @@ -0,0 +1,98 @@
    21.4 +<!--
    21.5 +To change this template, choose Tools | Templates
    21.6 +and open the template in the editor.
    21.7 +-->
    21.8 +<!DOCTYPE html>
    21.9 +<html lang="en" ng-app="bck2brwsr" ng-controller="DevCtrl">
   21.10 +    <head>
   21.11 +        <title>Back2Browser - DEW</title>
   21.12 +        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   21.13 +        <meta name="viewport" content="width=device-width, initial-scale=1.0">
   21.14 +        <link rel="stylesheet" href="css/bootstrap-combined.min.css"/>  
   21.15 +        <link rel="stylesheet" href="js/codemirror/codemirror.css">
   21.16 +        <link rel="stylesheet" href="js/codemirror/theme/elegant.css"/>
   21.17 +        <link rel="stylesheet" href="css/app.css"/>
   21.18 +    </head>
   21.19 +    <body>
   21.20 +                
   21.21 +        <div class="navbar navbar-fixed-top" style="width: 100%"> 
   21.22 +        <div class="navbar-inner" style="padding-left: 12px; padding-right: 12px;">
   21.23 +            <!-- a class="brand" style="font-size: 100%"><span class="text-info"><b>Java and HTML5</b></span><small>- Together at Last!</small></a-->
   21.24 +            <form class="navbar-form pull-right">
   21.25 +                <!-- select class="span2"></select -->
   21.26 +                <button ng-click="post()" class="btn btn-warning">Rebuild</button>
   21.27 +              </form>
   21.28 +            <!-- ul class="nav">                          
   21.29 +                <li><select class="btn-small" type="text"></select></li>
   21.30 +            </ul -->
   21.31 +            <!-- form class="form form-horizontal pull-right">
   21.32 +                <button class="btn btn-warning btn-small pull-right top" ng-click="post()">Rebuild</button>
   21.33 +            </form -->
   21.34 +            <!-- ul class="nav pull-right">
   21.35 +                
   21.36 +            </ul-->     
   21.37 +        </div>  
   21.38 +        </div>
   21.39 +
   21.40 +        <div class="container-fluid">        
   21.41 +        
   21.42 +        <div style="height: 4em;">&nbsp;</div>    
   21.43 +            
   21.44 +        <div class="row-fluid">
   21.45 +            <div class="span6" style="margin-bottom: 10px;"> 
   21.46 +                <table class="table table-condensed" style="margin-bottom: 2px">
   21.47 +                <tr><td><i class="ic-html5"></i> HTML5</td></tr>               
   21.48 +                </table>
   21.49 +                <div>
   21.50 +                    <textarea ui-codemirror='{ lineNumbers : true, mode : "xml", theme : "elegant", matchBrackets : true, lineWrapping : true }' ng-model="html"></textarea>
   21.51 +                    <div class="alert alert-error" ng-show="doc.modelError">
   21.52 +                        <small>{{doc.modelError.toString()}}</small>
   21.53 +                    </div>
   21.54 +                </div>    
   21.55 +            </div>
   21.56 +            
   21.57 +            <div class="span6">  
   21.58 +                <table class="table table-condensed" style="margin-bottom: 2px">
   21.59 +                <tr><td><i class="ic-java"></i> Java</td></tr>               
   21.60 +                </table>                
   21.61 +                <div>
   21.62 +                    <textarea id="editorJava" ui-codemirror='{ lineNumbers : true, mode : "text/x-java", theme : "elegant", matchBrackets : true, lineWrapping : true, gutters: ["CodeMirror-linenumbers", "issues"] }' ng-model="java"></textarea>
   21.63 +                    <div class="alert alert-error" ng-show="doc.modelError">
   21.64 +                        <small>{{doc.modelError.toString()}}</small>
   21.65 +                    </div>
   21.66 +                </div>
   21.67 +            </div>
   21.68 +        
   21.69 +        </div>    
   21.70 +            
   21.71 +        <table class="table table-condensed">
   21.72 +            <tr ng-click="gotoError(e.line, e.col)" ng-repeat="e in errors" ng-class="errorClass(e.kind)">
   21.73 +                <td style="text-align: right">{{e.line}}</td> 
   21.74 +                <td>:</td> 
   21.75 +                <td style="text-align: left">{{e.col}}</td> 
   21.76 +                <td width="100%" class="text-error error-hover">{{e.msg}} <i class="icon-play"/></td>
   21.77 +            </tr>            
   21.78 +        </table>    
   21.79 +            
   21.80 +        
   21.81 +        <div>&nbsp;</div>    
   21.82 +            
   21.83 +        <ul class="nav nav-tabs">
   21.84 +            <li ng-class="'active'"><a href="#">Result</a></li>
   21.85 +        </ul>    
   21.86 +        
   21.87 +        
   21.88 +        <!-- button class="btn" ng-click="reload()">Reload</button -->
   21.89 +        <iframe id="result" frameborder="0" scrolling="yes" width="100%" style="height: 1000px; overflow: auto; border: 1px solid #DFDFDF;" src="result.html">
   21.90 +            <p>Your browser does not support iframes.</p>
   21.91 +        </iframe>
   21.92 +            
   21.93 +        </div>
   21.94 +        
   21.95 +        <script src="js/angular/angular.min.js"></script>
   21.96 +        <script src="js/codemirror/codemirror.js"></script>
   21.97 +        <script src="js/codemirror/mode/xml.js"></script>
   21.98 +        <script src="js/codemirror/mode/clike.js"></script>
   21.99 +        <script src="js/app.js"></script>
  21.100 +    </body>
  21.101 +</html>
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/angular/angular.min.js	Sun Feb 03 07:48:42 2013 +0100
    22.3 @@ -0,0 +1,159 @@
    22.4 +/*
    22.5 + AngularJS v1.0.3
    22.6 + (c) 2010-2012 Google, Inc. http://angularjs.org
    22.7 + License: MIT
    22.8 +*/
    22.9 +(function(U,ca,p){'use strict';function m(b,a,c){var d;if(b)if(N(b))for(d in b)d!="prototype"&&d!="length"&&d!="name"&&b.hasOwnProperty(d)&&a.call(c,b[d],d);else if(b.forEach&&b.forEach!==m)b.forEach(a,c);else if(L(b)&&wa(b.length))for(d=0;d<b.length;d++)a.call(c,b[d],d);else for(d in b)b.hasOwnProperty(d)&&a.call(c,b[d],d);return b}function lb(b){var a=[],c;for(c in b)b.hasOwnProperty(c)&&a.push(c);return a.sort()}function ec(b,a,c){for(var d=lb(b),e=0;e<d.length;e++)a.call(c,b[d[e]],d[e]);return d}
   22.10 +function mb(b){return function(a,c){b(c,a)}}function xa(){for(var b=Z.length,a;b;){b--;a=Z[b].charCodeAt(0);if(a==57)return Z[b]="A",Z.join("");if(a==90)Z[b]="0";else return Z[b]=String.fromCharCode(a+1),Z.join("")}Z.unshift("0");return Z.join("")}function x(b){m(arguments,function(a){a!==b&&m(a,function(a,d){b[d]=a})});return b}function G(b){return parseInt(b,10)}function ya(b,a){return x(new (x(function(){},{prototype:b})),a)}function D(){}function ma(b){return b}function I(b){return function(){return b}}
   22.11 +function t(b){return typeof b=="undefined"}function v(b){return typeof b!="undefined"}function L(b){return b!=null&&typeof b=="object"}function F(b){return typeof b=="string"}function wa(b){return typeof b=="number"}function na(b){return Sa.apply(b)=="[object Date]"}function J(b){return Sa.apply(b)=="[object Array]"}function N(b){return typeof b=="function"}function oa(b){return b&&b.document&&b.location&&b.alert&&b.setInterval}function R(b){return F(b)?b.replace(/^\s*/,"").replace(/\s*$/,""):b}function fc(b){return b&&
   22.12 +(b.nodeName||b.bind&&b.find)}function Ta(b,a,c){var d=[];m(b,function(b,g,i){d.push(a.call(c,b,g,i))});return d}function gc(b,a){var c=0,d;if(J(b)||F(b))return b.length;else if(L(b))for(d in b)(!a||b.hasOwnProperty(d))&&c++;return c}function za(b,a){if(b.indexOf)return b.indexOf(a);for(var c=0;c<b.length;c++)if(a===b[c])return c;return-1}function Ua(b,a){var c=za(b,a);c>=0&&b.splice(c,1);return a}function V(b,a){if(oa(b)||b&&b.$evalAsync&&b.$watch)throw B("Can't copy Window or Scope");if(a){if(b===
   22.13 +a)throw B("Can't copy equivalent objects or arrays");if(J(b)){for(;a.length;)a.pop();for(var c=0;c<b.length;c++)a.push(V(b[c]))}else for(c in m(a,function(b,c){delete a[c]}),b)a[c]=V(b[c])}else(a=b)&&(J(b)?a=V(b,[]):na(b)?a=new Date(b.getTime()):L(b)&&(a=V(b,{})));return a}function hc(b,a){var a=a||{},c;for(c in b)b.hasOwnProperty(c)&&c.substr(0,2)!=="$$"&&(a[c]=b[c]);return a}function ha(b,a){if(b===a)return!0;if(b===null||a===null)return!1;if(b!==b&&a!==a)return!0;var c=typeof b,d;if(c==typeof a&&
   22.14 +c=="object")if(J(b)){if((c=b.length)==a.length){for(d=0;d<c;d++)if(!ha(b[d],a[d]))return!1;return!0}}else if(na(b))return na(a)&&b.getTime()==a.getTime();else{if(b&&b.$evalAsync&&b.$watch||a&&a.$evalAsync&&a.$watch||oa(b)||oa(a))return!1;c={};for(d in b){if(d.charAt(0)!=="$"&&!N(b[d])&&!ha(b[d],a[d]))return!1;c[d]=!0}for(d in a)if(!c[d]&&d.charAt(0)!=="$"&&!N(a[d]))return!1;return!0}return!1}function Va(b,a){var c=arguments.length>2?ia.call(arguments,2):[];return N(a)&&!(a instanceof RegExp)?c.length?
   22.15 +function(){return arguments.length?a.apply(b,c.concat(ia.call(arguments,0))):a.apply(b,c)}:function(){return arguments.length?a.apply(b,arguments):a.call(b)}:a}function ic(b,a){var c=a;/^\$+/.test(b)?c=p:oa(a)?c="$WINDOW":a&&ca===a?c="$DOCUMENT":a&&a.$evalAsync&&a.$watch&&(c="$SCOPE");return c}function da(b,a){return JSON.stringify(b,ic,a?"  ":null)}function nb(b){return F(b)?JSON.parse(b):b}function Wa(b){b&&b.length!==0?(b=E(""+b),b=!(b=="f"||b=="0"||b=="false"||b=="no"||b=="n"||b=="[]")):b=!1;
   22.16 +return b}function pa(b){b=u(b).clone();try{b.html("")}catch(a){}return u("<div>").append(b).html().match(/^(<[^>]+>)/)[1].replace(/^<([\w\-]+)/,function(a,b){return"<"+E(b)})}function Xa(b){var a={},c,d;m((b||"").split("&"),function(b){b&&(c=b.split("="),d=decodeURIComponent(c[0]),a[d]=v(c[1])?decodeURIComponent(c[1]):!0)});return a}function ob(b){var a=[];m(b,function(b,d){a.push(Ya(d,!0)+(b===!0?"":"="+Ya(b,!0)))});return a.length?a.join("&"):""}function Za(b){return Ya(b,!0).replace(/%26/gi,"&").replace(/%3D/gi,
   22.17 +"=").replace(/%2B/gi,"+")}function Ya(b,a){return encodeURIComponent(b).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(a?null:/%20/g,"+")}function jc(b,a){function c(a){a&&d.push(a)}var d=[b],e,g,i=["ng:app","ng-app","x-ng-app","data-ng-app"],f=/\sng[:\-]app(:\s*([\w\d_]+);?)?\s/;m(i,function(a){i[a]=!0;c(ca.getElementById(a));a=a.replace(":","\\:");b.querySelectorAll&&(m(b.querySelectorAll("."+a),c),m(b.querySelectorAll("."+a+"\\:"),c),m(b.querySelectorAll("["+
   22.18 +a+"]"),c))});m(d,function(a){if(!e){var b=f.exec(" "+a.className+" ");b?(e=a,g=(b[2]||"").replace(/\s+/g,",")):m(a.attributes,function(b){if(!e&&i[b.name])e=a,g=b.value})}});e&&a(e,g?[g]:[])}function pb(b,a){b=u(b);a=a||[];a.unshift(["$provide",function(a){a.value("$rootElement",b)}]);a.unshift("ng");var c=qb(a);c.invoke(["$rootScope","$rootElement","$compile","$injector",function(a,b,c,i){a.$apply(function(){b.data("$injector",i);c(b)(a)})}]);return c}function $a(b,a){a=a||"_";return b.replace(kc,
   22.19 +function(b,d){return(d?a:"")+b.toLowerCase()})}function qa(b,a,c){if(!b)throw new B("Argument '"+(a||"?")+"' is "+(c||"required"));return b}function ra(b,a,c){c&&J(b)&&(b=b[b.length-1]);qa(N(b),a,"not a function, got "+(b&&typeof b=="object"?b.constructor.name||"Object":typeof b));return b}function lc(b){function a(a,b,e){return a[b]||(a[b]=e())}return a(a(b,"angular",Object),"module",function(){var b={};return function(d,e,g){e&&b.hasOwnProperty(d)&&(b[d]=null);return a(b,d,function(){function a(c,
   22.20 +d,e){return function(){b[e||"push"]([c,d,arguments]);return j}}if(!e)throw B("No module: "+d);var b=[],c=[],k=a("$injector","invoke"),j={_invokeQueue:b,_runBlocks:c,requires:e,name:d,provider:a("$provide","provider"),factory:a("$provide","factory"),service:a("$provide","service"),value:a("$provide","value"),constant:a("$provide","constant","unshift"),filter:a("$filterProvider","register"),controller:a("$controllerProvider","register"),directive:a("$compileProvider","directive"),config:k,run:function(a){c.push(a);
   22.21 +return this}};g&&k(g);return j})}})}function rb(b){return b.replace(mc,function(a,b,d,e){return e?d.toUpperCase():d}).replace(nc,"Moz$1")}function ab(b,a){function c(){var e;for(var b=[this],c=a,i,f,h,k,j,l;b.length;){i=b.shift();f=0;for(h=i.length;f<h;f++){k=u(i[f]);c?k.triggerHandler("$destroy"):c=!c;j=0;for(e=(l=k.children()).length,k=e;j<k;j++)b.push(ja(l[j]))}}return d.apply(this,arguments)}var d=ja.fn[b],d=d.$original||d;c.$original=d;ja.fn[b]=c}function Q(b){if(b instanceof Q)return b;if(!(this instanceof
   22.22 +Q)){if(F(b)&&b.charAt(0)!="<")throw B("selectors not implemented");return new Q(b)}if(F(b)){var a=ca.createElement("div");a.innerHTML="<div>&#160;</div>"+b;a.removeChild(a.firstChild);bb(this,a.childNodes);this.remove()}else bb(this,b)}function cb(b){return b.cloneNode(!0)}function sa(b){sb(b);for(var a=0,b=b.childNodes||[];a<b.length;a++)sa(b[a])}function tb(b,a,c){var d=$(b,"events");$(b,"handle")&&(t(a)?m(d,function(a,c){db(b,c,a);delete d[c]}):t(c)?(db(b,a,d[a]),delete d[a]):Ua(d[a],c))}function sb(b){var a=
   22.23 +b[Aa],c=Ba[a];c&&(c.handle&&(c.events.$destroy&&c.handle({},"$destroy"),tb(b)),delete Ba[a],b[Aa]=p)}function $(b,a,c){var d=b[Aa],d=Ba[d||-1];if(v(c))d||(b[Aa]=d=++oc,d=Ba[d]={}),d[a]=c;else return d&&d[a]}function ub(b,a,c){var d=$(b,"data"),e=v(c),g=!e&&v(a),i=g&&!L(a);!d&&!i&&$(b,"data",d={});if(e)d[a]=c;else if(g)if(i)return d&&d[a];else x(d,a);else return d}function Ca(b,a){return(" "+b.className+" ").replace(/[\n\t]/g," ").indexOf(" "+a+" ")>-1}function vb(b,a){a&&m(a.split(" "),function(a){b.className=
   22.24 +R((" "+b.className+" ").replace(/[\n\t]/g," ").replace(" "+R(a)+" "," "))})}function wb(b,a){a&&m(a.split(" "),function(a){if(!Ca(b,a))b.className=R(b.className+" "+R(a))})}function bb(b,a){if(a)for(var a=!a.nodeName&&v(a.length)&&!oa(a)?a:[a],c=0;c<a.length;c++)b.push(a[c])}function xb(b,a){return Da(b,"$"+(a||"ngController")+"Controller")}function Da(b,a,c){b=u(b);for(b[0].nodeType==9&&(b=b.find("html"));b.length;){if(c=b.data(a))return c;b=b.parent()}}function yb(b,a){var c=Ea[a.toLowerCase()];
   22.25 +return c&&zb[b.nodeName]&&c}function pc(b,a){var c=function(c,e){if(!c.preventDefault)c.preventDefault=function(){c.returnValue=!1};if(!c.stopPropagation)c.stopPropagation=function(){c.cancelBubble=!0};if(!c.target)c.target=c.srcElement||ca;if(t(c.defaultPrevented)){var g=c.preventDefault;c.preventDefault=function(){c.defaultPrevented=!0;g.call(c)};c.defaultPrevented=!1}c.isDefaultPrevented=function(){return c.defaultPrevented};m(a[e||c.type],function(a){a.call(b,c)});aa<=8?(c.preventDefault=null,
   22.26 +c.stopPropagation=null,c.isDefaultPrevented=null):(delete c.preventDefault,delete c.stopPropagation,delete c.isDefaultPrevented)};c.elem=b;return c}function ga(b){var a=typeof b,c;if(a=="object"&&b!==null)if(typeof(c=b.$$hashKey)=="function")c=b.$$hashKey();else{if(c===p)c=b.$$hashKey=xa()}else c=b;return a+":"+c}function Fa(b){m(b,this.put,this)}function eb(){}function Ab(b){var a,c;if(typeof b=="function"){if(!(a=b.$inject))a=[],c=b.toString().replace(qc,""),c=c.match(rc),m(c[1].split(sc),function(b){b.replace(tc,
   22.27 +function(b,c,d){a.push(d)})}),b.$inject=a}else J(b)?(c=b.length-1,ra(b[c],"fn"),a=b.slice(0,c)):ra(b,"fn",!0);return a}function qb(b){function a(a){return function(b,c){if(L(b))m(b,mb(a));else return a(b,c)}}function c(a,b){N(b)&&(b=l.instantiate(b));if(!b.$get)throw B("Provider "+a+" must define $get factory method.");return j[a+f]=b}function d(a,b){return c(a,{$get:b})}function e(a){var b=[];m(a,function(a){if(!k.get(a))if(k.put(a,!0),F(a)){var c=ta(a);b=b.concat(e(c.requires)).concat(c._runBlocks);
   22.28 +try{for(var d=c._invokeQueue,c=0,f=d.length;c<f;c++){var h=d[c],g=h[0]=="$injector"?l:l.get(h[0]);g[h[1]].apply(g,h[2])}}catch(n){throw n.message&&(n.message+=" from "+a),n;}}else if(N(a))try{b.push(l.invoke(a))}catch(i){throw i.message&&(i.message+=" from "+a),i;}else if(J(a))try{b.push(l.invoke(a))}catch(j){throw j.message&&(j.message+=" from "+String(a[a.length-1])),j;}else ra(a,"module")});return b}function g(a,b){function c(d){if(typeof d!=="string")throw B("Service name expected");if(a.hasOwnProperty(d)){if(a[d]===
   22.29 +i)throw B("Circular dependency: "+h.join(" <- "));return a[d]}else try{return h.unshift(d),a[d]=i,a[d]=b(d)}finally{h.shift()}}function d(a,b,e){var f=[],k=Ab(a),g,n,i;n=0;for(g=k.length;n<g;n++)i=k[n],f.push(e&&e.hasOwnProperty(i)?e[i]:c(i,h));a.$inject||(a=a[g]);switch(b?-1:f.length){case 0:return a();case 1:return a(f[0]);case 2:return a(f[0],f[1]);case 3:return a(f[0],f[1],f[2]);case 4:return a(f[0],f[1],f[2],f[3]);case 5:return a(f[0],f[1],f[2],f[3],f[4]);case 6:return a(f[0],f[1],f[2],f[3],
   22.30 +f[4],f[5]);case 7:return a(f[0],f[1],f[2],f[3],f[4],f[5],f[6]);case 8:return a(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7]);case 9:return a(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8]);case 10:return a(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8],f[9]);default:return a.apply(b,f)}}return{invoke:d,instantiate:function(a,b){var c=function(){},e;c.prototype=(J(a)?a[a.length-1]:a).prototype;c=new c;e=d(a,c,b);return L(e)?e:c},get:c,annotate:Ab}}var i={},f="Provider",h=[],k=new Fa,j={$provide:{provider:a(c),
   22.31 +factory:a(d),service:a(function(a,b){return d(a,["$injector",function(a){return a.instantiate(b)}])}),value:a(function(a,b){return d(a,I(b))}),constant:a(function(a,b){j[a]=b;o[a]=b}),decorator:function(a,b){var c=l.get(a+f),d=c.$get;c.$get=function(){var a=r.invoke(d,c);return r.invoke(b,null,{$delegate:a})}}}},l=g(j,function(){throw B("Unknown provider: "+h.join(" <- "));}),o={},r=o.$injector=g(o,function(a){a=l.get(a+f);return r.invoke(a.$get,a)});m(e(b),function(a){r.invoke(a||D)});return r}function uc(){var b=
   22.32 +!0;this.disableAutoScrolling=function(){b=!1};this.$get=["$window","$location","$rootScope",function(a,c,d){function e(a){var b=null;m(a,function(a){!b&&E(a.nodeName)==="a"&&(b=a)});return b}function g(){var b=c.hash(),d;b?(d=i.getElementById(b))?d.scrollIntoView():(d=e(i.getElementsByName(b)))?d.scrollIntoView():b==="top"&&a.scrollTo(0,0):a.scrollTo(0,0)}var i=a.document;b&&d.$watch(function(){return c.hash()},function(){d.$evalAsync(g)});return g}]}function vc(b,a,c,d){function e(a){try{a.apply(null,
   22.33 +ia.call(arguments,1))}finally{if(n--,n===0)for(;w.length;)try{w.pop()()}catch(b){c.error(b)}}}function g(a,b){(function ea(){m(q,function(a){a()});s=b(ea,a)})()}function i(){O!=f.url()&&(O=f.url(),m(A,function(a){a(f.url())}))}var f=this,h=a[0],k=b.location,j=b.history,l=b.setTimeout,o=b.clearTimeout,r={};f.isMock=!1;var n=0,w=[];f.$$completeOutstandingRequest=e;f.$$incOutstandingRequestCount=function(){n++};f.notifyWhenNoOutstandingRequests=function(a){m(q,function(a){a()});n===0?a():w.push(a)};
   22.34 +var q=[],s;f.addPollFn=function(a){t(s)&&g(100,l);q.push(a);return a};var O=k.href,C=a.find("base");f.url=function(a,b){if(a){if(O!=a)return O=a,d.history?b?j.replaceState(null,"",a):(j.pushState(null,"",a),C.attr("href",C.attr("href"))):b?k.replace(a):k.href=a,f}else return k.href.replace(/%27/g,"'")};var A=[],K=!1;f.onUrlChange=function(a){K||(d.history&&u(b).bind("popstate",i),d.hashchange?u(b).bind("hashchange",i):f.addPollFn(i),K=!0);A.push(a);return a};f.baseHref=function(){var a=C.attr("href");
   22.35 +return a?a.replace(/^https?\:\/\/[^\/]*/,""):a};var W={},y="",M=f.baseHref();f.cookies=function(a,b){var d,e,f,k;if(a)if(b===p)h.cookie=escape(a)+"=;path="+M+";expires=Thu, 01 Jan 1970 00:00:00 GMT";else{if(F(b))d=(h.cookie=escape(a)+"="+escape(b)+";path="+M).length+1,d>4096&&c.warn("Cookie '"+a+"' possibly not set or overflowed because it was too large ("+d+" > 4096 bytes)!"),W.length>20&&c.warn("Cookie '"+a+"' possibly not set or overflowed because too many cookies were already set ("+W.length+
   22.36 +" > 20 )")}else{if(h.cookie!==y){y=h.cookie;d=y.split("; ");W={};for(f=0;f<d.length;f++)e=d[f],k=e.indexOf("="),k>0&&(W[unescape(e.substring(0,k))]=unescape(e.substring(k+1)))}return W}};f.defer=function(a,b){var c;n++;c=l(function(){delete r[c];e(a)},b||0);r[c]=!0;return c};f.defer.cancel=function(a){return r[a]?(delete r[a],o(a),e(D),!0):!1}}function wc(){this.$get=["$window","$log","$sniffer","$document",function(b,a,c,d){return new vc(b,d,a,c)}]}function xc(){this.$get=function(){function b(b,
   22.37 +d){function e(a){if(a!=l){if(o){if(o==a)o=a.n}else o=a;g(a.n,a.p);g(a,l);l=a;l.n=null}}function g(a,b){if(a!=b){if(a)a.p=b;if(b)b.n=a}}if(b in a)throw B("cacheId "+b+" taken");var i=0,f=x({},d,{id:b}),h={},k=d&&d.capacity||Number.MAX_VALUE,j={},l=null,o=null;return a[b]={put:function(a,b){var c=j[a]||(j[a]={key:a});e(c);t(b)||(a in h||i++,h[a]=b,i>k&&this.remove(o.key))},get:function(a){var b=j[a];if(b)return e(b),h[a]},remove:function(a){var b=j[a];if(b){if(b==l)l=b.p;if(b==o)o=b.n;g(b.n,b.p);delete j[a];
   22.38 +delete h[a];i--}},removeAll:function(){h={};i=0;j={};l=o=null},destroy:function(){j=f=h=null;delete a[b]},info:function(){return x({},f,{size:i})}}}var a={};b.info=function(){var b={};m(a,function(a,e){b[e]=a.info()});return b};b.get=function(b){return a[b]};return b}}function yc(){this.$get=["$cacheFactory",function(b){return b("templates")}]}function Bb(b){var a={},c="Directive",d=/^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/,e=/(([\d\w\-_]+)(?:\:([^;]+))?;?)/,g="Template must have exactly one root element. was: ";
   22.39 +this.directive=function f(d,e){F(d)?(qa(e,"directive"),a.hasOwnProperty(d)||(a[d]=[],b.factory(d+c,["$injector","$exceptionHandler",function(b,c){var e=[];m(a[d],function(a){try{var f=b.invoke(a);if(N(f))f={compile:I(f)};else if(!f.compile&&f.link)f.compile=I(f.link);f.priority=f.priority||0;f.name=f.name||d;f.require=f.require||f.controller&&f.name;f.restrict=f.restrict||"A";e.push(f)}catch(k){c(k)}});return e}])),a[d].push(e)):m(d,mb(f));return this};this.$get=["$injector","$interpolate","$exceptionHandler",
   22.40 +"$http","$templateCache","$parse","$controller","$rootScope",function(b,h,k,j,l,o,r,n){function w(a,b,c){a instanceof u||(a=u(a));m(a,function(b,c){b.nodeType==3&&(a[c]=u(b).wrap("<span></span>").parent()[0])});var d=s(a,b,a,c);return function(b,c){qa(b,"scope");var e=c?ua.clone.call(a):a;e.data("$scope",b);q(e,"ng-scope");c&&c(e,b);d&&d(b,e,e);return e}}function q(a,b){try{a.addClass(b)}catch(c){}}function s(a,b,c,d){function e(a,c,d,k){for(var g,h,j,n,o,l=0,r=0,q=f.length;l<q;r++)j=c[r],g=f[l++],
   22.41 +h=f[l++],g?(g.scope?(n=a.$new(L(g.scope)),u(j).data("$scope",n)):n=a,(o=g.transclude)||!k&&b?g(h,n,j,d,function(b){return function(c){var d=a.$new();return b(d,c).bind("$destroy",Va(d,d.$destroy))}}(o||b)):g(h,n,j,p,k)):h&&h(a,j.childNodes,p,k)}for(var f=[],k,g,h,j=0;j<a.length;j++)g=new ea,k=O(a[j],[],g,d),g=(k=k.length?C(k,a[j],g,b,c):null)&&k.terminal||!a[j].childNodes.length?null:s(a[j].childNodes,k?k.transclude:b),f.push(k),f.push(g),h=h||k||g;return h?e:null}function O(a,b,c,f){var k=c.$attr,
   22.42 +g;switch(a.nodeType){case 1:A(b,fa(Cb(a).toLowerCase()),"E",f);var h,j,n;g=a.attributes;for(var o=0,l=g&&g.length;o<l;o++)if(h=g[o],h.specified)j=h.name,n=fa(j.toLowerCase()),k[n]=j,c[n]=h=R(aa&&j=="href"?decodeURIComponent(a.getAttribute(j,2)):h.value),yb(a,n)&&(c[n]=!0),X(a,b,h,n),A(b,n,"A",f);a=a.className;if(F(a)&&a!=="")for(;g=e.exec(a);)n=fa(g[2]),A(b,n,"C",f)&&(c[n]=R(g[3])),a=a.substr(g.index+g[0].length);break;case 3:H(b,a.nodeValue);break;case 8:try{if(g=d.exec(a.nodeValue))n=fa(g[1]),A(b,
   22.43 +n,"M",f)&&(c[n]=R(g[2]))}catch(r){}}b.sort(y);return b}function C(a,b,c,d,e){function f(a,b){if(a)a.require=z.require,l.push(a);if(b)b.require=z.require,ba.push(b)}function h(a,b){var c,d="data",e=!1;if(F(a)){for(;(c=a.charAt(0))=="^"||c=="?";)a=a.substr(1),c=="^"&&(d="inheritedData"),e=e||c=="?";c=b[d]("$"+a+"Controller");if(!c&&!e)throw B("No controller: "+a);}else J(a)&&(c=[],m(a,function(a){c.push(h(a,b))}));return c}function j(a,d,e,f,g){var n,q,w,K,s;n=b===e?c:hc(c,new ea(u(e),c.$attr));q=n.$$element;
   22.44 +if(C){var zc=/^\s*([@=&])\s*(\w*)\s*$/,O=d.$parent||d;m(C.scope,function(a,b){var c=a.match(zc)||[],e=c[2]||b,f,g,k;switch(c[1]){case "@":n.$observe(e,function(a){d[b]=a});n.$$observers[e].$$scope=O;break;case "=":g=o(n[e]);k=g.assign||function(){f=d[b]=g(O);throw B(Db+n[e]+" (directive: "+C.name+")");};f=d[b]=g(O);d.$watch(function(){var a=g(O);a!==d[b]&&(a!==f?f=d[b]=a:k(O,a=f=d[b]));return a});break;case "&":g=o(n[e]);d[b]=function(a){return g(O,a)};break;default:throw B("Invalid isolate scope definition for directive "+
   22.45 +C.name+": "+a);}})}t&&m(t,function(a){var b={$scope:d,$element:q,$attrs:n,$transclude:g};s=a.controller;s=="@"&&(s=n[a.name]);q.data("$"+a.name+"Controller",r(s,b))});f=0;for(w=l.length;f<w;f++)try{K=l[f],K(d,q,n,K.require&&h(K.require,q))}catch(y){k(y,pa(q))}a&&a(d,e.childNodes,p,g);f=0;for(w=ba.length;f<w;f++)try{K=ba[f],K(d,q,n,K.require&&h(K.require,q))}catch(Ha){k(Ha,pa(q))}}for(var n=-Number.MAX_VALUE,l=[],ba=[],s=null,C=null,A=null,y=c.$$element=u(b),z,H,X,D,v=d,t,x,Y,E=0,G=a.length;E<G;E++){z=
   22.46 +a[E];X=p;if(n>z.priority)break;if(Y=z.scope)M("isolated scope",C,z,y),L(Y)&&(q(y,"ng-isolate-scope"),C=z),q(y,"ng-scope"),s=s||z;H=z.name;if(Y=z.controller)t=t||{},M("'"+H+"' controller",t[H],z,y),t[H]=z;if(Y=z.transclude)M("transclusion",D,z,y),D=z,n=z.priority,Y=="element"?(X=u(b),y=c.$$element=u("<\!-- "+H+": "+c[H]+" --\>"),b=y[0],Ga(e,u(X[0]),b),v=w(X,d,n)):(X=u(cb(b)).contents(),y.html(""),v=w(X,d));if(Y=z.template)if(M("template",A,z,y),A=z,Y=Ha(Y),z.replace){X=u("<div>"+R(Y)+"</div>").contents();
   22.47 +b=X[0];if(X.length!=1||b.nodeType!==1)throw new B(g+Y);Ga(e,y,b);H={$attr:{}};a=a.concat(O(b,a.splice(E+1,a.length-(E+1)),H));K(c,H);G=a.length}else y.html(Y);if(z.templateUrl)M("template",A,z,y),A=z,j=W(a.splice(E,a.length-E),j,y,c,e,z.replace,v),G=a.length;else if(z.compile)try{x=z.compile(y,c,v),N(x)?f(null,x):x&&f(x.pre,x.post)}catch(I){k(I,pa(y))}if(z.terminal)j.terminal=!0,n=Math.max(n,z.priority)}j.scope=s&&s.scope;j.transclude=D&&v;return j}function A(d,e,g,h){var j=!1;if(a.hasOwnProperty(e))for(var n,
   22.48 +e=b.get(e+c),o=0,l=e.length;o<l;o++)try{if(n=e[o],(h===p||h>n.priority)&&n.restrict.indexOf(g)!=-1)d.push(n),j=!0}catch(r){k(r)}return j}function K(a,b){var c=b.$attr,d=a.$attr,e=a.$$element;m(a,function(d,e){e.charAt(0)!="$"&&(b[e]&&(d+=(e==="style"?";":" ")+b[e]),a.$set(e,d,!0,c[e]))});m(b,function(b,f){f=="class"?(q(e,b),a["class"]=(a["class"]?a["class"]+" ":"")+b):f=="style"?e.attr("style",e.attr("style")+";"+b):f.charAt(0)!="$"&&!a.hasOwnProperty(f)&&(a[f]=b,d[f]=c[f])})}function W(a,b,c,d,e,
   22.49 +f,k){var h=[],n,o,r=c[0],q=a.shift(),w=x({},q,{controller:null,templateUrl:null,transclude:null,scope:null});c.html("");j.get(q.templateUrl,{cache:l}).success(function(j){var l,q,j=Ha(j);if(f){q=u("<div>"+R(j)+"</div>").contents();l=q[0];if(q.length!=1||l.nodeType!==1)throw new B(g+j);j={$attr:{}};Ga(e,c,l);O(l,a,j);K(d,j)}else l=r,c.html(j);a.unshift(w);n=C(a,c,d,k);for(o=s(c.contents(),k);h.length;){var ba=h.pop(),j=h.pop();q=h.pop();var y=h.pop(),m=l;q!==r&&(m=cb(l),Ga(j,u(q),m));n(function(){b(o,
   22.50 +y,m,e,ba)},y,m,e,ba)}h=null}).error(function(a,b,c,d){throw B("Failed to load template: "+d.url);});return function(a,c,d,e,f){h?(h.push(c),h.push(d),h.push(e),h.push(f)):n(function(){b(o,c,d,e,f)},c,d,e,f)}}function y(a,b){return b.priority-a.priority}function M(a,b,c,d){if(b)throw B("Multiple directives ["+b.name+", "+c.name+"] asking for "+a+" on: "+pa(d));}function H(a,b){var c=h(b,!0);c&&a.push({priority:0,compile:I(function(a,b){var d=b.parent(),e=d.data("$binding")||[];e.push(c);q(d.data("$binding",
   22.51 +e),"ng-binding");a.$watch(c,function(a){b[0].nodeValue=a})})})}function X(a,b,c,d){var e=h(c,!0);e&&b.push({priority:100,compile:I(function(a,b,c){b=c.$$observers||(c.$$observers={});d==="class"&&(e=h(c[d],!0));c[d]=p;(b[d]||(b[d]=[])).$$inter=!0;(c.$$observers&&c.$$observers[d].$$scope||a).$watch(e,function(a){c.$set(d,a)})})})}function Ga(a,b,c){var d=b[0],e=d.parentNode,f,g;if(a){f=0;for(g=a.length;f<g;f++)if(a[f]==d){a[f]=c;break}}e&&e.replaceChild(c,d);c[u.expando]=d[u.expando];b[0]=c}var ea=
   22.52 +function(a,b){this.$$element=a;this.$attr=b||{}};ea.prototype={$normalize:fa,$set:function(a,b,c,d){var e=yb(this.$$element[0],a),f=this.$$observers;e&&(this.$$element.prop(a,b),d=e);this[a]=b;d?this.$attr[a]=d:(d=this.$attr[a])||(this.$attr[a]=d=$a(a,"-"));c!==!1&&(b===null||b===p?this.$$element.removeAttr(d):this.$$element.attr(d,b));f&&m(f[a],function(a){try{a(b)}catch(c){k(c)}})},$observe:function(a,b){var c=this,d=c.$$observers||(c.$$observers={}),e=d[a]||(d[a]=[]);e.push(b);n.$evalAsync(function(){e.$$inter||
   22.53 +b(c[a])});return b}};var D=h.startSymbol(),ba=h.endSymbol(),Ha=D=="{{"||ba=="}}"?ma:function(a){return a.replace(/\{\{/g,D).replace(/}}/g,ba)};return w}]}function fa(b){return rb(b.replace(Ac,""))}function Bc(){var b={};this.register=function(a,c){L(a)?x(b,a):b[a]=c};this.$get=["$injector","$window",function(a,c){return function(d,e){if(F(d)){var g=d,d=b.hasOwnProperty(g)?b[g]:fb(e.$scope,g,!0)||fb(c,g,!0);ra(d,g,!0)}return a.instantiate(d,e)}}]}function Cc(){this.$get=["$window",function(b){return u(b.document)}]}
   22.54 +function Dc(){this.$get=["$log",function(b){return function(a,c){b.error.apply(b,arguments)}}]}function Ec(){var b="{{",a="}}";this.startSymbol=function(a){return a?(b=a,this):b};this.endSymbol=function(b){return b?(a=b,this):a};this.$get=["$parse",function(c){function d(d,f){for(var h,k,j=0,l=[],o=d.length,r=!1,n=[];j<o;)(h=d.indexOf(b,j))!=-1&&(k=d.indexOf(a,h+e))!=-1?(j!=h&&l.push(d.substring(j,h)),l.push(j=c(r=d.substring(h+e,k))),j.exp=r,j=k+g,r=!0):(j!=o&&l.push(d.substring(j)),j=o);if(!(o=
   22.55 +l.length))l.push(""),o=1;if(!f||r)return n.length=o,j=function(a){for(var b=0,c=o,d;b<c;b++){if(typeof(d=l[b])=="function")d=d(a),d==null||d==p?d="":typeof d!="string"&&(d=da(d));n[b]=d}return n.join("")},j.exp=d,j.parts=l,j}var e=b.length,g=a.length;d.startSymbol=function(){return b};d.endSymbol=function(){return a};return d}]}function Eb(b){for(var b=b.split("/"),a=b.length;a--;)b[a]=Za(b[a]);return b.join("/")}function va(b,a){var c=Fb.exec(b),c={protocol:c[1],host:c[3],port:G(c[5])||Gb[c[1]]||
   22.56 +null,path:c[6]||"/",search:c[8],hash:c[10]};if(a)a.$$protocol=c.protocol,a.$$host=c.host,a.$$port=c.port;return c}function ka(b,a,c){return b+"://"+a+(c==Gb[b]?"":":"+c)}function Fc(b,a,c){var d=va(b);return decodeURIComponent(d.path)!=a||t(d.hash)||d.hash.indexOf(c)!==0?b:ka(d.protocol,d.host,d.port)+a.substr(0,a.lastIndexOf("/"))+d.hash.substr(c.length)}function Gc(b,a,c){var d=va(b);if(decodeURIComponent(d.path)==a)return b;else{var e=d.search&&"?"+d.search||"",g=d.hash&&"#"+d.hash||"",i=a.substr(0,
   22.57 +a.lastIndexOf("/")),f=d.path.substr(i.length);if(d.path.indexOf(i)!==0)throw B('Invalid url "'+b+'", missing path prefix "'+i+'" !');return ka(d.protocol,d.host,d.port)+a+"#"+c+f+e+g}}function gb(b,a,c){a=a||"";this.$$parse=function(b){var c=va(b,this);if(c.path.indexOf(a)!==0)throw B('Invalid url "'+b+'", missing path prefix "'+a+'" !');this.$$path=decodeURIComponent(c.path.substr(a.length));this.$$search=Xa(c.search);this.$$hash=c.hash&&decodeURIComponent(c.hash)||"";this.$$compose()};this.$$compose=
   22.58 +function(){var b=ob(this.$$search),c=this.$$hash?"#"+Za(this.$$hash):"";this.$$url=Eb(this.$$path)+(b?"?"+b:"")+c;this.$$absUrl=ka(this.$$protocol,this.$$host,this.$$port)+a+this.$$url};this.$$rewriteAppUrl=function(a){if(a.indexOf(c)==0)return a};this.$$parse(b)}function Ia(b,a,c){var d;this.$$parse=function(b){var c=va(b,this);if(c.hash&&c.hash.indexOf(a)!==0)throw B('Invalid url "'+b+'", missing hash prefix "'+a+'" !');d=c.path+(c.search?"?"+c.search:"");c=Hc.exec((c.hash||"").substr(a.length));
   22.59 +this.$$path=c[1]?(c[1].charAt(0)=="/"?"":"/")+decodeURIComponent(c[1]):"";this.$$search=Xa(c[3]);this.$$hash=c[5]&&decodeURIComponent(c[5])||"";this.$$compose()};this.$$compose=function(){var b=ob(this.$$search),c=this.$$hash?"#"+Za(this.$$hash):"";this.$$url=Eb(this.$$path)+(b?"?"+b:"")+c;this.$$absUrl=ka(this.$$protocol,this.$$host,this.$$port)+d+(this.$$url?"#"+a+this.$$url:"")};this.$$rewriteAppUrl=function(a){if(a.indexOf(c)==0)return a};this.$$parse(b)}function Hb(b,a,c,d){Ia.apply(this,arguments);
   22.60 +this.$$rewriteAppUrl=function(b){if(b.indexOf(c)==0)return c+d+"#"+a+b.substr(c.length)}}function Ja(b){return function(){return this[b]}}function Ib(b,a){return function(c){if(t(c))return this[b];this[b]=a(c);this.$$compose();return this}}function Ic(){var b="",a=!1;this.hashPrefix=function(a){return v(a)?(b=a,this):b};this.html5Mode=function(b){return v(b)?(a=b,this):a};this.$get=["$rootScope","$browser","$sniffer","$rootElement",function(c,d,e,g){function i(a){c.$broadcast("$locationChangeSuccess",
   22.61 +f.absUrl(),a)}var f,h,k,j=d.url(),l=va(j);a?(h=d.baseHref()||"/",k=h.substr(0,h.lastIndexOf("/")),l=ka(l.protocol,l.host,l.port)+k+"/",f=e.history?new gb(Fc(j,h,b),k,l):new Hb(Gc(j,h,b),b,l,h.substr(k.length+1))):(l=ka(l.protocol,l.host,l.port)+(l.path||"")+(l.search?"?"+l.search:"")+"#"+b+"/",f=new Ia(j,b,l));g.bind("click",function(a){if(!a.ctrlKey&&!(a.metaKey||a.which==2)){for(var b=u(a.target);E(b[0].nodeName)!=="a";)if(b[0]===g[0]||!(b=b.parent())[0])return;var d=b.prop("href"),e=f.$$rewriteAppUrl(d);
   22.62 +d&&!b.attr("target")&&e&&(f.$$parse(e),c.$apply(),a.preventDefault(),U.angular["ff-684208-preventDefault"]=!0)}});f.absUrl()!=j&&d.url(f.absUrl(),!0);d.onUrlChange(function(a){f.absUrl()!=a&&(c.$evalAsync(function(){var b=f.absUrl();f.$$parse(a);i(b)}),c.$$phase||c.$digest())});var o=0;c.$watch(function(){var a=d.url(),b=f.$$replace;if(!o||a!=f.absUrl())o++,c.$evalAsync(function(){c.$broadcast("$locationChangeStart",f.absUrl(),a).defaultPrevented?f.$$parse(a):(d.url(f.absUrl(),b),i(a))});f.$$replace=
   22.63 +!1;return o});return f}]}function Jc(){this.$get=["$window",function(b){function a(a){a instanceof B&&(a.stack?a=a.message&&a.stack.indexOf(a.message)===-1?"Error: "+a.message+"\n"+a.stack:a.stack:a.sourceURL&&(a=a.message+"\n"+a.sourceURL+":"+a.line));return a}function c(c){var e=b.console||{},g=e[c]||e.log||D;return g.apply?function(){var b=[];m(arguments,function(c){b.push(a(c))});return g.apply(e,b)}:function(a,b){g(a,b)}}return{log:c("log"),warn:c("warn"),info:c("info"),error:c("error")}}]}function Kc(b,
   22.64 +a){function c(a){return a.indexOf(q)!=-1}function d(){return n+1<b.length?b.charAt(n+1):!1}function e(a){return"0"<=a&&a<="9"}function g(a){return a==" "||a=="\r"||a=="\t"||a=="\n"||a=="\u000b"||a=="\u00a0"}function i(a){return"a"<=a&&a<="z"||"A"<=a&&a<="Z"||"_"==a||a=="$"}function f(a){return a=="-"||a=="+"||e(a)}function h(a,c,d){d=d||n;throw B("Lexer Error: "+a+" at column"+(v(c)?"s "+c+"-"+n+" ["+b.substring(c,d)+"]":" "+d)+" in expression ["+b+"].");}function k(){for(var a="",c=n;n<b.length;){var k=
   22.65 +E(b.charAt(n));if(k=="."||e(k))a+=k;else{var g=d();if(k=="e"&&f(g))a+=k;else if(f(k)&&g&&e(g)&&a.charAt(a.length-1)=="e")a+=k;else if(f(k)&&(!g||!e(g))&&a.charAt(a.length-1)=="e")h("Invalid exponent");else break}n++}a*=1;o.push({index:c,text:a,json:!0,fn:function(){return a}})}function j(){for(var c="",d=n,f,k,h;n<b.length;){var j=b.charAt(n);if(j=="."||i(j)||e(j))j=="."&&(f=n),c+=j;else break;n++}if(f)for(k=n;k<b.length;){j=b.charAt(k);if(j=="("){h=c.substr(f-d+1);c=c.substr(0,f-d);n=k;break}if(g(j))k++;
   22.66 +else break}d={index:d,text:c};if(Ka.hasOwnProperty(c))d.fn=d.json=Ka[c];else{var l=Jb(c,a);d.fn=x(function(a,b){return l(a,b)},{assign:function(a,b){return Kb(a,c,b)}})}o.push(d);h&&(o.push({index:f,text:".",json:!1}),o.push({index:f+1,text:h,json:!1}))}function l(a){var c=n;n++;for(var d="",e=a,f=!1;n<b.length;){var k=b.charAt(n);e+=k;if(f)k=="u"?(k=b.substring(n+1,n+5),k.match(/[\da-f]{4}/i)||h("Invalid unicode escape [\\u"+k+"]"),n+=4,d+=String.fromCharCode(parseInt(k,16))):(f=Lc[k],d+=f?f:k),
   22.67 +f=!1;else if(k=="\\")f=!0;else if(k==a){n++;o.push({index:c,text:e,string:d,json:!0,fn:function(){return d}});return}else d+=k;n++}h("Unterminated quote",c)}for(var o=[],r,n=0,w=[],q,s=":";n<b.length;){q=b.charAt(n);if(c("\"'"))l(q);else if(e(q)||c(".")&&e(d()))k();else if(i(q)){if(j(),"{,".indexOf(s)!=-1&&w[0]=="{"&&(r=o[o.length-1]))r.json=r.text.indexOf(".")==-1}else if(c("(){}[].,;:"))o.push({index:n,text:q,json:":[,".indexOf(s)!=-1&&c("{[")||c("}]:,")}),c("{[")&&w.unshift(q),c("}]")&&w.shift(),
   22.68 +n++;else if(g(q)){n++;continue}else{var m=q+d(),C=Ka[q],A=Ka[m];A?(o.push({index:n,text:m,fn:A}),n+=2):C?(o.push({index:n,text:q,fn:C,json:"[,:".indexOf(s)!=-1&&c("+-")}),n+=1):h("Unexpected next character ",n,n+1)}s=q}return o}function Mc(b,a,c,d){function e(a,c){throw B("Syntax Error: Token '"+c.text+"' "+a+" at column "+(c.index+1)+" of the expression ["+b+"] starting at ["+b.substring(c.index)+"].");}function g(){if(M.length===0)throw B("Unexpected end of expression: "+b);return M[0]}function i(a,
   22.69 +b,c,d){if(M.length>0){var e=M[0],f=e.text;if(f==a||f==b||f==c||f==d||!a&&!b&&!c&&!d)return e}return!1}function f(b,c,d,f){return(b=i(b,c,d,f))?(a&&!b.json&&e("is not valid json",b),M.shift(),b):!1}function h(a){f(a)||e("is unexpected, expecting ["+a+"]",i())}function k(a,b){return function(c,d){return a(c,d,b)}}function j(a,b,c){return function(d,e){return b(d,e,a,c)}}function l(){for(var a=[];;)if(M.length>0&&!i("}",")",";","]")&&a.push(v()),!f(";"))return a.length==1?a[0]:function(b,c){for(var d,
   22.70 +e=0;e<a.length;e++){var f=a[e];f&&(d=f(b,c))}return d}}function o(){for(var a=f(),b=c(a.text),d=[];;)if(a=f(":"))d.push(H());else{var e=function(a,c,e){for(var e=[e],f=0;f<d.length;f++)e.push(d[f](a,c));return b.apply(a,e)};return function(){return e}}}function r(){for(var a=n(),b;;)if(b=f("||"))a=j(a,b.fn,n());else return a}function n(){var a=w(),b;if(b=f("&&"))a=j(a,b.fn,n());return a}function w(){var a=q(),b;if(b=f("==","!="))a=j(a,b.fn,w());return a}function q(){var a;a=s();for(var b;b=f("+",
   22.71 +"-");)a=j(a,b.fn,s());if(b=f("<",">","<=",">="))a=j(a,b.fn,q());return a}function s(){for(var a=m(),b;b=f("*","/","%");)a=j(a,b.fn,m());return a}function m(){var a;return f("+")?C():(a=f("-"))?j(W,a.fn,m()):(a=f("!"))?k(a.fn,m()):C()}function C(){var a;if(f("("))a=v(),h(")");else if(f("["))a=A();else if(f("{"))a=K();else{var b=f();(a=b.fn)||e("not a primary expression",b)}for(var c;b=f("(","[",".");)b.text==="("?(a=u(a,c),c=null):b.text==="["?(c=a,a=ea(a)):b.text==="."?(c=a,a=t(a)):e("IMPOSSIBLE");
   22.72 +return a}function A(){var a=[];if(g().text!="]"){do a.push(H());while(f(","))}h("]");return function(b,c){for(var d=[],e=0;e<a.length;e++)d.push(a[e](b,c));return d}}function K(){var a=[];if(g().text!="}"){do{var b=f(),b=b.string||b.text;h(":");var c=H();a.push({key:b,value:c})}while(f(","))}h("}");return function(b,c){for(var d={},e=0;e<a.length;e++){var f=a[e],k=f.value(b,c);d[f.key]=k}return d}}var W=I(0),y,M=Kc(b,d),H=function(){var a=r(),c,d;return(d=f("="))?(a.assign||e("implies assignment but ["+
   22.73 +b.substring(0,d.index)+"] can not be assigned to",d),c=r(),function(b,d){return a.assign(b,c(b,d),d)}):a},u=function(a,b){var c=[];if(g().text!=")"){do c.push(H());while(f(","))}h(")");return function(d,e){for(var f=[],k=b?b(d,e):d,h=0;h<c.length;h++)f.push(c[h](d,e));h=a(d,e)||D;return h.apply?h.apply(k,f):h(f[0],f[1],f[2],f[3],f[4])}},t=function(a){var b=f().text,c=Jb(b,d);return x(function(b,d){return c(a(b,d),d)},{assign:function(c,d,e){return Kb(a(c,e),b,d)}})},ea=function(a){var b=H();h("]");
   22.74 +return x(function(c,d){var e=a(c,d),f=b(c,d),k;if(!e)return p;if((e=e[f])&&e.then){k=e;if(!("$$v"in e))k.$$v=p,k.then(function(a){k.$$v=a});e=e.$$v}return e},{assign:function(c,d,e){return a(c,e)[b(c,e)]=d}})},v=function(){for(var a=H(),b;;)if(b=f("|"))a=j(a,b.fn,o());else return a};a?(H=r,u=t=ea=v=function(){e("is not valid json",{text:b,index:0})},y=C()):y=l();M.length!==0&&e("is an unexpected token",M[0]);return y}function Kb(b,a,c){for(var a=a.split("."),d=0;a.length>1;d++){var e=a.shift(),g=
   22.75 +b[e];g||(g={},b[e]=g);b=g}return b[a.shift()]=c}function fb(b,a,c){if(!a)return b;for(var a=a.split("."),d,e=b,g=a.length,i=0;i<g;i++)d=a[i],b&&(b=(e=b)[d]);return!c&&N(b)?Va(e,b):b}function Lb(b,a,c,d,e){return function(g,i){var f=i&&i.hasOwnProperty(b)?i:g,h;if(f===null||f===p)return f;if((f=f[b])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}if(!a||f===null||f===p)return f;if((f=f[a])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}if(!c||f===
   22.76 +null||f===p)return f;if((f=f[c])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}if(!d||f===null||f===p)return f;if((f=f[d])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}if(!e||f===null||f===p)return f;if((f=f[e])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}return f}}function Jb(b,a){if(hb.hasOwnProperty(b))return hb[b];var c=b.split("."),d=c.length,e;if(a)e=d<6?Lb(c[0],c[1],c[2],c[3],c[4]):function(a,b){var e=0,
   22.77 +k;do k=Lb(c[e++],c[e++],c[e++],c[e++],c[e++])(a,b),b=p,a=k;while(e<d);return k};else{var g="var l, fn, p;\n";m(c,function(a,b){g+="if(s === null || s === undefined) return s;\nl=s;\ns="+(b?"s":'((k&&k.hasOwnProperty("'+a+'"))?k:s)')+'["'+a+'"];\nif (s && s.then) {\n if (!("$$v" in s)) {\n p=s;\n p.$$v = undefined;\n p.then(function(v) {p.$$v=v;});\n}\n s=s.$$v\n}\n'});g+="return s;";e=Function("s","k",g);e.toString=function(){return g}}return hb[b]=e}function Nc(){var b={};this.$get=["$filter","$sniffer",
   22.78 +function(a,c){return function(d){switch(typeof d){case "string":return b.hasOwnProperty(d)?b[d]:b[d]=Mc(d,!1,a,c.csp);case "function":return d;default:return D}}}]}function Oc(){this.$get=["$rootScope","$exceptionHandler",function(b,a){return Pc(function(a){b.$evalAsync(a)},a)}]}function Pc(b,a){function c(a){return a}function d(a){return i(a)}var e=function(){var f=[],h,k;return k={resolve:function(a){if(f){var c=f;f=p;h=g(a);c.length&&b(function(){for(var a,b=0,d=c.length;b<d;b++)a=c[b],h.then(a[0],
   22.79 +a[1])})}},reject:function(a){k.resolve(i(a))},promise:{then:function(b,k){var g=e(),i=function(d){try{g.resolve((b||c)(d))}catch(e){a(e),g.reject(e)}},n=function(b){try{g.resolve((k||d)(b))}catch(c){a(c),g.reject(c)}};f?f.push([i,n]):h.then(i,n);return g.promise}}}},g=function(a){return a&&a.then?a:{then:function(c){var d=e();b(function(){d.resolve(c(a))});return d.promise}}},i=function(a){return{then:function(c,k){var g=e();b(function(){g.resolve((k||d)(a))});return g.promise}}};return{defer:e,reject:i,
   22.80 +when:function(f,h,k){var j=e(),l,o=function(b){try{return(h||c)(b)}catch(d){return a(d),i(d)}},r=function(b){try{return(k||d)(b)}catch(c){return a(c),i(c)}};b(function(){g(f).then(function(a){l||(l=!0,j.resolve(g(a).then(o,r)))},function(a){l||(l=!0,j.resolve(r(a)))})});return j.promise},all:function(a){var b=e(),c=a.length,d=[];c?m(a,function(a,e){g(a).then(function(a){e in d||(d[e]=a,--c||b.resolve(d))},function(a){e in d||b.reject(a)})}):b.resolve(d);return b.promise}}}function Qc(){var b={};this.when=
   22.81 +function(a,c){b[a]=x({reloadOnSearch:!0},c);if(a){var d=a[a.length-1]=="/"?a.substr(0,a.length-1):a+"/";b[d]={redirectTo:a}}return this};this.otherwise=function(a){this.when(null,a);return this};this.$get=["$rootScope","$location","$routeParams","$q","$injector","$http","$templateCache",function(a,c,d,e,g,i,f){function h(){var b=k(),h=r.current;if(b&&h&&b.$route===h.$route&&ha(b.pathParams,h.pathParams)&&!b.reloadOnSearch&&!o)h.params=b.params,V(h.params,d),a.$broadcast("$routeUpdate",h);else if(b||
   22.82 +h)o=!1,a.$broadcast("$routeChangeStart",b,h),(r.current=b)&&b.redirectTo&&(F(b.redirectTo)?c.path(j(b.redirectTo,b.params)).search(b.params).replace():c.url(b.redirectTo(b.pathParams,c.path(),c.search())).replace()),e.when(b).then(function(){if(b){var a=[],c=[],d;m(b.resolve||{},function(b,d){a.push(d);c.push(F(b)?g.get(b):g.invoke(b))});if(!v(d=b.template))if(v(d=b.templateUrl))d=i.get(d,{cache:f}).then(function(a){return a.data});v(d)&&(a.push("$template"),c.push(d));return e.all(c).then(function(b){var c=
   22.83 +{};m(b,function(b,d){c[a[d]]=b});return c})}}).then(function(c){if(b==r.current){if(b)b.locals=c,V(b.params,d);a.$broadcast("$routeChangeSuccess",b,h)}},function(c){b==r.current&&a.$broadcast("$routeChangeError",b,h,c)})}function k(){var a,d;m(b,function(b,e){if(!d&&(a=l(c.path(),e)))d=ya(b,{params:x({},c.search(),a),pathParams:a}),d.$route=b});return d||b[null]&&ya(b[null],{params:{},pathParams:{}})}function j(a,b){var c=[];m((a||"").split(":"),function(a,d){if(d==0)c.push(a);else{var e=a.match(/(\w+)(.*)/),
   22.84 +f=e[1];c.push(b[f]);c.push(e[2]||"");delete b[f]}});return c.join("")}var l=function(a,b){var c="^"+b.replace(/([\.\\\(\)\^\$])/g,"\\$1")+"$",d=[],e={};m(b.split(/\W/),function(a){if(a){var b=RegExp(":"+a+"([\\W])");c.match(b)&&(c=c.replace(b,"([^\\/]*)$1"),d.push(a))}});var f=a.match(RegExp(c));f&&m(d,function(a,b){e[a]=f[b+1]});return f?e:null},o=!1,r={routes:b,reload:function(){o=!0;a.$evalAsync(h)}};a.$on("$locationChangeSuccess",h);return r}]}function Rc(){this.$get=I({})}function Sc(){var b=
   22.85 +10;this.digestTtl=function(a){arguments.length&&(b=a);return b};this.$get=["$injector","$exceptionHandler","$parse",function(a,c,d){function e(){this.$id=xa();this.$$phase=this.$parent=this.$$watchers=this.$$nextSibling=this.$$prevSibling=this.$$childHead=this.$$childTail=null;this["this"]=this.$root=this;this.$$asyncQueue=[];this.$$listeners={}}function g(a){if(h.$$phase)throw B(h.$$phase+" already in progress");h.$$phase=a}function i(a,b){var c=d(a);ra(c,b);return c}function f(){}e.prototype={$new:function(a){if(N(a))throw B("API-CHANGE: Use $controller to instantiate controllers.");
   22.86 +a?(a=new e,a.$root=this.$root):(a=function(){},a.prototype=this,a=new a,a.$id=xa());a["this"]=a;a.$$listeners={};a.$parent=this;a.$$asyncQueue=[];a.$$watchers=a.$$nextSibling=a.$$childHead=a.$$childTail=null;a.$$prevSibling=this.$$childTail;this.$$childHead?this.$$childTail=this.$$childTail.$$nextSibling=a:this.$$childHead=this.$$childTail=a;return a},$watch:function(a,b,c){var d=i(a,"watch"),e=this.$$watchers,g={fn:b,last:f,get:d,exp:a,eq:!!c};if(!N(b)){var h=i(b||D,"listener");g.fn=function(a,b,
   22.87 +c){h(c)}}if(!e)e=this.$$watchers=[];e.unshift(g);return function(){Ua(e,g)}},$digest:function(){var a,d,e,i,r,n,m,q=b,s,p=[],C,A;g("$digest");do{m=!1;s=this;do{for(r=s.$$asyncQueue;r.length;)try{s.$eval(r.shift())}catch(K){c(K)}if(i=s.$$watchers)for(n=i.length;n--;)try{if(a=i[n],(d=a.get(s))!==(e=a.last)&&!(a.eq?ha(d,e):typeof d=="number"&&typeof e=="number"&&isNaN(d)&&isNaN(e)))m=!0,a.last=a.eq?V(d):d,a.fn(d,e===f?d:e,s),q<5&&(C=4-q,p[C]||(p[C]=[]),A=N(a.exp)?"fn: "+(a.exp.name||a.exp.toString()):
   22.88 +a.exp,A+="; newVal: "+da(d)+"; oldVal: "+da(e),p[C].push(A))}catch(W){c(W)}if(!(i=s.$$childHead||s!==this&&s.$$nextSibling))for(;s!==this&&!(i=s.$$nextSibling);)s=s.$parent}while(s=i);if(m&&!q--)throw h.$$phase=null,B(b+" $digest() iterations reached. Aborting!\nWatchers fired in the last 5 iterations: "+da(p));}while(m||r.length);h.$$phase=null},$destroy:function(){if(h!=this){var a=this.$parent;this.$broadcast("$destroy");if(a.$$childHead==this)a.$$childHead=this.$$nextSibling;if(a.$$childTail==
   22.89 +this)a.$$childTail=this.$$prevSibling;if(this.$$prevSibling)this.$$prevSibling.$$nextSibling=this.$$nextSibling;if(this.$$nextSibling)this.$$nextSibling.$$prevSibling=this.$$prevSibling;this.$parent=this.$$nextSibling=this.$$prevSibling=this.$$childHead=this.$$childTail=null}},$eval:function(a,b){return d(a)(this,b)},$evalAsync:function(a){this.$$asyncQueue.push(a)},$apply:function(a){try{return g("$apply"),this.$eval(a)}catch(b){c(b)}finally{h.$$phase=null;try{h.$digest()}catch(d){throw c(d),d;}}},
   22.90 +$on:function(a,b){var c=this.$$listeners[a];c||(this.$$listeners[a]=c=[]);c.push(b);return function(){c[za(c,b)]=null}},$emit:function(a,b){var d=[],e,f=this,g=!1,h={name:a,targetScope:f,stopPropagation:function(){g=!0},preventDefault:function(){h.defaultPrevented=!0},defaultPrevented:!1},i=[h].concat(ia.call(arguments,1)),m,p;do{e=f.$$listeners[a]||d;h.currentScope=f;m=0;for(p=e.length;m<p;m++)if(e[m])try{if(e[m].apply(null,i),g)return h}catch(C){c(C)}else e.splice(m,1),m--,p--;f=f.$parent}while(f);
   22.91 +return h},$broadcast:function(a,b){var d=this,e=this,f={name:a,targetScope:this,preventDefault:function(){f.defaultPrevented=!0},defaultPrevented:!1},g=[f].concat(ia.call(arguments,1)),h,i;do{d=e;f.currentScope=d;e=d.$$listeners[a]||[];h=0;for(i=e.length;h<i;h++)if(e[h])try{e[h].apply(null,g)}catch(m){c(m)}else e.splice(h,1),h--,i--;if(!(e=d.$$childHead||d!==this&&d.$$nextSibling))for(;d!==this&&!(e=d.$$nextSibling);)d=d.$parent}while(d=e);return f}};var h=new e;return h}]}function Tc(){this.$get=
   22.92 +["$window",function(b){var a={},c=G((/android (\d+)/.exec(E(b.navigator.userAgent))||[])[1]);return{history:!(!b.history||!b.history.pushState||c<4),hashchange:"onhashchange"in b&&(!b.document.documentMode||b.document.documentMode>7),hasEvent:function(c){if(c=="input"&&aa==9)return!1;if(t(a[c])){var e=b.document.createElement("div");a[c]="on"+c in e}return a[c]},csp:!1}}]}function Uc(){this.$get=I(U)}function Mb(b){var a={},c,d,e;if(!b)return a;m(b.split("\n"),function(b){e=b.indexOf(":");c=E(R(b.substr(0,
   22.93 +e)));d=R(b.substr(e+1));c&&(a[c]?a[c]+=", "+d:a[c]=d)});return a}function Nb(b){var a=L(b)?b:p;return function(c){a||(a=Mb(b));return c?a[E(c)]||null:a}}function Ob(b,a,c){if(N(c))return c(b,a);m(c,function(c){b=c(b,a)});return b}function Vc(){var b=/^\s*(\[|\{[^\{])/,a=/[\}\]]\s*$/,c=/^\)\]\}',?\n/,d=this.defaults={transformResponse:[function(d){F(d)&&(d=d.replace(c,""),b.test(d)&&a.test(d)&&(d=nb(d,!0)));return d}],transformRequest:[function(a){return L(a)&&Sa.apply(a)!=="[object File]"?da(a):a}],
   22.94 +headers:{common:{Accept:"application/json, text/plain, */*","X-Requested-With":"XMLHttpRequest"},post:{"Content-Type":"application/json;charset=utf-8"},put:{"Content-Type":"application/json;charset=utf-8"}}},e=this.responseInterceptors=[];this.$get=["$httpBackend","$browser","$cacheFactory","$rootScope","$q","$injector",function(a,b,c,h,k,j){function l(a){function c(a){var b=x({},a,{data:Ob(a.data,a.headers,f)});return 200<=a.status&&a.status<300?b:k.reject(b)}a.method=la(a.method);var e=a.transformRequest||
   22.95 +d.transformRequest,f=a.transformResponse||d.transformResponse,h=d.headers,h=x({"X-XSRF-TOKEN":b.cookies()["XSRF-TOKEN"]},h.common,h[E(a.method)],a.headers),e=Ob(a.data,Nb(h),e),g;t(a.data)&&delete h["Content-Type"];g=o(a,e,h);g=g.then(c,c);m(w,function(a){g=a(g)});g.success=function(b){g.then(function(c){b(c.data,c.status,c.headers,a)});return g};g.error=function(b){g.then(null,function(c){b(c.data,c.status,c.headers,a)});return g};return g}function o(b,c,d){function e(a,b,c){m&&(200<=a&&a<300?m.put(w,
   22.96 +[a,b,Mb(c)]):m.remove(w));f(b,a,c);h.$apply()}function f(a,c,d){c=Math.max(c,0);(200<=c&&c<300?j.resolve:j.reject)({data:a,status:c,headers:Nb(d),config:b})}function i(){var a=za(l.pendingRequests,b);a!==-1&&l.pendingRequests.splice(a,1)}var j=k.defer(),o=j.promise,m,p,w=r(b.url,b.params);l.pendingRequests.push(b);o.then(i,i);b.cache&&b.method=="GET"&&(m=L(b.cache)?b.cache:n);if(m)if(p=m.get(w))if(p.then)return p.then(i,i),p;else J(p)?f(p[1],p[0],V(p[2])):f(p,200,{});else m.put(w,o);p||a(b.method,
   22.97 +w,c,e,d,b.timeout,b.withCredentials);return o}function r(a,b){if(!b)return a;var c=[];ec(b,function(a,b){a==null||a==p||(L(a)&&(a=da(a)),c.push(encodeURIComponent(b)+"="+encodeURIComponent(a)))});return a+(a.indexOf("?")==-1?"?":"&")+c.join("&")}var n=c("$http"),w=[];m(e,function(a){w.push(F(a)?j.get(a):j.invoke(a))});l.pendingRequests=[];(function(a){m(arguments,function(a){l[a]=function(b,c){return l(x(c||{},{method:a,url:b}))}})})("get","delete","head","jsonp");(function(a){m(arguments,function(a){l[a]=
   22.98 +function(b,c,d){return l(x(d||{},{method:a,url:b,data:c}))}})})("post","put");l.defaults=d;return l}]}function Wc(){this.$get=["$browser","$window","$document",function(b,a,c){return Xc(b,Yc,b.defer,a.angular.callbacks,c[0],a.location.protocol.replace(":",""))}]}function Xc(b,a,c,d,e,g){function i(a,b){var c=e.createElement("script"),d=function(){e.body.removeChild(c);b&&b()};c.type="text/javascript";c.src=a;aa?c.onreadystatechange=function(){/loaded|complete/.test(c.readyState)&&d()}:c.onload=c.onerror=
   22.99 +d;e.body.appendChild(c)}return function(e,h,k,j,l,o,r){function n(a,c,d,e){c=(h.match(Fb)||["",g])[1]=="file"?d?200:404:c;a(c==1223?204:c,d,e);b.$$completeOutstandingRequest(D)}b.$$incOutstandingRequestCount();h=h||b.url();if(E(e)=="jsonp"){var p="_"+(d.counter++).toString(36);d[p]=function(a){d[p].data=a};i(h.replace("JSON_CALLBACK","angular.callbacks."+p),function(){d[p].data?n(j,200,d[p].data):n(j,-2);delete d[p]})}else{var q=new a;q.open(e,h,!0);m(l,function(a,b){a&&q.setRequestHeader(b,a)});
  22.100 +var s;q.onreadystatechange=function(){q.readyState==4&&n(j,s||q.status,q.responseText,q.getAllResponseHeaders())};if(r)q.withCredentials=!0;q.send(k||"");o>0&&c(function(){s=-1;q.abort()},o)}}}function Zc(){this.$get=function(){return{id:"en-us",NUMBER_FORMATS:{DECIMAL_SEP:".",GROUP_SEP:",",PATTERNS:[{minInt:1,minFrac:0,maxFrac:3,posPre:"",posSuf:"",negPre:"-",negSuf:"",gSize:3,lgSize:3},{minInt:1,minFrac:2,maxFrac:2,posPre:"\u00a4",posSuf:"",negPre:"(\u00a4",negSuf:")",gSize:3,lgSize:3}],CURRENCY_SYM:"$"},
  22.101 +DATETIME_FORMATS:{MONTH:"January,February,March,April,May,June,July,August,September,October,November,December".split(","),SHORTMONTH:"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(","),DAY:"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(","),SHORTDAY:"Sun,Mon,Tue,Wed,Thu,Fri,Sat".split(","),AMPMS:["AM","PM"],medium:"MMM d, y h:mm:ss a","short":"M/d/yy h:mm a",fullDate:"EEEE, MMMM d, y",longDate:"MMMM d, y",mediumDate:"MMM d, y",shortDate:"M/d/yy",mediumTime:"h:mm:ss a",
  22.102 +shortTime:"h:mm a"},pluralCat:function(b){return b===1?"one":"other"}}}}function $c(){this.$get=["$rootScope","$browser","$q","$exceptionHandler",function(b,a,c,d){function e(e,f,h){var k=c.defer(),j=k.promise,l=v(h)&&!h,f=a.defer(function(){try{k.resolve(e())}catch(a){k.reject(a),d(a)}l||b.$apply()},f),h=function(){delete g[j.$$timeoutId]};j.$$timeoutId=f;g[f]=k;j.then(h,h);return j}var g={};e.cancel=function(b){return b&&b.$$timeoutId in g?(g[b.$$timeoutId].reject("canceled"),a.defer.cancel(b.$$timeoutId)):
  22.103 +!1};return e}]}function Pb(b){function a(a,e){return b.factory(a+c,e)}var c="Filter";this.register=a;this.$get=["$injector",function(a){return function(b){return a.get(b+c)}}];a("currency",Qb);a("date",Rb);a("filter",ad);a("json",bd);a("limitTo",cd);a("lowercase",dd);a("number",Sb);a("orderBy",Tb);a("uppercase",ed)}function ad(){return function(b,a){if(!(b instanceof Array))return b;var c=[];c.check=function(a){for(var b=0;b<c.length;b++)if(!c[b](a))return!1;return!0};var d=function(a,b){if(b.charAt(0)===
  22.104 +"!")return!d(a,b.substr(1));switch(typeof a){case "boolean":case "number":case "string":return(""+a).toLowerCase().indexOf(b)>-1;case "object":for(var c in a)if(c.charAt(0)!=="$"&&d(a[c],b))return!0;return!1;case "array":for(c=0;c<a.length;c++)if(d(a[c],b))return!0;return!1;default:return!1}};switch(typeof a){case "boolean":case "number":case "string":a={$:a};case "object":for(var e in a)e=="$"?function(){var b=(""+a[e]).toLowerCase();b&&c.push(function(a){return d(a,b)})}():function(){var b=e,f=
  22.105 +(""+a[e]).toLowerCase();f&&c.push(function(a){return d(fb(a,b),f)})}();break;case "function":c.push(a);break;default:return b}for(var g=[],i=0;i<b.length;i++){var f=b[i];c.check(f)&&g.push(f)}return g}}function Qb(b){var a=b.NUMBER_FORMATS;return function(b,d){if(t(d))d=a.CURRENCY_SYM;return Ub(b,a.PATTERNS[1],a.GROUP_SEP,a.DECIMAL_SEP,2).replace(/\u00A4/g,d)}}function Sb(b){var a=b.NUMBER_FORMATS;return function(b,d){return Ub(b,a.PATTERNS[0],a.GROUP_SEP,a.DECIMAL_SEP,d)}}function Ub(b,a,c,d,e){if(isNaN(b)||
  22.106 +!isFinite(b))return"";var g=b<0,b=Math.abs(b),i=b+"",f="",h=[],k=!1;if(i.indexOf("e")!==-1){var j=i.match(/([\d\.]+)e(-?)(\d+)/);j&&j[2]=="-"&&j[3]>e+1?i="0":(f=i,k=!0)}if(!k){i=(i.split(Vb)[1]||"").length;t(e)&&(e=Math.min(Math.max(a.minFrac,i),a.maxFrac));var i=Math.pow(10,e),b=Math.round(b*i)/i,b=(""+b).split(Vb),i=b[0],b=b[1]||"",k=0,j=a.lgSize,l=a.gSize;if(i.length>=j+l)for(var k=i.length-j,o=0;o<k;o++)(k-o)%l===0&&o!==0&&(f+=c),f+=i.charAt(o);for(o=k;o<i.length;o++)(i.length-o)%j===0&&o!==0&&
  22.107 +(f+=c),f+=i.charAt(o);for(;b.length<e;)b+="0";e&&(f+=d+b.substr(0,e))}h.push(g?a.negPre:a.posPre);h.push(f);h.push(g?a.negSuf:a.posSuf);return h.join("")}function ib(b,a,c){var d="";b<0&&(d="-",b=-b);for(b=""+b;b.length<a;)b="0"+b;c&&(b=b.substr(b.length-a));return d+b}function P(b,a,c,d){return function(e){e=e["get"+b]();if(c>0||e>-c)e+=c;e===0&&c==-12&&(e=12);return ib(e,a,d)}}function La(b,a){return function(c,d){var e=c["get"+b](),g=la(a?"SHORT"+b:b);return d[g][e]}}function Rb(b){function a(a){var b;
  22.108 +if(b=a.match(c)){var a=new Date(0),g=0,i=0;b[9]&&(g=G(b[9]+b[10]),i=G(b[9]+b[11]));a.setUTCFullYear(G(b[1]),G(b[2])-1,G(b[3]));a.setUTCHours(G(b[4]||0)-g,G(b[5]||0)-i,G(b[6]||0),G(b[7]||0))}return a}var c=/^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;return function(c,e){var g="",i=[],f,h,e=e||"mediumDate",e=b.DATETIME_FORMATS[e]||e;F(c)&&(c=fd.test(c)?G(c):a(c));wa(c)&&(c=new Date(c));if(!na(c))return c;for(;e;)(h=gd.exec(e))?(i=i.concat(ia.call(h,
  22.109 +1)),e=i.pop()):(i.push(e),e=null);m(i,function(a){f=hd[a];g+=f?f(c,b.DATETIME_FORMATS):a.replace(/(^'|'$)/g,"").replace(/''/g,"'")});return g}}function bd(){return function(b){return da(b,!0)}}function cd(){return function(b,a){if(!(b instanceof Array))return b;var a=G(a),c=[],d,e;if(!b||!(b instanceof Array))return c;a>b.length?a=b.length:a<-b.length&&(a=-b.length);a>0?(d=0,e=a):(d=b.length+a,e=b.length);for(;d<e;d++)c.push(b[d]);return c}}function Tb(b){return function(a,c,d){function e(a,b){return Wa(b)?
  22.110 +function(b,c){return a(c,b)}:a}if(!(a instanceof Array))return a;if(!c)return a;for(var c=J(c)?c:[c],c=Ta(c,function(a){var c=!1,d=a||ma;if(F(a)){if(a.charAt(0)=="+"||a.charAt(0)=="-")c=a.charAt(0)=="-",a=a.substring(1);d=b(a)}return e(function(a,b){var c;c=d(a);var e=d(b),f=typeof c,g=typeof e;f==g?(f=="string"&&(c=c.toLowerCase()),f=="string"&&(e=e.toLowerCase()),c=c===e?0:c<e?-1:1):c=f<g?-1:1;return c},c)}),g=[],i=0;i<a.length;i++)g.push(a[i]);return g.sort(e(function(a,b){for(var d=0;d<c.length;d++){var e=
  22.111 +c[d](a,b);if(e!==0)return e}return 0},d))}}function S(b){N(b)&&(b={link:b});b.restrict=b.restrict||"AC";return I(b)}function Wb(b,a){function c(a,c){c=c?"-"+$a(c,"-"):"";b.removeClass((a?Ma:Na)+c).addClass((a?Na:Ma)+c)}var d=this,e=b.parent().controller("form")||Oa,g=0,i=d.$error={};d.$name=a.name;d.$dirty=!1;d.$pristine=!0;d.$valid=!0;d.$invalid=!1;e.$addControl(d);b.addClass(Pa);c(!0);d.$addControl=function(a){a.$name&&!d.hasOwnProperty(a.$name)&&(d[a.$name]=a)};d.$removeControl=function(a){a.$name&&
  22.112 +d[a.$name]===a&&delete d[a.$name];m(i,function(b,c){d.$setValidity(c,!0,a)})};d.$setValidity=function(a,b,k){var j=i[a];if(b){if(j&&(Ua(j,k),!j.length)){g--;if(!g)c(b),d.$valid=!0,d.$invalid=!1;i[a]=!1;c(!0,a);e.$setValidity(a,!0,d)}}else{g||c(b);if(j){if(za(j,k)!=-1)return}else i[a]=j=[],g++,c(!1,a),e.$setValidity(a,!1,d);j.push(k);d.$valid=!1;d.$invalid=!0}};d.$setDirty=function(){b.removeClass(Pa).addClass(Xb);d.$dirty=!0;d.$pristine=!1;e.$setDirty()}}function T(b){return t(b)||b===""||b===null||
  22.113 +b!==b}function Qa(b,a,c,d,e,g){var i=function(){var c=R(a.val());d.$viewValue!==c&&b.$apply(function(){d.$setViewValue(c)})};if(e.hasEvent("input"))a.bind("input",i);else{var f;a.bind("keydown",function(a){a=a.keyCode;a===91||15<a&&a<19||37<=a&&a<=40||f||(f=g.defer(function(){i();f=null}))});a.bind("change",i)}d.$render=function(){a.val(T(d.$viewValue)?"":d.$viewValue)};var h=c.ngPattern,k=function(a,b){return T(b)||a.test(b)?(d.$setValidity("pattern",!0),b):(d.$setValidity("pattern",!1),p)};h&&(h.match(/^\/(.*)\/$/)?
  22.114 +(h=RegExp(h.substr(1,h.length-2)),e=function(a){return k(h,a)}):e=function(a){var c=b.$eval(h);if(!c||!c.test)throw new B("Expected "+h+" to be a RegExp but was "+c);return k(c,a)},d.$formatters.push(e),d.$parsers.push(e));if(c.ngMinlength){var j=G(c.ngMinlength),e=function(a){return!T(a)&&a.length<j?(d.$setValidity("minlength",!1),p):(d.$setValidity("minlength",!0),a)};d.$parsers.push(e);d.$formatters.push(e)}if(c.ngMaxlength){var l=G(c.ngMaxlength),c=function(a){return!T(a)&&a.length>l?(d.$setValidity("maxlength",
  22.115 +!1),p):(d.$setValidity("maxlength",!0),a)};d.$parsers.push(c);d.$formatters.push(c)}}function jb(b,a){b="ngClass"+b;return S(function(c,d,e){function g(b,d){if(a===!0||c.$index%2===a)d&&b!==d&&i(d),f(b)}function i(a){L(a)&&!J(a)&&(a=Ta(a,function(a,b){if(a)return b}));d.removeClass(J(a)?a.join(" "):a)}function f(a){L(a)&&!J(a)&&(a=Ta(a,function(a,b){if(a)return b}));a&&d.addClass(J(a)?a.join(" "):a)}c.$watch(e[b],g,!0);e.$observe("class",function(){var a=c.$eval(e[b]);g(a,a)});b!=="ngClass"&&c.$watch("$index",
  22.116 +function(d,g){var j=d%2;j!==g%2&&(j==a?f(c.$eval(e[b])):i(c.$eval(e[b])))})})}var E=function(b){return F(b)?b.toLowerCase():b},la=function(b){return F(b)?b.toUpperCase():b},B=U.Error,aa=G((/msie (\d+)/.exec(E(navigator.userAgent))||[])[1]),u,ja,ia=[].slice,Ra=[].push,Sa=Object.prototype.toString,Yb=U.angular||(U.angular={}),ta,Cb,Z=["0","0","0"];D.$inject=[];ma.$inject=[];Cb=aa<9?function(b){b=b.nodeName?b:b[0];return b.scopeName&&b.scopeName!="HTML"?la(b.scopeName+":"+b.nodeName):b.nodeName}:function(b){return b.nodeName?
  22.117 +b.nodeName:b[0].nodeName};var kc=/[A-Z]/g,id={full:"1.0.3",major:1,minor:0,dot:3,codeName:"bouncy-thunder"},Ba=Q.cache={},Aa=Q.expando="ng-"+(new Date).getTime(),oc=1,Zb=U.document.addEventListener?function(b,a,c){b.addEventListener(a,c,!1)}:function(b,a,c){b.attachEvent("on"+a,c)},db=U.document.removeEventListener?function(b,a,c){b.removeEventListener(a,c,!1)}:function(b,a,c){b.detachEvent("on"+a,c)},mc=/([\:\-\_]+(.))/g,nc=/^moz([A-Z])/,ua=Q.prototype={ready:function(b){function a(){c||(c=!0,b())}
  22.118 +var c=!1;this.bind("DOMContentLoaded",a);Q(U).bind("load",a)},toString:function(){var b=[];m(this,function(a){b.push(""+a)});return"["+b.join(", ")+"]"},eq:function(b){return b>=0?u(this[b]):u(this[this.length+b])},length:0,push:Ra,sort:[].sort,splice:[].splice},Ea={};m("multiple,selected,checked,disabled,readOnly,required".split(","),function(b){Ea[E(b)]=b});var zb={};m("input,select,option,textarea,button,form".split(","),function(b){zb[la(b)]=!0});m({data:ub,inheritedData:Da,scope:function(b){return Da(b,
  22.119 +"$scope")},controller:xb,injector:function(b){return Da(b,"$injector")},removeAttr:function(b,a){b.removeAttribute(a)},hasClass:Ca,css:function(b,a,c){a=rb(a);if(v(c))b.style[a]=c;else{var d;aa<=8&&(d=b.currentStyle&&b.currentStyle[a],d===""&&(d="auto"));d=d||b.style[a];aa<=8&&(d=d===""?p:d);return d}},attr:function(b,a,c){var d=E(a);if(Ea[d])if(v(c))c?(b[a]=!0,b.setAttribute(a,d)):(b[a]=!1,b.removeAttribute(d));else return b[a]||(b.attributes.getNamedItem(a)||D).specified?d:p;else if(v(c))b.setAttribute(a,
  22.120 +c);else if(b.getAttribute)return b=b.getAttribute(a,2),b===null?p:b},prop:function(b,a,c){if(v(c))b[a]=c;else return b[a]},text:x(aa<9?function(b,a){if(b.nodeType==1){if(t(a))return b.innerText;b.innerText=a}else{if(t(a))return b.nodeValue;b.nodeValue=a}}:function(b,a){if(t(a))return b.textContent;b.textContent=a},{$dv:""}),val:function(b,a){if(t(a))return b.value;b.value=a},html:function(b,a){if(t(a))return b.innerHTML;for(var c=0,d=b.childNodes;c<d.length;c++)sa(d[c]);b.innerHTML=a}},function(b,
  22.121 +a){Q.prototype[a]=function(a,d){var e,g;if((b.length==2&&b!==Ca&&b!==xb?a:d)===p)if(L(a)){for(e=0;e<this.length;e++)if(b===ub)b(this[e],a);else for(g in a)b(this[e],g,a[g]);return this}else{if(this.length)return b(this[0],a,d)}else{for(e=0;e<this.length;e++)b(this[e],a,d);return this}return b.$dv}});m({removeData:sb,dealoc:sa,bind:function a(c,d,e){var g=$(c,"events"),i=$(c,"handle");g||$(c,"events",g={});i||$(c,"handle",i=pc(c,g));m(d.split(" "),function(d){var h=g[d];if(!h){if(d=="mouseenter"||
  22.122 +d=="mouseleave"){var k=0;g.mouseenter=[];g.mouseleave=[];a(c,"mouseover",function(a){k++;k==1&&i(a,"mouseenter")});a(c,"mouseout",function(a){k--;k==0&&i(a,"mouseleave")})}else Zb(c,d,i),g[d]=[];h=g[d]}h.push(e)})},unbind:tb,replaceWith:function(a,c){var d,e=a.parentNode;sa(a);m(new Q(c),function(c){d?e.insertBefore(c,d.nextSibling):e.replaceChild(c,a);d=c})},children:function(a){var c=[];m(a.childNodes,function(a){a.nodeName!="#text"&&c.push(a)});return c},contents:function(a){return a.childNodes},
  22.123 +append:function(a,c){m(new Q(c),function(c){a.nodeType===1&&a.appendChild(c)})},prepend:function(a,c){if(a.nodeType===1){var d=a.firstChild;m(new Q(c),function(c){d?a.insertBefore(c,d):(a.appendChild(c),d=c)})}},wrap:function(a,c){var c=u(c)[0],d=a.parentNode;d&&d.replaceChild(c,a);c.appendChild(a)},remove:function(a){sa(a);var c=a.parentNode;c&&c.removeChild(a)},after:function(a,c){var d=a,e=a.parentNode;m(new Q(c),function(a){e.insertBefore(a,d.nextSibling);d=a})},addClass:wb,removeClass:vb,toggleClass:function(a,
  22.124 +c,d){t(d)&&(d=!Ca(a,c));(d?wb:vb)(a,c)},parent:function(a){return(a=a.parentNode)&&a.nodeType!==11?a:null},next:function(a){return a.nextSibling},find:function(a,c){return a.getElementsByTagName(c)},clone:cb,triggerHandler:function(a,c){var d=($(a,"events")||{})[c];m(d,function(c){c.call(a,null)})}},function(a,c){Q.prototype[c]=function(c,e){for(var g,i=0;i<this.length;i++)g==p?(g=a(this[i],c,e),g!==p&&(g=u(g))):bb(g,a(this[i],c,e));return g==p?this:g}});Fa.prototype={put:function(a,c){this[ga(a)]=
  22.125 +c},get:function(a){return this[ga(a)]},remove:function(a){var c=this[a=ga(a)];delete this[a];return c}};eb.prototype={push:function(a,c){var d=this[a=ga(a)];d?d.push(c):this[a]=[c]},shift:function(a){var c=this[a=ga(a)];if(c)return c.length==1?(delete this[a],c[0]):c.shift()},peek:function(a){if(a=this[ga(a)])return a[0]}};var rc=/^function\s*[^\(]*\(\s*([^\)]*)\)/m,sc=/,/,tc=/^\s*(_?)(\S+?)\1\s*$/,qc=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg,Db="Non-assignable model expression: ";Bb.$inject=["$provide"];
  22.126 +var Ac=/^(x[\:\-_]|data[\:\-_])/i,Fb=/^([^:]+):\/\/(\w+:{0,1}\w*@)?([\w\.-]*)(:([0-9]+))?(\/[^\?#]*)?(\?([^#]*))?(#(.*))?$/,$b=/^([^\?#]*)?(\?([^#]*))?(#(.*))?$/,Hc=$b,Gb={http:80,https:443,ftp:21};gb.prototype={$$replace:!1,absUrl:Ja("$$absUrl"),url:function(a,c){if(t(a))return this.$$url;var d=$b.exec(a);d[1]&&this.path(decodeURIComponent(d[1]));if(d[2]||d[1])this.search(d[3]||"");this.hash(d[5]||"",c);return this},protocol:Ja("$$protocol"),host:Ja("$$host"),port:Ja("$$port"),path:Ib("$$path",function(a){return a.charAt(0)==
  22.127 +"/"?a:"/"+a}),search:function(a,c){if(t(a))return this.$$search;v(c)?c===null?delete this.$$search[a]:this.$$search[a]=c:this.$$search=F(a)?Xa(a):a;this.$$compose();return this},hash:Ib("$$hash",ma),replace:function(){this.$$replace=!0;return this}};Ia.prototype=ya(gb.prototype);Hb.prototype=ya(Ia.prototype);var Ka={"null":function(){return null},"true":function(){return!0},"false":function(){return!1},undefined:D,"+":function(a,c,d,e){d=d(a,c);e=e(a,c);return v(d)?v(e)?d+e:d:v(e)?e:p},"-":function(a,
  22.128 +c,d,e){d=d(a,c);e=e(a,c);return(v(d)?d:0)-(v(e)?e:0)},"*":function(a,c,d,e){return d(a,c)*e(a,c)},"/":function(a,c,d,e){return d(a,c)/e(a,c)},"%":function(a,c,d,e){return d(a,c)%e(a,c)},"^":function(a,c,d,e){return d(a,c)^e(a,c)},"=":D,"==":function(a,c,d,e){return d(a,c)==e(a,c)},"!=":function(a,c,d,e){return d(a,c)!=e(a,c)},"<":function(a,c,d,e){return d(a,c)<e(a,c)},">":function(a,c,d,e){return d(a,c)>e(a,c)},"<=":function(a,c,d,e){return d(a,c)<=e(a,c)},">=":function(a,c,d,e){return d(a,c)>=e(a,
  22.129 +c)},"&&":function(a,c,d,e){return d(a,c)&&e(a,c)},"||":function(a,c,d,e){return d(a,c)||e(a,c)},"&":function(a,c,d,e){return d(a,c)&e(a,c)},"|":function(a,c,d,e){return e(a,c)(a,c,d(a,c))},"!":function(a,c,d){return!d(a,c)}},Lc={n:"\n",f:"\u000c",r:"\r",t:"\t",v:"\u000b","'":"'",'"':'"'},hb={},Yc=U.XMLHttpRequest||function(){try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(c){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(d){}throw new B("This browser does not support XMLHttpRequest.");
  22.130 +};Pb.$inject=["$provide"];Qb.$inject=["$locale"];Sb.$inject=["$locale"];var Vb=".",hd={yyyy:P("FullYear",4),yy:P("FullYear",2,0,!0),y:P("FullYear",1),MMMM:La("Month"),MMM:La("Month",!0),MM:P("Month",2,1),M:P("Month",1,1),dd:P("Date",2),d:P("Date",1),HH:P("Hours",2),H:P("Hours",1),hh:P("Hours",2,-12),h:P("Hours",1,-12),mm:P("Minutes",2),m:P("Minutes",1),ss:P("Seconds",2),s:P("Seconds",1),EEEE:La("Day"),EEE:La("Day",!0),a:function(a,c){return a.getHours()<12?c.AMPMS[0]:c.AMPMS[1]},Z:function(a){a=a.getTimezoneOffset();
  22.131 +return ib(a/60,2)+ib(Math.abs(a%60),2)}},gd=/((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/,fd=/^\d+$/;Rb.$inject=["$locale"];var dd=I(E),ed=I(la);Tb.$inject=["$parse"];var jd=I({restrict:"E",compile:function(a,c){c.href||c.$set("href","");return function(a,c){c.bind("click",function(a){if(!c.attr("href"))return a.preventDefault(),!1})}}}),kb={};m(Ea,function(a,c){var d=fa("ng-"+c);kb[d]=function(){return{priority:100,compile:function(){return function(a,g,i){a.$watch(i[d],
  22.132 +function(a){i.$set(c,!!a)})}}}}});m(["src","href"],function(a){var c=fa("ng-"+a);kb[c]=function(){return{priority:99,link:function(d,e,g){g.$observe(c,function(c){c&&(g.$set(a,c),aa&&e.prop(a,c))})}}}});var Oa={$addControl:D,$removeControl:D,$setValidity:D,$setDirty:D};Wb.$inject=["$element","$attrs","$scope"];var Ra=function(a){return["$timeout",function(c){var d={name:"form",restrict:"E",controller:Wb,compile:function(){return{pre:function(a,d,i,f){if(!i.action){var h=function(a){a.preventDefault?
  22.133 +a.preventDefault():a.returnValue=!1};Zb(d[0],"submit",h);d.bind("$destroy",function(){c(function(){db(d[0],"submit",h)},0,!1)})}var k=d.parent().controller("form"),j=i.name||i.ngForm;j&&(a[j]=f);k&&d.bind("$destroy",function(){k.$removeControl(f);j&&(a[j]=p);x(f,Oa)})}}}};return a?x(V(d),{restrict:"EAC"}):d}]},kd=Ra(),ld=Ra(!0),md=/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/,nd=/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/,od=/^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/,
  22.134 +ac={text:Qa,number:function(a,c,d,e,g,i){Qa(a,c,d,e,g,i);e.$parsers.push(function(a){var c=T(a);return c||od.test(a)?(e.$setValidity("number",!0),a===""?null:c?a:parseFloat(a)):(e.$setValidity("number",!1),p)});e.$formatters.push(function(a){return T(a)?"":""+a});if(d.min){var f=parseFloat(d.min),a=function(a){return!T(a)&&a<f?(e.$setValidity("min",!1),p):(e.$setValidity("min",!0),a)};e.$parsers.push(a);e.$formatters.push(a)}if(d.max){var h=parseFloat(d.max),d=function(a){return!T(a)&&a>h?(e.$setValidity("max",
  22.135 +!1),p):(e.$setValidity("max",!0),a)};e.$parsers.push(d);e.$formatters.push(d)}e.$formatters.push(function(a){return T(a)||wa(a)?(e.$setValidity("number",!0),a):(e.$setValidity("number",!1),p)})},url:function(a,c,d,e,g,i){Qa(a,c,d,e,g,i);a=function(a){return T(a)||md.test(a)?(e.$setValidity("url",!0),a):(e.$setValidity("url",!1),p)};e.$formatters.push(a);e.$parsers.push(a)},email:function(a,c,d,e,g,i){Qa(a,c,d,e,g,i);a=function(a){return T(a)||nd.test(a)?(e.$setValidity("email",!0),a):(e.$setValidity("email",
  22.136 +!1),p)};e.$formatters.push(a);e.$parsers.push(a)},radio:function(a,c,d,e){t(d.name)&&c.attr("name",xa());c.bind("click",function(){c[0].checked&&a.$apply(function(){e.$setViewValue(d.value)})});e.$render=function(){c[0].checked=d.value==e.$viewValue};d.$observe("value",e.$render)},checkbox:function(a,c,d,e){var g=d.ngTrueValue,i=d.ngFalseValue;F(g)||(g=!0);F(i)||(i=!1);c.bind("click",function(){a.$apply(function(){e.$setViewValue(c[0].checked)})});e.$render=function(){c[0].checked=e.$viewValue};e.$formatters.push(function(a){return a===
  22.137 +g});e.$parsers.push(function(a){return a?g:i})},hidden:D,button:D,submit:D,reset:D},bc=["$browser","$sniffer",function(a,c){return{restrict:"E",require:"?ngModel",link:function(d,e,g,i){i&&(ac[E(g.type)]||ac.text)(d,e,g,i,c,a)}}}],Na="ng-valid",Ma="ng-invalid",Pa="ng-pristine",Xb="ng-dirty",pd=["$scope","$exceptionHandler","$attrs","$element","$parse",function(a,c,d,e,g){function i(a,c){c=c?"-"+$a(c,"-"):"";e.removeClass((a?Ma:Na)+c).addClass((a?Na:Ma)+c)}this.$modelValue=this.$viewValue=Number.NaN;
  22.138 +this.$parsers=[];this.$formatters=[];this.$viewChangeListeners=[];this.$pristine=!0;this.$dirty=!1;this.$valid=!0;this.$invalid=!1;this.$name=d.name;var f=g(d.ngModel),h=f.assign;if(!h)throw B(Db+d.ngModel+" ("+pa(e)+")");this.$render=D;var k=e.inheritedData("$formController")||Oa,j=0,l=this.$error={};e.addClass(Pa);i(!0);this.$setValidity=function(a,c){if(l[a]!==!c){if(c){if(l[a]&&j--,!j)i(!0),this.$valid=!0,this.$invalid=!1}else i(!1),this.$invalid=!0,this.$valid=!1,j++;l[a]=!c;i(c,a);k.$setValidity(a,
  22.139 +c,this)}};this.$setViewValue=function(d){this.$viewValue=d;if(this.$pristine)this.$dirty=!0,this.$pristine=!1,e.removeClass(Pa).addClass(Xb),k.$setDirty();m(this.$parsers,function(a){d=a(d)});if(this.$modelValue!==d)this.$modelValue=d,h(a,d),m(this.$viewChangeListeners,function(a){try{a()}catch(d){c(d)}})};var o=this;a.$watch(function(){var c=f(a);if(o.$modelValue!==c){var d=o.$formatters,e=d.length;for(o.$modelValue=c;e--;)c=d[e](c);if(o.$viewValue!==c)o.$viewValue=c,o.$render()}})}],qd=function(){return{require:["ngModel",
  22.140 +"^?form"],controller:pd,link:function(a,c,d,e){var g=e[0],i=e[1]||Oa;i.$addControl(g);c.bind("$destroy",function(){i.$removeControl(g)})}}},rd=I({require:"ngModel",link:function(a,c,d,e){e.$viewChangeListeners.push(function(){a.$eval(d.ngChange)})}}),cc=function(){return{require:"?ngModel",link:function(a,c,d,e){if(e){d.required=!0;var g=function(a){if(d.required&&(T(a)||a===!1))e.$setValidity("required",!1);else return e.$setValidity("required",!0),a};e.$formatters.push(g);e.$parsers.unshift(g);
  22.141 +d.$observe("required",function(){g(e.$viewValue)})}}}},sd=function(){return{require:"ngModel",link:function(a,c,d,e){var g=(a=/\/(.*)\//.exec(d.ngList))&&RegExp(a[1])||d.ngList||",";e.$parsers.push(function(a){var c=[];a&&m(a.split(g),function(a){a&&c.push(R(a))});return c});e.$formatters.push(function(a){return J(a)?a.join(", "):p})}}},td=/^(true|false|\d+)$/,ud=function(){return{priority:100,compile:function(a,c){return td.test(c.ngValue)?function(a,c,g){g.$set("value",a.$eval(g.ngValue))}:function(a,
  22.142 +c,g){a.$watch(g.ngValue,function(a){g.$set("value",a,!1)})}}}},vd=S(function(a,c,d){c.addClass("ng-binding").data("$binding",d.ngBind);a.$watch(d.ngBind,function(a){c.text(a==p?"":a)})}),wd=["$interpolate",function(a){return function(c,d,e){c=a(d.attr(e.$attr.ngBindTemplate));d.addClass("ng-binding").data("$binding",c);e.$observe("ngBindTemplate",function(a){d.text(a)})}}],xd=[function(){return function(a,c,d){c.addClass("ng-binding").data("$binding",d.ngBindHtmlUnsafe);a.$watch(d.ngBindHtmlUnsafe,
  22.143 +function(a){c.html(a||"")})}}],yd=jb("",!0),zd=jb("Odd",0),Ad=jb("Even",1),Bd=S({compile:function(a,c){c.$set("ngCloak",p);a.removeClass("ng-cloak")}}),Cd=[function(){return{scope:!0,controller:"@"}}],Dd=["$sniffer",function(a){return{priority:1E3,compile:function(){a.csp=!0}}}],dc={};m("click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave".split(" "),function(a){var c=fa("ng-"+a);dc[c]=["$parse",function(d){return function(e,g,i){var f=d(i[c]);g.bind(E(a),function(a){e.$apply(function(){f(e,
  22.144 +{$event:a})})})}}]});var Ed=S(function(a,c,d){c.bind("submit",function(){a.$apply(d.ngSubmit)})}),Fd=["$http","$templateCache","$anchorScroll","$compile",function(a,c,d,e){return{restrict:"ECA",terminal:!0,compile:function(g,i){var f=i.ngInclude||i.src,h=i.onload||"",k=i.autoscroll;return function(g,i){var o=0,m,n=function(){m&&(m.$destroy(),m=null);i.html("")};g.$watch(f,function(f){var p=++o;f?a.get(f,{cache:c}).success(function(a){p===o&&(m&&m.$destroy(),m=g.$new(),i.html(a),e(i.contents())(m),
  22.145 +v(k)&&(!k||g.$eval(k))&&d(),m.$emit("$includeContentLoaded"),g.$eval(h))}).error(function(){p===o&&n()}):n()})}}}}],Gd=S({compile:function(){return{pre:function(a,c,d){a.$eval(d.ngInit)}}}}),Hd=S({terminal:!0,priority:1E3}),Id=["$locale","$interpolate",function(a,c){var d=/{}/g;return{restrict:"EA",link:function(e,g,i){var f=i.count,h=g.attr(i.$attr.when),k=i.offset||0,j=e.$eval(h),l={},o=c.startSymbol(),r=c.endSymbol();m(j,function(a,e){l[e]=c(a.replace(d,o+f+"-"+k+r))});e.$watch(function(){var c=
  22.146 +parseFloat(e.$eval(f));return isNaN(c)?"":(j[c]||(c=a.pluralCat(c-k)),l[c](e,g,!0))},function(a){g.text(a)})}}}],Jd=S({transclude:"element",priority:1E3,terminal:!0,compile:function(a,c,d){return function(a,c,i){var f=i.ngRepeat,i=f.match(/^\s*(.+)\s+in\s+(.*)\s*$/),h,k,j;if(!i)throw B("Expected ngRepeat in form of '_item_ in _collection_' but got '"+f+"'.");f=i[1];h=i[2];i=f.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/);if(!i)throw B("'item' in 'item in collection' should be identifier or (key, value) but got '"+
  22.147 +f+"'.");k=i[3]||i[1];j=i[2];var l=new eb;a.$watch(function(a){var e,f,i=a.$eval(h),m=gc(i,!0),p,u=new eb,C,A,v,t,y=c;if(J(i))v=i||[];else{v=[];for(C in i)i.hasOwnProperty(C)&&C.charAt(0)!="$"&&v.push(C);v.sort()}e=0;for(f=v.length;e<f;e++){C=i===v?e:v[e];A=i[C];if(t=l.shift(A)){p=t.scope;u.push(A,t);if(e!==t.index)t.index=e,y.after(t.element);y=t.element}else p=a.$new();p[k]=A;j&&(p[j]=C);p.$index=e;p.$first=e===0;p.$last=e===m-1;p.$middle=!(p.$first||p.$last);t||d(p,function(a){y.after(a);t={scope:p,
  22.148 +element:y=a,index:e};u.push(A,t)})}for(C in l)if(l.hasOwnProperty(C))for(v=l[C];v.length;)A=v.pop(),A.element.remove(),A.scope.$destroy();l=u})}}}),Kd=S(function(a,c,d){a.$watch(d.ngShow,function(a){c.css("display",Wa(a)?"":"none")})}),Ld=S(function(a,c,d){a.$watch(d.ngHide,function(a){c.css("display",Wa(a)?"none":"")})}),Md=S(function(a,c,d){a.$watch(d.ngStyle,function(a,d){d&&a!==d&&m(d,function(a,d){c.css(d,"")});a&&c.css(a)},!0)}),Nd=I({restrict:"EA",compile:function(a,c){var d=c.ngSwitch||c.on,
  22.149 +e={};a.data("ng-switch",e);return function(a,i){var f,h,k;a.$watch(d,function(d){h&&(k.$destroy(),h.remove(),h=k=null);if(f=e["!"+d]||e["?"])a.$eval(c.change),k=a.$new(),f(k,function(a){h=a;i.append(a)})})}}}),Od=S({transclude:"element",priority:500,compile:function(a,c,d){a=a.inheritedData("ng-switch");qa(a);a["!"+c.ngSwitchWhen]=d}}),Pd=S({transclude:"element",priority:500,compile:function(a,c,d){a=a.inheritedData("ng-switch");qa(a);a["?"]=d}}),Qd=S({controller:["$transclude","$element",function(a,
  22.150 +c){a(function(a){c.append(a)})}]}),Rd=["$http","$templateCache","$route","$anchorScroll","$compile","$controller",function(a,c,d,e,g,i){return{restrict:"ECA",terminal:!0,link:function(a,c,k){function j(){var j=d.current&&d.current.locals,k=j&&j.$template;if(k){c.html(k);l&&(l.$destroy(),l=null);var k=g(c.contents()),p=d.current;l=p.scope=a.$new();if(p.controller)j.$scope=l,j=i(p.controller,j),c.contents().data("$ngControllerController",j);k(l);l.$emit("$viewContentLoaded");l.$eval(m);e()}else c.html(""),
  22.151 +l&&(l.$destroy(),l=null)}var l,m=k.onload||"";a.$on("$routeChangeSuccess",j);j()}}}],Sd=["$templateCache",function(a){return{restrict:"E",terminal:!0,compile:function(c,d){d.type=="text/ng-template"&&a.put(d.id,c[0].text)}}}],Td=I({terminal:!0}),Ud=["$compile","$parse",function(a,c){var d=/^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w\d]*)|(?:\(\s*([\$\w][\$\w\d]*)\s*,\s*([\$\w][\$\w\d]*)\s*\)))\s+in\s+(.*)$/,e={$setViewValue:D};return{restrict:"E",require:["select",
  22.152 +"?ngModel"],controller:["$element","$scope","$attrs",function(a,c,d){var h=this,k={},j=e,l;h.databound=d.ngModel;h.init=function(a,c,d){j=a;l=d};h.addOption=function(c){k[c]=!0;j.$viewValue==c&&(a.val(c),l.parent()&&l.remove())};h.removeOption=function(a){this.hasOption(a)&&(delete k[a],j.$viewValue==a&&this.renderUnknownOption(a))};h.renderUnknownOption=function(c){c="? "+ga(c)+" ?";l.val(c);a.prepend(l);a.val(c);l.prop("selected",!0)};h.hasOption=function(a){return k.hasOwnProperty(a)};c.$on("$destroy",
  22.153 +function(){h.renderUnknownOption=D})}],link:function(e,i,f,h){function k(a,c,d,e){d.$render=function(){var a=d.$viewValue;e.hasOption(a)?(A.parent()&&A.remove(),c.val(a),a===""&&s.prop("selected",!0)):t(a)&&s?c.val(""):e.renderUnknownOption(a)};c.bind("change",function(){a.$apply(function(){A.parent()&&A.remove();d.$setViewValue(c.val())})})}function j(a,c,d){var e;d.$render=function(){var a=new Fa(d.$viewValue);m(c.children(),function(c){c.selected=v(a.get(c.value))})};a.$watch(function(){ha(e,d.$viewValue)||
  22.154 +(e=V(d.$viewValue),d.$render())});c.bind("change",function(){a.$apply(function(){var a=[];m(c.children(),function(c){c.selected&&a.push(c.value)});d.$setViewValue(a)})})}function l(e,f,g){function h(){var a={"":[]},c=[""],d,i,s,t,u;s=g.$modelValue;t=r(e)||[];var y=l?lb(t):t,A,w,x;w={};u=!1;var z,B;if(n)u=new Fa(s);else if(s===null||q)a[""].push({selected:s===null,id:"",label:""}),u=!0;for(x=0;A=y.length,x<A;x++){w[k]=t[l?w[l]=y[x]:x];d=m(e,w)||"";if(!(i=a[d]))i=a[d]=[],c.push(d);n?d=u.remove(o(e,
  22.155 +w))!=p:(d=s===o(e,w),u=u||d);z=j(e,w);z=z===p?"":z;i.push({id:l?y[x]:x,label:z,selected:d})}!n&&!u&&a[""].unshift({id:"?",label:"",selected:!0});w=0;for(y=c.length;w<y;w++){d=c[w];i=a[d];if(v.length<=w)s={element:C.clone().attr("label",d),label:i.label},t=[s],v.push(t),f.append(s.element);else if(t=v[w],s=t[0],s.label!=d)s.element.attr("label",s.label=d);z=null;x=0;for(A=i.length;x<A;x++)if(d=i[x],u=t[x+1]){z=u.element;if(u.label!==d.label)z.text(u.label=d.label);if(u.id!==d.id)z.val(u.id=d.id);if(u.element.selected!==
  22.156 +d.selected)z.prop("selected",u.selected=d.selected)}else d.id===""&&q?B=q:(B=D.clone()).val(d.id).attr("selected",d.selected).text(d.label),t.push({element:B,label:d.label,id:d.id,selected:d.selected}),z?z.after(B):s.element.append(B),z=B;for(x++;t.length>x;)t.pop().element.remove()}for(;v.length>w;)v.pop()[0].element.remove()}var i;if(!(i=w.match(d)))throw B("Expected ngOptions in form of '_select_ (as _label_)? for (_key_,)?_value_ in _collection_' but got '"+w+"'.");var j=c(i[2]||i[1]),k=i[4]||
  22.157 +i[6],l=i[5],m=c(i[3]||""),o=c(i[2]?i[1]:k),r=c(i[7]),v=[[{element:f,label:""}]];q&&(a(q)(e),q.removeClass("ng-scope"),q.remove());f.html("");f.bind("change",function(){e.$apply(function(){var a,c=r(e)||[],d={},h,i,j,m,q,s;if(n){i=[];m=0;for(s=v.length;m<s;m++){a=v[m];j=1;for(q=a.length;j<q;j++)if((h=a[j].element)[0].selected)h=h.val(),l&&(d[l]=h),d[k]=c[h],i.push(o(e,d))}}else h=f.val(),h=="?"?i=p:h==""?i=null:(d[k]=c[h],l&&(d[l]=h),i=o(e,d));g.$setViewValue(i)})});g.$render=h;e.$watch(h)}if(h[1]){for(var o=
  22.158 +h[0],r=h[1],n=f.multiple,w=f.ngOptions,q=!1,s,D=u(ca.createElement("option")),C=u(ca.createElement("optgroup")),A=D.clone(),h=0,x=i.children(),E=x.length;h<E;h++)if(x[h].value==""){s=q=x.eq(h);break}o.init(r,q,A);if(n&&(f.required||f.ngRequired)){var y=function(a){r.$setValidity("required",!f.required||a&&a.length);return a};r.$parsers.push(y);r.$formatters.unshift(y);f.$observe("required",function(){y(r.$viewValue)})}w?l(e,i,r):n?j(e,i,r):k(e,i,r,o)}}}}],Vd=["$interpolate",function(a){var c={addOption:D,
  22.159 +removeOption:D};return{restrict:"E",priority:100,compile:function(d,e){if(t(e.value)){var g=a(d.text(),!0);g||e.$set("value",d.text())}return function(a,d,e){var k=d.parent(),j=k.data("$selectController")||k.parent().data("$selectController");j&&j.databound?d.prop("selected",!1):j=c;g?a.$watch(g,function(a,c){e.$set("value",a);a!==c&&j.removeOption(c);j.addOption(a)}):j.addOption(e.value);d.bind("$destroy",function(){j.removeOption(e.value)})}}}}],Wd=I({restrict:"E",terminal:!0});(ja=U.jQuery)?(u=
  22.160 +ja,x(ja.fn,{scope:ua.scope,controller:ua.controller,injector:ua.injector,inheritedData:ua.inheritedData}),ab("remove",!0),ab("empty"),ab("html")):u=Q;Yb.element=u;(function(a){x(a,{bootstrap:pb,copy:V,extend:x,equals:ha,element:u,forEach:m,injector:qb,noop:D,bind:Va,toJson:da,fromJson:nb,identity:ma,isUndefined:t,isDefined:v,isString:F,isFunction:N,isObject:L,isNumber:wa,isElement:fc,isArray:J,version:id,isDate:na,lowercase:E,uppercase:la,callbacks:{counter:0}});ta=lc(U);try{ta("ngLocale")}catch(c){ta("ngLocale",
  22.161 +[]).provider("$locale",Zc)}ta("ng",["ngLocale"],["$provide",function(a){a.provider("$compile",Bb).directive({a:jd,input:bc,textarea:bc,form:kd,script:Sd,select:Ud,style:Wd,option:Vd,ngBind:vd,ngBindHtmlUnsafe:xd,ngBindTemplate:wd,ngClass:yd,ngClassEven:Ad,ngClassOdd:zd,ngCsp:Dd,ngCloak:Bd,ngController:Cd,ngForm:ld,ngHide:Ld,ngInclude:Fd,ngInit:Gd,ngNonBindable:Hd,ngPluralize:Id,ngRepeat:Jd,ngShow:Kd,ngSubmit:Ed,ngStyle:Md,ngSwitch:Nd,ngSwitchWhen:Od,ngSwitchDefault:Pd,ngOptions:Td,ngView:Rd,ngTransclude:Qd,
  22.162 +ngModel:qd,ngList:sd,ngChange:rd,required:cc,ngRequired:cc,ngValue:ud}).directive(kb).directive(dc);a.provider({$anchorScroll:uc,$browser:wc,$cacheFactory:xc,$controller:Bc,$document:Cc,$exceptionHandler:Dc,$filter:Pb,$interpolate:Ec,$http:Vc,$httpBackend:Wc,$location:Ic,$log:Jc,$parse:Nc,$route:Qc,$routeParams:Rc,$rootScope:Sc,$q:Oc,$sniffer:Tc,$templateCache:yc,$timeout:$c,$window:Uc})}])})(Yb);u(ca).ready(function(){jc(ca,pb)})})(window,document);angular.element(document).find("head").append('<style type="text/css">@charset "UTF-8";[ng\\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak{display:none;}ng\\:form{display:block;}</style>');
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/app.js	Sun Feb 03 07:48:42 2013 +0100
    23.3 @@ -0,0 +1,224 @@
    23.4 +// 'use strict';
    23.5 +
    23.6 +// Declare app level module which depends on filters, and services
    23.7 +angular.module('bck2brwsr', []).
    23.8 +  directive('uiCodemirror', ['$timeout', function($timeout) {
    23.9 +        'use strict';
   23.10 +
   23.11 +        var events = ["cursorActivity", "viewportChange", "gutterClick", "focus", "blur", "scroll", "update"];
   23.12 +        return {
   23.13 +            restrict: 'A',
   23.14 +            require: 'ngModel',
   23.15 +            link: function(scope, elm, attrs, ngModel) {
   23.16 +                var options, opts, onChange, deferCodeMirror, codeMirror, timeoutId, val;
   23.17 +
   23.18 +                if (elm[0].type !== 'textarea') {
   23.19 +                    throw new Error('uiCodemirror3 can only be applied to a textarea element');
   23.20 +                }
   23.21 +
   23.22 +                options = /* uiConfig.codemirror  || */ {};
   23.23 +                opts = angular.extend({}, options, scope.$eval(attrs.uiCodemirror));
   23.24 +
   23.25 +                onChange = function(instance, changeObj) {                    
   23.26 +                    val = instance.getValue();
   23.27 +                    $timeout.cancel(timeoutId);
   23.28 +                    timeoutId = $timeout(function() {
   23.29 +                        ngModel.$setViewValue(val);                        
   23.30 +                      }, 500);                    
   23.31 +                };
   23.32 +                
   23.33 +                deferCodeMirror = function() {
   23.34 +                    codeMirror = CodeMirror.fromTextArea(elm[0], opts);
   23.35 +                    elm[0].codeMirror = codeMirror;
   23.36 +                    // codeMirror.on("change", onChange(opts.onChange));
   23.37 +                    codeMirror.on("change", onChange);
   23.38 +
   23.39 +                    for (var i = 0, n = events.length, aEvent; i < n; ++i) {
   23.40 +                        aEvent = opts["on" + events[i].charAt(0).toUpperCase() + events[i].slice(1)];
   23.41 +                        if (aEvent === void 0)
   23.42 +                            continue;
   23.43 +                        if (typeof aEvent !== "function")
   23.44 +                            continue;
   23.45 +                                                
   23.46 +                        var bound = _.bind( aEvent, scope );
   23.47 +                        
   23.48 +                        codeMirror.on(events[i], bound);
   23.49 +                    }
   23.50 +
   23.51 +                    // CodeMirror expects a string, so make sure it gets one.
   23.52 +                    // This does not change the model.
   23.53 +                    ngModel.$formatters.push(function(value) {
   23.54 +                        if (angular.isUndefined(value) || value === null) {
   23.55 +                            return '';
   23.56 +                        }
   23.57 +                        else if (angular.isObject(value) || angular.isArray(value)) {
   23.58 +                            throw new Error('ui-codemirror cannot use an object or an array as a model');
   23.59 +                        }
   23.60 +                        return value;
   23.61 +                    });
   23.62 +
   23.63 +                    // Override the ngModelController $render method, which is what gets called when the model is updated.
   23.64 +                    // This takes care of the synchronizing the codeMirror element with the underlying model, in the case that it is changed by something else.
   23.65 +                    ngModel.$render = function() {
   23.66 +                        codeMirror.setValue(ngModel.$viewValue);
   23.67 +                    };
   23.68 +
   23.69 +                };
   23.70 +
   23.71 +                $timeout(deferCodeMirror);
   23.72 +
   23.73 +            }
   23.74 +        };
   23.75 +}]);
   23.76 +
   23.77 +function DevCtrl( $scope, $http ) {
   23.78 +    var templateHtml = 
   23.79 +"<html><body>\n" +
   23.80 +"  <input data-bind=\"value: value, valueUpdate: 'afterkeydown'\" \n" +
   23.81 +"     value=\"0\" type=\"number\">\n" +
   23.82 +"  </input>\n" +
   23.83 +"  * <span data-bind=\"text: value\">0</span> \n" +
   23.84 +"  = <span data-bind=\"text: powerValue\">0</span>\n" +
   23.85 +"  <br/>\n" +
   23.86 +"  <button id='dupl'>Duplicate!</button>\n" +
   23.87 +"  <button id=\"clear\">Clear!</button>" +
   23.88 +" <hr/>\n" +
   23.89 +"\n" +
   23.90 +"\n" +
   23.91 +"\n" +
   23.92 +"\n" +
   23.93 +"\n" +
   23.94 +"\n" +
   23.95 +"\n" +
   23.96 +"\n" +
   23.97 +"\n" +
   23.98 +"\n" +
   23.99 +"\n" +
  23.100 +"\n" +
  23.101 +"\n" +
  23.102 +"\n" +
  23.103 +"\n" +
  23.104 +"\n" +
  23.105 +"\n" +
  23.106 +"\n" +
  23.107 +"\n" +
  23.108 +"\n" +
  23.109 +" <script src=\"/bck2brwsr.js\"></script>\n" +
  23.110 +" <script type=\"text/javascript\">\n" +
  23.111 +"   function ldCls(res) {\n" +
  23.112 +"     var request = new XMLHttpRequest();\n" +
  23.113 +"     request.open('GET', '/classes/' + res, false);\n" +
  23.114 +"     request.send();\n" +
  23.115 +"     var arr = eval('(' + request.responseText + ')');\n" +
  23.116 +"     return arr;\n" +
  23.117 +"   }\n" +
  23.118 +"   var vm = new bck2brwsr(ldCls);\n" +
  23.119 +"   vm.loadClass('${fqn}');\n" +
  23.120 +" </script>\n" +
  23.121 +"</body></html>";
  23.122 +    var templateJava = 
  23.123 +"package bck2brwsr.demo;\n" +
  23.124 +"import org.apidesign.bck2brwsr.htmlpage.api.*;\n" +
  23.125 +"import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;\n" +
  23.126 +"\n" +
  23.127 +"@Page(xhtml=\"index.html\", className=\"Index\", properties={\n" +
  23.128 +"  @Property(name=\"value\", type=int.class)\n" +
  23.129 +"})\n" +
  23.130 +"class YourFirstHTML5PageInRealLanguage {\n" +
  23.131 +"  static { new Index().applyBindings(); }\n" +
  23.132 +"  @On(event=CLICK, id=\"dupl\") static void duplicateValue(Index m) {\n" +
  23.133 +"    m.setValue(m.getValue() * 2);\n" +
  23.134 +"  }\n" +
  23.135 +"  @On(event=CLICK, id=\"clear\") static void zeroTheValue(Index m) {\n" +
  23.136 +"     m.setValue(0);;\n" +
  23.137 +"  }\n" +
  23.138 +"  @ComputedProperty static int powerValue(int value) {\n" +
  23.139 +"    return value * value;\n" +
  23.140 +"  }\n" +
  23.141 +"}";
  23.142 +
  23.143 +    
  23.144 +    $scope.makeMarker = function( editor, line ) {
  23.145 +        var marker = document.createElement("div");
  23.146 +        marker.innerHTML = " ";
  23.147 +        marker.className = "issue";
  23.148 +        
  23.149 +        var info = editor.lineInfo(line);
  23.150 +        editor.setGutterMarker(line, "issues", info.markers ? null : marker);
  23.151 +        
  23.152 +        return marker;
  23.153 +    };
  23.154 +    
  23.155 +    
  23.156 +    // Returns a function, that, as long as it continues to be invoked, will not
  23.157 +    // be triggered. The function will be called after it stops being called for
  23.158 +    // N milliseconds. If `immediate` is passed, trigger the function on the
  23.159 +    // leading edge, instead of the trailing.
  23.160 +    $scope.debounce = function(func, wait, immediate) {
  23.161 +      var timeout, result;
  23.162 +      return function() {
  23.163 +        var context = this, args = arguments;
  23.164 +        var later = function() {
  23.165 +          timeout = null;
  23.166 +          if (!immediate) result = func.apply(context, args);
  23.167 +        };
  23.168 +        var callNow = immediate && !timeout;
  23.169 +        clearTimeout(timeout);
  23.170 +        timeout = setTimeout(later, wait);
  23.171 +        if (callNow) result = func.apply(context, args);
  23.172 +        return result;
  23.173 +      };
  23.174 +    };
  23.175 +    
  23.176 +    $scope.reload = function() {
  23.177 +        $scope.errors = null;
  23.178 +        var frame = document.getElementById("result");        
  23.179 +        frame.src = "result.html";
  23.180 +        frame.contentDocument.location.reload(true);
  23.181 +        frame.contentWindow.location.reload();
  23.182 +        document.getElementById("editorJava").codeMirror.clearGutter("issues");   
  23.183 +    };
  23.184 +    
  23.185 +    $scope.fail = function( data ) {
  23.186 +        $scope.errors = eval( data );
  23.187 +        var editor = document.getElementById("editorJava").codeMirror;   
  23.188 +        editor.clearGutter( "issues" );
  23.189 +        
  23.190 +        for( var i = 0; i < $scope.errors.length; i ++ ) {
  23.191 +            $scope.makeMarker( editor, $scope.errors[i].line - 1 );
  23.192 +        }
  23.193 +        
  23.194 +    };
  23.195 +    
  23.196 +    $scope.post = function() {
  23.197 +        return $http({url: ".",
  23.198 +            method: "POST",
  23.199 +            //headers: this.headers,
  23.200 +            data: { html : $scope.html, java : $scope.java} 
  23.201 +        }).success( $scope.reload ).error( $scope.fail );
  23.202 +    };
  23.203 +    
  23.204 +    $scope.errorClass = function( kind ) {
  23.205 +        switch( kind ) {
  23.206 +            case "ERROR" :
  23.207 +                return "error";
  23.208 +            default :         
  23.209 +                return "warning";   
  23.210 +        }
  23.211 +    };
  23.212 +    
  23.213 +    $scope.gotoError = function( line, col ) {
  23.214 +        var editor = document.getElementById("editorJava").codeMirror;   
  23.215 +        editor.setCursor({ line: line - 1, ch : col - 1 });
  23.216 +        editor.focus();
  23.217 +    };
  23.218 +    
  23.219 +    $scope.tab = "html";
  23.220 +    $scope.html= templateHtml;  
  23.221 +    $scope.java = templateJava;  
  23.222 +    
  23.223 +    $scope.$watch( "html", $scope.debounce( $scope.post, 2000 ) );
  23.224 +    $scope.$watch( "java", $scope.debounce( $scope.post, 2000 ) );
  23.225 +    $scope.post();
  23.226 +    
  23.227 +}
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/codemirror.css	Sun Feb 03 07:48:42 2013 +0100
    24.3 @@ -0,0 +1,239 @@
    24.4 +/* BASICS */
    24.5 +
    24.6 +.CodeMirror {
    24.7 +  /* Set height, width, borders, and global font properties here */
    24.8 +  font-family: monospace;
    24.9 +  height: 300px;
   24.10 +}
   24.11 +.CodeMirror-scroll {
   24.12 +  /* Set scrolling behaviour here */
   24.13 +  overflow: auto;
   24.14 +}
   24.15 +
   24.16 +/* PADDING */
   24.17 +
   24.18 +.CodeMirror-lines {
   24.19 +  padding: 4px 0; /* Vertical padding around content */
   24.20 +}
   24.21 +.CodeMirror pre {
   24.22 +  padding: 0 4px; /* Horizontal padding of content */
   24.23 +}
   24.24 +
   24.25 +.CodeMirror-scrollbar-filler {
   24.26 +  background-color: white; /* The little square between H and V scrollbars */
   24.27 +}
   24.28 +
   24.29 +/* GUTTER */
   24.30 +
   24.31 +.CodeMirror-gutters {
   24.32 +  border-right: 1px solid #ddd;
   24.33 +  background-color: #f7f7f7;
   24.34 +}
   24.35 +.CodeMirror-linenumbers {}
   24.36 +.CodeMirror-linenumber {
   24.37 +  padding: 0 3px 0 5px;
   24.38 +  min-width: 20px;
   24.39 +  text-align: right;
   24.40 +  color: #999;
   24.41 +}
   24.42 +
   24.43 +/* CURSOR */
   24.44 +
   24.45 +.CodeMirror pre.CodeMirror-cursor {
   24.46 +  border-left: 1px solid black;
   24.47 +}
   24.48 +/* Shown when moving in bi-directional text */
   24.49 +.CodeMirror pre.CodeMirror-secondarycursor {
   24.50 +  border-left: 1px solid silver;
   24.51 +}
   24.52 +.cm-keymap-fat-cursor pre.CodeMirror-cursor {
   24.53 +  width: auto;
   24.54 +  border: 0;
   24.55 +  background: transparent;
   24.56 +  background: rgba(0, 200, 0, .4);
   24.57 +  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#6600c800, endColorstr=#4c00c800);
   24.58 +}
   24.59 +/* Kludge to turn off filter in ie9+, which also accepts rgba */
   24.60 +.cm-keymap-fat-cursor pre.CodeMirror-cursor:not(#nonsense_id) {
   24.61 +  filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
   24.62 +}
   24.63 +/* Can style cursor different in overwrite (non-insert) mode */
   24.64 +.CodeMirror pre.CodeMirror-cursor.CodeMirror-overwrite {}
   24.65 +
   24.66 +/* DEFAULT THEME */
   24.67 +
   24.68 +.cm-s-default .cm-keyword {color: #708;}
   24.69 +.cm-s-default .cm-atom {color: #219;}
   24.70 +.cm-s-default .cm-number {color: #164;}
   24.71 +.cm-s-default .cm-def {color: #00f;}
   24.72 +.cm-s-default .cm-variable {color: black;}
   24.73 +.cm-s-default .cm-variable-2 {color: #05a;}
   24.74 +.cm-s-default .cm-variable-3 {color: #085;}
   24.75 +.cm-s-default .cm-property {color: black;}
   24.76 +.cm-s-default .cm-operator {color: black;}
   24.77 +.cm-s-default .cm-comment {color: #a50;}
   24.78 +.cm-s-default .cm-string {color: #a11;}
   24.79 +.cm-s-default .cm-string-2 {color: #f50;}
   24.80 +.cm-s-default .cm-meta {color: #555;}
   24.81 +.cm-s-default .cm-error {color: #f00;}
   24.82 +.cm-s-default .cm-qualifier {color: #555;}
   24.83 +.cm-s-default .cm-builtin {color: #30a;}
   24.84 +.cm-s-default .cm-bracket {color: #997;}
   24.85 +.cm-s-default .cm-tag {color: #170;}
   24.86 +.cm-s-default .cm-attribute {color: #00c;}
   24.87 +.cm-s-default .cm-header {color: blue;}
   24.88 +.cm-s-default .cm-quote {color: #090;}
   24.89 +.cm-s-default .cm-hr {color: #999;}
   24.90 +.cm-s-default .cm-link {color: #00c;}
   24.91 +
   24.92 +.cm-negative {color: #d44;}
   24.93 +.cm-positive {color: #292;}
   24.94 +.cm-header, .cm-strong {font-weight: bold;}
   24.95 +.cm-em {font-style: italic;}
   24.96 +.cm-emstrong {font-style: italic; font-weight: bold;}
   24.97 +.cm-link {text-decoration: underline;}
   24.98 +
   24.99 +.cm-invalidchar {color: #f00;}
  24.100 +
  24.101 +div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
  24.102 +div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
  24.103 +
  24.104 +/* STOP */
  24.105 +
  24.106 +/* The rest of this file contains styles related to the mechanics of
  24.107 +   the editor. You probably shouldn't touch them. */
  24.108 +
  24.109 +.CodeMirror {
  24.110 +  line-height: 1;
  24.111 +  position: relative;
  24.112 +  overflow: hidden;
  24.113 +}
  24.114 +
  24.115 +.CodeMirror-scroll {
  24.116 +  /* 30px is the magic margin used to hide the element's real scrollbars */
  24.117 +  /* See overflow: hidden in .CodeMirror, and the paddings in .CodeMirror-sizer */
  24.118 +  margin-bottom: -30px; margin-right: -30px;
  24.119 +  padding-bottom: 30px; padding-right: 30px;
  24.120 +  height: 100%;
  24.121 +  outline: none; /* Prevent dragging from highlighting the element */
  24.122 +  position: relative;
  24.123 +}
  24.124 +.CodeMirror-sizer {
  24.125 +  position: relative;
  24.126 +}
  24.127 +
  24.128 +/* The fake, visible scrollbars. Used to force redraw during scrolling
  24.129 +   before actuall scrolling happens, thus preventing shaking and
  24.130 +   flickering artifacts. */
  24.131 +.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler {
  24.132 +  position: absolute;
  24.133 +  z-index: 6;
  24.134 +  display: none;
  24.135 +}
  24.136 +.CodeMirror-vscrollbar {
  24.137 +  right: 0; top: 0;
  24.138 +  overflow-x: hidden;
  24.139 +  overflow-y: scroll;
  24.140 +}
  24.141 +.CodeMirror-hscrollbar {
  24.142 +  bottom: 0; left: 0;
  24.143 +  overflow-y: hidden;
  24.144 +  overflow-x: scroll;
  24.145 +}
  24.146 +.CodeMirror-scrollbar-filler {
  24.147 +  right: 0; bottom: 0;
  24.148 +  z-index: 6;
  24.149 +}
  24.150 +
  24.151 +.CodeMirror-gutters {
  24.152 +  position: absolute; left: 0; top: 0;
  24.153 +  height: 100%;
  24.154 +  z-index: 3;
  24.155 +}
  24.156 +.CodeMirror-gutter {
  24.157 +  height: 100%;
  24.158 +  display: inline-block;
  24.159 +  /* Hack to make IE7 behave */
  24.160 +  *zoom:1;
  24.161 +  *display:inline;
  24.162 +}
  24.163 +.CodeMirror-gutter-elt {
  24.164 +  position: absolute;
  24.165 +  cursor: default;
  24.166 +  z-index: 4;
  24.167 +}
  24.168 +
  24.169 +.CodeMirror-lines {
  24.170 +  cursor: text;
  24.171 +}
  24.172 +.CodeMirror pre {
  24.173 +  /* Reset some styles that the rest of the page might have set */
  24.174 +  -moz-border-radius: 0; -webkit-border-radius: 0; -o-border-radius: 0; border-radius: 0;
  24.175 +  border-width: 0;
  24.176 +  background: transparent;
  24.177 +  font-family: inherit;
  24.178 +  font-size: inherit;
  24.179 +  margin: 0;
  24.180 +  white-space: pre;
  24.181 +  word-wrap: normal;
  24.182 +  line-height: inherit;
  24.183 +  color: inherit;
  24.184 +  z-index: 2;
  24.185 +  position: relative;
  24.186 +  overflow: visible;
  24.187 +}
  24.188 +.CodeMirror-wrap pre {
  24.189 +  word-wrap: break-word;
  24.190 +  white-space: pre-wrap;
  24.191 +  word-break: normal;
  24.192 +}
  24.193 +.CodeMirror-linebackground {
  24.194 +  position: absolute;
  24.195 +  left: 0; right: 0; top: 0; bottom: 0;
  24.196 +  z-index: 0;
  24.197 +}
  24.198 +
  24.199 +.CodeMirror-linewidget {
  24.200 +  position: relative;
  24.201 +  z-index: 2;
  24.202 +}
  24.203 +
  24.204 +.CodeMirror-wrap .CodeMirror-scroll {
  24.205 +  overflow-x: hidden;
  24.206 +}
  24.207 +
  24.208 +.CodeMirror-measure {
  24.209 +  position: absolute;
  24.210 +  width: 100%; height: 0px;
  24.211 +  overflow: hidden;
  24.212 +  visibility: hidden;
  24.213 +}
  24.214 +.CodeMirror-measure pre { position: static; }
  24.215 +
  24.216 +.CodeMirror pre.CodeMirror-cursor {
  24.217 +  position: absolute;
  24.218 +  visibility: hidden;
  24.219 +  border-right: none;
  24.220 +  width: 0;
  24.221 +}
  24.222 +.CodeMirror-focused pre.CodeMirror-cursor {
  24.223 +  visibility: visible;
  24.224 +}
  24.225 +
  24.226 +.CodeMirror-selected { background: #d9d9d9; }
  24.227 +.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
  24.228 +
  24.229 +.CodeMirror-searching {
  24.230 +  background: #ffa;
  24.231 +  background: rgba(255, 255, 0, .4);
  24.232 +}
  24.233 +
  24.234 +/* IE7 hack to prevent it from returning funny offsetTops on the spans */
  24.235 +.CodeMirror span { *vertical-align: text-bottom; }
  24.236 +
  24.237 +@media print {
  24.238 +  /* Hide the cursor when printing */
  24.239 +  .CodeMirror pre.CodeMirror-cursor {
  24.240 +    visibility: hidden;
  24.241 +  }
  24.242 +}
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/codemirror.js	Sun Feb 03 07:48:42 2013 +0100
    25.3 @@ -0,0 +1,4553 @@
    25.4 +// CodeMirror version 3.0
    25.5 +//
    25.6 +// CodeMirror is the only global var we claim
    25.7 +window.CodeMirror = (function() {
    25.8 +  "use strict";
    25.9 +
   25.10 +  // BROWSER SNIFFING
   25.11 +
   25.12 +  // Crude, but necessary to handle a number of hard-to-feature-detect
   25.13 +  // bugs and behavior differences.
   25.14 +  var gecko = /gecko\/\d/i.test(navigator.userAgent);
   25.15 +  var ie = /MSIE \d/.test(navigator.userAgent);
   25.16 +  var ie_lt8 = /MSIE [1-7]\b/.test(navigator.userAgent);
   25.17 +  var ie_lt9 = /MSIE [1-8]\b/.test(navigator.userAgent);
   25.18 +  var webkit = /WebKit\//.test(navigator.userAgent);
   25.19 +  var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(navigator.userAgent);
   25.20 +  var chrome = /Chrome\//.test(navigator.userAgent);
   25.21 +  var opera = /Opera\//.test(navigator.userAgent);
   25.22 +  var safari = /Apple Computer/.test(navigator.vendor);
   25.23 +  var khtml = /KHTML\//.test(navigator.userAgent);
   25.24 +  var mac_geLion = /Mac OS X 1\d\D([7-9]|\d\d)\D/.test(navigator.userAgent);
   25.25 +  var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent);
   25.26 +  var phantom = /PhantomJS/.test(navigator.userAgent);
   25.27 +
   25.28 +  var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
   25.29 +  // This is woefully incomplete. Suggestions for alternative methods welcome.
   25.30 +  var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent);
   25.31 +  var mac = ios || /Mac/.test(navigator.platform);
   25.32 +
   25.33 +  // Optimize some code when these features are not used
   25.34 +  var sawReadOnlySpans = false, sawCollapsedSpans = false;
   25.35 +
   25.36 +  // CONSTRUCTOR
   25.37 +
   25.38 +  function CodeMirror(place, options) {
   25.39 +    if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
   25.40 +    
   25.41 +    this.options = options = options || {};
   25.42 +    // Determine effective options based on given values and defaults.
   25.43 +    for (var opt in defaults) if (!options.hasOwnProperty(opt) && defaults.hasOwnProperty(opt))
   25.44 +      options[opt] = defaults[opt];
   25.45 +    setGuttersForLineNumbers(options);
   25.46 +
   25.47 +    var display = this.display = makeDisplay(place);
   25.48 +    display.wrapper.CodeMirror = this;
   25.49 +    updateGutters(this);
   25.50 +    if (options.autofocus && !mobile) focusInput(this);
   25.51 +
   25.52 +    this.view = makeView(new BranchChunk([new LeafChunk([makeLine("", null, textHeight(display))])]));
   25.53 +    this.nextOpId = 0;
   25.54 +    loadMode(this);
   25.55 +    themeChanged(this);
   25.56 +    if (options.lineWrapping)
   25.57 +      this.display.wrapper.className += " CodeMirror-wrap";
   25.58 +
   25.59 +    // Initialize the content.
   25.60 +    this.setValue(options.value || "");
   25.61 +    // Override magic textarea content restore that IE sometimes does
   25.62 +    // on our hidden textarea on reload
   25.63 +    if (ie) setTimeout(bind(resetInput, this, true), 20);
   25.64 +    this.view.history = makeHistory();
   25.65 +
   25.66 +    registerEventHandlers(this);
   25.67 +    // IE throws unspecified error in certain cases, when
   25.68 +    // trying to access activeElement before onload
   25.69 +    var hasFocus; try { hasFocus = (document.activeElement == display.input); } catch(e) { }
   25.70 +    if (hasFocus || (options.autofocus && !mobile)) setTimeout(bind(onFocus, this), 20);
   25.71 +    else onBlur(this);
   25.72 +
   25.73 +    operation(this, function() {
   25.74 +      for (var opt in optionHandlers)
   25.75 +        if (optionHandlers.propertyIsEnumerable(opt))
   25.76 +          optionHandlers[opt](this, options[opt], Init);
   25.77 +      for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
   25.78 +    })();
   25.79 +  }
   25.80 +
   25.81 +  // DISPLAY CONSTRUCTOR
   25.82 +
   25.83 +  function makeDisplay(place) {
   25.84 +    var d = {};
   25.85 +    var input = d.input = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none;");
   25.86 +    input.setAttribute("wrap", "off"); input.setAttribute("autocorrect", "off"); input.setAttribute("autocapitalize", "off");
   25.87 +    // Wraps and hides input textarea
   25.88 +    d.inputDiv = elt("div", [input], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
   25.89 +    // The actual fake scrollbars.
   25.90 +    d.scrollbarH = elt("div", [elt("div", null, null, "height: 1px")], "CodeMirror-hscrollbar");
   25.91 +    d.scrollbarV = elt("div", [elt("div", null, null, "width: 1px")], "CodeMirror-vscrollbar");
   25.92 +    d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
   25.93 +    // DIVs containing the selection and the actual code
   25.94 +    d.lineDiv = elt("div");
   25.95 +    d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
   25.96 +    // Blinky cursor, and element used to ensure cursor fits at the end of a line
   25.97 +    d.cursor = elt("pre", "\u00a0", "CodeMirror-cursor");
   25.98 +    // Secondary cursor, shown when on a 'jump' in bi-directional text
   25.99 +    d.otherCursor = elt("pre", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor");
  25.100 +    // Used to measure text size
  25.101 +    d.measure = elt("div", null, "CodeMirror-measure");
  25.102 +    // Wraps everything that needs to exist inside the vertically-padded coordinate system
  25.103 +    d.lineSpace = elt("div", [d.measure, d.selectionDiv, d.lineDiv, d.cursor, d.otherCursor],
  25.104 +                         null, "position: relative; outline: none");
  25.105 +    // Moved around its parent to cover visible view
  25.106 +    d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative");
  25.107 +    // Set to the height of the text, causes scrolling
  25.108 +    d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
  25.109 +    // D is needed because behavior of elts with overflow: auto and padding is inconsistent across browsers
  25.110 +    d.heightForcer = elt("div", "\u00a0", null, "position: absolute; height: " + scrollerCutOff + "px");
  25.111 +    // Will contain the gutters, if any
  25.112 +    d.gutters = elt("div", null, "CodeMirror-gutters");
  25.113 +    d.lineGutter = null;
  25.114 +    // Helper element to properly size the gutter backgrounds
  25.115 +    var scrollerInner = elt("div", [d.sizer, d.heightForcer, d.gutters], null, "position: relative; min-height: 100%");
  25.116 +    // Provides scrolling
  25.117 +    d.scroller = elt("div", [scrollerInner], "CodeMirror-scroll");
  25.118 +    d.scroller.setAttribute("tabIndex", "-1");
  25.119 +    // The element in which the editor lives.
  25.120 +    d.wrapper = elt("div", [d.inputDiv, d.scrollbarH, d.scrollbarV,
  25.121 +                            d.scrollbarFiller, d.scroller], "CodeMirror");
  25.122 +    // Work around IE7 z-index bug
  25.123 +    if (ie_lt8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
  25.124 +    if (place.appendChild) place.appendChild(d.wrapper); else place(d.wrapper);
  25.125 +
  25.126 +    // Needed to hide big blue blinking cursor on Mobile Safari
  25.127 +    if (ios) input.style.width = "0px";
  25.128 +    if (!webkit) d.scroller.draggable = true;
  25.129 +    // Needed to handle Tab key in KHTML
  25.130 +    if (khtml) { d.inputDiv.style.height = "1px"; d.inputDiv.style.position = "absolute"; }
  25.131 +    // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
  25.132 +    else if (ie_lt8) d.scrollbarH.style.minWidth = d.scrollbarV.style.minWidth = "18px";
  25.133 +
  25.134 +    // Current visible range (may be bigger than the view window).
  25.135 +    d.viewOffset = d.showingFrom = d.showingTo = d.lastSizeC = 0;
  25.136 +
  25.137 +    // Used to only resize the line number gutter when necessary (when
  25.138 +    // the amount of lines crosses a boundary that makes its width change)
  25.139 +    d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
  25.140 +    // See readInput and resetInput
  25.141 +    d.prevInput = "";
  25.142 +    // Set to true when a non-horizontal-scrolling widget is added. As
  25.143 +    // an optimization, widget aligning is skipped when d is false.
  25.144 +    d.alignWidgets = false;
  25.145 +    // Flag that indicates whether we currently expect input to appear
  25.146 +    // (after some event like 'keypress' or 'input') and are polling
  25.147 +    // intensively.
  25.148 +    d.pollingFast = false;
  25.149 +    // Self-resetting timeout for the poller
  25.150 +    d.poll = new Delayed();
  25.151 +    // True when a drag from the editor is active
  25.152 +    d.draggingText = false;
  25.153 +
  25.154 +    d.cachedCharWidth = d.cachedTextHeight = null;
  25.155 +    d.measureLineCache = [];
  25.156 +    d.measureLineCachePos = 0;
  25.157 +
  25.158 +    // Tracks when resetInput has punted to just putting a short
  25.159 +    // string instead of the (large) selection.
  25.160 +    d.inaccurateSelection = false;
  25.161 +
  25.162 +    // Used to adjust overwrite behaviour when a paste has been
  25.163 +    // detected
  25.164 +    d.pasteIncoming = false;
  25.165 +
  25.166 +    return d;
  25.167 +  }
  25.168 +
  25.169 +  // VIEW CONSTRUCTOR
  25.170 +
  25.171 +  function makeView(doc) {
  25.172 +    var selPos = {line: 0, ch: 0};
  25.173 +    return {
  25.174 +      doc: doc,
  25.175 +      // frontier is the point up to which the content has been parsed,
  25.176 +      frontier: 0, highlight: new Delayed(),
  25.177 +      sel: {from: selPos, to: selPos, head: selPos, anchor: selPos, shift: false, extend: false},
  25.178 +      scrollTop: 0, scrollLeft: 0,
  25.179 +      overwrite: false, focused: false,
  25.180 +      // Tracks the maximum line length so that
  25.181 +      // the horizontal scrollbar can be kept
  25.182 +      // static when scrolling.
  25.183 +      maxLine: getLine(doc, 0),
  25.184 +      maxLineLength: 0,
  25.185 +      maxLineChanged: false,
  25.186 +      suppressEdits: false,
  25.187 +      goalColumn: null,
  25.188 +      cantEdit: false,
  25.189 +      keyMaps: []
  25.190 +    };
  25.191 +  }
  25.192 +
  25.193 +  // STATE UPDATES
  25.194 +
  25.195 +  // Used to get the editor into a consistent state again when options change.
  25.196 +
  25.197 +  function loadMode(cm) {
  25.198 +    var doc = cm.view.doc;
  25.199 +    cm.view.mode = CodeMirror.getMode(cm.options, cm.options.mode);
  25.200 +    doc.iter(0, doc.size, function(line) { line.stateAfter = null; });
  25.201 +    cm.view.frontier = 0;
  25.202 +    startWorker(cm, 100);
  25.203 +  }
  25.204 +
  25.205 +  function wrappingChanged(cm) {
  25.206 +    var doc = cm.view.doc, th = textHeight(cm.display);
  25.207 +    if (cm.options.lineWrapping) {
  25.208 +      cm.display.wrapper.className += " CodeMirror-wrap";
  25.209 +      var perLine = cm.display.scroller.clientWidth / charWidth(cm.display) - 3;
  25.210 +      doc.iter(0, doc.size, function(line) {
  25.211 +        if (line.height == 0) return;
  25.212 +        var guess = Math.ceil(line.text.length / perLine) || 1;
  25.213 +        if (guess != 1) updateLineHeight(line, guess * th);
  25.214 +      });
  25.215 +      cm.display.sizer.style.minWidth = "";
  25.216 +    } else {
  25.217 +      cm.display.wrapper.className = cm.display.wrapper.className.replace(" CodeMirror-wrap", "");
  25.218 +      computeMaxLength(cm.view);
  25.219 +      doc.iter(0, doc.size, function(line) {
  25.220 +        if (line.height != 0) updateLineHeight(line, th);
  25.221 +      });
  25.222 +    }
  25.223 +    regChange(cm, 0, doc.size);
  25.224 +    clearCaches(cm);
  25.225 +    setTimeout(function(){updateScrollbars(cm.display, cm.view.doc.height);}, 100);
  25.226 +  }
  25.227 +
  25.228 +  function keyMapChanged(cm) {
  25.229 +    var style = keyMap[cm.options.keyMap].style;
  25.230 +    cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-keymap-\S+/g, "") +
  25.231 +      (style ? " cm-keymap-" + style : "");
  25.232 +  }
  25.233 +
  25.234 +  function themeChanged(cm) {
  25.235 +    cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
  25.236 +      cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
  25.237 +    clearCaches(cm);
  25.238 +  }
  25.239 +
  25.240 +  function guttersChanged(cm) {
  25.241 +    updateGutters(cm);
  25.242 +    updateDisplay(cm, true);
  25.243 +  }
  25.244 +
  25.245 +  function updateGutters(cm) {
  25.246 +    var gutters = cm.display.gutters, specs = cm.options.gutters;
  25.247 +    removeChildren(gutters);
  25.248 +    for (var i = 0; i < specs.length; ++i) {
  25.249 +      var gutterClass = specs[i];
  25.250 +      var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
  25.251 +      if (gutterClass == "CodeMirror-linenumbers") {
  25.252 +        cm.display.lineGutter = gElt;
  25.253 +        gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
  25.254 +      }
  25.255 +    }
  25.256 +    gutters.style.display = i ? "" : "none";
  25.257 +  }
  25.258 +
  25.259 +  function lineLength(doc, line) {
  25.260 +    if (line.height == 0) return 0;
  25.261 +    var len = line.text.length, merged, cur = line;
  25.262 +    while (merged = collapsedSpanAtStart(cur)) {
  25.263 +      var found = merged.find();
  25.264 +      cur = getLine(doc, found.from.line);
  25.265 +      len += found.from.ch - found.to.ch;
  25.266 +    }
  25.267 +    cur = line;
  25.268 +    while (merged = collapsedSpanAtEnd(cur)) {
  25.269 +      var found = merged.find();
  25.270 +      len -= cur.text.length - found.from.ch;
  25.271 +      cur = getLine(doc, found.to.line);
  25.272 +      len += cur.text.length - found.to.ch;
  25.273 +    }
  25.274 +    return len;
  25.275 +  }
  25.276 +
  25.277 +  function computeMaxLength(view) {
  25.278 +    view.maxLine = getLine(view.doc, 0);
  25.279 +    view.maxLineLength = lineLength(view.doc, view.maxLine);
  25.280 +    view.maxLineChanged = true;
  25.281 +    view.doc.iter(1, view.doc.size, function(line) {
  25.282 +      var len = lineLength(view.doc, line);
  25.283 +      if (len > view.maxLineLength) {
  25.284 +        view.maxLineLength = len;
  25.285 +        view.maxLine = line;
  25.286 +      }
  25.287 +    });
  25.288 +  }
  25.289 +
  25.290 +  // Make sure the gutters options contains the element
  25.291 +  // "CodeMirror-linenumbers" when the lineNumbers option is true.
  25.292 +  function setGuttersForLineNumbers(options) {
  25.293 +    var found = false;
  25.294 +    for (var i = 0; i < options.gutters.length; ++i) {
  25.295 +      if (options.gutters[i] == "CodeMirror-linenumbers") {
  25.296 +        if (options.lineNumbers) found = true;
  25.297 +        else options.gutters.splice(i--, 1);
  25.298 +      }
  25.299 +    }
  25.300 +    if (!found && options.lineNumbers)
  25.301 +      options.gutters.push("CodeMirror-linenumbers");
  25.302 +  }
  25.303 +
  25.304 +  // SCROLLBARS
  25.305 +
  25.306 +  // Re-synchronize the fake scrollbars with the actual size of the
  25.307 +  // content. Optionally force a scrollTop.
  25.308 +  function updateScrollbars(d /* display */, docHeight) {
  25.309 +    var totalHeight = docHeight + 2 * paddingTop(d);
  25.310 +    d.sizer.style.minHeight = d.heightForcer.style.top = totalHeight + "px";
  25.311 +    var scrollHeight = Math.max(totalHeight, d.scroller.scrollHeight);
  25.312 +    var needsH = d.scroller.scrollWidth > d.scroller.clientWidth;
  25.313 +    var needsV = scrollHeight > d.scroller.clientHeight;
  25.314 +    if (needsV) {
  25.315 +      d.scrollbarV.style.display = "block";
  25.316 +      d.scrollbarV.style.bottom = needsH ? scrollbarWidth(d.measure) + "px" : "0";
  25.317 +      d.scrollbarV.firstChild.style.height = 
  25.318 +        (scrollHeight - d.scroller.clientHeight + d.scrollbarV.clientHeight) + "px";
  25.319 +    } else d.scrollbarV.style.display = "";
  25.320 +    if (needsH) {
  25.321 +      d.scrollbarH.style.display = "block";
  25.322 +      d.scrollbarH.style.right = needsV ? scrollbarWidth(d.measure) + "px" : "0";
  25.323 +      d.scrollbarH.firstChild.style.width =
  25.324 +        (d.scroller.scrollWidth - d.scroller.clientWidth + d.scrollbarH.clientWidth) + "px";
  25.325 +    } else d.scrollbarH.style.display = "";
  25.326 +    if (needsH && needsV) {
  25.327 +      d.scrollbarFiller.style.display = "block";
  25.328 +      d.scrollbarFiller.style.height = d.scrollbarFiller.style.width = scrollbarWidth(d.measure) + "px";
  25.329 +    } else d.scrollbarFiller.style.display = "";
  25.330 +
  25.331 +    if (mac_geLion && scrollbarWidth(d.measure) === 0)
  25.332 +      d.scrollbarV.style.minWidth = d.scrollbarH.style.minHeight = mac_geMountainLion ? "18px" : "12px";
  25.333 +  }
  25.334 +
  25.335 +  function visibleLines(display, doc, viewPort) {
  25.336 +    var top = display.scroller.scrollTop, height = display.wrapper.clientHeight;
  25.337 +    if (typeof viewPort == "number") top = viewPort;
  25.338 +    else if (viewPort) {top = viewPort.top; height = viewPort.bottom - viewPort.top;}
  25.339 +    top = Math.floor(top - paddingTop(display));
  25.340 +    var bottom = Math.ceil(top + height);
  25.341 +    return {from: lineAtHeight(doc, top), to: lineAtHeight(doc, bottom)};
  25.342 +  }
  25.343 +
  25.344 +  // LINE NUMBERS
  25.345 +
  25.346 +  function alignHorizontally(cm) {
  25.347 +    var display = cm.display;
  25.348 +    if (!display.alignWidgets && !display.gutters.firstChild) return;
  25.349 +    var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.view.scrollLeft;
  25.350 +    var gutterW = display.gutters.offsetWidth, l = comp + "px";
  25.351 +    for (var n = display.lineDiv.firstChild; n; n = n.nextSibling) if (n.alignable) {
  25.352 +      for (var i = 0, a = n.alignable; i < a.length; ++i) a[i].style.left = l;
  25.353 +    }
  25.354 +    display.gutters.style.left = (comp + gutterW) + "px";
  25.355 +  }
  25.356 +
  25.357 +  function maybeUpdateLineNumberWidth(cm) {
  25.358 +    if (!cm.options.lineNumbers) return false;
  25.359 +    var doc = cm.view.doc, last = lineNumberFor(cm.options, doc.size - 1), display = cm.display;
  25.360 +    if (last.length != display.lineNumChars) {
  25.361 +      var test = display.measure.appendChild(elt("div", [elt("div", last)],
  25.362 +                                                 "CodeMirror-linenumber CodeMirror-gutter-elt"));
  25.363 +      var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
  25.364 +      display.lineGutter.style.width = "";
  25.365 +      display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding);
  25.366 +      display.lineNumWidth = display.lineNumInnerWidth + padding;
  25.367 +      display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
  25.368 +      display.lineGutter.style.width = display.lineNumWidth + "px";
  25.369 +      return true;
  25.370 +    }
  25.371 +    return false;
  25.372 +  }
  25.373 +
  25.374 +  function lineNumberFor(options, i) {
  25.375 +    return String(options.lineNumberFormatter(i + options.firstLineNumber));
  25.376 +  }
  25.377 +  function compensateForHScroll(display) {
  25.378 +    return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left;
  25.379 +  }
  25.380 +
  25.381 +  // DISPLAY DRAWING
  25.382 +
  25.383 +  function updateDisplay(cm, changes, viewPort) {
  25.384 +    var oldFrom = cm.display.showingFrom, oldTo = cm.display.showingTo;
  25.385 +    var updated = updateDisplayInner(cm, changes, viewPort);
  25.386 +    if (updated) {
  25.387 +      signalLater(cm, cm, "update", cm);
  25.388 +      if (cm.display.showingFrom != oldFrom || cm.display.showingTo != oldTo)
  25.389 +        signalLater(cm, cm, "viewportChange", cm, cm.display.showingFrom, cm.display.showingTo);
  25.390 +    }
  25.391 +    updateSelection(cm);
  25.392 +    updateScrollbars(cm.display, cm.view.doc.height);
  25.393 +
  25.394 +    return updated;
  25.395 +  }
  25.396 +
  25.397 +  // Uses a set of changes plus the current scroll position to
  25.398 +  // determine which DOM updates have to be made, and makes the
  25.399 +  // updates.
  25.400 +  function updateDisplayInner(cm, changes, viewPort) {
  25.401 +    var display = cm.display, doc = cm.view.doc;
  25.402 +    if (!display.wrapper.clientWidth) {
  25.403 +      display.showingFrom = display.showingTo = display.viewOffset = 0;
  25.404 +      return;
  25.405 +    }
  25.406 +
  25.407 +    // Compute the new visible window
  25.408 +    // If scrollTop is specified, use that to determine which lines
  25.409 +    // to render instead of the current scrollbar position.
  25.410 +    var visible = visibleLines(display, doc, viewPort);
  25.411 +    // Bail out if the visible area is already rendered and nothing changed.
  25.412 +    if (changes !== true && changes.length == 0 &&
  25.413 +        visible.from > display.showingFrom && visible.to < display.showingTo)
  25.414 +      return;
  25.415 +
  25.416 +    if (changes && maybeUpdateLineNumberWidth(cm))
  25.417 +      changes = true;
  25.418 +    display.sizer.style.marginLeft = display.scrollbarH.style.left = display.gutters.offsetWidth + "px";
  25.419 +
  25.420 +    // When merged lines are present, the line that needs to be
  25.421 +    // redrawn might not be the one that was changed.
  25.422 +    if (changes !== true && sawCollapsedSpans)
  25.423 +      for (var i = 0; i < changes.length; ++i) {
  25.424 +        var ch = changes[i], merged;
  25.425 +        while (merged = collapsedSpanAtStart(getLine(doc, ch.from))) {
  25.426 +          var from = merged.find().from.line;
  25.427 +          if (ch.diff) ch.diff -= ch.from - from;
  25.428 +          ch.from = from;
  25.429 +        }
  25.430 +      }
  25.431 +
  25.432 +    // Used to determine which lines need their line numbers updated
  25.433 +    var positionsChangedFrom = changes === true ? 0 : Infinity;
  25.434 +    if (cm.options.lineNumbers && changes && changes !== true)
  25.435 +      for (var i = 0; i < changes.length; ++i)
  25.436 +        if (changes[i].diff) { positionsChangedFrom = changes[i].from; break; }
  25.437 +
  25.438 +    var from = Math.max(visible.from - cm.options.viewportMargin, 0);
  25.439 +    var to = Math.min(doc.size, visible.to + cm.options.viewportMargin);
  25.440 +    if (display.showingFrom < from && from - display.showingFrom < 20) from = display.showingFrom;
  25.441 +    if (display.showingTo > to && display.showingTo - to < 20) to = Math.min(doc.size, display.showingTo);
  25.442 +    if (sawCollapsedSpans) {
  25.443 +      from = lineNo(visualLine(doc, getLine(doc, from)));
  25.444 +      while (to < doc.size && lineIsHidden(getLine(doc, to))) ++to;
  25.445 +    }
  25.446 +
  25.447 +    // Create a range of theoretically intact lines, and punch holes
  25.448 +    // in that using the change info.
  25.449 +    var intact = changes === true ? [] :
  25.450 +      computeIntact([{from: display.showingFrom, to: display.showingTo}], changes);
  25.451 +    // Clip off the parts that won't be visible
  25.452 +    var intactLines = 0;
  25.453 +    for (var i = 0; i < intact.length; ++i) {
  25.454 +      var range = intact[i];
  25.455 +      if (range.from < from) range.from = from;
  25.456 +      if (range.to > to) range.to = to;
  25.457 +      if (range.from >= range.to) intact.splice(i--, 1);
  25.458 +      else intactLines += range.to - range.from;
  25.459 +    }
  25.460 +    if (intactLines == to - from && from == display.showingFrom && to == display.showingTo)
  25.461 +      return;
  25.462 +    intact.sort(function(a, b) {return a.from - b.from;});
  25.463 +
  25.464 +    if (intactLines < (to - from) * .7) display.lineDiv.style.display = "none";
  25.465 +    patchDisplay(cm, from, to, intact, positionsChangedFrom);
  25.466 +    display.lineDiv.style.display = "";
  25.467 +
  25.468 +    var different = from != display.showingFrom || to != display.showingTo ||
  25.469 +      display.lastSizeC != display.wrapper.clientHeight;
  25.470 +    // This is just a bogus formula that detects when the editor is
  25.471 +    // resized or the font size changes.
  25.472 +    if (different) display.lastSizeC = display.wrapper.clientHeight;
  25.473 +    display.showingFrom = from; display.showingTo = to;
  25.474 +    startWorker(cm, 100);
  25.475 +
  25.476 +    var prevBottom = display.lineDiv.offsetTop;
  25.477 +    for (var node = display.lineDiv.firstChild, height; node; node = node.nextSibling) if (node.lineObj) {
  25.478 +      if (ie_lt8) {
  25.479 +        var bot = node.offsetTop + node.offsetHeight;
  25.480 +        height = bot - prevBottom;
  25.481 +        prevBottom = bot;
  25.482 +      } else {
  25.483 +        var box = node.getBoundingClientRect();
  25.484 +        height = box.bottom - box.top;
  25.485 +      }
  25.486 +      var diff = node.lineObj.height - height;
  25.487 +      if (height < 2) height = textHeight(display);
  25.488 +      if (diff > .001 || diff < -.001)
  25.489 +        updateLineHeight(node.lineObj, height);
  25.490 +    }
  25.491 +    display.viewOffset = heightAtLine(cm, getLine(doc, from));
  25.492 +    // Position the mover div to align with the current virtual scroll position
  25.493 +    display.mover.style.top = display.viewOffset + "px";
  25.494 +    return true;
  25.495 +  }
  25.496 +
  25.497 +  function computeIntact(intact, changes) {
  25.498 +    for (var i = 0, l = changes.length || 0; i < l; ++i) {
  25.499 +      var change = changes[i], intact2 = [], diff = change.diff || 0;
  25.500 +      for (var j = 0, l2 = intact.length; j < l2; ++j) {
  25.501 +        var range = intact[j];
  25.502 +        if (change.to <= range.from && change.diff) {
  25.503 +          intact2.push({from: range.from + diff, to: range.to + diff});
  25.504 +        } else if (change.to <= range.from || change.from >= range.to) {
  25.505 +          intact2.push(range);
  25.506 +        } else {
  25.507 +          if (change.from > range.from)
  25.508 +            intact2.push({from: range.from, to: change.from});
  25.509 +          if (change.to < range.to)
  25.510 +            intact2.push({from: change.to + diff, to: range.to + diff});
  25.511 +        }
  25.512 +      }
  25.513 +      intact = intact2;
  25.514 +    }
  25.515 +    return intact;
  25.516 +  }
  25.517 +
  25.518 +  function getDimensions(cm) {
  25.519 +    var d = cm.display, left = {}, width = {};
  25.520 +    for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
  25.521 +      left[cm.options.gutters[i]] = n.offsetLeft;
  25.522 +      width[cm.options.gutters[i]] = n.offsetWidth;
  25.523 +    }
  25.524 +    return {fixedPos: compensateForHScroll(d),
  25.525 +            gutterTotalWidth: d.gutters.offsetWidth,
  25.526 +            gutterLeft: left,
  25.527 +            gutterWidth: width,
  25.528 +            wrapperWidth: d.wrapper.clientWidth};
  25.529 +  }
  25.530 +
  25.531 +  function patchDisplay(cm, from, to, intact, updateNumbersFrom) {
  25.532 +    var dims = getDimensions(cm);
  25.533 +    var display = cm.display, lineNumbers = cm.options.lineNumbers;
  25.534 +    // IE does bad things to nodes when .innerHTML = "" is used on a parent
  25.535 +    // we still need widgets and markers intact to add back to the new content later
  25.536 +    if (!intact.length && !ie && (!webkit || !cm.display.currentWheelTarget))
  25.537 +      removeChildren(display.lineDiv);
  25.538 +    var container = display.lineDiv, cur = container.firstChild;
  25.539 +
  25.540 +    function rm(node) {
  25.541 +      var next = node.nextSibling;
  25.542 +      if (webkit && mac && cm.display.currentWheelTarget == node) {
  25.543 +        node.style.display = "none";
  25.544 +        node.lineObj = null;
  25.545 +      } else {
  25.546 +        container.removeChild(node);
  25.547 +      }
  25.548 +      return next;
  25.549 +    }
  25.550 +
  25.551 +    var nextIntact = intact.shift(), lineNo = from;
  25.552 +    cm.view.doc.iter(from, to, function(line) {
  25.553 +      if (nextIntact && nextIntact.to == lineNo) nextIntact = intact.shift();
  25.554 +      if (lineIsHidden(line)) {
  25.555 +        if (line.height != 0) updateLineHeight(line, 0);
  25.556 +      } else if (nextIntact && nextIntact.from <= lineNo && nextIntact.to > lineNo) {
  25.557 +        // This line is intact. Skip to the actual node. Update its
  25.558 +        // line number if needed.
  25.559 +        while (cur.lineObj != line) cur = rm(cur);
  25.560 +        if (lineNumbers && updateNumbersFrom <= lineNo && cur.lineNumber)
  25.561 +          setTextContent(cur.lineNumber, lineNumberFor(cm.options, lineNo));
  25.562 +        cur = cur.nextSibling;
  25.563 +      } else {
  25.564 +        // This line needs to be generated.
  25.565 +        var lineNode = buildLineElement(cm, line, lineNo, dims);
  25.566 +        container.insertBefore(lineNode, cur);
  25.567 +        lineNode.lineObj = line;
  25.568 +      }
  25.569 +      ++lineNo;
  25.570 +    });
  25.571 +    while (cur) cur = rm(cur);
  25.572 +  }
  25.573 +
  25.574 +  function buildLineElement(cm, line, lineNo, dims) {
  25.575 +    var lineElement = lineContent(cm, line);
  25.576 +    var markers = line.gutterMarkers, display = cm.display;
  25.577 +
  25.578 +    if (!cm.options.lineNumbers && !markers && !line.bgClass && !line.wrapClass &&
  25.579 +        (!line.widgets || !line.widgets.length)) return lineElement;
  25.580 +
  25.581 +    // Lines with gutter elements or a background class need
  25.582 +    // to be wrapped again, and have the extra elements added
  25.583 +    // to the wrapper div
  25.584 +
  25.585 +    var wrap = elt("div", null, line.wrapClass, "position: relative");
  25.586 +    if (cm.options.lineNumbers || markers) {
  25.587 +      var gutterWrap = wrap.appendChild(elt("div", null, null, "position: absolute; left: " +
  25.588 +                                            dims.fixedPos + "px"));
  25.589 +      wrap.alignable = [gutterWrap];
  25.590 +      if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
  25.591 +        wrap.lineNumber = gutterWrap.appendChild(
  25.592 +          elt("div", lineNumberFor(cm.options, lineNo),
  25.593 +              "CodeMirror-linenumber CodeMirror-gutter-elt",
  25.594 +              "left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: "
  25.595 +              + display.lineNumInnerWidth + "px"));
  25.596 +      if (markers)
  25.597 +        for (var k = 0; k < cm.options.gutters.length; ++k) {
  25.598 +          var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id];
  25.599 +          if (found)
  25.600 +            gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", "left: " +
  25.601 +                                       dims.gutterLeft[id] + "px; width: " + dims.gutterWidth[id] + "px"));
  25.602 +        }
  25.603 +    }
  25.604 +    // Kludge to make sure the styled element lies behind the selection (by z-index)
  25.605 +    if (line.bgClass)
  25.606 +      wrap.appendChild(elt("div", "\u00a0", line.bgClass + " CodeMirror-linebackground"));
  25.607 +    wrap.appendChild(lineElement);
  25.608 +    if (line.widgets)
  25.609 +      for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
  25.610 +        var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
  25.611 +        node.widget = widget;
  25.612 +        if (widget.noHScroll) {
  25.613 +          (wrap.alignable || (wrap.alignable = [])).push(node);
  25.614 +          var width = dims.wrapperWidth;
  25.615 +          node.style.left = dims.fixedPos + "px";
  25.616 +          if (!widget.coverGutter) {
  25.617 +            width -= dims.gutterTotalWidth;
  25.618 +            node.style.paddingLeft = dims.gutterTotalWidth + "px";
  25.619 +          }
  25.620 +          node.style.width = width + "px";
  25.621 +        }
  25.622 +        if (widget.coverGutter) {
  25.623 +          node.style.zIndex = 5;
  25.624 +          node.style.position = "relative";
  25.625 +          if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px";
  25.626 +        }
  25.627 +        if (widget.above)
  25.628 +          wrap.insertBefore(node, cm.options.lineNumbers && line.height != 0 ? gutterWrap : lineElement);
  25.629 +        else
  25.630 +          wrap.appendChild(node);
  25.631 +      }
  25.632 +
  25.633 +    if (ie_lt8) wrap.style.zIndex = 2;
  25.634 +    return wrap;
  25.635 +  }
  25.636 +
  25.637 +  // SELECTION / CURSOR
  25.638 +
  25.639 +  function updateSelection(cm) {
  25.640 +    var display = cm.display;
  25.641 +    var collapsed = posEq(cm.view.sel.from, cm.view.sel.to);
  25.642 +    if (collapsed || cm.options.showCursorWhenSelecting)
  25.643 +      updateSelectionCursor(cm);
  25.644 +    else
  25.645 +      display.cursor.style.display = display.otherCursor.style.display = "none";
  25.646 +    if (!collapsed)
  25.647 +      updateSelectionRange(cm);
  25.648 +    else
  25.649 +      display.selectionDiv.style.display = "none";
  25.650 +
  25.651 +    // Move the hidden textarea near the cursor to prevent scrolling artifacts
  25.652 +    var headPos = cursorCoords(cm, cm.view.sel.head, "div");
  25.653 +    var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
  25.654 +    display.inputDiv.style.top = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
  25.655 +                                                      headPos.top + lineOff.top - wrapOff.top)) + "px";
  25.656 +    display.inputDiv.style.left = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
  25.657 +                                                       headPos.left + lineOff.left - wrapOff.left)) + "px";
  25.658 +  }
  25.659 +
  25.660 +  // No selection, plain cursor
  25.661 +  function updateSelectionCursor(cm) {
  25.662 +    var display = cm.display, pos = cursorCoords(cm, cm.view.sel.head, "div");
  25.663 +    display.cursor.style.left = pos.left + "px";
  25.664 +    display.cursor.style.top = pos.top + "px";
  25.665 +    display.cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
  25.666 +    display.cursor.style.display = "";
  25.667 +
  25.668 +    if (pos.other) {
  25.669 +      display.otherCursor.style.display = "";
  25.670 +      display.otherCursor.style.left = pos.other.left + "px";
  25.671 +      display.otherCursor.style.top = pos.other.top + "px";
  25.672 +      display.otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
  25.673 +    } else { display.otherCursor.style.display = "none"; }
  25.674 +  }
  25.675 +
  25.676 +  // Highlight selection
  25.677 +  function updateSelectionRange(cm) {
  25.678 +    var display = cm.display, doc = cm.view.doc, sel = cm.view.sel;
  25.679 +    var fragment = document.createDocumentFragment();
  25.680 +    var clientWidth = display.lineSpace.offsetWidth, pl = paddingLeft(cm.display);
  25.681 +
  25.682 +    function add(left, top, width, bottom) {
  25.683 +      if (top < 0) top = 0;
  25.684 +      fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
  25.685 +                               "px; top: " + top + "px; width: " + (width == null ? clientWidth - left : width) +
  25.686 +                               "px; height: " + (bottom - top) + "px"));
  25.687 +    }
  25.688 +
  25.689 +    function drawForLine(line, fromArg, toArg, retTop) {
  25.690 +      var lineObj = getLine(doc, line);
  25.691 +      var lineLen = lineObj.text.length, rVal = retTop ? Infinity : -Infinity;
  25.692 +      function coords(ch) {
  25.693 +        return charCoords(cm, {line: line, ch: ch}, "div", lineObj);
  25.694 +      }
  25.695 +
  25.696 +      iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
  25.697 +        var leftPos = coords(dir == "rtl" ? to - 1 : from);
  25.698 +        var rightPos = coords(dir == "rtl" ? from : to - 1);
  25.699 +        var left = leftPos.left, right = rightPos.right;
  25.700 +        if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
  25.701 +          add(left, leftPos.top, null, leftPos.bottom);
  25.702 +          left = pl;
  25.703 +          if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
  25.704 +        }
  25.705 +        if (toArg == null && to == lineLen) right = clientWidth;
  25.706 +        if (fromArg == null && from == 0) left = pl;
  25.707 +        rVal = retTop ? Math.min(rightPos.top, rVal) : Math.max(rightPos.bottom, rVal);
  25.708 +        if (left < pl + 1) left = pl;
  25.709 +        add(left, rightPos.top, right - left, rightPos.bottom);
  25.710 +      });
  25.711 +      return rVal;
  25.712 +    }
  25.713 +
  25.714 +    if (sel.from.line == sel.to.line) {
  25.715 +      drawForLine(sel.from.line, sel.from.ch, sel.to.ch);
  25.716 +    } else {
  25.717 +      var fromObj = getLine(doc, sel.from.line);
  25.718 +      var cur = fromObj, merged, path = [sel.from.line, sel.from.ch], singleLine;
  25.719 +      while (merged = collapsedSpanAtEnd(cur)) {
  25.720 +        var found = merged.find();
  25.721 +        path.push(found.from.ch, found.to.line, found.to.ch);
  25.722 +        if (found.to.line == sel.to.line) {
  25.723 +          path.push(sel.to.ch);
  25.724 +          singleLine = true;
  25.725 +          break;
  25.726 +        }
  25.727 +        cur = getLine(doc, found.to.line);
  25.728 +      }
  25.729 +
  25.730 +      // This is a single, merged line
  25.731 +      if (singleLine) {
  25.732 +        for (var i = 0; i < path.length; i += 3)
  25.733 +          drawForLine(path[i], path[i+1], path[i+2]);
  25.734 +      } else {
  25.735 +        var middleTop, middleBot, toObj = getLine(doc, sel.to.line);
  25.736 +        if (sel.from.ch)
  25.737 +          // Draw the first line of selection.
  25.738 +          middleTop = drawForLine(sel.from.line, sel.from.ch, null, false);
  25.739 +        else
  25.740 +          // Simply include it in the middle block.
  25.741 +          middleTop = heightAtLine(cm, fromObj) - display.viewOffset;
  25.742 +
  25.743 +        if (!sel.to.ch)
  25.744 +          middleBot = heightAtLine(cm, toObj) - display.viewOffset;
  25.745 +        else
  25.746 +          middleBot = drawForLine(sel.to.line, collapsedSpanAtStart(toObj) ? null : 0, sel.to.ch, true);
  25.747 +
  25.748 +        if (middleTop < middleBot) add(pl, middleTop, null, middleBot);
  25.749 +      }
  25.750 +    }
  25.751 +
  25.752 +    removeChildrenAndAdd(display.selectionDiv, fragment);
  25.753 +    display.selectionDiv.style.display = "";
  25.754 +  }
  25.755 +
  25.756 +  // Cursor-blinking
  25.757 +  function restartBlink(cm) {
  25.758 +    var display = cm.display;
  25.759 +    clearInterval(display.blinker);
  25.760 +    var on = true;
  25.761 +    display.cursor.style.visibility = display.otherCursor.style.visibility = "";
  25.762 +    display.blinker = setInterval(function() {
  25.763 +      if (!display.cursor.offsetHeight) return;
  25.764 +      display.cursor.style.visibility = display.otherCursor.style.visibility = (on = !on) ? "" : "hidden";
  25.765 +    }, cm.options.cursorBlinkRate);
  25.766 +  }
  25.767 +
  25.768 +  // HIGHLIGHT WORKER
  25.769 +
  25.770 +  function startWorker(cm, time) {
  25.771 +    if (cm.view.frontier < cm.display.showingTo)
  25.772 +      cm.view.highlight.set(time, bind(highlightWorker, cm));
  25.773 +  }
  25.774 +
  25.775 +  function highlightWorker(cm) {
  25.776 +    var view = cm.view, doc = view.doc;
  25.777 +    if (view.frontier >= cm.display.showingTo) return;
  25.778 +    var end = +new Date + cm.options.workTime;
  25.779 +    var state = copyState(view.mode, getStateBefore(cm, view.frontier));
  25.780 +    var changed = [], prevChange;
  25.781 +    doc.iter(view.frontier, Math.min(doc.size, cm.display.showingTo + 500), function(line) {
  25.782 +      if (view.frontier >= cm.display.showingFrom) { // Visible
  25.783 +        if (highlightLine(cm, line, state) && view.frontier >= cm.display.showingFrom) {
  25.784 +          if (prevChange && prevChange.end == view.frontier) prevChange.end++;
  25.785 +          else changed.push(prevChange = {start: view.frontier, end: view.frontier + 1});
  25.786 +        }
  25.787 +        line.stateAfter = copyState(view.mode, state);
  25.788 +      } else {
  25.789 +        processLine(cm, line, state);
  25.790 +        line.stateAfter = view.frontier % 5 == 0 ? copyState(view.mode, state) : null;
  25.791 +      }
  25.792 +      ++view.frontier;
  25.793 +      if (+new Date > end) {
  25.794 +        startWorker(cm, cm.options.workDelay);
  25.795 +        return true;
  25.796 +      }
  25.797 +    });
  25.798 +    if (changed.length)
  25.799 +      operation(cm, function() {
  25.800 +        for (var i = 0; i < changed.length; ++i)
  25.801 +          regChange(this, changed[i].start, changed[i].end);
  25.802 +      })();
  25.803 +  }
  25.804 +
  25.805 +  // Finds the line to start with when starting a parse. Tries to
  25.806 +  // find a line with a stateAfter, so that it can start with a
  25.807 +  // valid state. If that fails, it returns the line with the
  25.808 +  // smallest indentation, which tends to need the least context to
  25.809 +  // parse correctly.
  25.810 +  function findStartLine(cm, n) {
  25.811 +    var minindent, minline, doc = cm.view.doc;
  25.812 +    for (var search = n, lim = n - 100; search > lim; --search) {
  25.813 +      if (search == 0) return 0;
  25.814 +      var line = getLine(doc, search-1);
  25.815 +      if (line.stateAfter) return search;
  25.816 +      var indented = countColumn(line.text, null, cm.options.tabSize);
  25.817 +      if (minline == null || minindent > indented) {
  25.818 +        minline = search - 1;
  25.819 +        minindent = indented;
  25.820 +      }
  25.821 +    }
  25.822 +    return minline;
  25.823 +  }
  25.824 +
  25.825 +  function getStateBefore(cm, n) {
  25.826 +    var view = cm.view;
  25.827 +    var pos = findStartLine(cm, n), state = pos && getLine(view.doc, pos-1).stateAfter;
  25.828 +    if (!state) state = startState(view.mode);
  25.829 +    else state = copyState(view.mode, state);
  25.830 +    view.doc.iter(pos, n, function(line) {
  25.831 +      processLine(cm, line, state);
  25.832 +      var save = pos == n - 1 || pos % 5 == 0 || pos >= view.showingFrom && pos < view.showingTo;
  25.833 +      line.stateAfter = save ? copyState(view.mode, state) : null;
  25.834 +      ++pos;
  25.835 +    });
  25.836 +    return state;
  25.837 +  }
  25.838 +
  25.839 +  // POSITION MEASUREMENT
  25.840 +  
  25.841 +  function paddingTop(display) {return display.lineSpace.offsetTop;}
  25.842 +  function paddingLeft(display) {
  25.843 +    var e = removeChildrenAndAdd(display.measure, elt("pre")).appendChild(elt("span", "x"));
  25.844 +    return e.offsetLeft;
  25.845 +  }
  25.846 +
  25.847 +  function measureChar(cm, line, ch, data) {
  25.848 +    var data = data || measureLine(cm, line), dir = -1;
  25.849 +    for (var pos = ch;; pos += dir) {
  25.850 +      var r = data[pos];
  25.851 +      if (r) break;
  25.852 +      if (dir < 0 && pos == 0) dir = 1;
  25.853 +    }
  25.854 +    return {left: pos < ch ? r.right : r.left,
  25.855 +            right: pos > ch ? r.left : r.right,
  25.856 +            top: r.top, bottom: r.bottom};
  25.857 +  }
  25.858 +
  25.859 +  function measureLine(cm, line) {
  25.860 +    // First look in the cache
  25.861 +    var display = cm.display, cache = cm.display.measureLineCache;
  25.862 +    for (var i = 0; i < cache.length; ++i) {
  25.863 +      var memo = cache[i];
  25.864 +      if (memo.text == line.text && memo.markedSpans == line.markedSpans &&
  25.865 +          display.scroller.clientWidth == memo.width)
  25.866 +        return memo.measure;
  25.867 +    }
  25.868 +    
  25.869 +    var measure = measureLineInner(cm, line);
  25.870 +    // Store result in the cache
  25.871 +    var memo = {text: line.text, width: display.scroller.clientWidth,
  25.872 +                markedSpans: line.markedSpans, measure: measure};
  25.873 +    if (cache.length == 16) cache[++display.measureLineCachePos % 16] = memo;
  25.874 +    else cache.push(memo);
  25.875 +    return measure;
  25.876 +  }
  25.877 +
  25.878 +  function measureLineInner(cm, line) {
  25.879 +    var display = cm.display, measure = emptyArray(line.text.length);
  25.880 +    var pre = lineContent(cm, line, measure);
  25.881 +
  25.882 +    // IE does not cache element positions of inline elements between
  25.883 +    // calls to getBoundingClientRect. This makes the loop below,
  25.884 +    // which gathers the positions of all the characters on the line,
  25.885 +    // do an amount of layout work quadratic to the number of
  25.886 +    // characters. When line wrapping is off, we try to improve things
  25.887 +    // by first subdividing the line into a bunch of inline blocks, so
  25.888 +    // that IE can reuse most of the layout information from caches
  25.889 +    // for those blocks. This does interfere with line wrapping, so it
  25.890 +    // doesn't work when wrapping is on, but in that case the
  25.891 +    // situation is slightly better, since IE does cache line-wrapping
  25.892 +    // information and only recomputes per-line.
  25.893 +    if (ie && !ie_lt8 && !cm.options.lineWrapping && pre.childNodes.length > 100) {
  25.894 +      var fragment = document.createDocumentFragment();
  25.895 +      var chunk = 10, n = pre.childNodes.length;
  25.896 +      for (var i = 0, chunks = Math.ceil(n / chunk); i < chunks; ++i) {
  25.897 +        var wrap = elt("div", null, null, "display: inline-block");
  25.898 +        for (var j = 0; j < chunk && n; ++j) {
  25.899 +          wrap.appendChild(pre.firstChild);
  25.900 +          --n;
  25.901 +        }
  25.902 +        fragment.appendChild(wrap);
  25.903 +      }
  25.904 +      pre.appendChild(fragment);
  25.905 +    }
  25.906 +
  25.907 +    removeChildrenAndAdd(display.measure, pre);
  25.908 +
  25.909 +    var outer = display.lineDiv.getBoundingClientRect();
  25.910 +    var vranges = [], data = emptyArray(line.text.length), maxBot = pre.offsetHeight;
  25.911 +    for (var i = 0, cur; i < measure.length; ++i) if (cur = measure[i]) {
  25.912 +      var size = cur.getBoundingClientRect();
  25.913 +      var top = Math.max(0, size.top - outer.top), bot = Math.min(size.bottom - outer.top, maxBot);
  25.914 +      for (var j = 0; j < vranges.length; j += 2) {
  25.915 +        var rtop = vranges[j], rbot = vranges[j+1];
  25.916 +        if (rtop > bot || rbot < top) continue;
  25.917 +        if (rtop <= top && rbot >= bot ||
  25.918 +            top <= rtop && bot >= rbot ||
  25.919 +            Math.min(bot, rbot) - Math.max(top, rtop) >= (bot - top) >> 1) {
  25.920 +          vranges[j] = Math.min(top, rtop);
  25.921 +          vranges[j+1] = Math.max(bot, rbot);
  25.922 +          break;
  25.923 +        }
  25.924 +      }
  25.925 +      if (j == vranges.length) vranges.push(top, bot);
  25.926 +      data[i] = {left: size.left - outer.left, right: size.right - outer.left, top: j};
  25.927 +    }
  25.928 +    for (var i = 0, cur; i < data.length; ++i) if (cur = data[i]) {
  25.929 +      var vr = cur.top;
  25.930 +      cur.top = vranges[vr]; cur.bottom = vranges[vr+1];
  25.931 +    }
  25.932 +    return data;
  25.933 +  }
  25.934 +
  25.935 +  function clearCaches(cm) {
  25.936 +    cm.display.measureLineCache.length = cm.display.measureLineCachePos = 0;
  25.937 +    cm.display.cachedCharWidth = cm.display.cachedTextHeight = null;
  25.938 +    cm.view.maxLineChanged = true;
  25.939 +  }
  25.940 +
  25.941 +  // Context is one of "line", "div" (display.lineDiv), "local"/null (editor), or "page"
  25.942 +  function intoCoordSystem(cm, lineObj, rect, context) {
  25.943 +    if (lineObj.widgets) for (var i = 0; i < lineObj.widgets.length; ++i) if (lineObj.widgets[i].above) {
  25.944 +      var size = lineObj.widgets[i].node.offsetHeight;
  25.945 +      rect.top += size; rect.bottom += size;
  25.946 +    }
  25.947 +    if (context == "line") return rect;
  25.948 +    if (!context) context = "local";
  25.949 +    var yOff = heightAtLine(cm, lineObj);
  25.950 +    if (context != "local") yOff -= cm.display.viewOffset;
  25.951 +    if (context == "page") {
  25.952 +      var lOff = cm.display.lineSpace.getBoundingClientRect();
  25.953 +      yOff += lOff.top + (window.pageYOffset || (document.documentElement || document.body).scrollTop);
  25.954 +      var xOff = lOff.left + (window.pageXOffset || (document.documentElement || document.body).scrollLeft);
  25.955 +      rect.left += xOff; rect.right += xOff;
  25.956 +    }
  25.957 +    rect.top += yOff; rect.bottom += yOff;
  25.958 +    return rect;
  25.959 +  }
  25.960 +
  25.961 +  function charCoords(cm, pos, context, lineObj) {
  25.962 +    if (!lineObj) lineObj = getLine(cm.view.doc, pos.line);
  25.963 +    return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch), context);
  25.964 +  }
  25.965 +
  25.966 +  function cursorCoords(cm, pos, context, lineObj, measurement) {
  25.967 +    lineObj = lineObj || getLine(cm.view.doc, pos.line);
  25.968 +    if (!measurement) measurement = measureLine(cm, lineObj);
  25.969 +    function get(ch, right) {
  25.970 +      var m = measureChar(cm, lineObj, ch, measurement);
  25.971 +      if (right) m.left = m.right; else m.right = m.left;
  25.972 +      return intoCoordSystem(cm, lineObj, m, context);
  25.973 +    }
  25.974 +    var order = getOrder(lineObj), ch = pos.ch;
  25.975 +    if (!order) return get(ch);
  25.976 +    var main, other, linedir = order[0].level;
  25.977 +    for (var i = 0; i < order.length; ++i) {
  25.978 +      var part = order[i], rtl = part.level % 2, nb, here;
  25.979 +      if (part.from < ch && part.to > ch) return get(ch, rtl);
  25.980 +      var left = rtl ? part.to : part.from, right = rtl ? part.from : part.to;
  25.981 +      if (left == ch) {
  25.982 +        // Opera and IE return bogus offsets and widths for edges
  25.983 +        // where the direction flips, but only for the side with the
  25.984 +        // lower level. So we try to use the side with the higher
  25.985 +        // level.
  25.986 +        if (i && part.level < (nb = order[i-1]).level) here = get(nb.level % 2 ? nb.from : nb.to - 1, true);
  25.987 +        else here = get(rtl && part.from != part.to ? ch - 1 : ch);
  25.988 +        if (rtl == linedir) main = here; else other = here;
  25.989 +      } else if (right == ch) {
  25.990 +        var nb = i < order.length - 1 && order[i+1];
  25.991 +        if (!rtl && nb && nb.from == nb.to) continue;
  25.992 +        if (nb && part.level < nb.level) here = get(nb.level % 2 ? nb.to - 1 : nb.from);
  25.993 +        else here = get(rtl ? ch : ch - 1, true);
  25.994 +        if (rtl == linedir) main = here; else other = here;
  25.995 +      }
  25.996 +    }
  25.997 +    if (linedir && !ch) other = get(order[0].to - 1);
  25.998 +    if (!main) return other;
  25.999 +    if (other) main.other = other;
 25.1000 +    return main;
 25.1001 +  }
 25.1002 +
 25.1003 +  // Coords must be lineSpace-local
 25.1004 +  function coordsChar(cm, x, y) {
 25.1005 +    var doc = cm.view.doc;
 25.1006 +    y += cm.display.viewOffset;
 25.1007 +    if (y < 0) return {line: 0, ch: 0, outside: true};
 25.1008 +    var lineNo = lineAtHeight(doc, y);
 25.1009 +    if (lineNo >= doc.size) return {line: doc.size - 1, ch: getLine(doc, doc.size - 1).text.length};
 25.1010 +    if (x < 0) x = 0;
 25.1011 +
 25.1012 +    for (;;) {
 25.1013 +      var lineObj = getLine(doc, lineNo);
 25.1014 +      var found = coordsCharInner(cm, lineObj, lineNo, x, y);
 25.1015 +      var merged = collapsedSpanAtEnd(lineObj);
 25.1016 +      if (merged && found.ch == lineRight(lineObj))
 25.1017 +        lineNo = merged.find().to.line;
 25.1018 +      else
 25.1019 +        return found;
 25.1020 +    }
 25.1021 +  }
 25.1022 +
 25.1023 +  function coordsCharInner(cm, lineObj, lineNo, x, y) {
 25.1024 +    var innerOff = y - heightAtLine(cm, lineObj);
 25.1025 +    var wrongLine = false, cWidth = cm.display.wrapper.clientWidth;
 25.1026 +    var measurement = measureLine(cm, lineObj);
 25.1027 +
 25.1028 +    function getX(ch) {
 25.1029 +      var sp = cursorCoords(cm, {line: lineNo, ch: ch}, "line",
 25.1030 +                            lineObj, measurement);
 25.1031 +      wrongLine = true;
 25.1032 +      if (innerOff > sp.bottom) return Math.max(0, sp.left - cWidth);
 25.1033 +      else if (innerOff < sp.top) return sp.left + cWidth;
 25.1034 +      else wrongLine = false;
 25.1035 +      return sp.left;
 25.1036 +    }
 25.1037 +
 25.1038 +    var bidi = getOrder(lineObj), dist = lineObj.text.length;
 25.1039 +    var from = lineLeft(lineObj), to = lineRight(lineObj);
 25.1040 +    var fromX = paddingLeft(cm.display), toX = getX(to);
 25.1041 +
 25.1042 +    if (x > toX) return {line: lineNo, ch: to, outside: wrongLine};
 25.1043 +    // Do a binary search between these bounds.
 25.1044 +    for (;;) {
 25.1045 +      if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
 25.1046 +        var after = x - fromX < toX - x, ch = after ? from : to;
 25.1047 +        while (isExtendingChar.test(lineObj.text.charAt(ch))) ++ch;
 25.1048 +        return {line: lineNo, ch: ch, after: after, outside: wrongLine};
 25.1049 +      }
 25.1050 +      var step = Math.ceil(dist / 2), middle = from + step;
 25.1051 +      if (bidi) {
 25.1052 +        middle = from;
 25.1053 +        for (var i = 0; i < step; ++i) middle = moveVisually(lineObj, middle, 1);
 25.1054 +      }
 25.1055 +      var middleX = getX(middle);
 25.1056 +      if (middleX > x) {to = middle; toX = middleX; if (wrongLine) toX += 1000; dist -= step;}
 25.1057 +      else {from = middle; fromX = middleX; dist = step;}
 25.1058 +    }
 25.1059 +  }
 25.1060 +
 25.1061 +  var measureText;
 25.1062 +  function textHeight(display) {
 25.1063 +    if (display.cachedTextHeight != null) return display.cachedTextHeight;
 25.1064 +    if (measureText == null) {
 25.1065 +      measureText = elt("pre");
 25.1066 +      // Measure a bunch of lines, for browsers that compute
 25.1067 +      // fractional heights.
 25.1068 +      for (var i = 0; i < 49; ++i) {
 25.1069 +        measureText.appendChild(document.createTextNode("x"));
 25.1070 +        measureText.appendChild(elt("br"));
 25.1071 +      }
 25.1072 +      measureText.appendChild(document.createTextNode("x"));
 25.1073 +    }
 25.1074 +    removeChildrenAndAdd(display.measure, measureText);
 25.1075 +    var height = measureText.offsetHeight / 50;
 25.1076 +    if (height > 3) display.cachedTextHeight = height;
 25.1077 +    removeChildren(display.measure);
 25.1078 +    return height || 1;
 25.1079 +  }
 25.1080 +
 25.1081 +  function charWidth(display) {
 25.1082 +    if (display.cachedCharWidth != null) return display.cachedCharWidth;
 25.1083 +    var anchor = elt("span", "x");
 25.1084 +    var pre = elt("pre", [anchor]);
 25.1085 +    removeChildrenAndAdd(display.measure, pre);
 25.1086 +    var width = anchor.offsetWidth;
 25.1087 +    if (width > 2) display.cachedCharWidth = width;
 25.1088 +    return width || 10;
 25.1089 +  }
 25.1090 +
 25.1091 +  // OPERATIONS
 25.1092 +
 25.1093 +  // Operations are used to wrap changes in such a way that each
 25.1094 +  // change won't have to update the cursor and display (which would
 25.1095 +  // be awkward, slow, and error-prone), but instead updates are
 25.1096 +  // batched and then all combined and executed at once.
 25.1097 +
 25.1098 +  function startOperation(cm) {
 25.1099 +    if (cm.curOp) ++cm.curOp.depth;
 25.1100 +    else cm.curOp = {
 25.1101 +      // Nested operations delay update until the outermost one
 25.1102 +      // finishes.
 25.1103 +      depth: 1,
 25.1104 +      // An array of ranges of lines that have to be updated. See
 25.1105 +      // updateDisplay.
 25.1106 +      changes: [],
 25.1107 +      delayedCallbacks: [],
 25.1108 +      updateInput: null,
 25.1109 +      userSelChange: null,
 25.1110 +      textChanged: null,
 25.1111 +      selectionChanged: false,
 25.1112 +      updateMaxLine: false,
 25.1113 +      id: ++cm.nextOpId
 25.1114 +    };
 25.1115 +  }
 25.1116 +
 25.1117 +  function endOperation(cm) {
 25.1118 +    var op = cm.curOp;
 25.1119 +    if (--op.depth) return;
 25.1120 +    cm.curOp = null;
 25.1121 +    var view = cm.view, display = cm.display;
 25.1122 +    if (op.updateMaxLine) computeMaxLength(view);
 25.1123 +    if (view.maxLineChanged && !cm.options.lineWrapping) {
 25.1124 +      var width = measureChar(cm, view.maxLine, view.maxLine.text.length).right;
 25.1125 +      display.sizer.style.minWidth = (width + 3 + scrollerCutOff) + "px";
 25.1126 +      view.maxLineChanged = false;
 25.1127 +    }
 25.1128 +    var newScrollPos, updated;
 25.1129 +    if (op.selectionChanged) {
 25.1130 +      var coords = cursorCoords(cm, view.sel.head);
 25.1131 +      newScrollPos = calculateScrollPos(cm, coords.left, coords.top, coords.left, coords.bottom);
 25.1132 +    }
 25.1133 +    if (op.changes.length || newScrollPos && newScrollPos.scrollTop != null)
 25.1134 +      updated = updateDisplay(cm, op.changes, newScrollPos && newScrollPos.scrollTop);
 25.1135 +    if (!updated && op.selectionChanged) updateSelection(cm);
 25.1136 +    if (newScrollPos) scrollCursorIntoView(cm);
 25.1137 +    if (op.selectionChanged) restartBlink(cm);
 25.1138 +
 25.1139 +    if (view.focused && op.updateInput)
 25.1140 +      resetInput(cm, op.userSelChange);
 25.1141 +
 25.1142 +    if (op.textChanged)
 25.1143 +      signal(cm, "change", cm, op.textChanged);
 25.1144 +    if (op.selectionChanged) signal(cm, "cursorActivity", cm);
 25.1145 +    for (var i = 0; i < op.delayedCallbacks.length; ++i) op.delayedCallbacks[i](cm);
 25.1146 +  }
 25.1147 +
 25.1148 +  // Wraps a function in an operation. Returns the wrapped function.
 25.1149 +  function operation(cm1, f) {
 25.1150 +    return function() {
 25.1151 +      var cm = cm1 || this;
 25.1152 +      startOperation(cm);
 25.1153 +      try {var result = f.apply(cm, arguments);}
 25.1154 +      finally {endOperation(cm);}
 25.1155 +      return result;
 25.1156 +    };
 25.1157 +  }
 25.1158 +
 25.1159 +  function regChange(cm, from, to, lendiff) {
 25.1160 +    cm.curOp.changes.push({from: from, to: to, diff: lendiff});
 25.1161 +  }
 25.1162 +
 25.1163 +  // INPUT HANDLING
 25.1164 +
 25.1165 +  function slowPoll(cm) {
 25.1166 +    if (cm.view.pollingFast) return;
 25.1167 +    cm.display.poll.set(cm.options.pollInterval, function() {
 25.1168 +      readInput(cm);
 25.1169 +      if (cm.view.focused) slowPoll(cm);
 25.1170 +    });
 25.1171 +  }
 25.1172 +
 25.1173 +  function fastPoll(cm) {
 25.1174 +    var missed = false;
 25.1175 +    cm.display.pollingFast = true;
 25.1176 +    function p() {
 25.1177 +      var changed = readInput(cm);
 25.1178 +      if (!changed && !missed) {missed = true; cm.display.poll.set(60, p);}
 25.1179 +      else {cm.display.pollingFast = false; slowPoll(cm);}
 25.1180 +    }
 25.1181 +    cm.display.poll.set(20, p);
 25.1182 +  }
 25.1183 +
 25.1184 +  // prevInput is a hack to work with IME. If we reset the textarea
 25.1185 +  // on every change, that breaks IME. So we look for changes
 25.1186 +  // compared to the previous content instead. (Modern browsers have
 25.1187 +  // events that indicate IME taking place, but these are not widely
 25.1188 +  // supported or compatible enough yet to rely on.)
 25.1189 +  function readInput(cm) {
 25.1190 +    var input = cm.display.input, prevInput = cm.display.prevInput, view = cm.view, sel = view.sel;
 25.1191 +    if (!view.focused || hasSelection(input) || isReadOnly(cm)) return false;
 25.1192 +    var text = input.value;
 25.1193 +    if (text == prevInput && posEq(sel.from, sel.to)) return false;
 25.1194 +    startOperation(cm);
 25.1195 +    view.sel.shift = false;
 25.1196 +    var same = 0, l = Math.min(prevInput.length, text.length);
 25.1197 +    while (same < l && prevInput[same] == text[same]) ++same;
 25.1198 +    var from = sel.from, to = sel.to;
 25.1199 +    if (same < prevInput.length)
 25.1200 +      from = {line: from.line, ch: from.ch - (prevInput.length - same)};
 25.1201 +    else if (view.overwrite && posEq(from, to) && !cm.display.pasteIncoming)
 25.1202 +      to = {line: to.line, ch: Math.min(getLine(cm.view.doc, to.line).text.length, to.ch + (text.length - same))};
 25.1203 +    var updateInput = cm.curOp.updateInput;
 25.1204 +    updateDoc(cm, from, to, splitLines(text.slice(same)), "end",
 25.1205 +              cm.display.pasteIncoming ? "paste" : "input", {from: from, to: to});
 25.1206 +    cm.curOp.updateInput = updateInput;
 25.1207 +    if (text.length > 1000) input.value = cm.display.prevInput = "";
 25.1208 +    else cm.display.prevInput = text;
 25.1209 +    endOperation(cm);
 25.1210 +    cm.display.pasteIncoming = false;
 25.1211 +    return true;
 25.1212 +  }
 25.1213 +
 25.1214 +  function resetInput(cm, user) {
 25.1215 +    var view = cm.view, minimal, selected;
 25.1216 +    if (!posEq(view.sel.from, view.sel.to)) {
 25.1217 +      cm.display.prevInput = "";
 25.1218 +      minimal = hasCopyEvent &&
 25.1219 +        (view.sel.to.line - view.sel.from.line > 100 || (selected = cm.getSelection()).length > 1000);
 25.1220 +      if (minimal) cm.display.input.value = "-";
 25.1221 +      else cm.display.input.value = selected || cm.getSelection();
 25.1222 +      if (view.focused) selectInput(cm.display.input);
 25.1223 +    } else if (user) cm.display.prevInput = cm.display.input.value = "";
 25.1224 +    cm.display.inaccurateSelection = minimal;
 25.1225 +  }
 25.1226 +
 25.1227 +  function focusInput(cm) {
 25.1228 +    if (cm.options.readOnly != "nocursor" && (ie || document.activeElement != cm.display.input))
 25.1229 +      cm.display.input.focus();
 25.1230 +  }
 25.1231 +
 25.1232 +  function isReadOnly(cm) {
 25.1233 +    return cm.options.readOnly || cm.view.cantEdit;
 25.1234 +  }
 25.1235 +
 25.1236 +  // EVENT HANDLERS
 25.1237 +
 25.1238 +  function registerEventHandlers(cm) {
 25.1239 +    var d = cm.display;
 25.1240 +    on(d.scroller, "mousedown", operation(cm, onMouseDown));
 25.1241 +    on(d.scroller, "dblclick", operation(cm, e_preventDefault));
 25.1242 +    on(d.lineSpace, "selectstart", function(e) {
 25.1243 +      if (!mouseEventInWidget(d, e)) e_preventDefault(e);
 25.1244 +    });
 25.1245 +    // Gecko browsers fire contextmenu *after* opening the menu, at
 25.1246 +    // which point we can't mess with it anymore. Context menu is
 25.1247 +    // handled in onMouseDown for Gecko.
 25.1248 +    if (!gecko) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e);});
 25.1249 +
 25.1250 +    on(d.scroller, "scroll", function() {
 25.1251 +      setScrollTop(cm, d.scroller.scrollTop);
 25.1252 +      setScrollLeft(cm, d.scroller.scrollLeft, true);
 25.1253 +      signal(cm, "scroll", cm);
 25.1254 +    });
 25.1255 +    on(d.scrollbarV, "scroll", function() {
 25.1256 +      setScrollTop(cm, d.scrollbarV.scrollTop);
 25.1257 +    });
 25.1258 +    on(d.scrollbarH, "scroll", function() {
 25.1259 +      setScrollLeft(cm, d.scrollbarH.scrollLeft);
 25.1260 +    });
 25.1261 +
 25.1262 +    on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e);});
 25.1263 +    on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e);});
 25.1264 +
 25.1265 +    function reFocus() { if (cm.view.focused) setTimeout(bind(focusInput, cm), 0); }
 25.1266 +    on(d.scrollbarH, "mousedown", reFocus);
 25.1267 +    on(d.scrollbarV, "mousedown", reFocus);
 25.1268 +    // Prevent wrapper from ever scrolling
 25.1269 +    on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
 25.1270 +    on(window, "resize", function resizeHandler() {
 25.1271 +      // Might be a text scaling operation, clear size caches.
 25.1272 +      d.cachedCharWidth = d.cachedTextHeight = null;
 25.1273 +      clearCaches(cm);
 25.1274 +      if (d.wrapper.parentNode) updateDisplay(cm, true);
 25.1275 +      else off(window, "resize", resizeHandler);
 25.1276 +    });
 25.1277 +
 25.1278 +    on(d.input, "keyup", operation(cm, function(e) {
 25.1279 +      if (cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
 25.1280 +      if (e_prop(e, "keyCode") == 16) cm.view.sel.shift = false;
 25.1281 +    }));
 25.1282 +    on(d.input, "input", bind(fastPoll, cm));
 25.1283 +    on(d.input, "keydown", operation(cm, onKeyDown));
 25.1284 +    on(d.input, "keypress", operation(cm, onKeyPress));
 25.1285 +    on(d.input, "focus", bind(onFocus, cm));
 25.1286 +    on(d.input, "blur", bind(onBlur, cm));
 25.1287 +
 25.1288 +    function drag_(e) {
 25.1289 +      if (cm.options.onDragEvent && cm.options.onDragEvent(cm, addStop(e))) return;
 25.1290 +      e_stop(e);
 25.1291 +    }
 25.1292 +    if (cm.options.dragDrop) {
 25.1293 +      on(d.scroller, "dragstart", function(e){onDragStart(cm, e);});
 25.1294 +      on(d.scroller, "dragenter", drag_);
 25.1295 +      on(d.scroller, "dragover", drag_);
 25.1296 +      on(d.scroller, "drop", operation(cm, onDrop));
 25.1297 +    }
 25.1298 +    on(d.scroller, "paste", function(){focusInput(cm); fastPoll(cm);});
 25.1299 +    on(d.input, "paste", function() {
 25.1300 +      d.pasteIncoming = true;
 25.1301 +      fastPoll(cm);
 25.1302 +    });
 25.1303 +
 25.1304 +    function prepareCopy() {
 25.1305 +      if (d.inaccurateSelection) {
 25.1306 +        d.prevInput = "";
 25.1307 +        d.inaccurateSelection = false;
 25.1308 +        d.input.value = cm.getSelection();
 25.1309 +        selectInput(d.input);
 25.1310 +      }
 25.1311 +    }
 25.1312 +    on(d.input, "cut", prepareCopy);
 25.1313 +    on(d.input, "copy", prepareCopy);
 25.1314 +
 25.1315 +    // Needed to handle Tab key in KHTML
 25.1316 +    if (khtml) on(d.sizer, "mouseup", function() {
 25.1317 +        if (document.activeElement == d.input) d.input.blur();
 25.1318 +        focusInput(cm);
 25.1319 +    });
 25.1320 +  }
 25.1321 +
 25.1322 +  function mouseEventInWidget(display, e) {
 25.1323 +    for (var n = e_target(e); n != display.wrapper; n = n.parentNode)
 25.1324 +      if (/\bCodeMirror-(?:line)?widget\b/.test(n.className) ||
 25.1325 +          n.parentNode == display.sizer && n != display.mover) return true;
 25.1326 +  }
 25.1327 +
 25.1328 +  function posFromMouse(cm, e, liberal) {
 25.1329 +    var display = cm.display;
 25.1330 +    if (!liberal) {
 25.1331 +      var target = e_target(e);
 25.1332 +      if (target == display.scrollbarH || target == display.scrollbarH.firstChild ||
 25.1333 +          target == display.scrollbarV || target == display.scrollbarV.firstChild ||
 25.1334 +          target == display.scrollbarFiller) return null;
 25.1335 +    }
 25.1336 +    var x, y, space = display.lineSpace.getBoundingClientRect();
 25.1337 +    // Fails unpredictably on IE[67] when mouse is dragged around quickly.
 25.1338 +    try { x = e.clientX; y = e.clientY; } catch (e) { return null; }
 25.1339 +    return coordsChar(cm, x - space.left, y - space.top);
 25.1340 +  }
 25.1341 +
 25.1342 +  var lastClick, lastDoubleClick;
 25.1343 +  function onMouseDown(e) {
 25.1344 +    var cm = this, display = cm.display, view = cm.view, sel = view.sel, doc = view.doc;
 25.1345 +    sel.shift = e_prop(e, "shiftKey");
 25.1346 +
 25.1347 +    if (mouseEventInWidget(display, e)) {
 25.1348 +      if (!webkit) {
 25.1349 +        display.scroller.draggable = false;
 25.1350 +        setTimeout(function(){display.scroller.draggable = true;}, 100);
 25.1351 +      }
 25.1352 +      return;
 25.1353 +    }
 25.1354 +    if (clickInGutter(cm, e)) return;
 25.1355 +    var start = posFromMouse(cm, e);
 25.1356 +
 25.1357 +    switch (e_button(e)) {
 25.1358 +    case 3:
 25.1359 +      if (gecko) onContextMenu.call(cm, cm, e);
 25.1360 +      return;
 25.1361 +    case 2:
 25.1362 +      if (start) extendSelection(cm, start);
 25.1363 +      setTimeout(bind(focusInput, cm), 20);
 25.1364 +      e_preventDefault(e);
 25.1365 +      return;
 25.1366 +    }
 25.1367 +    // For button 1, if it was clicked inside the editor
 25.1368 +    // (posFromMouse returning non-null), we have to adjust the
 25.1369 +    // selection.
 25.1370 +    if (!start) {if (e_target(e) == display.scroller) e_preventDefault(e); return;}
 25.1371 +
 25.1372 +    if (!view.focused) onFocus(cm);
 25.1373 +
 25.1374 +    var now = +new Date, type = "single";
 25.1375 +    if (lastDoubleClick && lastDoubleClick.time > now - 400 && posEq(lastDoubleClick.pos, start)) {
 25.1376 +      type = "triple";
 25.1377 +      e_preventDefault(e);
 25.1378 +      setTimeout(bind(focusInput, cm), 20);
 25.1379 +      selectLine(cm, start.line);
 25.1380 +    } else if (lastClick && lastClick.time > now - 400 && posEq(lastClick.pos, start)) {
 25.1381 +      type = "double";
 25.1382 +      lastDoubleClick = {time: now, pos: start};
 25.1383 +      e_preventDefault(e);
 25.1384 +      var word = findWordAt(getLine(doc, start.line).text, start);
 25.1385 +      extendSelection(cm, word.from, word.to);
 25.1386 +    } else { lastClick = {time: now, pos: start}; }
 25.1387 +
 25.1388 +    var last = start;
 25.1389 +    if (cm.options.dragDrop && dragAndDrop && !isReadOnly(cm) && !posEq(sel.from, sel.to) &&
 25.1390 +        !posLess(start, sel.from) && !posLess(sel.to, start) && type == "single") {
 25.1391 +      var dragEnd = operation(cm, function(e2) {
 25.1392 +        if (webkit) display.scroller.draggable = false;
 25.1393 +        view.draggingText = false;
 25.1394 +        off(document, "mouseup", dragEnd);
 25.1395 +        off(display.scroller, "drop", dragEnd);
 25.1396 +        if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
 25.1397 +          e_preventDefault(e2);
 25.1398 +          extendSelection(cm, start);
 25.1399 +          focusInput(cm);
 25.1400 +        }
 25.1401 +      });
 25.1402 +      // Let the drag handler handle this.
 25.1403 +      if (webkit) display.scroller.draggable = true;
 25.1404 +      view.draggingText = dragEnd;
 25.1405 +      // IE's approach to draggable
 25.1406 +      if (display.scroller.dragDrop) display.scroller.dragDrop();
 25.1407 +      on(document, "mouseup", dragEnd);
 25.1408 +      on(display.scroller, "drop", dragEnd);
 25.1409 +      return;
 25.1410 +    }
 25.1411 +    e_preventDefault(e);
 25.1412 +    if (type == "single") extendSelection(cm, clipPos(doc, start));
 25.1413 +
 25.1414 +    var startstart = sel.from, startend = sel.to;
 25.1415 +
 25.1416 +    function doSelect(cur) {
 25.1417 +      if (type == "single") {
 25.1418 +        extendSelection(cm, clipPos(doc, start), cur);
 25.1419 +        return;
 25.1420 +      }
 25.1421 +
 25.1422 +      startstart = clipPos(doc, startstart);
 25.1423 +      startend = clipPos(doc, startend);
 25.1424 +      if (type == "double") {
 25.1425 +        var word = findWordAt(getLine(doc, cur.line).text, cur);
 25.1426 +        if (posLess(cur, startstart)) extendSelection(cm, word.from, startend);
 25.1427 +        else extendSelection(cm, startstart, word.to);
 25.1428 +      } else if (type == "triple") {
 25.1429 +        if (posLess(cur, startstart)) extendSelection(cm, startend, clipPos(doc, {line: cur.line, ch: 0}));
 25.1430 +        else extendSelection(cm, startstart, clipPos(doc, {line: cur.line + 1, ch: 0}));
 25.1431 +      }
 25.1432 +    }
 25.1433 +
 25.1434 +    var editorSize = display.wrapper.getBoundingClientRect();
 25.1435 +    // Used to ensure timeout re-tries don't fire when another extend
 25.1436 +    // happened in the meantime (clearTimeout isn't reliable -- at
 25.1437 +    // least on Chrome, the timeouts still happen even when cleared,
 25.1438 +    // if the clear happens after their scheduled firing time).
 25.1439 +    var counter = 0;
 25.1440 +
 25.1441 +    function extend(e) {
 25.1442 +      var curCount = ++counter;
 25.1443 +      var cur = posFromMouse(cm, e, true);
 25.1444 +      if (!cur) return;
 25.1445 +      if (!posEq(cur, last)) {
 25.1446 +        if (!view.focused) onFocus(cm);
 25.1447 +        last = cur;
 25.1448 +        doSelect(cur);
 25.1449 +        var visible = visibleLines(display, doc);
 25.1450 +        if (cur.line >= visible.to || cur.line < visible.from)
 25.1451 +          setTimeout(operation(cm, function(){if (counter == curCount) extend(e);}), 150);
 25.1452 +      } else {
 25.1453 +        var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
 25.1454 +        if (outside) setTimeout(operation(cm, function() {
 25.1455 +          if (counter != curCount) return;
 25.1456 +          display.scroller.scrollTop += outside;
 25.1457 +          extend(e);
 25.1458 +        }), 50);
 25.1459 +      }
 25.1460 +    }
 25.1461 +
 25.1462 +    function done(e) {
 25.1463 +      counter = Infinity;
 25.1464 +      var cur = posFromMouse(cm, e);
 25.1465 +      if (cur) doSelect(cur);
 25.1466 +      e_preventDefault(e);
 25.1467 +      focusInput(cm);
 25.1468 +      off(document, "mousemove", move);
 25.1469 +      off(document, "mouseup", up);
 25.1470 +    }
 25.1471 +
 25.1472 +    var move = operation(cm, function(e) {
 25.1473 +      if (!ie && !e_button(e)) done(e);
 25.1474 +      else extend(e);
 25.1475 +    });
 25.1476 +    var up = operation(cm, done);
 25.1477 +    on(document, "mousemove", move);
 25.1478 +    on(document, "mouseup", up);
 25.1479 +  }
 25.1480 +
 25.1481 +  function onDrop(e) {
 25.1482 +    var cm = this;
 25.1483 +    if (cm.options.onDragEvent && cm.options.onDragEvent(cm, addStop(e))) return;
 25.1484 +    e_preventDefault(e);
 25.1485 +    var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
 25.1486 +    if (!pos || isReadOnly(cm)) return;
 25.1487 +    if (files && files.length && window.FileReader && window.File) {
 25.1488 +      var n = files.length, text = Array(n), read = 0;
 25.1489 +      var loadFile = function(file, i) {
 25.1490 +        var reader = new FileReader;
 25.1491 +        reader.onload = function() {
 25.1492 +          text[i] = reader.result;
 25.1493 +          if (++read == n) {
 25.1494 +            pos = clipPos(cm.view.doc, pos);
 25.1495 +            operation(cm, function() {
 25.1496 +              var end = replaceRange(cm, text.join(""), pos, pos, "paste");
 25.1497 +              setSelection(cm, pos, end);
 25.1498 +            })();
 25.1499 +          }
 25.1500 +        };
 25.1501 +        reader.readAsText(file);
 25.1502 +      };
 25.1503 +      for (var i = 0; i < n; ++i) loadFile(files[i], i);
 25.1504 +    } else {
 25.1505 +      // Don't do a replace if the drop happened inside of the selected text.
 25.1506 +      if (cm.view.draggingText && !(posLess(pos, cm.view.sel.from) || posLess(cm.view.sel.to, pos))) {
 25.1507 +        cm.view.draggingText(e);
 25.1508 +        if (ie) setTimeout(bind(focusInput, cm), 50);
 25.1509 +        return;
 25.1510 +      }
 25.1511 +      try {
 25.1512 +        var text = e.dataTransfer.getData("Text");
 25.1513 +        if (text) {
 25.1514 +          var curFrom = cm.view.sel.from, curTo = cm.view.sel.to;
 25.1515 +          setSelection(cm, pos, pos);
 25.1516 +          if (cm.view.draggingText) replaceRange(cm, "", curFrom, curTo, "paste");
 25.1517 +          cm.replaceSelection(text, null, "paste");
 25.1518 +          focusInput(cm);
 25.1519 +          onFocus(cm);
 25.1520 +        }
 25.1521 +      }
 25.1522 +      catch(e){}
 25.1523 +    }
 25.1524 +  }
 25.1525 +
 25.1526 +  function clickInGutter(cm, e) {
 25.1527 +    var display = cm.display;
 25.1528 +    try { var mX = e.clientX, mY = e.clientY; }
 25.1529 +    catch(e) { return false; }
 25.1530 +
 25.1531 +    if (mX >= Math.floor(display.gutters.getBoundingClientRect().right)) return false;
 25.1532 +    e_preventDefault(e);
 25.1533 +    if (!hasHandler(cm, "gutterClick")) return true;
 25.1534 +
 25.1535 +    var lineBox = display.lineDiv.getBoundingClientRect();
 25.1536 +    if (mY > lineBox.bottom) return true;
 25.1537 +    mY -= lineBox.top - display.viewOffset;
 25.1538 +
 25.1539 +    for (var i = 0; i < cm.options.gutters.length; ++i) {
 25.1540 +      var g = display.gutters.childNodes[i];
 25.1541 +      if (g && g.getBoundingClientRect().right >= mX) {
 25.1542 +        var line = lineAtHeight(cm.view.doc, mY);
 25.1543 +        var gutter = cm.options.gutters[i];
 25.1544 +        signalLater(cm, cm, "gutterClick", cm, line, gutter, e);
 25.1545 +        break;
 25.1546 +      }
 25.1547 +    }
 25.1548 +    return true;
 25.1549 +  }
 25.1550 +
 25.1551 +  function onDragStart(cm, e) {
 25.1552 +    var txt = cm.getSelection();
 25.1553 +    e.dataTransfer.setData("Text", txt);
 25.1554 +
 25.1555 +    // Use dummy image instead of default browsers image.
 25.1556 +    // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
 25.1557 +    if (e.dataTransfer.setDragImage && !safari)
 25.1558 +      e.dataTransfer.setDragImage(elt('img'), 0, 0);
 25.1559 +  }
 25.1560 +
 25.1561 +  function setScrollTop(cm, val) {
 25.1562 +    if (Math.abs(cm.view.scrollTop - val) < 2) return;
 25.1563 +    cm.view.scrollTop = val;
 25.1564 +    if (!gecko) updateDisplay(cm, [], val);
 25.1565 +    if (cm.display.scroller.scrollTop != val) cm.display.scroller.scrollTop = val;
 25.1566 +    if (cm.display.scrollbarV.scrollTop != val) cm.display.scrollbarV.scrollTop = val;
 25.1567 +    if (gecko) updateDisplay(cm, []);
 25.1568 +  }
 25.1569 +  function setScrollLeft(cm, val, isScroller) {
 25.1570 +    if (isScroller ? val == cm.view.scrollLeft : Math.abs(cm.view.scrollLeft - val) < 2) return;
 25.1571 +    cm.view.scrollLeft = val;
 25.1572 +    alignHorizontally(cm);
 25.1573 +    if (cm.display.scroller.scrollLeft != val) cm.display.scroller.scrollLeft = val;
 25.1574 +    if (cm.display.scrollbarH.scrollLeft != val) cm.display.scrollbarH.scrollLeft = val;
 25.1575 +  }
 25.1576 +
 25.1577 +  // Since the delta values reported on mouse wheel events are
 25.1578 +  // unstandardized between browsers and even browser versions, and
 25.1579 +  // generally horribly unpredictable, this code starts by measuring
 25.1580 +  // the scroll effect that the first few mouse wheel events have,
 25.1581 +  // and, from that, detects the way it can convert deltas to pixel
 25.1582 +  // offsets afterwards.
 25.1583 +  //
 25.1584 +  // The reason we want to know the amount a wheel event will scroll
 25.1585 +  // is that it gives us a chance to update the display before the
 25.1586 +  // actual scrolling happens, reducing flickering.
 25.1587 +
 25.1588 +  var wheelSamples = 0, wheelDX, wheelDY, wheelStartX, wheelStartY, wheelPixelsPerUnit = null;
 25.1589 +  // Fill in a browser-detected starting value on browsers where we
 25.1590 +  // know one. These don't have to be accurate -- the result of them
 25.1591 +  // being wrong would just be a slight flicker on the first wheel
 25.1592 +  // scroll (if it is large enough).
 25.1593 +  if (ie) wheelPixelsPerUnit = -.53;
 25.1594 +  else if (gecko) wheelPixelsPerUnit = 15;
 25.1595 +  else if (chrome) wheelPixelsPerUnit = -.7;
 25.1596 +  else if (safari) wheelPixelsPerUnit = -1/3;
 25.1597 +
 25.1598 +  function onScrollWheel(cm, e) {
 25.1599 +    var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
 25.1600 +    if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail;
 25.1601 +    if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail;
 25.1602 +    else if (dy == null) dy = e.wheelDelta;
 25.1603 +
 25.1604 +    // Webkit browsers on OS X abort momentum scrolls when the target
 25.1605 +    // of the scroll event is removed from the scrollable element.
 25.1606 +    // This hack (see related code in patchDisplay) makes sure the
 25.1607 +    // element is kept around.
 25.1608 +    if (dy && mac && webkit) {
 25.1609 +      for (var cur = e.target; cur != scroll; cur = cur.parentNode) {
 25.1610 +        if (cur.lineObj) {
 25.1611 +          cm.display.currentWheelTarget = cur;
 25.1612 +          break;
 25.1613 +        }
 25.1614 +      }
 25.1615 +    }
 25.1616 +
 25.1617 +    var scroll = cm.display.scroller;
 25.1618 +    // On some browsers, horizontal scrolling will cause redraws to
 25.1619 +    // happen before the gutter has been realigned, causing it to
 25.1620 +    // wriggle around in a most unseemly way. When we have an
 25.1621 +    // estimated pixels/delta value, we just handle horizontal
 25.1622 +    // scrolling entirely here. It'll be slightly off from native, but
 25.1623 +    // better than glitching out.
 25.1624 +    if (dx && !gecko && !opera && wheelPixelsPerUnit != null) {
 25.1625 +      if (dy)
 25.1626 +        setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
 25.1627 +      setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
 25.1628 +      e_preventDefault(e);
 25.1629 +      wheelStartX = null; // Abort measurement, if in progress
 25.1630 +      return;
 25.1631 +    }
 25.1632 +
 25.1633 +    if (dy && wheelPixelsPerUnit != null) {
 25.1634 +      var pixels = dy * wheelPixelsPerUnit;
 25.1635 +      var top = cm.view.scrollTop, bot = top + cm.display.wrapper.clientHeight;
 25.1636 +      if (pixels < 0) top = Math.max(0, top + pixels - 50);
 25.1637 +      else bot = Math.min(cm.view.doc.height, bot + pixels + 50);
 25.1638 +      updateDisplay(cm, [], {top: top, bottom: bot});
 25.1639 +    }
 25.1640 +
 25.1641 +    if (wheelSamples < 20) {
 25.1642 +      if (wheelStartX == null) {
 25.1643 +        wheelStartX = scroll.scrollLeft; wheelStartY = scroll.scrollTop;
 25.1644 +        wheelDX = dx; wheelDY = dy;
 25.1645 +        setTimeout(function() {
 25.1646 +          if (wheelStartX == null) return;
 25.1647 +          var movedX = scroll.scrollLeft - wheelStartX;
 25.1648 +          var movedY = scroll.scrollTop - wheelStartY;
 25.1649 +          var sample = (movedY && wheelDY && movedY / wheelDY) ||
 25.1650 +            (movedX && wheelDX && movedX / wheelDX);
 25.1651 +          wheelStartX = wheelStartY = null;
 25.1652 +          if (!sample) return;
 25.1653 +          wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
 25.1654 +          ++wheelSamples;
 25.1655 +        }, 200);
 25.1656 +      } else {
 25.1657 +        wheelDX += dx; wheelDY += dy;
 25.1658 +      }
 25.1659 +    }
 25.1660 +  }
 25.1661 +
 25.1662 +  function doHandleBinding(cm, bound, dropShift) {
 25.1663 +    if (typeof bound == "string") {
 25.1664 +      bound = commands[bound];
 25.1665 +      if (!bound) return false;
 25.1666 +    }
 25.1667 +    // Ensure previous input has been read, so that the handler sees a
 25.1668 +    // consistent view of the document
 25.1669 +    if (cm.display.pollingFast && readInput(cm)) cm.display.pollingFast = false;
 25.1670 +    var view = cm.view, prevShift = view.sel.shift;
 25.1671 +    try {
 25.1672 +      if (isReadOnly(cm)) view.suppressEdits = true;
 25.1673 +      if (dropShift) view.sel.shift = false;
 25.1674 +      bound(cm);
 25.1675 +    } catch(e) {
 25.1676 +      if (e != Pass) throw e;
 25.1677 +      return false;
 25.1678 +    } finally {
 25.1679 +      view.sel.shift = prevShift;
 25.1680 +      view.suppressEdits = false;
 25.1681 +    }
 25.1682 +    return true;
 25.1683 +  }
 25.1684 +
 25.1685 +  function allKeyMaps(cm) {
 25.1686 +    var maps = cm.view.keyMaps.slice(0);
 25.1687 +    maps.push(cm.options.keyMap);
 25.1688 +    if (cm.options.extraKeys) maps.unshift(cm.options.extraKeys);
 25.1689 +    return maps;
 25.1690 +  }
 25.1691 +
 25.1692 +  var maybeTransition;
 25.1693 +  function handleKeyBinding(cm, e) {
 25.1694 +    // Handle auto keymap transitions
 25.1695 +    var startMap = getKeyMap(cm.options.keyMap), next = startMap.auto;
 25.1696 +    clearTimeout(maybeTransition);
 25.1697 +    if (next && !isModifierKey(e)) maybeTransition = setTimeout(function() {
 25.1698 +      if (getKeyMap(cm.options.keyMap) == startMap)
 25.1699 +        cm.options.keyMap = (next.call ? next.call(null, cm) : next);
 25.1700 +    }, 50);
 25.1701 +
 25.1702 +    var name = keyNames[e_prop(e, "keyCode")], handled = false;
 25.1703 +    var flipCtrlCmd = mac && (opera || qtwebkit);
 25.1704 +    if (name == null || e.altGraphKey) return false;
 25.1705 +    if (e_prop(e, "altKey")) name = "Alt-" + name;
 25.1706 +    if (e_prop(e, flipCtrlCmd ? "metaKey" : "ctrlKey")) name = "Ctrl-" + name;
 25.1707 +    if (e_prop(e, flipCtrlCmd ? "ctrlKey" : "metaKey")) name = "Cmd-" + name;
 25.1708 +
 25.1709 +    var stopped = false;
 25.1710 +    function stop() { stopped = true; }
 25.1711 +    var keymaps = allKeyMaps(cm);
 25.1712 +
 25.1713 +    if (e_prop(e, "shiftKey")) {
 25.1714 +      handled = lookupKey("Shift-" + name, keymaps,
 25.1715 +                          function(b) {return doHandleBinding(cm, b, true);}, stop)
 25.1716 +        || lookupKey(name, keymaps, function(b) {
 25.1717 +          if (typeof b == "string" && /^go[A-Z]/.test(b)) return doHandleBinding(cm, b);
 25.1718 +        }, stop);
 25.1719 +    } else {
 25.1720 +      handled = lookupKey(name, keymaps,
 25.1721 +                          function(b) { return doHandleBinding(cm, b); }, stop);
 25.1722 +    }
 25.1723 +    if (stopped) handled = false;
 25.1724 +    if (handled) {
 25.1725 +      e_preventDefault(e);
 25.1726 +      restartBlink(cm);
 25.1727 +      if (ie_lt9) { e.oldKeyCode = e.keyCode; e.keyCode = 0; }
 25.1728 +    }
 25.1729 +    return handled;
 25.1730 +  }
 25.1731 +
 25.1732 +  function handleCharBinding(cm, e, ch) {
 25.1733 +    var handled = lookupKey("'" + ch + "'", allKeyMaps(cm),
 25.1734 +                            function(b) { return doHandleBinding(cm, b, true); });
 25.1735 +    if (handled) {
 25.1736 +      e_preventDefault(e);
 25.1737 +      restartBlink(cm);
 25.1738 +    }
 25.1739 +    return handled;
 25.1740 +  }
 25.1741 +
 25.1742 +  var lastStoppedKey = null;
 25.1743 +  function onKeyDown(e) {
 25.1744 +    var cm = this;
 25.1745 +    if (!cm.view.focused) onFocus(cm);
 25.1746 +    if (ie && e.keyCode == 27) { e.returnValue = false; }
 25.1747 +    if (cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
 25.1748 +    var code = e_prop(e, "keyCode");
 25.1749 +    // IE does strange things with escape.
 25.1750 +    cm.view.sel.shift = code == 16 || e_prop(e, "shiftKey");
 25.1751 +    // First give onKeyEvent option a chance to handle this.
 25.1752 +    var handled = handleKeyBinding(cm, e);
 25.1753 +    if (opera) {
 25.1754 +      lastStoppedKey = handled ? code : null;
 25.1755 +      // Opera has no cut event... we try to at least catch the key combo
 25.1756 +      if (!handled && code == 88 && !hasCopyEvent && e_prop(e, mac ? "metaKey" : "ctrlKey"))
 25.1757 +        cm.replaceSelection("");
 25.1758 +    }
 25.1759 +  }
 25.1760 +
 25.1761 +  function onKeyPress(e) {
 25.1762 +    var cm = this;
 25.1763 +    if (cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
 25.1764 +    var keyCode = e_prop(e, "keyCode"), charCode = e_prop(e, "charCode");
 25.1765 +    if (opera && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
 25.1766 +    if (((opera && (!e.which || e.which < 10)) || khtml) && handleKeyBinding(cm, e)) return;
 25.1767 +    var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
 25.1768 +    if (this.options.electricChars && this.view.mode.electricChars &&
 25.1769 +        this.options.smartIndent && !isReadOnly(this) &&
 25.1770 +        this.view.mode.electricChars.indexOf(ch) > -1)
 25.1771 +      setTimeout(operation(cm, function() {indentLine(cm, cm.view.sel.to.line, "smart");}), 75);
 25.1772 +    if (handleCharBinding(cm, e, ch)) return;
 25.1773 +    fastPoll(cm);
 25.1774 +  }
 25.1775 +
 25.1776 +  function onFocus(cm) {
 25.1777 +    if (cm.options.readOnly == "nocursor") return;
 25.1778 +    if (!cm.view.focused) {
 25.1779 +      signal(cm, "focus", cm);
 25.1780 +      cm.view.focused = true;
 25.1781 +      if (cm.display.scroller.className.search(/\bCodeMirror-focused\b/) == -1)
 25.1782 +        cm.display.scroller.className += " CodeMirror-focused";
 25.1783 +      resetInput(cm, true);
 25.1784 +    }
 25.1785 +    slowPoll(cm);
 25.1786 +    restartBlink(cm);
 25.1787 +  }
 25.1788 +  function onBlur(cm) {
 25.1789 +    if (cm.view.focused) {
 25.1790 +      signal(cm, "blur", cm);
 25.1791 +      cm.view.focused = false;
 25.1792 +      cm.display.scroller.className = cm.display.scroller.className.replace(" CodeMirror-focused", "");
 25.1793 +    }
 25.1794 +    clearInterval(cm.display.blinker);
 25.1795 +    setTimeout(function() {if (!cm.view.focused) cm.view.sel.shift = false;}, 150);
 25.1796 +  }
 25.1797 +
 25.1798 +  var detectingSelectAll;
 25.1799 +  function onContextMenu(cm, e) {
 25.1800 +    var display = cm.display, sel = cm.view.sel;
 25.1801 +    var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
 25.1802 +    if (!pos || opera) return; // Opera is difficult.
 25.1803 +    if (posEq(sel.from, sel.to) || posLess(pos, sel.from) || !posLess(pos, sel.to))
 25.1804 +      operation(cm, setSelection)(cm, pos, pos);
 25.1805 +
 25.1806 +    var oldCSS = display.input.style.cssText;
 25.1807 +    display.inputDiv.style.position = "absolute";
 25.1808 +    display.input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) +
 25.1809 +      "px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: white; outline: none;" +
 25.1810 +      "border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
 25.1811 +    focusInput(cm);
 25.1812 +    resetInput(cm, true);
 25.1813 +    // Adds "Select all" to context menu in FF
 25.1814 +    if (posEq(sel.from, sel.to)) display.input.value = display.prevInput = " ";
 25.1815 +
 25.1816 +    function rehide() {
 25.1817 +      display.inputDiv.style.position = "relative";
 25.1818 +      display.input.style.cssText = oldCSS;
 25.1819 +      if (ie_lt9) display.scrollbarV.scrollTop = display.scroller.scrollTop = scrollPos;
 25.1820 +      slowPoll(cm);
 25.1821 +
 25.1822 +      // Try to detect the user choosing select-all 
 25.1823 +      if (display.input.selectionStart != null) {
 25.1824 +        clearTimeout(detectingSelectAll);
 25.1825 +        var extval = display.input.value = " " + (posEq(sel.from, sel.to) ? "" : display.input.value), i = 0;
 25.1826 +        display.prevInput = " ";
 25.1827 +        display.input.selectionStart = 1; display.input.selectionEnd = extval.length;
 25.1828 +        detectingSelectAll = setTimeout(function poll(){
 25.1829 +          if (display.prevInput == " " && display.input.selectionStart == 0)
 25.1830 +            operation(cm, commands.selectAll)(cm);
 25.1831 +          else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500);
 25.1832 +          else resetInput(cm);
 25.1833 +        }, 200);
 25.1834 +      }
 25.1835 +    }
 25.1836 +
 25.1837 +    if (gecko) {
 25.1838 +      e_stop(e);
 25.1839 +      on(window, "mouseup", function mouseup() {
 25.1840 +        off(window, "mouseup", mouseup);
 25.1841 +        setTimeout(rehide, 20);
 25.1842 +      });
 25.1843 +    } else {
 25.1844 +      setTimeout(rehide, 50);
 25.1845 +    }
 25.1846 +  }
 25.1847 +
 25.1848 +  // UPDATING
 25.1849 +
 25.1850 +  // Replace the range from from to to by the strings in newText.
 25.1851 +  // Afterwards, set the selection to selFrom, selTo.
 25.1852 +  function updateDoc(cm, from, to, newText, selUpdate, origin) {
 25.1853 +    // Possibly split or suppress the update based on the presence
 25.1854 +    // of read-only spans in its range.
 25.1855 +    var split = sawReadOnlySpans &&
 25.1856 +      removeReadOnlyRanges(cm.view.doc, from, to);
 25.1857 +    if (split) {
 25.1858 +      for (var i = split.length - 1; i >= 1; --i)
 25.1859 +        updateDocInner(cm, split[i].from, split[i].to, [""], origin);
 25.1860 +      if (split.length)
 25.1861 +        return updateDocInner(cm, split[0].from, split[0].to, newText, selUpdate, origin);
 25.1862 +    } else {
 25.1863 +      return updateDocInner(cm, from, to, newText, selUpdate, origin);
 25.1864 +    }
 25.1865 +  }
 25.1866 +
 25.1867 +  function updateDocInner(cm, from, to, newText, selUpdate, origin) {
 25.1868 +    if (cm.view.suppressEdits) return;
 25.1869 +
 25.1870 +    var view = cm.view, doc = view.doc, old = [];
 25.1871 +    doc.iter(from.line, to.line + 1, function(line) {
 25.1872 +      old.push(newHL(line.text, line.markedSpans));
 25.1873 +    });
 25.1874 +    var startSelFrom = view.sel.from, startSelTo = view.sel.to;
 25.1875 +    var lines = updateMarkedSpans(hlSpans(old[0]), hlSpans(lst(old)), from.ch, to.ch, newText);
 25.1876 +    var retval = updateDocNoUndo(cm, from, to, lines, selUpdate, origin);
 25.1877 +    if (view.history) addChange(cm, from.line, newText.length, old, origin,
 25.1878 +                                startSelFrom, startSelTo, view.sel.from, view.sel.to);
 25.1879 +    return retval;
 25.1880 +  }
 25.1881 +
 25.1882 +  function unredoHelper(cm, type) {
 25.1883 +    var doc = cm.view.doc, hist = cm.view.history;
 25.1884 +    var set = (type == "undo" ? hist.done : hist.undone).pop();
 25.1885 +    if (!set) return;
 25.1886 +    var anti = {events: [], fromBefore: set.fromAfter, toBefore: set.toAfter,
 25.1887 +                fromAfter: set.fromBefore, toAfter: set.toBefore};
 25.1888 +    for (var i = set.events.length - 1; i >= 0; i -= 1) {
 25.1889 +      hist.dirtyCounter += type == "undo" ? -1 : 1;
 25.1890 +      var change = set.events[i];
 25.1891 +      var replaced = [], end = change.start + change.added;
 25.1892 +      doc.iter(change.start, end, function(line) { replaced.push(newHL(line.text, line.markedSpans)); });
 25.1893 +      anti.events.push({start: change.start, added: change.old.length, old: replaced});
 25.1894 +      var selPos = i ? null : {from: set.fromBefore, to: set.toBefore};
 25.1895 +      updateDocNoUndo(cm, {line: change.start, ch: 0}, {line: end - 1, ch: getLine(doc, end-1).text.length},
 25.1896 +                      change.old, selPos, type);
 25.1897 +    }
 25.1898 +    (type == "undo" ? hist.undone : hist.done).push(anti);
 25.1899 +  }
 25.1900 +
 25.1901 +  function updateDocNoUndo(cm, from, to, lines, selUpdate, origin) {
 25.1902 +    var view = cm.view, doc = view.doc, display = cm.display;
 25.1903 +    if (view.suppressEdits) return;
 25.1904 +
 25.1905 +    var nlines = to.line - from.line, firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
 25.1906 +    var recomputeMaxLength = false, checkWidthStart = from.line;
 25.1907 +    if (!cm.options.lineWrapping) {
 25.1908 +      checkWidthStart = lineNo(visualLine(doc, firstLine));
 25.1909 +      doc.iter(checkWidthStart, to.line + 1, function(line) {
 25.1910 +        if (lineLength(doc, line) == view.maxLineLength) {
 25.1911 +          recomputeMaxLength = true;
 25.1912 +          return true;
 25.1913 +        }
 25.1914 +      });
 25.1915 +    }
 25.1916 +
 25.1917 +    var lastHL = lst(lines), th = textHeight(display);
 25.1918 +
 25.1919 +    // First adjust the line structure
 25.1920 +    if (from.ch == 0 && to.ch == 0 && hlText(lastHL) == "") {
 25.1921 +      // This is a whole-line replace. Treated specially to make
 25.1922 +      // sure line objects move the way they are supposed to.
 25.1923 +      var added = [];
 25.1924 +      for (var i = 0, e = lines.length - 1; i < e; ++i)
 25.1925 +        added.push(makeLine(hlText(lines[i]), hlSpans(lines[i]), th));
 25.1926 +      updateLine(cm, lastLine, lastLine.text, hlSpans(lastHL));
 25.1927 +      if (nlines) doc.remove(from.line, nlines, cm);
 25.1928 +      if (added.length) doc.insert(from.line, added);
 25.1929 +    } else if (firstLine == lastLine) {
 25.1930 +      if (lines.length == 1) {
 25.1931 +        updateLine(cm, firstLine, firstLine.text.slice(0, from.ch) + hlText(lines[0]) +
 25.1932 +                   firstLine.text.slice(to.ch), hlSpans(lines[0]));
 25.1933 +      } else {
 25.1934 +        for (var added = [], i = 1, e = lines.length - 1; i < e; ++i)
 25.1935 +          added.push(makeLine(hlText(lines[i]), hlSpans(lines[i]), th));
 25.1936 +        added.push(makeLine(hlText(lastHL) + firstLine.text.slice(to.ch), hlSpans(lastHL), th));
 25.1937 +        updateLine(cm, firstLine, firstLine.text.slice(0, from.ch) + hlText(lines[0]), hlSpans(lines[0]));
 25.1938 +        doc.insert(from.line + 1, added);
 25.1939 +      }
 25.1940 +    } else if (lines.length == 1) {
 25.1941 +      updateLine(cm, firstLine, firstLine.text.slice(0, from.ch) + hlText(lines[0]) +
 25.1942 +                 lastLine.text.slice(to.ch), hlSpans(lines[0]));
 25.1943 +      doc.remove(from.line + 1, nlines, cm);
 25.1944 +    } else {
 25.1945 +      var added = [];
 25.1946 +      updateLine(cm, firstLine, firstLine.text.slice(0, from.ch) + hlText(lines[0]), hlSpans(lines[0]));
 25.1947 +      updateLine(cm, lastLine, hlText(lastHL) + lastLine.text.slice(to.ch), hlSpans(lastHL));
 25.1948 +      for (var i = 1, e = lines.length - 1; i < e; ++i)
 25.1949 +        added.push(makeLine(hlText(lines[i]), hlSpans(lines[i]), th));
 25.1950 +      if (nlines > 1) doc.remove(from.line + 1, nlines - 1, cm);
 25.1951 +      doc.insert(from.line + 1, added);
 25.1952 +    }
 25.1953 +
 25.1954 +    if (cm.options.lineWrapping) {
 25.1955 +      var perLine = Math.max(5, display.scroller.clientWidth / charWidth(display) - 3);
 25.1956 +      doc.iter(from.line, from.line + lines.length, function(line) {
 25.1957 +        if (line.height == 0) return;
 25.1958 +        var guess = (Math.ceil(line.text.length / perLine) || 1) * th;
 25.1959 +        if (guess != line.height) updateLineHeight(line, guess);
 25.1960 +      });
 25.1961 +    } else {
 25.1962 +      doc.iter(checkWidthStart, from.line + lines.length, function(line) {
 25.1963 +        var len = lineLength(doc, line);
 25.1964 +        if (len > view.maxLineLength) {
 25.1965 +          view.maxLine = line;
 25.1966 +          view.maxLineLength = len;
 25.1967 +          view.maxLineChanged = true;
 25.1968 +          recomputeMaxLength = false;
 25.1969 +        }
 25.1970 +      });
 25.1971 +      if (recomputeMaxLength) cm.curOp.updateMaxLine = true;
 25.1972 +    }
 25.1973 +
 25.1974 +    // Adjust frontier, schedule worker
 25.1975 +    view.frontier = Math.min(view.frontier, from.line);
 25.1976 +    startWorker(cm, 400);
 25.1977 +
 25.1978 +    var lendiff = lines.length - nlines - 1;
 25.1979 +    // Remember that these lines changed, for updating the display
 25.1980 +    regChange(cm, from.line, to.line + 1, lendiff);
 25.1981 +    if (hasHandler(cm, "change")) {
 25.1982 +      // Normalize lines to contain only strings, since that's what
 25.1983 +      // the change event handler expects
 25.1984 +      for (var i = 0; i < lines.length; ++i)
 25.1985 +        if (typeof lines[i] != "string") lines[i] = lines[i].text;
 25.1986 +      var changeObj = {from: from, to: to, text: lines, origin: origin};
 25.1987 +      if (cm.curOp.textChanged) {
 25.1988 +        for (var cur = cm.curOp.textChanged; cur.next; cur = cur.next) {}
 25.1989 +        cur.next = changeObj;
 25.1990 +      } else cm.curOp.textChanged = changeObj;
 25.1991 +    }
 25.1992 +
 25.1993 +    // Update the selection
 25.1994 +    var newSelFrom, newSelTo, end = {line: from.line + lines.length - 1,
 25.1995 +                                     ch: hlText(lastHL).length  + (lines.length == 1 ? from.ch : 0)};
 25.1996 +    if (selUpdate && typeof selUpdate != "string") {
 25.1997 +      if (selUpdate.from) { newSelFrom = selUpdate.from; newSelTo = selUpdate.to; }
 25.1998 +      else newSelFrom = newSelTo = selUpdate;
 25.1999 +    } else if (selUpdate == "end") {
 25.2000 +      newSelFrom = newSelTo = end;
 25.2001 +    } else if (selUpdate == "start") {
 25.2002 +      newSelFrom = newSelTo = from;
 25.2003 +    } else if (selUpdate == "around") {
 25.2004 +      newSelFrom = from; newSelTo = end;
 25.2005 +    } else {
 25.2006 +      var adjustPos = function(pos) {
 25.2007 +        if (posLess(pos, from)) return pos;
 25.2008 +        if (!posLess(to, pos)) return end;
 25.2009 +        var line = pos.line + lendiff;
 25.2010 +        var ch = pos.ch;
 25.2011 +        if (pos.line == to.line)
 25.2012 +          ch += hlText(lastHL).length - (to.ch - (to.line == from.line ? from.ch : 0));
 25.2013 +        return {line: line, ch: ch};
 25.2014 +      };
 25.2015 +      newSelFrom = adjustPos(view.sel.from);
 25.2016 +      newSelTo = adjustPos(view.sel.to);
 25.2017 +    }
 25.2018 +    setSelection(cm, newSelFrom, newSelTo, null, true);
 25.2019 +    return end;
 25.2020 +  }
 25.2021 +
 25.2022 +  function replaceRange(cm, code, from, to, origin) {
 25.2023 +    if (!to) to = from;
 25.2024 +    if (posLess(to, from)) { var tmp = to; to = from; from = tmp; }
 25.2025 +    return updateDoc(cm, from, to, splitLines(code), null, origin);
 25.2026 +  }
 25.2027 +
 25.2028 +  // SELECTION
 25.2029 +
 25.2030 +  function posEq(a, b) {return a.line == b.line && a.ch == b.ch;}
 25.2031 +  function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);}
 25.2032 +  function copyPos(x) {return {line: x.line, ch: x.ch};}
 25.2033 +
 25.2034 +  function clipLine(doc, n) {return Math.max(0, Math.min(n, doc.size-1));}
 25.2035 +  function clipPos(doc, pos) {
 25.2036 +    if (pos.line < 0) return {line: 0, ch: 0};
 25.2037 +    if (pos.line >= doc.size) return {line: doc.size-1, ch: getLine(doc, doc.size-1).text.length};
 25.2038 +    var ch = pos.ch, linelen = getLine(doc, pos.line).text.length;
 25.2039 +    if (ch == null || ch > linelen) return {line: pos.line, ch: linelen};
 25.2040 +    else if (ch < 0) return {line: pos.line, ch: 0};
 25.2041 +    else return pos;
 25.2042 +  }
 25.2043 +  function isLine(doc, l) {return l >= 0 && l < doc.size;}
 25.2044 +
 25.2045 +  // If shift is held, this will move the selection anchor. Otherwise,
 25.2046 +  // it'll set the whole selection.
 25.2047 +  function extendSelection(cm, pos, other, bias) {
 25.2048 +    var sel = cm.view.sel;
 25.2049 +    if (sel.shift || sel.extend) {
 25.2050 +      var anchor = sel.anchor;
 25.2051 +      if (other) {
 25.2052 +        var posBefore = posLess(pos, anchor);
 25.2053 +        if (posBefore != posLess(other, anchor)) {
 25.2054 +          anchor = pos;
 25.2055 +          pos = other;
 25.2056 +        } else if (posBefore != posLess(pos, other)) {
 25.2057 +          pos = other;
 25.2058 +        }
 25.2059 +      }
 25.2060 +      setSelection(cm, anchor, pos, bias);
 25.2061 +    } else {
 25.2062 +      setSelection(cm, pos, other || pos, bias);
 25.2063 +    }
 25.2064 +    cm.curOp.userSelChange = true;
 25.2065 +  }
 25.2066 +
 25.2067 +  // Update the selection. Last two args are only used by
 25.2068 +  // updateDoc, since they have to be expressed in the line
 25.2069 +  // numbers before the update.
 25.2070 +  function setSelection(cm, anchor, head, bias, checkAtomic) {
 25.2071 +    cm.view.goalColumn = null;
 25.2072 +    var sel = cm.view.sel;
 25.2073 +    // Skip over atomic spans.
 25.2074 +    if (checkAtomic || !posEq(anchor, sel.anchor))
 25.2075 +      anchor = skipAtomic(cm, anchor, bias, checkAtomic != "push");
 25.2076 +    if (checkAtomic || !posEq(head, sel.head))
 25.2077 +      head = skipAtomic(cm, head, bias, checkAtomic != "push");
 25.2078 +
 25.2079 +    if (posEq(sel.anchor, anchor) && posEq(sel.head, head)) return;
 25.2080 +
 25.2081 +    sel.anchor = anchor; sel.head = head;
 25.2082 +    var inv = posLess(head, anchor);
 25.2083 +    sel.from = inv ? head : anchor;
 25.2084 +    sel.to = inv ? anchor : head;
 25.2085 +
 25.2086 +    cm.curOp.updateInput = true;
 25.2087 +    cm.curOp.selectionChanged = true;
 25.2088 +  }
 25.2089 +
 25.2090 +  function reCheckSelection(cm) {
 25.2091 +    setSelection(cm, cm.view.sel.from, cm.view.sel.to, null, "push");
 25.2092 +  }
 25.2093 +
 25.2094 +  function skipAtomic(cm, pos, bias, mayClear) {
 25.2095 +    var doc = cm.view.doc, flipped = false, curPos = pos;
 25.2096 +    var dir = bias || 1;
 25.2097 +    cm.view.cantEdit = false;
 25.2098 +    search: for (;;) {
 25.2099 +      var line = getLine(doc, curPos.line), toClear;
 25.2100 +      if (line.markedSpans) {
 25.2101 +        for (var i = 0; i < line.markedSpans.length; ++i) {
 25.2102 +          var sp = line.markedSpans[i], m = sp.marker;
 25.2103 +          if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) &&
 25.2104 +              (sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) {
 25.2105 +            if (mayClear && m.clearOnEnter) {
 25.2106 +              (toClear || (toClear = [])).push(m);
 25.2107 +              continue;
 25.2108 +            } else if (!m.atomic) continue;
 25.2109 +            var newPos = m.find()[dir < 0 ? "from" : "to"];
 25.2110 +            if (posEq(newPos, curPos)) {
 25.2111 +              newPos.ch += dir;
 25.2112 +              if (newPos.ch < 0) {
 25.2113 +                if (newPos.line) newPos = clipPos(doc, {line: newPos.line - 1});
 25.2114 +                else newPos = null;
 25.2115 +              } else if (newPos.ch > line.text.length) {
 25.2116 +                if (newPos.line < doc.size - 1) newPos = {line: newPos.line + 1, ch: 0};
 25.2117 +                else newPos = null;
 25.2118 +              }
 25.2119 +              if (!newPos) {
 25.2120 +                if (flipped) {
 25.2121 +                  // Driven in a corner -- no valid cursor position found at all
 25.2122 +                  // -- try again *with* clearing, if we didn't already
 25.2123 +                  if (!mayClear) return skipAtomic(cm, pos, bias, true);
 25.2124 +                  // Otherwise, turn off editing until further notice, and return the start of the doc
 25.2125 +                  cm.view.cantEdit = true;
 25.2126 +                  return {line: 0, ch: 0};
 25.2127 +                }
 25.2128 +                flipped = true; newPos = pos; dir = -dir;
 25.2129 +              }
 25.2130 +            }
 25.2131 +            curPos = newPos;
 25.2132 +            continue search;
 25.2133 +          }
 25.2134 +        }
 25.2135 +        if (toClear) for (var i = 0; i < toClear.length; ++i) toClear[i].clear();
 25.2136 +      }
 25.2137 +      return curPos;
 25.2138 +    }
 25.2139 +  }
 25.2140 +
 25.2141 +  // SCROLLING
 25.2142 +
 25.2143 +  function scrollCursorIntoView(cm) {
 25.2144 +    var view = cm.view;
 25.2145 +    var coords = scrollPosIntoView(cm, view.sel.head);
 25.2146 +    if (!view.focused) return;
 25.2147 +    var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
 25.2148 +    if (coords.top + box.top < 0) doScroll = true;
 25.2149 +    else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
 25.2150 +    if (doScroll != null && !phantom) {
 25.2151 +      var hidden = display.cursor.style.display == "none";
 25.2152 +      if (hidden) {
 25.2153 +        display.cursor.style.display = "";
 25.2154 +        display.cursor.style.left = coords.left + "px";
 25.2155 +        display.cursor.style.top = (coords.top - display.viewOffset) + "px";
 25.2156 +      }
 25.2157 +      display.cursor.scrollIntoView(doScroll);
 25.2158 +      if (hidden) display.cursor.style.display = "none";
 25.2159 +    }
 25.2160 +  }
 25.2161 +
 25.2162 +  function scrollPosIntoView(cm, pos) {
 25.2163 +    for (;;) {
 25.2164 +      var changed = false, coords = cursorCoords(cm, pos);
 25.2165 +      var scrollPos = calculateScrollPos(cm, coords.left, coords.top, coords.left, coords.bottom);
 25.2166 +      var startTop = cm.view.scrollTop, startLeft = cm.view.scrollLeft;
 25.2167 +      if (scrollPos.scrollTop != null) {
 25.2168 +        setScrollTop(cm, scrollPos.scrollTop);
 25.2169 +        if (Math.abs(cm.view.scrollTop - startTop) > 1) changed = true;
 25.2170 +      }
 25.2171 +      if (scrollPos.scrollLeft != null) {
 25.2172 +        setScrollLeft(cm, scrollPos.scrollLeft);
 25.2173 +        if (Math.abs(cm.view.scrollLeft - startLeft) > 1) changed = true;
 25.2174 +      }
 25.2175 +      if (!changed) return coords;
 25.2176 +    }
 25.2177 +  }
 25.2178 +
 25.2179 +  function scrollIntoView(cm, x1, y1, x2, y2) {
 25.2180 +    var scrollPos = calculateScrollPos(cm, x1, y1, x2, y2);
 25.2181 +    if (scrollPos.scrollTop != null) setScrollTop(cm, scrollPos.scrollTop);
 25.2182 +    if (scrollPos.scrollLeft != null) setScrollLeft(cm, scrollPos.scrollLeft);
 25.2183 +  }
 25.2184 +
 25.2185 +  function calculateScrollPos(cm, x1, y1, x2, y2) {
 25.2186 +    var display = cm.display, pt = paddingTop(display);
 25.2187 +    y1 += pt; y2 += pt;
 25.2188 +    var screen = display.scroller.clientHeight - scrollerCutOff, screentop = display.scroller.scrollTop, result = {};
 25.2189 +    var docBottom = cm.view.doc.height + 2 * pt;
 25.2190 +    var atTop = y1 < pt + 10, atBottom = y2 + pt > docBottom - 10;
 25.2191 +    if (y1 < screentop) result.scrollTop = atTop ? 0 : Math.max(0, y1);
 25.2192 +    else if (y2 > screentop + screen) result.scrollTop = (atBottom ? docBottom : y2) - screen;
 25.2193 +
 25.2194 +    var screenw = display.scroller.clientWidth - scrollerCutOff, screenleft = display.scroller.scrollLeft;
 25.2195 +    x1 += display.gutters.offsetWidth; x2 += display.gutters.offsetWidth;
 25.2196 +    var gutterw = display.gutters.offsetWidth;
 25.2197 +    var atLeft = x1 < gutterw + 10;
 25.2198 +    if (x1 < screenleft + gutterw || atLeft) {
 25.2199 +      if (atLeft) x1 = 0;
 25.2200 +      result.scrollLeft = Math.max(0, x1 - 10 - gutterw);
 25.2201 +    } else if (x2 > screenw + screenleft - 3) {
 25.2202 +      result.scrollLeft = x2 + 10 - screenw;
 25.2203 +    }
 25.2204 +    return result;
 25.2205 +  }
 25.2206 +
 25.2207 +  // API UTILITIES
 25.2208 +
 25.2209 +  function indentLine(cm, n, how, aggressive) {
 25.2210 +    var doc = cm.view.doc;
 25.2211 +    if (!how) how = "add";
 25.2212 +    if (how == "smart") {
 25.2213 +      if (!cm.view.mode.indent) how = "prev";
 25.2214 +      else var state = getStateBefore(cm, n);
 25.2215 +    }
 25.2216 +
 25.2217 +    var tabSize = cm.options.tabSize;
 25.2218 +    var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
 25.2219 +    var curSpaceString = line.text.match(/^\s*/)[0], indentation;
 25.2220 +    if (how == "smart") {
 25.2221 +      indentation = cm.view.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
 25.2222 +      if (indentation == Pass) {
 25.2223 +        if (!aggressive) return;
 25.2224 +        how = "prev";
 25.2225 +      }
 25.2226 +    }
 25.2227 +    if (how == "prev") {
 25.2228 +      if (n) indentation = countColumn(getLine(doc, n-1).text, null, tabSize);
 25.2229 +      else indentation = 0;
 25.2230 +    }
 25.2231 +    else if (how == "add") indentation = curSpace + cm.options.indentUnit;
 25.2232 +    else if (how == "subtract") indentation = curSpace - cm.options.indentUnit;
 25.2233 +    indentation = Math.max(0, indentation);
 25.2234 +
 25.2235 +    var indentString = "", pos = 0;
 25.2236 +    if (cm.options.indentWithTabs)
 25.2237 +      for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
 25.2238 +    if (pos < indentation) indentString += spaceStr(indentation - pos);
 25.2239 +
 25.2240 +    if (indentString != curSpaceString)
 25.2241 +      replaceRange(cm, indentString, {line: n, ch: 0}, {line: n, ch: curSpaceString.length}, "input");
 25.2242 +    line.stateAfter = null;
 25.2243 +  }
 25.2244 +
 25.2245 +  function changeLine(cm, handle, op) {
 25.2246 +    var no = handle, line = handle, doc = cm.view.doc;
 25.2247 +    if (typeof handle == "number") line = getLine(doc, clipLine(doc, handle));
 25.2248 +    else no = lineNo(handle);
 25.2249 +    if (no == null) return null;
 25.2250 +    if (op(line, no)) regChange(cm, no, no + 1);
 25.2251 +    else return null;
 25.2252 +    return line;
 25.2253 +  }
 25.2254 +
 25.2255 +  function findPosH(cm, dir, unit, visually) {
 25.2256 +    var doc = cm.view.doc, end = cm.view.sel.head, line = end.line, ch = end.ch;
 25.2257 +    var lineObj = getLine(doc, line);
 25.2258 +    function findNextLine() {
 25.2259 +      var l = line + dir;
 25.2260 +      if (l < 0 || l == doc.size) return false;
 25.2261 +      line = l;
 25.2262 +      return lineObj = getLine(doc, l);
 25.2263 +    }
 25.2264 +    function moveOnce(boundToLine) {
 25.2265 +      var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
 25.2266 +      if (next == null) {
 25.2267 +        if (!boundToLine && findNextLine()) {
 25.2268 +          if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
 25.2269 +          else ch = dir < 0 ? lineObj.text.length : 0;
 25.2270 +        } else return false;
 25.2271 +      } else ch = next;
 25.2272 +      return true;
 25.2273 +    }
 25.2274 +    if (unit == "char") moveOnce();
 25.2275 +    else if (unit == "column") moveOnce(true);
 25.2276 +    else if (unit == "word") {
 25.2277 +      var sawWord = false;
 25.2278 +      for (;;) {
 25.2279 +        if (dir < 0) if (!moveOnce()) break;
 25.2280 +        if (isWordChar(lineObj.text.charAt(ch))) sawWord = true;
 25.2281 +        else if (sawWord) {if (dir < 0) {dir = 1; moveOnce();} break;}
 25.2282 +        if (dir > 0) if (!moveOnce()) break;
 25.2283 +      }
 25.2284 +    }
 25.2285 +    return skipAtomic(cm, {line: line, ch: ch}, dir, true);
 25.2286 +  }
 25.2287 +
 25.2288 +  function findWordAt(line, pos) {
 25.2289 +    var start = pos.ch, end = pos.ch;
 25.2290 +    if (line) {
 25.2291 +      if (pos.after === false || end == line.length) --start; else ++end;
 25.2292 +      var startChar = line.charAt(start);
 25.2293 +      var check = isWordChar(startChar) ? isWordChar :
 25.2294 +        /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);} :
 25.2295 +      function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
 25.2296 +      while (start > 0 && check(line.charAt(start - 1))) --start;
 25.2297 +      while (end < line.length && check(line.charAt(end))) ++end;
 25.2298 +    }
 25.2299 +    return {from: {line: pos.line, ch: start}, to: {line: pos.line, ch: end}};
 25.2300 +  }
 25.2301 +
 25.2302 +  function selectLine(cm, line) {
 25.2303 +    extendSelection(cm, {line: line, ch: 0}, clipPos(cm.view.doc, {line: line + 1, ch: 0}));
 25.2304 +  }
 25.2305 +
 25.2306 +  // PROTOTYPE
 25.2307 +
 25.2308 +  // The publicly visible API. Note that operation(null, f) means
 25.2309 +  // 'wrap f in an operation, performed on its `this` parameter'
 25.2310 +
 25.2311 +  CodeMirror.prototype = {
 25.2312 +    getValue: function(lineSep) {
 25.2313 +      var text = [], doc = this.view.doc;
 25.2314 +      doc.iter(0, doc.size, function(line) { text.push(line.text); });
 25.2315 +      return text.join(lineSep || "\n");
 25.2316 +    },
 25.2317 +
 25.2318 +    setValue: operation(null, function(code) {
 25.2319 +      var doc = this.view.doc, top = {line: 0, ch: 0}, lastLen = getLine(doc, doc.size-1).text.length;
 25.2320 +      updateDocInner(this, top, {line: doc.size - 1, ch: lastLen}, splitLines(code), top, top, "setValue");
 25.2321 +    }),
 25.2322 +
 25.2323 +    getSelection: function(lineSep) { return this.getRange(this.view.sel.from, this.view.sel.to, lineSep); },
 25.2324 +
 25.2325 +    replaceSelection: operation(null, function(code, collapse, origin) {
 25.2326 +      var sel = this.view.sel;
 25.2327 +      updateDoc(this, sel.from, sel.to, splitLines(code), collapse || "around", origin);
 25.2328 +    }),
 25.2329 +
 25.2330 +    focus: function(){window.focus(); focusInput(this); onFocus(this); fastPoll(this);},
 25.2331 +
 25.2332 +    setOption: function(option, value) {
 25.2333 +      var options = this.options, old = options[option];
 25.2334 +      if (options[option] == value && option != "mode") return;
 25.2335 +      options[option] = value;
 25.2336 +      if (optionHandlers.hasOwnProperty(option))
 25.2337 +        operation(this, optionHandlers[option])(this, value, old);
 25.2338 +    },
 25.2339 +
 25.2340 +    getOption: function(option) {return this.options[option];},
 25.2341 +
 25.2342 +    getMode: function() {return this.view.mode;},
 25.2343 +
 25.2344 +    addKeyMap: function(map) {
 25.2345 +      this.view.keyMaps.push(map);
 25.2346 +    },
 25.2347 +
 25.2348 +    removeKeyMap: function(map) {
 25.2349 +      var maps = this.view.keyMaps;
 25.2350 +      for (var i = 0; i < maps.length; ++i)
 25.2351 +        if ((typeof map == "string" ? maps[i].name : maps[i]) == map) {
 25.2352 +          maps.splice(i, 1);
 25.2353 +          return true;
 25.2354 +        }
 25.2355 +    },
 25.2356 +
 25.2357 +    undo: operation(null, function() {unredoHelper(this, "undo");}),
 25.2358 +    redo: operation(null, function() {unredoHelper(this, "redo");}),
 25.2359 +
 25.2360 +    indentLine: operation(null, function(n, dir, aggressive) {
 25.2361 +      if (typeof dir != "string") {
 25.2362 +        if (dir == null) dir = this.options.smartIndent ? "smart" : "prev";
 25.2363 +        else dir = dir ? "add" : "subtract";
 25.2364 +      }
 25.2365 +      if (isLine(this.view.doc, n)) indentLine(this, n, dir, aggressive);
 25.2366 +    }),
 25.2367 +
 25.2368 +    indentSelection: operation(null, function(how) {
 25.2369 +      var sel = this.view.sel;
 25.2370 +      if (posEq(sel.from, sel.to)) return indentLine(this, sel.from.line, how);
 25.2371 +      var e = sel.to.line - (sel.to.ch ? 0 : 1);
 25.2372 +      for (var i = sel.from.line; i <= e; ++i) indentLine(this, i, how);
 25.2373 +    }),
 25.2374 +
 25.2375 +    historySize: function() {
 25.2376 +      var hist = this.view.history;
 25.2377 +      return {undo: hist.done.length, redo: hist.undone.length};
 25.2378 +    },
 25.2379 +
 25.2380 +    clearHistory: function() {this.view.history = makeHistory();},
 25.2381 +
 25.2382 +    markClean: function() {
 25.2383 +      this.view.history.dirtyCounter = 0;
 25.2384 +      this.view.history.lastOp = this.view.history.lastOrigin = null;
 25.2385 +    },
 25.2386 +
 25.2387 +    isClean: function () {return this.view.history.dirtyCounter == 0;},
 25.2388 +      
 25.2389 +    getHistory: function() {
 25.2390 +      var hist = this.view.history;
 25.2391 +      function cp(arr) {
 25.2392 +        for (var i = 0, nw = [], nwelt; i < arr.length; ++i) {
 25.2393 +          var set = arr[i];
 25.2394 +          nw.push({events: nwelt = [], fromBefore: set.fromBefore, toBefore: set.toBefore,
 25.2395 +                   fromAfter: set.fromAfter, toAfter: set.toAfter});
 25.2396 +          for (var j = 0, elt = set.events; j < elt.length; ++j) {
 25.2397 +            var old = [], cur = elt[j];
 25.2398 +            nwelt.push({start: cur.start, added: cur.added, old: old});
 25.2399 +            for (var k = 0; k < cur.old.length; ++k) old.push(hlText(cur.old[k]));
 25.2400 +          }
 25.2401 +        }
 25.2402 +        return nw;
 25.2403 +      }
 25.2404 +      return {done: cp(hist.done), undone: cp(hist.undone)};
 25.2405 +    },
 25.2406 +
 25.2407 +    setHistory: function(histData) {
 25.2408 +      var hist = this.view.history = makeHistory();
 25.2409 +      hist.done = histData.done;
 25.2410 +      hist.undone = histData.undone;
 25.2411 +    },
 25.2412 +
 25.2413 +    // Fetch the parser token for a given character. Useful for hacks
 25.2414 +    // that want to inspect the mode state (say, for completion).
 25.2415 +    getTokenAt: function(pos) {
 25.2416 +      var doc = this.view.doc;
 25.2417 +      pos = clipPos(doc, pos);
 25.2418 +      var state = getStateBefore(this, pos.line), mode = this.view.mode;
 25.2419 +      var line = getLine(doc, pos.line);
 25.2420 +      var stream = new StringStream(line.text, this.options.tabSize);
 25.2421 +      while (stream.pos < pos.ch && !stream.eol()) {
 25.2422 +        stream.start = stream.pos;
 25.2423 +        var style = mode.token(stream, state);
 25.2424 +      }
 25.2425 +      return {start: stream.start,
 25.2426 +              end: stream.pos,
 25.2427 +              string: stream.current(),
 25.2428 +              className: style || null, // Deprecated, use 'type' instead
 25.2429 +              type: style || null,
 25.2430 +              state: state};
 25.2431 +    },
 25.2432 +
 25.2433 +    getStateAfter: function(line) {
 25.2434 +      var doc = this.view.doc;
 25.2435 +      line = clipLine(doc, line == null ? doc.size - 1: line);
 25.2436 +      return getStateBefore(this, line + 1);
 25.2437 +    },
 25.2438 +
 25.2439 +    cursorCoords: function(start, mode) {
 25.2440 +      var pos, sel = this.view.sel;
 25.2441 +      if (start == null) pos = sel.head;
 25.2442 +      else if (typeof start == "object") pos = clipPos(this.view.doc, start);
 25.2443 +      else pos = start ? sel.from : sel.to;
 25.2444 +      return cursorCoords(this, pos, mode || "page");
 25.2445 +    },
 25.2446 +
 25.2447 +    charCoords: function(pos, mode) {
 25.2448 +      return charCoords(this, clipPos(this.view.doc, pos), mode || "page");
 25.2449 +    },
 25.2450 +
 25.2451 +    coordsChar: function(coords) {
 25.2452 +      var off = this.display.lineSpace.getBoundingClientRect();
 25.2453 +      return coordsChar(this, coords.left - off.left, coords.top - off.top);
 25.2454 +    },
 25.2455 +
 25.2456 +    defaultTextHeight: function() { return textHeight(this.display); },
 25.2457 +
 25.2458 +    markText: operation(null, function(from, to, options) {
 25.2459 +      return markText(this, clipPos(this.view.doc, from), clipPos(this.view.doc, to),
 25.2460 +                      options, "range");
 25.2461 +    }),
 25.2462 +
 25.2463 +    setBookmark: operation(null, function(pos, widget) {
 25.2464 +      pos = clipPos(this.view.doc, pos);
 25.2465 +      return markText(this, pos, pos, widget ? {replacedWith: widget} : {}, "bookmark");
 25.2466 +    }),
 25.2467 +
 25.2468 +    findMarksAt: function(pos) {
 25.2469 +      var doc = this.view.doc;
 25.2470 +      pos = clipPos(doc, pos);
 25.2471 +      var markers = [], spans = getLine(doc, pos.line).markedSpans;
 25.2472 +      if (spans) for (var i = 0; i < spans.length; ++i) {
 25.2473 +        var span = spans[i];
 25.2474 +        if ((span.from == null || span.from <= pos.ch) &&
 25.2475 +            (span.to == null || span.to >= pos.ch))
 25.2476 +          markers.push(span.marker);
 25.2477 +      }
 25.2478 +      return markers;
 25.2479 +    },
 25.2480 +
 25.2481 +    setGutterMarker: operation(null, function(line, gutterID, value) {
 25.2482 +      return changeLine(this, line, function(line) {
 25.2483 +        var markers = line.gutterMarkers || (line.gutterMarkers = {});
 25.2484 +        markers[gutterID] = value;
 25.2485 +        if (!value && isEmpty(markers)) line.gutterMarkers = null;
 25.2486 +        return true;
 25.2487 +      });
 25.2488 +    }),
 25.2489 +
 25.2490 +    clearGutter: operation(null, function(gutterID) {
 25.2491 +      var i = 0, cm = this, doc = cm.view.doc;
 25.2492 +      doc.iter(0, doc.size, function(line) {
 25.2493 +        if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
 25.2494 +          line.gutterMarkers[gutterID] = null;
 25.2495 +          regChange(cm, i, i + 1);
 25.2496 +          if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null;
 25.2497 +        }
 25.2498 +        ++i;
 25.2499 +      });
 25.2500 +    }),
 25.2501 +
 25.2502 +    addLineClass: operation(null, function(handle, where, cls) {
 25.2503 +      return changeLine(this, handle, function(line) {
 25.2504 +        var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : "wrapClass";
 25.2505 +        if (!line[prop]) line[prop] = cls;
 25.2506 +        else if (new RegExp("\\b" + cls + "\\b").test(line[prop])) return false;
 25.2507 +        else line[prop] += " " + cls;
 25.2508 +        return true;
 25.2509 +      });
 25.2510 +    }),
 25.2511 +
 25.2512 +    removeLineClass: operation(null, function(handle, where, cls) {
 25.2513 +      return changeLine(this, handle, function(line) {
 25.2514 +        var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : "wrapClass";
 25.2515 +        var cur = line[prop];
 25.2516 +        if (!cur) return false;
 25.2517 +        else if (cls == null) line[prop] = null;
 25.2518 +        else {
 25.2519 +          var upd = cur.replace(new RegExp("^" + cls + "\\b\\s*|\\s*\\b" + cls + "\\b"), "");
 25.2520 +          if (upd == cur) return false;
 25.2521 +          line[prop] = upd || null;
 25.2522 +        }
 25.2523 +        return true;
 25.2524 +      });
 25.2525 +    }),
 25.2526 +
 25.2527 +    addLineWidget: operation(null, function(handle, node, options) {
 25.2528 +      var widget = options || {};
 25.2529 +      widget.node = node;
 25.2530 +      if (widget.noHScroll) this.display.alignWidgets = true;
 25.2531 +      changeLine(this, handle, function(line) {
 25.2532 +        (line.widgets || (line.widgets = [])).push(widget);
 25.2533 +        widget.line = line;
 25.2534 +        return true;
 25.2535 +      });
 25.2536 +      return widget;
 25.2537 +    }),
 25.2538 +
 25.2539 +    removeLineWidget: operation(null, function(widget) {
 25.2540 +      var ws = widget.line.widgets, no = lineNo(widget.line);
 25.2541 +      if (no == null) return;
 25.2542 +      for (var i = 0; i < ws.length; ++i) if (ws[i] == widget) ws.splice(i--, 1);
 25.2543 +      regChange(this, no, no + 1);
 25.2544 +    }),
 25.2545 +
 25.2546 +    lineInfo: function(line) {
 25.2547 +      if (typeof line == "number") {
 25.2548 +        if (!isLine(this.view.doc, line)) return null;
 25.2549 +        var n = line;
 25.2550 +        line = getLine(this.view.doc, line);
 25.2551 +        if (!line) return null;
 25.2552 +      } else {
 25.2553 +        var n = lineNo(line);
 25.2554 +        if (n == null) return null;
 25.2555 +      }
 25.2556 +      return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
 25.2557 +              textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
 25.2558 +              widgets: line.widgets};
 25.2559 +    },
 25.2560 +
 25.2561 +    getViewport: function() { return {from: this.display.showingFrom, to: this.display.showingTo};},
 25.2562 +
 25.2563 +    addWidget: function(pos, node, scroll, vert, horiz) {
 25.2564 +      var display = this.display;
 25.2565 +      pos = cursorCoords(this, clipPos(this.view.doc, pos));
 25.2566 +      var top = pos.top, left = pos.left;
 25.2567 +      node.style.position = "absolute";
 25.2568 +      display.sizer.appendChild(node);
 25.2569 +      if (vert == "over") top = pos.top;
 25.2570 +      else if (vert == "near") {
 25.2571 +        var vspace = Math.max(display.wrapper.clientHeight, this.view.doc.height),
 25.2572 +        hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
 25.2573 +        if (pos.bottom + node.offsetHeight > vspace && pos.top > node.offsetHeight)
 25.2574 +          top = pos.top - node.offsetHeight;
 25.2575 +        if (left + node.offsetWidth > hspace)
 25.2576 +          left = hspace - node.offsetWidth;
 25.2577 +      }
 25.2578 +      node.style.top = (top + paddingTop(display)) + "px";
 25.2579 +      node.style.left = node.style.right = "";
 25.2580 +      if (horiz == "right") {
 25.2581 +        left = display.sizer.clientWidth - node.offsetWidth;
 25.2582 +        node.style.right = "0px";
 25.2583 +      } else {
 25.2584 +        if (horiz == "left") left = 0;
 25.2585 +        else if (horiz == "middle") left = (display.sizer.clientWidth - node.offsetWidth) / 2;
 25.2586 +        node.style.left = left + "px";
 25.2587 +      }
 25.2588 +      if (scroll)
 25.2589 +        scrollIntoView(this, left, top, left + node.offsetWidth, top + node.offsetHeight);
 25.2590 +    },
 25.2591 +
 25.2592 +    lineCount: function() {return this.view.doc.size;},
 25.2593 +
 25.2594 +    clipPos: function(pos) {return clipPos(this.view.doc, pos);},
 25.2595 +
 25.2596 +    getCursor: function(start) {
 25.2597 +      var sel = this.view.sel, pos;
 25.2598 +      if (start == null || start == "head") pos = sel.head;
 25.2599 +      else if (start == "anchor") pos = sel.anchor;
 25.2600 +      else if (start == "end" || start === false) pos = sel.to;
 25.2601 +      else pos = sel.from;
 25.2602 +      return copyPos(pos);
 25.2603 +    },
 25.2604 +
 25.2605 +    somethingSelected: function() {return !posEq(this.view.sel.from, this.view.sel.to);},
 25.2606 +
 25.2607 +    setCursor: operation(null, function(line, ch, extend) {
 25.2608 +      var pos = clipPos(this.view.doc, typeof line == "number" ? {line: line, ch: ch || 0} : line);
 25.2609 +      if (extend) extendSelection(this, pos);
 25.2610 +      else setSelection(this, pos, pos);
 25.2611 +    }),
 25.2612 +
 25.2613 +    setSelection: operation(null, function(anchor, head) {
 25.2614 +      var doc = this.view.doc;
 25.2615 +      setSelection(this, clipPos(doc, anchor), clipPos(doc, head || anchor));
 25.2616 +    }),
 25.2617 +
 25.2618 +    extendSelection: operation(null, function(from, to) {
 25.2619 +      var doc = this.view.doc;
 25.2620 +      extendSelection(this, clipPos(doc, from), to && clipPos(doc, to));
 25.2621 +    }),
 25.2622 +
 25.2623 +    setExtending: function(val) {this.view.sel.extend = val;},
 25.2624 +
 25.2625 +    getLine: function(line) {var l = this.getLineHandle(line); return l && l.text;},
 25.2626 +
 25.2627 +    getLineHandle: function(line) {
 25.2628 +      var doc = this.view.doc;
 25.2629 +      if (isLine(doc, line)) return getLine(doc, line);
 25.2630 +    },
 25.2631 +
 25.2632 +    getLineNumber: function(line) {return lineNo(line);},
 25.2633 +
 25.2634 +    setLine: operation(null, function(line, text) {
 25.2635 +      if (isLine(this.view.doc, line))
 25.2636 +        replaceRange(this, text, {line: line, ch: 0}, {line: line, ch: getLine(this.view.doc, line).text.length});
 25.2637 +    }),
 25.2638 +
 25.2639 +    removeLine: operation(null, function(line) {
 25.2640 +      if (isLine(this.view.doc, line))
 25.2641 +        replaceRange(this, "", {line: line, ch: 0}, clipPos(this.view.doc, {line: line+1, ch: 0}));
 25.2642 +    }),
 25.2643 +
 25.2644 +    replaceRange: operation(null, function(code, from, to) {
 25.2645 +      var doc = this.view.doc;
 25.2646 +      from = clipPos(doc, from);
 25.2647 +      to = to ? clipPos(doc, to) : from;
 25.2648 +      return replaceRange(this, code, from, to);
 25.2649 +    }),
 25.2650 +
 25.2651 +    getRange: function(from, to, lineSep) {
 25.2652 +      var doc = this.view.doc;
 25.2653 +      from = clipPos(doc, from); to = clipPos(doc, to);
 25.2654 +      var l1 = from.line, l2 = to.line;
 25.2655 +      if (l1 == l2) return getLine(doc, l1).text.slice(from.ch, to.ch);
 25.2656 +      var code = [getLine(doc, l1).text.slice(from.ch)];
 25.2657 +      doc.iter(l1 + 1, l2, function(line) { code.push(line.text); });
 25.2658 +      code.push(getLine(doc, l2).text.slice(0, to.ch));
 25.2659 +      return code.join(lineSep || "\n");
 25.2660 +    },
 25.2661 +
 25.2662 +    triggerOnKeyDown: operation(null, onKeyDown),
 25.2663 +
 25.2664 +    execCommand: function(cmd) {return commands[cmd](this);},
 25.2665 +
 25.2666 +    // Stuff used by commands, probably not much use to outside code.
 25.2667 +    moveH: operation(null, function(dir, unit) {
 25.2668 +      var sel = this.view.sel, pos = dir < 0 ? sel.from : sel.to;
 25.2669 +      if (sel.shift || sel.extend || posEq(sel.from, sel.to)) pos = findPosH(this, dir, unit, true);
 25.2670 +      extendSelection(this, pos, pos, dir);
 25.2671 +    }),
 25.2672 +
 25.2673 +    deleteH: operation(null, function(dir, unit) {
 25.2674 +      var sel = this.view.sel;
 25.2675 +      if (!posEq(sel.from, sel.to)) replaceRange(this, "", sel.from, sel.to, "delete");
 25.2676 +      else replaceRange(this, "", sel.from, findPosH(this, dir, unit, false), "delete");
 25.2677 +      this.curOp.userSelChange = true;
 25.2678 +    }),
 25.2679 +
 25.2680 +    moveV: operation(null, function(dir, unit) {
 25.2681 +      var view = this.view, doc = view.doc, display = this.display;
 25.2682 +      var cur = view.sel.head, pos = cursorCoords(this, cur, "div");
 25.2683 +      var x = pos.left, y;
 25.2684 +      if (view.goalColumn != null) x = view.goalColumn;
 25.2685 +      if (unit == "page") {
 25.2686 +        var pageSize = Math.min(display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
 25.2687 +        y = pos.top + dir * pageSize;
 25.2688 +      } else if (unit == "line") {
 25.2689 +        y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
 25.2690 +      }
 25.2691 +      do {
 25.2692 +        var target = coordsChar(this, x, y);
 25.2693 +        y += dir * 5;
 25.2694 +      } while (target.outside && (dir < 0 ? y > 0 : y < doc.height));
 25.2695 +
 25.2696 +      if (unit == "page") display.scrollbarV.scrollTop += charCoords(this, target, "div").top - pos.top;
 25.2697 +      extendSelection(this, target, target, dir);
 25.2698 +      view.goalColumn = x;
 25.2699 +    }),
 25.2700 +
 25.2701 +    toggleOverwrite: function() {
 25.2702 +      if (this.view.overwrite = !this.view.overwrite)
 25.2703 +        this.display.cursor.className += " CodeMirror-overwrite";
 25.2704 +      else
 25.2705 +        this.display.cursor.className = this.display.cursor.className.replace(" CodeMirror-overwrite", "");
 25.2706 +    },
 25.2707 +
 25.2708 +    posFromIndex: function(off) {
 25.2709 +      var lineNo = 0, ch, doc = this.view.doc;
 25.2710 +      doc.iter(0, doc.size, function(line) {
 25.2711 +        var sz = line.text.length + 1;
 25.2712 +        if (sz > off) { ch = off; return true; }
 25.2713 +        off -= sz;
 25.2714 +        ++lineNo;
 25.2715 +      });
 25.2716 +      return clipPos(doc, {line: lineNo, ch: ch});
 25.2717 +    },
 25.2718 +    indexFromPos: function (coords) {
 25.2719 +      if (coords.line < 0 || coords.ch < 0) return 0;
 25.2720 +      var index = coords.ch;
 25.2721 +      this.view.doc.iter(0, coords.line, function (line) {
 25.2722 +        index += line.text.length + 1;
 25.2723 +      });
 25.2724 +      return index;
 25.2725 +    },
 25.2726 +
 25.2727 +    scrollTo: function(x, y) {
 25.2728 +      if (x != null) this.display.scrollbarH.scrollLeft = this.display.scroller.scrollLeft = x;
 25.2729 +      if (y != null) this.display.scrollbarV.scrollTop = this.display.scroller.scrollTop = y;
 25.2730 +      updateDisplay(this, []);
 25.2731 +    },
 25.2732 +    getScrollInfo: function() {
 25.2733 +      var scroller = this.display.scroller, co = scrollerCutOff;
 25.2734 +      return {left: scroller.scrollLeft, top: scroller.scrollTop,
 25.2735 +              height: scroller.scrollHeight - co, width: scroller.scrollWidth - co,
 25.2736 +              clientHeight: scroller.clientHeight - co, clientWidth: scroller.clientWidth - co};
 25.2737 +    },
 25.2738 +
 25.2739 +    scrollIntoView: function(pos) {
 25.2740 +      if (typeof pos == "number") pos = {line: pos, ch: 0};
 25.2741 +      pos = pos ? clipPos(this.view.doc, pos) : this.view.sel.head;
 25.2742 +      scrollPosIntoView(this, pos);
 25.2743 +    },
 25.2744 +
 25.2745 +    setSize: function(width, height) {
 25.2746 +      function interpret(val) {
 25.2747 +        return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val;
 25.2748 +      }
 25.2749 +      if (width != null) this.display.wrapper.style.width = interpret(width);
 25.2750 +      if (height != null) this.display.wrapper.style.height = interpret(height);
 25.2751 +      this.refresh();
 25.2752 +    },
 25.2753 +
 25.2754 +    on: function(type, f) {on(this, type, f);},
 25.2755 +    off: function(type, f) {off(this, type, f);},
 25.2756 +
 25.2757 +    operation: function(f){return operation(this, f)();},
 25.2758 +
 25.2759 +    refresh: function() {
 25.2760 +      clearCaches(this);
 25.2761 +      if (this.display.scroller.scrollHeight > this.view.scrollTop)
 25.2762 +        this.display.scrollbarV.scrollTop = this.display.scroller.scrollTop = this.view.scrollTop;
 25.2763 +      updateDisplay(this, true);
 25.2764 +    },
 25.2765 +
 25.2766 +    getInputField: function(){return this.display.input;},
 25.2767 +    getWrapperElement: function(){return this.display.wrapper;},
 25.2768 +    getScrollerElement: function(){return this.display.scroller;},
 25.2769 +    getGutterElement: function(){return this.display.gutters;}
 25.2770 +  };
 25.2771 +
 25.2772 +  // OPTION DEFAULTS
 25.2773 +
 25.2774 +  var optionHandlers = CodeMirror.optionHandlers = {};
 25.2775 +
 25.2776 +  // The default configuration options.
 25.2777 +  var defaults = CodeMirror.defaults = {};
 25.2778 +
 25.2779 +  function option(name, deflt, handle, notOnInit) {
 25.2780 +    CodeMirror.defaults[name] = deflt;
 25.2781 +    if (handle) optionHandlers[name] =
 25.2782 +      notOnInit ? function(cm, val, old) {if (old != Init) handle(cm, val, old);} : handle;
 25.2783 +  }
 25.2784 +
 25.2785 +  var Init = CodeMirror.Init = {toString: function(){return "CodeMirror.Init";}};
 25.2786 +
 25.2787 +  // These two are, on init, called from the constructor because they
 25.2788 +  // have to be initialized before the editor can start at all.
 25.2789 +  option("value", "", function(cm, val) {cm.setValue(val);}, true);
 25.2790 +  option("mode", null, loadMode, true);
 25.2791 +
 25.2792 +  option("indentUnit", 2, loadMode, true);
 25.2793 +  option("indentWithTabs", false);
 25.2794 +  option("smartIndent", true);
 25.2795 +  option("tabSize", 4, function(cm) {
 25.2796 +    loadMode(cm);
 25.2797 +    clearCaches(cm);
 25.2798 +    updateDisplay(cm, true);
 25.2799 +  }, true);
 25.2800 +  option("electricChars", true);
 25.2801 +
 25.2802 +  option("theme", "default", function(cm) {
 25.2803 +    themeChanged(cm);
 25.2804 +    guttersChanged(cm);
 25.2805 +  }, true);
 25.2806 +  option("keyMap", "default", keyMapChanged);
 25.2807 +  option("extraKeys", null);
 25.2808 +
 25.2809 +  option("onKeyEvent", null);
 25.2810 +  option("onDragEvent", null);
 25.2811 +
 25.2812 +  option("lineWrapping", false, wrappingChanged, true);
 25.2813 +  option("gutters", [], function(cm) {
 25.2814 +    setGuttersForLineNumbers(cm.options);
 25.2815 +    guttersChanged(cm);
 25.2816 +  }, true);
 25.2817 +  option("lineNumbers", false, function(cm) {
 25.2818 +    setGuttersForLineNumbers(cm.options);
 25.2819 +    guttersChanged(cm);
 25.2820 +  }, true);
 25.2821 +  option("firstLineNumber", 1, guttersChanged, true);
 25.2822 +  option("lineNumberFormatter", function(integer) {return integer;}, guttersChanged, true);
 25.2823 +  option("showCursorWhenSelecting", false, updateSelection, true);
 25.2824 +  
 25.2825 +  option("readOnly", false, function(cm, val) {
 25.2826 +    if (val == "nocursor") {onBlur(cm); cm.display.input.blur();}
 25.2827 +    else if (!val) resetInput(cm, true);
 25.2828 +  });
 25.2829 +  option("dragDrop", true);
 25.2830 +
 25.2831 +  option("cursorBlinkRate", 530);
 25.2832 +  option("cursorHeight", 1);
 25.2833 +  option("workTime", 100);
 25.2834 +  option("workDelay", 100);
 25.2835 +  option("flattenSpans", true);
 25.2836 +  option("pollInterval", 100);
 25.2837 +  option("undoDepth", 40);
 25.2838 +  option("viewportMargin", 10, function(cm){cm.refresh();}, true);
 25.2839 +
 25.2840 +  option("tabindex", null, function(cm, val) {
 25.2841 +    cm.display.input.tabIndex = val || "";
 25.2842 +  });
 25.2843 +  option("autofocus", null);
 25.2844 +
 25.2845 +  // MODE DEFINITION AND QUERYING
 25.2846 +
 25.2847 +  // Known modes, by name and by MIME
 25.2848 +  var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
 25.2849 +
 25.2850 +  CodeMirror.defineMode = function(name, mode) {
 25.2851 +    if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
 25.2852 +    if (arguments.length > 2) {
 25.2853 +      mode.dependencies = [];
 25.2854 +      for (var i = 2; i < arguments.length; ++i) mode.dependencies.push(arguments[i]);
 25.2855 +    }
 25.2856 +    modes[name] = mode;
 25.2857 +  };
 25.2858 +
 25.2859 +  CodeMirror.defineMIME = function(mime, spec) {
 25.2860 +    mimeModes[mime] = spec;
 25.2861 +  };
 25.2862 +
 25.2863 +  CodeMirror.resolveMode = function(spec) {
 25.2864 +    if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
 25.2865 +      spec = mimeModes[spec];
 25.2866 +    else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec))
 25.2867 +      return CodeMirror.resolveMode("application/xml");
 25.2868 +    if (typeof spec == "string") return {name: spec};
 25.2869 +    else return spec || {name: "null"};
 25.2870 +  };
 25.2871 +
 25.2872 +  CodeMirror.getMode = function(options, spec) {
 25.2873 +    var spec = CodeMirror.resolveMode(spec);
 25.2874 +    var mfactory = modes[spec.name];
 25.2875 +    if (!mfactory) return CodeMirror.getMode(options, "text/plain");
 25.2876 +    var modeObj = mfactory(options, spec);
 25.2877 +    if (modeExtensions.hasOwnProperty(spec.name)) {
 25.2878 +      var exts = modeExtensions[spec.name];
 25.2879 +      for (var prop in exts) {
 25.2880 +        if (!exts.hasOwnProperty(prop)) continue;
 25.2881 +        if (modeObj.hasOwnProperty(prop)) modeObj["_" + prop] = modeObj[prop];
 25.2882 +        modeObj[prop] = exts[prop];
 25.2883 +      }
 25.2884 +    }
 25.2885 +    modeObj.name = spec.name;
 25.2886 +    return modeObj;
 25.2887 +  };
 25.2888 +
 25.2889 +  CodeMirror.defineMode("null", function() {
 25.2890 +    return {token: function(stream) {stream.skipToEnd();}};
 25.2891 +  });
 25.2892 +  CodeMirror.defineMIME("text/plain", "null");
 25.2893 +
 25.2894 +  var modeExtensions = CodeMirror.modeExtensions = {};
 25.2895 +  CodeMirror.extendMode = function(mode, properties) {
 25.2896 +    var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
 25.2897 +    for (var prop in properties) if (properties.hasOwnProperty(prop))
 25.2898 +      exts[prop] = properties[prop];
 25.2899 +  };
 25.2900 +
 25.2901 +  // EXTENSIONS
 25.2902 +
 25.2903 +  CodeMirror.defineExtension = function(name, func) {
 25.2904 +    CodeMirror.prototype[name] = func;
 25.2905 +  };
 25.2906 +
 25.2907 +  CodeMirror.defineOption = option;
 25.2908 +
 25.2909 +  var initHooks = [];
 25.2910 +  CodeMirror.defineInitHook = function(f) {initHooks.push(f);};
 25.2911 +
 25.2912 +  // MODE STATE HANDLING
 25.2913 +
 25.2914 +  // Utility functions for working with state. Exported because modes
 25.2915 +  // sometimes need to do this.
 25.2916 +  function copyState(mode, state) {
 25.2917 +    if (state === true) return state;
 25.2918 +    if (mode.copyState) return mode.copyState(state);
 25.2919 +    var nstate = {};
 25.2920 +    for (var n in state) {
 25.2921 +      var val = state[n];
 25.2922 +      if (val instanceof Array) val = val.concat([]);
 25.2923 +      nstate[n] = val;
 25.2924 +    }
 25.2925 +    return nstate;
 25.2926 +  }
 25.2927 +  CodeMirror.copyState = copyState;
 25.2928 +
 25.2929 +  function startState(mode, a1, a2) {
 25.2930 +    return mode.startState ? mode.startState(a1, a2) : true;
 25.2931 +  }
 25.2932 +  CodeMirror.startState = startState;
 25.2933 +
 25.2934 +  CodeMirror.innerMode = function(mode, state) {
 25.2935 +    while (mode.innerMode) {
 25.2936 +      var info = mode.innerMode(state);
 25.2937 +      state = info.state;
 25.2938 +      mode = info.mode;
 25.2939 +    }
 25.2940 +    return info || {mode: mode, state: state};
 25.2941 +  };
 25.2942 +
 25.2943 +  // STANDARD COMMANDS
 25.2944 +
 25.2945 +  var commands = CodeMirror.commands = {
 25.2946 +    selectAll: function(cm) {cm.setSelection({line: 0, ch: 0}, {line: cm.lineCount() - 1});},
 25.2947 +    killLine: function(cm) {
 25.2948 +      var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
 25.2949 +      if (!sel && cm.getLine(from.line).length == from.ch)
 25.2950 +        cm.replaceRange("", from, {line: from.line + 1, ch: 0}, "delete");
 25.2951 +      else cm.replaceRange("", from, sel ? to : {line: from.line}, "delete");
 25.2952 +    },
 25.2953 +    deleteLine: function(cm) {
 25.2954 +      var l = cm.getCursor().line;
 25.2955 +      cm.replaceRange("", {line: l, ch: 0}, {line: l}, "delete");
 25.2956 +    },
 25.2957 +    undo: function(cm) {cm.undo();},
 25.2958 +    redo: function(cm) {cm.redo();},
 25.2959 +    goDocStart: function(cm) {cm.extendSelection({line: 0, ch: 0});},
 25.2960 +    goDocEnd: function(cm) {cm.extendSelection({line: cm.lineCount() - 1});},
 25.2961 +    goLineStart: function(cm) {
 25.2962 +      cm.extendSelection(lineStart(cm, cm.getCursor().line));
 25.2963 +    },
 25.2964 +    goLineStartSmart: function(cm) {
 25.2965 +      var cur = cm.getCursor(), start = lineStart(cm, cur.line);
 25.2966 +      var line = cm.getLineHandle(start.line);
 25.2967 +      var order = getOrder(line);
 25.2968 +      if (!order || order[0].level == 0) {
 25.2969 +        var firstNonWS = Math.max(0, line.text.search(/\S/));
 25.2970 +        var inWS = cur.line == start.line && cur.ch <= firstNonWS && cur.ch;
 25.2971 +        cm.extendSelection({line: start.line, ch: inWS ? 0 : firstNonWS});
 25.2972 +      } else cm.extendSelection(start);
 25.2973 +    },
 25.2974 +    goLineEnd: function(cm) {
 25.2975 +      cm.extendSelection(lineEnd(cm, cm.getCursor().line));
 25.2976 +    },
 25.2977 +    goLineUp: function(cm) {cm.moveV(-1, "line");},
 25.2978 +    goLineDown: function(cm) {cm.moveV(1, "line");},
 25.2979 +    goPageUp: function(cm) {cm.moveV(-1, "page");},
 25.2980 +    goPageDown: function(cm) {cm.moveV(1, "page");},
 25.2981 +    goCharLeft: function(cm) {cm.moveH(-1, "char");},
 25.2982 +    goCharRight: function(cm) {cm.moveH(1, "char");},
 25.2983 +    goColumnLeft: function(cm) {cm.moveH(-1, "column");},
 25.2984 +    goColumnRight: function(cm) {cm.moveH(1, "column");},
 25.2985 +    goWordLeft: function(cm) {cm.moveH(-1, "word");},
 25.2986 +    goWordRight: function(cm) {cm.moveH(1, "word");},
 25.2987 +    delCharBefore: function(cm) {cm.deleteH(-1, "char");},
 25.2988 +    delCharAfter: function(cm) {cm.deleteH(1, "char");},
 25.2989 +    delWordBefore: function(cm) {cm.deleteH(-1, "word");},
 25.2990 +    delWordAfter: function(cm) {cm.deleteH(1, "word");},
 25.2991 +    indentAuto: function(cm) {cm.indentSelection("smart");},
 25.2992 +    indentMore: function(cm) {cm.indentSelection("add");},
 25.2993 +    indentLess: function(cm) {cm.indentSelection("subtract");},
 25.2994 +    insertTab: function(cm) {cm.replaceSelection("\t", "end", "input");},
 25.2995 +    defaultTab: function(cm) {
 25.2996 +      if (cm.somethingSelected()) cm.indentSelection("add");
 25.2997 +      else cm.replaceSelection("\t", "end", "input");
 25.2998 +    },
 25.2999 +    transposeChars: function(cm) {
 25.3000 +      var cur = cm.getCursor(), line = cm.getLine(cur.line);
 25.3001 +      if (cur.ch > 0 && cur.ch < line.length - 1)
 25.3002 +        cm.replaceRange(line.charAt(cur.ch) + line.charAt(cur.ch - 1),
 25.3003 +                        {line: cur.line, ch: cur.ch - 1}, {line: cur.line, ch: cur.ch + 1});
 25.3004 +    },
 25.3005 +    newlineAndIndent: function(cm) {
 25.3006 +      operation(cm, function() {
 25.3007 +        cm.replaceSelection("\n", "end", "input");
 25.3008 +        cm.indentLine(cm.getCursor().line, null, true);
 25.3009 +      })();
 25.3010 +    },
 25.3011 +    toggleOverwrite: function(cm) {cm.toggleOverwrite();}
 25.3012 +  };
 25.3013 +
 25.3014 +  // STANDARD KEYMAPS
 25.3015 +
 25.3016 +  var keyMap = CodeMirror.keyMap = {};
 25.3017 +  keyMap.basic = {
 25.3018 +    "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
 25.3019 +    "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
 25.3020 +    "Delete": "delCharAfter", "Backspace": "delCharBefore", "Tab": "defaultTab", "Shift-Tab": "indentAuto",
 25.3021 +    "Enter": "newlineAndIndent", "Insert": "toggleOverwrite"
 25.3022 +  };
 25.3023 +  // Note that the save and find-related commands aren't defined by
 25.3024 +  // default. Unknown commands are simply ignored.
 25.3025 +  keyMap.pcDefault = {
 25.3026 +    "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
 25.3027 +    "Ctrl-Home": "goDocStart", "Alt-Up": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Down": "goDocEnd",
 25.3028 +    "Ctrl-Left": "goWordLeft", "Ctrl-Right": "goWordRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
 25.3029 +    "Ctrl-Backspace": "delWordBefore", "Ctrl-Delete": "delWordAfter", "Ctrl-S": "save", "Ctrl-F": "find",
 25.3030 +    "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
 25.3031 +    "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
 25.3032 +    fallthrough: "basic"
 25.3033 +  };
 25.3034 +  keyMap.macDefault = {
 25.3035 +    "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
 25.3036 +    "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goWordLeft",
 25.3037 +    "Alt-Right": "goWordRight", "Cmd-Left": "goLineStart", "Cmd-Right": "goLineEnd", "Alt-Backspace": "delWordBefore",
 25.3038 +    "Ctrl-Alt-Backspace": "delWordAfter", "Alt-Delete": "delWordAfter", "Cmd-S": "save", "Cmd-F": "find",
 25.3039 +    "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
 25.3040 +    "Cmd-[": "indentLess", "Cmd-]": "indentMore",
 25.3041 +    fallthrough: ["basic", "emacsy"]
 25.3042 +  };
 25.3043 +  keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
 25.3044 +  keyMap.emacsy = {
 25.3045 +    "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
 25.3046 +    "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
 25.3047 +    "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
 25.3048 +    "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
 25.3049 +  };
 25.3050 +
 25.3051 +  // KEYMAP DISPATCH
 25.3052 +
 25.3053 +  function getKeyMap(val) {
 25.3054 +    if (typeof val == "string") return keyMap[val];
 25.3055 +    else return val;
 25.3056 +  }
 25.3057 +
 25.3058 +  function lookupKey(name, maps, handle, stop) {
 25.3059 +    function lookup(map) {
 25.3060 +      map = getKeyMap(map);
 25.3061 +      var found = map[name];
 25.3062 +      if (found === false) {
 25.3063 +        if (stop) stop();
 25.3064 +        return true;
 25.3065 +      }
 25.3066 +      if (found != null && handle(found)) return true;
 25.3067 +      if (map.nofallthrough) {
 25.3068 +        if (stop) stop();
 25.3069 +        return true;
 25.3070 +      }
 25.3071 +      var fallthrough = map.fallthrough;
 25.3072 +      if (fallthrough == null) return false;
 25.3073 +      if (Object.prototype.toString.call(fallthrough) != "[object Array]")
 25.3074 +        return lookup(fallthrough);
 25.3075 +      for (var i = 0, e = fallthrough.length; i < e; ++i) {
 25.3076 +        if (lookup(fallthrough[i])) return true;
 25.3077 +      }
 25.3078 +      return false;
 25.3079 +    }
 25.3080 +
 25.3081 +    for (var i = 0; i < maps.length; ++i)
 25.3082 +      if (lookup(maps[i])) return true;
 25.3083 +  }
 25.3084 +  function isModifierKey(event) {
 25.3085 +    var name = keyNames[e_prop(event, "keyCode")];
 25.3086 +    return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
 25.3087 +  }
 25.3088 +  CodeMirror.isModifierKey = isModifierKey;
 25.3089 +
 25.3090 +  // FROMTEXTAREA
 25.3091 +
 25.3092 +  CodeMirror.fromTextArea = function(textarea, options) {
 25.3093 +    if (!options) options = {};
 25.3094 +    options.value = textarea.value;
 25.3095 +    if (!options.tabindex && textarea.tabindex)
 25.3096 +      options.tabindex = textarea.tabindex;
 25.3097 +    // Set autofocus to true if this textarea is focused, or if it has
 25.3098 +    // autofocus and no other element is focused.
 25.3099 +    if (options.autofocus == null) {
 25.3100 +      var hasFocus = document.body;
 25.3101 +      // doc.activeElement occasionally throws on IE
 25.3102 +      try { hasFocus = document.activeElement; } catch(e) {}
 25.3103 +      options.autofocus = hasFocus == textarea ||
 25.3104 +        textarea.getAttribute("autofocus") != null && hasFocus == document.body;
 25.3105 +    }
 25.3106 +
 25.3107 +    function save() {textarea.value = cm.getValue();}
 25.3108 +    if (textarea.form) {
 25.3109 +      // Deplorable hack to make the submit method do the right thing.
 25.3110 +      on(textarea.form, "submit", save);
 25.3111 +      var form = textarea.form, realSubmit = form.submit;
 25.3112 +      try {
 25.3113 +        form.submit = function wrappedSubmit() {
 25.3114 +          save();
 25.3115 +          form.submit = realSubmit;
 25.3116 +          form.submit();
 25.3117 +          form.submit = wrappedSubmit;
 25.3118 +        };
 25.3119 +      } catch(e) {}
 25.3120 +    }
 25.3121 +
 25.3122 +    textarea.style.display = "none";
 25.3123 +    var cm = CodeMirror(function(node) {
 25.3124 +      textarea.parentNode.insertBefore(node, textarea.nextSibling);
 25.3125 +    }, options);
 25.3126 +    cm.save = save;
 25.3127 +    cm.getTextArea = function() { return textarea; };
 25.3128 +    cm.toTextArea = function() {
 25.3129 +      save();
 25.3130 +      textarea.parentNode.removeChild(cm.getWrapperElement());
 25.3131 +      textarea.style.display = "";
 25.3132 +      if (textarea.form) {
 25.3133 +        off(textarea.form, "submit", save);
 25.3134 +        if (typeof textarea.form.submit == "function")
 25.3135 +          textarea.form.submit = realSubmit;
 25.3136 +      }
 25.3137 +    };
 25.3138 +    return cm;
 25.3139 +  };
 25.3140 +
 25.3141 +  // STRING STREAM
 25.3142 +
 25.3143 +  // Fed to the mode parsers, provides helper functions to make
 25.3144 +  // parsers more succinct.
 25.3145 +
 25.3146 +  // The character stream used by a mode's parser.
 25.3147 +  function StringStream(string, tabSize) {
 25.3148 +    this.pos = this.start = 0;
 25.3149 +    this.string = string;
 25.3150 +    this.tabSize = tabSize || 8;
 25.3151 +  }
 25.3152 +
 25.3153 +  StringStream.prototype = {
 25.3154 +    eol: function() {return this.pos >= this.string.length;},
 25.3155 +    sol: function() {return this.pos == 0;},
 25.3156 +    peek: function() {return this.string.charAt(this.pos) || undefined;},
 25.3157 +    next: function() {
 25.3158 +      if (this.pos < this.string.length)
 25.3159 +        return this.string.charAt(this.pos++);
 25.3160 +    },
 25.3161 +    eat: function(match) {
 25.3162 +      var ch = this.string.charAt(this.pos);
 25.3163 +      if (typeof match == "string") var ok = ch == match;
 25.3164 +      else var ok = ch && (match.test ? match.test(ch) : match(ch));
 25.3165 +      if (ok) {++this.pos; return ch;}
 25.3166 +    },
 25.3167 +    eatWhile: function(match) {
 25.3168 +      var start = this.pos;
 25.3169 +      while (this.eat(match)){}
 25.3170 +      return this.pos > start;
 25.3171 +    },
 25.3172 +    eatSpace: function() {
 25.3173 +      var start = this.pos;
 25.3174 +      while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
 25.3175 +      return this.pos > start;
 25.3176 +    },
 25.3177 +    skipToEnd: function() {this.pos = this.string.length;},
 25.3178 +    skipTo: function(ch) {
 25.3179 +      var found = this.string.indexOf(ch, this.pos);
 25.3180 +      if (found > -1) {this.pos = found; return true;}
 25.3181 +    },
 25.3182 +    backUp: function(n) {this.pos -= n;},
 25.3183 +    column: function() {return countColumn(this.string, this.start, this.tabSize);},
 25.3184 +    indentation: function() {return countColumn(this.string, null, this.tabSize);},
 25.3185 +    match: function(pattern, consume, caseInsensitive) {
 25.3186 +      if (typeof pattern == "string") {
 25.3187 +        var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
 25.3188 +        if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
 25.3189 +          if (consume !== false) this.pos += pattern.length;
 25.3190 +          return true;
 25.3191 +        }
 25.3192 +      } else {
 25.3193 +        var match = this.string.slice(this.pos).match(pattern);
 25.3194 +        if (match && match.index > 0) return null;
 25.3195 +        if (match && consume !== false) this.pos += match[0].length;
 25.3196 +        return match;
 25.3197 +      }
 25.3198 +    },
 25.3199 +    current: function(){return this.string.slice(this.start, this.pos);}
 25.3200 +  };
 25.3201 +  CodeMirror.StringStream = StringStream;
 25.3202 +
 25.3203 +  // TEXTMARKERS
 25.3204 +
 25.3205 +  function TextMarker(cm, type) {
 25.3206 +    this.lines = [];
 25.3207 +    this.type = type;
 25.3208 +    this.cm = cm;
 25.3209 +  }
 25.3210 +
 25.3211 +  TextMarker.prototype.clear = function() {
 25.3212 +    if (this.explicitlyCleared) return;
 25.3213 +    startOperation(this.cm);
 25.3214 +    var min = null, max = null;
 25.3215 +    for (var i = 0; i < this.lines.length; ++i) {
 25.3216 +      var line = this.lines[i];
 25.3217 +      var span = getMarkedSpanFor(line.markedSpans, this);
 25.3218 +      if (span.to != null) max = lineNo(line);
 25.3219 +      line.markedSpans = removeMarkedSpan(line.markedSpans, span);
 25.3220 +      if (span.from != null)
 25.3221 +        min = lineNo(line);
 25.3222 +      else if (this.collapsed && !lineIsHidden(line))
 25.3223 +        updateLineHeight(line, textHeight(this.cm.display));
 25.3224 +    }
 25.3225 +    if (min != null) regChange(this.cm, min, max + 1);
 25.3226 +    this.lines.length = 0;
 25.3227 +    this.explicitlyCleared = true;
 25.3228 +    if (this.collapsed && this.cm.view.cantEdit) {
 25.3229 +      this.cm.view.cantEdit = false;
 25.3230 +      reCheckSelection(this.cm);
 25.3231 +    }
 25.3232 +    endOperation(this.cm);
 25.3233 +    signalLater(this.cm, this, "clear");
 25.3234 +  };
 25.3235 +
 25.3236 +  TextMarker.prototype.find = function() {
 25.3237 +    var from, to;
 25.3238 +    for (var i = 0; i < this.lines.length; ++i) {
 25.3239 +      var line = this.lines[i];
 25.3240 +      var span = getMarkedSpanFor(line.markedSpans, this);
 25.3241 +      if (span.from != null || span.to != null) {
 25.3242 +        var found = lineNo(line);
 25.3243 +        if (span.from != null) from = {line: found, ch: span.from};
 25.3244 +        if (span.to != null) to = {line: found, ch: span.to};
 25.3245 +      }
 25.3246 +    }
 25.3247 +    if (this.type == "bookmark") return from;
 25.3248 +    return from && {from: from, to: to};
 25.3249 +  };
 25.3250 +
 25.3251 +  function markText(cm, from, to, options, type) {
 25.3252 +    var doc = cm.view.doc;
 25.3253 +    var marker = new TextMarker(cm, type);
 25.3254 +    if (type == "range" && !posLess(from, to)) return marker;
 25.3255 +    if (options) for (var opt in options) if (options.hasOwnProperty(opt))
 25.3256 +      marker[opt] = options[opt];
 25.3257 +    if (marker.replacedWith) {
 25.3258 +      marker.collapsed = true;
 25.3259 +      marker.replacedWith = elt("span", [marker.replacedWith], "CodeMirror-widget");
 25.3260 +    }
 25.3261 +    if (marker.collapsed) sawCollapsedSpans = true;
 25.3262 +
 25.3263 +    var curLine = from.line, size = 0, collapsedAtStart, collapsedAtEnd;
 25.3264 +    doc.iter(curLine, to.line + 1, function(line) {
 25.3265 +      var span = {from: null, to: null, marker: marker};
 25.3266 +      size += line.text.length;
 25.3267 +      if (curLine == from.line) {span.from = from.ch; size -= from.ch;}
 25.3268 +      if (curLine == to.line) {span.to = to.ch; size -= line.text.length - to.ch;}
 25.3269 +      if (marker.collapsed) {
 25.3270 +        if (curLine == to.line) collapsedAtEnd = collapsedSpanAt(line, to.ch);
 25.3271 +        if (curLine == from.line) collapsedAtStart = collapsedSpanAt(line, from.ch);
 25.3272 +        else updateLineHeight(line, 0);
 25.3273 +      }
 25.3274 +      addMarkedSpan(line, span);
 25.3275 +      if (marker.collapsed && curLine == from.line && lineIsHidden(line))
 25.3276 +        updateLineHeight(line, 0);
 25.3277 +      ++curLine;
 25.3278 +    });
 25.3279 +
 25.3280 +    if (marker.readOnly) {
 25.3281 +      sawReadOnlySpans = true;
 25.3282 +      if (cm.view.history.done.length || cm.view.history.undone.length)
 25.3283 +        cm.clearHistory();
 25.3284 +    }
 25.3285 +    if (marker.collapsed) {
 25.3286 +      if (collapsedAtStart != collapsedAtEnd)
 25.3287 +        throw new Error("Inserting collapsed marker overlapping an existing one");
 25.3288 +      marker.size = size;
 25.3289 +      marker.atomic = true;
 25.3290 +    }
 25.3291 +    if (marker.className || marker.startStyle || marker.endStyle || marker.collapsed)
 25.3292 +      regChange(cm, from.line, to.line + 1);
 25.3293 +    if (marker.atomic) reCheckSelection(cm);
 25.3294 +    return marker;
 25.3295 +  }
 25.3296 +
 25.3297 +  // TEXTMARKER SPANS
 25.3298 +
 25.3299 +  function getMarkedSpanFor(spans, marker) {
 25.3300 +    if (spans) for (var i = 0; i < spans.length; ++i) {
 25.3301 +      var span = spans[i];
 25.3302 +      if (span.marker == marker) return span;
 25.3303 +    }
 25.3304 +  }
 25.3305 +  function removeMarkedSpan(spans, span) {
 25.3306 +    for (var r, i = 0; i < spans.length; ++i)
 25.3307 +      if (spans[i] != span) (r || (r = [])).push(spans[i]);
 25.3308 +    return r;
 25.3309 +  }
 25.3310 +  function addMarkedSpan(line, span) {
 25.3311 +    line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
 25.3312 +    span.marker.lines.push(line);
 25.3313 +  }
 25.3314 +
 25.3315 +  function markedSpansBefore(old, startCh) {
 25.3316 +    if (old) for (var i = 0, nw; i < old.length; ++i) {
 25.3317 +      var span = old[i], marker = span.marker;
 25.3318 +      var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
 25.3319 +      if (startsBefore || marker.type == "bookmark" && span.from == startCh) {
 25.3320 +        var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);
 25.3321 +        (nw || (nw = [])).push({from: span.from,
 25.3322 +                                to: endsAfter ? null : span.to,
 25.3323 +                                marker: marker});
 25.3324 +      }
 25.3325 +    }
 25.3326 +    return nw;
 25.3327 +  }
 25.3328 +
 25.3329 +  function markedSpansAfter(old, startCh, endCh) {
 25.3330 +    if (old) for (var i = 0, nw; i < old.length; ++i) {
 25.3331 +      var span = old[i], marker = span.marker;
 25.3332 +      var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
 25.3333 +      if (endsAfter || marker.type == "bookmark" && span.from == endCh && span.from != startCh) {
 25.3334 +        var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);
 25.3335 +        (nw || (nw = [])).push({from: startsBefore ? null : span.from - endCh,
 25.3336 +                                to: span.to == null ? null : span.to - endCh,
 25.3337 +                                marker: marker});
 25.3338 +      }
 25.3339 +    }
 25.3340 +    return nw;
 25.3341 +  }
 25.3342 +
 25.3343 +  function updateMarkedSpans(oldFirst, oldLast, startCh, endCh, newText) {
 25.3344 +    if (!oldFirst && !oldLast) return newText;
 25.3345 +    // Get the spans that 'stick out' on both sides
 25.3346 +    var first = markedSpansBefore(oldFirst, startCh);
 25.3347 +    var last = markedSpansAfter(oldLast, startCh, endCh);
 25.3348 +
 25.3349 +    // Next, merge those two ends
 25.3350 +    var sameLine = newText.length == 1, offset = lst(newText).length + (sameLine ? startCh : 0);
 25.3351 +    if (first) {
 25.3352 +      // Fix up .to properties of first
 25.3353 +      for (var i = 0; i < first.length; ++i) {
 25.3354 +        var span = first[i];
 25.3355 +        if (span.to == null) {
 25.3356 +          var found = getMarkedSpanFor(last, span.marker);
 25.3357 +          if (!found) span.to = startCh;
 25.3358 +          else if (sameLine) span.to = found.to == null ? null : found.to + offset;
 25.3359 +        }
 25.3360 +      }
 25.3361 +    }
 25.3362 +    if (last) {
 25.3363 +      // Fix up .from in last (or move them into first in case of sameLine)
 25.3364 +      for (var i = 0; i < last.length; ++i) {
 25.3365 +        var span = last[i];
 25.3366 +        if (span.to != null) span.to += offset;
 25.3367 +        if (span.from == null) {
 25.3368 +          var found = getMarkedSpanFor(first, span.marker);
 25.3369 +          if (!found) {
 25.3370 +            span.from = offset;
 25.3371 +            if (sameLine) (first || (first = [])).push(span);
 25.3372 +          }
 25.3373 +        } else {
 25.3374 +          span.from += offset;
 25.3375 +          if (sameLine) (first || (first = [])).push(span);
 25.3376 +        }
 25.3377 +      }
 25.3378 +    }
 25.3379 +
 25.3380 +    var newMarkers = [newHL(newText[0], first)];
 25.3381 +    if (!sameLine) {
 25.3382 +      // Fill gap with whole-line-spans
 25.3383 +      var gap = newText.length - 2, gapMarkers;
 25.3384 +      if (gap > 0 && first)
 25.3385 +        for (var i = 0; i < first.length; ++i)
 25.3386 +          if (first[i].to == null)
 25.3387 +            (gapMarkers || (gapMarkers = [])).push({from: null, to: null, marker: first[i].marker});
 25.3388 +      for (var i = 0; i < gap; ++i)
 25.3389 +        newMarkers.push(newHL(newText[i+1], gapMarkers));
 25.3390 +      newMarkers.push(newHL(lst(newText), last));
 25.3391 +    }
 25.3392 +    return newMarkers;
 25.3393 +  }
 25.3394 +
 25.3395 +  function removeReadOnlyRanges(doc, from, to) {
 25.3396 +    var markers = null;
 25.3397 +    doc.iter(from.line, to.line + 1, function(line) {
 25.3398 +      if (line.markedSpans) for (var i = 0; i < line.markedSpans.length; ++i) {
 25.3399 +        var mark = line.markedSpans[i].marker;
 25.3400 +        if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
 25.3401 +          (markers || (markers = [])).push(mark);
 25.3402 +      }
 25.3403 +    });
 25.3404 +    if (!markers) return null;
 25.3405 +    var parts = [{from: from, to: to}];
 25.3406 +    for (var i = 0; i < markers.length; ++i) {
 25.3407 +      var m = markers[i].find();
 25.3408 +      for (var j = 0; j < parts.length; ++j) {
 25.3409 +        var p = parts[j];
 25.3410 +        if (!posLess(m.from, p.to) || posLess(m.to, p.from)) continue;
 25.3411 +        var newParts = [j, 1];
 25.3412 +        if (posLess(p.from, m.from)) newParts.push({from: p.from, to: m.from});
 25.3413 +        if (posLess(m.to, p.to)) newParts.push({from: m.to, to: p.to});
 25.3414 +        parts.splice.apply(parts, newParts);
 25.3415 +        j += newParts.length - 1;
 25.3416 +      }
 25.3417 +    }
 25.3418 +    return parts;
 25.3419 +  }
 25.3420 +
 25.3421 +  function collapsedSpanAt(line, ch) {
 25.3422 +    var sps = sawCollapsedSpans && line.markedSpans, found;
 25.3423 +    if (sps) for (var sp, i = 0; i < sps.length; ++i) {
 25.3424 +      sp = sps[i];
 25.3425 +      if (!sp.marker.collapsed) continue;
 25.3426 +      if ((sp.from == null || sp.from < ch) &&
 25.3427 +          (sp.to == null || sp.to > ch) &&
 25.3428 +          (!found || found.width < sp.marker.width))
 25.3429 +        found = sp.marker;
 25.3430 +    }
 25.3431 +    return found;
 25.3432 +  }
 25.3433 +  function collapsedSpanAtStart(line) { return collapsedSpanAt(line, -1); }
 25.3434 +  function collapsedSpanAtEnd(line) { return collapsedSpanAt(line, line.text.length + 1); }
 25.3435 +
 25.3436 +  function visualLine(doc, line) {
 25.3437 +    var merged;
 25.3438 +    while (merged = collapsedSpanAtStart(line))
 25.3439 +      line = getLine(doc, merged.find().from.line);
 25.3440 +    return line;
 25.3441 +  }
 25.3442 +
 25.3443 +  function lineIsHidden(line) {
 25.3444 +    var sps = sawCollapsedSpans && line.markedSpans;
 25.3445 +    if (sps) for (var sp, i = 0; i < sps.length; ++i) {
 25.3446 +      sp = sps[i];
 25.3447 +      if (!sp.marker.collapsed) continue;
 25.3448 +      if (sp.from == null) return true;
 25.3449 +      if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(line, sp))
 25.3450 +        return true;
 25.3451 +    }
 25.3452 +  }
 25.3453 +  window.lineIsHidden = lineIsHidden;
 25.3454 +  function lineIsHiddenInner(line, span) {
 25.3455 +    if (span.to == null || span.marker.inclusiveRight && span.to == line.text.length)
 25.3456 +      return true;
 25.3457 +    for (var sp, i = 0; i < line.markedSpans.length; ++i) {
 25.3458 +      sp = line.markedSpans[i];
 25.3459 +      if (sp.marker.collapsed && sp.from == span.to &&
 25.3460 +          (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
 25.3461 +          lineIsHiddenInner(line, sp)) return true;
 25.3462 +    }
 25.3463 +  }
 25.3464 +
 25.3465 +  // hl stands for history-line, a data structure that can be either a
 25.3466 +  // string (line without markers) or a {text, markedSpans} object.
 25.3467 +  function hlText(val) { return typeof val == "string" ? val : val.text; }
 25.3468 +  function hlSpans(val) {
 25.3469 +    if (typeof val == "string") return null;
 25.3470 +    var spans = val.markedSpans, out = null;
 25.3471 +    for (var i = 0; i < spans.length; ++i) {
 25.3472 +      if (spans[i].marker.explicitlyCleared) { if (!out) out = spans.slice(0, i); }
 25.3473 +      else if (out) out.push(spans[i]);
 25.3474 +    }
 25.3475 +    return !out ? spans : out.length ? out : null;
 25.3476 +  }
 25.3477 +  function newHL(text, spans) { return spans ? {text: text, markedSpans: spans} : text; }
 25.3478 +
 25.3479 +  function detachMarkedSpans(line) {
 25.3480 +    var spans = line.markedSpans;
 25.3481 +    if (!spans) return;
 25.3482 +    for (var i = 0; i < spans.length; ++i) {
 25.3483 +      var lines = spans[i].marker.lines;
 25.3484 +      var ix = indexOf(lines, line);
 25.3485 +      lines.splice(ix, 1);
 25.3486 +    }
 25.3487 +    line.markedSpans = null;
 25.3488 +  }
 25.3489 +
 25.3490 +  function attachMarkedSpans(line, spans) {
 25.3491 +    if (!spans) return;
 25.3492 +    for (var i = 0; i < spans.length; ++i)
 25.3493 +      spans[i].marker.lines.push(line);
 25.3494 +    line.markedSpans = spans;
 25.3495 +  }
 25.3496 +
 25.3497 +  // LINE DATA STRUCTURE
 25.3498 +
 25.3499 +  // Line objects. These hold state related to a line, including
 25.3500 +  // highlighting info (the styles array).
 25.3501 +  function makeLine(text, markedSpans, height) {
 25.3502 +    var line = {text: text, height: height};
 25.3503 +    attachMarkedSpans(line, markedSpans);
 25.3504 +    if (lineIsHidden(line)) line.height = 0;
 25.3505 +    return line;
 25.3506 +  }
 25.3507 +
 25.3508 +  function updateLine(cm, line, text, markedSpans) {
 25.3509 +    line.text = text;
 25.3510 +    line.stateAfter = line.styles = null;
 25.3511 +    if (line.order != null) line.order = null;
 25.3512 +    detachMarkedSpans(line);
 25.3513 +    attachMarkedSpans(line, markedSpans);
 25.3514 +    if (lineIsHidden(line)) line.height = 0;
 25.3515 +    else if (!line.height) line.height = textHeight(cm.display);
 25.3516 +    signalLater(cm, line, "change");
 25.3517 +  }
 25.3518 +
 25.3519 +  function cleanUpLine(line) {
 25.3520 +    line.parent = null;
 25.3521 +    detachMarkedSpans(line);
 25.3522 +  }
 25.3523 +
 25.3524 +  // Run the given mode's parser over a line, update the styles
 25.3525 +  // array, which contains alternating fragments of text and CSS
 25.3526 +  // classes.
 25.3527 +  function highlightLine(cm, line, state) {
 25.3528 +    var mode = cm.view.mode, flattenSpans = cm.options.flattenSpans;
 25.3529 +    var changed = !line.styles, pos = 0, curText = "", curStyle = null;
 25.3530 +    var stream = new StringStream(line.text, cm.options.tabSize), st = line.styles || (line.styles = []);
 25.3531 +    if (line.text == "" && mode.blankLine) mode.blankLine(state);
 25.3532 +    while (!stream.eol()) {
 25.3533 +      var style = mode.token(stream, state), substr = stream.current();
 25.3534 +      stream.start = stream.pos;
 25.3535 +      if (!flattenSpans || curStyle != style) {
 25.3536 +        if (curText) {
 25.3537 +          changed = changed || pos >= st.length || curText != st[pos] || curStyle != st[pos+1];
 25.3538 +          st[pos++] = curText; st[pos++] = curStyle;
 25.3539 +        }
 25.3540 +        curText = substr; curStyle = style;
 25.3541 +      } else curText = curText + substr;
 25.3542 +      // Give up when line is ridiculously long
 25.3543 +      if (stream.pos > 5000) break;
 25.3544 +    }
 25.3545 +    if (curText) {
 25.3546 +      changed = changed || pos >= st.length || curText != st[pos] || curStyle != st[pos+1];
 25.3547 +      st[pos++] = curText; st[pos++] = curStyle;
 25.3548 +    }
 25.3549 +    if (stream.pos > 5000) { st[pos++] = line.text.slice(stream.pos); st[pos++] = null; }
 25.3550 +    if (pos != st.length) { st.length = pos; changed = true; }
 25.3551 +    return changed;
 25.3552 +  }
 25.3553 +
 25.3554 +  // Lightweight form of highlight -- proceed over this line and
 25.3555 +  // update state, but don't save a style array.
 25.3556 +  function processLine(cm, line, state) {
 25.3557 +    var mode = cm.view.mode;
 25.3558 +    var stream = new StringStream(line.text, cm.options.tabSize);
 25.3559 +    if (line.text == "" && mode.blankLine) mode.blankLine(state);
 25.3560 +    while (!stream.eol() && stream.pos <= 5000) {
 25.3561 +      mode.token(stream, state);
 25.3562 +      stream.start = stream.pos;
 25.3563 +    }
 25.3564 +  }
 25.3565 +
 25.3566 +  var styleToClassCache = {};
 25.3567 +  function styleToClass(style) {
 25.3568 +    if (!style) return null;
 25.3569 +    return styleToClassCache[style] ||
 25.3570 +      (styleToClassCache[style] = "cm-" + style.replace(/ +/g, " cm-"));
 25.3571 +  }
 25.3572 +
 25.3573 +  function lineContent(cm, realLine, measure) {
 25.3574 +    var merged, line = realLine, lineBefore, sawBefore, simple = true;
 25.3575 +    while (merged = collapsedSpanAtStart(line)) {
 25.3576 +      simple = false;
 25.3577 +      line = getLine(cm.view.doc, merged.find().from.line);
 25.3578 +      if (!lineBefore) lineBefore = line;
 25.3579 +    }
 25.3580 +
 25.3581 +    var builder = {pre: elt("pre"), col: 0, pos: 0, display: !measure,
 25.3582 +                   measure: null, addedOne: false, cm: cm};
 25.3583 +    if (line.textClass) builder.pre.className = line.textClass;
 25.3584 +
 25.3585 +    do {
 25.3586 +      if (!line.styles)
 25.3587 +        highlightLine(cm, line, line.stateAfter = getStateBefore(cm, lineNo(line)));
 25.3588 +      builder.measure = line == realLine && measure;
 25.3589 +      builder.pos = 0;
 25.3590 +      builder.addToken = builder.measure ? buildTokenMeasure : buildToken;
 25.3591 +      if (measure && sawBefore && line != realLine && !builder.addedOne) {
 25.3592 +        measure[0] = builder.pre.appendChild(zeroWidthElement(cm.display.measure));
 25.3593 +        builder.addedOne = true;
 25.3594 +      }
 25.3595 +      var next = insertLineContent(line, builder);
 25.3596 +      sawBefore = line == lineBefore;
 25.3597 +      if (next) {
 25.3598 +        line = getLine(cm.view.doc, next.to.line);
 25.3599 +        simple = false;
 25.3600 +      }
 25.3601 +    } while (next);
 25.3602 +
 25.3603 +    if (measure && !builder.addedOne)
 25.3604 +      measure[0] = builder.pre.appendChild(simple ? elt("span", "\u00a0") : zeroWidthElement(cm.display.measure));
 25.3605 +    if (!builder.pre.firstChild && !lineIsHidden(realLine))
 25.3606 +      builder.pre.appendChild(document.createTextNode("\u00a0"));
 25.3607 +
 25.3608 +    return builder.pre;
 25.3609 +  }
 25.3610 +
 25.3611 +  var tokenSpecialChars = /[\t\u0000-\u0019\u200b\u2028\u2029\uFEFF]/g;
 25.3612 +  function buildToken(builder, text, style, startStyle, endStyle) {
 25.3613 +    if (!text) return;
 25.3614 +    if (!tokenSpecialChars.test(text)) {
 25.3615 +      builder.col += text.length;
 25.3616 +      var content = document.createTextNode(text);
 25.3617 +    } else {
 25.3618 +      var content = document.createDocumentFragment(), pos = 0;
 25.3619 +      while (true) {
 25.3620 +        tokenSpecialChars.lastIndex = pos;
 25.3621 +        var m = tokenSpecialChars.exec(text);
 25.3622 +        var skipped = m ? m.index - pos : text.length - pos;
 25.3623 +        if (skipped) {
 25.3624 +          content.appendChild(document.createTextNode(text.slice(pos, pos + skipped)));
 25.3625 +          builder.col += skipped;
 25.3626 +        }
 25.3627 +        if (!m) break;
 25.3628 +        pos += skipped + 1;
 25.3629 +        if (m[0] == "\t") {
 25.3630 +          var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
 25.3631 +          content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
 25.3632 +          builder.col += tabWidth;
 25.3633 +        } else {
 25.3634 +          var token = elt("span", "\u2022", "cm-invalidchar");
 25.3635 +          token.title = "\\u" + m[0].charCodeAt(0).toString(16);
 25.3636 +          content.appendChild(token);
 25.3637 +          builder.col += 1;
 25.3638 +        }
 25.3639 +      }
 25.3640 +    }
 25.3641 +    if (style || startStyle || endStyle || builder.measure) {
 25.3642 +      var fullStyle = style || "";
 25.3643 +      if (startStyle) fullStyle += startStyle;
 25.3644 +      if (endStyle) fullStyle += endStyle;
 25.3645 +      return builder.pre.appendChild(elt("span", [content], fullStyle));
 25.3646 +    }
 25.3647 +    builder.pre.appendChild(content);
 25.3648 +  }
 25.3649 +
 25.3650 +  function buildTokenMeasure(builder, text, style, startStyle, endStyle) {
 25.3651 +    for (var i = 0; i < text.length; ++i) {
 25.3652 +      if (i && i < text.length - 1 &&
 25.3653 +          builder.cm.options.lineWrapping &&
 25.3654 +          spanAffectsWrapping.test(text.slice(i - 1, i + 1)))
 25.3655 +        builder.pre.appendChild(elt("wbr"));
 25.3656 +      builder.measure[builder.pos++] =
 25.3657 +        buildToken(builder, text.charAt(i), style,
 25.3658 +                   i == 0 && startStyle, i == text.length - 1 && endStyle);
 25.3659 +    }
 25.3660 +    if (text.length) builder.addedOne = true;
 25.3661 +  }
 25.3662 +
 25.3663 +  function buildCollapsedSpan(builder, size, widget) {
 25.3664 +    if (widget) {
 25.3665 +      if (!builder.display) widget = widget.cloneNode(true);
 25.3666 +      builder.pre.appendChild(widget);
 25.3667 +      if (builder.measure && size) {
 25.3668 +        builder.measure[builder.pos] = widget;
 25.3669 +        builder.addedOne = true;
 25.3670 +      }
 25.3671 +    }
 25.3672 +    builder.pos += size;
 25.3673 +  }
 25.3674 +
 25.3675 +  // Outputs a number of spans to make up a line, taking highlighting
 25.3676 +  // and marked text into account.
 25.3677 +  function insertLineContent(line, builder) {
 25.3678 +    var st = line.styles, spans = line.markedSpans;
 25.3679 +    if (!spans) {
 25.3680 +      for (var i = 0; i < st.length; i+=2)
 25.3681 +        builder.addToken(builder, st[i], styleToClass(st[i+1]));
 25.3682 +      return;
 25.3683 +    }
 25.3684 +
 25.3685 +    var allText = line.text, len = allText.length;
 25.3686 +    var pos = 0, i = 0, text = "", style;
 25.3687 +    var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, collapsed;
 25.3688 +    for (;;) {
 25.3689 +      if (nextChange == pos) { // Update current marker set
 25.3690 +        spanStyle = spanEndStyle = spanStartStyle = "";
 25.3691 +        collapsed = null; nextChange = Infinity;
 25.3692 +        var foundBookmark = null;
 25.3693 +        for (var j = 0; j < spans.length; ++j) {
 25.3694 +          var sp = spans[j], m = sp.marker;
 25.3695 +          if (sp.from <= pos && (sp.to == null || sp.to > pos)) {
 25.3696 +            if (sp.to != null && nextChange > sp.to) { nextChange = sp.to; spanEndStyle = ""; }
 25.3697 +            if (m.className) spanStyle += " " + m.className;
 25.3698 +            if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle;
 25.3699 +            if (m.endStyle && sp.to == nextChange) spanEndStyle += " " + m.endStyle;
 25.3700 +            if (m.collapsed && (!collapsed || collapsed.marker.width < m.width))
 25.3701 +              collapsed = sp;
 25.3702 +          } else if (sp.from > pos && nextChange > sp.from) {
 25.3703 +            nextChange = sp.from;
 25.3704 +          }
 25.3705 +          if (m.type == "bookmark" && sp.from == pos && m.replacedWith)
 25.3706 +            foundBookmark = m.replacedWith;
 25.3707 +        }
 25.3708 +        if (collapsed && (collapsed.from || 0) == pos) {
 25.3709 +          buildCollapsedSpan(builder, (collapsed.to == null ? len : collapsed.to) - pos,
 25.3710 +                             collapsed.from != null && collapsed.marker.replacedWith);
 25.3711 +          if (collapsed.to == null) return collapsed.marker.find();
 25.3712 +        }
 25.3713 +        if (foundBookmark && !collapsed) buildCollapsedSpan(builder, 0, foundBookmark);
 25.3714 +      }
 25.3715 +      if (pos >= len) break;
 25.3716 +
 25.3717 +      var upto = Math.min(len, nextChange);
 25.3718 +      while (true) {
 25.3719 +        if (text) {
 25.3720 +          var end = pos + text.length;
 25.3721 +          if (!collapsed) {
 25.3722 +            var tokenText = end > upto ? text.slice(0, upto - pos) : text;
 25.3723 +            builder.addToken(builder, tokenText, style + spanStyle,
 25.3724 +                             spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "");
 25.3725 +          }
 25.3726 +          if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
 25.3727 +          pos = end;
 25.3728 +          spanStartStyle = "";
 25.3729 +        }
 25.3730 +        text = st[i++]; style = styleToClass(st[i++]);
 25.3731 +      }
 25.3732 +    }
 25.3733 +  }
 25.3734 +
 25.3735 +  // DOCUMENT DATA STRUCTURE
 25.3736 +
 25.3737 +  function LeafChunk(lines) {
 25.3738 +    this.lines = lines;
 25.3739 +    this.parent = null;
 25.3740 +    for (var i = 0, e = lines.length, height = 0; i < e; ++i) {
 25.3741 +      lines[i].parent = this;
 25.3742 +      height += lines[i].height;
 25.3743 +    }
 25.3744 +    this.height = height;
 25.3745 +  }
 25.3746 +
 25.3747 +  LeafChunk.prototype = {
 25.3748 +    chunkSize: function() { return this.lines.length; },
 25.3749 +    remove: function(at, n, cm) {
 25.3750 +      for (var i = at, e = at + n; i < e; ++i) {
 25.3751 +        var line = this.lines[i];
 25.3752 +        this.height -= line.height;
 25.3753 +        cleanUpLine(line);
 25.3754 +        signalLater(cm, line, "delete");
 25.3755 +      }
 25.3756 +      this.lines.splice(at, n);
 25.3757 +    },
 25.3758 +    collapse: function(lines) {
 25.3759 +      lines.splice.apply(lines, [lines.length, 0].concat(this.lines));
 25.3760 +    },
 25.3761 +    insertHeight: function(at, lines, height) {
 25.3762 +      this.height += height;
 25.3763 +      this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
 25.3764 +      for (var i = 0, e = lines.length; i < e; ++i) lines[i].parent = this;
 25.3765 +    },
 25.3766 +    iterN: function(at, n, op) {
 25.3767 +      for (var e = at + n; at < e; ++at)
 25.3768 +        if (op(this.lines[at])) return true;
 25.3769 +    }
 25.3770 +  };
 25.3771 +
 25.3772 +  function BranchChunk(children) {
 25.3773 +    this.children = children;
 25.3774 +    var size = 0, height = 0;
 25.3775 +    for (var i = 0, e = children.length; i < e; ++i) {
 25.3776 +      var ch = children[i];
 25.3777 +      size += ch.chunkSize(); height += ch.height;
 25.3778 +      ch.parent = this;
 25.3779 +    }
 25.3780 +    this.size = size;
 25.3781 +    this.height = height;
 25.3782 +    this.parent = null;
 25.3783 +  }
 25.3784 +
 25.3785 +  BranchChunk.prototype = {
 25.3786 +    chunkSize: function() { return this.size; },
 25.3787 +    remove: function(at, n, callbacks) {
 25.3788 +      this.size -= n;
 25.3789 +      for (var i = 0; i < this.children.length; ++i) {
 25.3790 +        var child = this.children[i], sz = child.chunkSize();
 25.3791 +        if (at < sz) {
 25.3792 +          var rm = Math.min(n, sz - at), oldHeight = child.height;
 25.3793 +          child.remove(at, rm, callbacks);
 25.3794 +          this.height -= oldHeight - child.height;
 25.3795 +          if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
 25.3796 +          if ((n -= rm) == 0) break;
 25.3797 +          at = 0;
 25.3798 +        } else at -= sz;
 25.3799 +      }
 25.3800 +      if (this.size - n < 25) {
 25.3801 +        var lines = [];
 25.3802 +        this.collapse(lines);
 25.3803 +        this.children = [new LeafChunk(lines)];
 25.3804 +        this.children[0].parent = this;
 25.3805 +      }
 25.3806 +    },
 25.3807 +    collapse: function(lines) {
 25.3808 +      for (var i = 0, e = this.children.length; i < e; ++i) this.children[i].collapse(lines);
 25.3809 +    },
 25.3810 +    insert: function(at, lines) {
 25.3811 +      var height = 0;
 25.3812 +      for (var i = 0, e = lines.length; i < e; ++i) height += lines[i].height;
 25.3813 +      this.insertHeight(at, lines, height);
 25.3814 +    },
 25.3815 +    insertHeight: function(at, lines, height) {
 25.3816 +      this.size += lines.length;
 25.3817 +      this.height += height;
 25.3818 +      for (var i = 0, e = this.children.length; i < e; ++i) {
 25.3819 +        var child = this.children[i], sz = child.chunkSize();
 25.3820 +        if (at <= sz) {
 25.3821 +          child.insertHeight(at, lines, height);
 25.3822 +          if (child.lines && child.lines.length > 50) {
 25.3823 +            while (child.lines.length > 50) {
 25.3824 +              var spilled = child.lines.splice(child.lines.length - 25, 25);
 25.3825 +              var newleaf = new LeafChunk(spilled);
 25.3826 +              child.height -= newleaf.height;
 25.3827 +              this.children.splice(i + 1, 0, newleaf);
 25.3828 +              newleaf.parent = this;
 25.3829 +            }
 25.3830 +            this.maybeSpill();
 25.3831 +          }
 25.3832 +          break;
 25.3833 +        }
 25.3834 +        at -= sz;
 25.3835 +      }
 25.3836 +    },
 25.3837 +    maybeSpill: function() {
 25.3838 +      if (this.children.length <= 10) return;
 25.3839 +      var me = this;
 25.3840 +      do {
 25.3841 +        var spilled = me.children.splice(me.children.length - 5, 5);
 25.3842 +        var sibling = new BranchChunk(spilled);
 25.3843 +        if (!me.parent) { // Become the parent node
 25.3844 +          var copy = new BranchChunk(me.children);
 25.3845 +          copy.parent = me;
 25.3846 +          me.children = [copy, sibling];
 25.3847 +          me = copy;
 25.3848 +        } else {
 25.3849 +          me.size -= sibling.size;
 25.3850 +          me.height -= sibling.height;
 25.3851 +          var myIndex = indexOf(me.parent.children, me);
 25.3852 +          me.parent.children.splice(myIndex + 1, 0, sibling);
 25.3853 +        }
 25.3854 +        sibling.parent = me.parent;
 25.3855 +      } while (me.children.length > 10);
 25.3856 +      me.parent.maybeSpill();
 25.3857 +    },
 25.3858 +    iter: function(from, to, op) { this.iterN(from, to - from, op); },
 25.3859 +    iterN: function(at, n, op) {
 25.3860 +      for (var i = 0, e = this.children.length; i < e; ++i) {
 25.3861 +        var child = this.children[i], sz = child.chunkSize();
 25.3862 +        if (at < sz) {
 25.3863 +          var used = Math.min(n, sz - at);
 25.3864 +          if (child.iterN(at, used, op)) return true;
 25.3865 +          if ((n -= used) == 0) break;
 25.3866 +          at = 0;
 25.3867 +        } else at -= sz;
 25.3868 +      }
 25.3869 +    }
 25.3870 +  };
 25.3871 +
 25.3872 +  // LINE UTILITIES
 25.3873 +
 25.3874 +  function getLine(chunk, n) {
 25.3875 +    while (!chunk.lines) {
 25.3876 +      for (var i = 0;; ++i) {
 25.3877 +        var child = chunk.children[i], sz = child.chunkSize();
 25.3878 +        if (n < sz) { chunk = child; break; }
 25.3879 +        n -= sz;
 25.3880 +      }
 25.3881 +    }
 25.3882 +    return chunk.lines[n];
 25.3883 +  }
 25.3884 +
 25.3885 +  function updateLineHeight(line, height) {
 25.3886 +    var diff = height - line.height;
 25.3887 +    for (var n = line; n; n = n.parent) n.height += diff;
 25.3888 +  }
 25.3889 +
 25.3890 +  function lineNo(line) {
 25.3891 +    if (line.parent == null) return null;
 25.3892 +    var cur = line.parent, no = indexOf(cur.lines, line);
 25.3893 +    for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
 25.3894 +      for (var i = 0;; ++i) {
 25.3895 +        if (chunk.children[i] == cur) break;
 25.3896 +        no += chunk.children[i].chunkSize();
 25.3897 +      }
 25.3898 +    }
 25.3899 +    return no;
 25.3900 +  }
 25.3901 +
 25.3902 +  function lineAtHeight(chunk, h) {
 25.3903 +    var n = 0;
 25.3904 +    outer: do {
 25.3905 +      for (var i = 0, e = chunk.children.length; i < e; ++i) {
 25.3906 +        var child = chunk.children[i], ch = child.height;
 25.3907 +        if (h < ch) { chunk = child; continue outer; }
 25.3908 +        h -= ch;
 25.3909 +        n += child.chunkSize();
 25.3910 +      }
 25.3911 +      return n;
 25.3912 +    } while (!chunk.lines);
 25.3913 +    for (var i = 0, e = chunk.lines.length; i < e; ++i) {
 25.3914 +      var line = chunk.lines[i], lh = line.height;
 25.3915 +      if (h < lh) break;
 25.3916 +      h -= lh;
 25.3917 +    }
 25.3918 +    return n + i;
 25.3919 +  }
 25.3920 +
 25.3921 +  function heightAtLine(cm, lineObj) {
 25.3922 +    lineObj = visualLine(cm.view.doc, lineObj);
 25.3923 +
 25.3924 +    var h = 0, chunk = lineObj.parent;
 25.3925 +    for (var i = 0; i < chunk.lines.length; ++i) {
 25.3926 +      var line = chunk.lines[i];
 25.3927 +      if (line == lineObj) break;
 25.3928 +      else h += line.height;
 25.3929 +    }
 25.3930 +    for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
 25.3931 +      for (var i = 0; i < p.children.length; ++i) {
 25.3932 +        var cur = p.children[i];
 25.3933 +        if (cur == chunk) break;
 25.3934 +        else h += cur.height;
 25.3935 +      }
 25.3936 +    }
 25.3937 +    return h;
 25.3938 +  }
 25.3939 +
 25.3940 +  function getOrder(line) {
 25.3941 +    var order = line.order;
 25.3942 +    if (order == null) order = line.order = bidiOrdering(line.text);
 25.3943 +    return order;
 25.3944 +  }
 25.3945 +
 25.3946 +  // HISTORY
 25.3947 +
 25.3948 +  function makeHistory() {
 25.3949 +    return {
 25.3950 +      // Arrays of history events. Doing something adds an event to
 25.3951 +      // done and clears undo. Undoing moves events from done to
 25.3952 +      // undone, redoing moves them in the other direction.
 25.3953 +      done: [], undone: [],
 25.3954 +      // Used to track when changes can be merged into a single undo
 25.3955 +      // event
 25.3956 +      lastTime: 0, lastOp: null, lastOrigin: null,
 25.3957 +      // Used by the isClean() method
 25.3958 +      dirtyCounter: 0
 25.3959 +    };
 25.3960 +  }
 25.3961 +
 25.3962 +  function addChange(cm, start, added, old, origin, fromBefore, toBefore, fromAfter, toAfter) {
 25.3963 +    var history = cm.view.history;
 25.3964 +    history.undone.length = 0;
 25.3965 +    var time = +new Date, cur = lst(history.done);
 25.3966 +    
 25.3967 +    if (cur &&
 25.3968 +        (history.lastOp == cm.curOp.id ||
 25.3969 +         history.lastOrigin == origin && (origin == "input" || origin == "delete") &&
 25.3970 +         history.lastTime > time - 600)) {
 25.3971 +      // Merge this change into the last event
 25.3972 +      var last = lst(cur.events);
 25.3973 +      if (last.start > start + old.length || last.start + last.added < start) {
 25.3974 +        // Doesn't intersect with last sub-event, add new sub-event
 25.3975 +        cur.events.push({start: start, added: added, old: old});
 25.3976 +      } else {
 25.3977 +        // Patch up the last sub-event
 25.3978 +        var startBefore = Math.max(0, last.start - start),
 25.3979 +        endAfter = Math.max(0, (start + old.length) - (last.start + last.added));
 25.3980 +        for (var i = startBefore; i > 0; --i) last.old.unshift(old[i - 1]);
 25.3981 +        for (var i = endAfter; i > 0; --i) last.old.push(old[old.length - i]);
 25.3982 +        if (startBefore) last.start = start;
 25.3983 +        last.added += added - (old.length - startBefore - endAfter);
 25.3984 +      }
 25.3985 +      cur.fromAfter = fromAfter; cur.toAfter = toAfter;
 25.3986 +    } else {
 25.3987 +      // Can not be merged, start a new event.
 25.3988 +      cur = {events: [{start: start, added: added, old: old}],
 25.3989 +             fromBefore: fromBefore, toBefore: toBefore, fromAfter: fromAfter, toAfter: toAfter};
 25.3990 +      history.done.push(cur);
 25.3991 +      while (history.done.length > cm.options.undoDepth)
 25.3992 +        history.done.shift();
 25.3993 +      if (history.dirtyCounter < 0)
 25.3994 +          // The user has made a change after undoing past the last clean state. 
 25.3995 +          // We can never get back to a clean state now until markClean() is called.
 25.3996 +          history.dirtyCounter = NaN;
 25.3997 +      else
 25.3998 +        history.dirtyCounter++;
 25.3999 +    }
 25.4000 +    history.lastTime = time;
 25.4001 +    history.lastOp = cm.curOp.id;
 25.4002 +    history.lastOrigin = origin;
 25.4003 +  }
 25.4004 +
 25.4005 +  // EVENT OPERATORS
 25.4006 +
 25.4007 +  function stopMethod() {e_stop(this);}
 25.4008 +  // Ensure an event has a stop method.
 25.4009 +  function addStop(event) {
 25.4010 +    if (!event.stop) event.stop = stopMethod;
 25.4011 +    return event;
 25.4012 +  }
 25.4013 +
 25.4014 +  function e_preventDefault(e) {
 25.4015 +    if (e.preventDefault) e.preventDefault();
 25.4016 +    else e.returnValue = false;
 25.4017 +  }
 25.4018 +  function e_stopPropagation(e) {
 25.4019 +    if (e.stopPropagation) e.stopPropagation();
 25.4020 +    else e.cancelBubble = true;
 25.4021 +  }
 25.4022 +  function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
 25.4023 +  CodeMirror.e_stop = e_stop;
 25.4024 +  CodeMirror.e_preventDefault = e_preventDefault;
 25.4025 +  CodeMirror.e_stopPropagation = e_stopPropagation;
 25.4026 +
 25.4027 +  function e_target(e) {return e.target || e.srcElement;}
 25.4028 +  function e_button(e) {
 25.4029 +    var b = e.which;
 25.4030 +    if (b == null) {
 25.4031 +      if (e.button & 1) b = 1;
 25.4032 +      else if (e.button & 2) b = 3;
 25.4033 +      else if (e.button & 4) b = 2;
 25.4034 +    }
 25.4035 +    if (mac && e.ctrlKey && b == 1) b = 3;
 25.4036 +    return b;
 25.4037 +  }
 25.4038 +
 25.4039 +  // Allow 3rd-party code to override event properties by adding an override
 25.4040 +  // object to an event object.
 25.4041 +  function e_prop(e, prop) {
 25.4042 +    var overridden = e.override && e.override.hasOwnProperty(prop);
 25.4043 +    return overridden ? e.override[prop] : e[prop];
 25.4044 +  }
 25.4045 +
 25.4046 +  // EVENT HANDLING
 25.4047 +
 25.4048 +  function on(emitter, type, f) {
 25.4049 +    if (emitter.addEventListener)
 25.4050 +      emitter.addEventListener(type, f, false);
 25.4051 +    else if (emitter.attachEvent)
 25.4052 +      emitter.attachEvent("on" + type, f);
 25.4053 +    else {
 25.4054 +      var map = emitter._handlers || (emitter._handlers = {});
 25.4055 +      var arr = map[type] || (map[type] = []);
 25.4056 +      arr.push(f);
 25.4057 +    }
 25.4058 +  }
 25.4059 +
 25.4060 +  function off(emitter, type, f) {
 25.4061 +    if (emitter.removeEventListener)
 25.4062 +      emitter.removeEventListener(type, f, false);
 25.4063 +    else if (emitter.detachEvent)
 25.4064 +      emitter.detachEvent("on" + type, f);
 25.4065 +    else {
 25.4066 +      var arr = emitter._handlers && emitter._handlers[type];
 25.4067 +      if (!arr) return;
 25.4068 +      for (var i = 0; i < arr.length; ++i)
 25.4069 +        if (arr[i] == f) { arr.splice(i, 1); break; }
 25.4070 +    }
 25.4071 +  }
 25.4072 +
 25.4073 +  function signal(emitter, type /*, values...*/) {
 25.4074 +    var arr = emitter._handlers && emitter._handlers[type];
 25.4075 +    if (!arr) return;
 25.4076 +    var args = Array.prototype.slice.call(arguments, 2);
 25.4077 +    for (var i = 0; i < arr.length; ++i) arr[i].apply(null, args);
 25.4078 +  }
 25.4079 +
 25.4080 +  function signalLater(cm, emitter, type /*, values...*/) {
 25.4081 +    var arr = emitter._handlers && emitter._handlers[type];
 25.4082 +    if (!arr) return;
 25.4083 +    var args = Array.prototype.slice.call(arguments, 3), flist = cm.curOp && cm.curOp.delayedCallbacks;
 25.4084 +    function bnd(f) {return function(){f.apply(null, args);};};
 25.4085 +    for (var i = 0; i < arr.length; ++i)
 25.4086 +      if (flist) flist.push(bnd(arr[i]));
 25.4087 +      else arr[i].apply(null, args);
 25.4088 +  }
 25.4089 +
 25.4090 +  function hasHandler(emitter, type) {
 25.4091 +    var arr = emitter._handlers && emitter._handlers[type];
 25.4092 +    return arr && arr.length > 0;
 25.4093 +  }
 25.4094 +
 25.4095 +  CodeMirror.on = on; CodeMirror.off = off; CodeMirror.signal = signal;
 25.4096 +
 25.4097 +  // MISC UTILITIES
 25.4098 +
 25.4099 +  // Number of pixels added to scroller and sizer to hide scrollbar
 25.4100 +  var scrollerCutOff = 30;
 25.4101 +
 25.4102 +  // Returned or thrown by various protocols to signal 'I'm not
 25.4103 +  // handling this'.
 25.4104 +  var Pass = CodeMirror.Pass = {toString: function(){return "CodeMirror.Pass";}};
 25.4105 +
 25.4106 +  function Delayed() {this.id = null;}
 25.4107 +  Delayed.prototype = {set: function(ms, f) {clearTimeout(this.id); this.id = setTimeout(f, ms);}};
 25.4108 +
 25.4109 +  // Counts the column offset in a string, taking tabs into account.
 25.4110 +  // Used mostly to find indentation.
 25.4111 +  function countColumn(string, end, tabSize) {
 25.4112 +    if (end == null) {
 25.4113 +      end = string.search(/[^\s\u00a0]/);
 25.4114 +      if (end == -1) end = string.length;
 25.4115 +    }
 25.4116 +    for (var i = 0, n = 0; i < end; ++i) {
 25.4117 +      if (string.charAt(i) == "\t") n += tabSize - (n % tabSize);
 25.4118 +      else ++n;
 25.4119 +    }
 25.4120 +    return n;
 25.4121 +  }
 25.4122 +  CodeMirror.countColumn = countColumn;
 25.4123 +
 25.4124 +  var spaceStrs = [""];
 25.4125 +  function spaceStr(n) {
 25.4126 +    while (spaceStrs.length <= n)
 25.4127 +      spaceStrs.push(lst(spaceStrs) + " ");
 25.4128 +    return spaceStrs[n];
 25.4129 +  }
 25.4130 +
 25.4131 +  function lst(arr) { return arr[arr.length-1]; }
 25.4132 +
 25.4133 +  function selectInput(node) {
 25.4134 +    if (ios) { // Mobile Safari apparently has a bug where select() is broken.
 25.4135 +      node.selectionStart = 0;
 25.4136 +      node.selectionEnd = node.value.length;
 25.4137 +    } else node.select();
 25.4138 +  }
 25.4139 +
 25.4140 +  function indexOf(collection, elt) {
 25.4141 +    if (collection.indexOf) return collection.indexOf(elt);
 25.4142 +    for (var i = 0, e = collection.length; i < e; ++i)
 25.4143 +      if (collection[i] == elt) return i;
 25.4144 +    return -1;
 25.4145 +  }
 25.4146 +
 25.4147 +  function emptyArray(size) {
 25.4148 +    for (var a = [], i = 0; i < size; ++i) a.push(undefined);
 25.4149 +    return a;
 25.4150 +  }
 25.4151 +
 25.4152 +  function bind(f) {
 25.4153 +    var args = Array.prototype.slice.call(arguments, 1);
 25.4154 +    return function(){return f.apply(null, args);};
 25.4155 +  }
 25.4156 +
 25.4157 +  var nonASCIISingleCaseWordChar = /[\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc]/;
 25.4158 +  function isWordChar(ch) {
 25.4159 +    return /\w/.test(ch) || ch > "\x80" &&
 25.4160 +      (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
 25.4161 +  }
 25.4162 +
 25.4163 +  function isEmpty(obj) {
 25.4164 +    var c = 0;
 25.4165 +    for (var n in obj) if (obj.hasOwnProperty(n) && obj[n]) ++c;
 25.4166 +    return !c;
 25.4167 +  }
 25.4168 +
 25.4169 +  var isExtendingChar = /[\u0300-\u036F\u0483-\u0487\u0488-\u0489\u0591-\u05BD\u05BF\u05C1-\u05C2\u05C4-\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7-\u06E8\u06EA-\u06ED\uA66F\uA670-\uA672\uA674-\uA67D\uA69F]/;
 25.4170 +
 25.4171 +  // DOM UTILITIES
 25.4172 +
 25.4173 +  function elt(tag, content, className, style) {
 25.4174 +    var e = document.createElement(tag);
 25.4175 +    if (className) e.className = className;
 25.4176 +    if (style) e.style.cssText = style;
 25.4177 +    if (typeof content == "string") setTextContent(e, content);
 25.4178 +    else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
 25.4179 +    return e;
 25.4180 +  }
 25.4181 +
 25.4182 +  function removeChildren(e) {
 25.4183 +    e.innerHTML = "";
 25.4184 +    return e;
 25.4185 +  }
 25.4186 +
 25.4187 +  function removeChildrenAndAdd(parent, e) {
 25.4188 +    return removeChildren(parent).appendChild(e);
 25.4189 +  }
 25.4190 +
 25.4191 +  function setTextContent(e, str) {
 25.4192 +    if (ie_lt9) {
 25.4193 +      e.innerHTML = "";
 25.4194 +      e.appendChild(document.createTextNode(str));
 25.4195 +    } else e.textContent = str;
 25.4196 +  }
 25.4197 +
 25.4198 +  // FEATURE DETECTION
 25.4199 +
 25.4200 +  // Detect drag-and-drop
 25.4201 +  var dragAndDrop = function() {
 25.4202 +    // There is *some* kind of drag-and-drop support in IE6-8, but I
 25.4203 +    // couldn't get it to work yet.
 25.4204 +    if (ie_lt9) return false;
 25.4205 +    var div = elt('div');
 25.4206 +    return "draggable" in div || "dragDrop" in div;
 25.4207 +  }();
 25.4208 +
 25.4209 +  // For a reason I have yet to figure out, some browsers disallow
 25.4210 +  // word wrapping between certain characters *only* if a new inline
 25.4211 +  // element is started between them. This makes it hard to reliably
 25.4212 +  // measure the position of things, since that requires inserting an
 25.4213 +  // extra span. This terribly fragile set of regexps matches the
 25.4214 +  // character combinations that suffer from this phenomenon on the
 25.4215 +  // various browsers.
 25.4216 +  var spanAffectsWrapping = /^$/; // Won't match any two-character string
 25.4217 +  if (gecko) spanAffectsWrapping = /$'/;
 25.4218 +  else if (safari) spanAffectsWrapping = /\-[^ \-?]|\?[^ !'\"\),.\-\/:;\?\]\}]/;
 25.4219 +  else if (chrome) spanAffectsWrapping = /\-[^ \-\.?]|\?[^ \-\.?\]\}:;!'\"\),\/]|[\.!\"#&%\)*+,:;=>\]|\}~][\(\{\[<]|\$'/;
 25.4220 +
 25.4221 +  var knownScrollbarWidth;
 25.4222 +  function scrollbarWidth(measure) {
 25.4223 +    if (knownScrollbarWidth != null) return knownScrollbarWidth;
 25.4224 +    var test = elt("div", null, null, "width: 50px; height: 50px; overflow-x: scroll");
 25.4225 +    removeChildrenAndAdd(measure, test);
 25.4226 +    if (test.offsetWidth)
 25.4227 +      knownScrollbarWidth = test.offsetHeight - test.clientHeight;
 25.4228 +    return knownScrollbarWidth || 0;
 25.4229 +  }
 25.4230 +
 25.4231 +  var zwspSupported;
 25.4232 +  function zeroWidthElement(measure) {
 25.4233 +    if (zwspSupported == null) {
 25.4234 +      var test = elt("span", "\u200b");
 25.4235 +      removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
 25.4236 +      if (measure.firstChild.offsetHeight != 0)
 25.4237 +        zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !ie_lt8;
 25.4238 +    }
 25.4239 +    if (zwspSupported) return elt("span", "\u200b");
 25.4240 +    else return elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
 25.4241 +  }
 25.4242 +
 25.4243 +  // See if "".split is the broken IE version, if so, provide an
 25.4244 +  // alternative way to split lines.
 25.4245 +  var splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
 25.4246 +    var pos = 0, result = [], l = string.length;
 25.4247 +    while (pos <= l) {
 25.4248 +      var nl = string.indexOf("\n", pos);
 25.4249 +      if (nl == -1) nl = string.length;
 25.4250 +      var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
 25.4251 +      var rt = line.indexOf("\r");
 25.4252 +      if (rt != -1) {
 25.4253 +        result.push(line.slice(0, rt));
 25.4254 +        pos += rt + 1;
 25.4255 +      } else {
 25.4256 +        result.push(line);
 25.4257 +        pos = nl + 1;
 25.4258 +      }
 25.4259 +    }
 25.4260 +    return result;
 25.4261 +  } : function(string){return string.split(/\r\n?|\n/);};
 25.4262 +  CodeMirror.splitLines = splitLines;
 25.4263 +
 25.4264 +  var hasSelection = window.getSelection ? function(te) {
 25.4265 +    try { return te.selectionStart != te.selectionEnd; }
 25.4266 +    catch(e) { return false; }
 25.4267 +  } : function(te) {
 25.4268 +    try {var range = te.ownerDocument.selection.createRange();}
 25.4269 +    catch(e) {}
 25.4270 +    if (!range || range.parentElement() != te) return false;
 25.4271 +    return range.compareEndPoints("StartToEnd", range) != 0;
 25.4272 +  };
 25.4273 +
 25.4274 +  var hasCopyEvent = (function() {
 25.4275 +    var e = elt("div");
 25.4276 +    if ("oncopy" in e) return true;
 25.4277 +    e.setAttribute("oncopy", "return;");
 25.4278 +    return typeof e.oncopy == 'function';
 25.4279 +  })();
 25.4280 +
 25.4281 +  // KEY NAMING
 25.4282 +
 25.4283 +  var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
 25.4284 +                  19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
 25.4285 +                  36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
 25.4286 +                  46: "Delete", 59: ";", 91: "Mod", 92: "Mod", 93: "Mod", 109: "-", 107: "=", 127: "Delete",
 25.4287 +                  186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
 25.4288 +                  221: "]", 222: "'", 63276: "PageUp", 63277: "PageDown", 63275: "End", 63273: "Home",
 25.4289 +                  63234: "Left", 63232: "Up", 63235: "Right", 63233: "Down", 63302: "Insert", 63272: "Delete"};
 25.4290 +  CodeMirror.keyNames = keyNames;
 25.4291 +  (function() {
 25.4292 +    // Number keys
 25.4293 +    for (var i = 0; i < 10; i++) keyNames[i + 48] = String(i);
 25.4294 +    // Alphabetic keys
 25.4295 +    for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
 25.4296 +    // Function keys
 25.4297 +    for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
 25.4298 +  })();
 25.4299 +
 25.4300 +  // BIDI HELPERS
 25.4301 +
 25.4302 +  function iterateBidiSections(order, from, to, f) {
 25.4303 +    if (!order) return f(from, to, "ltr");
 25.4304 +    for (var i = 0; i < order.length; ++i) {
 25.4305 +      var part = order[i];
 25.4306 +      if (part.from < to && part.to > from)
 25.4307 +        f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr");
 25.4308 +    }
 25.4309 +  }
 25.4310 +
 25.4311 +  function bidiLeft(part) { return part.level % 2 ? part.to : part.from; }
 25.4312 +  function bidiRight(part) { return part.level % 2 ? part.from : part.to; }
 25.4313 +
 25.4314 +  function lineLeft(line) { var order = getOrder(line); return order ? bidiLeft(order[0]) : 0; }
 25.4315 +  function lineRight(line) {
 25.4316 +    var order = getOrder(line);
 25.4317 +    if (!order) return line.text.length;
 25.4318 +    return bidiRight(lst(order));
 25.4319 +  }
 25.4320 +
 25.4321 +  function lineStart(cm, lineN) {
 25.4322 +    var line = getLine(cm.view.doc, lineN);
 25.4323 +    var visual = visualLine(cm.view.doc, line);
 25.4324 +    if (visual != line) lineN = lineNo(visual);
 25.4325 +    var order = getOrder(visual);
 25.4326 +    var ch = !order ? 0 : order[0].level % 2 ? lineRight(visual) : lineLeft(visual);
 25.4327 +    return {line: lineN, ch: ch};
 25.4328 +  }
 25.4329 +  function lineEnd(cm, lineNo) {
 25.4330 +    var merged, line;
 25.4331 +    while (merged = collapsedSpanAtEnd(line = getLine(cm.view.doc, lineNo)))
 25.4332 +      lineNo = merged.find().to.line;
 25.4333 +    var order = getOrder(line);
 25.4334 +    var ch = !order ? line.text.length : order[0].level % 2 ? lineLeft(line) : lineRight(line);
 25.4335 +    return {line: lineNo, ch: ch};
 25.4336 +  }
 25.4337 +
 25.4338 +  // This is somewhat involved. It is needed in order to move
 25.4339 +  // 'visually' through bi-directional text -- i.e., pressing left
 25.4340 +  // should make the cursor go left, even when in RTL text. The
 25.4341 +  // tricky part is the 'jumps', where RTL and LTR text touch each
 25.4342 +  // other. This often requires the cursor offset to move more than
 25.4343 +  // one unit, in order to visually move one unit.
 25.4344 +  function moveVisually(line, start, dir, byUnit) {
 25.4345 +    var bidi = getOrder(line);
 25.4346 +    if (!bidi) return moveLogically(line, start, dir, byUnit);
 25.4347 +    var moveOneUnit = byUnit ? function(pos, dir) {
 25.4348 +      do pos += dir;
 25.4349 +      while (pos > 0 && isExtendingChar.test(line.text.charAt(pos)));
 25.4350 +      return pos;
 25.4351 +    } : function(pos, dir) { return pos + dir; };
 25.4352 +    var linedir = bidi[0].level;
 25.4353 +    for (var i = 0; i < bidi.length; ++i) {
 25.4354 +      var part = bidi[i], sticky = part.level % 2 == linedir;
 25.4355 +      if ((part.from < start && part.to > start) ||
 25.4356 +          (sticky && (part.from == start || part.to == start))) break;
 25.4357 +    }
 25.4358 +    var target = moveOneUnit(start, part.level % 2 ? -dir : dir);
 25.4359 +
 25.4360 +    while (target != null) {
 25.4361 +      if (part.level % 2 == linedir) {
 25.4362 +        if (target < part.from || target > part.to) {
 25.4363 +          part = bidi[i += dir];
 25.4364 +          target = part && (dir > 0 == part.level % 2 ? moveOneUnit(part.to, -1) : moveOneUnit(part.from, 1));
 25.4365 +        } else break;
 25.4366 +      } else {
 25.4367 +        if (target == bidiLeft(part)) {
 25.4368 +          part = bidi[--i];
 25.4369 +          target = part && bidiRight(part);
 25.4370 +        } else if (target == bidiRight(part)) {
 25.4371 +          part = bidi[++i];
 25.4372 +          target = part && bidiLeft(part);
 25.4373 +        } else break;
 25.4374 +      }
 25.4375 +    }
 25.4376 +
 25.4377 +    return target < 0 || target > line.text.length ? null : target;
 25.4378 +  }
 25.4379 +
 25.4380 +  function moveLogically(line, start, dir, byUnit) {
 25.4381 +    var target = start + dir;
 25.4382 +    if (byUnit) while (target > 0 && isExtendingChar.test(line.text.charAt(target))) target += dir;
 25.4383 +    return target < 0 || target > line.text.length ? null : target;
 25.4384 +  }
 25.4385 +
 25.4386 +  // Bidirectional ordering algorithm
 25.4387 +  // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
 25.4388 +  // that this (partially) implements.
 25.4389 +
 25.4390 +  // One-char codes used for character types:
 25.4391 +  // L (L):   Left-to-Right
 25.4392 +  // R (R):   Right-to-Left
 25.4393 +  // r (AL):  Right-to-Left Arabic
 25.4394 +  // 1 (EN):  European Number
 25.4395 +  // + (ES):  European Number Separator
 25.4396 +  // % (ET):  European Number Terminator
 25.4397 +  // n (AN):  Arabic Number
 25.4398 +  // , (CS):  Common Number Separator
 25.4399 +  // m (NSM): Non-Spacing Mark
 25.4400 +  // b (BN):  Boundary Neutral
 25.4401 +  // s (B):   Paragraph Separator
 25.4402 +  // t (S):   Segment Separator
 25.4403 +  // w (WS):  Whitespace
 25.4404 +  // N (ON):  Other Neutrals
 25.4405 +
 25.4406 +  // Returns null if characters are ordered as they appear
 25.4407 +  // (left-to-right), or an array of sections ({from, to, level}
 25.4408 +  // objects) in the order in which they occur visually.
 25.4409 +  var bidiOrdering = (function() {
 25.4410 +    // Character types for codepoints 0 to 0xff
 25.4411 +    var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLL";
 25.4412 +    // Character types for codepoints 0x600 to 0x6ff
 25.4413 +    var arabicTypes = "rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmmrrrrrrrrrrrrrrrrrr";
 25.4414 +    function charType(code) {
 25.4415 +      if (code <= 0xff) return lowTypes.charAt(code);
 25.4416 +      else if (0x590 <= code && code <= 0x5f4) return "R";
 25.4417 +      else if (0x600 <= code && code <= 0x6ff) return arabicTypes.charAt(code - 0x600);
 25.4418 +      else if (0x700 <= code && code <= 0x8ac) return "r";
 25.4419 +      else return "L";
 25.4420 +    }
 25.4421 +
 25.4422 +    var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
 25.4423 +    var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
 25.4424 +
 25.4425 +    return function charOrdering(str) {
 25.4426 +      if (!bidiRE.test(str)) return false;
 25.4427 +      var len = str.length, types = [], startType = null;
 25.4428 +      for (var i = 0, type; i < len; ++i) {
 25.4429 +        types.push(type = charType(str.charCodeAt(i)));
 25.4430 +        if (startType == null) {
 25.4431 +          if (type == "L") startType = "L";
 25.4432 +          else if (type == "R" || type == "r") startType = "R";
 25.4433 +        }
 25.4434 +      }
 25.4435 +      if (startType == null) startType = "L";
 25.4436 +
 25.4437 +      // W1. Examine each non-spacing mark (NSM) in the level run, and
 25.4438 +      // change the type of the NSM to the type of the previous
 25.4439 +      // character. If the NSM is at the start of the level run, it will
 25.4440 +      // get the type of sor.
 25.4441 +      for (var i = 0, prev = startType; i < len; ++i) {
 25.4442 +        var type = types[i];
 25.4443 +        if (type == "m") types[i] = prev;
 25.4444 +        else prev = type;
 25.4445 +      }
 25.4446 +
 25.4447 +      // W2. Search backwards from each instance of a European number
 25.4448 +      // until the first strong type (R, L, AL, or sor) is found. If an
 25.4449 +      // AL is found, change the type of the European number to Arabic
 25.4450 +      // number.
 25.4451 +      // W3. Change all ALs to R.
 25.4452 +      for (var i = 0, cur = startType; i < len; ++i) {
 25.4453 +        var type = types[i];
 25.4454 +        if (type == "1" && cur == "r") types[i] = "n";
 25.4455 +        else if (isStrong.test(type)) { cur = type; if (type == "r") types[i] = "R"; }
 25.4456 +      }
 25.4457 +
 25.4458 +      // W4. A single European separator between two European numbers
 25.4459 +      // changes to a European number. A single common separator between
 25.4460 +      // two numbers of the same type changes to that type.
 25.4461 +      for (var i = 1, prev = types[0]; i < len - 1; ++i) {
 25.4462 +        var type = types[i];
 25.4463 +        if (type == "+" && prev == "1" && types[i+1] == "1") types[i] = "1";
 25.4464 +        else if (type == "," && prev == types[i+1] &&
 25.4465 +                 (prev == "1" || prev == "n")) types[i] = prev;
 25.4466 +        prev = type;
 25.4467 +      }
 25.4468 +
 25.4469 +      // W5. A sequence of European terminators adjacent to European
 25.4470 +      // numbers changes to all European numbers.
 25.4471 +      // W6. Otherwise, separators and terminators change to Other
 25.4472 +      // Neutral.
 25.4473 +      for (var i = 0; i < len; ++i) {
 25.4474 +        var type = types[i];
 25.4475 +        if (type == ",") types[i] = "N";
 25.4476 +        else if (type == "%") {
 25.4477 +          for (var end = i + 1; end < len && types[end] == "%"; ++end) {}
 25.4478 +          var replace = (i && types[i-1] == "!") || (end < len - 1 && types[end] == "1") ? "1" : "N";
 25.4479 +          for (var j = i; j < end; ++j) types[j] = replace;
 25.4480 +          i = end - 1;
 25.4481 +        }
 25.4482 +      }
 25.4483 +
 25.4484 +      // W7. Search backwards from each instance of a European number
 25.4485 +      // until the first strong type (R, L, or sor) is found. If an L is
 25.4486 +      // found, then change the type of the European number to L.
 25.4487 +      for (var i = 0, cur = startType; i < len; ++i) {
 25.4488 +        var type = types[i];
 25.4489 +        if (cur == "L" && type == "1") types[i] = "L";
 25.4490 +        else if (isStrong.test(type)) cur = type;
 25.4491 +      }
 25.4492 +
 25.4493 +      // N1. A sequence of neutrals takes the direction of the
 25.4494 +      // surrounding strong text if the text on both sides has the same
 25.4495 +      // direction. European and Arabic numbers act as if they were R in
 25.4496 +      // terms of their influence on neutrals. Start-of-level-run (sor)
 25.4497 +      // and end-of-level-run (eor) are used at level run boundaries.
 25.4498 +      // N2. Any remaining neutrals take the embedding direction.
 25.4499 +      for (var i = 0; i < len; ++i) {
 25.4500 +        if (isNeutral.test(types[i])) {
 25.4501 +          for (var end = i + 1; end < len && isNeutral.test(types[end]); ++end) {}
 25.4502 +          var before = (i ? types[i-1] : startType) == "L";
 25.4503 +          var after = (end < len - 1 ? types[end] : startType) == "L";
 25.4504 +          var replace = before || after ? "L" : "R";
 25.4505 +          for (var j = i; j < end; ++j) types[j] = replace;
 25.4506 +          i = end - 1;
 25.4507 +        }
 25.4508 +      }
 25.4509 +
 25.4510 +      // Here we depart from the documented algorithm, in order to avoid
 25.4511 +      // building up an actual levels array. Since there are only three
 25.4512 +      // levels (0, 1, 2) in an implementation that doesn't take
 25.4513 +      // explicit embedding into account, we can build up the order on
 25.4514 +      // the fly, without following the level-based algorithm.
 25.4515 +      var order = [], m;
 25.4516 +      for (var i = 0; i < len;) {
 25.4517 +        if (countsAsLeft.test(types[i])) {
 25.4518 +          var start = i;
 25.4519 +          for (++i; i < len && countsAsLeft.test(types[i]); ++i) {}
 25.4520 +          order.push({from: start, to: i, level: 0});
 25.4521 +        } else {
 25.4522 +          var pos = i, at = order.length;
 25.4523 +          for (++i; i < len && types[i] != "L"; ++i) {}
 25.4524 +          for (var j = pos; j < i;) {
 25.4525 +            if (countsAsNum.test(types[j])) {
 25.4526 +              if (pos < j) order.splice(at, 0, {from: pos, to: j, level: 1});
 25.4527 +              var nstart = j;
 25.4528 +              for (++j; j < i && countsAsNum.test(types[j]); ++j) {}
 25.4529 +              order.splice(at, 0, {from: nstart, to: j, level: 2});
 25.4530 +              pos = j;
 25.4531 +            } else ++j;
 25.4532 +          }
 25.4533 +          if (pos < i) order.splice(at, 0, {from: pos, to: i, level: 1});
 25.4534 +        }
 25.4535 +      }
 25.4536 +      if (order[0].level == 1 && (m = str.match(/^\s+/))) {
 25.4537 +        order[0].from = m[0].length;
 25.4538 +        order.unshift({from: 0, to: m[0].length, level: 0});
 25.4539 +      }
 25.4540 +      if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
 25.4541 +        lst(order).to -= m[0].length;
 25.4542 +        order.push({from: len - m[0].length, to: len, level: 0});
 25.4543 +      }
 25.4544 +      if (order[0].level != lst(order).level)
 25.4545 +        order.push({from: len, to: len, level: order[0].level});
 25.4546 +
 25.4547 +      return order;
 25.4548 +    };
 25.4549 +  })();
 25.4550 +
 25.4551 +  // THE END
 25.4552 +
 25.4553 +  CodeMirror.version = "3.0";
 25.4554 +
 25.4555 +  return CodeMirror;
 25.4556 +})();
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/mode/clike.js	Sun Feb 03 07:48:42 2013 +0100
    26.3 @@ -0,0 +1,300 @@
    26.4 +CodeMirror.defineMode("clike", function(config, parserConfig) {
    26.5 +  var indentUnit = config.indentUnit,
    26.6 +      statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
    26.7 +      keywords = parserConfig.keywords || {},
    26.8 +      builtin = parserConfig.builtin || {},
    26.9 +      blockKeywords = parserConfig.blockKeywords || {},
   26.10 +      atoms = parserConfig.atoms || {},
   26.11 +      hooks = parserConfig.hooks || {},
   26.12 +      multiLineStrings = parserConfig.multiLineStrings;
   26.13 +  var isOperatorChar = /[+\-*&%=<>!?|\/]/;
   26.14 +
   26.15 +  var curPunc;
   26.16 +
   26.17 +  function tokenBase(stream, state) {
   26.18 +    var ch = stream.next();
   26.19 +    if (hooks[ch]) {
   26.20 +      var result = hooks[ch](stream, state);
   26.21 +      if (result !== false) return result;
   26.22 +    }
   26.23 +    if (ch == '"' || ch == "'") {
   26.24 +      state.tokenize = tokenString(ch);
   26.25 +      return state.tokenize(stream, state);
   26.26 +    }
   26.27 +    if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
   26.28 +      curPunc = ch;
   26.29 +      return null;
   26.30 +    }
   26.31 +    if (/\d/.test(ch)) {
   26.32 +      stream.eatWhile(/[\w\.]/);
   26.33 +      return "number";
   26.34 +    }
   26.35 +    if (ch == "/") {
   26.36 +      if (stream.eat("*")) {
   26.37 +        state.tokenize = tokenComment;
   26.38 +        return tokenComment(stream, state);
   26.39 +      }
   26.40 +      if (stream.eat("/")) {
   26.41 +        stream.skipToEnd();
   26.42 +        return "comment";
   26.43 +      }
   26.44 +    }
   26.45 +    if (isOperatorChar.test(ch)) {
   26.46 +      stream.eatWhile(isOperatorChar);
   26.47 +      return "operator";
   26.48 +    }
   26.49 +    stream.eatWhile(/[\w\$_]/);
   26.50 +    var cur = stream.current();
   26.51 +    if (keywords.propertyIsEnumerable(cur)) {
   26.52 +      if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
   26.53 +      return "keyword";
   26.54 +    }
   26.55 +    if (builtin.propertyIsEnumerable(cur)) {
   26.56 +      if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
   26.57 +      return "builtin";
   26.58 +    }
   26.59 +    if (atoms.propertyIsEnumerable(cur)) return "atom";
   26.60 +    return "variable";
   26.61 +  }
   26.62 +
   26.63 +  function tokenString(quote) {
   26.64 +    return function(stream, state) {
   26.65 +      var escaped = false, next, end = false;
   26.66 +      while ((next = stream.next()) != null) {
   26.67 +        if (next == quote && !escaped) {end = true; break;}
   26.68 +        escaped = !escaped && next == "\\";
   26.69 +      }
   26.70 +      if (end || !(escaped || multiLineStrings))
   26.71 +        state.tokenize = null;
   26.72 +      return "string";
   26.73 +    };
   26.74 +  }
   26.75 +
   26.76 +  function tokenComment(stream, state) {
   26.77 +    var maybeEnd = false, ch;
   26.78 +    while (ch = stream.next()) {
   26.79 +      if (ch == "/" && maybeEnd) {
   26.80 +        state.tokenize = null;
   26.81 +        break;
   26.82 +      }
   26.83 +      maybeEnd = (ch == "*");
   26.84 +    }
   26.85 +    return "comment";
   26.86 +  }
   26.87 +
   26.88 +  function Context(indented, column, type, align, prev) {
   26.89 +    this.indented = indented;
   26.90 +    this.column = column;
   26.91 +    this.type = type;
   26.92 +    this.align = align;
   26.93 +    this.prev = prev;
   26.94 +  }
   26.95 +  function pushContext(state, col, type) {
   26.96 +    var indent = state.indented;
   26.97 +    if (state.context && state.context.type == "statement")
   26.98 +      indent = state.context.indented;
   26.99 +    return state.context = new Context(indent, col, type, null, state.context);
  26.100 +  }
  26.101 +  function popContext(state) {
  26.102 +    var t = state.context.type;
  26.103 +    if (t == ")" || t == "]" || t == "}")
  26.104 +      state.indented = state.context.indented;
  26.105 +    return state.context = state.context.prev;
  26.106 +  }
  26.107 +
  26.108 +  // Interface
  26.109 +
  26.110 +  return {
  26.111 +    startState: function(basecolumn) {
  26.112 +      return {
  26.113 +        tokenize: null,
  26.114 +        context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
  26.115 +        indented: 0,
  26.116 +        startOfLine: true
  26.117 +      };
  26.118 +    },
  26.119 +
  26.120 +    token: function(stream, state) {
  26.121 +      var ctx = state.context;
  26.122 +      if (stream.sol()) {
  26.123 +        if (ctx.align == null) ctx.align = false;
  26.124 +        state.indented = stream.indentation();
  26.125 +        state.startOfLine = true;
  26.126 +      }
  26.127 +      if (stream.eatSpace()) return null;
  26.128 +      curPunc = null;
  26.129 +      var style = (state.tokenize || tokenBase)(stream, state);
  26.130 +      if (style == "comment" || style == "meta") return style;
  26.131 +      if (ctx.align == null) ctx.align = true;
  26.132 +
  26.133 +      if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state);
  26.134 +      else if (curPunc == "{") pushContext(state, stream.column(), "}");
  26.135 +      else if (curPunc == "[") pushContext(state, stream.column(), "]");
  26.136 +      else if (curPunc == "(") pushContext(state, stream.column(), ")");
  26.137 +      else if (curPunc == "}") {
  26.138 +        while (ctx.type == "statement") ctx = popContext(state);
  26.139 +        if (ctx.type == "}") ctx = popContext(state);
  26.140 +        while (ctx.type == "statement") ctx = popContext(state);
  26.141 +      }
  26.142 +      else if (curPunc == ctx.type) popContext(state);
  26.143 +      else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement"))
  26.144 +        pushContext(state, stream.column(), "statement");
  26.145 +      state.startOfLine = false;
  26.146 +      return style;
  26.147 +    },
  26.148 +
  26.149 +    indent: function(state, textAfter) {
  26.150 +      if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
  26.151 +      var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
  26.152 +      if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
  26.153 +      var closing = firstChar == ctx.type;
  26.154 +      if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
  26.155 +      else if (ctx.align) return ctx.column + (closing ? 0 : 1);
  26.156 +      else return ctx.indented + (closing ? 0 : indentUnit);
  26.157 +    },
  26.158 +
  26.159 +    electricChars: "{}"
  26.160 +  };
  26.161 +});
  26.162 +
  26.163 +(function() {
  26.164 +  function words(str) {
  26.165 +    var obj = {}, words = str.split(" ");
  26.166 +    for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
  26.167 +    return obj;
  26.168 +  }
  26.169 +  var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
  26.170 +    "double static else struct entry switch extern typedef float union for unsigned " +
  26.171 +    "goto while enum void const signed volatile";
  26.172 +
  26.173 +  function cppHook(stream, state) {
  26.174 +    if (!state.startOfLine) return false;
  26.175 +    for (;;) {
  26.176 +      if (stream.skipTo("\\")) {
  26.177 +        stream.next();
  26.178 +        if (stream.eol()) {
  26.179 +          state.tokenize = cppHook;
  26.180 +          break;
  26.181 +        }
  26.182 +      } else {
  26.183 +        stream.skipToEnd();
  26.184 +        state.tokenize = null;
  26.185 +        break;
  26.186 +      }
  26.187 +    }
  26.188 +    return "meta";
  26.189 +  }
  26.190 +
  26.191 +  // C#-style strings where "" escapes a quote.
  26.192 +  function tokenAtString(stream, state) {
  26.193 +    var next;
  26.194 +    while ((next = stream.next()) != null) {
  26.195 +      if (next == '"' && !stream.eat('"')) {
  26.196 +        state.tokenize = null;
  26.197 +        break;
  26.198 +      }
  26.199 +    }
  26.200 +    return "string";
  26.201 +  }
  26.202 +
  26.203 +  function mimes(ms, mode) {
  26.204 +    for (var i = 0; i < ms.length; ++i) CodeMirror.defineMIME(ms[i], mode);
  26.205 +  }
  26.206 +
  26.207 +  mimes(["text/x-csrc", "text/x-c", "text/x-chdr"], {
  26.208 +    name: "clike",
  26.209 +    keywords: words(cKeywords),
  26.210 +    blockKeywords: words("case do else for if switch while struct"),
  26.211 +    atoms: words("null"),
  26.212 +    hooks: {"#": cppHook}
  26.213 +  });
  26.214 +  mimes(["text/x-c++src", "text/x-c++hdr"], {
  26.215 +    name: "clike",
  26.216 +    keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
  26.217 +                    "static_cast typeid catch operator template typename class friend private " +
  26.218 +                    "this using const_cast inline public throw virtual delete mutable protected " +
  26.219 +                    "wchar_t"),
  26.220 +    blockKeywords: words("catch class do else finally for if struct switch try while"),
  26.221 +    atoms: words("true false null"),
  26.222 +    hooks: {"#": cppHook}
  26.223 +  });
  26.224 +  CodeMirror.defineMIME("text/x-java", {
  26.225 +    name: "clike",
  26.226 +    keywords: words("abstract assert boolean break byte case catch char class const continue default " + 
  26.227 +                    "do double else enum extends final finally float for goto if implements import " +
  26.228 +                    "instanceof int interface long native new package private protected public " +
  26.229 +                    "return short static strictfp super switch synchronized this throw throws transient " +
  26.230 +                    "try void volatile while"),
  26.231 +    blockKeywords: words("catch class do else finally for if switch try while"),
  26.232 +    atoms: words("true false null"),
  26.233 +    hooks: {
  26.234 +      "@": function(stream) {
  26.235 +        stream.eatWhile(/[\w\$_]/);
  26.236 +        return "meta";
  26.237 +      }
  26.238 +    }
  26.239 +  });
  26.240 +  CodeMirror.defineMIME("text/x-csharp", {
  26.241 +    name: "clike",
  26.242 +    keywords: words("abstract as base break case catch checked class const continue" + 
  26.243 +                    " default delegate do else enum event explicit extern finally fixed for" + 
  26.244 +                    " foreach goto if implicit in interface internal is lock namespace new" + 
  26.245 +                    " operator out override params private protected public readonly ref return sealed" + 
  26.246 +                    " sizeof stackalloc static struct switch this throw try typeof unchecked" + 
  26.247 +                    " unsafe using virtual void volatile while add alias ascending descending dynamic from get" + 
  26.248 +                    " global group into join let orderby partial remove select set value var yield"),
  26.249 +    blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
  26.250 +    builtin: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" +
  26.251 +                    " Guid Int16 Int32 Int64 Object SByte Single String TimeSpan UInt16 UInt32" +
  26.252 +                    " UInt64 bool byte char decimal double short int long object"  +
  26.253 +                    " sbyte float string ushort uint ulong"),
  26.254 +    atoms: words("true false null"),
  26.255 +    hooks: {
  26.256 +      "@": function(stream, state) {
  26.257 +        if (stream.eat('"')) {
  26.258 +          state.tokenize = tokenAtString;
  26.259 +          return tokenAtString(stream, state);
  26.260 +        }
  26.261 +        stream.eatWhile(/[\w\$_]/);
  26.262 +        return "meta";
  26.263 +      }
  26.264 +    }
  26.265 +  });
  26.266 +  CodeMirror.defineMIME("text/x-scala", {
  26.267 +    name: "clike",
  26.268 +    keywords: words(
  26.269 +      
  26.270 +      /* scala */
  26.271 +      "abstract case catch class def do else extends false final finally for forSome if " +
  26.272 +      "implicit import lazy match new null object override package private protected return " +
  26.273 +      "sealed super this throw trait try trye type val var while with yield _ : = => <- <: " +
  26.274 +      "<% >: # @ " +
  26.275 +                    
  26.276 +      /* package scala */
  26.277 +      "assert assume require print println printf readLine readBoolean readByte readShort " +
  26.278 +      "readChar readInt readLong readFloat readDouble " +
  26.279 +      
  26.280 +      "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
  26.281 +      "Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " +
  26.282 +      "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
  26.283 +      "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
  26.284 +      "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector :: #:: " +
  26.285 +      
  26.286 +      /* package java.lang */            
  26.287 +      "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
  26.288 +      "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
  26.289 +      "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
  26.290 +      "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
  26.291 +      
  26.292 +      
  26.293 +    ),
  26.294 +    blockKeywords: words("catch class do else finally for forSome if match switch try while"),
  26.295 +    atoms: words("true false null"),
  26.296 +    hooks: {
  26.297 +      "@": function(stream) {
  26.298 +        stream.eatWhile(/[\w\$_]/);
  26.299 +        return "meta";
  26.300 +      }
  26.301 +    }
  26.302 +  });
  26.303 +}());
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/mode/xml.js	Sun Feb 03 07:48:42 2013 +0100
    27.3 @@ -0,0 +1,324 @@
    27.4 +CodeMirror.defineMode("xml", function(config, parserConfig) {
    27.5 +  var indentUnit = config.indentUnit;
    27.6 +  var Kludges = parserConfig.htmlMode ? {
    27.7 +    autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
    27.8 +                      'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
    27.9 +                      'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
   27.10 +                      'track': true, 'wbr': true},
   27.11 +    implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
   27.12 +                       'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
   27.13 +                       'th': true, 'tr': true},
   27.14 +    contextGrabbers: {
   27.15 +      'dd': {'dd': true, 'dt': true},
   27.16 +      'dt': {'dd': true, 'dt': true},
   27.17 +      'li': {'li': true},
   27.18 +      'option': {'option': true, 'optgroup': true},
   27.19 +      'optgroup': {'optgroup': true},
   27.20 +      'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
   27.21 +            'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
   27.22 +            'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
   27.23 +            'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
   27.24 +            'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
   27.25 +      'rp': {'rp': true, 'rt': true},
   27.26 +      'rt': {'rp': true, 'rt': true},
   27.27 +      'tbody': {'tbody': true, 'tfoot': true},
   27.28 +      'td': {'td': true, 'th': true},
   27.29 +      'tfoot': {'tbody': true},
   27.30 +      'th': {'td': true, 'th': true},
   27.31 +      'thead': {'tbody': true, 'tfoot': true},
   27.32 +      'tr': {'tr': true}
   27.33 +    },
   27.34 +    doNotIndent: {"pre": true},
   27.35 +    allowUnquoted: true,
   27.36 +    allowMissing: true
   27.37 +  } : {
   27.38 +    autoSelfClosers: {},
   27.39 +    implicitlyClosed: {},
   27.40 +    contextGrabbers: {},
   27.41 +    doNotIndent: {},
   27.42 +    allowUnquoted: false,
   27.43 +    allowMissing: false
   27.44 +  };
   27.45 +  var alignCDATA = parserConfig.alignCDATA;
   27.46 +
   27.47 +  // Return variables for tokenizers
   27.48 +  var tagName, type;
   27.49 +
   27.50 +  function inText(stream, state) {
   27.51 +    function chain(parser) {
   27.52 +      state.tokenize = parser;
   27.53 +      return parser(stream, state);
   27.54 +    }
   27.55 +
   27.56 +    var ch = stream.next();
   27.57 +    if (ch == "<") {
   27.58 +      if (stream.eat("!")) {
   27.59 +        if (stream.eat("[")) {
   27.60 +          if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
   27.61 +          else return null;
   27.62 +        }
   27.63 +        else if (stream.match("--")) return chain(inBlock("comment", "-->"));
   27.64 +        else if (stream.match("DOCTYPE", true, true)) {
   27.65 +          stream.eatWhile(/[\w\._\-]/);
   27.66 +          return chain(doctype(1));
   27.67 +        }
   27.68 +        else return null;
   27.69 +      }
   27.70 +      else if (stream.eat("?")) {
   27.71 +        stream.eatWhile(/[\w\._\-]/);
   27.72 +        state.tokenize = inBlock("meta", "?>");
   27.73 +        return "meta";
   27.74 +      }
   27.75 +      else {
   27.76 +        var isClose = stream.eat("/");
   27.77 +        tagName = "";
   27.78 +        var c;
   27.79 +        while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
   27.80 +        if (!tagName) return "error";
   27.81 +        type = isClose ? "closeTag" : "openTag";
   27.82 +        state.tokenize = inTag;
   27.83 +        return "tag";
   27.84 +      }
   27.85 +    }
   27.86 +    else if (ch == "&") {
   27.87 +      var ok;
   27.88 +      if (stream.eat("#")) {
   27.89 +        if (stream.eat("x")) {
   27.90 +          ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");          
   27.91 +        } else {
   27.92 +          ok = stream.eatWhile(/[\d]/) && stream.eat(";");
   27.93 +        }
   27.94 +      } else {
   27.95 +        ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
   27.96 +      }
   27.97 +      return ok ? "atom" : "error";
   27.98 +    }
   27.99 +    else {
  27.100 +      stream.eatWhile(/[^&<]/);
  27.101 +      return null;
  27.102 +    }
  27.103 +  }
  27.104 +
  27.105 +  function inTag(stream, state) {
  27.106 +    var ch = stream.next();
  27.107 +    if (ch == ">" || (ch == "/" && stream.eat(">"))) {
  27.108 +      state.tokenize = inText;
  27.109 +      type = ch == ">" ? "endTag" : "selfcloseTag";
  27.110 +      return "tag";
  27.111 +    }
  27.112 +    else if (ch == "=") {
  27.113 +      type = "equals";
  27.114 +      return null;
  27.115 +    }
  27.116 +    else if (/[\'\"]/.test(ch)) {
  27.117 +      state.tokenize = inAttribute(ch);
  27.118 +      return state.tokenize(stream, state);
  27.119 +    }
  27.120 +    else {
  27.121 +      stream.eatWhile(/[^\s\u00a0=<>\"\']/);
  27.122 +      return "word";
  27.123 +    }
  27.124 +  }
  27.125 +
  27.126 +  function inAttribute(quote) {
  27.127 +    return function(stream, state) {
  27.128 +      while (!stream.eol()) {
  27.129 +        if (stream.next() == quote) {
  27.130 +          state.tokenize = inTag;
  27.131 +          break;
  27.132 +        }
  27.133 +      }
  27.134 +      return "string";
  27.135 +    };
  27.136 +  }
  27.137 +
  27.138 +  function inBlock(style, terminator) {
  27.139 +    return function(stream, state) {
  27.140 +      while (!stream.eol()) {
  27.141 +        if (stream.match(terminator)) {
  27.142 +          state.tokenize = inText;
  27.143 +          break;
  27.144 +        }
  27.145 +        stream.next();
  27.146 +      }
  27.147 +      return style;
  27.148 +    };
  27.149 +  }
  27.150 +  function doctype(depth) {
  27.151 +    return function(stream, state) {
  27.152 +      var ch;
  27.153 +      while ((ch = stream.next()) != null) {
  27.154 +        if (ch == "<") {
  27.155 +          state.tokenize = doctype(depth + 1);
  27.156 +          return state.tokenize(stream, state);
  27.157 +        } else if (ch == ">") {
  27.158 +          if (depth == 1) {
  27.159 +            state.tokenize = inText;
  27.160 +            break;
  27.161 +          } else {
  27.162 +            state.tokenize = doctype(depth - 1);
  27.163 +            return state.tokenize(stream, state);
  27.164 +          }
  27.165 +        }
  27.166 +      }
  27.167 +      return "meta";
  27.168 +    };
  27.169 +  }
  27.170 +
  27.171 +  var curState, setStyle;
  27.172 +  function pass() {
  27.173 +    for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
  27.174 +  }
  27.175 +  function cont() {
  27.176 +    pass.apply(null, arguments);
  27.177 +    return true;
  27.178 +  }
  27.179 +
  27.180 +  function pushContext(tagName, startOfLine) {
  27.181 +    var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent);
  27.182 +    curState.context = {
  27.183 +      prev: curState.context,
  27.184 +      tagName: tagName,
  27.185 +      indent: curState.indented,
  27.186 +      startOfLine: startOfLine,
  27.187 +      noIndent: noIndent
  27.188 +    };
  27.189 +  }
  27.190 +  function popContext() {
  27.191 +    if (curState.context) curState.context = curState.context.prev;
  27.192 +  }
  27.193 +
  27.194 +  function element(type) {
  27.195 +    if (type == "openTag") {
  27.196 +      curState.tagName = tagName;
  27.197 +      return cont(attributes, endtag(curState.startOfLine));
  27.198 +    } else if (type == "closeTag") {
  27.199 +      var err = false;
  27.200 +      if (curState.context) {
  27.201 +        if (curState.context.tagName != tagName) {
  27.202 +          if (Kludges.implicitlyClosed.hasOwnProperty(curState.context.tagName.toLowerCase())) {
  27.203 +            popContext();
  27.204 +          }
  27.205 +          err = !curState.context || curState.context.tagName != tagName;
  27.206 +        }
  27.207 +      } else {
  27.208 +        err = true;
  27.209 +      }
  27.210 +      if (err) setStyle = "error";
  27.211 +      return cont(endclosetag(err));
  27.212 +    }
  27.213 +    return cont();
  27.214 +  }
  27.215 +  function endtag(startOfLine) {
  27.216 +    return function(type) {
  27.217 +      var tagName = curState.tagName;
  27.218 +      curState.tagName = null;
  27.219 +      if (type == "selfcloseTag" ||
  27.220 +          (type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(tagName.toLowerCase()))) {
  27.221 +        maybePopContext(tagName.toLowerCase());
  27.222 +        return cont();
  27.223 +      }
  27.224 +      if (type == "endTag") {
  27.225 +        maybePopContext(tagName.toLowerCase());
  27.226 +        pushContext(tagName, startOfLine);
  27.227 +        return cont();
  27.228 +      }
  27.229 +      return cont();
  27.230 +    };
  27.231 +  }
  27.232 +  function endclosetag(err) {
  27.233 +    return function(type) {
  27.234 +      if (err) setStyle = "error";
  27.235 +      if (type == "endTag") { popContext(); return cont(); }
  27.236 +      setStyle = "error";
  27.237 +      return cont(arguments.callee);
  27.238 +    };
  27.239 +  }
  27.240 +  function maybePopContext(nextTagName) {
  27.241 +    var parentTagName;
  27.242 +    while (true) {
  27.243 +      if (!curState.context) {
  27.244 +        return;
  27.245 +      }
  27.246 +      parentTagName = curState.context.tagName.toLowerCase();
  27.247 +      if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) ||
  27.248 +          !Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
  27.249 +        return;
  27.250 +      }
  27.251 +      popContext();
  27.252 +    }
  27.253 +  }
  27.254 +
  27.255 +  function attributes(type) {
  27.256 +    if (type == "word") {setStyle = "attribute"; return cont(attribute, attributes);}
  27.257 +    if (type == "endTag" || type == "selfcloseTag") return pass();
  27.258 +    setStyle = "error";
  27.259 +    return cont(attributes);
  27.260 +  }
  27.261 +  function attribute(type) {
  27.262 +    if (type == "equals") return cont(attvalue, attributes);
  27.263 +    if (!Kludges.allowMissing) setStyle = "error";
  27.264 +    else if (type == "word") setStyle = "attribute";
  27.265 +    return (type == "endTag" || type == "selfcloseTag") ? pass() : cont();
  27.266 +  }
  27.267 +  function attvalue(type) {
  27.268 +    if (type == "string") return cont(attvaluemaybe);
  27.269 +    if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();}
  27.270 +    setStyle = "error";
  27.271 +    return (type == "endTag" || type == "selfCloseTag") ? pass() : cont();
  27.272 +  }
  27.273 +  function attvaluemaybe(type) {
  27.274 +    if (type == "string") return cont(attvaluemaybe);
  27.275 +    else return pass();
  27.276 +  }
  27.277 +
  27.278 +  return {
  27.279 +    startState: function() {
  27.280 +      return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null};
  27.281 +    },
  27.282 +
  27.283 +    token: function(stream, state) {
  27.284 +      if (stream.sol()) {
  27.285 +        state.startOfLine = true;
  27.286 +        state.indented = stream.indentation();
  27.287 +      }
  27.288 +      if (stream.eatSpace()) return null;
  27.289 +
  27.290 +      setStyle = type = tagName = null;
  27.291 +      var style = state.tokenize(stream, state);
  27.292 +      state.type = type;
  27.293 +      if ((style || type) && style != "comment") {
  27.294 +        curState = state;
  27.295 +        while (true) {
  27.296 +          var comb = state.cc.pop() || element;
  27.297 +          if (comb(type || style)) break;
  27.298 +        }
  27.299 +      }
  27.300 +      state.startOfLine = false;
  27.301 +      return setStyle || style;
  27.302 +    },
  27.303 +
  27.304 +    indent: function(state, textAfter, fullLine) {
  27.305 +      var context = state.context;
  27.306 +      if ((state.tokenize != inTag && state.tokenize != inText) ||
  27.307 +          context && context.noIndent)
  27.308 +        return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
  27.309 +      if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
  27.310 +      if (context && /^<\//.test(textAfter))
  27.311 +        context = context.prev;
  27.312 +      while (context && !context.startOfLine)
  27.313 +        context = context.prev;
  27.314 +      if (context) return context.indent + indentUnit;
  27.315 +      else return 0;
  27.316 +    },
  27.317 +
  27.318 +    electricChars: "/",
  27.319 +
  27.320 +    configuration: parserConfig.htmlMode ? "html" : "xml"
  27.321 +  };
  27.322 +});
  27.323 +
  27.324 +CodeMirror.defineMIME("text/xml", "xml");
  27.325 +CodeMirror.defineMIME("application/xml", "xml");
  27.326 +if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
  27.327 +  CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/theme/elegant.css	Sun Feb 03 07:48:42 2013 +0100
    28.3 @@ -0,0 +1,10 @@
    28.4 +.cm-s-elegant span.cm-number, .cm-s-elegant span.cm-string, .cm-s-elegant span.cm-atom {color: #762;}
    28.5 +.cm-s-elegant span.cm-comment {color: #262; font-style: italic; line-height: 1em;}
    28.6 +.cm-s-elegant span.cm-meta {color: #555; font-style: italic; line-height: 1em;}
    28.7 +.cm-s-elegant span.cm-variable {color: black;}
    28.8 +.cm-s-elegant span.cm-variable-2 {color: #b11;}
    28.9 +.cm-s-elegant span.cm-qualifier {color: #555;}
   28.10 +.cm-s-elegant span.cm-keyword {color: #730;}
   28.11 +.cm-s-elegant span.cm-builtin {color: #30a;}
   28.12 +.cm-s-elegant span.cm-error {background-color: #fdd;}
   28.13 +.cm-s-elegant span.cm-link {color: #762;}
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/dew/src/test/java/org/apidesign/bck2brwsr/dew/CompileTest.java	Sun Feb 03 07:48:42 2013 +0100
    29.3 @@ -0,0 +1,45 @@
    29.4 +/**
    29.5 + * Back 2 Browser Bytecode Translator
    29.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    29.7 + *
    29.8 + * This program is free software: you can redistribute it and/or modify
    29.9 + * it under the terms of the GNU General Public License as published by
   29.10 + * the Free Software Foundation, version 2 of the License.
   29.11 + *
   29.12 + * This program is distributed in the hope that it will be useful,
   29.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   29.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   29.15 + * GNU General Public License for more details.
   29.16 + *
   29.17 + * You should have received a copy of the GNU General Public License
   29.18 + * along with this program. Look for COPYING file in the top folder.
   29.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   29.20 + */
   29.21 +package org.apidesign.bck2brwsr.dew;
   29.22 +
   29.23 +import java.io.IOException;
   29.24 +import static org.testng.Assert.*;
   29.25 +import org.testng.annotations.Test;
   29.26 +
   29.27 +/**
   29.28 + *
   29.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   29.30 + */
   29.31 +public class CompileTest  {
   29.32 +    @Test public void testCompile() throws IOException {
   29.33 +        String html = "<html><body>"
   29.34 +                + " <button id='btn'>Hello!</button>"
   29.35 +                + "</body></html>";
   29.36 +        String java = "package x.y.z;"
   29.37 +                + "import org.apidesign.bck2brwsr.htmlpage.api.*;"
   29.38 +                + "import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;"
   29.39 +            + "@Page(xhtml=\"index.html\", className=\"Index\")"
   29.40 +            + "class X { "
   29.41 +            + "   @On(event=CLICK, id=\"btn\") static void clcs() {}"
   29.42 +            + "}";
   29.43 +        Compile result = Compile.create(html, java);
   29.44 +
   29.45 +        assertNotNull(result.get("x/y/z/X.class"), "Class X is compiled: " + result);
   29.46 +        assertNotNull(result.get("x/y/z/Index.class"), "Class Index is compiled: " + result);
   29.47 +    }
   29.48 +}
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/emul/compact/pom.xml	Sun Feb 03 07:48:42 2013 +0100
    30.3 @@ -0,0 +1,47 @@
    30.4 +<?xml version="1.0"?>
    30.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"
    30.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    30.7 +  <modelVersion>4.0.0</modelVersion>
    30.8 +  <parent>
    30.9 +    <groupId>org.apidesign.bck2brwsr</groupId>
   30.10 +    <artifactId>emul.pom</artifactId>
   30.11 +    <version>0.3-SNAPSHOT</version>
   30.12 +  </parent>
   30.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
   30.14 +  <artifactId>emul</artifactId>
   30.15 +  <version>0.3-SNAPSHOT</version>
   30.16 +  <name>Compact API Profile</name>
   30.17 +  <url>http://maven.apache.org</url>
   30.18 +  <properties>
   30.19 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   30.20 +  </properties>
   30.21 +  <dependencies>
   30.22 +    <dependency>
   30.23 +      <groupId>${project.groupId}</groupId>
   30.24 +      <artifactId>emul.mini</artifactId>
   30.25 +      <version>${project.version}</version>
   30.26 +    </dependency>
   30.27 +    <dependency>
   30.28 +      <groupId>${project.groupId}</groupId>
   30.29 +      <artifactId>vmtest</artifactId>
   30.30 +      <version>${project.version}</version>
   30.31 +      <scope>test</scope>
   30.32 +    </dependency>
   30.33 +  </dependencies>
   30.34 +  <build>
   30.35 +      <plugins>
   30.36 +          <plugin>
   30.37 +              <groupId>org.apache.maven.plugins</groupId>
   30.38 +              <artifactId>maven-compiler-plugin</artifactId>
   30.39 +              <version>2.5.1</version>
   30.40 +              <configuration>
   30.41 +                  <compilerArguments>
   30.42 +                      <bootclasspath>netbeans.ignore.jdk.bootclasspath</bootclasspath>
   30.43 +                  </compilerArguments>
   30.44 +                 <source>1.7</source>
   30.45 +                 <target>1.7</target>
   30.46 +              </configuration>
   30.47 +          </plugin>
   30.48 +      </plugins>
   30.49 +  </build>
   30.50 +</project>
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/emul/compact/src/main/java/java/io/BufferedReader.java	Sun Feb 03 07:48:42 2013 +0100
    31.3 @@ -0,0 +1,523 @@
    31.4 +/*
    31.5 + * Copyright (c) 1996, 2011, 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.io;
   31.30 +
   31.31 +
   31.32 +
   31.33 +/**
   31.34 + * Reads text from a character-input stream, buffering characters so as to
   31.35 + * provide for the efficient reading of characters, arrays, and lines.
   31.36 + *
   31.37 + * <p> The buffer size may be specified, or the default size may be used.  The
   31.38 + * default is large enough for most purposes.
   31.39 + *
   31.40 + * <p> In general, each read request made of a Reader causes a corresponding
   31.41 + * read request to be made of the underlying character or byte stream.  It is
   31.42 + * therefore advisable to wrap a BufferedReader around any Reader whose read()
   31.43 + * operations may be costly, such as FileReaders and InputStreamReaders.  For
   31.44 + * example,
   31.45 + *
   31.46 + * <pre>
   31.47 + * BufferedReader in
   31.48 + *   = new BufferedReader(new FileReader("foo.in"));
   31.49 + * </pre>
   31.50 + *
   31.51 + * will buffer the input from the specified file.  Without buffering, each
   31.52 + * invocation of read() or readLine() could cause bytes to be read from the
   31.53 + * file, converted into characters, and then returned, which can be very
   31.54 + * inefficient.
   31.55 + *
   31.56 + * <p> Programs that use DataInputStreams for textual input can be localized by
   31.57 + * replacing each DataInputStream with an appropriate BufferedReader.
   31.58 + *
   31.59 + * @see FileReader
   31.60 + * @see InputStreamReader
   31.61 + * @see java.nio.file.Files#newBufferedReader
   31.62 + *
   31.63 + * @author      Mark Reinhold
   31.64 + * @since       JDK1.1
   31.65 + */
   31.66 +
   31.67 +public class BufferedReader extends Reader {
   31.68 +
   31.69 +    private Reader in;
   31.70 +
   31.71 +    private char cb[];
   31.72 +    private int nChars, nextChar;
   31.73 +
   31.74 +    private static final int INVALIDATED = -2;
   31.75 +    private static final int UNMARKED = -1;
   31.76 +    private int markedChar = UNMARKED;
   31.77 +    private int readAheadLimit = 0; /* Valid only when markedChar > 0 */
   31.78 +
   31.79 +    /** If the next character is a line feed, skip it */
   31.80 +    private boolean skipLF = false;
   31.81 +
   31.82 +    /** The skipLF flag when the mark was set */
   31.83 +    private boolean markedSkipLF = false;
   31.84 +
   31.85 +    private static int defaultCharBufferSize = 8192;
   31.86 +    private static int defaultExpectedLineLength = 80;
   31.87 +
   31.88 +    /**
   31.89 +     * Creates a buffering character-input stream that uses an input buffer of
   31.90 +     * the specified size.
   31.91 +     *
   31.92 +     * @param  in   A Reader
   31.93 +     * @param  sz   Input-buffer size
   31.94 +     *
   31.95 +     * @exception  IllegalArgumentException  If sz is <= 0
   31.96 +     */
   31.97 +    public BufferedReader(Reader in, int sz) {
   31.98 +        super(in);
   31.99 +        if (sz <= 0)
  31.100 +            throw new IllegalArgumentException("Buffer size <= 0");
  31.101 +        this.in = in;
  31.102 +        cb = new char[sz];
  31.103 +        nextChar = nChars = 0;
  31.104 +    }
  31.105 +
  31.106 +    /**
  31.107 +     * Creates a buffering character-input stream that uses a default-sized
  31.108 +     * input buffer.
  31.109 +     *
  31.110 +     * @param  in   A Reader
  31.111 +     */
  31.112 +    public BufferedReader(Reader in) {
  31.113 +        this(in, defaultCharBufferSize);
  31.114 +    }
  31.115 +
  31.116 +    /** Checks to make sure that the stream has not been closed */
  31.117 +    private void ensureOpen() throws IOException {
  31.118 +        if (in == null)
  31.119 +            throw new IOException("Stream closed");
  31.120 +    }
  31.121 +
  31.122 +    /**
  31.123 +     * Fills the input buffer, taking the mark into account if it is valid.
  31.124 +     */
  31.125 +    private void fill() throws IOException {
  31.126 +        int dst;
  31.127 +        if (markedChar <= UNMARKED) {
  31.128 +            /* No mark */
  31.129 +            dst = 0;
  31.130 +        } else {
  31.131 +            /* Marked */
  31.132 +            int delta = nextChar - markedChar;
  31.133 +            if (delta >= readAheadLimit) {
  31.134 +                /* Gone past read-ahead limit: Invalidate mark */
  31.135 +                markedChar = INVALIDATED;
  31.136 +                readAheadLimit = 0;
  31.137 +                dst = 0;
  31.138 +            } else {
  31.139 +                if (readAheadLimit <= cb.length) {
  31.140 +                    /* Shuffle in the current buffer */
  31.141 +                    System.arraycopy(cb, markedChar, cb, 0, delta);
  31.142 +                    markedChar = 0;
  31.143 +                    dst = delta;
  31.144 +                } else {
  31.145 +                    /* Reallocate buffer to accommodate read-ahead limit */
  31.146 +                    char ncb[] = new char[readAheadLimit];
  31.147 +                    System.arraycopy(cb, markedChar, ncb, 0, delta);
  31.148 +                    cb = ncb;
  31.149 +                    markedChar = 0;
  31.150 +                    dst = delta;
  31.151 +                }
  31.152 +                nextChar = nChars = delta;
  31.153 +            }
  31.154 +        }
  31.155 +
  31.156 +        int n;
  31.157 +        do {
  31.158 +            n = in.read(cb, dst, cb.length - dst);
  31.159 +        } while (n == 0);
  31.160 +        if (n > 0) {
  31.161 +            nChars = dst + n;
  31.162 +            nextChar = dst;
  31.163 +        }
  31.164 +    }
  31.165 +
  31.166 +    /**
  31.167 +     * Reads a single character.
  31.168 +     *
  31.169 +     * @return The character read, as an integer in the range
  31.170 +     *         0 to 65535 (<tt>0x00-0xffff</tt>), or -1 if the
  31.171 +     *         end of the stream has been reached
  31.172 +     * @exception  IOException  If an I/O error occurs
  31.173 +     */
  31.174 +    public int read() throws IOException {
  31.175 +        synchronized (lock) {
  31.176 +            ensureOpen();
  31.177 +            for (;;) {
  31.178 +                if (nextChar >= nChars) {
  31.179 +                    fill();
  31.180 +                    if (nextChar >= nChars)
  31.181 +                        return -1;
  31.182 +                }
  31.183 +                if (skipLF) {
  31.184 +                    skipLF = false;
  31.185 +                    if (cb[nextChar] == '\n') {
  31.186 +                        nextChar++;
  31.187 +                        continue;
  31.188 +                    }
  31.189 +                }
  31.190 +                return cb[nextChar++];
  31.191 +            }
  31.192 +        }
  31.193 +    }
  31.194 +
  31.195 +    /**
  31.196 +     * Reads characters into a portion of an array, reading from the underlying
  31.197 +     * stream if necessary.
  31.198 +     */
  31.199 +    private int read1(char[] cbuf, int off, int len) throws IOException {
  31.200 +        if (nextChar >= nChars) {
  31.201 +            /* If the requested length is at least as large as the buffer, and
  31.202 +               if there is no mark/reset activity, and if line feeds are not
  31.203 +               being skipped, do not bother to copy the characters into the
  31.204 +               local buffer.  In this way buffered streams will cascade
  31.205 +               harmlessly. */
  31.206 +            if (len >= cb.length && markedChar <= UNMARKED && !skipLF) {
  31.207 +                return in.read(cbuf, off, len);
  31.208 +            }
  31.209 +            fill();
  31.210 +        }
  31.211 +        if (nextChar >= nChars) return -1;
  31.212 +        if (skipLF) {
  31.213 +            skipLF = false;
  31.214 +            if (cb[nextChar] == '\n') {
  31.215 +                nextChar++;
  31.216 +                if (nextChar >= nChars)
  31.217 +                    fill();
  31.218 +                if (nextChar >= nChars)
  31.219 +                    return -1;
  31.220 +            }
  31.221 +        }
  31.222 +        int n = Math.min(len, nChars - nextChar);
  31.223 +        System.arraycopy(cb, nextChar, cbuf, off, n);
  31.224 +        nextChar += n;
  31.225 +        return n;
  31.226 +    }
  31.227 +
  31.228 +    /**
  31.229 +     * Reads characters into a portion of an array.
  31.230 +     *
  31.231 +     * <p> This method implements the general contract of the corresponding
  31.232 +     * <code>{@link Reader#read(char[], int, int) read}</code> method of the
  31.233 +     * <code>{@link Reader}</code> class.  As an additional convenience, it
  31.234 +     * attempts to read as many characters as possible by repeatedly invoking
  31.235 +     * the <code>read</code> method of the underlying stream.  This iterated
  31.236 +     * <code>read</code> continues until one of the following conditions becomes
  31.237 +     * true: <ul>
  31.238 +     *
  31.239 +     *   <li> The specified number of characters have been read,
  31.240 +     *
  31.241 +     *   <li> The <code>read</code> method of the underlying stream returns
  31.242 +     *   <code>-1</code>, indicating end-of-file, or
  31.243 +     *
  31.244 +     *   <li> The <code>ready</code> method of the underlying stream
  31.245 +     *   returns <code>false</code>, indicating that further input requests
  31.246 +     *   would block.
  31.247 +     *
  31.248 +     * </ul> If the first <code>read</code> on the underlying stream returns
  31.249 +     * <code>-1</code> to indicate end-of-file then this method returns
  31.250 +     * <code>-1</code>.  Otherwise this method returns the number of characters
  31.251 +     * actually read.
  31.252 +     *
  31.253 +     * <p> Subclasses of this class are encouraged, but not required, to
  31.254 +     * attempt to read as many characters as possible in the same fashion.
  31.255 +     *
  31.256 +     * <p> Ordinarily this method takes characters from this stream's character
  31.257 +     * buffer, filling it from the underlying stream as necessary.  If,
  31.258 +     * however, the buffer is empty, the mark is not valid, and the requested
  31.259 +     * length is at least as large as the buffer, then this method will read
  31.260 +     * characters directly from the underlying stream into the given array.
  31.261 +     * Thus redundant <code>BufferedReader</code>s will not copy data
  31.262 +     * unnecessarily.
  31.263 +     *
  31.264 +     * @param      cbuf  Destination buffer
  31.265 +     * @param      off   Offset at which to start storing characters
  31.266 +     * @param      len   Maximum number of characters to read
  31.267 +     *
  31.268 +     * @return     The number of characters read, or -1 if the end of the
  31.269 +     *             stream has been reached
  31.270 +     *
  31.271 +     * @exception  IOException  If an I/O error occurs
  31.272 +     */
  31.273 +    public int read(char cbuf[], int off, int len) throws IOException {
  31.274 +        synchronized (lock) {
  31.275 +            ensureOpen();
  31.276 +            if ((off < 0) || (off > cbuf.length) || (len < 0) ||
  31.277 +                ((off + len) > cbuf.length) || ((off + len) < 0)) {
  31.278 +                throw new IndexOutOfBoundsException();
  31.279 +            } else if (len == 0) {
  31.280 +                return 0;
  31.281 +            }
  31.282 +
  31.283 +            int n = read1(cbuf, off, len);
  31.284 +            if (n <= 0) return n;
  31.285 +            while ((n < len) && in.ready()) {
  31.286 +                int n1 = read1(cbuf, off + n, len - n);
  31.287 +                if (n1 <= 0) break;
  31.288 +                n += n1;
  31.289 +            }
  31.290 +            return n;
  31.291 +        }
  31.292 +    }
  31.293 +
  31.294 +    /**
  31.295 +     * Reads a line of text.  A line is considered to be terminated by any one
  31.296 +     * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
  31.297 +     * followed immediately by a linefeed.
  31.298 +     *
  31.299 +     * @param      ignoreLF  If true, the next '\n' will be skipped
  31.300 +     *
  31.301 +     * @return     A String containing the contents of the line, not including
  31.302 +     *             any line-termination characters, or null if the end of the
  31.303 +     *             stream has been reached
  31.304 +     *
  31.305 +     * @see        java.io.LineNumberReader#readLine()
  31.306 +     *
  31.307 +     * @exception  IOException  If an I/O error occurs
  31.308 +     */
  31.309 +    String readLine(boolean ignoreLF) throws IOException {
  31.310 +        StringBuffer s = null;
  31.311 +        int startChar;
  31.312 +
  31.313 +        synchronized (lock) {
  31.314 +            ensureOpen();
  31.315 +            boolean omitLF = ignoreLF || skipLF;
  31.316 +
  31.317 +        bufferLoop:
  31.318 +            for (;;) {
  31.319 +
  31.320 +                if (nextChar >= nChars)
  31.321 +                    fill();
  31.322 +                if (nextChar >= nChars) { /* EOF */
  31.323 +                    if (s != null && s.length() > 0)
  31.324 +                        return s.toString();
  31.325 +                    else
  31.326 +                        return null;
  31.327 +                }
  31.328 +                boolean eol = false;
  31.329 +                char c = 0;
  31.330 +                int i;
  31.331 +
  31.332 +                /* Skip a leftover '\n', if necessary */
  31.333 +                if (omitLF && (cb[nextChar] == '\n'))
  31.334 +                    nextChar++;
  31.335 +                skipLF = false;
  31.336 +                omitLF = false;
  31.337 +
  31.338 +            charLoop:
  31.339 +                for (i = nextChar; i < nChars; i++) {
  31.340 +                    c = cb[i];
  31.341 +                    if ((c == '\n') || (c == '\r')) {
  31.342 +                        eol = true;
  31.343 +                        break charLoop;
  31.344 +                    }
  31.345 +                }
  31.346 +
  31.347 +                startChar = nextChar;
  31.348 +                nextChar = i;
  31.349 +
  31.350 +                if (eol) {
  31.351 +                    String str;
  31.352 +                    if (s == null) {
  31.353 +                        str = new String(cb, startChar, i - startChar);
  31.354 +                    } else {
  31.355 +                        s.append(cb, startChar, i - startChar);
  31.356 +                        str = s.toString();
  31.357 +                    }
  31.358 +                    nextChar++;
  31.359 +                    if (c == '\r') {
  31.360 +                        skipLF = true;
  31.361 +                    }
  31.362 +                    return str;
  31.363 +                }
  31.364 +
  31.365 +                if (s == null)
  31.366 +                    s = new StringBuffer(defaultExpectedLineLength);
  31.367 +                s.append(cb, startChar, i - startChar);
  31.368 +            }
  31.369 +        }
  31.370 +    }
  31.371 +
  31.372 +    /**
  31.373 +     * Reads a line of text.  A line is considered to be terminated by any one
  31.374 +     * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
  31.375 +     * followed immediately by a linefeed.
  31.376 +     *
  31.377 +     * @return     A String containing the contents of the line, not including
  31.378 +     *             any line-termination characters, or null if the end of the
  31.379 +     *             stream has been reached
  31.380 +     *
  31.381 +     * @exception  IOException  If an I/O error occurs
  31.382 +     *
  31.383 +     * @see java.nio.file.Files#readAllLines
  31.384 +     */
  31.385 +    public String readLine() throws IOException {
  31.386 +        return readLine(false);
  31.387 +    }
  31.388 +
  31.389 +    /**
  31.390 +     * Skips characters.
  31.391 +     *
  31.392 +     * @param  n  The number of characters to skip
  31.393 +     *
  31.394 +     * @return    The number of characters actually skipped
  31.395 +     *
  31.396 +     * @exception  IllegalArgumentException  If <code>n</code> is negative.
  31.397 +     * @exception  IOException  If an I/O error occurs
  31.398 +     */
  31.399 +    public long skip(long n) throws IOException {
  31.400 +        if (n < 0L) {
  31.401 +            throw new IllegalArgumentException("skip value is negative");
  31.402 +        }
  31.403 +        synchronized (lock) {
  31.404 +            ensureOpen();
  31.405 +            long r = n;
  31.406 +            while (r > 0) {
  31.407 +                if (nextChar >= nChars)
  31.408 +                    fill();
  31.409 +                if (nextChar >= nChars) /* EOF */
  31.410 +                    break;
  31.411 +                if (skipLF) {
  31.412 +                    skipLF = false;
  31.413 +                    if (cb[nextChar] == '\n') {
  31.414 +                        nextChar++;
  31.415 +                    }
  31.416 +                }
  31.417 +                long d = nChars - nextChar;
  31.418 +                if (r <= d) {
  31.419 +                    nextChar += r;
  31.420 +                    r = 0;
  31.421 +                    break;
  31.422 +                }
  31.423 +                else {
  31.424 +                    r -= d;
  31.425 +                    nextChar = nChars;
  31.426 +                }
  31.427 +            }
  31.428 +            return n - r;
  31.429 +        }
  31.430 +    }
  31.431 +
  31.432 +    /**
  31.433 +     * Tells whether this stream is ready to be read.  A buffered character
  31.434 +     * stream is ready if the buffer is not empty, or if the underlying
  31.435 +     * character stream is ready.
  31.436 +     *
  31.437 +     * @exception  IOException  If an I/O error occurs
  31.438 +     */
  31.439 +    public boolean ready() throws IOException {
  31.440 +        synchronized (lock) {
  31.441 +            ensureOpen();
  31.442 +
  31.443 +            /*
  31.444 +             * If newline needs to be skipped and the next char to be read
  31.445 +             * is a newline character, then just skip it right away.
  31.446 +             */
  31.447 +            if (skipLF) {
  31.448 +                /* Note that in.ready() will return true if and only if the next
  31.449 +                 * read on the stream will not block.
  31.450 +                 */
  31.451 +                if (nextChar >= nChars && in.ready()) {
  31.452 +                    fill();
  31.453 +                }
  31.454 +                if (nextChar < nChars) {
  31.455 +                    if (cb[nextChar] == '\n')
  31.456 +                        nextChar++;
  31.457 +                    skipLF = false;
  31.458 +                }
  31.459 +            }
  31.460 +            return (nextChar < nChars) || in.ready();
  31.461 +        }
  31.462 +    }
  31.463 +
  31.464 +    /**
  31.465 +     * Tells whether this stream supports the mark() operation, which it does.
  31.466 +     */
  31.467 +    public boolean markSupported() {
  31.468 +        return true;
  31.469 +    }
  31.470 +
  31.471 +    /**
  31.472 +     * Marks the present position in the stream.  Subsequent calls to reset()
  31.473 +     * will attempt to reposition the stream to this point.
  31.474 +     *
  31.475 +     * @param readAheadLimit   Limit on the number of characters that may be
  31.476 +     *                         read while still preserving the mark. An attempt
  31.477 +     *                         to reset the stream after reading characters
  31.478 +     *                         up to this limit or beyond may fail.
  31.479 +     *                         A limit value larger than the size of the input
  31.480 +     *                         buffer will cause a new buffer to be allocated
  31.481 +     *                         whose size is no smaller than limit.
  31.482 +     *                         Therefore large values should be used with care.
  31.483 +     *
  31.484 +     * @exception  IllegalArgumentException  If readAheadLimit is < 0
  31.485 +     * @exception  IOException  If an I/O error occurs
  31.486 +     */
  31.487 +    public void mark(int readAheadLimit) throws IOException {
  31.488 +        if (readAheadLimit < 0) {
  31.489 +            throw new IllegalArgumentException("Read-ahead limit < 0");
  31.490 +        }
  31.491 +        synchronized (lock) {
  31.492 +            ensureOpen();
  31.493 +            this.readAheadLimit = readAheadLimit;
  31.494 +            markedChar = nextChar;
  31.495 +            markedSkipLF = skipLF;
  31.496 +        }
  31.497 +    }
  31.498 +
  31.499 +    /**
  31.500 +     * Resets the stream to the most recent mark.
  31.501 +     *
  31.502 +     * @exception  IOException  If the stream has never been marked,
  31.503 +     *                          or if the mark has been invalidated
  31.504 +     */
  31.505 +    public void reset() throws IOException {
  31.506 +        synchronized (lock) {
  31.507 +            ensureOpen();
  31.508 +            if (markedChar < 0)
  31.509 +                throw new IOException((markedChar == INVALIDATED)
  31.510 +                                      ? "Mark invalid"
  31.511 +                                      : "Stream not marked");
  31.512 +            nextChar = markedChar;
  31.513 +            skipLF = markedSkipLF;
  31.514 +        }
  31.515 +    }
  31.516 +
  31.517 +    public void close() throws IOException {
  31.518 +        synchronized (lock) {
  31.519 +            if (in == null)
  31.520 +                return;
  31.521 +            in.close();
  31.522 +            in = null;
  31.523 +            cb = null;
  31.524 +        }
  31.525 +    }
  31.526 +}
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/emul/compact/src/main/java/java/io/InputStreamReader.java	Sun Feb 03 07:48:42 2013 +0100
    32.3 @@ -0,0 +1,230 @@
    32.4 +/*
    32.5 + * Copyright (c) 1996, 2005, 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.io;
   32.30 +
   32.31 +
   32.32 +/**
   32.33 + * An InputStreamReader is a bridge from byte streams to character streams: It
   32.34 + * reads bytes and decodes them into characters using a specified {@link
   32.35 + * java.nio.charset.Charset <code>charset</code>}.  The charset that it uses
   32.36 + * may be specified by name or may be given explicitly, or the platform's
   32.37 + * default charset may be accepted.
   32.38 + *
   32.39 + * <p> Each invocation of one of an InputStreamReader's read() methods may
   32.40 + * cause one or more bytes to be read from the underlying byte-input stream.
   32.41 + * To enable the efficient conversion of bytes to characters, more bytes may
   32.42 + * be read ahead from the underlying stream than are necessary to satisfy the
   32.43 + * current read operation.
   32.44 + *
   32.45 + * <p> For top efficiency, consider wrapping an InputStreamReader within a
   32.46 + * BufferedReader.  For example:
   32.47 + *
   32.48 + * <pre>
   32.49 + * BufferedReader in
   32.50 + *   = new BufferedReader(new InputStreamReader(System.in));
   32.51 + * </pre>
   32.52 + *
   32.53 + * @see BufferedReader
   32.54 + * @see InputStream
   32.55 + * @see java.nio.charset.Charset
   32.56 + *
   32.57 + * @author      Mark Reinhold
   32.58 + * @since       JDK1.1
   32.59 + */
   32.60 +
   32.61 +public class InputStreamReader extends Reader {
   32.62 +
   32.63 +    /**
   32.64 +     * Creates an InputStreamReader that uses the default charset.
   32.65 +     *
   32.66 +     * @param  in   An InputStream
   32.67 +     */
   32.68 +    public InputStreamReader(InputStream in) {
   32.69 +        super(in);
   32.70 +    }
   32.71 +
   32.72 +    /**
   32.73 +     * Creates an InputStreamReader that uses the named charset.
   32.74 +     *
   32.75 +     * @param  in
   32.76 +     *         An InputStream
   32.77 +     *
   32.78 +     * @param  charsetName
   32.79 +     *         The name of a supported
   32.80 +     *         {@link java.nio.charset.Charset </code>charset<code>}
   32.81 +     *
   32.82 +     * @exception  UnsupportedEncodingException
   32.83 +     *             If the named charset is not supported
   32.84 +     */
   32.85 +    public InputStreamReader(InputStream in, String charsetName)
   32.86 +        throws UnsupportedEncodingException
   32.87 +    {
   32.88 +        super(in);
   32.89 +        if (!charsetName.toUpperCase().equals("UTF-8")) {
   32.90 +            throw new UnsupportedEncodingException(charsetName);
   32.91 +        }
   32.92 +    }
   32.93 +
   32.94 +    /**
   32.95 +     * Creates an InputStreamReader that uses the given charset. </p>
   32.96 +     *
   32.97 +     * @param  in       An InputStream
   32.98 +     * @param  cs       A charset
   32.99 +     *
  32.100 +     * @since 1.4
  32.101 +     * @spec JSR-51
  32.102 +     */
  32.103 +/* XXX:
  32.104 +    public InputStreamReader(InputStream in, Charset cs) {
  32.105 +        super(in);
  32.106 +        if (cs == null)
  32.107 +            throw new NullPointerException("charset");
  32.108 +        sd = StreamDecoder.forInputStreamReader(in, this, cs);
  32.109 +    }
  32.110 +*/
  32.111 +    /**
  32.112 +     * Creates an InputStreamReader that uses the given charset decoder.  </p>
  32.113 +     *
  32.114 +     * @param  in       An InputStream
  32.115 +     * @param  dec      A charset decoder
  32.116 +     *
  32.117 +     * @since 1.4
  32.118 +     * @spec JSR-51
  32.119 +     */
  32.120 +/* XXX:
  32.121 +    public InputStreamReader(InputStream in, CharsetDecoder dec) {
  32.122 +        super(in);
  32.123 +        if (dec == null)
  32.124 +            throw new NullPointerException("charset decoder");
  32.125 +        sd = StreamDecoder.forInputStreamReader(in, this, dec);
  32.126 +    }
  32.127 +*/
  32.128 +    
  32.129 +    /**
  32.130 +     * Returns the name of the character encoding being used by this stream.
  32.131 +     *
  32.132 +     * <p> If the encoding has an historical name then that name is returned;
  32.133 +     * otherwise the encoding's canonical name is returned.
  32.134 +     *
  32.135 +     * <p> If this instance was created with the {@link
  32.136 +     * #InputStreamReader(InputStream, String)} constructor then the returned
  32.137 +     * name, being unique for the encoding, may differ from the name passed to
  32.138 +     * the constructor. This method will return <code>null</code> if the
  32.139 +     * stream has been closed.
  32.140 +     * </p>
  32.141 +     * @return The historical name of this encoding, or
  32.142 +     *         <code>null</code> if the stream has been closed
  32.143 +     *
  32.144 +     * @see java.nio.charset.Charset
  32.145 +     *
  32.146 +     * @revised 1.4
  32.147 +     * @spec JSR-51
  32.148 +     */
  32.149 +    public String getEncoding() {
  32.150 +        return "UTF-8";
  32.151 +    }
  32.152 +
  32.153 +    /**
  32.154 +     * Reads a single character.
  32.155 +     *
  32.156 +     * @return The character read, or -1 if the end of the stream has been
  32.157 +     *         reached
  32.158 +     *
  32.159 +     * @exception  IOException  If an I/O error occurs
  32.160 +     */
  32.161 +    public int read() throws IOException {
  32.162 +        final InputStream is = (InputStream)lock;
  32.163 +        int c = is.read();
  32.164 +        if (c == -1) {
  32.165 +            return -1;
  32.166 +        }
  32.167 +        c = (int) c & 0xff;
  32.168 +        switch (c >> 4) {
  32.169 +            case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
  32.170 +                /* 0xxxxxxx*/
  32.171 +                return c;
  32.172 +            case 12: case 13: {
  32.173 +                /* 110x xxxx   10xx xxxx*/
  32.174 +                int char2 = (int) is.read();
  32.175 +                if ((char2 & 0xC0) != 0x80)
  32.176 +                    throw new UTFDataFormatException("malformed input");
  32.177 +                return (((c & 0x1F) << 6) | (char2 & 0x3F));
  32.178 +            }
  32.179 +            case 14: {
  32.180 +                /* 1110 xxxx  10xx xxxx  10xx xxxx */
  32.181 +                int char2 = is.read();
  32.182 +                int char3 = is.read();
  32.183 +                if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
  32.184 +                    throw new UTFDataFormatException("malformed input");
  32.185 +                return (((c    & 0x0F) << 12) |
  32.186 +                       ((char2 & 0x3F) << 6)  |
  32.187 +                       ((char3 & 0x3F) << 0));
  32.188 +            }
  32.189 +            default:
  32.190 +                /* 10xx xxxx,  1111 xxxx */
  32.191 +                throw new UTFDataFormatException("malformed input");
  32.192 +        }
  32.193 +    }
  32.194 +    
  32.195 +    /**
  32.196 +     * Reads characters into a portion of an array.
  32.197 +     *
  32.198 +     * @param      cbuf     Destination buffer
  32.199 +     * @param      offset   Offset at which to start storing characters
  32.200 +     * @param      length   Maximum number of characters to read
  32.201 +     *
  32.202 +     * @return     The number of characters read, or -1 if the end of the
  32.203 +     *             stream has been reached
  32.204 +     *
  32.205 +     * @exception  IOException  If an I/O error occurs
  32.206 +     */
  32.207 +    public int read(char cbuf[], int offset, int length) throws IOException {
  32.208 +        for (int i = 0; i < length; i++) {
  32.209 +            int ch = read();
  32.210 +            if (ch == -1) {
  32.211 +                if (i == 0) return -1;
  32.212 +                return i;
  32.213 +            }
  32.214 +            cbuf[offset++] = (char) ch;
  32.215 +        }
  32.216 +        return length;
  32.217 +    }
  32.218 +
  32.219 +    /**
  32.220 +     * Tells whether this stream is ready to be read.  An InputStreamReader is
  32.221 +     * ready if its input buffer is not empty, or if bytes are available to be
  32.222 +     * read from the underlying byte stream.
  32.223 +     *
  32.224 +     * @exception  IOException  If an I/O error occurs
  32.225 +     */
  32.226 +    public boolean ready() throws IOException {
  32.227 +        return ((InputStream)lock).available() > 0;
  32.228 +    }
  32.229 +
  32.230 +    public void close() throws IOException {
  32.231 +        ((InputStream)lock).close();
  32.232 +    }
  32.233 +}
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/emul/compact/src/main/java/java/io/Reader.java	Sun Feb 03 07:48:42 2013 +0100
    33.3 @@ -0,0 +1,262 @@
    33.4 +/*
    33.5 + * Copyright (c) 1996, 2006, 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.io;
   33.30 +
   33.31 +
   33.32 +/**
   33.33 + * Abstract class for reading character streams.  The only methods that a
   33.34 + * subclass must implement are read(char[], int, int) and close().  Most
   33.35 + * subclasses, however, will override some of the methods defined here in order
   33.36 + * to provide higher efficiency, additional functionality, or both.
   33.37 + *
   33.38 + *
   33.39 + * @see BufferedReader
   33.40 + * @see   LineNumberReader
   33.41 + * @see CharArrayReader
   33.42 + * @see InputStreamReader
   33.43 + * @see   FileReader
   33.44 + * @see FilterReader
   33.45 + * @see   PushbackReader
   33.46 + * @see PipedReader
   33.47 + * @see StringReader
   33.48 + * @see Writer
   33.49 + *
   33.50 + * @author      Mark Reinhold
   33.51 + * @since       JDK1.1
   33.52 + */
   33.53 +
   33.54 +public abstract class Reader implements Readable, Closeable {
   33.55 +
   33.56 +    /**
   33.57 +     * The object used to synchronize operations on this stream.  For
   33.58 +     * efficiency, a character-stream object may use an object other than
   33.59 +     * itself to protect critical sections.  A subclass should therefore use
   33.60 +     * the object in this field rather than <tt>this</tt> or a synchronized
   33.61 +     * method.
   33.62 +     */
   33.63 +    protected Object lock;
   33.64 +
   33.65 +    /**
   33.66 +     * Creates a new character-stream reader whose critical sections will
   33.67 +     * synchronize on the reader itself.
   33.68 +     */
   33.69 +    protected Reader() {
   33.70 +        this.lock = this;
   33.71 +    }
   33.72 +
   33.73 +    /**
   33.74 +     * Creates a new character-stream reader whose critical sections will
   33.75 +     * synchronize on the given object.
   33.76 +     *
   33.77 +     * @param lock  The Object to synchronize on.
   33.78 +     */
   33.79 +    protected Reader(Object lock) {
   33.80 +        if (lock == null) {
   33.81 +            throw new NullPointerException();
   33.82 +        }
   33.83 +        this.lock = lock;
   33.84 +    }
   33.85 +
   33.86 +    /**
   33.87 +     * Attempts to read characters into the specified character buffer.
   33.88 +     * The buffer is used as a repository of characters as-is: the only
   33.89 +     * changes made are the results of a put operation. No flipping or
   33.90 +     * rewinding of the buffer is performed.
   33.91 +     *
   33.92 +     * @param target the buffer to read characters into
   33.93 +     * @return The number of characters added to the buffer, or
   33.94 +     *         -1 if this source of characters is at its end
   33.95 +     * @throws IOException if an I/O error occurs
   33.96 +     * @throws NullPointerException if target is null
   33.97 +     * @throws ReadOnlyBufferException if target is a read only buffer
   33.98 +     * @since 1.5
   33.99 +     */
  33.100 +//    public int read(java.nio.CharBuffer target) throws IOException {
  33.101 +//        int len = target.remaining();
  33.102 +//        char[] cbuf = new char[len];
  33.103 +//        int n = read(cbuf, 0, len);
  33.104 +//        if (n > 0)
  33.105 +//            target.put(cbuf, 0, n);
  33.106 +//        return n;
  33.107 +//    }
  33.108 +
  33.109 +    /**
  33.110 +     * Reads a single character.  This method will block until a character is
  33.111 +     * available, an I/O error occurs, or the end of the stream is reached.
  33.112 +     *
  33.113 +     * <p> Subclasses that intend to support efficient single-character input
  33.114 +     * should override this method.
  33.115 +     *
  33.116 +     * @return     The character read, as an integer in the range 0 to 65535
  33.117 +     *             (<tt>0x00-0xffff</tt>), or -1 if the end of the stream has
  33.118 +     *             been reached
  33.119 +     *
  33.120 +     * @exception  IOException  If an I/O error occurs
  33.121 +     */
  33.122 +    public int read() throws IOException {
  33.123 +        char cb[] = new char[1];
  33.124 +        if (read(cb, 0, 1) == -1)
  33.125 +            return -1;
  33.126 +        else
  33.127 +            return cb[0];
  33.128 +    }
  33.129 +
  33.130 +    /**
  33.131 +     * Reads characters into an array.  This method will block until some input
  33.132 +     * is available, an I/O error occurs, or the end of the stream is reached.
  33.133 +     *
  33.134 +     * @param       cbuf  Destination buffer
  33.135 +     *
  33.136 +     * @return      The number of characters read, or -1
  33.137 +     *              if the end of the stream
  33.138 +     *              has been reached
  33.139 +     *
  33.140 +     * @exception   IOException  If an I/O error occurs
  33.141 +     */
  33.142 +    public int read(char cbuf[]) throws IOException {
  33.143 +        return read(cbuf, 0, cbuf.length);
  33.144 +    }
  33.145 +
  33.146 +    /**
  33.147 +     * Reads characters into a portion of an array.  This method will block
  33.148 +     * until some input is available, an I/O error occurs, or the end of the
  33.149 +     * stream is reached.
  33.150 +     *
  33.151 +     * @param      cbuf  Destination buffer
  33.152 +     * @param      off   Offset at which to start storing characters
  33.153 +     * @param      len   Maximum number of characters to read
  33.154 +     *
  33.155 +     * @return     The number of characters read, or -1 if the end of the
  33.156 +     *             stream has been reached
  33.157 +     *
  33.158 +     * @exception  IOException  If an I/O error occurs
  33.159 +     */
  33.160 +    abstract public int read(char cbuf[], int off, int len) throws IOException;
  33.161 +
  33.162 +    /** Maximum skip-buffer size */
  33.163 +    private static final int maxSkipBufferSize = 8192;
  33.164 +
  33.165 +    /** Skip buffer, null until allocated */
  33.166 +    private char skipBuffer[] = null;
  33.167 +
  33.168 +    /**
  33.169 +     * Skips characters.  This method will block until some characters are
  33.170 +     * available, an I/O error occurs, or the end of the stream is reached.
  33.171 +     *
  33.172 +     * @param  n  The number of characters to skip
  33.173 +     *
  33.174 +     * @return    The number of characters actually skipped
  33.175 +     *
  33.176 +     * @exception  IllegalArgumentException  If <code>n</code> is negative.
  33.177 +     * @exception  IOException  If an I/O error occurs
  33.178 +     */
  33.179 +    public long skip(long n) throws IOException {
  33.180 +        if (n < 0L)
  33.181 +            throw new IllegalArgumentException("skip value is negative");
  33.182 +        int nn = (int) Math.min(n, maxSkipBufferSize);
  33.183 +        synchronized (lock) {
  33.184 +            if ((skipBuffer == null) || (skipBuffer.length < nn))
  33.185 +                skipBuffer = new char[nn];
  33.186 +            long r = n;
  33.187 +            while (r > 0) {
  33.188 +                int nc = read(skipBuffer, 0, (int)Math.min(r, nn));
  33.189 +                if (nc == -1)
  33.190 +                    break;
  33.191 +                r -= nc;
  33.192 +            }
  33.193 +            return n - r;
  33.194 +        }
  33.195 +    }
  33.196 +
  33.197 +    /**
  33.198 +     * Tells whether this stream is ready to be read.
  33.199 +     *
  33.200 +     * @return True if the next read() is guaranteed not to block for input,
  33.201 +     * false otherwise.  Note that returning false does not guarantee that the
  33.202 +     * next read will block.
  33.203 +     *
  33.204 +     * @exception  IOException  If an I/O error occurs
  33.205 +     */
  33.206 +    public boolean ready() throws IOException {
  33.207 +        return false;
  33.208 +    }
  33.209 +
  33.210 +    /**
  33.211 +     * Tells whether this stream supports the mark() operation. The default
  33.212 +     * implementation always returns false. Subclasses should override this
  33.213 +     * method.
  33.214 +     *
  33.215 +     * @return true if and only if this stream supports the mark operation.
  33.216 +     */
  33.217 +    public boolean markSupported() {
  33.218 +        return false;
  33.219 +    }
  33.220 +
  33.221 +    /**
  33.222 +     * Marks the present position in the stream.  Subsequent calls to reset()
  33.223 +     * will attempt to reposition the stream to this point.  Not all
  33.224 +     * character-input streams support the mark() operation.
  33.225 +     *
  33.226 +     * @param  readAheadLimit  Limit on the number of characters that may be
  33.227 +     *                         read while still preserving the mark.  After
  33.228 +     *                         reading this many characters, attempting to
  33.229 +     *                         reset the stream may fail.
  33.230 +     *
  33.231 +     * @exception  IOException  If the stream does not support mark(),
  33.232 +     *                          or if some other I/O error occurs
  33.233 +     */
  33.234 +    public void mark(int readAheadLimit) throws IOException {
  33.235 +        throw new IOException("mark() not supported");
  33.236 +    }
  33.237 +
  33.238 +    /**
  33.239 +     * Resets the stream.  If the stream has been marked, then attempt to
  33.240 +     * reposition it at the mark.  If the stream has not been marked, then
  33.241 +     * attempt to reset it in some way appropriate to the particular stream,
  33.242 +     * for example by repositioning it to its starting point.  Not all
  33.243 +     * character-input streams support the reset() operation, and some support
  33.244 +     * reset() without supporting mark().
  33.245 +     *
  33.246 +     * @exception  IOException  If the stream has not been marked,
  33.247 +     *                          or if the mark has been invalidated,
  33.248 +     *                          or if the stream does not support reset(),
  33.249 +     *                          or if some other I/O error occurs
  33.250 +     */
  33.251 +    public void reset() throws IOException {
  33.252 +        throw new IOException("reset() not supported");
  33.253 +    }
  33.254 +
  33.255 +    /**
  33.256 +     * Closes the stream and releases any system resources associated with
  33.257 +     * it.  Once the stream has been closed, further read(), ready(),
  33.258 +     * mark(), reset(), or skip() invocations will throw an IOException.
  33.259 +     * Closing a previously closed stream has no effect.
  33.260 +     *
  33.261 +     * @exception  IOException  If an I/O error occurs
  33.262 +     */
  33.263 +     abstract public void close() throws IOException;
  33.264 +
  33.265 +}
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/emul/compact/src/main/java/java/lang/AbstractMethodError.java	Sun Feb 03 07:48:42 2013 +0100
    34.3 @@ -0,0 +1,58 @@
    34.4 +/*
    34.5 + * Copyright (c) 1994, 2008, 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 + * Thrown when an application tries to call an abstract method.
   34.33 + * Normally, this error is caught by the compiler; this error can
   34.34 + * only occur at run time if the definition of some class has
   34.35 + * incompatibly changed since the currently executing method was last
   34.36 + * compiled.
   34.37 + *
   34.38 + * @author  unascribed
   34.39 + * @since   JDK1.0
   34.40 + */
   34.41 +public
   34.42 +class AbstractMethodError extends IncompatibleClassChangeError {
   34.43 +    private static final long serialVersionUID = -1654391082989018462L;
   34.44 +
   34.45 +    /**
   34.46 +     * Constructs an <code>AbstractMethodError</code> with no detail  message.
   34.47 +     */
   34.48 +    public AbstractMethodError() {
   34.49 +        super();
   34.50 +    }
   34.51 +
   34.52 +    /**
   34.53 +     * Constructs an <code>AbstractMethodError</code> with the specified
   34.54 +     * detail message.
   34.55 +     *
   34.56 +     * @param   s   the detail message.
   34.57 +     */
   34.58 +    public AbstractMethodError(String s) {
   34.59 +        super(s);
   34.60 +    }
   34.61 +}
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/emul/compact/src/main/java/java/lang/Cloneable.java	Sun Feb 03 07:48:42 2013 +0100
    35.3 @@ -0,0 +1,54 @@
    35.4 +/*
    35.5 + * Copyright (c) 1995, 2004, 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 + * A class implements the <code>Cloneable</code> interface to
   35.33 + * indicate to the {@link java.lang.Object#clone()} method that it
   35.34 + * is legal for that method to make a
   35.35 + * field-for-field copy of instances of that class.
   35.36 + * <p>
   35.37 + * Invoking Object's clone method on an instance that does not implement the
   35.38 + * <code>Cloneable</code> interface results in the exception
   35.39 + * <code>CloneNotSupportedException</code> being thrown.
   35.40 + * <p>
   35.41 + * By convention, classes that implement this interface should override
   35.42 + * <tt>Object.clone</tt> (which is protected) with a public method.
   35.43 + * See {@link java.lang.Object#clone()} for details on overriding this
   35.44 + * method.
   35.45 + * <p>
   35.46 + * Note that this interface does <i>not</i> contain the <tt>clone</tt> method.
   35.47 + * Therefore, it is not possible to clone an object merely by virtue of the
   35.48 + * fact that it implements this interface.  Even if the clone method is invoked
   35.49 + * reflectively, there is no guarantee that it will succeed.
   35.50 + *
   35.51 + * @author  unascribed
   35.52 + * @see     java.lang.CloneNotSupportedException
   35.53 + * @see     java.lang.Object#clone()
   35.54 + * @since   JDK1.0
   35.55 + */
   35.56 +public interface Cloneable {
   35.57 +}
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/emul/compact/src/main/java/java/lang/IncompatibleClassChangeError.java	Sun Feb 03 07:48:42 2013 +0100
    36.3 @@ -0,0 +1,57 @@
    36.4 +/*
    36.5 + * Copyright (c) 1994, 2008, 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 +/**
   36.32 + * Thrown when an incompatible class change has occurred to some class
   36.33 + * definition. The definition of some class, on which the currently
   36.34 + * executing method depends, has since changed.
   36.35 + *
   36.36 + * @author  unascribed
   36.37 + * @since   JDK1.0
   36.38 + */
   36.39 +public
   36.40 +class IncompatibleClassChangeError extends LinkageError {
   36.41 +    private static final long serialVersionUID = -4914975503642802119L;
   36.42 +
   36.43 +    /**
   36.44 +     * Constructs an <code>IncompatibleClassChangeError</code> with no
   36.45 +     * detail message.
   36.46 +     */
   36.47 +    public IncompatibleClassChangeError () {
   36.48 +        super();
   36.49 +    }
   36.50 +
   36.51 +    /**
   36.52 +     * Constructs an <code>IncompatibleClassChangeError</code> with the
   36.53 +     * specified detail message.
   36.54 +     *
   36.55 +     * @param   s   the detail message.
   36.56 +     */
   36.57 +    public IncompatibleClassChangeError(String s) {
   36.58 +        super(s);
   36.59 +    }
   36.60 +}
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/emul/compact/src/main/java/java/lang/InternalError.java	Sun Feb 03 07:48:42 2013 +0100
    37.3 @@ -0,0 +1,55 @@
    37.4 +/*
    37.5 + * Copyright (c) 1994, 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 + * Thrown to indicate some unexpected internal error has occurred in
   37.33 + * the Java Virtual Machine.
   37.34 + *
   37.35 + * @author  unascribed
   37.36 + * @since   JDK1.0
   37.37 + */
   37.38 +public
   37.39 +class InternalError extends VirtualMachineError {
   37.40 +    private static final long serialVersionUID = -9062593416125562365L;
   37.41 +
   37.42 +    /**
   37.43 +     * Constructs an <code>InternalError</code> with no detail message.
   37.44 +     */
   37.45 +    public InternalError() {
   37.46 +        super();
   37.47 +    }
   37.48 +
   37.49 +    /**
   37.50 +     * Constructs an <code>InternalError</code> with the specified
   37.51 +     * detail message.
   37.52 +     *
   37.53 +     * @param   s   the detail message.
   37.54 +     */
   37.55 +    public InternalError(String s) {
   37.56 +        super(s);
   37.57 +    }
   37.58 +}
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/emul/compact/src/main/java/java/lang/Iterable.java	Sun Feb 03 07:48:42 2013 +0100
    38.3 @@ -0,0 +1,46 @@
    38.4 +/*
    38.5 + * Copyright (c) 2003, 2010, 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 +import java.util.Iterator;
   38.32 +
   38.33 +/**
   38.34 + * Implementing this interface allows an object to be the target of
   38.35 + * the "foreach" statement.
   38.36 + *
   38.37 + * @param <T> the type of elements returned by the iterator
   38.38 + *
   38.39 + * @since 1.5
   38.40 + */
   38.41 +public interface Iterable<T> {
   38.42 +
   38.43 +    /**
   38.44 +     * Returns an iterator over a set of elements of type T.
   38.45 +     *
   38.46 +     * @return an Iterator.
   38.47 +     */
   38.48 +    Iterator<T> iterator();
   38.49 +}
    39.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.2 +++ b/emul/compact/src/main/java/java/lang/NoSuchFieldError.java	Sun Feb 03 07:48:42 2013 +0100
    39.3 @@ -0,0 +1,59 @@
    39.4 +/*
    39.5 + * Copyright (c) 1995, 2008, 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 + * Thrown if an application tries to access or modify a specified
   39.33 + * field of an object, and that object no longer has that field.
   39.34 + * <p>
   39.35 + * Normally, this error is caught by the compiler; this error can
   39.36 + * only occur at run time if the definition of a class has
   39.37 + * incompatibly changed.
   39.38 + *
   39.39 + * @author  unascribed
   39.40 + * @since   JDK1.0
   39.41 + */
   39.42 +public
   39.43 +class NoSuchFieldError extends IncompatibleClassChangeError {
   39.44 +    private static final long serialVersionUID = -3456430195886129035L;
   39.45 +
   39.46 +    /**
   39.47 +     * Constructs a <code>NoSuchFieldError</code> with no detail message.
   39.48 +     */
   39.49 +    public NoSuchFieldError() {
   39.50 +        super();
   39.51 +    }
   39.52 +
   39.53 +    /**
   39.54 +     * Constructs a <code>NoSuchFieldError</code> with the specified
   39.55 +     * detail message.
   39.56 +     *
   39.57 +     * @param   s   the detail message.
   39.58 +     */
   39.59 +    public NoSuchFieldError(String s) {
   39.60 +        super(s);
   39.61 +    }
   39.62 +}
    40.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.2 +++ b/emul/compact/src/main/java/java/lang/Readable.java	Sun Feb 03 07:48:42 2013 +0100
    40.3 @@ -0,0 +1,55 @@
    40.4 +/*
    40.5 + * Copyright (c) 2003, 2010, 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 +import java.io.IOException;
   40.32 +
   40.33 +/**
   40.34 + * A <tt>Readable</tt> is a source of characters. Characters from
   40.35 + * a <tt>Readable</tt> are made available to callers of the read
   40.36 + * method via a {@link java.nio.CharBuffer CharBuffer}.
   40.37 + *
   40.38 + * @since 1.5
   40.39 + */
   40.40 +
   40.41 +public interface Readable {
   40.42 +
   40.43 +    /**
   40.44 +     * Attempts to read characters into the specified character buffer.
   40.45 +     * The buffer is used as a repository of characters as-is: the only
   40.46 +     * changes made are the results of a put operation. No flipping or
   40.47 +     * rewinding of the buffer is performed.
   40.48 +     *
   40.49 +     * @param cb the buffer to read characters into
   40.50 +     * @return The number of {@code char} values added to the buffer,
   40.51 +     *                 or -1 if this source of characters is at its end
   40.52 +     * @throws IOException if an I/O error occurs
   40.53 +     * @throws NullPointerException if cb is null
   40.54 +     * @throws java.nio.ReadOnlyBufferException if cb is a read only buffer
   40.55 +     */
   40.56 +// XXX:    public int read(java.nio.CharBuffer cb) throws IOException;
   40.57 +
   40.58 +}
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/emul/compact/src/main/java/java/lang/SafeVarargs.java	Sun Feb 03 07:48:42 2013 +0100
    41.3 @@ -0,0 +1,91 @@
    41.4 +/*
    41.5 + * Copyright (c) 2010, 2011, 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 +import java.lang.annotation.*;
   41.32 +
   41.33 +/**
   41.34 + * A programmer assertion that the body of the annotated method or
   41.35 + * constructor does not perform potentially unsafe operations on its
   41.36 + * varargs parameter.  Applying this annotation to a method or
   41.37 + * constructor suppresses unchecked warnings about a
   41.38 + * <i>non-reifiable</i> variable arity (vararg) type and suppresses
   41.39 + * unchecked warnings about parameterized array creation at call
   41.40 + * sites.
   41.41 + *
   41.42 + * <p> In addition to the usage restrictions imposed by its {@link
   41.43 + * Target @Target} meta-annotation, compilers are required to implement
   41.44 + * additional usage restrictions on this annotation type; it is a
   41.45 + * compile-time error if a method or constructor declaration is
   41.46 + * annotated with a {@code @SafeVarargs} annotation, and either:
   41.47 + * <ul>
   41.48 + * <li>  the declaration is a fixed arity method or constructor
   41.49 + *
   41.50 + * <li> the declaration is a variable arity method that is neither
   41.51 + * {@code static} nor {@code final}.
   41.52 + *
   41.53 + * </ul>
   41.54 + *
   41.55 + * <p> Compilers are encouraged to issue warnings when this annotation
   41.56 + * type is applied to a method or constructor declaration where:
   41.57 + *
   41.58 + * <ul>
   41.59 + *
   41.60 + * <li> The variable arity parameter has a reifiable element type,
   41.61 + * which includes primitive types, {@code Object}, and {@code String}.
   41.62 + * (The unchecked warnings this annotation type suppresses already do
   41.63 + * not occur for a reifiable element type.)
   41.64 + *
   41.65 + * <li> The body of the method or constructor declaration performs
   41.66 + * potentially unsafe operations, such as an assignment to an element
   41.67 + * of the variable arity parameter's array that generates an unchecked
   41.68 + * warning.  Some unsafe operations do not trigger an unchecked
   41.69 + * warning.  For example, the aliasing in
   41.70 + *
   41.71 + * <blockquote><pre>
   41.72 + * &#64;SafeVarargs // Not actually safe!
   41.73 + * static void m(List&lt;String&gt;... stringLists) {
   41.74 + *   Object[] array = stringLists;
   41.75 + *   List&lt;Integer&gt; tmpList = Arrays.asList(42);
   41.76 + *   array[0] = tmpList; // Semantically invalid, but compiles without warnings
   41.77 + *   String s = stringLists[0].get(0); // Oh no, ClassCastException at runtime!
   41.78 + * }
   41.79 + * </pre></blockquote>
   41.80 + *
   41.81 + * leads to a {@code ClassCastException} at runtime.
   41.82 + *
   41.83 + * <p>Future versions of the platform may mandate compiler errors for
   41.84 + * such unsafe operations.
   41.85 + *
   41.86 + * </ul>
   41.87 + *
   41.88 + * @jls 4.7 Reifiable Types
   41.89 + * @jls 8.4.1 Formal Parameters
   41.90 + */
   41.91 +@Documented
   41.92 +@Retention(RetentionPolicy.RUNTIME)
   41.93 +@Target({ElementType.CONSTRUCTOR, ElementType.METHOD})
   41.94 +public @interface SafeVarargs {}
    42.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.2 +++ b/emul/compact/src/main/java/java/lang/SuppressWarnings.java	Sun Feb 03 07:48:42 2013 +0100
    42.3 @@ -0,0 +1,64 @@
    42.4 +/*
    42.5 + * Copyright (c) 2004, 2011, 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 java.lang.annotation.*;
   42.32 +import static java.lang.annotation.ElementType.*;
   42.33 +
   42.34 +/**
   42.35 + * Indicates that the named compiler warnings should be suppressed in the
   42.36 + * annotated element (and in all program elements contained in the annotated
   42.37 + * element).  Note that the set of warnings suppressed in a given element is
   42.38 + * a superset of the warnings suppressed in all containing elements.  For
   42.39 + * example, if you annotate a class to suppress one warning and annotate a
   42.40 + * method to suppress another, both warnings will be suppressed in the method.
   42.41 + *
   42.42 + * <p>As a matter of style, programmers should always use this annotation
   42.43 + * on the most deeply nested element where it is effective.  If you want to
   42.44 + * suppress a warning in a particular method, you should annotate that
   42.45 + * method rather than its class.
   42.46 + *
   42.47 + * @since 1.5
   42.48 + * @author Josh Bloch
   42.49 + */
   42.50 +@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
   42.51 +@Retention(RetentionPolicy.SOURCE)
   42.52 +public @interface SuppressWarnings {
   42.53 +    /**
   42.54 +     * The set of warnings that are to be suppressed by the compiler in the
   42.55 +     * annotated element.  Duplicate names are permitted.  The second and
   42.56 +     * successive occurrences of a name are ignored.  The presence of
   42.57 +     * unrecognized warning names is <i>not</i> an error: Compilers must
   42.58 +     * ignore any warning names they do not recognize.  They are, however,
   42.59 +     * free to emit a warning if an annotation contains an unrecognized
   42.60 +     * warning name.
   42.61 +     *
   42.62 +     * <p>Compiler vendors should document the warning names they support in
   42.63 +     * conjunction with this annotation type. They are encouraged to cooperate
   42.64 +     * to ensure that the same names work across multiple compilers.
   42.65 +     */
   42.66 +    String[] value();
   42.67 +}
    43.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.2 +++ b/emul/compact/src/main/java/java/lang/System.java	Sun Feb 03 07:48:42 2013 +0100
    43.3 @@ -0,0 +1,36 @@
    43.4 +/**
    43.5 + * Back 2 Browser Bytecode Translator
    43.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    43.7 + *
    43.8 + * This program is free software: you can redistribute it and/or modify
    43.9 + * it under the terms of the GNU General Public License as published by
   43.10 + * the Free Software Foundation, version 2 of the License.
   43.11 + *
   43.12 + * This program is distributed in the hope that it will be useful,
   43.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   43.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   43.15 + * GNU General Public License for more details.
   43.16 + *
   43.17 + * You should have received a copy of the GNU General Public License
   43.18 + * along with this program. Look for COPYING file in the top folder.
   43.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   43.20 + */
   43.21 +package java.lang;
   43.22 +
   43.23 +/** Poor man's re-implementation of most important System methods.
   43.24 + *
   43.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   43.26 + */
   43.27 +public class System {
   43.28 +    private System() {
   43.29 +    }
   43.30 +    
   43.31 +    public static void arraycopy(Object value, int srcBegin, Object dst, int dstBegin, int count) {
   43.32 +        org.apidesign.bck2brwsr.emul.lang.System.arraycopy(value, srcBegin, dst, dstBegin, count);
   43.33 +    }
   43.34 +    
   43.35 +    public static long currentTimeMillis() {
   43.36 +        return org.apidesign.bck2brwsr.emul.lang.System.currentTimeMillis();
   43.37 +    }
   43.38 +    
   43.39 +}
    44.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.2 +++ b/emul/compact/src/main/java/java/util/AbstractCollection.java	Sun Feb 03 07:48:42 2013 +0100
    44.3 @@ -0,0 +1,457 @@
    44.4 +/*
    44.5 + * Copyright (c) 1997, 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.util;
   44.30 +
   44.31 +/**
   44.32 + * This class provides a skeletal implementation of the <tt>Collection</tt>
   44.33 + * interface, to minimize the effort required to implement this interface. <p>
   44.34 + *
   44.35 + * To implement an unmodifiable collection, the programmer needs only to
   44.36 + * extend this class and provide implementations for the <tt>iterator</tt> and
   44.37 + * <tt>size</tt> methods.  (The iterator returned by the <tt>iterator</tt>
   44.38 + * method must implement <tt>hasNext</tt> and <tt>next</tt>.)<p>
   44.39 + *
   44.40 + * To implement a modifiable collection, the programmer must additionally
   44.41 + * override this class's <tt>add</tt> method (which otherwise throws an
   44.42 + * <tt>UnsupportedOperationException</tt>), and the iterator returned by the
   44.43 + * <tt>iterator</tt> method must additionally implement its <tt>remove</tt>
   44.44 + * method.<p>
   44.45 + *
   44.46 + * The programmer should generally provide a void (no argument) and
   44.47 + * <tt>Collection</tt> constructor, as per the recommendation in the
   44.48 + * <tt>Collection</tt> interface specification.<p>
   44.49 + *
   44.50 + * The documentation for each non-abstract method in this class describes its
   44.51 + * implementation in detail.  Each of these methods may be overridden if
   44.52 + * the collection being implemented admits a more efficient implementation.<p>
   44.53 + *
   44.54 + * This class is a member of the
   44.55 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   44.56 + * Java Collections Framework</a>.
   44.57 + *
   44.58 + * @author  Josh Bloch
   44.59 + * @author  Neal Gafter
   44.60 + * @see Collection
   44.61 + * @since 1.2
   44.62 + */
   44.63 +
   44.64 +public abstract class AbstractCollection<E> implements Collection<E> {
   44.65 +    /**
   44.66 +     * Sole constructor.  (For invocation by subclass constructors, typically
   44.67 +     * implicit.)
   44.68 +     */
   44.69 +    protected AbstractCollection() {
   44.70 +    }
   44.71 +
   44.72 +    // Query Operations
   44.73 +
   44.74 +    /**
   44.75 +     * Returns an iterator over the elements contained in this collection.
   44.76 +     *
   44.77 +     * @return an iterator over the elements contained in this collection
   44.78 +     */
   44.79 +    public abstract Iterator<E> iterator();
   44.80 +
   44.81 +    public abstract int size();
   44.82 +
   44.83 +    /**
   44.84 +     * {@inheritDoc}
   44.85 +     *
   44.86 +     * <p>This implementation returns <tt>size() == 0</tt>.
   44.87 +     */
   44.88 +    public boolean isEmpty() {
   44.89 +        return size() == 0;
   44.90 +    }
   44.91 +
   44.92 +    /**
   44.93 +     * {@inheritDoc}
   44.94 +     *
   44.95 +     * <p>This implementation iterates over the elements in the collection,
   44.96 +     * checking each element in turn for equality with the specified element.
   44.97 +     *
   44.98 +     * @throws ClassCastException   {@inheritDoc}
   44.99 +     * @throws NullPointerException {@inheritDoc}
  44.100 +     */
  44.101 +    public boolean contains(Object o) {
  44.102 +        Iterator<E> it = iterator();
  44.103 +        if (o==null) {
  44.104 +            while (it.hasNext())
  44.105 +                if (it.next()==null)
  44.106 +                    return true;
  44.107 +        } else {
  44.108 +            while (it.hasNext())
  44.109 +                if (o.equals(it.next()))
  44.110 +                    return true;
  44.111 +        }
  44.112 +        return false;
  44.113 +    }
  44.114 +
  44.115 +    /**
  44.116 +     * {@inheritDoc}
  44.117 +     *
  44.118 +     * <p>This implementation returns an array containing all the elements
  44.119 +     * returned by this collection's iterator, in the same order, stored in
  44.120 +     * consecutive elements of the array, starting with index {@code 0}.
  44.121 +     * The length of the returned array is equal to the number of elements
  44.122 +     * returned by the iterator, even if the size of this collection changes
  44.123 +     * during iteration, as might happen if the collection permits
  44.124 +     * concurrent modification during iteration.  The {@code size} method is
  44.125 +     * called only as an optimization hint; the correct result is returned
  44.126 +     * even if the iterator returns a different number of elements.
  44.127 +     *
  44.128 +     * <p>This method is equivalent to:
  44.129 +     *
  44.130 +     *  <pre> {@code
  44.131 +     * List<E> list = new ArrayList<E>(size());
  44.132 +     * for (E e : this)
  44.133 +     *     list.add(e);
  44.134 +     * return list.toArray();
  44.135 +     * }</pre>
  44.136 +     */
  44.137 +    public Object[] toArray() {
  44.138 +        // Estimate size of array; be prepared to see more or fewer elements
  44.139 +        Object[] r = new Object[size()];
  44.140 +        Iterator<E> it = iterator();
  44.141 +        for (int i = 0; i < r.length; i++) {
  44.142 +            if (! it.hasNext()) // fewer elements than expected
  44.143 +                return Arrays.copyOf(r, i);
  44.144 +            r[i] = it.next();
  44.145 +        }
  44.146 +        return it.hasNext() ? finishToArray(r, it) : r;
  44.147 +    }
  44.148 +
  44.149 +    /**
  44.150 +     * {@inheritDoc}
  44.151 +     *
  44.152 +     * <p>This implementation returns an array containing all the elements
  44.153 +     * returned by this collection's iterator in the same order, stored in
  44.154 +     * consecutive elements of the array, starting with index {@code 0}.
  44.155 +     * If the number of elements returned by the iterator is too large to
  44.156 +     * fit into the specified array, then the elements are returned in a
  44.157 +     * newly allocated array with length equal to the number of elements
  44.158 +     * returned by the iterator, even if the size of this collection
  44.159 +     * changes during iteration, as might happen if the collection permits
  44.160 +     * concurrent modification during iteration.  The {@code size} method is
  44.161 +     * called only as an optimization hint; the correct result is returned
  44.162 +     * even if the iterator returns a different number of elements.
  44.163 +     *
  44.164 +     * <p>This method is equivalent to:
  44.165 +     *
  44.166 +     *  <pre> {@code
  44.167 +     * List<E> list = new ArrayList<E>(size());
  44.168 +     * for (E e : this)
  44.169 +     *     list.add(e);
  44.170 +     * return list.toArray(a);
  44.171 +     * }</pre>
  44.172 +     *
  44.173 +     * @throws ArrayStoreException  {@inheritDoc}
  44.174 +     * @throws NullPointerException {@inheritDoc}
  44.175 +     */
  44.176 +    public <T> T[] toArray(T[] a) {
  44.177 +        // Estimate size of array; be prepared to see more or fewer elements
  44.178 +        int size = size();
  44.179 +        T[] r = a.length >= size ? a :
  44.180 +                  (T[])java.lang.reflect.Array
  44.181 +                  .newInstance(a.getClass().getComponentType(), size);
  44.182 +        Iterator<E> it = iterator();
  44.183 +
  44.184 +        for (int i = 0; i < r.length; i++) {
  44.185 +            if (! it.hasNext()) { // fewer elements than expected
  44.186 +                if (a != r)
  44.187 +                    return Arrays.copyOf(r, i);
  44.188 +                r[i] = null; // null-terminate
  44.189 +                return r;
  44.190 +            }
  44.191 +            r[i] = (T)it.next();
  44.192 +        }
  44.193 +        return it.hasNext() ? finishToArray(r, it) : r;
  44.194 +    }
  44.195 +
  44.196 +    /**
  44.197 +     * The maximum size of array to allocate.
  44.198 +     * Some VMs reserve some header words in an array.
  44.199 +     * Attempts to allocate larger arrays may result in
  44.200 +     * OutOfMemoryError: Requested array size exceeds VM limit
  44.201 +     */
  44.202 +    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
  44.203 +
  44.204 +    /**
  44.205 +     * Reallocates the array being used within toArray when the iterator
  44.206 +     * returned more elements than expected, and finishes filling it from
  44.207 +     * the iterator.
  44.208 +     *
  44.209 +     * @param r the array, replete with previously stored elements
  44.210 +     * @param it the in-progress iterator over this collection
  44.211 +     * @return array containing the elements in the given array, plus any
  44.212 +     *         further elements returned by the iterator, trimmed to size
  44.213 +     */
  44.214 +    private static <T> T[] finishToArray(T[] r, Iterator<?> it) {
  44.215 +        int i = r.length;
  44.216 +        while (it.hasNext()) {
  44.217 +            int cap = r.length;
  44.218 +            if (i == cap) {
  44.219 +                int newCap = cap + (cap >> 1) + 1;
  44.220 +                // overflow-conscious code
  44.221 +                if (newCap - MAX_ARRAY_SIZE > 0)
  44.222 +                    newCap = hugeCapacity(cap + 1);
  44.223 +                r = Arrays.copyOf(r, newCap);
  44.224 +            }
  44.225 +            r[i++] = (T)it.next();
  44.226 +        }
  44.227 +        // trim if overallocated
  44.228 +        return (i == r.length) ? r : Arrays.copyOf(r, i);
  44.229 +    }
  44.230 +
  44.231 +    private static int hugeCapacity(int minCapacity) {
  44.232 +        if (minCapacity < 0) // overflow
  44.233 +            throw new OutOfMemoryError
  44.234 +                ("Required array size too large");
  44.235 +        return (minCapacity > MAX_ARRAY_SIZE) ?
  44.236 +            Integer.MAX_VALUE :
  44.237 +            MAX_ARRAY_SIZE;
  44.238 +    }
  44.239 +
  44.240 +    // Modification Operations
  44.241 +
  44.242 +    /**
  44.243 +     * {@inheritDoc}
  44.244 +     *
  44.245 +     * <p>This implementation always throws an
  44.246 +     * <tt>UnsupportedOperationException</tt>.
  44.247 +     *
  44.248 +     * @throws UnsupportedOperationException {@inheritDoc}
  44.249 +     * @throws ClassCastException            {@inheritDoc}
  44.250 +     * @throws NullPointerException          {@inheritDoc}
  44.251 +     * @throws IllegalArgumentException      {@inheritDoc}
  44.252 +     * @throws IllegalStateException         {@inheritDoc}
  44.253 +     */
  44.254 +    public boolean add(E e) {
  44.255 +        throw new UnsupportedOperationException();
  44.256 +    }
  44.257 +
  44.258 +    /**
  44.259 +     * {@inheritDoc}
  44.260 +     *
  44.261 +     * <p>This implementation iterates over the collection looking for the
  44.262 +     * specified element.  If it finds the element, it removes the element
  44.263 +     * from the collection using the iterator's remove method.
  44.264 +     *
  44.265 +     * <p>Note that this implementation throws an
  44.266 +     * <tt>UnsupportedOperationException</tt> if the iterator returned by this
  44.267 +     * collection's iterator method does not implement the <tt>remove</tt>
  44.268 +     * method and this collection contains the specified object.
  44.269 +     *
  44.270 +     * @throws UnsupportedOperationException {@inheritDoc}
  44.271 +     * @throws ClassCastException            {@inheritDoc}
  44.272 +     * @throws NullPointerException          {@inheritDoc}
  44.273 +     */
  44.274 +    public boolean remove(Object o) {
  44.275 +        Iterator<E> it = iterator();
  44.276 +        if (o==null) {
  44.277 +            while (it.hasNext()) {
  44.278 +                if (it.next()==null) {
  44.279 +                    it.remove();
  44.280 +                    return true;
  44.281 +                }
  44.282 +            }
  44.283 +        } else {
  44.284 +            while (it.hasNext()) {
  44.285 +                if (o.equals(it.next())) {
  44.286 +                    it.remove();
  44.287 +                    return true;
  44.288 +                }
  44.289 +            }
  44.290 +        }
  44.291 +        return false;
  44.292 +    }
  44.293 +
  44.294 +
  44.295 +    // Bulk Operations
  44.296 +
  44.297 +    /**
  44.298 +     * {@inheritDoc}
  44.299 +     *
  44.300 +     * <p>This implementation iterates over the specified collection,
  44.301 +     * checking each element returned by the iterator in turn to see
  44.302 +     * if it's contained in this collection.  If all elements are so
  44.303 +     * contained <tt>true</tt> is returned, otherwise <tt>false</tt>.
  44.304 +     *
  44.305 +     * @throws ClassCastException            {@inheritDoc}
  44.306 +     * @throws NullPointerException          {@inheritDoc}
  44.307 +     * @see #contains(Object)
  44.308 +     */
  44.309 +    public boolean containsAll(Collection<?> c) {
  44.310 +        for (Object e : c)
  44.311 +            if (!contains(e))
  44.312 +                return false;
  44.313 +        return true;
  44.314 +    }
  44.315 +
  44.316 +    /**
  44.317 +     * {@inheritDoc}
  44.318 +     *
  44.319 +     * <p>This implementation iterates over the specified collection, and adds
  44.320 +     * each object returned by the iterator to this collection, in turn.
  44.321 +     *
  44.322 +     * <p>Note that this implementation will throw an
  44.323 +     * <tt>UnsupportedOperationException</tt> unless <tt>add</tt> is
  44.324 +     * overridden (assuming the specified collection is non-empty).
  44.325 +     *
  44.326 +     * @throws UnsupportedOperationException {@inheritDoc}
  44.327 +     * @throws ClassCastException            {@inheritDoc}
  44.328 +     * @throws NullPointerException          {@inheritDoc}
  44.329 +     * @throws IllegalArgumentException      {@inheritDoc}
  44.330 +     * @throws IllegalStateException         {@inheritDoc}
  44.331 +     *
  44.332 +     * @see #add(Object)
  44.333 +     */
  44.334 +    public boolean addAll(Collection<? extends E> c) {
  44.335 +        boolean modified = false;
  44.336 +        for (E e : c)
  44.337 +            if (add(e))
  44.338 +                modified = true;
  44.339 +        return modified;
  44.340 +    }
  44.341 +
  44.342 +    /**
  44.343 +     * {@inheritDoc}
  44.344 +     *
  44.345 +     * <p>This implementation iterates over this collection, checking each
  44.346 +     * element returned by the iterator in turn to see if it's contained
  44.347 +     * in the specified collection.  If it's so contained, it's removed from
  44.348 +     * this collection with the iterator's <tt>remove</tt> method.
  44.349 +     *
  44.350 +     * <p>Note that this implementation will throw an
  44.351 +     * <tt>UnsupportedOperationException</tt> if the iterator returned by the
  44.352 +     * <tt>iterator</tt> method does not implement the <tt>remove</tt> method
  44.353 +     * and this collection contains one or more elements in common with the
  44.354 +     * specified collection.
  44.355 +     *
  44.356 +     * @throws UnsupportedOperationException {@inheritDoc}
  44.357 +     * @throws ClassCastException            {@inheritDoc}
  44.358 +     * @throws NullPointerException          {@inheritDoc}
  44.359 +     *
  44.360 +     * @see #remove(Object)
  44.361 +     * @see #contains(Object)
  44.362 +     */
  44.363 +    public boolean removeAll(Collection<?> c) {
  44.364 +        boolean modified = false;
  44.365 +        Iterator<?> it = iterator();
  44.366 +        while (it.hasNext()) {
  44.367 +            if (c.contains(it.next())) {
  44.368 +                it.remove();
  44.369 +                modified = true;
  44.370 +            }
  44.371 +        }
  44.372 +        return modified;
  44.373 +    }
  44.374 +
  44.375 +    /**
  44.376 +     * {@inheritDoc}
  44.377 +     *
  44.378 +     * <p>This implementation iterates over this collection, checking each
  44.379 +     * element returned by the iterator in turn to see if it's contained
  44.380 +     * in the specified collection.  If it's not so contained, it's removed
  44.381 +     * from this collection with the iterator's <tt>remove</tt> method.
  44.382 +     *
  44.383 +     * <p>Note that this implementation will throw an
  44.384 +     * <tt>UnsupportedOperationException</tt> if the iterator returned by the
  44.385 +     * <tt>iterator</tt> method does not implement the <tt>remove</tt> method
  44.386 +     * and this collection contains one or more elements not present in the
  44.387 +     * specified collection.
  44.388 +     *
  44.389 +     * @throws UnsupportedOperationException {@inheritDoc}
  44.390 +     * @throws ClassCastException            {@inheritDoc}
  44.391 +     * @throws NullPointerException          {@inheritDoc}
  44.392 +     *
  44.393 +     * @see #remove(Object)
  44.394 +     * @see #contains(Object)
  44.395 +     */
  44.396 +    public boolean retainAll(Collection<?> c) {
  44.397 +        boolean modified = false;
  44.398 +        Iterator<E> it = iterator();
  44.399 +        while (it.hasNext()) {
  44.400 +            if (!c.contains(it.next())) {
  44.401 +                it.remove();
  44.402 +                modified = true;
  44.403 +            }
  44.404 +        }
  44.405 +        return modified;
  44.406 +    }
  44.407 +
  44.408 +    /**
  44.409 +     * {@inheritDoc}
  44.410 +     *
  44.411 +     * <p>This implementation iterates over this collection, removing each
  44.412 +     * element using the <tt>Iterator.remove</tt> operation.  Most
  44.413 +     * implementations will probably choose to override this method for
  44.414 +     * efficiency.
  44.415 +     *
  44.416 +     * <p>Note that this implementation will throw an
  44.417 +     * <tt>UnsupportedOperationException</tt> if the iterator returned by this
  44.418 +     * collection's <tt>iterator</tt> method does not implement the
  44.419 +     * <tt>remove</tt> method and this collection is non-empty.
  44.420 +     *
  44.421 +     * @throws UnsupportedOperationException {@inheritDoc}
  44.422 +     */
  44.423 +    public void clear() {
  44.424 +        Iterator<E> it = iterator();
  44.425 +        while (it.hasNext()) {
  44.426 +            it.next();
  44.427 +            it.remove();
  44.428 +        }
  44.429 +    }
  44.430 +
  44.431 +
  44.432 +    //  String conversion
  44.433 +
  44.434 +    /**
  44.435 +     * Returns a string representation of this collection.  The string
  44.436 +     * representation consists of a list of the collection's elements in the
  44.437 +     * order they are returned by its iterator, enclosed in square brackets
  44.438 +     * (<tt>"[]"</tt>).  Adjacent elements are separated by the characters
  44.439 +     * <tt>", "</tt> (comma and space).  Elements are converted to strings as
  44.440 +     * by {@link String#valueOf(Object)}.
  44.441 +     *
  44.442 +     * @return a string representation of this collection
  44.443 +     */
  44.444 +    public String toString() {
  44.445 +        Iterator<E> it = iterator();
  44.446 +        if (! it.hasNext())
  44.447 +            return "[]";
  44.448 +
  44.449 +        StringBuilder sb = new StringBuilder();
  44.450 +        sb.append('[');
  44.451 +        for (;;) {
  44.452 +            E e = it.next();
  44.453 +            sb.append(e == this ? "(this Collection)" : e);
  44.454 +            if (! it.hasNext())
  44.455 +                return sb.append(']').toString();
  44.456 +            sb.append(',').append(' ');
  44.457 +        }
  44.458 +    }
  44.459 +
  44.460 +}
    45.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.2 +++ b/emul/compact/src/main/java/java/util/AbstractList.java	Sun Feb 03 07:48:42 2013 +0100
    45.3 @@ -0,0 +1,781 @@
    45.4 +/*
    45.5 + * Copyright (c) 1997, 2010, 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.util;
   45.30 +
   45.31 +/**
   45.32 + * This class provides a skeletal implementation of the {@link List}
   45.33 + * interface to minimize the effort required to implement this interface
   45.34 + * backed by a "random access" data store (such as an array).  For sequential
   45.35 + * access data (such as a linked list), {@link AbstractSequentialList} should
   45.36 + * be used in preference to this class.
   45.37 + *
   45.38 + * <p>To implement an unmodifiable list, the programmer needs only to extend
   45.39 + * this class and provide implementations for the {@link #get(int)} and
   45.40 + * {@link List#size() size()} methods.
   45.41 + *
   45.42 + * <p>To implement a modifiable list, the programmer must additionally
   45.43 + * override the {@link #set(int, Object) set(int, E)} method (which otherwise
   45.44 + * throws an {@code UnsupportedOperationException}).  If the list is
   45.45 + * variable-size the programmer must additionally override the
   45.46 + * {@link #add(int, Object) add(int, E)} and {@link #remove(int)} methods.
   45.47 + *
   45.48 + * <p>The programmer should generally provide a void (no argument) and collection
   45.49 + * constructor, as per the recommendation in the {@link Collection} interface
   45.50 + * specification.
   45.51 + *
   45.52 + * <p>Unlike the other abstract collection implementations, the programmer does
   45.53 + * <i>not</i> have to provide an iterator implementation; the iterator and
   45.54 + * list iterator are implemented by this class, on top of the "random access"
   45.55 + * methods:
   45.56 + * {@link #get(int)},
   45.57 + * {@link #set(int, Object) set(int, E)},
   45.58 + * {@link #add(int, Object) add(int, E)} and
   45.59 + * {@link #remove(int)}.
   45.60 + *
   45.61 + * <p>The documentation for each non-abstract method in this class describes its
   45.62 + * implementation in detail.  Each of these methods may be overridden if the
   45.63 + * collection being implemented admits a more efficient implementation.
   45.64 + *
   45.65 + * <p>This class is a member of the
   45.66 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   45.67 + * Java Collections Framework</a>.
   45.68 + *
   45.69 + * @author  Josh Bloch
   45.70 + * @author  Neal Gafter
   45.71 + * @since 1.2
   45.72 + */
   45.73 +
   45.74 +public abstract class AbstractList<E> extends AbstractCollection<E> implements List<E> {
   45.75 +    /**
   45.76 +     * Sole constructor.  (For invocation by subclass constructors, typically
   45.77 +     * implicit.)
   45.78 +     */
   45.79 +    protected AbstractList() {
   45.80 +    }
   45.81 +
   45.82 +    /**
   45.83 +     * Appends the specified element to the end of this list (optional
   45.84 +     * operation).
   45.85 +     *
   45.86 +     * <p>Lists that support this operation may place limitations on what
   45.87 +     * elements may be added to this list.  In particular, some
   45.88 +     * lists will refuse to add null elements, and others will impose
   45.89 +     * restrictions on the type of elements that may be added.  List
   45.90 +     * classes should clearly specify in their documentation any restrictions
   45.91 +     * on what elements may be added.
   45.92 +     *
   45.93 +     * <p>This implementation calls {@code add(size(), e)}.
   45.94 +     *
   45.95 +     * <p>Note that this implementation throws an
   45.96 +     * {@code UnsupportedOperationException} unless
   45.97 +     * {@link #add(int, Object) add(int, E)} is overridden.
   45.98 +     *
   45.99 +     * @param e element to be appended to this list
  45.100 +     * @return {@code true} (as specified by {@link Collection#add})
  45.101 +     * @throws UnsupportedOperationException if the {@code add} operation
  45.102 +     *         is not supported by this list
  45.103 +     * @throws ClassCastException if the class of the specified element
  45.104 +     *         prevents it from being added to this list
  45.105 +     * @throws NullPointerException if the specified element is null and this
  45.106 +     *         list does not permit null elements
  45.107 +     * @throws IllegalArgumentException if some property of this element
  45.108 +     *         prevents it from being added to this list
  45.109 +     */
  45.110 +    public boolean add(E e) {
  45.111 +        add(size(), e);
  45.112 +        return true;
  45.113 +    }
  45.114 +
  45.115 +    /**
  45.116 +     * {@inheritDoc}
  45.117 +     *
  45.118 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  45.119 +     */
  45.120 +    abstract public E get(int index);
  45.121 +
  45.122 +    /**
  45.123 +     * {@inheritDoc}
  45.124 +     *
  45.125 +     * <p>This implementation always throws an
  45.126 +     * {@code UnsupportedOperationException}.
  45.127 +     *
  45.128 +     * @throws UnsupportedOperationException {@inheritDoc}
  45.129 +     * @throws ClassCastException            {@inheritDoc}
  45.130 +     * @throws NullPointerException          {@inheritDoc}
  45.131 +     * @throws IllegalArgumentException      {@inheritDoc}
  45.132 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
  45.133 +     */
  45.134 +    public E set(int index, E element) {
  45.135 +        throw new UnsupportedOperationException();
  45.136 +    }
  45.137 +
  45.138 +    /**
  45.139 +     * {@inheritDoc}
  45.140 +     *
  45.141 +     * <p>This implementation always throws an
  45.142 +     * {@code UnsupportedOperationException}.
  45.143 +     *
  45.144 +     * @throws UnsupportedOperationException {@inheritDoc}
  45.145 +     * @throws ClassCastException            {@inheritDoc}
  45.146 +     * @throws NullPointerException          {@inheritDoc}
  45.147 +     * @throws IllegalArgumentException      {@inheritDoc}
  45.148 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
  45.149 +     */
  45.150 +    public void add(int index, E element) {
  45.151 +        throw new UnsupportedOperationException();
  45.152 +    }
  45.153 +
  45.154 +    /**
  45.155 +     * {@inheritDoc}
  45.156 +     *
  45.157 +     * <p>This implementation always throws an
  45.158 +     * {@code UnsupportedOperationException}.
  45.159 +     *
  45.160 +     * @throws UnsupportedOperationException {@inheritDoc}
  45.161 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
  45.162 +     */
  45.163 +    public E remove(int index) {
  45.164 +        throw new UnsupportedOperationException();
  45.165 +    }
  45.166 +
  45.167 +
  45.168 +    // Search Operations
  45.169 +
  45.170 +    /**
  45.171 +     * {@inheritDoc}
  45.172 +     *
  45.173 +     * <p>This implementation first gets a list iterator (with
  45.174 +     * {@code listIterator()}).  Then, it iterates over the list until the
  45.175 +     * specified element is found or the end of the list is reached.
  45.176 +     *
  45.177 +     * @throws ClassCastException   {@inheritDoc}
  45.178 +     * @throws NullPointerException {@inheritDoc}
  45.179 +     */
  45.180 +    public int indexOf(Object o) {
  45.181 +        ListIterator<E> it = listIterator();
  45.182 +        if (o==null) {
  45.183 +            while (it.hasNext())
  45.184 +                if (it.next()==null)
  45.185 +                    return it.previousIndex();
  45.186 +        } else {
  45.187 +            while (it.hasNext())
  45.188 +                if (o.equals(it.next()))
  45.189 +                    return it.previousIndex();
  45.190 +        }
  45.191 +        return -1;
  45.192 +    }
  45.193 +
  45.194 +    /**
  45.195 +     * {@inheritDoc}
  45.196 +     *
  45.197 +     * <p>This implementation first gets a list iterator that points to the end
  45.198 +     * of the list (with {@code listIterator(size())}).  Then, it iterates
  45.199 +     * backwards over the list until the specified element is found, or the
  45.200 +     * beginning of the list is reached.
  45.201 +     *
  45.202 +     * @throws ClassCastException   {@inheritDoc}
  45.203 +     * @throws NullPointerException {@inheritDoc}
  45.204 +     */
  45.205 +    public int lastIndexOf(Object o) {
  45.206 +        ListIterator<E> it = listIterator(size());
  45.207 +        if (o==null) {
  45.208 +            while (it.hasPrevious())
  45.209 +                if (it.previous()==null)
  45.210 +                    return it.nextIndex();
  45.211 +        } else {
  45.212 +            while (it.hasPrevious())
  45.213 +                if (o.equals(it.previous()))
  45.214 +                    return it.nextIndex();
  45.215 +        }
  45.216 +        return -1;
  45.217 +    }
  45.218 +
  45.219 +
  45.220 +    // Bulk Operations
  45.221 +
  45.222 +    /**
  45.223 +     * Removes all of the elements from this list (optional operation).
  45.224 +     * The list will be empty after this call returns.
  45.225 +     *
  45.226 +     * <p>This implementation calls {@code removeRange(0, size())}.
  45.227 +     *
  45.228 +     * <p>Note that this implementation throws an
  45.229 +     * {@code UnsupportedOperationException} unless {@code remove(int
  45.230 +     * index)} or {@code removeRange(int fromIndex, int toIndex)} is
  45.231 +     * overridden.
  45.232 +     *
  45.233 +     * @throws UnsupportedOperationException if the {@code clear} operation
  45.234 +     *         is not supported by this list
  45.235 +     */
  45.236 +    public void clear() {
  45.237 +        removeRange(0, size());
  45.238 +    }
  45.239 +
  45.240 +    /**
  45.241 +     * {@inheritDoc}
  45.242 +     *
  45.243 +     * <p>This implementation gets an iterator over the specified collection
  45.244 +     * and iterates over it, inserting the elements obtained from the
  45.245 +     * iterator into this list at the appropriate position, one at a time,
  45.246 +     * using {@code add(int, E)}.
  45.247 +     * Many implementations will override this method for efficiency.
  45.248 +     *
  45.249 +     * <p>Note that this implementation throws an
  45.250 +     * {@code UnsupportedOperationException} unless
  45.251 +     * {@link #add(int, Object) add(int, E)} is overridden.
  45.252 +     *
  45.253 +     * @throws UnsupportedOperationException {@inheritDoc}
  45.254 +     * @throws ClassCastException            {@inheritDoc}
  45.255 +     * @throws NullPointerException          {@inheritDoc}
  45.256 +     * @throws IllegalArgumentException      {@inheritDoc}
  45.257 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
  45.258 +     */
  45.259 +    public boolean addAll(int index, Collection<? extends E> c) {
  45.260 +        rangeCheckForAdd(index);
  45.261 +        boolean modified = false;
  45.262 +        for (E e : c) {
  45.263 +            add(index++, e);
  45.264 +            modified = true;
  45.265 +        }
  45.266 +        return modified;
  45.267 +    }
  45.268 +
  45.269 +
  45.270 +    // Iterators
  45.271 +
  45.272 +    /**
  45.273 +     * Returns an iterator over the elements in this list in proper sequence.
  45.274 +     *
  45.275 +     * <p>This implementation returns a straightforward implementation of the
  45.276 +     * iterator interface, relying on the backing list's {@code size()},
  45.277 +     * {@code get(int)}, and {@code remove(int)} methods.
  45.278 +     *
  45.279 +     * <p>Note that the iterator returned by this method will throw an
  45.280 +     * {@link UnsupportedOperationException} in response to its
  45.281 +     * {@code remove} method unless the list's {@code remove(int)} method is
  45.282 +     * overridden.
  45.283 +     *
  45.284 +     * <p>This implementation can be made to throw runtime exceptions in the
  45.285 +     * face of concurrent modification, as described in the specification
  45.286 +     * for the (protected) {@link #modCount} field.
  45.287 +     *
  45.288 +     * @return an iterator over the elements in this list in proper sequence
  45.289 +     */
  45.290 +    public Iterator<E> iterator() {
  45.291 +        return new Itr();
  45.292 +    }
  45.293 +
  45.294 +    /**
  45.295 +     * {@inheritDoc}
  45.296 +     *
  45.297 +     * <p>This implementation returns {@code listIterator(0)}.
  45.298 +     *
  45.299 +     * @see #listIterator(int)
  45.300 +     */
  45.301 +    public ListIterator<E> listIterator() {
  45.302 +        return listIterator(0);
  45.303 +    }
  45.304 +
  45.305 +    /**
  45.306 +     * {@inheritDoc}
  45.307 +     *
  45.308 +     * <p>This implementation returns a straightforward implementation of the
  45.309 +     * {@code ListIterator} interface that extends the implementation of the
  45.310 +     * {@code Iterator} interface returned by the {@code iterator()} method.
  45.311 +     * The {@code ListIterator} implementation relies on the backing list's
  45.312 +     * {@code get(int)}, {@code set(int, E)}, {@code add(int, E)}
  45.313 +     * and {@code remove(int)} methods.
  45.314 +     *
  45.315 +     * <p>Note that the list iterator returned by this implementation will
  45.316 +     * throw an {@link UnsupportedOperationException} in response to its
  45.317 +     * {@code remove}, {@code set} and {@code add} methods unless the
  45.318 +     * list's {@code remove(int)}, {@code set(int, E)}, and
  45.319 +     * {@code add(int, E)} methods are overridden.
  45.320 +     *
  45.321 +     * <p>This implementation can be made to throw runtime exceptions in the
  45.322 +     * face of concurrent modification, as described in the specification for
  45.323 +     * the (protected) {@link #modCount} field.
  45.324 +     *
  45.325 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  45.326 +     */
  45.327 +    public ListIterator<E> listIterator(final int index) {
  45.328 +        rangeCheckForAdd(index);
  45.329 +
  45.330 +        return new ListItr(index);
  45.331 +    }
  45.332 +
  45.333 +    private class Itr implements Iterator<E> {
  45.334 +        /**
  45.335 +         * Index of element to be returned by subsequent call to next.
  45.336 +         */
  45.337 +        int cursor = 0;
  45.338 +
  45.339 +        /**
  45.340 +         * Index of element returned by most recent call to next or
  45.341 +         * previous.  Reset to -1 if this element is deleted by a call
  45.342 +         * to remove.
  45.343 +         */
  45.344 +        int lastRet = -1;
  45.345 +
  45.346 +        /**
  45.347 +         * The modCount value that the iterator believes that the backing
  45.348 +         * List should have.  If this expectation is violated, the iterator
  45.349 +         * has detected concurrent modification.
  45.350 +         */
  45.351 +        int expectedModCount = modCount;
  45.352 +
  45.353 +        public boolean hasNext() {
  45.354 +            return cursor != size();
  45.355 +        }
  45.356 +
  45.357 +        public E next() {
  45.358 +            checkForComodification();
  45.359 +            try {
  45.360 +                int i = cursor;
  45.361 +                E next = get(i);
  45.362 +                lastRet = i;
  45.363 +                cursor = i + 1;
  45.364 +                return next;
  45.365 +            } catch (IndexOutOfBoundsException e) {
  45.366 +                checkForComodification();
  45.367 +                throw new NoSuchElementException();
  45.368 +            }
  45.369 +        }
  45.370 +
  45.371 +        public void remove() {
  45.372 +            if (lastRet < 0)
  45.373 +                throw new IllegalStateException();
  45.374 +            checkForComodification();
  45.375 +
  45.376 +            try {
  45.377 +                AbstractList.this.remove(lastRet);
  45.378 +                if (lastRet < cursor)
  45.379 +                    cursor--;
  45.380 +                lastRet = -1;
  45.381 +                expectedModCount = modCount;
  45.382 +            } catch (IndexOutOfBoundsException e) {
  45.383 +                throw new ConcurrentModificationException();
  45.384 +            }
  45.385 +        }
  45.386 +
  45.387 +        final void checkForComodification() {
  45.388 +            if (modCount != expectedModCount)
  45.389 +                throw new ConcurrentModificationException();
  45.390 +        }
  45.391 +    }
  45.392 +
  45.393 +    private class ListItr extends Itr implements ListIterator<E> {
  45.394 +        ListItr(int index) {
  45.395 +            cursor = index;
  45.396 +        }
  45.397 +
  45.398 +        public boolean hasPrevious() {
  45.399 +            return cursor != 0;
  45.400 +        }
  45.401 +
  45.402 +        public E previous() {
  45.403 +            checkForComodification();
  45.404 +            try {
  45.405 +                int i = cursor - 1;
  45.406 +                E previous = get(i);
  45.407 +                lastRet = cursor = i;
  45.408 +                return previous;
  45.409 +            } catch (IndexOutOfBoundsException e) {
  45.410 +                checkForComodification();
  45.411 +                throw new NoSuchElementException();
  45.412 +            }
  45.413 +        }
  45.414 +
  45.415 +        public int nextIndex() {
  45.416 +            return cursor;
  45.417 +        }
  45.418 +
  45.419 +        public int previousIndex() {
  45.420 +            return cursor-1;
  45.421 +        }
  45.422 +
  45.423 +        public void set(E e) {
  45.424 +            if (lastRet < 0)
  45.425 +                throw new IllegalStateException();
  45.426 +            checkForComodification();
  45.427 +
  45.428 +            try {
  45.429 +                AbstractList.this.set(lastRet, e);
  45.430 +                expectedModCount = modCount;
  45.431 +            } catch (IndexOutOfBoundsException ex) {
  45.432 +                throw new ConcurrentModificationException();
  45.433 +            }
  45.434 +        }
  45.435 +
  45.436 +        public void add(E e) {
  45.437 +            checkForComodification();
  45.438 +
  45.439 +            try {
  45.440 +                int i = cursor;
  45.441 +                AbstractList.this.add(i, e);
  45.442 +                lastRet = -1;
  45.443 +                cursor = i + 1;
  45.444 +                expectedModCount = modCount;
  45.445 +            } catch (IndexOutOfBoundsException ex) {
  45.446 +                throw new ConcurrentModificationException();
  45.447 +            }
  45.448 +        }
  45.449 +    }
  45.450 +
  45.451 +    /**
  45.452 +     * {@inheritDoc}
  45.453 +     *
  45.454 +     * <p>This implementation returns a list that subclasses
  45.455 +     * {@code AbstractList}.  The subclass stores, in private fields, the
  45.456 +     * offset of the subList within the backing list, the size of the subList
  45.457 +     * (which can change over its lifetime), and the expected
  45.458 +     * {@code modCount} value of the backing list.  There are two variants
  45.459 +     * of the subclass, one of which implements {@code RandomAccess}.
  45.460 +     * If this list implements {@code RandomAccess} the returned list will
  45.461 +     * be an instance of the subclass that implements {@code RandomAccess}.
  45.462 +     *
  45.463 +     * <p>The subclass's {@code set(int, E)}, {@code get(int)},
  45.464 +     * {@code add(int, E)}, {@code remove(int)}, {@code addAll(int,
  45.465 +     * Collection)} and {@code removeRange(int, int)} methods all
  45.466 +     * delegate to the corresponding methods on the backing abstract list,
  45.467 +     * after bounds-checking the index and adjusting for the offset.  The
  45.468 +     * {@code addAll(Collection c)} method merely returns {@code addAll(size,
  45.469 +     * c)}.
  45.470 +     *
  45.471 +     * <p>The {@code listIterator(int)} method returns a "wrapper object"
  45.472 +     * over a list iterator on the backing list, which is created with the
  45.473 +     * corresponding method on the backing list.  The {@code iterator} method
  45.474 +     * merely returns {@code listIterator()}, and the {@code size} method
  45.475 +     * merely returns the subclass's {@code size} field.
  45.476 +     *
  45.477 +     * <p>All methods first check to see if the actual {@code modCount} of
  45.478 +     * the backing list is equal to its expected value, and throw a
  45.479 +     * {@code ConcurrentModificationException} if it is not.
  45.480 +     *
  45.481 +     * @throws IndexOutOfBoundsException if an endpoint index value is out of range
  45.482 +     *         {@code (fromIndex < 0 || toIndex > size)}
  45.483 +     * @throws IllegalArgumentException if the endpoint indices are out of order
  45.484 +     *         {@code (fromIndex > toIndex)}
  45.485 +     */
  45.486 +    public List<E> subList(int fromIndex, int toIndex) {
  45.487 +        return (this instanceof RandomAccess ?
  45.488 +                new RandomAccessSubList<>(this, fromIndex, toIndex) :
  45.489 +                new SubList<>(this, fromIndex, toIndex));
  45.490 +    }
  45.491 +
  45.492 +    // Comparison and hashing
  45.493 +
  45.494 +    /**
  45.495 +     * Compares the specified object with this list for equality.  Returns
  45.496 +     * {@code true} if and only if the specified object is also a list, both
  45.497 +     * lists have the same size, and all corresponding pairs of elements in
  45.498 +     * the two lists are <i>equal</i>.  (Two elements {@code e1} and
  45.499 +     * {@code e2} are <i>equal</i> if {@code (e1==null ? e2==null :
  45.500 +     * e1.equals(e2))}.)  In other words, two lists are defined to be
  45.501 +     * equal if they contain the same elements in the same order.<p>
  45.502 +     *
  45.503 +     * This implementation first checks if the specified object is this
  45.504 +     * list. If so, it returns {@code true}; if not, it checks if the
  45.505 +     * specified object is a list. If not, it returns {@code false}; if so,
  45.506 +     * it iterates over both lists, comparing corresponding pairs of elements.
  45.507 +     * If any comparison returns {@code false}, this method returns
  45.508 +     * {@code false}.  If either iterator runs out of elements before the
  45.509 +     * other it returns {@code false} (as the lists are of unequal length);
  45.510 +     * otherwise it returns {@code true} when the iterations complete.
  45.511 +     *
  45.512 +     * @param o the object to be compared for equality with this list
  45.513 +     * @return {@code true} if the specified object is equal to this list
  45.514 +     */
  45.515 +    public boolean equals(Object o) {
  45.516 +        if (o == this)
  45.517 +            return true;
  45.518 +        if (!(o instanceof List))
  45.519 +            return false;
  45.520 +
  45.521 +        ListIterator<E> e1 = listIterator();
  45.522 +        ListIterator e2 = ((List) o).listIterator();
  45.523 +        while (e1.hasNext() && e2.hasNext()) {
  45.524 +            E o1 = e1.next();
  45.525 +            Object o2 = e2.next();
  45.526 +            if (!(o1==null ? o2==null : o1.equals(o2)))
  45.527 +                return false;
  45.528 +        }
  45.529 +        return !(e1.hasNext() || e2.hasNext());
  45.530 +    }
  45.531 +
  45.532 +    /**
  45.533 +     * Returns the hash code value for this list.
  45.534 +     *
  45.535 +     * <p>This implementation uses exactly the code that is used to define the
  45.536 +     * list hash function in the documentation for the {@link List#hashCode}
  45.537 +     * method.
  45.538 +     *
  45.539 +     * @return the hash code value for this list
  45.540 +     */
  45.541 +    public int hashCode() {
  45.542 +        int hashCode = 1;
  45.543 +        for (E e : this)
  45.544 +            hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
  45.545 +        return hashCode;
  45.546 +    }
  45.547 +
  45.548 +    /**
  45.549 +     * Removes from this list all of the elements whose index is between
  45.550 +     * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
  45.551 +     * Shifts any succeeding elements to the left (reduces their index).
  45.552 +     * This call shortens the list by {@code (toIndex - fromIndex)} elements.
  45.553 +     * (If {@code toIndex==fromIndex}, this operation has no effect.)
  45.554 +     *
  45.555 +     * <p>This method is called by the {@code clear} operation on this list
  45.556 +     * and its subLists.  Overriding this method to take advantage of
  45.557 +     * the internals of the list implementation can <i>substantially</i>
  45.558 +     * improve the performance of the {@code clear} operation on this list
  45.559 +     * and its subLists.
  45.560 +     *
  45.561 +     * <p>This implementation gets a list iterator positioned before
  45.562 +     * {@code fromIndex}, and repeatedly calls {@code ListIterator.next}
  45.563 +     * followed by {@code ListIterator.remove} until the entire range has
  45.564 +     * been removed.  <b>Note: if {@code ListIterator.remove} requires linear
  45.565 +     * time, this implementation requires quadratic time.</b>
  45.566 +     *
  45.567 +     * @param fromIndex index of first element to be removed
  45.568 +     * @param toIndex index after last element to be removed
  45.569 +     */
  45.570 +    protected void removeRange(int fromIndex, int toIndex) {
  45.571 +        ListIterator<E> it = listIterator(fromIndex);
  45.572 +        for (int i=0, n=toIndex-fromIndex; i<n; i++) {
  45.573 +            it.next();
  45.574 +            it.remove();
  45.575 +        }
  45.576 +    }
  45.577 +
  45.578 +    /**
  45.579 +     * The number of times this list has been <i>structurally modified</i>.
  45.580 +     * Structural modifications are those that change the size of the
  45.581 +     * list, or otherwise perturb it in such a fashion that iterations in
  45.582 +     * progress may yield incorrect results.
  45.583 +     *
  45.584 +     * <p>This field is used by the iterator and list iterator implementation
  45.585 +     * returned by the {@code iterator} and {@code listIterator} methods.
  45.586 +     * If the value of this field changes unexpectedly, the iterator (or list
  45.587 +     * iterator) will throw a {@code ConcurrentModificationException} in
  45.588 +     * response to the {@code next}, {@code remove}, {@code previous},
  45.589 +     * {@code set} or {@code add} operations.  This provides
  45.590 +     * <i>fail-fast</i> behavior, rather than non-deterministic behavior in
  45.591 +     * the face of concurrent modification during iteration.
  45.592 +     *
  45.593 +     * <p><b>Use of this field by subclasses is optional.</b> If a subclass
  45.594 +     * wishes to provide fail-fast iterators (and list iterators), then it
  45.595 +     * merely has to increment this field in its {@code add(int, E)} and
  45.596 +     * {@code remove(int)} methods (and any other methods that it overrides
  45.597 +     * that result in structural modifications to the list).  A single call to
  45.598 +     * {@code add(int, E)} or {@code remove(int)} must add no more than
  45.599 +     * one to this field, or the iterators (and list iterators) will throw
  45.600 +     * bogus {@code ConcurrentModificationExceptions}.  If an implementation
  45.601 +     * does not wish to provide fail-fast iterators, this field may be
  45.602 +     * ignored.
  45.603 +     */
  45.604 +    protected transient int modCount = 0;
  45.605 +
  45.606 +    private void rangeCheckForAdd(int index) {
  45.607 +        if (index < 0 || index > size())
  45.608 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  45.609 +    }
  45.610 +
  45.611 +    private String outOfBoundsMsg(int index) {
  45.612 +        return "Index: "+index+", Size: "+size();
  45.613 +    }
  45.614 +}
  45.615 +
  45.616 +class SubList<E> extends AbstractList<E> {
  45.617 +    private final AbstractList<E> l;
  45.618 +    private final int offset;
  45.619 +    private int size;
  45.620 +
  45.621 +    SubList(AbstractList<E> list, int fromIndex, int toIndex) {
  45.622 +        if (fromIndex < 0)
  45.623 +            throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
  45.624 +        if (toIndex > list.size())
  45.625 +            throw new IndexOutOfBoundsException("toIndex = " + toIndex);
  45.626 +        if (fromIndex > toIndex)
  45.627 +            throw new IllegalArgumentException("fromIndex(" + fromIndex +
  45.628 +                                               ") > toIndex(" + toIndex + ")");
  45.629 +        l = list;
  45.630 +        offset = fromIndex;
  45.631 +        size = toIndex - fromIndex;
  45.632 +        this.modCount = l.modCount;
  45.633 +    }
  45.634 +
  45.635 +    public E set(int index, E element) {
  45.636 +        rangeCheck(index);
  45.637 +        checkForComodification();
  45.638 +        return l.set(index+offset, element);
  45.639 +    }
  45.640 +
  45.641 +    public E get(int index) {
  45.642 +        rangeCheck(index);
  45.643 +        checkForComodification();
  45.644 +        return l.get(index+offset);
  45.645 +    }
  45.646 +
  45.647 +    public int size() {
  45.648 +        checkForComodification();
  45.649 +        return size;
  45.650 +    }
  45.651 +
  45.652 +    public void add(int index, E element) {
  45.653 +        rangeCheckForAdd(index);
  45.654 +        checkForComodification();
  45.655 +        l.add(index+offset, element);
  45.656 +        this.modCount = l.modCount;
  45.657 +        size++;
  45.658 +    }
  45.659 +
  45.660 +    public E remove(int index) {
  45.661 +        rangeCheck(index);
  45.662 +        checkForComodification();
  45.663 +        E result = l.remove(index+offset);
  45.664 +        this.modCount = l.modCount;
  45.665 +        size--;
  45.666 +        return result;
  45.667 +    }
  45.668 +
  45.669 +    protected void removeRange(int fromIndex, int toIndex) {
  45.670 +        checkForComodification();
  45.671 +        l.removeRange(fromIndex+offset, toIndex+offset);
  45.672 +        this.modCount = l.modCount;
  45.673 +        size -= (toIndex-fromIndex);
  45.674 +    }
  45.675 +
  45.676 +    public boolean addAll(Collection<? extends E> c) {
  45.677 +        return addAll(size, c);
  45.678 +    }
  45.679 +
  45.680 +    public boolean addAll(int index, Collection<? extends E> c) {
  45.681 +        rangeCheckForAdd(index);
  45.682 +        int cSize = c.size();
  45.683 +        if (cSize==0)
  45.684 +            return false;
  45.685 +
  45.686 +        checkForComodification();
  45.687 +        l.addAll(offset+index, c);
  45.688 +        this.modCount = l.modCount;
  45.689 +        size += cSize;
  45.690 +        return true;
  45.691 +    }
  45.692 +
  45.693 +    public Iterator<E> iterator() {
  45.694 +        return listIterator();
  45.695 +    }
  45.696 +
  45.697 +    public ListIterator<E> listIterator(final int index) {
  45.698 +        checkForComodification();
  45.699 +        rangeCheckForAdd(index);
  45.700 +
  45.701 +        return new ListIterator<E>() {
  45.702 +            private final ListIterator<E> i = l.listIterator(index+offset);
  45.703 +
  45.704 +            public boolean hasNext() {
  45.705 +                return nextIndex() < size;
  45.706 +            }
  45.707 +
  45.708 +            public E next() {
  45.709 +                if (hasNext())
  45.710 +                    return i.next();
  45.711 +                else
  45.712 +                    throw new NoSuchElementException();
  45.713 +            }
  45.714 +
  45.715 +            public boolean hasPrevious() {
  45.716 +                return previousIndex() >= 0;
  45.717 +            }
  45.718 +
  45.719 +            public E previous() {
  45.720 +                if (hasPrevious())
  45.721 +                    return i.previous();
  45.722 +                else
  45.723 +                    throw new NoSuchElementException();
  45.724 +            }
  45.725 +
  45.726 +            public int nextIndex() {
  45.727 +                return i.nextIndex() - offset;
  45.728 +            }
  45.729 +
  45.730 +            public int previousIndex() {
  45.731 +                return i.previousIndex() - offset;
  45.732 +            }
  45.733 +
  45.734 +            public void remove() {
  45.735 +                i.remove();
  45.736 +                SubList.this.modCount = l.modCount;
  45.737 +                size--;
  45.738 +            }
  45.739 +
  45.740 +            public void set(E e) {
  45.741 +                i.set(e);
  45.742 +            }
  45.743 +
  45.744 +            public void add(E e) {
  45.745 +                i.add(e);
  45.746 +                SubList.this.modCount = l.modCount;
  45.747 +                size++;
  45.748 +            }
  45.749 +        };
  45.750 +    }
  45.751 +
  45.752 +    public List<E> subList(int fromIndex, int toIndex) {
  45.753 +        return new SubList<>(this, fromIndex, toIndex);
  45.754 +    }
  45.755 +
  45.756 +    private void rangeCheck(int index) {
  45.757 +        if (index < 0 || index >= size)
  45.758 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  45.759 +    }
  45.760 +
  45.761 +    private void rangeCheckForAdd(int index) {
  45.762 +        if (index < 0 || index > size)
  45.763 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  45.764 +    }
  45.765 +
  45.766 +    private String outOfBoundsMsg(int index) {
  45.767 +        return "Index: "+index+", Size: "+size;
  45.768 +    }
  45.769 +
  45.770 +    private void checkForComodification() {
  45.771 +        if (this.modCount != l.modCount)
  45.772 +            throw new ConcurrentModificationException();
  45.773 +    }
  45.774 +}
  45.775 +
  45.776 +class RandomAccessSubList<E> extends SubList<E> implements RandomAccess {
  45.777 +    RandomAccessSubList(AbstractList<E> list, int fromIndex, int toIndex) {
  45.778 +        super(list, fromIndex, toIndex);
  45.779 +    }
  45.780 +
  45.781 +    public List<E> subList(int fromIndex, int toIndex) {
  45.782 +        return new RandomAccessSubList<>(this, fromIndex, toIndex);
  45.783 +    }
  45.784 +}
    46.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.2 +++ b/emul/compact/src/main/java/java/util/AbstractMap.java	Sun Feb 03 07:48:42 2013 +0100
    46.3 @@ -0,0 +1,822 @@
    46.4 +/*
    46.5 + * Copyright (c) 1997, 2010, 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.util;
   46.30 +import java.util.Map.Entry;
   46.31 +
   46.32 +/**
   46.33 + * This class provides a skeletal implementation of the <tt>Map</tt>
   46.34 + * interface, to minimize the effort required to implement this interface.
   46.35 + *
   46.36 + * <p>To implement an unmodifiable map, the programmer needs only to extend this
   46.37 + * class and provide an implementation for the <tt>entrySet</tt> method, which
   46.38 + * returns a set-view of the map's mappings.  Typically, the returned set
   46.39 + * will, in turn, be implemented atop <tt>AbstractSet</tt>.  This set should
   46.40 + * not support the <tt>add</tt> or <tt>remove</tt> methods, and its iterator
   46.41 + * should not support the <tt>remove</tt> method.
   46.42 + *
   46.43 + * <p>To implement a modifiable map, the programmer must additionally override
   46.44 + * this class's <tt>put</tt> method (which otherwise throws an
   46.45 + * <tt>UnsupportedOperationException</tt>), and the iterator returned by
   46.46 + * <tt>entrySet().iterator()</tt> must additionally implement its
   46.47 + * <tt>remove</tt> method.
   46.48 + *
   46.49 + * <p>The programmer should generally provide a void (no argument) and map
   46.50 + * constructor, as per the recommendation in the <tt>Map</tt> interface
   46.51 + * specification.
   46.52 + *
   46.53 + * <p>The documentation for each non-abstract method in this class describes its
   46.54 + * implementation in detail.  Each of these methods may be overridden if the
   46.55 + * map being implemented admits a more efficient implementation.
   46.56 + *
   46.57 + * <p>This class is a member of the
   46.58 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   46.59 + * Java Collections Framework</a>.
   46.60 + *
   46.61 + * @param <K> the type of keys maintained by this map
   46.62 + * @param <V> the type of mapped values
   46.63 + *
   46.64 + * @author  Josh Bloch
   46.65 + * @author  Neal Gafter
   46.66 + * @see Map
   46.67 + * @see Collection
   46.68 + * @since 1.2
   46.69 + */
   46.70 +
   46.71 +public abstract class AbstractMap<K,V> implements Map<K,V> {
   46.72 +    /**
   46.73 +     * Sole constructor.  (For invocation by subclass constructors, typically
   46.74 +     * implicit.)
   46.75 +     */
   46.76 +    protected AbstractMap() {
   46.77 +    }
   46.78 +
   46.79 +    // Query Operations
   46.80 +
   46.81 +    /**
   46.82 +     * {@inheritDoc}
   46.83 +     *
   46.84 +     * <p>This implementation returns <tt>entrySet().size()</tt>.
   46.85 +     */
   46.86 +    public int size() {
   46.87 +        return entrySet().size();
   46.88 +    }
   46.89 +
   46.90 +    /**
   46.91 +     * {@inheritDoc}
   46.92 +     *
   46.93 +     * <p>This implementation returns <tt>size() == 0</tt>.
   46.94 +     */
   46.95 +    public boolean isEmpty() {
   46.96 +        return size() == 0;
   46.97 +    }
   46.98 +
   46.99 +    /**
  46.100 +     * {@inheritDoc}
  46.101 +     *
  46.102 +     * <p>This implementation iterates over <tt>entrySet()</tt> searching
  46.103 +     * for an entry with the specified value.  If such an entry is found,
  46.104 +     * <tt>true</tt> is returned.  If the iteration terminates without
  46.105 +     * finding such an entry, <tt>false</tt> is returned.  Note that this
  46.106 +     * implementation requires linear time in the size of the map.
  46.107 +     *
  46.108 +     * @throws ClassCastException   {@inheritDoc}
  46.109 +     * @throws NullPointerException {@inheritDoc}
  46.110 +     */
  46.111 +    public boolean containsValue(Object value) {
  46.112 +        Iterator<Entry<K,V>> i = entrySet().iterator();
  46.113 +        if (value==null) {
  46.114 +            while (i.hasNext()) {
  46.115 +                Entry<K,V> e = i.next();
  46.116 +                if (e.getValue()==null)
  46.117 +                    return true;
  46.118 +            }
  46.119 +        } else {
  46.120 +            while (i.hasNext()) {
  46.121 +                Entry<K,V> e = i.next();
  46.122 +                if (value.equals(e.getValue()))
  46.123 +                    return true;
  46.124 +            }
  46.125 +        }
  46.126 +        return false;
  46.127 +    }
  46.128 +
  46.129 +    /**
  46.130 +     * {@inheritDoc}
  46.131 +     *
  46.132 +     * <p>This implementation iterates over <tt>entrySet()</tt> searching
  46.133 +     * for an entry with the specified key.  If such an entry is found,
  46.134 +     * <tt>true</tt> is returned.  If the iteration terminates without
  46.135 +     * finding such an entry, <tt>false</tt> is returned.  Note that this
  46.136 +     * implementation requires linear time in the size of the map; many
  46.137 +     * implementations will override this method.
  46.138 +     *
  46.139 +     * @throws ClassCastException   {@inheritDoc}
  46.140 +     * @throws NullPointerException {@inheritDoc}
  46.141 +     */
  46.142 +    public boolean containsKey(Object key) {
  46.143 +        Iterator<Map.Entry<K,V>> i = entrySet().iterator();
  46.144 +        if (key==null) {
  46.145 +            while (i.hasNext()) {
  46.146 +                Entry<K,V> e = i.next();
  46.147 +                if (e.getKey()==null)
  46.148 +                    return true;
  46.149 +            }
  46.150 +        } else {
  46.151 +            while (i.hasNext()) {
  46.152 +                Entry<K,V> e = i.next();
  46.153 +                if (key.equals(e.getKey()))
  46.154 +                    return true;
  46.155 +            }
  46.156 +        }
  46.157 +        return false;
  46.158 +    }
  46.159 +
  46.160 +    /**
  46.161 +     * {@inheritDoc}
  46.162 +     *
  46.163 +     * <p>This implementation iterates over <tt>entrySet()</tt> searching
  46.164 +     * for an entry with the specified key.  If such an entry is found,
  46.165 +     * the entry's value is returned.  If the iteration terminates without
  46.166 +     * finding such an entry, <tt>null</tt> is returned.  Note that this
  46.167 +     * implementation requires linear time in the size of the map; many
  46.168 +     * implementations will override this method.
  46.169 +     *
  46.170 +     * @throws ClassCastException            {@inheritDoc}
  46.171 +     * @throws NullPointerException          {@inheritDoc}
  46.172 +     */
  46.173 +    public V get(Object key) {
  46.174 +        Iterator<Entry<K,V>> i = entrySet().iterator();
  46.175 +        if (key==null) {
  46.176 +            while (i.hasNext()) {
  46.177 +                Entry<K,V> e = i.next();
  46.178 +                if (e.getKey()==null)
  46.179 +                    return e.getValue();
  46.180 +            }
  46.181 +        } else {
  46.182 +            while (i.hasNext()) {
  46.183 +                Entry<K,V> e = i.next();
  46.184 +                if (key.equals(e.getKey()))
  46.185 +                    return e.getValue();
  46.186 +            }
  46.187 +        }
  46.188 +        return null;
  46.189 +    }
  46.190 +
  46.191 +
  46.192 +    // Modification Operations
  46.193 +
  46.194 +    /**
  46.195 +     * {@inheritDoc}
  46.196 +     *
  46.197 +     * <p>This implementation always throws an
  46.198 +     * <tt>UnsupportedOperationException</tt>.
  46.199 +     *
  46.200 +     * @throws UnsupportedOperationException {@inheritDoc}
  46.201 +     * @throws ClassCastException            {@inheritDoc}
  46.202 +     * @throws NullPointerException          {@inheritDoc}
  46.203 +     * @throws IllegalArgumentException      {@inheritDoc}
  46.204 +     */
  46.205 +    public V put(K key, V value) {
  46.206 +        throw new UnsupportedOperationException();
  46.207 +    }
  46.208 +
  46.209 +    /**
  46.210 +     * {@inheritDoc}
  46.211 +     *
  46.212 +     * <p>This implementation iterates over <tt>entrySet()</tt> searching for an
  46.213 +     * entry with the specified key.  If such an entry is found, its value is
  46.214 +     * obtained with its <tt>getValue</tt> operation, the entry is removed
  46.215 +     * from the collection (and the backing map) with the iterator's
  46.216 +     * <tt>remove</tt> operation, and the saved value is returned.  If the
  46.217 +     * iteration terminates without finding such an entry, <tt>null</tt> is
  46.218 +     * returned.  Note that this implementation requires linear time in the
  46.219 +     * size of the map; many implementations will override this method.
  46.220 +     *
  46.221 +     * <p>Note that this implementation throws an
  46.222 +     * <tt>UnsupportedOperationException</tt> if the <tt>entrySet</tt>
  46.223 +     * iterator does not support the <tt>remove</tt> method and this map
  46.224 +     * contains a mapping for the specified key.
  46.225 +     *
  46.226 +     * @throws UnsupportedOperationException {@inheritDoc}
  46.227 +     * @throws ClassCastException            {@inheritDoc}
  46.228 +     * @throws NullPointerException          {@inheritDoc}
  46.229 +     */
  46.230 +    public V remove(Object key) {
  46.231 +        Iterator<Entry<K,V>> i = entrySet().iterator();
  46.232 +        Entry<K,V> correctEntry = null;
  46.233 +        if (key==null) {
  46.234 +            while (correctEntry==null && i.hasNext()) {
  46.235 +                Entry<K,V> e = i.next();
  46.236 +                if (e.getKey()==null)
  46.237 +                    correctEntry = e;
  46.238 +            }
  46.239 +        } else {
  46.240 +            while (correctEntry==null && i.hasNext()) {
  46.241 +                Entry<K,V> e = i.next();
  46.242 +                if (key.equals(e.getKey()))
  46.243 +                    correctEntry = e;
  46.244 +            }
  46.245 +        }
  46.246 +
  46.247 +        V oldValue = null;
  46.248 +        if (correctEntry !=null) {
  46.249 +            oldValue = correctEntry.getValue();
  46.250 +            i.remove();
  46.251 +        }
  46.252 +        return oldValue;
  46.253 +    }
  46.254 +
  46.255 +
  46.256 +    // Bulk Operations
  46.257 +
  46.258 +    /**
  46.259 +     * {@inheritDoc}
  46.260 +     *
  46.261 +     * <p>This implementation iterates over the specified map's
  46.262 +     * <tt>entrySet()</tt> collection, and calls this map's <tt>put</tt>
  46.263 +     * operation once for each entry returned by the iteration.
  46.264 +     *
  46.265 +     * <p>Note that this implementation throws an
  46.266 +     * <tt>UnsupportedOperationException</tt> if this map does not support
  46.267 +     * the <tt>put</tt> operation and the specified map is nonempty.
  46.268 +     *
  46.269 +     * @throws UnsupportedOperationException {@inheritDoc}
  46.270 +     * @throws ClassCastException            {@inheritDoc}
  46.271 +     * @throws NullPointerException          {@inheritDoc}
  46.272 +     * @throws IllegalArgumentException      {@inheritDoc}
  46.273 +     */
  46.274 +    public void putAll(Map<? extends K, ? extends V> m) {
  46.275 +        for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
  46.276 +            put(e.getKey(), e.getValue());
  46.277 +    }
  46.278 +
  46.279 +    /**
  46.280 +     * {@inheritDoc}
  46.281 +     *
  46.282 +     * <p>This implementation calls <tt>entrySet().clear()</tt>.
  46.283 +     *
  46.284 +     * <p>Note that this implementation throws an
  46.285 +     * <tt>UnsupportedOperationException</tt> if the <tt>entrySet</tt>
  46.286 +     * does not support the <tt>clear</tt> operation.
  46.287 +     *
  46.288 +     * @throws UnsupportedOperationException {@inheritDoc}
  46.289 +     */
  46.290 +    public void clear() {
  46.291 +        entrySet().clear();
  46.292 +    }
  46.293 +
  46.294 +
  46.295 +    // Views
  46.296 +
  46.297 +    /**
  46.298 +     * Each of these fields are initialized to contain an instance of the
  46.299 +     * appropriate view the first time this view is requested.  The views are
  46.300 +     * stateless, so there's no reason to create more than one of each.
  46.301 +     */
  46.302 +    transient volatile Set<K>        keySet = null;
  46.303 +    transient volatile Collection<V> values = null;
  46.304 +
  46.305 +    /**
  46.306 +     * {@inheritDoc}
  46.307 +     *
  46.308 +     * <p>This implementation returns a set that subclasses {@link AbstractSet}.
  46.309 +     * The subclass's iterator method returns a "wrapper object" over this
  46.310 +     * map's <tt>entrySet()</tt> iterator.  The <tt>size</tt> method
  46.311 +     * delegates to this map's <tt>size</tt> method and the
  46.312 +     * <tt>contains</tt> method delegates to this map's
  46.313 +     * <tt>containsKey</tt> method.
  46.314 +     *
  46.315 +     * <p>The set is created the first time this method is called,
  46.316 +     * and returned in response to all subsequent calls.  No synchronization
  46.317 +     * is performed, so there is a slight chance that multiple calls to this
  46.318 +     * method will not all return the same set.
  46.319 +     */
  46.320 +    public Set<K> keySet() {
  46.321 +        if (keySet == null) {
  46.322 +            keySet = new AbstractSet<K>() {
  46.323 +                public Iterator<K> iterator() {
  46.324 +                    return new Iterator<K>() {
  46.325 +                        private Iterator<Entry<K,V>> i = entrySet().iterator();
  46.326 +
  46.327 +                        public boolean hasNext() {
  46.328 +                            return i.hasNext();
  46.329 +                        }
  46.330 +
  46.331 +                        public K next() {
  46.332 +                            return i.next().getKey();
  46.333 +                        }
  46.334 +
  46.335 +                        public void remove() {
  46.336 +                            i.remove();
  46.337 +                        }
  46.338 +                    };
  46.339 +                }
  46.340 +
  46.341 +                public int size() {
  46.342 +                    return AbstractMap.this.size();
  46.343 +                }
  46.344 +
  46.345 +                public boolean isEmpty() {
  46.346 +                    return AbstractMap.this.isEmpty();
  46.347 +                }
  46.348 +
  46.349 +                public void clear() {
  46.350 +                    AbstractMap.this.clear();
  46.351 +                }
  46.352 +
  46.353 +                public boolean contains(Object k) {
  46.354 +                    return AbstractMap.this.containsKey(k);
  46.355 +                }
  46.356 +            };
  46.357 +        }
  46.358 +        return keySet;
  46.359 +    }
  46.360 +
  46.361 +    /**
  46.362 +     * {@inheritDoc}
  46.363 +     *
  46.364 +     * <p>This implementation returns a collection that subclasses {@link
  46.365 +     * AbstractCollection}.  The subclass's iterator method returns a
  46.366 +     * "wrapper object" over this map's <tt>entrySet()</tt> iterator.
  46.367 +     * The <tt>size</tt> method delegates to this map's <tt>size</tt>
  46.368 +     * method and the <tt>contains</tt> method delegates to this map's
  46.369 +     * <tt>containsValue</tt> method.
  46.370 +     *
  46.371 +     * <p>The collection is created the first time this method is called, and
  46.372 +     * returned in response to all subsequent calls.  No synchronization is
  46.373 +     * performed, so there is a slight chance that multiple calls to this
  46.374 +     * method will not all return the same collection.
  46.375 +     */
  46.376 +    public Collection<V> values() {
  46.377 +        if (values == null) {
  46.378 +            values = new AbstractCollection<V>() {
  46.379 +                public Iterator<V> iterator() {
  46.380 +                    return new Iterator<V>() {
  46.381 +                        private Iterator<Entry<K,V>> i = entrySet().iterator();
  46.382 +
  46.383 +                        public boolean hasNext() {
  46.384 +                            return i.hasNext();
  46.385 +                        }
  46.386 +
  46.387 +                        public V next() {
  46.388 +                            return i.next().getValue();
  46.389 +                        }
  46.390 +
  46.391 +                        public void remove() {
  46.392 +                            i.remove();
  46.393 +                        }
  46.394 +                    };
  46.395 +                }
  46.396 +
  46.397 +                public int size() {
  46.398 +                    return AbstractMap.this.size();
  46.399 +                }
  46.400 +
  46.401 +                public boolean isEmpty() {
  46.402 +                    return AbstractMap.this.isEmpty();
  46.403 +                }
  46.404 +
  46.405 +                public void clear() {
  46.406 +                    AbstractMap.this.clear();
  46.407 +                }
  46.408 +
  46.409 +                public boolean contains(Object v) {
  46.410 +                    return AbstractMap.this.containsValue(v);
  46.411 +                }
  46.412 +            };
  46.413 +        }
  46.414 +        return values;
  46.415 +    }
  46.416 +
  46.417 +    public abstract Set<Entry<K,V>> entrySet();
  46.418 +
  46.419 +
  46.420 +    // Comparison and hashing
  46.421 +
  46.422 +    /**
  46.423 +     * Compares the specified object with this map for equality.  Returns
  46.424 +     * <tt>true</tt> if the given object is also a map and the two maps
  46.425 +     * represent the same mappings.  More formally, two maps <tt>m1</tt> and
  46.426 +     * <tt>m2</tt> represent the same mappings if
  46.427 +     * <tt>m1.entrySet().equals(m2.entrySet())</tt>.  This ensures that the
  46.428 +     * <tt>equals</tt> method works properly across different implementations
  46.429 +     * of the <tt>Map</tt> interface.
  46.430 +     *
  46.431 +     * <p>This implementation first checks if the specified object is this map;
  46.432 +     * if so it returns <tt>true</tt>.  Then, it checks if the specified
  46.433 +     * object is a map whose size is identical to the size of this map; if
  46.434 +     * not, it returns <tt>false</tt>.  If so, it iterates over this map's
  46.435 +     * <tt>entrySet</tt> collection, and checks that the specified map
  46.436 +     * contains each mapping that this map contains.  If the specified map
  46.437 +     * fails to contain such a mapping, <tt>false</tt> is returned.  If the
  46.438 +     * iteration completes, <tt>true</tt> is returned.
  46.439 +     *
  46.440 +     * @param o object to be compared for equality with this map
  46.441 +     * @return <tt>true</tt> if the specified object is equal to this map
  46.442 +     */
  46.443 +    public boolean equals(Object o) {
  46.444 +        if (o == this)
  46.445 +            return true;
  46.446 +
  46.447 +        if (!(o instanceof Map))
  46.448 +            return false;
  46.449 +        Map<K,V> m = (Map<K,V>) o;
  46.450 +        if (m.size() != size())
  46.451 +            return false;
  46.452 +
  46.453 +        try {
  46.454 +            Iterator<Entry<K,V>> i = entrySet().iterator();
  46.455 +            while (i.hasNext()) {
  46.456 +                Entry<K,V> e = i.next();
  46.457 +                K key = e.getKey();
  46.458 +                V value = e.getValue();
  46.459 +                if (value == null) {
  46.460 +                    if (!(m.get(key)==null && m.containsKey(key)))
  46.461 +                        return false;
  46.462 +                } else {
  46.463 +                    if (!value.equals(m.get(key)))
  46.464 +                        return false;
  46.465 +                }
  46.466 +            }
  46.467 +        } catch (ClassCastException unused) {
  46.468 +            return false;
  46.469 +        } catch (NullPointerException unused) {
  46.470 +            return false;
  46.471 +        }
  46.472 +
  46.473 +        return true;
  46.474 +    }
  46.475 +
  46.476 +    /**
  46.477 +     * Returns the hash code value for this map.  The hash code of a map is
  46.478 +     * defined to be the sum of the hash codes of each entry in the map's
  46.479 +     * <tt>entrySet()</tt> view.  This ensures that <tt>m1.equals(m2)</tt>
  46.480 +     * implies that <tt>m1.hashCode()==m2.hashCode()</tt> for any two maps
  46.481 +     * <tt>m1</tt> and <tt>m2</tt>, as required by the general contract of
  46.482 +     * {@link Object#hashCode}.
  46.483 +     *
  46.484 +     * <p>This implementation iterates over <tt>entrySet()</tt>, calling
  46.485 +     * {@link Map.Entry#hashCode hashCode()} on each element (entry) in the
  46.486 +     * set, and adding up the results.
  46.487 +     *
  46.488 +     * @return the hash code value for this map
  46.489 +     * @see Map.Entry#hashCode()
  46.490 +     * @see Object#equals(Object)
  46.491 +     * @see Set#equals(Object)
  46.492 +     */
  46.493 +    public int hashCode() {
  46.494 +        int h = 0;
  46.495 +        Iterator<Entry<K,V>> i = entrySet().iterator();
  46.496 +        while (i.hasNext())
  46.497 +            h += i.next().hashCode();
  46.498 +        return h;
  46.499 +    }
  46.500 +
  46.501 +    /**
  46.502 +     * Returns a string representation of this map.  The string representation
  46.503 +     * consists of a list of key-value mappings in the order returned by the
  46.504 +     * map's <tt>entrySet</tt> view's iterator, enclosed in braces
  46.505 +     * (<tt>"{}"</tt>).  Adjacent mappings are separated by the characters
  46.506 +     * <tt>", "</tt> (comma and space).  Each key-value mapping is rendered as
  46.507 +     * the key followed by an equals sign (<tt>"="</tt>) followed by the
  46.508 +     * associated value.  Keys and values are converted to strings as by
  46.509 +     * {@link String#valueOf(Object)}.
  46.510 +     *
  46.511 +     * @return a string representation of this map
  46.512 +     */
  46.513 +    public String toString() {
  46.514 +        Iterator<Entry<K,V>> i = entrySet().iterator();
  46.515 +        if (! i.hasNext())
  46.516 +            return "{}";
  46.517 +
  46.518 +        StringBuilder sb = new StringBuilder();
  46.519 +        sb.append('{');
  46.520 +        for (;;) {
  46.521 +            Entry<K,V> e = i.next();
  46.522 +            K key = e.getKey();
  46.523 +            V value = e.getValue();
  46.524 +            sb.append(key   == this ? "(this Map)" : key);
  46.525 +            sb.append('=');
  46.526 +            sb.append(value == this ? "(this Map)" : value);
  46.527 +            if (! i.hasNext())
  46.528 +                return sb.append('}').toString();
  46.529 +            sb.append(',').append(' ');
  46.530 +        }
  46.531 +    }
  46.532 +
  46.533 +    /**
  46.534 +     * Returns a shallow copy of this <tt>AbstractMap</tt> instance: the keys
  46.535 +     * and values themselves are not cloned.
  46.536 +     *
  46.537 +     * @return a shallow copy of this map
  46.538 +     */
  46.539 +    protected Object clone() throws CloneNotSupportedException {
  46.540 +        AbstractMap<K,V> result = (AbstractMap<K,V>)super.clone();
  46.541 +        result.keySet = null;
  46.542 +        result.values = null;
  46.543 +        return result;
  46.544 +    }
  46.545 +
  46.546 +    /**
  46.547 +     * Utility method for SimpleEntry and SimpleImmutableEntry.
  46.548 +     * Test for equality, checking for nulls.
  46.549 +     */
  46.550 +    private static boolean eq(Object o1, Object o2) {
  46.551 +        return o1 == null ? o2 == null : o1.equals(o2);
  46.552 +    }
  46.553 +
  46.554 +    // Implementation Note: SimpleEntry and SimpleImmutableEntry
  46.555 +    // are distinct unrelated classes, even though they share
  46.556 +    // some code. Since you can't add or subtract final-ness
  46.557 +    // of a field in a subclass, they can't share representations,
  46.558 +    // and the amount of duplicated code is too small to warrant
  46.559 +    // exposing a common abstract class.
  46.560 +
  46.561 +
  46.562 +    /**
  46.563 +     * An Entry maintaining a key and a value.  The value may be
  46.564 +     * changed using the <tt>setValue</tt> method.  This class
  46.565 +     * facilitates the process of building custom map
  46.566 +     * implementations. For example, it may be convenient to return
  46.567 +     * arrays of <tt>SimpleEntry</tt> instances in method
  46.568 +     * <tt>Map.entrySet().toArray</tt>.
  46.569 +     *
  46.570 +     * @since 1.6
  46.571 +     */
  46.572 +    public static class SimpleEntry<K,V>
  46.573 +        implements Entry<K,V>, java.io.Serializable
  46.574 +    {
  46.575 +        private static final long serialVersionUID = -8499721149061103585L;
  46.576 +
  46.577 +        private final K key;
  46.578 +        private V value;
  46.579 +
  46.580 +        /**
  46.581 +         * Creates an entry representing a mapping from the specified
  46.582 +         * key to the specified value.
  46.583 +         *
  46.584 +         * @param key the key represented by this entry
  46.585 +         * @param value the value represented by this entry
  46.586 +         */
  46.587 +        public SimpleEntry(K key, V value) {
  46.588 +            this.key   = key;
  46.589 +            this.value = value;
  46.590 +        }
  46.591 +
  46.592 +        /**
  46.593 +         * Creates an entry representing the same mapping as the
  46.594 +         * specified entry.
  46.595 +         *
  46.596 +         * @param entry the entry to copy
  46.597 +         */
  46.598 +        public SimpleEntry(Entry<? extends K, ? extends V> entry) {
  46.599 +            this.key   = entry.getKey();
  46.600 +            this.value = entry.getValue();
  46.601 +        }
  46.602 +
  46.603 +        /**
  46.604 +         * Returns the key corresponding to this entry.
  46.605 +         *
  46.606 +         * @return the key corresponding to this entry
  46.607 +         */
  46.608 +        public K getKey() {
  46.609 +            return key;
  46.610 +        }
  46.611 +
  46.612 +        /**
  46.613 +         * Returns the value corresponding to this entry.
  46.614 +         *
  46.615 +         * @return the value corresponding to this entry
  46.616 +         */
  46.617 +        public V getValue() {
  46.618 +            return value;
  46.619 +        }
  46.620 +
  46.621 +        /**
  46.622 +         * Replaces the value corresponding to this entry with the specified
  46.623 +         * value.
  46.624 +         *
  46.625 +         * @param value new value to be stored in this entry
  46.626 +         * @return the old value corresponding to the entry
  46.627 +         */
  46.628 +        public V setValue(V value) {
  46.629 +            V oldValue = this.value;
  46.630 +            this.value = value;
  46.631 +            return oldValue;
  46.632 +        }
  46.633 +
  46.634 +        /**
  46.635 +         * Compares the specified object with this entry for equality.
  46.636 +         * Returns {@code true} if the given object is also a map entry and
  46.637 +         * the two entries represent the same mapping.  More formally, two
  46.638 +         * entries {@code e1} and {@code e2} represent the same mapping
  46.639 +         * if<pre>
  46.640 +         *   (e1.getKey()==null ?
  46.641 +         *    e2.getKey()==null :
  46.642 +         *    e1.getKey().equals(e2.getKey()))
  46.643 +         *   &amp;&amp;
  46.644 +         *   (e1.getValue()==null ?
  46.645 +         *    e2.getValue()==null :
  46.646 +         *    e1.getValue().equals(e2.getValue()))</pre>
  46.647 +         * This ensures that the {@code equals} method works properly across
  46.648 +         * different implementations of the {@code Map.Entry} interface.
  46.649 +         *
  46.650 +         * @param o object to be compared for equality with this map entry
  46.651 +         * @return {@code true} if the specified object is equal to this map
  46.652 +         *         entry
  46.653 +         * @see    #hashCode
  46.654 +         */
  46.655 +        public boolean equals(Object o) {
  46.656 +            if (!(o instanceof Map.Entry))
  46.657 +                return false;
  46.658 +            Map.Entry e = (Map.Entry)o;
  46.659 +            return eq(key, e.getKey()) && eq(value, e.getValue());
  46.660 +        }
  46.661 +
  46.662 +        /**
  46.663 +         * Returns the hash code value for this map entry.  The hash code
  46.664 +         * of a map entry {@code e} is defined to be: <pre>
  46.665 +         *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
  46.666 +         *   (e.getValue()==null ? 0 : e.getValue().hashCode())</pre>
  46.667 +         * This ensures that {@code e1.equals(e2)} implies that
  46.668 +         * {@code e1.hashCode()==e2.hashCode()} for any two Entries
  46.669 +         * {@code e1} and {@code e2}, as required by the general
  46.670 +         * contract of {@link Object#hashCode}.
  46.671 +         *
  46.672 +         * @return the hash code value for this map entry
  46.673 +         * @see    #equals
  46.674 +         */
  46.675 +        public int hashCode() {
  46.676 +            return (key   == null ? 0 :   key.hashCode()) ^
  46.677 +                   (value == null ? 0 : value.hashCode());
  46.678 +        }
  46.679 +
  46.680 +        /**
  46.681 +         * Returns a String representation of this map entry.  This
  46.682 +         * implementation returns the string representation of this
  46.683 +         * entry's key followed by the equals character ("<tt>=</tt>")
  46.684 +         * followed by the string representation of this entry's value.
  46.685 +         *
  46.686 +         * @return a String representation of this map entry
  46.687 +         */
  46.688 +        public String toString() {
  46.689 +            return key + "=" + value;
  46.690 +        }
  46.691 +
  46.692 +    }
  46.693 +
  46.694 +    /**
  46.695 +     * An Entry maintaining an immutable key and value.  This class
  46.696 +     * does not support method <tt>setValue</tt>.  This class may be
  46.697 +     * convenient in methods that return thread-safe snapshots of
  46.698 +     * key-value mappings.
  46.699 +     *
  46.700 +     * @since 1.6
  46.701 +     */
  46.702 +    public static class SimpleImmutableEntry<K,V>
  46.703 +        implements Entry<K,V>, java.io.Serializable
  46.704 +    {
  46.705 +        private static final long serialVersionUID = 7138329143949025153L;
  46.706 +
  46.707 +        private final K key;
  46.708 +        private final V value;
  46.709 +
  46.710 +        /**
  46.711 +         * Creates an entry representing a mapping from the specified
  46.712 +         * key to the specified value.
  46.713 +         *
  46.714 +         * @param key the key represented by this entry
  46.715 +         * @param value the value represented by this entry
  46.716 +         */
  46.717 +        public SimpleImmutableEntry(K key, V value) {
  46.718 +            this.key   = key;
  46.719 +            this.value = value;
  46.720 +        }
  46.721 +
  46.722 +        /**
  46.723 +         * Creates an entry representing the same mapping as the
  46.724 +         * specified entry.
  46.725 +         *
  46.726 +         * @param entry the entry to copy
  46.727 +         */
  46.728 +        public SimpleImmutableEntry(Entry<? extends K, ? extends V> entry) {
  46.729 +            this.key   = entry.getKey();
  46.730 +            this.value = entry.getValue();
  46.731 +        }
  46.732 +
  46.733 +        /**
  46.734 +         * Returns the key corresponding to this entry.
  46.735 +         *
  46.736 +         * @return the key corresponding to this entry
  46.737 +         */
  46.738 +        public K getKey() {
  46.739 +            return key;
  46.740 +        }
  46.741 +
  46.742 +        /**
  46.743 +         * Returns the value corresponding to this entry.
  46.744 +         *
  46.745 +         * @return the value corresponding to this entry
  46.746 +         */
  46.747 +        public V getValue() {
  46.748 +            return value;
  46.749 +        }
  46.750 +
  46.751 +        /**
  46.752 +         * Replaces the value corresponding to this entry with the specified
  46.753 +         * value (optional operation).  This implementation simply throws
  46.754 +         * <tt>UnsupportedOperationException</tt>, as this class implements
  46.755 +         * an <i>immutable</i> map entry.
  46.756 +         *
  46.757 +         * @param value new value to be stored in this entry
  46.758 +         * @return (Does not return)
  46.759 +         * @throws UnsupportedOperationException always
  46.760 +         */
  46.761 +        public V setValue(V value) {
  46.762 +            throw new UnsupportedOperationException();
  46.763 +        }
  46.764 +
  46.765 +        /**
  46.766 +         * Compares the specified object with this entry for equality.
  46.767 +         * Returns {@code true} if the given object is also a map entry and
  46.768 +         * the two entries represent the same mapping.  More formally, two
  46.769 +         * entries {@code e1} and {@code e2} represent the same mapping
  46.770 +         * if<pre>
  46.771 +         *   (e1.getKey()==null ?
  46.772 +         *    e2.getKey()==null :
  46.773 +         *    e1.getKey().equals(e2.getKey()))
  46.774 +         *   &amp;&amp;
  46.775 +         *   (e1.getValue()==null ?
  46.776 +         *    e2.getValue()==null :
  46.777 +         *    e1.getValue().equals(e2.getValue()))</pre>
  46.778 +         * This ensures that the {@code equals} method works properly across
  46.779 +         * different implementations of the {@code Map.Entry} interface.
  46.780 +         *
  46.781 +         * @param o object to be compared for equality with this map entry
  46.782 +         * @return {@code true} if the specified object is equal to this map
  46.783 +         *         entry
  46.784 +         * @see    #hashCode
  46.785 +         */
  46.786 +        public boolean equals(Object o) {
  46.787 +            if (!(o instanceof Map.Entry))
  46.788 +                return false;
  46.789 +            Map.Entry e = (Map.Entry)o;
  46.790 +            return eq(key, e.getKey()) && eq(value, e.getValue());
  46.791 +        }
  46.792 +
  46.793 +        /**
  46.794 +         * Returns the hash code value for this map entry.  The hash code
  46.795 +         * of a map entry {@code e} is defined to be: <pre>
  46.796 +         *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
  46.797 +         *   (e.getValue()==null ? 0 : e.getValue().hashCode())</pre>
  46.798 +         * This ensures that {@code e1.equals(e2)} implies that
  46.799 +         * {@code e1.hashCode()==e2.hashCode()} for any two Entries
  46.800 +         * {@code e1} and {@code e2}, as required by the general
  46.801 +         * contract of {@link Object#hashCode}.
  46.802 +         *
  46.803 +         * @return the hash code value for this map entry
  46.804 +         * @see    #equals
  46.805 +         */
  46.806 +        public int hashCode() {
  46.807 +            return (key   == null ? 0 :   key.hashCode()) ^
  46.808 +                   (value == null ? 0 : value.hashCode());
  46.809 +        }
  46.810 +
  46.811 +        /**
  46.812 +         * Returns a String representation of this map entry.  This
  46.813 +         * implementation returns the string representation of this
  46.814 +         * entry's key followed by the equals character ("<tt>=</tt>")
  46.815 +         * followed by the string representation of this entry's value.
  46.816 +         *
  46.817 +         * @return a String representation of this map entry
  46.818 +         */
  46.819 +        public String toString() {
  46.820 +            return key + "=" + value;
  46.821 +        }
  46.822 +
  46.823 +    }
  46.824 +
  46.825 +}
    47.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.2 +++ b/emul/compact/src/main/java/java/util/AbstractQueue.java	Sun Feb 03 07:48:42 2013 +0100
    47.3 @@ -0,0 +1,192 @@
    47.4 +/*
    47.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    47.6 + *
    47.7 + * This code is free software; you can redistribute it and/or modify it
    47.8 + * under the terms of the GNU General Public License version 2 only, as
    47.9 + * published by the Free Software Foundation.  Oracle designates this
   47.10 + * particular file as subject to the "Classpath" exception as provided
   47.11 + * by Oracle in the LICENSE file that accompanied this code.
   47.12 + *
   47.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
   47.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   47.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   47.16 + * version 2 for more details (a copy is included in the LICENSE file that
   47.17 + * accompanied this code).
   47.18 + *
   47.19 + * You should have received a copy of the GNU General Public License version
   47.20 + * 2 along with this work; if not, write to the Free Software Foundation,
   47.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   47.22 + *
   47.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   47.24 + * or visit www.oracle.com if you need additional information or have any
   47.25 + * questions.
   47.26 + */
   47.27 +
   47.28 +/*
   47.29 + * This file is available under and governed by the GNU General Public
   47.30 + * License version 2 only, as published by the Free Software Foundation.
   47.31 + * However, the following notice accompanied the original version of this
   47.32 + * file:
   47.33 + *
   47.34 + * Written by Doug Lea with assistance from members of JCP JSR-166
   47.35 + * Expert Group and released to the public domain, as explained at
   47.36 + * http://creativecommons.org/publicdomain/zero/1.0/
   47.37 + */
   47.38 +
   47.39 +package java.util;
   47.40 +
   47.41 +/**
   47.42 + * This class provides skeletal implementations of some {@link Queue}
   47.43 + * operations. The implementations in this class are appropriate when
   47.44 + * the base implementation does <em>not</em> allow <tt>null</tt>
   47.45 + * elements.  Methods {@link #add add}, {@link #remove remove}, and
   47.46 + * {@link #element element} are based on {@link #offer offer}, {@link
   47.47 + * #poll poll}, and {@link #peek peek}, respectively, but throw
   47.48 + * exceptions instead of indicating failure via <tt>false</tt> or
   47.49 + * <tt>null</tt> returns.
   47.50 + *
   47.51 + * <p>A <tt>Queue</tt> implementation that extends this class must
   47.52 + * minimally define a method {@link Queue#offer} which does not permit
   47.53 + * insertion of <tt>null</tt> elements, along with methods {@link
   47.54 + * Queue#peek}, {@link Queue#poll}, {@link Collection#size}, and
   47.55 + * {@link Collection#iterator}.  Typically, additional methods will be
   47.56 + * overridden as well.  If these requirements cannot be met, consider
   47.57 + * instead subclassing {@link AbstractCollection}.
   47.58 + *
   47.59 + * <p>This class is a member of the
   47.60 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   47.61 + * Java Collections Framework</a>.
   47.62 + *
   47.63 + * @since 1.5
   47.64 + * @author Doug Lea
   47.65 + * @param <E> the type of elements held in this collection
   47.66 + */
   47.67 +public abstract class AbstractQueue<E>
   47.68 +    extends AbstractCollection<E>
   47.69 +    implements Queue<E> {
   47.70 +
   47.71 +    /**
   47.72 +     * Constructor for use by subclasses.
   47.73 +     */
   47.74 +    protected AbstractQueue() {
   47.75 +    }
   47.76 +
   47.77 +    /**
   47.78 +     * Inserts the specified element into this queue if it is possible to do so
   47.79 +     * immediately without violating capacity restrictions, returning
   47.80 +     * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt>
   47.81 +     * if no space is currently available.
   47.82 +     *
   47.83 +     * <p>This implementation returns <tt>true</tt> if <tt>offer</tt> succeeds,
   47.84 +     * else throws an <tt>IllegalStateException</tt>.
   47.85 +     *
   47.86 +     * @param e the element to add
   47.87 +     * @return <tt>true</tt> (as specified by {@link Collection#add})
   47.88 +     * @throws IllegalStateException if the element cannot be added at this
   47.89 +     *         time due to capacity restrictions
   47.90 +     * @throws ClassCastException if the class of the specified element
   47.91 +     *         prevents it from being added to this queue
   47.92 +     * @throws NullPointerException if the specified element is null and
   47.93 +     *         this queue does not permit null elements
   47.94 +     * @throws IllegalArgumentException if some property of this element
   47.95 +     *         prevents it from being added to this queue
   47.96 +     */
   47.97 +    public boolean add(E e) {
   47.98 +        if (offer(e))
   47.99 +            return true;
  47.100 +        else
  47.101 +            throw new IllegalStateException("Queue full");
  47.102 +    }
  47.103 +
  47.104 +    /**
  47.105 +     * Retrieves and removes the head of this queue.  This method differs
  47.106 +     * from {@link #poll poll} only in that it throws an exception if this
  47.107 +     * queue is empty.
  47.108 +     *
  47.109 +     * <p>This implementation returns the result of <tt>poll</tt>
  47.110 +     * unless the queue is empty.
  47.111 +     *
  47.112 +     * @return the head of this queue
  47.113 +     * @throws NoSuchElementException if this queue is empty
  47.114 +     */
  47.115 +    public E remove() {
  47.116 +        E x = poll();
  47.117 +        if (x != null)
  47.118 +            return x;
  47.119 +        else
  47.120 +            throw new NoSuchElementException();
  47.121 +    }
  47.122 +
  47.123 +    /**
  47.124 +     * Retrieves, but does not remove, the head of this queue.  This method
  47.125 +     * differs from {@link #peek peek} only in that it throws an exception if
  47.126 +     * this queue is empty.
  47.127 +     *
  47.128 +     * <p>This implementation returns the result of <tt>peek</tt>
  47.129 +     * unless the queue is empty.
  47.130 +     *
  47.131 +     * @return the head of this queue
  47.132 +     * @throws NoSuchElementException if this queue is empty
  47.133 +     */
  47.134 +    public E element() {
  47.135 +        E x = peek();
  47.136 +        if (x != null)
  47.137 +            return x;
  47.138 +        else
  47.139 +            throw new NoSuchElementException();
  47.140 +    }
  47.141 +
  47.142 +    /**
  47.143 +     * Removes all of the elements from this queue.
  47.144 +     * The queue will be empty after this call returns.
  47.145 +     *
  47.146 +     * <p>This implementation repeatedly invokes {@link #poll poll} until it
  47.147 +     * returns <tt>null</tt>.
  47.148 +     */
  47.149 +    public void clear() {
  47.150 +        while (poll() != null)
  47.151 +            ;
  47.152 +    }
  47.153 +
  47.154 +    /**
  47.155 +     * Adds all of the elements in the specified collection to this
  47.156 +     * queue.  Attempts to addAll of a queue to itself result in
  47.157 +     * <tt>IllegalArgumentException</tt>. Further, the behavior of
  47.158 +     * this operation is undefined if the specified collection is
  47.159 +     * modified while the operation is in progress.
  47.160 +     *
  47.161 +     * <p>This implementation iterates over the specified collection,
  47.162 +     * and adds each element returned by the iterator to this
  47.163 +     * queue, in turn.  A runtime exception encountered while
  47.164 +     * trying to add an element (including, in particular, a
  47.165 +     * <tt>null</tt> element) may result in only some of the elements
  47.166 +     * having been successfully added when the associated exception is
  47.167 +     * thrown.
  47.168 +     *
  47.169 +     * @param c collection containing elements to be added to this queue
  47.170 +     * @return <tt>true</tt> if this queue changed as a result of the call
  47.171 +     * @throws ClassCastException if the class of an element of the specified
  47.172 +     *         collection prevents it from being added to this queue
  47.173 +     * @throws NullPointerException if the specified collection contains a
  47.174 +     *         null element and this queue does not permit null elements,
  47.175 +     *         or if the specified collection is null
  47.176 +     * @throws IllegalArgumentException if some property of an element of the
  47.177 +     *         specified collection prevents it from being added to this
  47.178 +     *         queue, or if the specified collection is this queue
  47.179 +     * @throws IllegalStateException if not all the elements can be added at
  47.180 +     *         this time due to insertion restrictions
  47.181 +     * @see #add(Object)
  47.182 +     */
  47.183 +    public boolean addAll(Collection<? extends E> c) {
  47.184 +        if (c == null)
  47.185 +            throw new NullPointerException();
  47.186 +        if (c == this)
  47.187 +            throw new IllegalArgumentException();
  47.188 +        boolean modified = false;
  47.189 +        for (E e : c)
  47.190 +            if (add(e))
  47.191 +                modified = true;
  47.192 +        return modified;
  47.193 +    }
  47.194 +
  47.195 +}
    48.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.2 +++ b/emul/compact/src/main/java/java/util/AbstractSequentialList.java	Sun Feb 03 07:48:42 2013 +0100
    48.3 @@ -0,0 +1,253 @@
    48.4 +/*
    48.5 + * Copyright (c) 1997, 2006, 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.util;
   48.30 +
   48.31 +/**
   48.32 + * This class provides a skeletal implementation of the <tt>List</tt>
   48.33 + * interface to minimize the effort required to implement this interface
   48.34 + * backed by a "sequential access" data store (such as a linked list).  For
   48.35 + * random access data (such as an array), <tt>AbstractList</tt> should be used
   48.36 + * in preference to this class.<p>
   48.37 + *
   48.38 + * This class is the opposite of the <tt>AbstractList</tt> class in the sense
   48.39 + * that it implements the "random access" methods (<tt>get(int index)</tt>,
   48.40 + * <tt>set(int index, E element)</tt>, <tt>add(int index, E element)</tt> and
   48.41 + * <tt>remove(int index)</tt>) on top of the list's list iterator, instead of
   48.42 + * the other way around.<p>
   48.43 + *
   48.44 + * To implement a list the programmer needs only to extend this class and
   48.45 + * provide implementations for the <tt>listIterator</tt> and <tt>size</tt>
   48.46 + * methods.  For an unmodifiable list, the programmer need only implement the
   48.47 + * list iterator's <tt>hasNext</tt>, <tt>next</tt>, <tt>hasPrevious</tt>,
   48.48 + * <tt>previous</tt> and <tt>index</tt> methods.<p>
   48.49 + *
   48.50 + * For a modifiable list the programmer should additionally implement the list
   48.51 + * iterator's <tt>set</tt> method.  For a variable-size list the programmer
   48.52 + * should additionally implement the list iterator's <tt>remove</tt> and
   48.53 + * <tt>add</tt> methods.<p>
   48.54 + *
   48.55 + * The programmer should generally provide a void (no argument) and collection
   48.56 + * constructor, as per the recommendation in the <tt>Collection</tt> interface
   48.57 + * specification.<p>
   48.58 + *
   48.59 + * This class is a member of the
   48.60 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   48.61 + * Java Collections Framework</a>.
   48.62 + *
   48.63 + * @author  Josh Bloch
   48.64 + * @author  Neal Gafter
   48.65 + * @see Collection
   48.66 + * @see List
   48.67 + * @see AbstractList
   48.68 + * @see AbstractCollection
   48.69 + * @since 1.2
   48.70 + */
   48.71 +
   48.72 +public abstract class AbstractSequentialList<E> extends AbstractList<E> {
   48.73 +    /**
   48.74 +     * Sole constructor.  (For invocation by subclass constructors, typically
   48.75 +     * implicit.)
   48.76 +     */
   48.77 +    protected AbstractSequentialList() {
   48.78 +    }
   48.79 +
   48.80 +    /**
   48.81 +     * Returns the element at the specified position in this list.
   48.82 +     *
   48.83 +     * <p>This implementation first gets a list iterator pointing to the
   48.84 +     * indexed element (with <tt>listIterator(index)</tt>).  Then, it gets
   48.85 +     * the element using <tt>ListIterator.next</tt> and returns it.
   48.86 +     *
   48.87 +     * @throws IndexOutOfBoundsException {@inheritDoc}
   48.88 +     */
   48.89 +    public E get(int index) {
   48.90 +        try {
   48.91 +            return listIterator(index).next();
   48.92 +        } catch (NoSuchElementException exc) {
   48.93 +            throw new IndexOutOfBoundsException("Index: "+index);
   48.94 +        }
   48.95 +    }
   48.96 +
   48.97 +    /**
   48.98 +     * Replaces the element at the specified position in this list with the
   48.99 +     * specified element (optional operation).
  48.100 +     *
  48.101 +     * <p>This implementation first gets a list iterator pointing to the
  48.102 +     * indexed element (with <tt>listIterator(index)</tt>).  Then, it gets
  48.103 +     * the current element using <tt>ListIterator.next</tt> and replaces it
  48.104 +     * with <tt>ListIterator.set</tt>.
  48.105 +     *
  48.106 +     * <p>Note that this implementation will throw an
  48.107 +     * <tt>UnsupportedOperationException</tt> if the list iterator does not
  48.108 +     * implement the <tt>set</tt> operation.
  48.109 +     *
  48.110 +     * @throws UnsupportedOperationException {@inheritDoc}
  48.111 +     * @throws ClassCastException            {@inheritDoc}
  48.112 +     * @throws NullPointerException          {@inheritDoc}
  48.113 +     * @throws IllegalArgumentException      {@inheritDoc}
  48.114 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
  48.115 +     */
  48.116 +    public E set(int index, E element) {
  48.117 +        try {
  48.118 +            ListIterator<E> e = listIterator(index);
  48.119 +            E oldVal = e.next();
  48.120 +            e.set(element);
  48.121 +            return oldVal;
  48.122 +        } catch (NoSuchElementException exc) {
  48.123 +            throw new IndexOutOfBoundsException("Index: "+index);
  48.124 +        }
  48.125 +    }
  48.126 +
  48.127 +    /**
  48.128 +     * Inserts the specified element at the specified position in this list
  48.129 +     * (optional operation).  Shifts the element currently at that position
  48.130 +     * (if any) and any subsequent elements to the right (adds one to their
  48.131 +     * indices).
  48.132 +     *
  48.133 +     * <p>This implementation first gets a list iterator pointing to the
  48.134 +     * indexed element (with <tt>listIterator(index)</tt>).  Then, it
  48.135 +     * inserts the specified element with <tt>ListIterator.add</tt>.
  48.136 +     *
  48.137 +     * <p>Note that this implementation will throw an
  48.138 +     * <tt>UnsupportedOperationException</tt> if the list iterator does not
  48.139 +     * implement the <tt>add</tt> operation.
  48.140 +     *
  48.141 +     * @throws UnsupportedOperationException {@inheritDoc}
  48.142 +     * @throws ClassCastException            {@inheritDoc}
  48.143 +     * @throws NullPointerException          {@inheritDoc}
  48.144 +     * @throws IllegalArgumentException      {@inheritDoc}
  48.145 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
  48.146 +     */
  48.147 +    public void add(int index, E element) {
  48.148 +        try {
  48.149 +            listIterator(index).add(element);
  48.150 +        } catch (NoSuchElementException exc) {
  48.151 +            throw new IndexOutOfBoundsException("Index: "+index);
  48.152 +        }
  48.153 +    }
  48.154 +
  48.155 +    /**
  48.156 +     * Removes the element at the specified position in this list (optional
  48.157 +     * operation).  Shifts any subsequent elements to the left (subtracts one
  48.158 +     * from their indices).  Returns the element that was removed from the
  48.159 +     * list.
  48.160 +     *
  48.161 +     * <p>This implementation first gets a list iterator pointing to the
  48.162 +     * indexed element (with <tt>listIterator(index)</tt>).  Then, it removes
  48.163 +     * the element with <tt>ListIterator.remove</tt>.
  48.164 +     *
  48.165 +     * <p>Note that this implementation will throw an
  48.166 +     * <tt>UnsupportedOperationException</tt> if the list iterator does not
  48.167 +     * implement the <tt>remove</tt> operation.
  48.168 +     *
  48.169 +     * @throws UnsupportedOperationException {@inheritDoc}
  48.170 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
  48.171 +     */
  48.172 +    public E remove(int index) {
  48.173 +        try {
  48.174 +            ListIterator<E> e = listIterator(index);
  48.175 +            E outCast = e.next();
  48.176 +            e.remove();
  48.177 +            return outCast;
  48.178 +        } catch (NoSuchElementException exc) {
  48.179 +            throw new IndexOutOfBoundsException("Index: "+index);
  48.180 +        }
  48.181 +    }
  48.182 +
  48.183 +
  48.184 +    // Bulk Operations
  48.185 +
  48.186 +    /**
  48.187 +     * Inserts all of the elements in the specified collection into this
  48.188 +     * list at the specified position (optional operation).  Shifts the
  48.189 +     * element currently at that position (if any) and any subsequent
  48.190 +     * elements to the right (increases their indices).  The new elements
  48.191 +     * will appear in this list in the order that they are returned by the
  48.192 +     * specified collection's iterator.  The behavior of this operation is
  48.193 +     * undefined if the specified collection is modified while the
  48.194 +     * operation is in progress.  (Note that this will occur if the specified
  48.195 +     * collection is this list, and it's nonempty.)
  48.196 +     *
  48.197 +     * <p>This implementation gets an iterator over the specified collection and
  48.198 +     * a list iterator over this list pointing to the indexed element (with
  48.199 +     * <tt>listIterator(index)</tt>).  Then, it iterates over the specified
  48.200 +     * collection, inserting the elements obtained from the iterator into this
  48.201 +     * list, one at a time, using <tt>ListIterator.add</tt> followed by
  48.202 +     * <tt>ListIterator.next</tt> (to skip over the added element).
  48.203 +     *
  48.204 +     * <p>Note that this implementation will throw an
  48.205 +     * <tt>UnsupportedOperationException</tt> if the list iterator returned by
  48.206 +     * the <tt>listIterator</tt> method does not implement the <tt>add</tt>
  48.207 +     * operation.
  48.208 +     *
  48.209 +     * @throws UnsupportedOperationException {@inheritDoc}
  48.210 +     * @throws ClassCastException            {@inheritDoc}
  48.211 +     * @throws NullPointerException          {@inheritDoc}
  48.212 +     * @throws IllegalArgumentException      {@inheritDoc}
  48.213 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
  48.214 +     */
  48.215 +    public boolean addAll(int index, Collection<? extends E> c) {
  48.216 +        try {
  48.217 +            boolean modified = false;
  48.218 +            ListIterator<E> e1 = listIterator(index);
  48.219 +            Iterator<? extends E> e2 = c.iterator();
  48.220 +            while (e2.hasNext()) {
  48.221 +                e1.add(e2.next());
  48.222 +                modified = true;
  48.223 +            }
  48.224 +            return modified;
  48.225 +        } catch (NoSuchElementException exc) {
  48.226 +            throw new IndexOutOfBoundsException("Index: "+index);
  48.227 +        }
  48.228 +    }
  48.229 +
  48.230 +
  48.231 +    // Iterators
  48.232 +
  48.233 +    /**
  48.234 +     * Returns an iterator over the elements in this list (in proper
  48.235 +     * sequence).<p>
  48.236 +     *
  48.237 +     * This implementation merely returns a list iterator over the list.
  48.238 +     *
  48.239 +     * @return an iterator over the elements in this list (in proper sequence)
  48.240 +     */
  48.241 +    public Iterator<E> iterator() {
  48.242 +        return listIterator();
  48.243 +    }
  48.244 +
  48.245 +    /**
  48.246 +     * Returns a list iterator over the elements in this list (in proper
  48.247 +     * sequence).
  48.248 +     *
  48.249 +     * @param  index index of first element to be returned from the list
  48.250 +     *         iterator (by a call to the <code>next</code> method)
  48.251 +     * @return a list iterator over the elements in this list (in proper
  48.252 +     *         sequence)
  48.253 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  48.254 +     */
  48.255 +    public abstract ListIterator<E> listIterator(int index);
  48.256 +}
    49.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.2 +++ b/emul/compact/src/main/java/java/util/AbstractSet.java	Sun Feb 03 07:48:42 2013 +0100
    49.3 @@ -0,0 +1,185 @@
    49.4 +/*
    49.5 + * Copyright (c) 1997, 2006, 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.util;
   49.30 +
   49.31 +/**
   49.32 + * This class provides a skeletal implementation of the <tt>Set</tt>
   49.33 + * interface to minimize the effort required to implement this
   49.34 + * interface. <p>
   49.35 + *
   49.36 + * The process of implementing a set by extending this class is identical
   49.37 + * to that of implementing a Collection by extending AbstractCollection,
   49.38 + * except that all of the methods and constructors in subclasses of this
   49.39 + * class must obey the additional constraints imposed by the <tt>Set</tt>
   49.40 + * interface (for instance, the add method must not permit addition of
   49.41 + * multiple instances of an object to a set).<p>
   49.42 + *
   49.43 + * Note that this class does not override any of the implementations from
   49.44 + * the <tt>AbstractCollection</tt> class.  It merely adds implementations
   49.45 + * for <tt>equals</tt> and <tt>hashCode</tt>.<p>
   49.46 + *
   49.47 + * This class is a member of the
   49.48 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   49.49 + * Java Collections Framework</a>.
   49.50 + *
   49.51 + * @param <E> the type of elements maintained by this set
   49.52 + *
   49.53 + * @author  Josh Bloch
   49.54 + * @author  Neal Gafter
   49.55 + * @see Collection
   49.56 + * @see AbstractCollection
   49.57 + * @see Set
   49.58 + * @since 1.2
   49.59 + */
   49.60 +
   49.61 +public abstract class AbstractSet<E> extends AbstractCollection<E> implements Set<E> {
   49.62 +    /**
   49.63 +     * Sole constructor.  (For invocation by subclass constructors, typically
   49.64 +     * implicit.)
   49.65 +     */
   49.66 +    protected AbstractSet() {
   49.67 +    }
   49.68 +
   49.69 +    // Comparison and hashing
   49.70 +
   49.71 +    /**
   49.72 +     * Compares the specified object with this set for equality.  Returns
   49.73 +     * <tt>true</tt> if the given object is also a set, the two sets have
   49.74 +     * the same size, and every member of the given set is contained in
   49.75 +     * this set.  This ensures that the <tt>equals</tt> method works
   49.76 +     * properly across different implementations of the <tt>Set</tt>
   49.77 +     * interface.<p>
   49.78 +     *
   49.79 +     * This implementation first checks if the specified object is this
   49.80 +     * set; if so it returns <tt>true</tt>.  Then, it checks if the
   49.81 +     * specified object is a set whose size is identical to the size of
   49.82 +     * this set; if not, it returns false.  If so, it returns
   49.83 +     * <tt>containsAll((Collection) o)</tt>.
   49.84 +     *
   49.85 +     * @param o object to be compared for equality with this set
   49.86 +     * @return <tt>true</tt> if the specified object is equal to this set
   49.87 +     */
   49.88 +    public boolean equals(Object o) {
   49.89 +        if (o == this)
   49.90 +            return true;
   49.91 +
   49.92 +        if (!(o instanceof Set))
   49.93 +            return false;
   49.94 +        Collection c = (Collection) o;
   49.95 +        if (c.size() != size())
   49.96 +            return false;
   49.97 +        try {
   49.98 +            return containsAll(c);
   49.99 +        } catch (ClassCastException unused)   {
  49.100 +            return false;
  49.101 +        } catch (NullPointerException unused) {
  49.102 +            return false;
  49.103 +        }
  49.104 +    }
  49.105 +
  49.106 +    /**
  49.107 +     * Returns the hash code value for this set.  The hash code of a set is
  49.108 +     * defined to be the sum of the hash codes of the elements in the set,
  49.109 +     * where the hash code of a <tt>null</tt> element is defined to be zero.
  49.110 +     * This ensures that <tt>s1.equals(s2)</tt> implies that
  49.111 +     * <tt>s1.hashCode()==s2.hashCode()</tt> for any two sets <tt>s1</tt>
  49.112 +     * and <tt>s2</tt>, as required by the general contract of
  49.113 +     * {@link Object#hashCode}.
  49.114 +     *
  49.115 +     * <p>This implementation iterates over the set, calling the
  49.116 +     * <tt>hashCode</tt> method on each element in the set, and adding up
  49.117 +     * the results.
  49.118 +     *
  49.119 +     * @return the hash code value for this set
  49.120 +     * @see Object#equals(Object)
  49.121 +     * @see Set#equals(Object)
  49.122 +     */
  49.123 +    public int hashCode() {
  49.124 +        int h = 0;
  49.125 +        Iterator<E> i = iterator();
  49.126 +        while (i.hasNext()) {
  49.127 +            E obj = i.next();
  49.128 +            if (obj != null)
  49.129 +                h += obj.hashCode();
  49.130 +        }
  49.131 +        return h;
  49.132 +    }
  49.133 +
  49.134 +    /**
  49.135 +     * Removes from this set all of its elements that are contained in the
  49.136 +     * specified collection (optional operation).  If the specified
  49.137 +     * collection is also a set, this operation effectively modifies this
  49.138 +     * set so that its value is the <i>asymmetric set difference</i> of
  49.139 +     * the two sets.
  49.140 +     *
  49.141 +     * <p>This implementation determines which is the smaller of this set
  49.142 +     * and the specified collection, by invoking the <tt>size</tt>
  49.143 +     * method on each.  If this set has fewer elements, then the
  49.144 +     * implementation iterates over this set, checking each element
  49.145 +     * returned by the iterator in turn to see if it is contained in
  49.146 +     * the specified collection.  If it is so contained, it is removed
  49.147 +     * from this set with the iterator's <tt>remove</tt> method.  If
  49.148 +     * the specified collection has fewer elements, then the
  49.149 +     * implementation iterates over the specified collection, removing
  49.150 +     * from this set each element returned by the iterator, using this
  49.151 +     * set's <tt>remove</tt> method.
  49.152 +     *
  49.153 +     * <p>Note that this implementation will throw an
  49.154 +     * <tt>UnsupportedOperationException</tt> if the iterator returned by the
  49.155 +     * <tt>iterator</tt> method does not implement the <tt>remove</tt> method.
  49.156 +     *
  49.157 +     * @param  c collection containing elements to be removed from this set
  49.158 +     * @return <tt>true</tt> if this set changed as a result of the call
  49.159 +     * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
  49.160 +     *         is not supported by this set
  49.161 +     * @throws ClassCastException if the class of an element of this set
  49.162 +     *         is incompatible with the specified collection
  49.163 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  49.164 +     * @throws NullPointerException if this set contains a null element and the
  49.165 +     *         specified collection does not permit null elements
  49.166 +     * (<a href="Collection.html#optional-restrictions">optional</a>),
  49.167 +     *         or if the specified collection is null
  49.168 +     * @see #remove(Object)
  49.169 +     * @see #contains(Object)
  49.170 +     */
  49.171 +    public boolean removeAll(Collection<?> c) {
  49.172 +        boolean modified = false;
  49.173 +
  49.174 +        if (size() > c.size()) {
  49.175 +            for (Iterator<?> i = c.iterator(); i.hasNext(); )
  49.176 +                modified |= remove(i.next());
  49.177 +        } else {
  49.178 +            for (Iterator<?> i = iterator(); i.hasNext(); ) {
  49.179 +                if (c.contains(i.next())) {
  49.180 +                    i.remove();
  49.181 +                    modified = true;
  49.182 +                }
  49.183 +            }
  49.184 +        }
  49.185 +        return modified;
  49.186 +    }
  49.187 +
  49.188 +}
    50.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.2 +++ b/emul/compact/src/main/java/java/util/ArrayDeque.java	Sun Feb 03 07:48:42 2013 +0100
    50.3 @@ -0,0 +1,830 @@
    50.4 +/*
    50.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    50.6 + *
    50.7 + * This code is free software; you can redistribute it and/or modify it
    50.8 + * under the terms of the GNU General Public License version 2 only, as
    50.9 + * published by the Free Software Foundation.  Oracle designates this
   50.10 + * particular file as subject to the "Classpath" exception as provided
   50.11 + * by Oracle in the LICENSE file that accompanied this code.
   50.12 + *
   50.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
   50.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   50.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   50.16 + * version 2 for more details (a copy is included in the LICENSE file that
   50.17 + * accompanied this code).
   50.18 + *
   50.19 + * You should have received a copy of the GNU General Public License version
   50.20 + * 2 along with this work; if not, write to the Free Software Foundation,
   50.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   50.22 + *
   50.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   50.24 + * or visit www.oracle.com if you need additional information or have any
   50.25 + * questions.
   50.26 + */
   50.27 +
   50.28 +/*
   50.29 + * This file is available under and governed by the GNU General Public
   50.30 + * License version 2 only, as published by the Free Software Foundation.
   50.31 + * However, the following notice accompanied the original version of this
   50.32 + * file:
   50.33 + *
   50.34 + * Written by Josh Bloch of Google Inc. and released to the public domain,
   50.35 + * as explained at http://creativecommons.org/publicdomain/zero/1.0/.
   50.36 + */
   50.37 +
   50.38 +package java.util;
   50.39 +import java.io.*;
   50.40 +
   50.41 +/**
   50.42 + * Resizable-array implementation of the {@link Deque} interface.  Array
   50.43 + * deques have no capacity restrictions; they grow as necessary to support
   50.44 + * usage.  They are not thread-safe; in the absence of external
   50.45 + * synchronization, they do not support concurrent access by multiple threads.
   50.46 + * Null elements are prohibited.  This class is likely to be faster than
   50.47 + * {@link Stack} when used as a stack, and faster than {@link LinkedList}
   50.48 + * when used as a queue.
   50.49 + *
   50.50 + * <p>Most <tt>ArrayDeque</tt> operations run in amortized constant time.
   50.51 + * Exceptions include {@link #remove(Object) remove}, {@link
   50.52 + * #removeFirstOccurrence removeFirstOccurrence}, {@link #removeLastOccurrence
   50.53 + * removeLastOccurrence}, {@link #contains contains}, {@link #iterator
   50.54 + * iterator.remove()}, and the bulk operations, all of which run in linear
   50.55 + * time.
   50.56 + *
   50.57 + * <p>The iterators returned by this class's <tt>iterator</tt> method are
   50.58 + * <i>fail-fast</i>: If the deque is modified at any time after the iterator
   50.59 + * is created, in any way except through the iterator's own <tt>remove</tt>
   50.60 + * method, the iterator will generally throw a {@link
   50.61 + * ConcurrentModificationException}.  Thus, in the face of concurrent
   50.62 + * modification, the iterator fails quickly and cleanly, rather than risking
   50.63 + * arbitrary, non-deterministic behavior at an undetermined time in the
   50.64 + * future.
   50.65 + *
   50.66 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
   50.67 + * as it is, generally speaking, impossible to make any hard guarantees in the
   50.68 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
   50.69 + * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
   50.70 + * Therefore, it would be wrong to write a program that depended on this
   50.71 + * exception for its correctness: <i>the fail-fast behavior of iterators
   50.72 + * should be used only to detect bugs.</i>
   50.73 + *
   50.74 + * <p>This class and its iterator implement all of the
   50.75 + * <em>optional</em> methods of the {@link Collection} and {@link
   50.76 + * Iterator} interfaces.
   50.77 + *
   50.78 + * <p>This class is a member of the
   50.79 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   50.80 + * Java Collections Framework</a>.
   50.81 + *
   50.82 + * @author  Josh Bloch and Doug Lea
   50.83 + * @since   1.6
   50.84 + * @param <E> the type of elements held in this collection
   50.85 + */
   50.86 +public class ArrayDeque<E> extends AbstractCollection<E>
   50.87 +                           implements Deque<E>, Cloneable, Serializable
   50.88 +{
   50.89 +    /**
   50.90 +     * The array in which the elements of the deque are stored.
   50.91 +     * The capacity of the deque is the length of this array, which is
   50.92 +     * always a power of two. The array is never allowed to become
   50.93 +     * full, except transiently within an addX method where it is
   50.94 +     * resized (see doubleCapacity) immediately upon becoming full,
   50.95 +     * thus avoiding head and tail wrapping around to equal each
   50.96 +     * other.  We also guarantee that all array cells not holding
   50.97 +     * deque elements are always null.
   50.98 +     */
   50.99 +    private transient E[] elements;
  50.100 +
  50.101 +    /**
  50.102 +     * The index of the element at the head of the deque (which is the
  50.103 +     * element that would be removed by remove() or pop()); or an
  50.104 +     * arbitrary number equal to tail if the deque is empty.
  50.105 +     */
  50.106 +    private transient int head;
  50.107 +
  50.108 +    /**
  50.109 +     * The index at which the next element would be added to the tail
  50.110 +     * of the deque (via addLast(E), add(E), or push(E)).
  50.111 +     */
  50.112 +    private transient int tail;
  50.113 +
  50.114 +    /**
  50.115 +     * The minimum capacity that we'll use for a newly created deque.
  50.116 +     * Must be a power of 2.
  50.117 +     */
  50.118 +    private static final int MIN_INITIAL_CAPACITY = 8;
  50.119 +
  50.120 +    // ******  Array allocation and resizing utilities ******
  50.121 +
  50.122 +    /**
  50.123 +     * Allocate empty array to hold the given number of elements.
  50.124 +     *
  50.125 +     * @param numElements  the number of elements to hold
  50.126 +     */
  50.127 +    private void allocateElements(int numElements) {
  50.128 +        int initialCapacity = MIN_INITIAL_CAPACITY;
  50.129 +        // Find the best power of two to hold elements.
  50.130 +        // Tests "<=" because arrays aren't kept full.
  50.131 +        if (numElements >= initialCapacity) {
  50.132 +            initialCapacity = numElements;
  50.133 +            initialCapacity |= (initialCapacity >>>  1);
  50.134 +            initialCapacity |= (initialCapacity >>>  2);
  50.135 +            initialCapacity |= (initialCapacity >>>  4);
  50.136 +            initialCapacity |= (initialCapacity >>>  8);
  50.137 +            initialCapacity |= (initialCapacity >>> 16);
  50.138 +            initialCapacity++;
  50.139 +
  50.140 +            if (initialCapacity < 0)   // Too many elements, must back off
  50.141 +                initialCapacity >>>= 1;// Good luck allocating 2 ^ 30 elements
  50.142 +        }
  50.143 +        elements = (E[]) new Object[initialCapacity];
  50.144 +    }
  50.145 +
  50.146 +    /**
  50.147 +     * Double the capacity of this deque.  Call only when full, i.e.,
  50.148 +     * when head and tail have wrapped around to become equal.
  50.149 +     */
  50.150 +    private void doubleCapacity() {
  50.151 +        assert head == tail;
  50.152 +        int p = head;
  50.153 +        int n = elements.length;
  50.154 +        int r = n - p; // number of elements to the right of p
  50.155 +        int newCapacity = n << 1;
  50.156 +        if (newCapacity < 0)
  50.157 +            throw new IllegalStateException("Sorry, deque too big");
  50.158 +        Object[] a = new Object[newCapacity];
  50.159 +        System.arraycopy(elements, p, a, 0, r);
  50.160 +        System.arraycopy(elements, 0, a, r, p);
  50.161 +        elements = (E[])a;
  50.162 +        head = 0;
  50.163 +        tail = n;
  50.164 +    }
  50.165 +
  50.166 +    /**
  50.167 +     * Copies the elements from our element array into the specified array,
  50.168 +     * in order (from first to last element in the deque).  It is assumed
  50.169 +     * that the array is large enough to hold all elements in the deque.
  50.170 +     *
  50.171 +     * @return its argument
  50.172 +     */
  50.173 +    private <T> T[] copyElements(T[] a) {
  50.174 +        if (head < tail) {
  50.175 +            System.arraycopy(elements, head, a, 0, size());
  50.176 +        } else if (head > tail) {
  50.177 +            int headPortionLen = elements.length - head;
  50.178 +            System.arraycopy(elements, head, a, 0, headPortionLen);
  50.179 +            System.arraycopy(elements, 0, a, headPortionLen, tail);
  50.180 +        }
  50.181 +        return a;
  50.182 +    }
  50.183 +
  50.184 +    /**
  50.185 +     * Constructs an empty array deque with an initial capacity
  50.186 +     * sufficient to hold 16 elements.
  50.187 +     */
  50.188 +    public ArrayDeque() {
  50.189 +        elements = (E[]) new Object[16];
  50.190 +    }
  50.191 +
  50.192 +    /**
  50.193 +     * Constructs an empty array deque with an initial capacity
  50.194 +     * sufficient to hold the specified number of elements.
  50.195 +     *
  50.196 +     * @param numElements  lower bound on initial capacity of the deque
  50.197 +     */
  50.198 +    public ArrayDeque(int numElements) {
  50.199 +        allocateElements(numElements);
  50.200 +    }
  50.201 +
  50.202 +    /**
  50.203 +     * Constructs a deque containing the elements of the specified
  50.204 +     * collection, in the order they are returned by the collection's
  50.205 +     * iterator.  (The first element returned by the collection's
  50.206 +     * iterator becomes the first element, or <i>front</i> of the
  50.207 +     * deque.)
  50.208 +     *
  50.209 +     * @param c the collection whose elements are to be placed into the deque
  50.210 +     * @throws NullPointerException if the specified collection is null
  50.211 +     */
  50.212 +    public ArrayDeque(Collection<? extends E> c) {
  50.213 +        allocateElements(c.size());
  50.214 +        addAll(c);
  50.215 +    }
  50.216 +
  50.217 +    // The main insertion and extraction methods are addFirst,
  50.218 +    // addLast, pollFirst, pollLast. The other methods are defined in
  50.219 +    // terms of these.
  50.220 +
  50.221 +    /**
  50.222 +     * Inserts the specified element at the front of this deque.
  50.223 +     *
  50.224 +     * @param e the element to add
  50.225 +     * @throws NullPointerException if the specified element is null
  50.226 +     */
  50.227 +    public void addFirst(E e) {
  50.228 +        if (e == null)
  50.229 +            throw new NullPointerException();
  50.230 +        elements[head = (head - 1) & (elements.length - 1)] = e;
  50.231 +        if (head == tail)
  50.232 +            doubleCapacity();
  50.233 +    }
  50.234 +
  50.235 +    /**
  50.236 +     * Inserts the specified element at the end of this deque.
  50.237 +     *
  50.238 +     * <p>This method is equivalent to {@link #add}.
  50.239 +     *
  50.240 +     * @param e the element to add
  50.241 +     * @throws NullPointerException if the specified element is null
  50.242 +     */
  50.243 +    public void addLast(E e) {
  50.244 +        if (e == null)
  50.245 +            throw new NullPointerException();
  50.246 +        elements[tail] = e;
  50.247 +        if ( (tail = (tail + 1) & (elements.length - 1)) == head)
  50.248 +            doubleCapacity();
  50.249 +    }
  50.250 +
  50.251 +    /**
  50.252 +     * Inserts the specified element at the front of this deque.
  50.253 +     *
  50.254 +     * @param e the element to add
  50.255 +     * @return <tt>true</tt> (as specified by {@link Deque#offerFirst})
  50.256 +     * @throws NullPointerException if the specified element is null
  50.257 +     */
  50.258 +    public boolean offerFirst(E e) {
  50.259 +        addFirst(e);
  50.260 +        return true;
  50.261 +    }
  50.262 +
  50.263 +    /**
  50.264 +     * Inserts the specified element at the end of this deque.
  50.265 +     *
  50.266 +     * @param e the element to add
  50.267 +     * @return <tt>true</tt> (as specified by {@link Deque#offerLast})
  50.268 +     * @throws NullPointerException if the specified element is null
  50.269 +     */
  50.270 +    public boolean offerLast(E e) {
  50.271 +        addLast(e);
  50.272 +        return true;
  50.273 +    }
  50.274 +
  50.275 +    /**
  50.276 +     * @throws NoSuchElementException {@inheritDoc}
  50.277 +     */
  50.278 +    public E removeFirst() {
  50.279 +        E x = pollFirst();
  50.280 +        if (x == null)
  50.281 +            throw new NoSuchElementException();
  50.282 +        return x;
  50.283 +    }
  50.284 +
  50.285 +    /**
  50.286 +     * @throws NoSuchElementException {@inheritDoc}
  50.287 +     */
  50.288 +    public E removeLast() {
  50.289 +        E x = pollLast();
  50.290 +        if (x == null)
  50.291 +            throw new NoSuchElementException();
  50.292 +        return x;
  50.293 +    }
  50.294 +
  50.295 +    public E pollFirst() {
  50.296 +        int h = head;
  50.297 +        E result = elements[h]; // Element is null if deque empty
  50.298 +        if (result == null)
  50.299 +            return null;
  50.300 +        elements[h] = null;     // Must null out slot
  50.301 +        head = (h + 1) & (elements.length - 1);
  50.302 +        return result;
  50.303 +    }
  50.304 +
  50.305 +    public E pollLast() {
  50.306 +        int t = (tail - 1) & (elements.length - 1);
  50.307 +        E result = elements[t];
  50.308 +        if (result == null)
  50.309 +            return null;
  50.310 +        elements[t] = null;
  50.311 +        tail = t;
  50.312 +        return result;
  50.313 +    }
  50.314 +
  50.315 +    /**
  50.316 +     * @throws NoSuchElementException {@inheritDoc}
  50.317 +     */
  50.318 +    public E getFirst() {
  50.319 +        E x = elements[head];
  50.320 +        if (x == null)
  50.321 +            throw new NoSuchElementException();
  50.322 +        return x;
  50.323 +    }
  50.324 +
  50.325 +    /**
  50.326 +     * @throws NoSuchElementException {@inheritDoc}
  50.327 +     */
  50.328 +    public E getLast() {
  50.329 +        E x = elements[(tail - 1) & (elements.length - 1)];
  50.330 +        if (x == null)
  50.331 +            throw new NoSuchElementException();
  50.332 +        return x;
  50.333 +    }
  50.334 +
  50.335 +    public E peekFirst() {
  50.336 +        return elements[head]; // elements[head] is null if deque empty
  50.337 +    }
  50.338 +
  50.339 +    public E peekLast() {
  50.340 +        return elements[(tail - 1) & (elements.length - 1)];
  50.341 +    }
  50.342 +
  50.343 +    /**
  50.344 +     * Removes the first occurrence of the specified element in this
  50.345 +     * deque (when traversing the deque from head to tail).
  50.346 +     * If the deque does not contain the element, it is unchanged.
  50.347 +     * More formally, removes the first element <tt>e</tt> such that
  50.348 +     * <tt>o.equals(e)</tt> (if such an element exists).
  50.349 +     * Returns <tt>true</tt> if this deque contained the specified element
  50.350 +     * (or equivalently, if this deque changed as a result of the call).
  50.351 +     *
  50.352 +     * @param o element to be removed from this deque, if present
  50.353 +     * @return <tt>true</tt> if the deque contained the specified element
  50.354 +     */
  50.355 +    public boolean removeFirstOccurrence(Object o) {
  50.356 +        if (o == null)
  50.357 +            return false;
  50.358 +        int mask = elements.length - 1;
  50.359 +        int i = head;
  50.360 +        E x;
  50.361 +        while ( (x = elements[i]) != null) {
  50.362 +            if (o.equals(x)) {
  50.363 +                delete(i);
  50.364 +                return true;
  50.365 +            }
  50.366 +            i = (i + 1) & mask;
  50.367 +        }
  50.368 +        return false;
  50.369 +    }
  50.370 +
  50.371 +    /**
  50.372 +     * Removes the last occurrence of the specified element in this
  50.373 +     * deque (when traversing the deque from head to tail).
  50.374 +     * If the deque does not contain the element, it is unchanged.
  50.375 +     * More formally, removes the last element <tt>e</tt> such that
  50.376 +     * <tt>o.equals(e)</tt> (if such an element exists).
  50.377 +     * Returns <tt>true</tt> if this deque contained the specified element
  50.378 +     * (or equivalently, if this deque changed as a result of the call).
  50.379 +     *
  50.380 +     * @param o element to be removed from this deque, if present
  50.381 +     * @return <tt>true</tt> if the deque contained the specified element
  50.382 +     */
  50.383 +    public boolean removeLastOccurrence(Object o) {
  50.384 +        if (o == null)
  50.385 +            return false;
  50.386 +        int mask = elements.length - 1;
  50.387 +        int i = (tail - 1) & mask;
  50.388 +        E x;
  50.389 +        while ( (x = elements[i]) != null) {
  50.390 +            if (o.equals(x)) {
  50.391 +                delete(i);
  50.392 +                return true;
  50.393 +            }
  50.394 +            i = (i - 1) & mask;
  50.395 +        }
  50.396 +        return false;
  50.397 +    }
  50.398 +
  50.399 +    // *** Queue methods ***
  50.400 +
  50.401 +    /**
  50.402 +     * Inserts the specified element at the end of this deque.
  50.403 +     *
  50.404 +     * <p>This method is equivalent to {@link #addLast}.
  50.405 +     *
  50.406 +     * @param e the element to add
  50.407 +     * @return <tt>true</tt> (as specified by {@link Collection#add})
  50.408 +     * @throws NullPointerException if the specified element is null
  50.409 +     */
  50.410 +    public boolean add(E e) {
  50.411 +        addLast(e);
  50.412 +        return true;
  50.413 +    }
  50.414 +
  50.415 +    /**
  50.416 +     * Inserts the specified element at the end of this deque.
  50.417 +     *
  50.418 +     * <p>This method is equivalent to {@link #offerLast}.
  50.419 +     *
  50.420 +     * @param e the element to add
  50.421 +     * @return <tt>true</tt> (as specified by {@link Queue#offer})
  50.422 +     * @throws NullPointerException if the specified element is null
  50.423 +     */
  50.424 +    public boolean offer(E e) {
  50.425 +        return offerLast(e);
  50.426 +    }
  50.427 +
  50.428 +    /**
  50.429 +     * Retrieves and removes the head of the queue represented by this deque.
  50.430 +     *
  50.431 +     * This method differs from {@link #poll poll} only in that it throws an
  50.432 +     * exception if this deque is empty.
  50.433 +     *
  50.434 +     * <p>This method is equivalent to {@link #removeFirst}.
  50.435 +     *
  50.436 +     * @return the head of the queue represented by this deque
  50.437 +     * @throws NoSuchElementException {@inheritDoc}
  50.438 +     */
  50.439 +    public E remove() {
  50.440 +        return removeFirst();
  50.441 +    }
  50.442 +
  50.443 +    /**
  50.444 +     * Retrieves and removes the head of the queue represented by this deque
  50.445 +     * (in other words, the first element of this deque), or returns
  50.446 +     * <tt>null</tt> if this deque is empty.
  50.447 +     *
  50.448 +     * <p>This method is equivalent to {@link #pollFirst}.
  50.449 +     *
  50.450 +     * @return the head of the queue represented by this deque, or
  50.451 +     *         <tt>null</tt> if this deque is empty
  50.452 +     */
  50.453 +    public E poll() {
  50.454 +        return pollFirst();
  50.455 +    }
  50.456 +
  50.457 +    /**
  50.458 +     * Retrieves, but does not remove, the head of the queue represented by
  50.459 +     * this deque.  This method differs from {@link #peek peek} only in
  50.460 +     * that it throws an exception if this deque is empty.
  50.461 +     *
  50.462 +     * <p>This method is equivalent to {@link #getFirst}.
  50.463 +     *
  50.464 +     * @return the head of the queue represented by this deque
  50.465 +     * @throws NoSuchElementException {@inheritDoc}
  50.466 +     */
  50.467 +    public E element() {
  50.468 +        return getFirst();
  50.469 +    }
  50.470 +
  50.471 +    /**
  50.472 +     * Retrieves, but does not remove, the head of the queue represented by
  50.473 +     * this deque, or returns <tt>null</tt> if this deque is empty.
  50.474 +     *
  50.475 +     * <p>This method is equivalent to {@link #peekFirst}.
  50.476 +     *
  50.477 +     * @return the head of the queue represented by this deque, or
  50.478 +     *         <tt>null</tt> if this deque is empty
  50.479 +     */
  50.480 +    public E peek() {
  50.481 +        return peekFirst();
  50.482 +    }
  50.483 +
  50.484 +    // *** Stack methods ***
  50.485 +
  50.486 +    /**
  50.487 +     * Pushes an element onto the stack represented by this deque.  In other
  50.488 +     * words, inserts the element at the front of this deque.
  50.489 +     *
  50.490 +     * <p>This method is equivalent to {@link #addFirst}.
  50.491 +     *
  50.492 +     * @param e the element to push
  50.493 +     * @throws NullPointerException if the specified element is null
  50.494 +     */
  50.495 +    public void push(E e) {
  50.496 +        addFirst(e);
  50.497 +    }
  50.498 +
  50.499 +    /**
  50.500 +     * Pops an element from the stack represented by this deque.  In other
  50.501 +     * words, removes and returns the first element of this deque.
  50.502 +     *
  50.503 +     * <p>This method is equivalent to {@link #removeFirst()}.
  50.504 +     *
  50.505 +     * @return the element at the front of this deque (which is the top
  50.506 +     *         of the stack represented by this deque)
  50.507 +     * @throws NoSuchElementException {@inheritDoc}
  50.508 +     */
  50.509 +    public E pop() {
  50.510 +        return removeFirst();
  50.511 +    }
  50.512 +
  50.513 +    private void checkInvariants() {
  50.514 +        assert elements[tail] == null;
  50.515 +        assert head == tail ? elements[head] == null :
  50.516 +            (elements[head] != null &&
  50.517 +             elements[(tail - 1) & (elements.length - 1)] != null);
  50.518 +        assert elements[(head - 1) & (elements.length - 1)] == null;
  50.519 +    }
  50.520 +
  50.521 +    /**
  50.522 +     * Removes the element at the specified position in the elements array,
  50.523 +     * adjusting head and tail as necessary.  This can result in motion of
  50.524 +     * elements backwards or forwards in the array.
  50.525 +     *
  50.526 +     * <p>This method is called delete rather than remove to emphasize
  50.527 +     * that its semantics differ from those of {@link List#remove(int)}.
  50.528 +     *
  50.529 +     * @return true if elements moved backwards
  50.530 +     */
  50.531 +    private boolean delete(int i) {
  50.532 +        checkInvariants();
  50.533 +        final E[] elements = this.elements;
  50.534 +        final int mask = elements.length - 1;
  50.535 +        final int h = head;
  50.536 +        final int t = tail;
  50.537 +        final int front = (i - h) & mask;
  50.538 +        final int back  = (t - i) & mask;
  50.539 +
  50.540 +        // Invariant: head <= i < tail mod circularity
  50.541 +        if (front >= ((t - h) & mask))
  50.542 +            throw new ConcurrentModificationException();
  50.543 +
  50.544 +        // Optimize for least element motion
  50.545 +        if (front < back) {
  50.546 +            if (h <= i) {
  50.547 +                System.arraycopy(elements, h, elements, h + 1, front);
  50.548 +            } else { // Wrap around
  50.549 +                System.arraycopy(elements, 0, elements, 1, i);
  50.550 +                elements[0] = elements[mask];
  50.551 +                System.arraycopy(elements, h, elements, h + 1, mask - h);
  50.552 +            }
  50.553 +            elements[h] = null;
  50.554 +            head = (h + 1) & mask;
  50.555 +            return false;
  50.556 +        } else {
  50.557 +            if (i < t) { // Copy the null tail as well
  50.558 +                System.arraycopy(elements, i + 1, elements, i, back);
  50.559 +                tail = t - 1;
  50.560 +            } else { // Wrap around
  50.561 +                System.arraycopy(elements, i + 1, elements, i, mask - i);
  50.562 +                elements[mask] = elements[0];
  50.563 +                System.arraycopy(elements, 1, elements, 0, t);
  50.564 +                tail = (t - 1) & mask;
  50.565 +            }
  50.566 +            return true;
  50.567 +        }
  50.568 +    }
  50.569 +
  50.570 +    // *** Collection Methods ***
  50.571 +
  50.572 +    /**
  50.573 +     * Returns the number of elements in this deque.
  50.574 +     *
  50.575 +     * @return the number of elements in this deque
  50.576 +     */
  50.577 +    public int size() {
  50.578 +        return (tail - head) & (elements.length - 1);
  50.579 +    }
  50.580 +
  50.581 +    /**
  50.582 +     * Returns <tt>true</tt> if this deque contains no elements.
  50.583 +     *
  50.584 +     * @return <tt>true</tt> if this deque contains no elements
  50.585 +     */
  50.586 +    public boolean isEmpty() {
  50.587 +        return head == tail;
  50.588 +    }
  50.589 +
  50.590 +    /**
  50.591 +     * Returns an iterator over the elements in this deque.  The elements
  50.592 +     * will be ordered from first (head) to last (tail).  This is the same
  50.593 +     * order that elements would be dequeued (via successive calls to
  50.594 +     * {@link #remove} or popped (via successive calls to {@link #pop}).
  50.595 +     *
  50.596 +     * @return an iterator over the elements in this deque
  50.597 +     */
  50.598 +    public Iterator<E> iterator() {
  50.599 +        return new DeqIterator();
  50.600 +    }
  50.601 +
  50.602 +    public Iterator<E> descendingIterator() {
  50.603 +        return new DescendingIterator();
  50.604 +    }
  50.605 +
  50.606 +    private class DeqIterator implements Iterator<E> {
  50.607 +        /**
  50.608 +         * Index of element to be returned by subsequent call to next.
  50.609 +         */
  50.610 +        private int cursor = head;
  50.611 +
  50.612 +        /**
  50.613 +         * Tail recorded at construction (also in remove), to stop
  50.614 +         * iterator and also to check for comodification.
  50.615 +         */
  50.616 +        private int fence = tail;
  50.617 +
  50.618 +        /**
  50.619 +         * Index of element returned by most recent call to next.
  50.620 +         * Reset to -1 if element is deleted by a call to remove.
  50.621 +         */
  50.622 +        private int lastRet = -1;
  50.623 +
  50.624 +        public boolean hasNext() {
  50.625 +            return cursor != fence;
  50.626 +        }
  50.627 +
  50.628 +        public E next() {
  50.629 +            if (cursor == fence)
  50.630 +                throw new NoSuchElementException();
  50.631 +            E result = elements[cursor];
  50.632 +            // This check doesn't catch all possible comodifications,
  50.633 +            // but does catch the ones that corrupt traversal
  50.634 +            if (tail != fence || result == null)
  50.635 +                throw new ConcurrentModificationException();
  50.636 +            lastRet = cursor;
  50.637 +            cursor = (cursor + 1) & (elements.length - 1);
  50.638 +            return result;
  50.639 +        }
  50.640 +
  50.641 +        public void remove() {
  50.642 +            if (lastRet < 0)
  50.643 +                throw new IllegalStateException();
  50.644 +            if (delete(lastRet)) { // if left-shifted, undo increment in next()
  50.645 +                cursor = (cursor - 1) & (elements.length - 1);
  50.646 +                fence = tail;
  50.647 +            }
  50.648 +            lastRet = -1;
  50.649 +        }
  50.650 +    }
  50.651 +
  50.652 +    private class DescendingIterator implements Iterator<E> {
  50.653 +        /*
  50.654 +         * This class is nearly a mirror-image of DeqIterator, using
  50.655 +         * tail instead of head for initial cursor, and head instead of
  50.656 +         * tail for fence.
  50.657 +         */
  50.658 +        private int cursor = tail;
  50.659 +        private int fence = head;
  50.660 +        private int lastRet = -1;
  50.661 +
  50.662 +        public boolean hasNext() {
  50.663 +            return cursor != fence;
  50.664 +        }
  50.665 +
  50.666 +        public E next() {
  50.667 +            if (cursor == fence)
  50.668 +                throw new NoSuchElementException();
  50.669 +            cursor = (cursor - 1) & (elements.length - 1);
  50.670 +            E result = elements[cursor];
  50.671 +            if (head != fence || result == null)
  50.672 +                throw new ConcurrentModificationException();
  50.673 +            lastRet = cursor;
  50.674 +            return result;
  50.675 +        }
  50.676 +
  50.677 +        public void remove() {
  50.678 +            if (lastRet < 0)
  50.679 +                throw new IllegalStateException();
  50.680 +            if (!delete(lastRet)) {
  50.681 +                cursor = (cursor + 1) & (elements.length - 1);
  50.682 +                fence = head;
  50.683 +            }
  50.684 +            lastRet = -1;
  50.685 +        }
  50.686 +    }
  50.687 +
  50.688 +    /**
  50.689 +     * Returns <tt>true</tt> if this deque contains the specified element.
  50.690 +     * More formally, returns <tt>true</tt> if and only if this deque contains
  50.691 +     * at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>.
  50.692 +     *
  50.693 +     * @param o object to be checked for containment in this deque
  50.694 +     * @return <tt>true</tt> if this deque contains the specified element
  50.695 +     */
  50.696 +    public boolean contains(Object o) {
  50.697 +        if (o == null)
  50.698 +            return false;
  50.699 +        int mask = elements.length - 1;
  50.700 +        int i = head;
  50.701 +        E x;
  50.702 +        while ( (x = elements[i]) != null) {
  50.703 +            if (o.equals(x))
  50.704 +                return true;
  50.705 +            i = (i + 1) & mask;
  50.706 +        }
  50.707 +        return false;
  50.708 +    }
  50.709 +
  50.710 +    /**
  50.711 +     * Removes a single instance of the specified element from this deque.
  50.712 +     * If the deque does not contain the element, it is unchanged.
  50.713 +     * More formally, removes the first element <tt>e</tt> such that
  50.714 +     * <tt>o.equals(e)</tt> (if such an element exists).
  50.715 +     * Returns <tt>true</tt> if this deque contained the specified element
  50.716 +     * (or equivalently, if this deque changed as a result of the call).
  50.717 +     *
  50.718 +     * <p>This method is equivalent to {@link #removeFirstOccurrence}.
  50.719 +     *
  50.720 +     * @param o element to be removed from this deque, if present
  50.721 +     * @return <tt>true</tt> if this deque contained the specified element
  50.722 +     */
  50.723 +    public boolean remove(Object o) {
  50.724 +        return removeFirstOccurrence(o);
  50.725 +    }
  50.726 +
  50.727 +    /**
  50.728 +     * Removes all of the elements from this deque.
  50.729 +     * The deque will be empty after this call returns.
  50.730 +     */
  50.731 +    public void clear() {
  50.732 +        int h = head;
  50.733 +        int t = tail;
  50.734 +        if (h != t) { // clear all cells
  50.735 +            head = tail = 0;
  50.736 +            int i = h;
  50.737 +            int mask = elements.length - 1;
  50.738 +            do {
  50.739 +                elements[i] = null;
  50.740 +                i = (i + 1) & mask;
  50.741 +            } while (i != t);
  50.742 +        }
  50.743 +    }
  50.744 +
  50.745 +    /**
  50.746 +     * Returns an array containing all of the elements in this deque
  50.747 +     * in proper sequence (from first to last element).
  50.748 +     *
  50.749 +     * <p>The returned array will be "safe" in that no references to it are
  50.750 +     * maintained by this deque.  (In other words, this method must allocate
  50.751 +     * a new array).  The caller is thus free to modify the returned array.
  50.752 +     *
  50.753 +     * <p>This method acts as bridge between array-based and collection-based
  50.754 +     * APIs.
  50.755 +     *
  50.756 +     * @return an array containing all of the elements in this deque
  50.757 +     */
  50.758 +    public Object[] toArray() {
  50.759 +        return copyElements(new Object[size()]);
  50.760 +    }
  50.761 +
  50.762 +    /**
  50.763 +     * Returns an array containing all of the elements in this deque in
  50.764 +     * proper sequence (from first to last element); the runtime type of the
  50.765 +     * returned array is that of the specified array.  If the deque fits in
  50.766 +     * the specified array, it is returned therein.  Otherwise, a new array
  50.767 +     * is allocated with the runtime type of the specified array and the
  50.768 +     * size of this deque.
  50.769 +     *
  50.770 +     * <p>If this deque fits in the specified array with room to spare
  50.771 +     * (i.e., the array has more elements than this deque), the element in
  50.772 +     * the array immediately following the end of the deque is set to
  50.773 +     * <tt>null</tt>.
  50.774 +     *
  50.775 +     * <p>Like the {@link #toArray()} method, this method acts as bridge between
  50.776 +     * array-based and collection-based APIs.  Further, this method allows
  50.777 +     * precise control over the runtime type of the output array, and may,
  50.778 +     * under certain circumstances, be used to save allocation costs.
  50.779 +     *
  50.780 +     * <p>Suppose <tt>x</tt> is a deque known to contain only strings.
  50.781 +     * The following code can be used to dump the deque into a newly
  50.782 +     * allocated array of <tt>String</tt>:
  50.783 +     *
  50.784 +     * <pre>
  50.785 +     *     String[] y = x.toArray(new String[0]);</pre>
  50.786 +     *
  50.787 +     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
  50.788 +     * <tt>toArray()</tt>.
  50.789 +     *
  50.790 +     * @param a the array into which the elements of the deque are to
  50.791 +     *          be stored, if it is big enough; otherwise, a new array of the
  50.792 +     *          same runtime type is allocated for this purpose
  50.793 +     * @return an array containing all of the elements in this deque
  50.794 +     * @throws ArrayStoreException if the runtime type of the specified array
  50.795 +     *         is not a supertype of the runtime type of every element in
  50.796 +     *         this deque
  50.797 +     * @throws NullPointerException if the specified array is null
  50.798 +     */
  50.799 +    public <T> T[] toArray(T[] a) {
  50.800 +        int size = size();
  50.801 +        if (a.length < size)
  50.802 +            a = (T[])java.lang.reflect.Array.newInstance(
  50.803 +                    a.getClass().getComponentType(), size);
  50.804 +        copyElements(a);
  50.805 +        if (a.length > size)
  50.806 +            a[size] = null;
  50.807 +        return a;
  50.808 +    }
  50.809 +
  50.810 +    // *** Object methods ***
  50.811 +
  50.812 +    /**
  50.813 +     * Returns a copy of this deque.
  50.814 +     *
  50.815 +     * @return a copy of this deque
  50.816 +     */
  50.817 +    public ArrayDeque<E> clone() {
  50.818 +        try {
  50.819 +            ArrayDeque<E> result = (ArrayDeque<E>) super.clone();
  50.820 +            result.elements = Arrays.copyOf(elements, elements.length);
  50.821 +            return result;
  50.822 +
  50.823 +        } catch (CloneNotSupportedException e) {
  50.824 +            throw new AssertionError();
  50.825 +        }
  50.826 +    }
  50.827 +
  50.828 +    /**
  50.829 +     * Appease the serialization gods.
  50.830 +     */
  50.831 +    private static final long serialVersionUID = 2340985798034038923L;
  50.832 +
  50.833 +}
    51.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.2 +++ b/emul/compact/src/main/java/java/util/ArrayList.java	Sun Feb 03 07:48:42 2013 +0100
    51.3 @@ -0,0 +1,1088 @@
    51.4 +/*
    51.5 + * Copyright (c) 1997, 2010, 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.util;
   51.30 +
   51.31 +
   51.32 +/**
   51.33 + * Resizable-array implementation of the <tt>List</tt> interface.  Implements
   51.34 + * all optional list operations, and permits all elements, including
   51.35 + * <tt>null</tt>.  In addition to implementing the <tt>List</tt> interface,
   51.36 + * this class provides methods to manipulate the size of the array that is
   51.37 + * used internally to store the list.  (This class is roughly equivalent to
   51.38 + * <tt>Vector</tt>, except that it is unsynchronized.)
   51.39 + *
   51.40 + * <p>The <tt>size</tt>, <tt>isEmpty</tt>, <tt>get</tt>, <tt>set</tt>,
   51.41 + * <tt>iterator</tt>, and <tt>listIterator</tt> operations run in constant
   51.42 + * time.  The <tt>add</tt> operation runs in <i>amortized constant time</i>,
   51.43 + * that is, adding n elements requires O(n) time.  All of the other operations
   51.44 + * run in linear time (roughly speaking).  The constant factor is low compared
   51.45 + * to that for the <tt>LinkedList</tt> implementation.
   51.46 + *
   51.47 + * <p>Each <tt>ArrayList</tt> instance has a <i>capacity</i>.  The capacity is
   51.48 + * the size of the array used to store the elements in the list.  It is always
   51.49 + * at least as large as the list size.  As elements are added to an ArrayList,
   51.50 + * its capacity grows automatically.  The details of the growth policy are not
   51.51 + * specified beyond the fact that adding an element has constant amortized
   51.52 + * time cost.
   51.53 + *
   51.54 + * <p>An application can increase the capacity of an <tt>ArrayList</tt> instance
   51.55 + * before adding a large number of elements using the <tt>ensureCapacity</tt>
   51.56 + * operation.  This may reduce the amount of incremental reallocation.
   51.57 + *
   51.58 + * <p><strong>Note that this implementation is not synchronized.</strong>
   51.59 + * If multiple threads access an <tt>ArrayList</tt> instance concurrently,
   51.60 + * and at least one of the threads modifies the list structurally, it
   51.61 + * <i>must</i> be synchronized externally.  (A structural modification is
   51.62 + * any operation that adds or deletes one or more elements, or explicitly
   51.63 + * resizes the backing array; merely setting the value of an element is not
   51.64 + * a structural modification.)  This is typically accomplished by
   51.65 + * synchronizing on some object that naturally encapsulates the list.
   51.66 + *
   51.67 + * If no such object exists, the list should be "wrapped" using the
   51.68 + * {@link Collections#synchronizedList Collections.synchronizedList}
   51.69 + * method.  This is best done at creation time, to prevent accidental
   51.70 + * unsynchronized access to the list:<pre>
   51.71 + *   List list = Collections.synchronizedList(new ArrayList(...));</pre>
   51.72 + *
   51.73 + * <p><a name="fail-fast"/>
   51.74 + * The iterators returned by this class's {@link #iterator() iterator} and
   51.75 + * {@link #listIterator(int) listIterator} methods are <em>fail-fast</em>:
   51.76 + * if the list is structurally modified at any time after the iterator is
   51.77 + * created, in any way except through the iterator's own
   51.78 + * {@link ListIterator#remove() remove} or
   51.79 + * {@link ListIterator#add(Object) add} methods, the iterator will throw a
   51.80 + * {@link ConcurrentModificationException}.  Thus, in the face of
   51.81 + * concurrent modification, the iterator fails quickly and cleanly, rather
   51.82 + * than risking arbitrary, non-deterministic behavior at an undetermined
   51.83 + * time in the future.
   51.84 + *
   51.85 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
   51.86 + * as it is, generally speaking, impossible to make any hard guarantees in the
   51.87 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
   51.88 + * throw {@code ConcurrentModificationException} on a best-effort basis.
   51.89 + * Therefore, it would be wrong to write a program that depended on this
   51.90 + * exception for its correctness:  <i>the fail-fast behavior of iterators
   51.91 + * should be used only to detect bugs.</i>
   51.92 + *
   51.93 + * <p>This class is a member of the
   51.94 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   51.95 + * Java Collections Framework</a>.
   51.96 + *
   51.97 + * @author  Josh Bloch
   51.98 + * @author  Neal Gafter
   51.99 + * @see     Collection
  51.100 + * @see     List
  51.101 + * @see     LinkedList
  51.102 + * @see     Vector
  51.103 + * @since   1.2
  51.104 + */
  51.105 +
  51.106 +public class ArrayList<E> extends AbstractList<E>
  51.107 +        implements List<E>, RandomAccess, Cloneable, java.io.Serializable
  51.108 +{
  51.109 +    private static final long serialVersionUID = 8683452581122892189L;
  51.110 +
  51.111 +    /**
  51.112 +     * The array buffer into which the elements of the ArrayList are stored.
  51.113 +     * The capacity of the ArrayList is the length of this array buffer.
  51.114 +     */
  51.115 +    private transient Object[] elementData;
  51.116 +
  51.117 +    /**
  51.118 +     * The size of the ArrayList (the number of elements it contains).
  51.119 +     *
  51.120 +     * @serial
  51.121 +     */
  51.122 +    private int size;
  51.123 +
  51.124 +    /**
  51.125 +     * Constructs an empty list with the specified initial capacity.
  51.126 +     *
  51.127 +     * @param  initialCapacity  the initial capacity of the list
  51.128 +     * @throws IllegalArgumentException if the specified initial capacity
  51.129 +     *         is negative
  51.130 +     */
  51.131 +    public ArrayList(int initialCapacity) {
  51.132 +        super();
  51.133 +        if (initialCapacity < 0)
  51.134 +            throw new IllegalArgumentException("Illegal Capacity: "+
  51.135 +                                               initialCapacity);
  51.136 +        this.elementData = new Object[initialCapacity];
  51.137 +    }
  51.138 +
  51.139 +    /**
  51.140 +     * Constructs an empty list with an initial capacity of ten.
  51.141 +     */
  51.142 +    public ArrayList() {
  51.143 +        this(10);
  51.144 +    }
  51.145 +
  51.146 +    /**
  51.147 +     * Constructs a list containing the elements of the specified
  51.148 +     * collection, in the order they are returned by the collection's
  51.149 +     * iterator.
  51.150 +     *
  51.151 +     * @param c the collection whose elements are to be placed into this list
  51.152 +     * @throws NullPointerException if the specified collection is null
  51.153 +     */
  51.154 +    public ArrayList(Collection<? extends E> c) {
  51.155 +        elementData = c.toArray();
  51.156 +        size = elementData.length;
  51.157 +        // c.toArray might (incorrectly) not return Object[] (see 6260652)
  51.158 +        if (elementData.getClass() != Object[].class)
  51.159 +            elementData = Arrays.copyOf(elementData, size, Object[].class);
  51.160 +    }
  51.161 +
  51.162 +    /**
  51.163 +     * Trims the capacity of this <tt>ArrayList</tt> instance to be the
  51.164 +     * list's current size.  An application can use this operation to minimize
  51.165 +     * the storage of an <tt>ArrayList</tt> instance.
  51.166 +     */
  51.167 +    public void trimToSize() {
  51.168 +        modCount++;
  51.169 +        int oldCapacity = elementData.length;
  51.170 +        if (size < oldCapacity) {
  51.171 +            elementData = Arrays.copyOf(elementData, size);
  51.172 +        }
  51.173 +    }
  51.174 +
  51.175 +    /**
  51.176 +     * Increases the capacity of this <tt>ArrayList</tt> instance, if
  51.177 +     * necessary, to ensure that it can hold at least the number of elements
  51.178 +     * specified by the minimum capacity argument.
  51.179 +     *
  51.180 +     * @param   minCapacity   the desired minimum capacity
  51.181 +     */
  51.182 +    public void ensureCapacity(int minCapacity) {
  51.183 +        if (minCapacity > 0)
  51.184 +            ensureCapacityInternal(minCapacity);
  51.185 +    }
  51.186 +
  51.187 +    private void ensureCapacityInternal(int minCapacity) {
  51.188 +        modCount++;
  51.189 +        // overflow-conscious code
  51.190 +        if (minCapacity - elementData.length > 0)
  51.191 +            grow(minCapacity);
  51.192 +    }
  51.193 +
  51.194 +    /**
  51.195 +     * The maximum size of array to allocate.
  51.196 +     * Some VMs reserve some header words in an array.
  51.197 +     * Attempts to allocate larger arrays may result in
  51.198 +     * OutOfMemoryError: Requested array size exceeds VM limit
  51.199 +     */
  51.200 +    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
  51.201 +
  51.202 +    /**
  51.203 +     * Increases the capacity to ensure that it can hold at least the
  51.204 +     * number of elements specified by the minimum capacity argument.
  51.205 +     *
  51.206 +     * @param minCapacity the desired minimum capacity
  51.207 +     */
  51.208 +    private void grow(int minCapacity) {
  51.209 +        // overflow-conscious code
  51.210 +        int oldCapacity = elementData.length;
  51.211 +        int newCapacity = oldCapacity + (oldCapacity >> 1);
  51.212 +        if (newCapacity - minCapacity < 0)
  51.213 +            newCapacity = minCapacity;
  51.214 +        if (newCapacity - MAX_ARRAY_SIZE > 0)
  51.215 +            newCapacity = hugeCapacity(minCapacity);
  51.216 +        // minCapacity is usually close to size, so this is a win:
  51.217 +        elementData = Arrays.copyOf(elementData, newCapacity);
  51.218 +    }
  51.219 +
  51.220 +    private static int hugeCapacity(int minCapacity) {
  51.221 +        if (minCapacity < 0) // overflow
  51.222 +            throw new OutOfMemoryError();
  51.223 +        return (minCapacity > MAX_ARRAY_SIZE) ?
  51.224 +            Integer.MAX_VALUE :
  51.225 +            MAX_ARRAY_SIZE;
  51.226 +    }
  51.227 +
  51.228 +    /**
  51.229 +     * Returns the number of elements in this list.
  51.230 +     *
  51.231 +     * @return the number of elements in this list
  51.232 +     */
  51.233 +    public int size() {
  51.234 +        return size;
  51.235 +    }
  51.236 +
  51.237 +    /**
  51.238 +     * Returns <tt>true</tt> if this list contains no elements.
  51.239 +     *
  51.240 +     * @return <tt>true</tt> if this list contains no elements
  51.241 +     */
  51.242 +    public boolean isEmpty() {
  51.243 +        return size == 0;
  51.244 +    }
  51.245 +
  51.246 +    /**
  51.247 +     * Returns <tt>true</tt> if this list contains the specified element.
  51.248 +     * More formally, returns <tt>true</tt> if and only if this list contains
  51.249 +     * at least one element <tt>e</tt> such that
  51.250 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  51.251 +     *
  51.252 +     * @param o element whose presence in this list is to be tested
  51.253 +     * @return <tt>true</tt> if this list contains the specified element
  51.254 +     */
  51.255 +    public boolean contains(Object o) {
  51.256 +        return indexOf(o) >= 0;
  51.257 +    }
  51.258 +
  51.259 +    /**
  51.260 +     * Returns the index of the first occurrence of the specified element
  51.261 +     * in this list, or -1 if this list does not contain the element.
  51.262 +     * More formally, returns the lowest index <tt>i</tt> such that
  51.263 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  51.264 +     * or -1 if there is no such index.
  51.265 +     */
  51.266 +    public int indexOf(Object o) {
  51.267 +        if (o == null) {
  51.268 +            for (int i = 0; i < size; i++)
  51.269 +                if (elementData[i]==null)
  51.270 +                    return i;
  51.271 +        } else {
  51.272 +            for (int i = 0; i < size; i++)
  51.273 +                if (o.equals(elementData[i]))
  51.274 +                    return i;
  51.275 +        }
  51.276 +        return -1;
  51.277 +    }
  51.278 +
  51.279 +    /**
  51.280 +     * Returns the index of the last occurrence of the specified element
  51.281 +     * in this list, or -1 if this list does not contain the element.
  51.282 +     * More formally, returns the highest index <tt>i</tt> such that
  51.283 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  51.284 +     * or -1 if there is no such index.
  51.285 +     */
  51.286 +    public int lastIndexOf(Object o) {
  51.287 +        if (o == null) {
  51.288 +            for (int i = size-1; i >= 0; i--)
  51.289 +                if (elementData[i]==null)
  51.290 +                    return i;
  51.291 +        } else {
  51.292 +            for (int i = size-1; i >= 0; i--)
  51.293 +                if (o.equals(elementData[i]))
  51.294 +                    return i;
  51.295 +        }
  51.296 +        return -1;
  51.297 +    }
  51.298 +
  51.299 +    /**
  51.300 +     * Returns a shallow copy of this <tt>ArrayList</tt> instance.  (The
  51.301 +     * elements themselves are not copied.)
  51.302 +     *
  51.303 +     * @return a clone of this <tt>ArrayList</tt> instance
  51.304 +     */
  51.305 +    public Object clone() {
  51.306 +        try {
  51.307 +            @SuppressWarnings("unchecked")
  51.308 +                ArrayList<E> v = (ArrayList<E>) super.clone();
  51.309 +            v.elementData = Arrays.copyOf(elementData, size);
  51.310 +            v.modCount = 0;
  51.311 +            return v;
  51.312 +        } catch (CloneNotSupportedException e) {
  51.313 +            // this shouldn't happen, since we are Cloneable
  51.314 +            throw new InternalError();
  51.315 +        }
  51.316 +    }
  51.317 +
  51.318 +    /**
  51.319 +     * Returns an array containing all of the elements in this list
  51.320 +     * in proper sequence (from first to last element).
  51.321 +     *
  51.322 +     * <p>The returned array will be "safe" in that no references to it are
  51.323 +     * maintained by this list.  (In other words, this method must allocate
  51.324 +     * a new array).  The caller is thus free to modify the returned array.
  51.325 +     *
  51.326 +     * <p>This method acts as bridge between array-based and collection-based
  51.327 +     * APIs.
  51.328 +     *
  51.329 +     * @return an array containing all of the elements in this list in
  51.330 +     *         proper sequence
  51.331 +     */
  51.332 +    public Object[] toArray() {
  51.333 +        return Arrays.copyOf(elementData, size);
  51.334 +    }
  51.335 +
  51.336 +    /**
  51.337 +     * Returns an array containing all of the elements in this list in proper
  51.338 +     * sequence (from first to last element); the runtime type of the returned
  51.339 +     * array is that of the specified array.  If the list fits in the
  51.340 +     * specified array, it is returned therein.  Otherwise, a new array is
  51.341 +     * allocated with the runtime type of the specified array and the size of
  51.342 +     * this list.
  51.343 +     *
  51.344 +     * <p>If the list fits in the specified array with room to spare
  51.345 +     * (i.e., the array has more elements than the list), the element in
  51.346 +     * the array immediately following the end of the collection is set to
  51.347 +     * <tt>null</tt>.  (This is useful in determining the length of the
  51.348 +     * list <i>only</i> if the caller knows that the list does not contain
  51.349 +     * any null elements.)
  51.350 +     *
  51.351 +     * @param a the array into which the elements of the list are to
  51.352 +     *          be stored, if it is big enough; otherwise, a new array of the
  51.353 +     *          same runtime type is allocated for this purpose.
  51.354 +     * @return an array containing the elements of the list
  51.355 +     * @throws ArrayStoreException if the runtime type of the specified array
  51.356 +     *         is not a supertype of the runtime type of every element in
  51.357 +     *         this list
  51.358 +     * @throws NullPointerException if the specified array is null
  51.359 +     */
  51.360 +    @SuppressWarnings("unchecked")
  51.361 +    public <T> T[] toArray(T[] a) {
  51.362 +        if (a.length < size)
  51.363 +            // Make a new array of a's runtime type, but my contents:
  51.364 +            return (T[]) Arrays.copyOf(elementData, size, a.getClass());
  51.365 +        System.arraycopy(elementData, 0, a, 0, size);
  51.366 +        if (a.length > size)
  51.367 +            a[size] = null;
  51.368 +        return a;
  51.369 +    }
  51.370 +
  51.371 +    // Positional Access Operations
  51.372 +
  51.373 +    @SuppressWarnings("unchecked")
  51.374 +    E elementData(int index) {
  51.375 +        return (E) elementData[index];
  51.376 +    }
  51.377 +
  51.378 +    /**
  51.379 +     * Returns the element at the specified position in this list.
  51.380 +     *
  51.381 +     * @param  index index of the element to return
  51.382 +     * @return the element at the specified position in this list
  51.383 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  51.384 +     */
  51.385 +    public E get(int index) {
  51.386 +        rangeCheck(index);
  51.387 +
  51.388 +        return elementData(index);
  51.389 +    }
  51.390 +
  51.391 +    /**
  51.392 +     * Replaces the element at the specified position in this list with
  51.393 +     * the specified element.
  51.394 +     *
  51.395 +     * @param index index of the element to replace
  51.396 +     * @param element element to be stored at the specified position
  51.397 +     * @return the element previously at the specified position
  51.398 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  51.399 +     */
  51.400 +    public E set(int index, E element) {
  51.401 +        rangeCheck(index);
  51.402 +
  51.403 +        E oldValue = elementData(index);
  51.404 +        elementData[index] = element;
  51.405 +        return oldValue;
  51.406 +    }
  51.407 +
  51.408 +    /**
  51.409 +     * Appends the specified element to the end of this list.
  51.410 +     *
  51.411 +     * @param e element to be appended to this list
  51.412 +     * @return <tt>true</tt> (as specified by {@link Collection#add})
  51.413 +     */
  51.414 +    public boolean add(E e) {
  51.415 +        ensureCapacityInternal(size + 1);  // Increments modCount!!
  51.416 +        elementData[size++] = e;
  51.417 +        return true;
  51.418 +    }
  51.419 +
  51.420 +    /**
  51.421 +     * Inserts the specified element at the specified position in this
  51.422 +     * list. Shifts the element currently at that position (if any) and
  51.423 +     * any subsequent elements to the right (adds one to their indices).
  51.424 +     *
  51.425 +     * @param index index at which the specified element is to be inserted
  51.426 +     * @param element element to be inserted
  51.427 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  51.428 +     */
  51.429 +    public void add(int index, E element) {
  51.430 +        rangeCheckForAdd(index);
  51.431 +
  51.432 +        ensureCapacityInternal(size + 1);  // Increments modCount!!
  51.433 +        System.arraycopy(elementData, index, elementData, index + 1,
  51.434 +                         size - index);
  51.435 +        elementData[index] = element;
  51.436 +        size++;
  51.437 +    }
  51.438 +
  51.439 +    /**
  51.440 +     * Removes the element at the specified position in this list.
  51.441 +     * Shifts any subsequent elements to the left (subtracts one from their
  51.442 +     * indices).
  51.443 +     *
  51.444 +     * @param index the index of the element to be removed
  51.445 +     * @return the element that was removed from the list
  51.446 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  51.447 +     */
  51.448 +    public E remove(int index) {
  51.449 +        rangeCheck(index);
  51.450 +
  51.451 +        modCount++;
  51.452 +        E oldValue = elementData(index);
  51.453 +
  51.454 +        int numMoved = size - index - 1;
  51.455 +        if (numMoved > 0)
  51.456 +            System.arraycopy(elementData, index+1, elementData, index,
  51.457 +                             numMoved);
  51.458 +        elementData[--size] = null; // Let gc do its work
  51.459 +
  51.460 +        return oldValue;
  51.461 +    }
  51.462 +
  51.463 +    /**
  51.464 +     * Removes the first occurrence of the specified element from this list,
  51.465 +     * if it is present.  If the list does not contain the element, it is
  51.466 +     * unchanged.  More formally, removes the element with the lowest index
  51.467 +     * <tt>i</tt> such that
  51.468 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
  51.469 +     * (if such an element exists).  Returns <tt>true</tt> if this list
  51.470 +     * contained the specified element (or equivalently, if this list
  51.471 +     * changed as a result of the call).
  51.472 +     *
  51.473 +     * @param o element to be removed from this list, if present
  51.474 +     * @return <tt>true</tt> if this list contained the specified element
  51.475 +     */
  51.476 +    public boolean remove(Object o) {
  51.477 +        if (o == null) {
  51.478 +            for (int index = 0; index < size; index++)
  51.479 +                if (elementData[index] == null) {
  51.480 +                    fastRemove(index);
  51.481 +                    return true;
  51.482 +                }
  51.483 +        } else {
  51.484 +            for (int index = 0; index < size; index++)
  51.485 +                if (o.equals(elementData[index])) {
  51.486 +                    fastRemove(index);
  51.487 +                    return true;
  51.488 +                }
  51.489 +        }
  51.490 +        return false;
  51.491 +    }
  51.492 +
  51.493 +    /*
  51.494 +     * Private remove method that skips bounds checking and does not
  51.495 +     * return the value removed.
  51.496 +     */
  51.497 +    private void fastRemove(int index) {
  51.498 +        modCount++;
  51.499 +        int numMoved = size - index - 1;
  51.500 +        if (numMoved > 0)
  51.501 +            System.arraycopy(elementData, index+1, elementData, index,
  51.502 +                             numMoved);
  51.503 +        elementData[--size] = null; // Let gc do its work
  51.504 +    }
  51.505 +
  51.506 +    /**
  51.507 +     * Removes all of the elements from this list.  The list will
  51.508 +     * be empty after this call returns.
  51.509 +     */
  51.510 +    public void clear() {
  51.511 +        modCount++;
  51.512 +
  51.513 +        // Let gc do its work
  51.514 +        for (int i = 0; i < size; i++)
  51.515 +            elementData[i] = null;
  51.516 +
  51.517 +        size = 0;
  51.518 +    }
  51.519 +
  51.520 +    /**
  51.521 +     * Appends all of the elements in the specified collection to the end of
  51.522 +     * this list, in the order that they are returned by the
  51.523 +     * specified collection's Iterator.  The behavior of this operation is
  51.524 +     * undefined if the specified collection is modified while the operation
  51.525 +     * is in progress.  (This implies that the behavior of this call is
  51.526 +     * undefined if the specified collection is this list, and this
  51.527 +     * list is nonempty.)
  51.528 +     *
  51.529 +     * @param c collection containing elements to be added to this list
  51.530 +     * @return <tt>true</tt> if this list changed as a result of the call
  51.531 +     * @throws NullPointerException if the specified collection is null
  51.532 +     */
  51.533 +    public boolean addAll(Collection<? extends E> c) {
  51.534 +        Object[] a = c.toArray();
  51.535 +        int numNew = a.length;
  51.536 +        ensureCapacityInternal(size + numNew);  // Increments modCount
  51.537 +        System.arraycopy(a, 0, elementData, size, numNew);
  51.538 +        size += numNew;
  51.539 +        return numNew != 0;
  51.540 +    }
  51.541 +
  51.542 +    /**
  51.543 +     * Inserts all of the elements in the specified collection into this
  51.544 +     * list, starting at the specified position.  Shifts the element
  51.545 +     * currently at that position (if any) and any subsequent elements to
  51.546 +     * the right (increases their indices).  The new elements will appear
  51.547 +     * in the list in the order that they are returned by the
  51.548 +     * specified collection's iterator.
  51.549 +     *
  51.550 +     * @param index index at which to insert the first element from the
  51.551 +     *              specified collection
  51.552 +     * @param c collection containing elements to be added to this list
  51.553 +     * @return <tt>true</tt> if this list changed as a result of the call
  51.554 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  51.555 +     * @throws NullPointerException if the specified collection is null
  51.556 +     */
  51.557 +    public boolean addAll(int index, Collection<? extends E> c) {
  51.558 +        rangeCheckForAdd(index);
  51.559 +
  51.560 +        Object[] a = c.toArray();
  51.561 +        int numNew = a.length;
  51.562 +        ensureCapacityInternal(size + numNew);  // Increments modCount
  51.563 +
  51.564 +        int numMoved = size - index;
  51.565 +        if (numMoved > 0)
  51.566 +            System.arraycopy(elementData, index, elementData, index + numNew,
  51.567 +                             numMoved);
  51.568 +
  51.569 +        System.arraycopy(a, 0, elementData, index, numNew);
  51.570 +        size += numNew;
  51.571 +        return numNew != 0;
  51.572 +    }
  51.573 +
  51.574 +    /**
  51.575 +     * Removes from this list all of the elements whose index is between
  51.576 +     * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
  51.577 +     * Shifts any succeeding elements to the left (reduces their index).
  51.578 +     * This call shortens the list by {@code (toIndex - fromIndex)} elements.
  51.579 +     * (If {@code toIndex==fromIndex}, this operation has no effect.)
  51.580 +     *
  51.581 +     * @throws IndexOutOfBoundsException if {@code fromIndex} or
  51.582 +     *         {@code toIndex} is out of range
  51.583 +     *         ({@code fromIndex < 0 ||
  51.584 +     *          fromIndex >= size() ||
  51.585 +     *          toIndex > size() ||
  51.586 +     *          toIndex < fromIndex})
  51.587 +     */
  51.588 +    protected void removeRange(int fromIndex, int toIndex) {
  51.589 +        modCount++;
  51.590 +        int numMoved = size - toIndex;
  51.591 +        System.arraycopy(elementData, toIndex, elementData, fromIndex,
  51.592 +                         numMoved);
  51.593 +
  51.594 +        // Let gc do its work
  51.595 +        int newSize = size - (toIndex-fromIndex);
  51.596 +        while (size != newSize)
  51.597 +            elementData[--size] = null;
  51.598 +    }
  51.599 +
  51.600 +    /**
  51.601 +     * Checks if the given index is in range.  If not, throws an appropriate
  51.602 +     * runtime exception.  This method does *not* check if the index is
  51.603 +     * negative: It is always used immediately prior to an array access,
  51.604 +     * which throws an ArrayIndexOutOfBoundsException if index is negative.
  51.605 +     */
  51.606 +    private void rangeCheck(int index) {
  51.607 +        if (index >= size)
  51.608 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  51.609 +    }
  51.610 +
  51.611 +    /**
  51.612 +     * A version of rangeCheck used by add and addAll.
  51.613 +     */
  51.614 +    private void rangeCheckForAdd(int index) {
  51.615 +        if (index > size || index < 0)
  51.616 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  51.617 +    }
  51.618 +
  51.619 +    /**
  51.620 +     * Constructs an IndexOutOfBoundsException detail message.
  51.621 +     * Of the many possible refactorings of the error handling code,
  51.622 +     * this "outlining" performs best with both server and client VMs.
  51.623 +     */
  51.624 +    private String outOfBoundsMsg(int index) {
  51.625 +        return "Index: "+index+", Size: "+size;
  51.626 +    }
  51.627 +
  51.628 +    /**
  51.629 +     * Removes from this list all of its elements that are contained in the
  51.630 +     * specified collection.
  51.631 +     *
  51.632 +     * @param c collection containing elements to be removed from this list
  51.633 +     * @return {@code true} if this list changed as a result of the call
  51.634 +     * @throws ClassCastException if the class of an element of this list
  51.635 +     *         is incompatible with the specified collection
  51.636 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  51.637 +     * @throws NullPointerException if this list contains a null element and the
  51.638 +     *         specified collection does not permit null elements
  51.639 +     * (<a href="Collection.html#optional-restrictions">optional</a>),
  51.640 +     *         or if the specified collection is null
  51.641 +     * @see Collection#contains(Object)
  51.642 +     */
  51.643 +    public boolean removeAll(Collection<?> c) {
  51.644 +        return batchRemove(c, false);
  51.645 +    }
  51.646 +
  51.647 +    /**
  51.648 +     * Retains only the elements in this list that are contained in the
  51.649 +     * specified collection.  In other words, removes from this list all
  51.650 +     * of its elements that are not contained in the specified collection.
  51.651 +     *
  51.652 +     * @param c collection containing elements to be retained in this list
  51.653 +     * @return {@code true} if this list changed as a result of the call
  51.654 +     * @throws ClassCastException if the class of an element of this list
  51.655 +     *         is incompatible with the specified collection
  51.656 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  51.657 +     * @throws NullPointerException if this list contains a null element and the
  51.658 +     *         specified collection does not permit null elements
  51.659 +     * (<a href="Collection.html#optional-restrictions">optional</a>),
  51.660 +     *         or if the specified collection is null
  51.661 +     * @see Collection#contains(Object)
  51.662 +     */
  51.663 +    public boolean retainAll(Collection<?> c) {
  51.664 +        return batchRemove(c, true);
  51.665 +    }
  51.666 +
  51.667 +    private boolean batchRemove(Collection<?> c, boolean complement) {
  51.668 +        final Object[] elementData = this.elementData;
  51.669 +        int r = 0, w = 0;
  51.670 +        boolean modified = false;
  51.671 +        try {
  51.672 +            for (; r < size; r++)
  51.673 +                if (c.contains(elementData[r]) == complement)
  51.674 +                    elementData[w++] = elementData[r];
  51.675 +        } finally {
  51.676 +            // Preserve behavioral compatibility with AbstractCollection,
  51.677 +            // even if c.contains() throws.
  51.678 +            if (r != size) {
  51.679 +                System.arraycopy(elementData, r,
  51.680 +                                 elementData, w,
  51.681 +                                 size - r);
  51.682 +                w += size - r;
  51.683 +            }
  51.684 +            if (w != size) {
  51.685 +                for (int i = w; i < size; i++)
  51.686 +                    elementData[i] = null;
  51.687 +                modCount += size - w;
  51.688 +                size = w;
  51.689 +                modified = true;
  51.690 +            }
  51.691 +        }
  51.692 +        return modified;
  51.693 +    }
  51.694 +
  51.695 +    /**
  51.696 +     * Returns a list iterator over the elements in this list (in proper
  51.697 +     * sequence), starting at the specified position in the list.
  51.698 +     * The specified index indicates the first element that would be
  51.699 +     * returned by an initial call to {@link ListIterator#next next}.
  51.700 +     * An initial call to {@link ListIterator#previous previous} would
  51.701 +     * return the element with the specified index minus one.
  51.702 +     *
  51.703 +     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
  51.704 +     *
  51.705 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  51.706 +     */
  51.707 +    public ListIterator<E> listIterator(int index) {
  51.708 +        if (index < 0 || index > size)
  51.709 +            throw new IndexOutOfBoundsException("Index: "+index);
  51.710 +        return new ListItr(index);
  51.711 +    }
  51.712 +
  51.713 +    /**
  51.714 +     * Returns a list iterator over the elements in this list (in proper
  51.715 +     * sequence).
  51.716 +     *
  51.717 +     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
  51.718 +     *
  51.719 +     * @see #listIterator(int)
  51.720 +     */
  51.721 +    public ListIterator<E> listIterator() {
  51.722 +        return new ListItr(0);
  51.723 +    }
  51.724 +
  51.725 +    /**
  51.726 +     * Returns an iterator over the elements in this list in proper sequence.
  51.727 +     *
  51.728 +     * <p>The returned iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
  51.729 +     *
  51.730 +     * @return an iterator over the elements in this list in proper sequence
  51.731 +     */
  51.732 +    public Iterator<E> iterator() {
  51.733 +        return new Itr();
  51.734 +    }
  51.735 +
  51.736 +    /**
  51.737 +     * An optimized version of AbstractList.Itr
  51.738 +     */
  51.739 +    private class Itr implements Iterator<E> {
  51.740 +        int cursor;       // index of next element to return
  51.741 +        int lastRet = -1; // index of last element returned; -1 if no such
  51.742 +        int expectedModCount = modCount;
  51.743 +
  51.744 +        public boolean hasNext() {
  51.745 +            return cursor != size;
  51.746 +        }
  51.747 +
  51.748 +        @SuppressWarnings("unchecked")
  51.749 +        public E next() {
  51.750 +            checkForComodification();
  51.751 +            int i = cursor;
  51.752 +            if (i >= size)
  51.753 +                throw new NoSuchElementException();
  51.754 +            Object[] elementData = ArrayList.this.elementData;
  51.755 +            if (i >= elementData.length)
  51.756 +                throw new ConcurrentModificationException();
  51.757 +            cursor = i + 1;
  51.758 +            return (E) elementData[lastRet = i];
  51.759 +        }
  51.760 +
  51.761 +        public void remove() {
  51.762 +            if (lastRet < 0)
  51.763 +                throw new IllegalStateException();
  51.764 +            checkForComodification();
  51.765 +
  51.766 +            try {
  51.767 +                ArrayList.this.remove(lastRet);
  51.768 +                cursor = lastRet;
  51.769 +                lastRet = -1;
  51.770 +                expectedModCount = modCount;
  51.771 +            } catch (IndexOutOfBoundsException ex) {
  51.772 +                throw new ConcurrentModificationException();
  51.773 +            }
  51.774 +        }
  51.775 +
  51.776 +        final void checkForComodification() {
  51.777 +            if (modCount != expectedModCount)
  51.778 +                throw new ConcurrentModificationException();
  51.779 +        }
  51.780 +    }
  51.781 +
  51.782 +    /**
  51.783 +     * An optimized version of AbstractList.ListItr
  51.784 +     */
  51.785 +    private class ListItr extends Itr implements ListIterator<E> {
  51.786 +        ListItr(int index) {
  51.787 +            super();
  51.788 +            cursor = index;
  51.789 +        }
  51.790 +
  51.791 +        public boolean hasPrevious() {
  51.792 +            return cursor != 0;
  51.793 +        }
  51.794 +
  51.795 +        public int nextIndex() {
  51.796 +            return cursor;
  51.797 +        }
  51.798 +
  51.799 +        public int previousIndex() {
  51.800 +            return cursor - 1;
  51.801 +        }
  51.802 +
  51.803 +        @SuppressWarnings("unchecked")
  51.804 +        public E previous() {
  51.805 +            checkForComodification();
  51.806 +            int i = cursor - 1;
  51.807 +            if (i < 0)
  51.808 +                throw new NoSuchElementException();
  51.809 +            Object[] elementData = ArrayList.this.elementData;
  51.810 +            if (i >= elementData.length)
  51.811 +                throw new ConcurrentModificationException();
  51.812 +            cursor = i;
  51.813 +            return (E) elementData[lastRet = i];
  51.814 +        }
  51.815 +
  51.816 +        public void set(E e) {
  51.817 +            if (lastRet < 0)
  51.818 +                throw new IllegalStateException();
  51.819 +            checkForComodification();
  51.820 +
  51.821 +            try {
  51.822 +                ArrayList.this.set(lastRet, e);
  51.823 +            } catch (IndexOutOfBoundsException ex) {
  51.824 +                throw new ConcurrentModificationException();
  51.825 +            }
  51.826 +        }
  51.827 +
  51.828 +        public void add(E e) {
  51.829 +            checkForComodification();
  51.830 +
  51.831 +            try {
  51.832 +                int i = cursor;
  51.833 +                ArrayList.this.add(i, e);
  51.834 +                cursor = i + 1;
  51.835 +                lastRet = -1;
  51.836 +                expectedModCount = modCount;
  51.837 +            } catch (IndexOutOfBoundsException ex) {
  51.838 +                throw new ConcurrentModificationException();
  51.839 +            }
  51.840 +        }
  51.841 +    }
  51.842 +
  51.843 +    /**
  51.844 +     * Returns a view of the portion of this list between the specified
  51.845 +     * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.  (If
  51.846 +     * {@code fromIndex} and {@code toIndex} are equal, the returned list is
  51.847 +     * empty.)  The returned list is backed by this list, so non-structural
  51.848 +     * changes in the returned list are reflected in this list, and vice-versa.
  51.849 +     * The returned list supports all of the optional list operations.
  51.850 +     *
  51.851 +     * <p>This method eliminates the need for explicit range operations (of
  51.852 +     * the sort that commonly exist for arrays).  Any operation that expects
  51.853 +     * a list can be used as a range operation by passing a subList view
  51.854 +     * instead of a whole list.  For example, the following idiom
  51.855 +     * removes a range of elements from a list:
  51.856 +     * <pre>
  51.857 +     *      list.subList(from, to).clear();
  51.858 +     * </pre>
  51.859 +     * Similar idioms may be constructed for {@link #indexOf(Object)} and
  51.860 +     * {@link #lastIndexOf(Object)}, and all of the algorithms in the
  51.861 +     * {@link Collections} class can be applied to a subList.
  51.862 +     *
  51.863 +     * <p>The semantics of the list returned by this method become undefined if
  51.864 +     * the backing list (i.e., this list) is <i>structurally modified</i> in
  51.865 +     * any way other than via the returned list.  (Structural modifications are
  51.866 +     * those that change the size of this list, or otherwise perturb it in such
  51.867 +     * a fashion that iterations in progress may yield incorrect results.)
  51.868 +     *
  51.869 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  51.870 +     * @throws IllegalArgumentException {@inheritDoc}
  51.871 +     */
  51.872 +    public List<E> subList(int fromIndex, int toIndex) {
  51.873 +        subListRangeCheck(fromIndex, toIndex, size);
  51.874 +        return new SubList(this, 0, fromIndex, toIndex);
  51.875 +    }
  51.876 +
  51.877 +    static void subListRangeCheck(int fromIndex, int toIndex, int size) {
  51.878 +        if (fromIndex < 0)
  51.879 +            throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
  51.880 +        if (toIndex > size)
  51.881 +            throw new IndexOutOfBoundsException("toIndex = " + toIndex);
  51.882 +        if (fromIndex > toIndex)
  51.883 +            throw new IllegalArgumentException("fromIndex(" + fromIndex +
  51.884 +                                               ") > toIndex(" + toIndex + ")");
  51.885 +    }
  51.886 +
  51.887 +    private class SubList extends AbstractList<E> implements RandomAccess {
  51.888 +        private final AbstractList<E> parent;
  51.889 +        private final int parentOffset;
  51.890 +        private final int offset;
  51.891 +        int size;
  51.892 +
  51.893 +        SubList(AbstractList<E> parent,
  51.894 +                int offset, int fromIndex, int toIndex) {
  51.895 +            this.parent = parent;
  51.896 +            this.parentOffset = fromIndex;
  51.897 +            this.offset = offset + fromIndex;
  51.898 +            this.size = toIndex - fromIndex;
  51.899 +            this.modCount = ArrayList.this.modCount;
  51.900 +        }
  51.901 +
  51.902 +        public E set(int index, E e) {
  51.903 +            rangeCheck(index);
  51.904 +            checkForComodification();
  51.905 +            E oldValue = ArrayList.this.elementData(offset + index);
  51.906 +            ArrayList.this.elementData[offset + index] = e;
  51.907 +            return oldValue;
  51.908 +        }
  51.909 +
  51.910 +        public E get(int index) {
  51.911 +            rangeCheck(index);
  51.912 +            checkForComodification();
  51.913 +            return ArrayList.this.elementData(offset + index);
  51.914 +        }
  51.915 +
  51.916 +        public int size() {
  51.917 +            checkForComodification();
  51.918 +            return this.size;
  51.919 +        }
  51.920 +
  51.921 +        public void add(int index, E e) {
  51.922 +            rangeCheckForAdd(index);
  51.923 +            checkForComodification();
  51.924 +            parent.add(parentOffset + index, e);
  51.925 +            this.modCount = parent.modCount;
  51.926 +            this.size++;
  51.927 +        }
  51.928 +
  51.929 +        public E remove(int index) {
  51.930 +            rangeCheck(index);
  51.931 +            checkForComodification();
  51.932 +            E result = parent.remove(parentOffset + index);
  51.933 +            this.modCount = parent.modCount;
  51.934 +            this.size--;
  51.935 +            return result;
  51.936 +        }
  51.937 +
  51.938 +        protected void removeRange(int fromIndex, int toIndex) {
  51.939 +            checkForComodification();
  51.940 +            parent.removeRange(parentOffset + fromIndex,
  51.941 +                               parentOffset + toIndex);
  51.942 +            this.modCount = parent.modCount;
  51.943 +            this.size -= toIndex - fromIndex;
  51.944 +        }
  51.945 +
  51.946 +        public boolean addAll(Collection<? extends E> c) {
  51.947 +            return addAll(this.size, c);
  51.948 +        }
  51.949 +
  51.950 +        public boolean addAll(int index, Collection<? extends E> c) {
  51.951 +            rangeCheckForAdd(index);
  51.952 +            int cSize = c.size();
  51.953 +            if (cSize==0)
  51.954 +                return false;
  51.955 +
  51.956 +            checkForComodification();
  51.957 +            parent.addAll(parentOffset + index, c);
  51.958 +            this.modCount = parent.modCount;
  51.959 +            this.size += cSize;
  51.960 +            return true;
  51.961 +        }
  51.962 +
  51.963 +        public Iterator<E> iterator() {
  51.964 +            return listIterator();
  51.965 +        }
  51.966 +
  51.967 +        public ListIterator<E> listIterator(final int index) {
  51.968 +            checkForComodification();
  51.969 +            rangeCheckForAdd(index);
  51.970 +            final int offset = this.offset;
  51.971 +
  51.972 +            return new ListIterator<E>() {
  51.973 +                int cursor = index;
  51.974 +                int lastRet = -1;
  51.975 +                int expectedModCount = ArrayList.this.modCount;
  51.976 +
  51.977 +                public boolean hasNext() {
  51.978 +                    return cursor != SubList.this.size;
  51.979 +                }
  51.980 +
  51.981 +                @SuppressWarnings("unchecked")
  51.982 +                public E next() {
  51.983 +                    checkForComodification();
  51.984 +                    int i = cursor;
  51.985 +                    if (i >= SubList.this.size)
  51.986 +                        throw new NoSuchElementException();
  51.987 +                    Object[] elementData = ArrayList.this.elementData;
  51.988 +                    if (offset + i >= elementData.length)
  51.989 +                        throw new ConcurrentModificationException();
  51.990 +                    cursor = i + 1;
  51.991 +                    return (E) elementData[offset + (lastRet = i)];
  51.992 +                }
  51.993 +
  51.994 +                public boolean hasPrevious() {
  51.995 +                    return cursor != 0;
  51.996 +                }
  51.997 +
  51.998 +                @SuppressWarnings("unchecked")
  51.999 +                public E previous() {
 51.1000 +                    checkForComodification();
 51.1001 +                    int i = cursor - 1;
 51.1002 +                    if (i < 0)
 51.1003 +                        throw new NoSuchElementException();
 51.1004 +                    Object[] elementData = ArrayList.this.elementData;
 51.1005 +                    if (offset + i >= elementData.length)
 51.1006 +                        throw new ConcurrentModificationException();
 51.1007 +                    cursor = i;
 51.1008 +                    return (E) elementData[offset + (lastRet = i)];
 51.1009 +                }
 51.1010 +
 51.1011 +                public int nextIndex() {
 51.1012 +                    return cursor;
 51.1013 +                }
 51.1014 +
 51.1015 +                public int previousIndex() {
 51.1016 +                    return cursor - 1;
 51.1017 +                }
 51.1018 +
 51.1019 +                public void remove() {
 51.1020 +                    if (lastRet < 0)
 51.1021 +                        throw new IllegalStateException();
 51.1022 +                    checkForComodification();
 51.1023 +
 51.1024 +                    try {
 51.1025 +                        SubList.this.remove(lastRet);
 51.1026 +                        cursor = lastRet;
 51.1027 +                        lastRet = -1;
 51.1028 +                        expectedModCount = ArrayList.this.modCount;
 51.1029 +                    } catch (IndexOutOfBoundsException ex) {
 51.1030 +                        throw new ConcurrentModificationException();
 51.1031 +                    }
 51.1032 +                }
 51.1033 +
 51.1034 +                public void set(E e) {
 51.1035 +                    if (lastRet < 0)
 51.1036 +                        throw new IllegalStateException();
 51.1037 +                    checkForComodification();
 51.1038 +
 51.1039 +                    try {
 51.1040 +                        ArrayList.this.set(offset + lastRet, e);
 51.1041 +                    } catch (IndexOutOfBoundsException ex) {
 51.1042 +                        throw new ConcurrentModificationException();
 51.1043 +                    }
 51.1044 +                }
 51.1045 +
 51.1046 +                public void add(E e) {
 51.1047 +                    checkForComodification();
 51.1048 +
 51.1049 +                    try {
 51.1050 +                        int i = cursor;
 51.1051 +                        SubList.this.add(i, e);
 51.1052 +                        cursor = i + 1;
 51.1053 +                        lastRet = -1;
 51.1054 +                        expectedModCount = ArrayList.this.modCount;
 51.1055 +                    } catch (IndexOutOfBoundsException ex) {
 51.1056 +                        throw new ConcurrentModificationException();
 51.1057 +                    }
 51.1058 +                }
 51.1059 +
 51.1060 +                final void checkForComodification() {
 51.1061 +                    if (expectedModCount != ArrayList.this.modCount)
 51.1062 +                        throw new ConcurrentModificationException();
 51.1063 +                }
 51.1064 +            };
 51.1065 +        }
 51.1066 +
 51.1067 +        public List<E> subList(int fromIndex, int toIndex) {
 51.1068 +            subListRangeCheck(fromIndex, toIndex, size);
 51.1069 +            return new SubList(this, offset, fromIndex, toIndex);
 51.1070 +        }
 51.1071 +
 51.1072 +        private void rangeCheck(int index) {
 51.1073 +            if (index < 0 || index >= this.size)
 51.1074 +                throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
 51.1075 +        }
 51.1076 +
 51.1077 +        private void rangeCheckForAdd(int index) {
 51.1078 +            if (index < 0 || index > this.size)
 51.1079 +                throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
 51.1080 +        }
 51.1081 +
 51.1082 +        private String outOfBoundsMsg(int index) {
 51.1083 +            return "Index: "+index+", Size: "+this.size;
 51.1084 +        }
 51.1085 +
 51.1086 +        private void checkForComodification() {
 51.1087 +            if (ArrayList.this.modCount != this.modCount)
 51.1088 +                throw new ConcurrentModificationException();
 51.1089 +        }
 51.1090 +    }
 51.1091 +}
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/emul/compact/src/main/java/java/util/Arrays.java	Sun Feb 03 07:48:42 2013 +0100
    52.3 @@ -0,0 +1,3670 @@
    52.4 +/*
    52.5 + * Copyright (c) 1997, 2011, 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.util;
   52.30 +
   52.31 +import java.lang.reflect.*;
   52.32 +
   52.33 +/**
   52.34 + * This class contains various methods for manipulating arrays (such as
   52.35 + * sorting and searching). This class also contains a static factory
   52.36 + * that allows arrays to be viewed as lists.
   52.37 + *
   52.38 + * <p>The methods in this class all throw a {@code NullPointerException},
   52.39 + * if the specified array reference is null, except where noted.
   52.40 + *
   52.41 + * <p>The documentation for the methods contained in this class includes
   52.42 + * briefs description of the <i>implementations</i>. Such descriptions should
   52.43 + * be regarded as <i>implementation notes</i>, rather than parts of the
   52.44 + * <i>specification</i>. Implementors should feel free to substitute other
   52.45 + * algorithms, so long as the specification itself is adhered to. (For
   52.46 + * example, the algorithm used by {@code sort(Object[])} does not have to be
   52.47 + * a MergeSort, but it does have to be <i>stable</i>.)
   52.48 + *
   52.49 + * <p>This class is a member of the
   52.50 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   52.51 + * Java Collections Framework</a>.
   52.52 + *
   52.53 + * @author Josh Bloch
   52.54 + * @author Neal Gafter
   52.55 + * @author John Rose
   52.56 + * @since  1.2
   52.57 + */
   52.58 +public class Arrays {
   52.59 +
   52.60 +    // Suppresses default constructor, ensuring non-instantiability.
   52.61 +    private Arrays() {}
   52.62 +
   52.63 +    /*
   52.64 +     * Sorting of primitive type arrays.
   52.65 +     */
   52.66 +
   52.67 +    /**
   52.68 +     * Sorts the specified array into ascending numerical order.
   52.69 +     *
   52.70 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
   52.71 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
   52.72 +     * offers O(n log(n)) performance on many data sets that cause other
   52.73 +     * quicksorts to degrade to quadratic performance, and is typically
   52.74 +     * faster than traditional (one-pivot) Quicksort implementations.
   52.75 +     *
   52.76 +     * @param a the array to be sorted
   52.77 +     */
   52.78 +    public static void sort(int[] a) {
   52.79 +        DualPivotQuicksort.sort(a);
   52.80 +    }
   52.81 +
   52.82 +    /**
   52.83 +     * Sorts the specified range of the array into ascending order. The range
   52.84 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
   52.85 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
   52.86 +     * the range to be sorted is empty.
   52.87 +     *
   52.88 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
   52.89 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
   52.90 +     * offers O(n log(n)) performance on many data sets that cause other
   52.91 +     * quicksorts to degrade to quadratic performance, and is typically
   52.92 +     * faster than traditional (one-pivot) Quicksort implementations.
   52.93 +     *
   52.94 +     * @param a the array to be sorted
   52.95 +     * @param fromIndex the index of the first element, inclusive, to be sorted
   52.96 +     * @param toIndex the index of the last element, exclusive, to be sorted
   52.97 +     *
   52.98 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
   52.99 +     * @throws ArrayIndexOutOfBoundsException
  52.100 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  52.101 +     */
  52.102 +    public static void sort(int[] a, int fromIndex, int toIndex) {
  52.103 +        rangeCheck(a.length, fromIndex, toIndex);
  52.104 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  52.105 +    }
  52.106 +
  52.107 +    /**
  52.108 +     * Sorts the specified array into ascending numerical order.
  52.109 +     *
  52.110 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  52.111 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  52.112 +     * offers O(n log(n)) performance on many data sets that cause other
  52.113 +     * quicksorts to degrade to quadratic performance, and is typically
  52.114 +     * faster than traditional (one-pivot) Quicksort implementations.
  52.115 +     *
  52.116 +     * @param a the array to be sorted
  52.117 +     */
  52.118 +    public static void sort(long[] a) {
  52.119 +        DualPivotQuicksort.sort(a);
  52.120 +    }
  52.121 +
  52.122 +    /**
  52.123 +     * Sorts the specified range of the array into ascending order. The range
  52.124 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
  52.125 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
  52.126 +     * the range to be sorted is empty.
  52.127 +     *
  52.128 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  52.129 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  52.130 +     * offers O(n log(n)) performance on many data sets that cause other
  52.131 +     * quicksorts to degrade to quadratic performance, and is typically
  52.132 +     * faster than traditional (one-pivot) Quicksort implementations.
  52.133 +     *
  52.134 +     * @param a the array to be sorted
  52.135 +     * @param fromIndex the index of the first element, inclusive, to be sorted
  52.136 +     * @param toIndex the index of the last element, exclusive, to be sorted
  52.137 +     *
  52.138 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
  52.139 +     * @throws ArrayIndexOutOfBoundsException
  52.140 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  52.141 +     */
  52.142 +    public static void sort(long[] a, int fromIndex, int toIndex) {
  52.143 +        rangeCheck(a.length, fromIndex, toIndex);
  52.144 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  52.145 +    }
  52.146 +
  52.147 +    /**
  52.148 +     * Sorts the specified array into ascending numerical order.
  52.149 +     *
  52.150 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  52.151 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  52.152 +     * offers O(n log(n)) performance on many data sets that cause other
  52.153 +     * quicksorts to degrade to quadratic performance, and is typically
  52.154 +     * faster than traditional (one-pivot) Quicksort implementations.
  52.155 +     *
  52.156 +     * @param a the array to be sorted
  52.157 +     */
  52.158 +    public static void sort(short[] a) {
  52.159 +        DualPivotQuicksort.sort(a);
  52.160 +    }
  52.161 +
  52.162 +    /**
  52.163 +     * Sorts the specified range of the array into ascending order. The range
  52.164 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
  52.165 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
  52.166 +     * the range to be sorted is empty.
  52.167 +     *
  52.168 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  52.169 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  52.170 +     * offers O(n log(n)) performance on many data sets that cause other
  52.171 +     * quicksorts to degrade to quadratic performance, and is typically
  52.172 +     * faster than traditional (one-pivot) Quicksort implementations.
  52.173 +     *
  52.174 +     * @param a the array to be sorted
  52.175 +     * @param fromIndex the index of the first element, inclusive, to be sorted
  52.176 +     * @param toIndex the index of the last element, exclusive, to be sorted
  52.177 +     *
  52.178 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
  52.179 +     * @throws ArrayIndexOutOfBoundsException
  52.180 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  52.181 +     */
  52.182 +    public static void sort(short[] a, int fromIndex, int toIndex) {
  52.183 +        rangeCheck(a.length, fromIndex, toIndex);
  52.184 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  52.185 +    }
  52.186 +
  52.187 +    /**
  52.188 +     * Sorts the specified array into ascending numerical order.
  52.189 +     *
  52.190 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  52.191 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  52.192 +     * offers O(n log(n)) performance on many data sets that cause other
  52.193 +     * quicksorts to degrade to quadratic performance, and is typically
  52.194 +     * faster than traditional (one-pivot) Quicksort implementations.
  52.195 +     *
  52.196 +     * @param a the array to be sorted
  52.197 +     */
  52.198 +    public static void sort(char[] a) {
  52.199 +        DualPivotQuicksort.sort(a);
  52.200 +    }
  52.201 +
  52.202 +    /**
  52.203 +     * Sorts the specified range of the array into ascending order. The range
  52.204 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
  52.205 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
  52.206 +     * the range to be sorted is empty.
  52.207 +     *
  52.208 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  52.209 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  52.210 +     * offers O(n log(n)) performance on many data sets that cause other
  52.211 +     * quicksorts to degrade to quadratic performance, and is typically
  52.212 +     * faster than traditional (one-pivot) Quicksort implementations.
  52.213 +     *
  52.214 +     * @param a the array to be sorted
  52.215 +     * @param fromIndex the index of the first element, inclusive, to be sorted
  52.216 +     * @param toIndex the index of the last element, exclusive, to be sorted
  52.217 +     *
  52.218 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
  52.219 +     * @throws ArrayIndexOutOfBoundsException
  52.220 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  52.221 +     */
  52.222 +    public static void sort(char[] a, int fromIndex, int toIndex) {
  52.223 +        rangeCheck(a.length, fromIndex, toIndex);
  52.224 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  52.225 +    }
  52.226 +
  52.227 +    /**
  52.228 +     * Sorts the specified array into ascending numerical order.
  52.229 +     *
  52.230 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  52.231 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  52.232 +     * offers O(n log(n)) performance on many data sets that cause other
  52.233 +     * quicksorts to degrade to quadratic performance, and is typically
  52.234 +     * faster than traditional (one-pivot) Quicksort implementations.
  52.235 +     *
  52.236 +     * @param a the array to be sorted
  52.237 +     */
  52.238 +    public static void sort(byte[] a) {
  52.239 +        DualPivotQuicksort.sort(a);
  52.240 +    }
  52.241 +
  52.242 +    /**
  52.243 +     * Sorts the specified range of the array into ascending order. The range
  52.244 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
  52.245 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
  52.246 +     * the range to be sorted is empty.
  52.247 +     *
  52.248 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  52.249 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  52.250 +     * offers O(n log(n)) performance on many data sets that cause other
  52.251 +     * quicksorts to degrade to quadratic performance, and is typically
  52.252 +     * faster than traditional (one-pivot) Quicksort implementations.
  52.253 +     *
  52.254 +     * @param a the array to be sorted
  52.255 +     * @param fromIndex the index of the first element, inclusive, to be sorted
  52.256 +     * @param toIndex the index of the last element, exclusive, to be sorted
  52.257 +     *
  52.258 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
  52.259 +     * @throws ArrayIndexOutOfBoundsException
  52.260 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  52.261 +     */
  52.262 +    public static void sort(byte[] a, int fromIndex, int toIndex) {
  52.263 +        rangeCheck(a.length, fromIndex, toIndex);
  52.264 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  52.265 +    }
  52.266 +
  52.267 +    /**
  52.268 +     * Sorts the specified array into ascending numerical order.
  52.269 +     *
  52.270 +     * <p>The {@code <} relation does not provide a total order on all float
  52.271 +     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
  52.272 +     * value compares neither less than, greater than, nor equal to any value,
  52.273 +     * even itself. This method uses the total order imposed by the method
  52.274 +     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
  52.275 +     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
  52.276 +     * other value and all {@code Float.NaN} values are considered equal.
  52.277 +     *
  52.278 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  52.279 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  52.280 +     * offers O(n log(n)) performance on many data sets that cause other
  52.281 +     * quicksorts to degrade to quadratic performance, and is typically
  52.282 +     * faster than traditional (one-pivot) Quicksort implementations.
  52.283 +     *
  52.284 +     * @param a the array to be sorted
  52.285 +     */
  52.286 +    public static void sort(float[] a) {
  52.287 +        DualPivotQuicksort.sort(a);
  52.288 +    }
  52.289 +
  52.290 +    /**
  52.291 +     * Sorts the specified range of the array into ascending order. The range
  52.292 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
  52.293 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
  52.294 +     * the range to be sorted is empty.
  52.295 +     *
  52.296 +     * <p>The {@code <} relation does not provide a total order on all float
  52.297 +     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
  52.298 +     * value compares neither less than, greater than, nor equal to any value,
  52.299 +     * even itself. This method uses the total order imposed by the method
  52.300 +     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
  52.301 +     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
  52.302 +     * other value and all {@code Float.NaN} values are considered equal.
  52.303 +     *
  52.304 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  52.305 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  52.306 +     * offers O(n log(n)) performance on many data sets that cause other
  52.307 +     * quicksorts to degrade to quadratic performance, and is typically
  52.308 +     * faster than traditional (one-pivot) Quicksort implementations.
  52.309 +     *
  52.310 +     * @param a the array to be sorted
  52.311 +     * @param fromIndex the index of the first element, inclusive, to be sorted
  52.312 +     * @param toIndex the index of the last element, exclusive, to be sorted
  52.313 +     *
  52.314 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
  52.315 +     * @throws ArrayIndexOutOfBoundsException
  52.316 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  52.317 +     */
  52.318 +    public static void sort(float[] a, int fromIndex, int toIndex) {
  52.319 +        rangeCheck(a.length, fromIndex, toIndex);
  52.320 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  52.321 +    }
  52.322 +
  52.323 +    /**
  52.324 +     * Sorts the specified array into ascending numerical order.
  52.325 +     *
  52.326 +     * <p>The {@code <} relation does not provide a total order on all double
  52.327 +     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
  52.328 +     * value compares neither less than, greater than, nor equal to any value,
  52.329 +     * even itself. This method uses the total order imposed by the method
  52.330 +     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
  52.331 +     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
  52.332 +     * other value and all {@code Double.NaN} values are considered equal.
  52.333 +     *
  52.334 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  52.335 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  52.336 +     * offers O(n log(n)) performance on many data sets that cause other
  52.337 +     * quicksorts to degrade to quadratic performance, and is typically
  52.338 +     * faster than traditional (one-pivot) Quicksort implementations.
  52.339 +     *
  52.340 +     * @param a the array to be sorted
  52.341 +     */
  52.342 +    public static void sort(double[] a) {
  52.343 +        DualPivotQuicksort.sort(a);
  52.344 +    }
  52.345 +
  52.346 +    /**
  52.347 +     * Sorts the specified range of the array into ascending order. The range
  52.348 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
  52.349 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
  52.350 +     * the range to be sorted is empty.
  52.351 +     *
  52.352 +     * <p>The {@code <} relation does not provide a total order on all double
  52.353 +     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
  52.354 +     * value compares neither less than, greater than, nor equal to any value,
  52.355 +     * even itself. This method uses the total order imposed by the method
  52.356 +     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
  52.357 +     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
  52.358 +     * other value and all {@code Double.NaN} values are considered equal.
  52.359 +     *
  52.360 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  52.361 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  52.362 +     * offers O(n log(n)) performance on many data sets that cause other
  52.363 +     * quicksorts to degrade to quadratic performance, and is typically
  52.364 +     * faster than traditional (one-pivot) Quicksort implementations.
  52.365 +     *
  52.366 +     * @param a the array to be sorted
  52.367 +     * @param fromIndex the index of the first element, inclusive, to be sorted
  52.368 +     * @param toIndex the index of the last element, exclusive, to be sorted
  52.369 +     *
  52.370 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
  52.371 +     * @throws ArrayIndexOutOfBoundsException
  52.372 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  52.373 +     */
  52.374 +    public static void sort(double[] a, int fromIndex, int toIndex) {
  52.375 +        rangeCheck(a.length, fromIndex, toIndex);
  52.376 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  52.377 +    }
  52.378 +
  52.379 +    /*
  52.380 +     * Sorting of complex type arrays.
  52.381 +     */
  52.382 +
  52.383 +    /**
  52.384 +     * Old merge sort implementation can be selected (for
  52.385 +     * compatibility with broken comparators) using a system property.
  52.386 +     * Cannot be a static boolean in the enclosing class due to
  52.387 +     * circular dependencies. To be removed in a future release.
  52.388 +     */
  52.389 +    static final class LegacyMergeSort {
  52.390 +        private static final boolean userRequested = false;
  52.391 +    }
  52.392 +
  52.393 +    /*
  52.394 +     * If this platform has an optimizing VM, check whether ComparableTimSort
  52.395 +     * offers any performance benefit over TimSort in conjunction with a
  52.396 +     * comparator that returns:
  52.397 +     *    {@code ((Comparable)first).compareTo(Second)}.
  52.398 +     * If not, you are better off deleting ComparableTimSort to
  52.399 +     * eliminate the code duplication.  In other words, the commented
  52.400 +     * out code below is the preferable implementation for sorting
  52.401 +     * arrays of Comparables if it offers sufficient performance.
  52.402 +     */
  52.403 +
  52.404 +//    /**
  52.405 +//     * A comparator that implements the natural ordering of a group of
  52.406 +//     * mutually comparable elements.  Using this comparator saves us
  52.407 +//     * from duplicating most of the code in this file (one version for
  52.408 +//     * Comparables, one for explicit Comparators).
  52.409 +//     */
  52.410 +//    private static final Comparator<Object> NATURAL_ORDER =
  52.411 +//            new Comparator<Object>() {
  52.412 +//        @SuppressWarnings("unchecked")
  52.413 +//        public int compare(Object first, Object second) {
  52.414 +//            return ((Comparable<Object>)first).compareTo(second);
  52.415 +//        }
  52.416 +//    };
  52.417 +//
  52.418 +//    public static void sort(Object[] a) {
  52.419 +//        sort(a, 0, a.length, NATURAL_ORDER);
  52.420 +//    }
  52.421 +//
  52.422 +//    public static void sort(Object[] a, int fromIndex, int toIndex) {
  52.423 +//        sort(a, fromIndex, toIndex, NATURAL_ORDER);
  52.424 +//    }
  52.425 +
  52.426 +    /**
  52.427 +     * Sorts the specified array of objects into ascending order, according
  52.428 +     * to the {@linkplain Comparable natural ordering} of its elements.
  52.429 +     * All elements in the array must implement the {@link Comparable}
  52.430 +     * interface.  Furthermore, all elements in the array must be
  52.431 +     * <i>mutually comparable</i> (that is, {@code e1.compareTo(e2)} must
  52.432 +     * not throw a {@code ClassCastException} for any elements {@code e1}
  52.433 +     * and {@code e2} in the array).
  52.434 +     *
  52.435 +     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
  52.436 +     * not be reordered as a result of the sort.
  52.437 +     *
  52.438 +     * <p>Implementation note: This implementation is a stable, adaptive,
  52.439 +     * iterative mergesort that requires far fewer than n lg(n) comparisons
  52.440 +     * when the input array is partially sorted, while offering the
  52.441 +     * performance of a traditional mergesort when the input array is
  52.442 +     * randomly ordered.  If the input array is nearly sorted, the
  52.443 +     * implementation requires approximately n comparisons.  Temporary
  52.444 +     * storage requirements vary from a small constant for nearly sorted
  52.445 +     * input arrays to n/2 object references for randomly ordered input
  52.446 +     * arrays.
  52.447 +     *
  52.448 +     * <p>The implementation takes equal advantage of ascending and
  52.449 +     * descending order in its input array, and can take advantage of
  52.450 +     * ascending and descending order in different parts of the the same
  52.451 +     * input array.  It is well-suited to merging two or more sorted arrays:
  52.452 +     * simply concatenate the arrays and sort the resulting array.
  52.453 +     *
  52.454 +     * <p>The implementation was adapted from Tim Peters's list sort for Python
  52.455 +     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
  52.456 +     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
  52.457 +     * Sorting and Information Theoretic Complexity", in Proceedings of the
  52.458 +     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
  52.459 +     * January 1993.
  52.460 +     *
  52.461 +     * @param a the array to be sorted
  52.462 +     * @throws ClassCastException if the array contains elements that are not
  52.463 +     *         <i>mutually comparable</i> (for example, strings and integers)
  52.464 +     * @throws IllegalArgumentException (optional) if the natural
  52.465 +     *         ordering of the array elements is found to violate the
  52.466 +     *         {@link Comparable} contract
  52.467 +     */
  52.468 +    public static void sort(Object[] a) {
  52.469 +        if (LegacyMergeSort.userRequested)
  52.470 +            legacyMergeSort(a);
  52.471 +        else
  52.472 +            ComparableTimSort.sort(a);
  52.473 +    }
  52.474 +
  52.475 +    /** To be removed in a future release. */
  52.476 +    private static void legacyMergeSort(Object[] a) {
  52.477 +        Object[] aux = a.clone();
  52.478 +        mergeSort(aux, a, 0, a.length, 0);
  52.479 +    }
  52.480 +
  52.481 +    /**
  52.482 +     * Sorts the specified range of the specified array of objects into
  52.483 +     * ascending order, according to the
  52.484 +     * {@linkplain Comparable natural ordering} of its
  52.485 +     * elements.  The range to be sorted extends from index
  52.486 +     * {@code fromIndex}, inclusive, to index {@code toIndex}, exclusive.
  52.487 +     * (If {@code fromIndex==toIndex}, the range to be sorted is empty.)  All
  52.488 +     * elements in this range must implement the {@link Comparable}
  52.489 +     * interface.  Furthermore, all elements in this range must be <i>mutually
  52.490 +     * comparable</i> (that is, {@code e1.compareTo(e2)} must not throw a
  52.491 +     * {@code ClassCastException} for any elements {@code e1} and
  52.492 +     * {@code e2} in the array).
  52.493 +     *
  52.494 +     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
  52.495 +     * not be reordered as a result of the sort.
  52.496 +     *
  52.497 +     * <p>Implementation note: This implementation is a stable, adaptive,
  52.498 +     * iterative mergesort that requires far fewer than n lg(n) comparisons
  52.499 +     * when the input array is partially sorted, while offering the
  52.500 +     * performance of a traditional mergesort when the input array is
  52.501 +     * randomly ordered.  If the input array is nearly sorted, the
  52.502 +     * implementation requires approximately n comparisons.  Temporary
  52.503 +     * storage requirements vary from a small constant for nearly sorted
  52.504 +     * input arrays to n/2 object references for randomly ordered input
  52.505 +     * arrays.
  52.506 +     *
  52.507 +     * <p>The implementation takes equal advantage of ascending and
  52.508 +     * descending order in its input array, and can take advantage of
  52.509 +     * ascending and descending order in different parts of the the same
  52.510 +     * input array.  It is well-suited to merging two or more sorted arrays:
  52.511 +     * simply concatenate the arrays and sort the resulting array.
  52.512 +     *
  52.513 +     * <p>The implementation was adapted from Tim Peters's list sort for Python
  52.514 +     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
  52.515 +     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
  52.516 +     * Sorting and Information Theoretic Complexity", in Proceedings of the
  52.517 +     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
  52.518 +     * January 1993.
  52.519 +     *
  52.520 +     * @param a the array to be sorted
  52.521 +     * @param fromIndex the index of the first element (inclusive) to be
  52.522 +     *        sorted
  52.523 +     * @param toIndex the index of the last element (exclusive) to be sorted
  52.524 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex} or
  52.525 +     *         (optional) if the natural ordering of the array elements is
  52.526 +     *         found to violate the {@link Comparable} contract
  52.527 +     * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
  52.528 +     *         {@code toIndex > a.length}
  52.529 +     * @throws ClassCastException if the array contains elements that are
  52.530 +     *         not <i>mutually comparable</i> (for example, strings and
  52.531 +     *         integers).
  52.532 +     */
  52.533 +    public static void sort(Object[] a, int fromIndex, int toIndex) {
  52.534 +        if (LegacyMergeSort.userRequested)
  52.535 +            legacyMergeSort(a, fromIndex, toIndex);
  52.536 +        else
  52.537 +            ComparableTimSort.sort(a, fromIndex, toIndex);
  52.538 +    }
  52.539 +
  52.540 +    /** To be removed in a future release. */
  52.541 +    private static void legacyMergeSort(Object[] a,
  52.542 +                                        int fromIndex, int toIndex) {
  52.543 +        rangeCheck(a.length, fromIndex, toIndex);
  52.544 +        Object[] aux = copyOfRange(a, fromIndex, toIndex);
  52.545 +        mergeSort(aux, a, fromIndex, toIndex, -fromIndex);
  52.546 +    }
  52.547 +
  52.548 +    /**
  52.549 +     * Tuning parameter: list size at or below which insertion sort will be
  52.550 +     * used in preference to mergesort.
  52.551 +     * To be removed in a future release.
  52.552 +     */
  52.553 +    private static final int INSERTIONSORT_THRESHOLD = 7;
  52.554 +
  52.555 +    /**
  52.556 +     * Src is the source array that starts at index 0
  52.557 +     * Dest is the (possibly larger) array destination with a possible offset
  52.558 +     * low is the index in dest to start sorting
  52.559 +     * high is the end index in dest to end sorting
  52.560 +     * off is the offset to generate corresponding low, high in src
  52.561 +     * To be removed in a future release.
  52.562 +     */
  52.563 +    private static void mergeSort(Object[] src,
  52.564 +                                  Object[] dest,
  52.565 +                                  int low,
  52.566 +                                  int high,
  52.567 +                                  int off) {
  52.568 +        int length = high - low;
  52.569 +
  52.570 +        // Insertion sort on smallest arrays
  52.571 +        if (length < INSERTIONSORT_THRESHOLD) {
  52.572 +            for (int i=low; i<high; i++)
  52.573 +                for (int j=i; j>low &&
  52.574 +                         ((Comparable) dest[j-1]).compareTo(dest[j])>0; j--)
  52.575 +                    swap(dest, j, j-1);
  52.576 +            return;
  52.577 +        }
  52.578 +
  52.579 +        // Recursively sort halves of dest into src
  52.580 +        int destLow  = low;
  52.581 +        int destHigh = high;
  52.582 +        low  += off;
  52.583 +        high += off;
  52.584 +        int mid = (low + high) >>> 1;
  52.585 +        mergeSort(dest, src, low, mid, -off);
  52.586 +        mergeSort(dest, src, mid, high, -off);
  52.587 +
  52.588 +        // If list is already sorted, just copy from src to dest.  This is an
  52.589 +        // optimization that results in faster sorts for nearly ordered lists.
  52.590 +        if (((Comparable)src[mid-1]).compareTo(src[mid]) <= 0) {
  52.591 +            System.arraycopy(src, low, dest, destLow, length);
  52.592 +            return;
  52.593 +        }
  52.594 +
  52.595 +        // Merge sorted halves (now in src) into dest
  52.596 +        for(int i = destLow, p = low, q = mid; i < destHigh; i++) {
  52.597 +            if (q >= high || p < mid && ((Comparable)src[p]).compareTo(src[q])<=0)
  52.598 +                dest[i] = src[p++];
  52.599 +            else
  52.600 +                dest[i] = src[q++];
  52.601 +        }
  52.602 +    }
  52.603 +
  52.604 +    /**
  52.605 +     * Swaps x[a] with x[b].
  52.606 +     */
  52.607 +    private static void swap(Object[] x, int a, int b) {
  52.608 +        Object t = x[a];
  52.609 +        x[a] = x[b];
  52.610 +        x[b] = t;
  52.611 +    }
  52.612 +
  52.613 +    /**
  52.614 +     * Sorts the specified array of objects according to the order induced by
  52.615 +     * the specified comparator.  All elements in the array must be
  52.616 +     * <i>mutually comparable</i> by the specified comparator (that is,
  52.617 +     * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException}
  52.618 +     * for any elements {@code e1} and {@code e2} in the array).
  52.619 +     *
  52.620 +     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
  52.621 +     * not be reordered as a result of the sort.
  52.622 +     *
  52.623 +     * <p>Implementation note: This implementation is a stable, adaptive,
  52.624 +     * iterative mergesort that requires far fewer than n lg(n) comparisons
  52.625 +     * when the input array is partially sorted, while offering the
  52.626 +     * performance of a traditional mergesort when the input array is
  52.627 +     * randomly ordered.  If the input array is nearly sorted, the
  52.628 +     * implementation requires approximately n comparisons.  Temporary
  52.629 +     * storage requirements vary from a small constant for nearly sorted
  52.630 +     * input arrays to n/2 object references for randomly ordered input
  52.631 +     * arrays.
  52.632 +     *
  52.633 +     * <p>The implementation takes equal advantage of ascending and
  52.634 +     * descending order in its input array, and can take advantage of
  52.635 +     * ascending and descending order in different parts of the the same
  52.636 +     * input array.  It is well-suited to merging two or more sorted arrays:
  52.637 +     * simply concatenate the arrays and sort the resulting array.
  52.638 +     *
  52.639 +     * <p>The implementation was adapted from Tim Peters's list sort for Python
  52.640 +     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
  52.641 +     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
  52.642 +     * Sorting and Information Theoretic Complexity", in Proceedings of the
  52.643 +     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
  52.644 +     * January 1993.
  52.645 +     *
  52.646 +     * @param a the array to be sorted
  52.647 +     * @param c the comparator to determine the order of the array.  A
  52.648 +     *        {@code null} value indicates that the elements'
  52.649 +     *        {@linkplain Comparable natural ordering} should be used.
  52.650 +     * @throws ClassCastException if the array contains elements that are
  52.651 +     *         not <i>mutually comparable</i> using the specified comparator
  52.652 +     * @throws IllegalArgumentException (optional) if the comparator is
  52.653 +     *         found to violate the {@link Comparator} contract
  52.654 +     */
  52.655 +    public static <T> void sort(T[] a, Comparator<? super T> c) {
  52.656 +        if (LegacyMergeSort.userRequested)
  52.657 +            legacyMergeSort(a, c);
  52.658 +        else
  52.659 +            TimSort.sort(a, c);
  52.660 +    }
  52.661 +
  52.662 +    /** To be removed in a future release. */
  52.663 +    private static <T> void legacyMergeSort(T[] a, Comparator<? super T> c) {
  52.664 +        T[] aux = a.clone();
  52.665 +        if (c==null)
  52.666 +            mergeSort(aux, a, 0, a.length, 0);
  52.667 +        else
  52.668 +            mergeSort(aux, a, 0, a.length, 0, c);
  52.669 +    }
  52.670 +
  52.671 +    /**
  52.672 +     * Sorts the specified range of the specified array of objects according
  52.673 +     * to the order induced by the specified comparator.  The range to be
  52.674 +     * sorted extends from index {@code fromIndex}, inclusive, to index
  52.675 +     * {@code toIndex}, exclusive.  (If {@code fromIndex==toIndex}, the
  52.676 +     * range to be sorted is empty.)  All elements in the range must be
  52.677 +     * <i>mutually comparable</i> by the specified comparator (that is,
  52.678 +     * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException}
  52.679 +     * for any elements {@code e1} and {@code e2} in the range).
  52.680 +     *
  52.681 +     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
  52.682 +     * not be reordered as a result of the sort.
  52.683 +     *
  52.684 +     * <p>Implementation note: This implementation is a stable, adaptive,
  52.685 +     * iterative mergesort that requires far fewer than n lg(n) comparisons
  52.686 +     * when the input array is partially sorted, while offering the
  52.687 +     * performance of a traditional mergesort when the input array is
  52.688 +     * randomly ordered.  If the input array is nearly sorted, the
  52.689 +     * implementation requires approximately n comparisons.  Temporary
  52.690 +     * storage requirements vary from a small constant for nearly sorted
  52.691 +     * input arrays to n/2 object references for randomly ordered input
  52.692 +     * arrays.
  52.693 +     *
  52.694 +     * <p>The implementation takes equal advantage of ascending and
  52.695 +     * descending order in its input array, and can take advantage of
  52.696 +     * ascending and descending order in different parts of the the same
  52.697 +     * input array.  It is well-suited to merging two or more sorted arrays:
  52.698 +     * simply concatenate the arrays and sort the resulting array.
  52.699 +     *
  52.700 +     * <p>The implementation was adapted from Tim Peters's list sort for Python
  52.701 +     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
  52.702 +     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
  52.703 +     * Sorting and Information Theoretic Complexity", in Proceedings of the
  52.704 +     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
  52.705 +     * January 1993.
  52.706 +     *
  52.707 +     * @param a the array to be sorted
  52.708 +     * @param fromIndex the index of the first element (inclusive) to be
  52.709 +     *        sorted
  52.710 +     * @param toIndex the index of the last element (exclusive) to be sorted
  52.711 +     * @param c the comparator to determine the order of the array.  A
  52.712 +     *        {@code null} value indicates that the elements'
  52.713 +     *        {@linkplain Comparable natural ordering} should be used.
  52.714 +     * @throws ClassCastException if the array contains elements that are not
  52.715 +     *         <i>mutually comparable</i> using the specified comparator.
  52.716 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex} or
  52.717 +     *         (optional) if the comparator is found to violate the
  52.718 +     *         {@link Comparator} contract
  52.719 +     * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
  52.720 +     *         {@code toIndex > a.length}
  52.721 +     */
  52.722 +    public static <T> void sort(T[] a, int fromIndex, int toIndex,
  52.723 +                                Comparator<? super T> c) {
  52.724 +        if (LegacyMergeSort.userRequested)
  52.725 +            legacyMergeSort(a, fromIndex, toIndex, c);
  52.726 +        else
  52.727 +            TimSort.sort(a, fromIndex, toIndex, c);
  52.728 +    }
  52.729 +
  52.730 +    /** To be removed in a future release. */
  52.731 +    private static <T> void legacyMergeSort(T[] a, int fromIndex, int toIndex,
  52.732 +                                            Comparator<? super T> c) {
  52.733 +        rangeCheck(a.length, fromIndex, toIndex);
  52.734 +        T[] aux = copyOfRange(a, fromIndex, toIndex);
  52.735 +        if (c==null)
  52.736 +            mergeSort(aux, a, fromIndex, toIndex, -fromIndex);
  52.737 +        else
  52.738 +            mergeSort(aux, a, fromIndex, toIndex, -fromIndex, c);
  52.739 +    }
  52.740 +
  52.741 +    /**
  52.742 +     * Src is the source array that starts at index 0
  52.743 +     * Dest is the (possibly larger) array destination with a possible offset
  52.744 +     * low is the index in dest to start sorting
  52.745 +     * high is the end index in dest to end sorting
  52.746 +     * off is the offset into src corresponding to low in dest
  52.747 +     * To be removed in a future release.
  52.748 +     */
  52.749 +    private static void mergeSort(Object[] src,
  52.750 +                                  Object[] dest,
  52.751 +                                  int low, int high, int off,
  52.752 +                                  Comparator c) {
  52.753 +        int length = high - low;
  52.754 +
  52.755 +        // Insertion sort on smallest arrays
  52.756 +        if (length < INSERTIONSORT_THRESHOLD) {
  52.757 +            for (int i=low; i<high; i++)
  52.758 +                for (int j=i; j>low && c.compare(dest[j-1], dest[j])>0; j--)
  52.759 +                    swap(dest, j, j-1);
  52.760 +            return;
  52.761 +        }
  52.762 +
  52.763 +        // Recursively sort halves of dest into src
  52.764 +        int destLow  = low;
  52.765 +        int destHigh = high;
  52.766 +        low  += off;
  52.767 +        high += off;
  52.768 +        int mid = (low + high) >>> 1;
  52.769 +        mergeSort(dest, src, low, mid, -off, c);
  52.770 +        mergeSort(dest, src, mid, high, -off, c);
  52.771 +
  52.772 +        // If list is already sorted, just copy from src to dest.  This is an
  52.773 +        // optimization that results in faster sorts for nearly ordered lists.
  52.774 +        if (c.compare(src[mid-1], src[mid]) <= 0) {
  52.775 +           System.arraycopy(src, low, dest, destLow, length);
  52.776 +           return;
  52.777 +        }
  52.778 +
  52.779 +        // Merge sorted halves (now in src) into dest
  52.780 +        for(int i = destLow, p = low, q = mid; i < destHigh; i++) {
  52.781 +            if (q >= high || p < mid && c.compare(src[p], src[q]) <= 0)
  52.782 +                dest[i] = src[p++];
  52.783 +            else
  52.784 +                dest[i] = src[q++];
  52.785 +        }
  52.786 +    }
  52.787 +
  52.788 +    /**
  52.789 +     * Checks that {@code fromIndex} and {@code toIndex} are in
  52.790 +     * the range and throws an appropriate exception, if they aren't.
  52.791 +     */
  52.792 +    private static void rangeCheck(int length, int fromIndex, int toIndex) {
  52.793 +        if (fromIndex > toIndex) {
  52.794 +            throw new IllegalArgumentException(
  52.795 +                "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
  52.796 +        }
  52.797 +        if (fromIndex < 0) {
  52.798 +            throw new ArrayIndexOutOfBoundsException(fromIndex);
  52.799 +        }
  52.800 +        if (toIndex > length) {
  52.801 +            throw new ArrayIndexOutOfBoundsException(toIndex);
  52.802 +        }
  52.803 +    }
  52.804 +
  52.805 +    // Searching
  52.806 +
  52.807 +    /**
  52.808 +     * Searches the specified array of longs for the specified value using the
  52.809 +     * binary search algorithm.  The array must be sorted (as
  52.810 +     * by the {@link #sort(long[])} method) prior to making this call.  If it
  52.811 +     * is not sorted, the results are undefined.  If the array contains
  52.812 +     * multiple elements with the specified value, there is no guarantee which
  52.813 +     * one will be found.
  52.814 +     *
  52.815 +     * @param a the array to be searched
  52.816 +     * @param key the value to be searched for
  52.817 +     * @return index of the search key, if it is contained in the array;
  52.818 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  52.819 +     *         <i>insertion point</i> is defined as the point at which the
  52.820 +     *         key would be inserted into the array: the index of the first
  52.821 +     *         element greater than the key, or <tt>a.length</tt> if all
  52.822 +     *         elements in the array are less than the specified key.  Note
  52.823 +     *         that this guarantees that the return value will be &gt;= 0 if
  52.824 +     *         and only if the key is found.
  52.825 +     */
  52.826 +    public static int binarySearch(long[] a, long key) {
  52.827 +        return binarySearch0(a, 0, a.length, key);
  52.828 +    }
  52.829 +
  52.830 +    /**
  52.831 +     * Searches a range of
  52.832 +     * the specified array of longs for the specified value using the
  52.833 +     * binary search algorithm.
  52.834 +     * The range must be sorted (as
  52.835 +     * by the {@link #sort(long[], int, int)} method)
  52.836 +     * prior to making this call.  If it
  52.837 +     * is not sorted, the results are undefined.  If the range contains
  52.838 +     * multiple elements with the specified value, there is no guarantee which
  52.839 +     * one will be found.
  52.840 +     *
  52.841 +     * @param a the array to be searched
  52.842 +     * @param fromIndex the index of the first element (inclusive) to be
  52.843 +     *          searched
  52.844 +     * @param toIndex the index of the last element (exclusive) to be searched
  52.845 +     * @param key the value to be searched for
  52.846 +     * @return index of the search key, if it is contained in the array
  52.847 +     *         within the specified range;
  52.848 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  52.849 +     *         <i>insertion point</i> is defined as the point at which the
  52.850 +     *         key would be inserted into the array: the index of the first
  52.851 +     *         element in the range greater than the key,
  52.852 +     *         or <tt>toIndex</tt> if all
  52.853 +     *         elements in the range are less than the specified key.  Note
  52.854 +     *         that this guarantees that the return value will be &gt;= 0 if
  52.855 +     *         and only if the key is found.
  52.856 +     * @throws IllegalArgumentException
  52.857 +     *         if {@code fromIndex > toIndex}
  52.858 +     * @throws ArrayIndexOutOfBoundsException
  52.859 +     *         if {@code fromIndex < 0 or toIndex > a.length}
  52.860 +     * @since 1.6
  52.861 +     */
  52.862 +    public static int binarySearch(long[] a, int fromIndex, int toIndex,
  52.863 +                                   long key) {
  52.864 +        rangeCheck(a.length, fromIndex, toIndex);
  52.865 +        return binarySearch0(a, fromIndex, toIndex, key);
  52.866 +    }
  52.867 +
  52.868 +    // Like public version, but without range checks.
  52.869 +    private static int binarySearch0(long[] a, int fromIndex, int toIndex,
  52.870 +                                     long key) {
  52.871 +        int low = fromIndex;
  52.872 +        int high = toIndex - 1;
  52.873 +
  52.874 +        while (low <= high) {
  52.875 +            int mid = (low + high) >>> 1;
  52.876 +            long midVal = a[mid];
  52.877 +
  52.878 +            if (midVal < key)
  52.879 +                low = mid + 1;
  52.880 +            else if (midVal > key)
  52.881 +                high = mid - 1;
  52.882 +            else
  52.883 +                return mid; // key found
  52.884 +        }
  52.885 +        return -(low + 1);  // key not found.
  52.886 +    }
  52.887 +
  52.888 +    /**
  52.889 +     * Searches the specified array of ints for the specified value using the
  52.890 +     * binary search algorithm.  The array must be sorted (as
  52.891 +     * by the {@link #sort(int[])} method) prior to making this call.  If it
  52.892 +     * is not sorted, the results are undefined.  If the array contains
  52.893 +     * multiple elements with the specified value, there is no guarantee which
  52.894 +     * one will be found.
  52.895 +     *
  52.896 +     * @param a the array to be searched
  52.897 +     * @param key the value to be searched for
  52.898 +     * @return index of the search key, if it is contained in the array;
  52.899 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  52.900 +     *         <i>insertion point</i> is defined as the point at which the
  52.901 +     *         key would be inserted into the array: the index of the first
  52.902 +     *         element greater than the key, or <tt>a.length</tt> if all
  52.903 +     *         elements in the array are less than the specified key.  Note
  52.904 +     *         that this guarantees that the return value will be &gt;= 0 if
  52.905 +     *         and only if the key is found.
  52.906 +     */
  52.907 +    public static int binarySearch(int[] a, int key) {
  52.908 +        return binarySearch0(a, 0, a.length, key);
  52.909 +    }
  52.910 +
  52.911 +    /**
  52.912 +     * Searches a range of
  52.913 +     * the specified array of ints for the specified value using the
  52.914 +     * binary search algorithm.
  52.915 +     * The range must be sorted (as
  52.916 +     * by the {@link #sort(int[], int, int)} method)
  52.917 +     * prior to making this call.  If it
  52.918 +     * is not sorted, the results are undefined.  If the range contains
  52.919 +     * multiple elements with the specified value, there is no guarantee which
  52.920 +     * one will be found.
  52.921 +     *
  52.922 +     * @param a the array to be searched
  52.923 +     * @param fromIndex the index of the first element (inclusive) to be
  52.924 +     *          searched
  52.925 +     * @param toIndex the index of the last element (exclusive) to be searched
  52.926 +     * @param key the value to be searched for
  52.927 +     * @return index of the search key, if it is contained in the array
  52.928 +     *         within the specified range;
  52.929 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  52.930 +     *         <i>insertion point</i> is defined as the point at which the
  52.931 +     *         key would be inserted into the array: the index of the first
  52.932 +     *         element in the range greater than the key,
  52.933 +     *         or <tt>toIndex</tt> if all
  52.934 +     *         elements in the range are less than the specified key.  Note
  52.935 +     *         that this guarantees that the return value will be &gt;= 0 if
  52.936 +     *         and only if the key is found.
  52.937 +     * @throws IllegalArgumentException
  52.938 +     *         if {@code fromIndex > toIndex}
  52.939 +     * @throws ArrayIndexOutOfBoundsException
  52.940 +     *         if {@code fromIndex < 0 or toIndex > a.length}
  52.941 +     * @since 1.6
  52.942 +     */
  52.943 +    public static int binarySearch(int[] a, int fromIndex, int toIndex,
  52.944 +                                   int key) {
  52.945 +        rangeCheck(a.length, fromIndex, toIndex);
  52.946 +        return binarySearch0(a, fromIndex, toIndex, key);
  52.947 +    }
  52.948 +
  52.949 +    // Like public version, but without range checks.
  52.950 +    private static int binarySearch0(int[] a, int fromIndex, int toIndex,
  52.951 +                                     int key) {
  52.952 +        int low = fromIndex;
  52.953 +        int high = toIndex - 1;
  52.954 +
  52.955 +        while (low <= high) {
  52.956 +            int mid = (low + high) >>> 1;
  52.957 +            int midVal = a[mid];
  52.958 +
  52.959 +            if (midVal < key)
  52.960 +                low = mid + 1;
  52.961 +            else if (midVal > key)
  52.962 +                high = mid - 1;
  52.963 +            else
  52.964 +                return mid; // key found
  52.965 +        }
  52.966 +        return -(low + 1);  // key not found.
  52.967 +    }
  52.968 +
  52.969 +    /**
  52.970 +     * Searches the specified array of shorts for the specified value using
  52.971 +     * the binary search algorithm.  The array must be sorted
  52.972 +     * (as by the {@link #sort(short[])} method) prior to making this call.  If
  52.973 +     * it is not sorted, the results are undefined.  If the array contains
  52.974 +     * multiple elements with the specified value, there is no guarantee which
  52.975 +     * one will be found.
  52.976 +     *
  52.977 +     * @param a the array to be searched
  52.978 +     * @param key the value to be searched for
  52.979 +     * @return index of the search key, if it is contained in the array;
  52.980 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  52.981 +     *         <i>insertion point</i> is defined as the point at which the
  52.982 +     *         key would be inserted into the array: the index of the first
  52.983 +     *         element greater than the key, or <tt>a.length</tt> if all
  52.984 +     *         elements in the array are less than the specified key.  Note
  52.985 +     *         that this guarantees that the return value will be &gt;= 0 if
  52.986 +     *         and only if the key is found.
  52.987 +     */
  52.988 +    public static int binarySearch(short[] a, short key) {
  52.989 +        return binarySearch0(a, 0, a.length, key);
  52.990 +    }
  52.991 +
  52.992 +    /**
  52.993 +     * Searches a range of
  52.994 +     * the specified array of shorts for the specified value using
  52.995 +     * the binary search algorithm.
  52.996 +     * The range must be sorted
  52.997 +     * (as by the {@link #sort(short[], int, int)} method)
  52.998 +     * prior to making this call.  If
  52.999 +     * it is not sorted, the results are undefined.  If the range contains
 52.1000 +     * multiple elements with the specified value, there is no guarantee which
 52.1001 +     * one will be found.
 52.1002 +     *
 52.1003 +     * @param a the array to be searched
 52.1004 +     * @param fromIndex the index of the first element (inclusive) to be
 52.1005 +     *          searched
 52.1006 +     * @param toIndex the index of the last element (exclusive) to be searched
 52.1007 +     * @param key the value to be searched for
 52.1008 +     * @return index of the search key, if it is contained in the array
 52.1009 +     *         within the specified range;
 52.1010 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 52.1011 +     *         <i>insertion point</i> is defined as the point at which the
 52.1012 +     *         key would be inserted into the array: the index of the first
 52.1013 +     *         element in the range greater than the key,
 52.1014 +     *         or <tt>toIndex</tt> if all
 52.1015 +     *         elements in the range are less than the specified key.  Note
 52.1016 +     *         that this guarantees that the return value will be &gt;= 0 if
 52.1017 +     *         and only if the key is found.
 52.1018 +     * @throws IllegalArgumentException
 52.1019 +     *         if {@code fromIndex > toIndex}
 52.1020 +     * @throws ArrayIndexOutOfBoundsException
 52.1021 +     *         if {@code fromIndex < 0 or toIndex > a.length}
 52.1022 +     * @since 1.6
 52.1023 +     */
 52.1024 +    public static int binarySearch(short[] a, int fromIndex, int toIndex,
 52.1025 +                                   short key) {
 52.1026 +        rangeCheck(a.length, fromIndex, toIndex);
 52.1027 +        return binarySearch0(a, fromIndex, toIndex, key);
 52.1028 +    }
 52.1029 +
 52.1030 +    // Like public version, but without range checks.
 52.1031 +    private static int binarySearch0(short[] a, int fromIndex, int toIndex,
 52.1032 +                                     short key) {
 52.1033 +        int low = fromIndex;
 52.1034 +        int high = toIndex - 1;
 52.1035 +
 52.1036 +        while (low <= high) {
 52.1037 +            int mid = (low + high) >>> 1;
 52.1038 +            short midVal = a[mid];
 52.1039 +
 52.1040 +            if (midVal < key)
 52.1041 +                low = mid + 1;
 52.1042 +            else if (midVal > key)
 52.1043 +                high = mid - 1;
 52.1044 +            else
 52.1045 +                return mid; // key found
 52.1046 +        }
 52.1047 +        return -(low + 1);  // key not found.
 52.1048 +    }
 52.1049 +
 52.1050 +    /**
 52.1051 +     * Searches the specified array of chars for the specified value using the
 52.1052 +     * binary search algorithm.  The array must be sorted (as
 52.1053 +     * by the {@link #sort(char[])} method) prior to making this call.  If it
 52.1054 +     * is not sorted, the results are undefined.  If the array contains
 52.1055 +     * multiple elements with the specified value, there is no guarantee which
 52.1056 +     * one will be found.
 52.1057 +     *
 52.1058 +     * @param a the array to be searched
 52.1059 +     * @param key the value to be searched for
 52.1060 +     * @return index of the search key, if it is contained in the array;
 52.1061 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 52.1062 +     *         <i>insertion point</i> is defined as the point at which the
 52.1063 +     *         key would be inserted into the array: the index of the first
 52.1064 +     *         element greater than the key, or <tt>a.length</tt> if all
 52.1065 +     *         elements in the array are less than the specified key.  Note
 52.1066 +     *         that this guarantees that the return value will be &gt;= 0 if
 52.1067 +     *         and only if the key is found.
 52.1068 +     */
 52.1069 +    public static int binarySearch(char[] a, char key) {
 52.1070 +        return binarySearch0(a, 0, a.length, key);
 52.1071 +    }
 52.1072 +
 52.1073 +    /**
 52.1074 +     * Searches a range of
 52.1075 +     * the specified array of chars for the specified value using the
 52.1076 +     * binary search algorithm.
 52.1077 +     * The range must be sorted (as
 52.1078 +     * by the {@link #sort(char[], int, int)} method)
 52.1079 +     * prior to making this call.  If it
 52.1080 +     * is not sorted, the results are undefined.  If the range contains
 52.1081 +     * multiple elements with the specified value, there is no guarantee which
 52.1082 +     * one will be found.
 52.1083 +     *
 52.1084 +     * @param a the array to be searched
 52.1085 +     * @param fromIndex the index of the first element (inclusive) to be
 52.1086 +     *          searched
 52.1087 +     * @param toIndex the index of the last element (exclusive) to be searched
 52.1088 +     * @param key the value to be searched for
 52.1089 +     * @return index of the search key, if it is contained in the array
 52.1090 +     *         within the specified range;
 52.1091 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 52.1092 +     *         <i>insertion point</i> is defined as the point at which the
 52.1093 +     *         key would be inserted into the array: the index of the first
 52.1094 +     *         element in the range greater than the key,
 52.1095 +     *         or <tt>toIndex</tt> if all
 52.1096 +     *         elements in the range are less than the specified key.  Note
 52.1097 +     *         that this guarantees that the return value will be &gt;= 0 if
 52.1098 +     *         and only if the key is found.
 52.1099 +     * @throws IllegalArgumentException
 52.1100 +     *         if {@code fromIndex > toIndex}
 52.1101 +     * @throws ArrayIndexOutOfBoundsException
 52.1102 +     *         if {@code fromIndex < 0 or toIndex > a.length}
 52.1103 +     * @since 1.6
 52.1104 +     */
 52.1105 +    public static int binarySearch(char[] a, int fromIndex, int toIndex,
 52.1106 +                                   char key) {
 52.1107 +        rangeCheck(a.length, fromIndex, toIndex);
 52.1108 +        return binarySearch0(a, fromIndex, toIndex, key);
 52.1109 +    }
 52.1110 +
 52.1111 +    // Like public version, but without range checks.
 52.1112 +    private static int binarySearch0(char[] a, int fromIndex, int toIndex,
 52.1113 +                                     char key) {
 52.1114 +        int low = fromIndex;
 52.1115 +        int high = toIndex - 1;
 52.1116 +
 52.1117 +        while (low <= high) {
 52.1118 +            int mid = (low + high) >>> 1;
 52.1119 +            char midVal = a[mid];
 52.1120 +
 52.1121 +            if (midVal < key)
 52.1122 +                low = mid + 1;
 52.1123 +            else if (midVal > key)
 52.1124 +                high = mid - 1;
 52.1125 +            else
 52.1126 +                return mid; // key found
 52.1127 +        }
 52.1128 +        return -(low + 1);  // key not found.
 52.1129 +    }
 52.1130 +
 52.1131 +    /**
 52.1132 +     * Searches the specified array of bytes for the specified value using the
 52.1133 +     * binary search algorithm.  The array must be sorted (as
 52.1134 +     * by the {@link #sort(byte[])} method) prior to making this call.  If it
 52.1135 +     * is not sorted, the results are undefined.  If the array contains
 52.1136 +     * multiple elements with the specified value, there is no guarantee which
 52.1137 +     * one will be found.
 52.1138 +     *
 52.1139 +     * @param a the array to be searched
 52.1140 +     * @param key the value to be searched for
 52.1141 +     * @return index of the search key, if it is contained in the array;
 52.1142 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 52.1143 +     *         <i>insertion point</i> is defined as the point at which the
 52.1144 +     *         key would be inserted into the array: the index of the first
 52.1145 +     *         element greater than the key, or <tt>a.length</tt> if all
 52.1146 +     *         elements in the array are less than the specified key.  Note
 52.1147 +     *         that this guarantees that the return value will be &gt;= 0 if
 52.1148 +     *         and only if the key is found.
 52.1149 +     */
 52.1150 +    public static int binarySearch(byte[] a, byte key) {
 52.1151 +        return binarySearch0(a, 0, a.length, key);
 52.1152 +    }
 52.1153 +
 52.1154 +    /**
 52.1155 +     * Searches a range of
 52.1156 +     * the specified array of bytes for the specified value using the
 52.1157 +     * binary search algorithm.
 52.1158 +     * The range must be sorted (as
 52.1159 +     * by the {@link #sort(byte[], int, int)} method)
 52.1160 +     * prior to making this call.  If it
 52.1161 +     * is not sorted, the results are undefined.  If the range contains
 52.1162 +     * multiple elements with the specified value, there is no guarantee which
 52.1163 +     * one will be found.
 52.1164 +     *
 52.1165 +     * @param a the array to be searched
 52.1166 +     * @param fromIndex the index of the first element (inclusive) to be
 52.1167 +     *          searched
 52.1168 +     * @param toIndex the index of the last element (exclusive) to be searched
 52.1169 +     * @param key the value to be searched for
 52.1170 +     * @return index of the search key, if it is contained in the array
 52.1171 +     *         within the specified range;
 52.1172 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 52.1173 +     *         <i>insertion point</i> is defined as the point at which the
 52.1174 +     *         key would be inserted into the array: the index of the first
 52.1175 +     *         element in the range greater than the key,
 52.1176 +     *         or <tt>toIndex</tt> if all
 52.1177 +     *         elements in the range are less than the specified key.  Note
 52.1178 +     *         that this guarantees that the return value will be &gt;= 0 if
 52.1179 +     *         and only if the key is found.
 52.1180 +     * @throws IllegalArgumentException
 52.1181 +     *         if {@code fromIndex > toIndex}
 52.1182 +     * @throws ArrayIndexOutOfBoundsException
 52.1183 +     *         if {@code fromIndex < 0 or toIndex > a.length}
 52.1184 +     * @since 1.6
 52.1185 +     */
 52.1186 +    public static int binarySearch(byte[] a, int fromIndex, int toIndex,
 52.1187 +                                   byte key) {
 52.1188 +        rangeCheck(a.length, fromIndex, toIndex);
 52.1189 +        return binarySearch0(a, fromIndex, toIndex, key);
 52.1190 +    }
 52.1191 +
 52.1192 +    // Like public version, but without range checks.
 52.1193 +    private static int binarySearch0(byte[] a, int fromIndex, int toIndex,
 52.1194 +                                     byte key) {
 52.1195 +        int low = fromIndex;
 52.1196 +        int high = toIndex - 1;
 52.1197 +
 52.1198 +        while (low <= high) {
 52.1199 +            int mid = (low + high) >>> 1;
 52.1200 +            byte midVal = a[mid];
 52.1201 +
 52.1202 +            if (midVal < key)
 52.1203 +                low = mid + 1;
 52.1204 +            else if (midVal > key)
 52.1205 +                high = mid - 1;
 52.1206 +            else
 52.1207 +                return mid; // key found
 52.1208 +        }
 52.1209 +        return -(low + 1);  // key not found.
 52.1210 +    }
 52.1211 +
 52.1212 +    /**
 52.1213 +     * Searches the specified array of doubles for the specified value using
 52.1214 +     * the binary search algorithm.  The array must be sorted
 52.1215 +     * (as by the {@link #sort(double[])} method) prior to making this call.
 52.1216 +     * If it is not sorted, the results are undefined.  If the array contains
 52.1217 +     * multiple elements with the specified value, there is no guarantee which
 52.1218 +     * one will be found.  This method considers all NaN values to be
 52.1219 +     * equivalent and equal.
 52.1220 +     *
 52.1221 +     * @param a the array to be searched
 52.1222 +     * @param key the value to be searched for
 52.1223 +     * @return index of the search key, if it is contained in the array;
 52.1224 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 52.1225 +     *         <i>insertion point</i> is defined as the point at which the
 52.1226 +     *         key would be inserted into the array: the index of the first
 52.1227 +     *         element greater than the key, or <tt>a.length</tt> if all
 52.1228 +     *         elements in the array are less than the specified key.  Note
 52.1229 +     *         that this guarantees that the return value will be &gt;= 0 if
 52.1230 +     *         and only if the key is found.
 52.1231 +     */
 52.1232 +    public static int binarySearch(double[] a, double key) {
 52.1233 +        return binarySearch0(a, 0, a.length, key);
 52.1234 +    }
 52.1235 +
 52.1236 +    /**
 52.1237 +     * Searches a range of
 52.1238 +     * the specified array of doubles for the specified value using
 52.1239 +     * the binary search algorithm.
 52.1240 +     * The range must be sorted
 52.1241 +     * (as by the {@link #sort(double[], int, int)} method)
 52.1242 +     * prior to making this call.
 52.1243 +     * If it is not sorted, the results are undefined.  If the range contains
 52.1244 +     * multiple elements with the specified value, there is no guarantee which
 52.1245 +     * one will be found.  This method considers all NaN values to be
 52.1246 +     * equivalent and equal.
 52.1247 +     *
 52.1248 +     * @param a the array to be searched
 52.1249 +     * @param fromIndex the index of the first element (inclusive) to be
 52.1250 +     *          searched
 52.1251 +     * @param toIndex the index of the last element (exclusive) to be searched
 52.1252 +     * @param key the value to be searched for
 52.1253 +     * @return index of the search key, if it is contained in the array
 52.1254 +     *         within the specified range;
 52.1255 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 52.1256 +     *         <i>insertion point</i> is defined as the point at which the
 52.1257 +     *         key would be inserted into the array: the index of the first
 52.1258 +     *         element in the range greater than the key,
 52.1259 +     *         or <tt>toIndex</tt> if all
 52.1260 +     *         elements in the range are less than the specified key.  Note
 52.1261 +     *         that this guarantees that the return value will be &gt;= 0 if
 52.1262 +     *         and only if the key is found.
 52.1263 +     * @throws IllegalArgumentException
 52.1264 +     *         if {@code fromIndex > toIndex}
 52.1265 +     * @throws ArrayIndexOutOfBoundsException
 52.1266 +     *         if {@code fromIndex < 0 or toIndex > a.length}
 52.1267 +     * @since 1.6
 52.1268 +     */
 52.1269 +    public static int binarySearch(double[] a, int fromIndex, int toIndex,
 52.1270 +                                   double key) {
 52.1271 +        rangeCheck(a.length, fromIndex, toIndex);
 52.1272 +        return binarySearch0(a, fromIndex, toIndex, key);
 52.1273 +    }
 52.1274 +
 52.1275 +    // Like public version, but without range checks.
 52.1276 +    private static int binarySearch0(double[] a, int fromIndex, int toIndex,
 52.1277 +                                     double key) {
 52.1278 +        int low = fromIndex;
 52.1279 +        int high = toIndex - 1;
 52.1280 +
 52.1281 +        while (low <= high) {
 52.1282 +            int mid = (low + high) >>> 1;
 52.1283 +            double midVal = a[mid];
 52.1284 +
 52.1285 +            if (midVal < key)
 52.1286 +                low = mid + 1;  // Neither val is NaN, thisVal is smaller
 52.1287 +            else if (midVal > key)
 52.1288 +                high = mid - 1; // Neither val is NaN, thisVal is larger
 52.1289 +            else {
 52.1290 +                long midBits = Double.doubleToLongBits(midVal);
 52.1291 +                long keyBits = Double.doubleToLongBits(key);
 52.1292 +                if (midBits == keyBits)     // Values are equal
 52.1293 +                    return mid;             // Key found
 52.1294 +                else if (midBits < keyBits) // (-0.0, 0.0) or (!NaN, NaN)
 52.1295 +                    low = mid + 1;
 52.1296 +                else                        // (0.0, -0.0) or (NaN, !NaN)
 52.1297 +                    high = mid - 1;
 52.1298 +            }
 52.1299 +        }
 52.1300 +        return -(low + 1);  // key not found.
 52.1301 +    }
 52.1302 +
 52.1303 +    /**
 52.1304 +     * Searches the specified array of floats for the specified value using
 52.1305 +     * the binary search algorithm. The array must be sorted
 52.1306 +     * (as by the {@link #sort(float[])} method) prior to making this call. If
 52.1307 +     * it is not sorted, the results are undefined. If the array contains
 52.1308 +     * multiple elements with the specified value, there is no guarantee which
 52.1309 +     * one will be found. This method considers all NaN values to be
 52.1310 +     * equivalent and equal.
 52.1311 +     *
 52.1312 +     * @param a the array to be searched
 52.1313 +     * @param key the value to be searched for
 52.1314 +     * @return index of the search key, if it is contained in the array;
 52.1315 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>. The
 52.1316 +     *         <i>insertion point</i> is defined as the point at which the
 52.1317 +     *         key would be inserted into the array: the index of the first
 52.1318 +     *         element greater than the key, or <tt>a.length</tt> if all
 52.1319 +     *         elements in the array are less than the specified key. Note
 52.1320 +     *         that this guarantees that the return value will be &gt;= 0 if
 52.1321 +     *         and only if the key is found.
 52.1322 +     */
 52.1323 +    public static int binarySearch(float[] a, float key) {
 52.1324 +        return binarySearch0(a, 0, a.length, key);
 52.1325 +    }
 52.1326 +
 52.1327 +    /**
 52.1328 +     * Searches a range of
 52.1329 +     * the specified array of floats for the specified value using
 52.1330 +     * the binary search algorithm.
 52.1331 +     * The range must be sorted
 52.1332 +     * (as by the {@link #sort(float[], int, int)} method)
 52.1333 +     * prior to making this call. If
 52.1334 +     * it is not sorted, the results are undefined. If the range contains
 52.1335 +     * multiple elements with the specified value, there is no guarantee which
 52.1336 +     * one will be found. This method considers all NaN values to be
 52.1337 +     * equivalent and equal.
 52.1338 +     *
 52.1339 +     * @param a the array to be searched
 52.1340 +     * @param fromIndex the index of the first element (inclusive) to be
 52.1341 +     *          searched
 52.1342 +     * @param toIndex the index of the last element (exclusive) to be searched
 52.1343 +     * @param key the value to be searched for
 52.1344 +     * @return index of the search key, if it is contained in the array
 52.1345 +     *         within the specified range;
 52.1346 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>. The
 52.1347 +     *         <i>insertion point</i> is defined as the point at which the
 52.1348 +     *         key would be inserted into the array: the index of the first
 52.1349 +     *         element in the range greater than the key,
 52.1350 +     *         or <tt>toIndex</tt> if all
 52.1351 +     *         elements in the range are less than the specified key. Note
 52.1352 +     *         that this guarantees that the return value will be &gt;= 0 if
 52.1353 +     *         and only if the key is found.
 52.1354 +     * @throws IllegalArgumentException
 52.1355 +     *         if {@code fromIndex > toIndex}
 52.1356 +     * @throws ArrayIndexOutOfBoundsException
 52.1357 +     *         if {@code fromIndex < 0 or toIndex > a.length}
 52.1358 +     * @since 1.6
 52.1359 +     */
 52.1360 +    public static int binarySearch(float[] a, int fromIndex, int toIndex,
 52.1361 +                                   float key) {
 52.1362 +        rangeCheck(a.length, fromIndex, toIndex);
 52.1363 +        return binarySearch0(a, fromIndex, toIndex, key);
 52.1364 +    }
 52.1365 +
 52.1366 +    // Like public version, but without range checks.
 52.1367 +    private static int binarySearch0(float[] a, int fromIndex, int toIndex,
 52.1368 +                                     float key) {
 52.1369 +        int low = fromIndex;
 52.1370 +        int high = toIndex - 1;
 52.1371 +
 52.1372 +        while (low <= high) {
 52.1373 +            int mid = (low + high) >>> 1;
 52.1374 +            float midVal = a[mid];
 52.1375 +
 52.1376 +            if (midVal < key)
 52.1377 +                low = mid + 1;  // Neither val is NaN, thisVal is smaller
 52.1378 +            else if (midVal > key)
 52.1379 +                high = mid - 1; // Neither val is NaN, thisVal is larger
 52.1380 +            else {
 52.1381 +                int midBits = Float.floatToIntBits(midVal);
 52.1382 +                int keyBits = Float.floatToIntBits(key);
 52.1383 +                if (midBits == keyBits)     // Values are equal
 52.1384 +                    return mid;             // Key found
 52.1385 +                else if (midBits < keyBits) // (-0.0, 0.0) or (!NaN, NaN)
 52.1386 +                    low = mid + 1;
 52.1387 +                else                        // (0.0, -0.0) or (NaN, !NaN)
 52.1388 +                    high = mid - 1;
 52.1389 +            }
 52.1390 +        }
 52.1391 +        return -(low + 1);  // key not found.
 52.1392 +    }
 52.1393 +
 52.1394 +    /**
 52.1395 +     * Searches the specified array for the specified object using the binary
 52.1396 +     * search algorithm. The array must be sorted into ascending order
 52.1397 +     * according to the
 52.1398 +     * {@linkplain Comparable natural ordering}
 52.1399 +     * of its elements (as by the
 52.1400 +     * {@link #sort(Object[])} method) prior to making this call.
 52.1401 +     * If it is not sorted, the results are undefined.
 52.1402 +     * (If the array contains elements that are not mutually comparable (for
 52.1403 +     * example, strings and integers), it <i>cannot</i> be sorted according
 52.1404 +     * to the natural ordering of its elements, hence results are undefined.)
 52.1405 +     * If the array contains multiple
 52.1406 +     * elements equal to the specified object, there is no guarantee which
 52.1407 +     * one will be found.
 52.1408 +     *
 52.1409 +     * @param a the array to be searched
 52.1410 +     * @param key the value to be searched for
 52.1411 +     * @return index of the search key, if it is contained in the array;
 52.1412 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 52.1413 +     *         <i>insertion point</i> is defined as the point at which the
 52.1414 +     *         key would be inserted into the array: the index of the first
 52.1415 +     *         element greater than the key, or <tt>a.length</tt> if all
 52.1416 +     *         elements in the array are less than the specified key.  Note
 52.1417 +     *         that this guarantees that the return value will be &gt;= 0 if
 52.1418 +     *         and only if the key is found.
 52.1419 +     * @throws ClassCastException if the search key is not comparable to the
 52.1420 +     *         elements of the array.
 52.1421 +     */
 52.1422 +    public static int binarySearch(Object[] a, Object key) {
 52.1423 +        return binarySearch0(a, 0, a.length, key);
 52.1424 +    }
 52.1425 +
 52.1426 +    /**
 52.1427 +     * Searches a range of
 52.1428 +     * the specified array for the specified object using the binary
 52.1429 +     * search algorithm.
 52.1430 +     * The range must be sorted into ascending order
 52.1431 +     * according to the
 52.1432 +     * {@linkplain Comparable natural ordering}
 52.1433 +     * of its elements (as by the
 52.1434 +     * {@link #sort(Object[], int, int)} method) prior to making this
 52.1435 +     * call.  If it is not sorted, the results are undefined.
 52.1436 +     * (If the range contains elements that are not mutually comparable (for
 52.1437 +     * example, strings and integers), it <i>cannot</i> be sorted according
 52.1438 +     * to the natural ordering of its elements, hence results are undefined.)
 52.1439 +     * If the range contains multiple
 52.1440 +     * elements equal to the specified object, there is no guarantee which
 52.1441 +     * one will be found.
 52.1442 +     *
 52.1443 +     * @param a the array to be searched
 52.1444 +     * @param fromIndex the index of the first element (inclusive) to be
 52.1445 +     *          searched
 52.1446 +     * @param toIndex the index of the last element (exclusive) to be searched
 52.1447 +     * @param key the value to be searched for
 52.1448 +     * @return index of the search key, if it is contained in the array
 52.1449 +     *         within the specified range;
 52.1450 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 52.1451 +     *         <i>insertion point</i> is defined as the point at which the
 52.1452 +     *         key would be inserted into the array: the index of the first
 52.1453 +     *         element in the range greater than the key,
 52.1454 +     *         or <tt>toIndex</tt> if all
 52.1455 +     *         elements in the range are less than the specified key.  Note
 52.1456 +     *         that this guarantees that the return value will be &gt;= 0 if
 52.1457 +     *         and only if the key is found.
 52.1458 +     * @throws ClassCastException if the search key is not comparable to the
 52.1459 +     *         elements of the array within the specified range.
 52.1460 +     * @throws IllegalArgumentException
 52.1461 +     *         if {@code fromIndex > toIndex}
 52.1462 +     * @throws ArrayIndexOutOfBoundsException
 52.1463 +     *         if {@code fromIndex < 0 or toIndex > a.length}
 52.1464 +     * @since 1.6
 52.1465 +     */
 52.1466 +    public static int binarySearch(Object[] a, int fromIndex, int toIndex,
 52.1467 +                                   Object key) {
 52.1468 +        rangeCheck(a.length, fromIndex, toIndex);
 52.1469 +        return binarySearch0(a, fromIndex, toIndex, key);
 52.1470 +    }
 52.1471 +
 52.1472 +    // Like public version, but without range checks.
 52.1473 +    private static int binarySearch0(Object[] a, int fromIndex, int toIndex,
 52.1474 +                                     Object key) {
 52.1475 +        int low = fromIndex;
 52.1476 +        int high = toIndex - 1;
 52.1477 +
 52.1478 +        while (low <= high) {
 52.1479 +            int mid = (low + high) >>> 1;
 52.1480 +            Comparable midVal = (Comparable)a[mid];
 52.1481 +            int cmp = midVal.compareTo(key);
 52.1482 +
 52.1483 +            if (cmp < 0)
 52.1484 +                low = mid + 1;
 52.1485 +            else if (cmp > 0)
 52.1486 +                high = mid - 1;
 52.1487 +            else
 52.1488 +                return mid; // key found
 52.1489 +        }
 52.1490 +        return -(low + 1);  // key not found.
 52.1491 +    }
 52.1492 +
 52.1493 +    /**
 52.1494 +     * Searches the specified array for the specified object using the binary
 52.1495 +     * search algorithm.  The array must be sorted into ascending order
 52.1496 +     * according to the specified comparator (as by the
 52.1497 +     * {@link #sort(Object[], Comparator) sort(T[], Comparator)}
 52.1498 +     * method) prior to making this call.  If it is
 52.1499 +     * not sorted, the results are undefined.
 52.1500 +     * If the array contains multiple
 52.1501 +     * elements equal to the specified object, there is no guarantee which one
 52.1502 +     * will be found.
 52.1503 +     *
 52.1504 +     * @param a the array to be searched
 52.1505 +     * @param key the value to be searched for
 52.1506 +     * @param c the comparator by which the array is ordered.  A
 52.1507 +     *        <tt>null</tt> value indicates that the elements'
 52.1508 +     *        {@linkplain Comparable natural ordering} should be used.
 52.1509 +     * @return index of the search key, if it is contained in the array;
 52.1510 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 52.1511 +     *         <i>insertion point</i> is defined as the point at which the
 52.1512 +     *         key would be inserted into the array: the index of the first
 52.1513 +     *         element greater than the key, or <tt>a.length</tt> if all
 52.1514 +     *         elements in the array are less than the specified key.  Note
 52.1515 +     *         that this guarantees that the return value will be &gt;= 0 if
 52.1516 +     *         and only if the key is found.
 52.1517 +     * @throws ClassCastException if the array contains elements that are not
 52.1518 +     *         <i>mutually comparable</i> using the specified comparator,
 52.1519 +     *         or the search key is not comparable to the
 52.1520 +     *         elements of the array using this comparator.
 52.1521 +     */
 52.1522 +    public static <T> int binarySearch(T[] a, T key, Comparator<? super T> c) {
 52.1523 +        return binarySearch0(a, 0, a.length, key, c);
 52.1524 +    }
 52.1525 +
 52.1526 +    /**
 52.1527 +     * Searches a range of
 52.1528 +     * the specified array for the specified object using the binary
 52.1529 +     * search algorithm.
 52.1530 +     * The range must be sorted into ascending order
 52.1531 +     * according to the specified comparator (as by the
 52.1532 +     * {@link #sort(Object[], int, int, Comparator)
 52.1533 +     * sort(T[], int, int, Comparator)}
 52.1534 +     * method) prior to making this call.
 52.1535 +     * If it is not sorted, the results are undefined.
 52.1536 +     * If the range contains multiple elements equal to the specified object,
 52.1537 +     * there is no guarantee which one will be found.
 52.1538 +     *
 52.1539 +     * @param a the array to be searched
 52.1540 +     * @param fromIndex the index of the first element (inclusive) to be
 52.1541 +     *          searched
 52.1542 +     * @param toIndex the index of the last element (exclusive) to be searched
 52.1543 +     * @param key the value to be searched for
 52.1544 +     * @param c the comparator by which the array is ordered.  A
 52.1545 +     *        <tt>null</tt> value indicates that the elements'
 52.1546 +     *        {@linkplain Comparable natural ordering} should be used.
 52.1547 +     * @return index of the search key, if it is contained in the array
 52.1548 +     *         within the specified range;
 52.1549 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 52.1550 +     *         <i>insertion point</i> is defined as the point at which the
 52.1551 +     *         key would be inserted into the array: the index of the first
 52.1552 +     *         element in the range greater than the key,
 52.1553 +     *         or <tt>toIndex</tt> if all
 52.1554 +     *         elements in the range are less than the specified key.  Note
 52.1555 +     *         that this guarantees that the return value will be &gt;= 0 if
 52.1556 +     *         and only if the key is found.
 52.1557 +     * @throws ClassCastException if the range contains elements that are not
 52.1558 +     *         <i>mutually comparable</i> using the specified comparator,
 52.1559 +     *         or the search key is not comparable to the
 52.1560 +     *         elements in the range using this comparator.
 52.1561 +     * @throws IllegalArgumentException
 52.1562 +     *         if {@code fromIndex > toIndex}
 52.1563 +     * @throws ArrayIndexOutOfBoundsException
 52.1564 +     *         if {@code fromIndex < 0 or toIndex > a.length}
 52.1565 +     * @since 1.6
 52.1566 +     */
 52.1567 +    public static <T> int binarySearch(T[] a, int fromIndex, int toIndex,
 52.1568 +                                       T key, Comparator<? super T> c) {
 52.1569 +        rangeCheck(a.length, fromIndex, toIndex);
 52.1570 +        return binarySearch0(a, fromIndex, toIndex, key, c);
 52.1571 +    }
 52.1572 +
 52.1573 +    // Like public version, but without range checks.
 52.1574 +    private static <T> int binarySearch0(T[] a, int fromIndex, int toIndex,
 52.1575 +                                         T key, Comparator<? super T> c) {
 52.1576 +        if (c == null) {
 52.1577 +            return binarySearch0(a, fromIndex, toIndex, key);
 52.1578 +        }
 52.1579 +        int low = fromIndex;
 52.1580 +        int high = toIndex - 1;
 52.1581 +
 52.1582 +        while (low <= high) {
 52.1583 +            int mid = (low + high) >>> 1;
 52.1584 +            T midVal = a[mid];
 52.1585 +            int cmp = c.compare(midVal, key);
 52.1586 +            if (cmp < 0)
 52.1587 +                low = mid + 1;
 52.1588 +            else if (cmp > 0)
 52.1589 +                high = mid - 1;
 52.1590 +            else
 52.1591 +                return mid; // key found
 52.1592 +        }
 52.1593 +        return -(low + 1);  // key not found.
 52.1594 +    }
 52.1595 +
 52.1596 +    // Equality Testing
 52.1597 +
 52.1598 +    /**
 52.1599 +     * Returns <tt>true</tt> if the two specified arrays of longs are
 52.1600 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
 52.1601 +     * arrays contain the same number of elements, and all corresponding pairs
 52.1602 +     * of elements in the two arrays are equal.  In other words, two arrays
 52.1603 +     * are equal if they contain the same elements in the same order.  Also,
 52.1604 +     * two array references are considered equal if both are <tt>null</tt>.<p>
 52.1605 +     *
 52.1606 +     * @param a one array to be tested for equality
 52.1607 +     * @param a2 the other array to be tested for equality
 52.1608 +     * @return <tt>true</tt> if the two arrays are equal
 52.1609 +     */
 52.1610 +    public static boolean equals(long[] a, long[] a2) {
 52.1611 +        if (a==a2)
 52.1612 +            return true;
 52.1613 +        if (a==null || a2==null)
 52.1614 +            return false;
 52.1615 +
 52.1616 +        int length = a.length;
 52.1617 +        if (a2.length != length)
 52.1618 +            return false;
 52.1619 +
 52.1620 +        for (int i=0; i<length; i++)
 52.1621 +            if (a[i] != a2[i])
 52.1622 +                return false;
 52.1623 +
 52.1624 +        return true;
 52.1625 +    }
 52.1626 +
 52.1627 +    /**
 52.1628 +     * Returns <tt>true</tt> if the two specified arrays of ints are
 52.1629 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
 52.1630 +     * arrays contain the same number of elements, and all corresponding pairs
 52.1631 +     * of elements in the two arrays are equal.  In other words, two arrays
 52.1632 +     * are equal if they contain the same elements in the same order.  Also,
 52.1633 +     * two array references are considered equal if both are <tt>null</tt>.<p>
 52.1634 +     *
 52.1635 +     * @param a one array to be tested for equality
 52.1636 +     * @param a2 the other array to be tested for equality
 52.1637 +     * @return <tt>true</tt> if the two arrays are equal
 52.1638 +     */
 52.1639 +    public static boolean equals(int[] a, int[] a2) {
 52.1640 +        if (a==a2)
 52.1641 +            return true;
 52.1642 +        if (a==null || a2==null)
 52.1643 +            return false;
 52.1644 +
 52.1645 +        int length = a.length;
 52.1646 +        if (a2.length != length)
 52.1647 +            return false;
 52.1648 +
 52.1649 +        for (int i=0; i<length; i++)
 52.1650 +            if (a[i] != a2[i])
 52.1651 +                return false;
 52.1652 +
 52.1653 +        return true;
 52.1654 +    }
 52.1655 +
 52.1656 +    /**
 52.1657 +     * Returns <tt>true</tt> if the two specified arrays of shorts are
 52.1658 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
 52.1659 +     * arrays contain the same number of elements, and all corresponding pairs
 52.1660 +     * of elements in the two arrays are equal.  In other words, two arrays
 52.1661 +     * are equal if they contain the same elements in the same order.  Also,
 52.1662 +     * two array references are considered equal if both are <tt>null</tt>.<p>
 52.1663 +     *
 52.1664 +     * @param a one array to be tested for equality
 52.1665 +     * @param a2 the other array to be tested for equality
 52.1666 +     * @return <tt>true</tt> if the two arrays are equal
 52.1667 +     */
 52.1668 +    public static boolean equals(short[] a, short a2[]) {
 52.1669 +        if (a==a2)
 52.1670 +            return true;
 52.1671 +        if (a==null || a2==null)
 52.1672 +            return false;
 52.1673 +
 52.1674 +        int length = a.length;
 52.1675 +        if (a2.length != length)
 52.1676 +            return false;
 52.1677 +
 52.1678 +        for (int i=0; i<length; i++)
 52.1679 +            if (a[i] != a2[i])
 52.1680 +                return false;
 52.1681 +
 52.1682 +        return true;
 52.1683 +    }
 52.1684 +
 52.1685 +    /**
 52.1686 +     * Returns <tt>true</tt> if the two specified arrays of chars are
 52.1687 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
 52.1688 +     * arrays contain the same number of elements, and all corresponding pairs
 52.1689 +     * of elements in the two arrays are equal.  In other words, two arrays
 52.1690 +     * are equal if they contain the same elements in the same order.  Also,
 52.1691 +     * two array references are considered equal if both are <tt>null</tt>.<p>
 52.1692 +     *
 52.1693 +     * @param a one array to be tested for equality
 52.1694 +     * @param a2 the other array to be tested for equality
 52.1695 +     * @return <tt>true</tt> if the two arrays are equal
 52.1696 +     */
 52.1697 +    public static boolean equals(char[] a, char[] a2) {
 52.1698 +        if (a==a2)
 52.1699 +            return true;
 52.1700 +        if (a==null || a2==null)
 52.1701 +            return false;
 52.1702 +
 52.1703 +        int length = a.length;
 52.1704 +        if (a2.length != length)
 52.1705 +            return false;
 52.1706 +
 52.1707 +        for (int i=0; i<length; i++)
 52.1708 +            if (a[i] != a2[i])
 52.1709 +                return false;
 52.1710 +
 52.1711 +        return true;
 52.1712 +    }
 52.1713 +
 52.1714 +    /**
 52.1715 +     * Returns <tt>true</tt> if the two specified arrays of bytes are
 52.1716 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
 52.1717 +     * arrays contain the same number of elements, and all corresponding pairs
 52.1718 +     * of elements in the two arrays are equal.  In other words, two arrays
 52.1719 +     * are equal if they contain the same elements in the same order.  Also,
 52.1720 +     * two array references are considered equal if both are <tt>null</tt>.<p>
 52.1721 +     *
 52.1722 +     * @param a one array to be tested for equality
 52.1723 +     * @param a2 the other array to be tested for equality
 52.1724 +     * @return <tt>true</tt> if the two arrays are equal
 52.1725 +     */
 52.1726 +    public static boolean equals(byte[] a, byte[] a2) {
 52.1727 +        if (a==a2)
 52.1728 +            return true;
 52.1729 +        if (a==null || a2==null)
 52.1730 +            return false;
 52.1731 +
 52.1732 +        int length = a.length;
 52.1733 +        if (a2.length != length)
 52.1734 +            return false;
 52.1735 +
 52.1736 +        for (int i=0; i<length; i++)
 52.1737 +            if (a[i] != a2[i])
 52.1738 +                return false;
 52.1739 +
 52.1740 +        return true;
 52.1741 +    }
 52.1742 +
 52.1743 +    /**
 52.1744 +     * Returns <tt>true</tt> if the two specified arrays of booleans are
 52.1745 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
 52.1746 +     * arrays contain the same number of elements, and all corresponding pairs
 52.1747 +     * of elements in the two arrays are equal.  In other words, two arrays
 52.1748 +     * are equal if they contain the same elements in the same order.  Also,
 52.1749 +     * two array references are considered equal if both are <tt>null</tt>.<p>
 52.1750 +     *
 52.1751 +     * @param a one array to be tested for equality
 52.1752 +     * @param a2 the other array to be tested for equality
 52.1753 +     * @return <tt>true</tt> if the two arrays are equal
 52.1754 +     */
 52.1755 +    public static boolean equals(boolean[] a, boolean[] a2) {
 52.1756 +        if (a==a2)
 52.1757 +            return true;
 52.1758 +        if (a==null || a2==null)
 52.1759 +            return false;
 52.1760 +
 52.1761 +        int length = a.length;
 52.1762 +        if (a2.length != length)
 52.1763 +            return false;
 52.1764 +
 52.1765 +        for (int i=0; i<length; i++)
 52.1766 +            if (a[i] != a2[i])
 52.1767 +                return false;
 52.1768 +
 52.1769 +        return true;
 52.1770 +    }
 52.1771 +
 52.1772 +    /**
 52.1773 +     * Returns <tt>true</tt> if the two specified arrays of doubles are
 52.1774 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
 52.1775 +     * arrays contain the same number of elements, and all corresponding pairs
 52.1776 +     * of elements in the two arrays are equal.  In other words, two arrays
 52.1777 +     * are equal if they contain the same elements in the same order.  Also,
 52.1778 +     * two array references are considered equal if both are <tt>null</tt>.<p>
 52.1779 +     *
 52.1780 +     * Two doubles <tt>d1</tt> and <tt>d2</tt> are considered equal if:
 52.1781 +     * <pre>    <tt>new Double(d1).equals(new Double(d2))</tt></pre>
 52.1782 +     * (Unlike the <tt>==</tt> operator, this method considers
 52.1783 +     * <tt>NaN</tt> equals to itself, and 0.0d unequal to -0.0d.)
 52.1784 +     *
 52.1785 +     * @param a one array to be tested for equality
 52.1786 +     * @param a2 the other array to be tested for equality
 52.1787 +     * @return <tt>true</tt> if the two arrays are equal
 52.1788 +     * @see Double#equals(Object)
 52.1789 +     */
 52.1790 +    public static boolean equals(double[] a, double[] a2) {
 52.1791 +        if (a==a2)
 52.1792 +            return true;
 52.1793 +        if (a==null || a2==null)
 52.1794 +            return false;
 52.1795 +
 52.1796 +        int length = a.length;
 52.1797 +        if (a2.length != length)
 52.1798 +            return false;
 52.1799 +
 52.1800 +        for (int i=0; i<length; i++)
 52.1801 +            if (Double.doubleToLongBits(a[i])!=Double.doubleToLongBits(a2[i]))
 52.1802 +                return false;
 52.1803 +
 52.1804 +        return true;
 52.1805 +    }
 52.1806 +
 52.1807 +    /**
 52.1808 +     * Returns <tt>true</tt> if the two specified arrays of floats are
 52.1809 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
 52.1810 +     * arrays contain the same number of elements, and all corresponding pairs
 52.1811 +     * of elements in the two arrays are equal.  In other words, two arrays
 52.1812 +     * are equal if they contain the same elements in the same order.  Also,
 52.1813 +     * two array references are considered equal if both are <tt>null</tt>.<p>
 52.1814 +     *
 52.1815 +     * Two floats <tt>f1</tt> and <tt>f2</tt> are considered equal if:
 52.1816 +     * <pre>    <tt>new Float(f1).equals(new Float(f2))</tt></pre>
 52.1817 +     * (Unlike the <tt>==</tt> operator, this method considers
 52.1818 +     * <tt>NaN</tt> equals to itself, and 0.0f unequal to -0.0f.)
 52.1819 +     *
 52.1820 +     * @param a one array to be tested for equality
 52.1821 +     * @param a2 the other array to be tested for equality
 52.1822 +     * @return <tt>true</tt> if the two arrays are equal
 52.1823 +     * @see Float#equals(Object)
 52.1824 +     */
 52.1825 +    public static boolean equals(float[] a, float[] a2) {
 52.1826 +        if (a==a2)
 52.1827 +            return true;
 52.1828 +        if (a==null || a2==null)
 52.1829 +            return false;
 52.1830 +
 52.1831 +        int length = a.length;
 52.1832 +        if (a2.length != length)
 52.1833 +            return false;
 52.1834 +
 52.1835 +        for (int i=0; i<length; i++)
 52.1836 +            if (Float.floatToIntBits(a[i])!=Float.floatToIntBits(a2[i]))
 52.1837 +                return false;
 52.1838 +
 52.1839 +        return true;
 52.1840 +    }
 52.1841 +
 52.1842 +    /**
 52.1843 +     * Returns <tt>true</tt> if the two specified arrays of Objects are
 52.1844 +     * <i>equal</i> to one another.  The two arrays are considered equal if
 52.1845 +     * both arrays contain the same number of elements, and all corresponding
 52.1846 +     * pairs of elements in the two arrays are equal.  Two objects <tt>e1</tt>
 52.1847 +     * and <tt>e2</tt> are considered <i>equal</i> if <tt>(e1==null ? e2==null
 52.1848 +     * : e1.equals(e2))</tt>.  In other words, the two arrays are equal if
 52.1849 +     * they contain the same elements in the same order.  Also, two array
 52.1850 +     * references are considered equal if both are <tt>null</tt>.<p>
 52.1851 +     *
 52.1852 +     * @param a one array to be tested for equality
 52.1853 +     * @param a2 the other array to be tested for equality
 52.1854 +     * @return <tt>true</tt> if the two arrays are equal
 52.1855 +     */
 52.1856 +    public static boolean equals(Object[] a, Object[] a2) {
 52.1857 +        if (a==a2)
 52.1858 +            return true;
 52.1859 +        if (a==null || a2==null)
 52.1860 +            return false;
 52.1861 +
 52.1862 +        int length = a.length;
 52.1863 +        if (a2.length != length)
 52.1864 +            return false;
 52.1865 +
 52.1866 +        for (int i=0; i<length; i++) {
 52.1867 +            Object o1 = a[i];
 52.1868 +            Object o2 = a2[i];
 52.1869 +            if (!(o1==null ? o2==null : o1.equals(o2)))
 52.1870 +                return false;
 52.1871 +        }
 52.1872 +
 52.1873 +        return true;
 52.1874 +    }
 52.1875 +
 52.1876 +    // Filling
 52.1877 +
 52.1878 +    /**
 52.1879 +     * Assigns the specified long value to each element of the specified array
 52.1880 +     * of longs.
 52.1881 +     *
 52.1882 +     * @param a the array to be filled
 52.1883 +     * @param val the value to be stored in all elements of the array
 52.1884 +     */
 52.1885 +    public static void fill(long[] a, long val) {
 52.1886 +        for (int i = 0, len = a.length; i < len; i++)
 52.1887 +            a[i] = val;
 52.1888 +    }
 52.1889 +
 52.1890 +    /**
 52.1891 +     * Assigns the specified long value to each element of the specified
 52.1892 +     * range of the specified array of longs.  The range to be filled
 52.1893 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
 52.1894 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 52.1895 +     * range to be filled is empty.)
 52.1896 +     *
 52.1897 +     * @param a the array to be filled
 52.1898 +     * @param fromIndex the index of the first element (inclusive) to be
 52.1899 +     *        filled with the specified value
 52.1900 +     * @param toIndex the index of the last element (exclusive) to be
 52.1901 +     *        filled with the specified value
 52.1902 +     * @param val the value to be stored in all elements of the array
 52.1903 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 52.1904 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 52.1905 +     *         <tt>toIndex &gt; a.length</tt>
 52.1906 +     */
 52.1907 +    public static void fill(long[] a, int fromIndex, int toIndex, long val) {
 52.1908 +        rangeCheck(a.length, fromIndex, toIndex);
 52.1909 +        for (int i = fromIndex; i < toIndex; i++)
 52.1910 +            a[i] = val;
 52.1911 +    }
 52.1912 +
 52.1913 +    /**
 52.1914 +     * Assigns the specified int value to each element of the specified array
 52.1915 +     * of ints.
 52.1916 +     *
 52.1917 +     * @param a the array to be filled
 52.1918 +     * @param val the value to be stored in all elements of the array
 52.1919 +     */
 52.1920 +    public static void fill(int[] a, int val) {
 52.1921 +        for (int i = 0, len = a.length; i < len; i++)
 52.1922 +            a[i] = val;
 52.1923 +    }
 52.1924 +
 52.1925 +    /**
 52.1926 +     * Assigns the specified int value to each element of the specified
 52.1927 +     * range of the specified array of ints.  The range to be filled
 52.1928 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
 52.1929 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 52.1930 +     * range to be filled is empty.)
 52.1931 +     *
 52.1932 +     * @param a the array to be filled
 52.1933 +     * @param fromIndex the index of the first element (inclusive) to be
 52.1934 +     *        filled with the specified value
 52.1935 +     * @param toIndex the index of the last element (exclusive) to be
 52.1936 +     *        filled with the specified value
 52.1937 +     * @param val the value to be stored in all elements of the array
 52.1938 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 52.1939 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 52.1940 +     *         <tt>toIndex &gt; a.length</tt>
 52.1941 +     */
 52.1942 +    public static void fill(int[] a, int fromIndex, int toIndex, int val) {
 52.1943 +        rangeCheck(a.length, fromIndex, toIndex);
 52.1944 +        for (int i = fromIndex; i < toIndex; i++)
 52.1945 +            a[i] = val;
 52.1946 +    }
 52.1947 +
 52.1948 +    /**
 52.1949 +     * Assigns the specified short value to each element of the specified array
 52.1950 +     * of shorts.
 52.1951 +     *
 52.1952 +     * @param a the array to be filled
 52.1953 +     * @param val the value to be stored in all elements of the array
 52.1954 +     */
 52.1955 +    public static void fill(short[] a, short val) {
 52.1956 +        for (int i = 0, len = a.length; i < len; i++)
 52.1957 +            a[i] = val;
 52.1958 +    }
 52.1959 +
 52.1960 +    /**
 52.1961 +     * Assigns the specified short value to each element of the specified
 52.1962 +     * range of the specified array of shorts.  The range to be filled
 52.1963 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
 52.1964 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 52.1965 +     * range to be filled is empty.)
 52.1966 +     *
 52.1967 +     * @param a the array to be filled
 52.1968 +     * @param fromIndex the index of the first element (inclusive) to be
 52.1969 +     *        filled with the specified value
 52.1970 +     * @param toIndex the index of the last element (exclusive) to be
 52.1971 +     *        filled with the specified value
 52.1972 +     * @param val the value to be stored in all elements of the array
 52.1973 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 52.1974 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 52.1975 +     *         <tt>toIndex &gt; a.length</tt>
 52.1976 +     */
 52.1977 +    public static void fill(short[] a, int fromIndex, int toIndex, short val) {
 52.1978 +        rangeCheck(a.length, fromIndex, toIndex);
 52.1979 +        for (int i = fromIndex; i < toIndex; i++)
 52.1980 +            a[i] = val;
 52.1981 +    }
 52.1982 +
 52.1983 +    /**
 52.1984 +     * Assigns the specified char value to each element of the specified array
 52.1985 +     * of chars.
 52.1986 +     *
 52.1987 +     * @param a the array to be filled
 52.1988 +     * @param val the value to be stored in all elements of the array
 52.1989 +     */
 52.1990 +    public static void fill(char[] a, char val) {
 52.1991 +        for (int i = 0, len = a.length; i < len; i++)
 52.1992 +            a[i] = val;
 52.1993 +    }
 52.1994 +
 52.1995 +    /**
 52.1996 +     * Assigns the specified char value to each element of the specified
 52.1997 +     * range of the specified array of chars.  The range to be filled
 52.1998 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
 52.1999 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 52.2000 +     * range to be filled is empty.)
 52.2001 +     *
 52.2002 +     * @param a the array to be filled
 52.2003 +     * @param fromIndex the index of the first element (inclusive) to be
 52.2004 +     *        filled with the specified value
 52.2005 +     * @param toIndex the index of the last element (exclusive) to be
 52.2006 +     *        filled with the specified value
 52.2007 +     * @param val the value to be stored in all elements of the array
 52.2008 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 52.2009 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 52.2010 +     *         <tt>toIndex &gt; a.length</tt>
 52.2011 +     */
 52.2012 +    public static void fill(char[] a, int fromIndex, int toIndex, char val) {
 52.2013 +        rangeCheck(a.length, fromIndex, toIndex);
 52.2014 +        for (int i = fromIndex; i < toIndex; i++)
 52.2015 +            a[i] = val;
 52.2016 +    }
 52.2017 +
 52.2018 +    /**
 52.2019 +     * Assigns the specified byte value to each element of the specified array
 52.2020 +     * of bytes.
 52.2021 +     *
 52.2022 +     * @param a the array to be filled
 52.2023 +     * @param val the value to be stored in all elements of the array
 52.2024 +     */
 52.2025 +    public static void fill(byte[] a, byte val) {
 52.2026 +        for (int i = 0, len = a.length; i < len; i++)
 52.2027 +            a[i] = val;
 52.2028 +    }
 52.2029 +
 52.2030 +    /**
 52.2031 +     * Assigns the specified byte value to each element of the specified
 52.2032 +     * range of the specified array of bytes.  The range to be filled
 52.2033 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
 52.2034 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 52.2035 +     * range to be filled is empty.)
 52.2036 +     *
 52.2037 +     * @param a the array to be filled
 52.2038 +     * @param fromIndex the index of the first element (inclusive) to be
 52.2039 +     *        filled with the specified value
 52.2040 +     * @param toIndex the index of the last element (exclusive) to be
 52.2041 +     *        filled with the specified value
 52.2042 +     * @param val the value to be stored in all elements of the array
 52.2043 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 52.2044 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 52.2045 +     *         <tt>toIndex &gt; a.length</tt>
 52.2046 +     */
 52.2047 +    public static void fill(byte[] a, int fromIndex, int toIndex, byte val) {
 52.2048 +        rangeCheck(a.length, fromIndex, toIndex);
 52.2049 +        for (int i = fromIndex; i < toIndex; i++)
 52.2050 +            a[i] = val;
 52.2051 +    }
 52.2052 +
 52.2053 +    /**
 52.2054 +     * Assigns the specified boolean value to each element of the specified
 52.2055 +     * array of booleans.
 52.2056 +     *
 52.2057 +     * @param a the array to be filled
 52.2058 +     * @param val the value to be stored in all elements of the array
 52.2059 +     */
 52.2060 +    public static void fill(boolean[] a, boolean val) {
 52.2061 +        for (int i = 0, len = a.length; i < len; i++)
 52.2062 +            a[i] = val;
 52.2063 +    }
 52.2064 +
 52.2065 +    /**
 52.2066 +     * Assigns the specified boolean value to each element of the specified
 52.2067 +     * range of the specified array of booleans.  The range to be filled
 52.2068 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
 52.2069 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 52.2070 +     * range to be filled is empty.)
 52.2071 +     *
 52.2072 +     * @param a the array to be filled
 52.2073 +     * @param fromIndex the index of the first element (inclusive) to be
 52.2074 +     *        filled with the specified value
 52.2075 +     * @param toIndex the index of the last element (exclusive) to be
 52.2076 +     *        filled with the specified value
 52.2077 +     * @param val the value to be stored in all elements of the array
 52.2078 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 52.2079 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 52.2080 +     *         <tt>toIndex &gt; a.length</tt>
 52.2081 +     */
 52.2082 +    public static void fill(boolean[] a, int fromIndex, int toIndex,
 52.2083 +                            boolean val) {
 52.2084 +        rangeCheck(a.length, fromIndex, toIndex);
 52.2085 +        for (int i = fromIndex; i < toIndex; i++)
 52.2086 +            a[i] = val;
 52.2087 +    }
 52.2088 +
 52.2089 +    /**
 52.2090 +     * Assigns the specified double value to each element of the specified
 52.2091 +     * array of doubles.
 52.2092 +     *
 52.2093 +     * @param a the array to be filled
 52.2094 +     * @param val the value to be stored in all elements of the array
 52.2095 +     */
 52.2096 +    public static void fill(double[] a, double val) {
 52.2097 +        for (int i = 0, len = a.length; i < len; i++)
 52.2098 +            a[i] = val;
 52.2099 +    }
 52.2100 +
 52.2101 +    /**
 52.2102 +     * Assigns the specified double value to each element of the specified
 52.2103 +     * range of the specified array of doubles.  The range to be filled
 52.2104 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
 52.2105 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 52.2106 +     * range to be filled is empty.)
 52.2107 +     *
 52.2108 +     * @param a the array to be filled
 52.2109 +     * @param fromIndex the index of the first element (inclusive) to be
 52.2110 +     *        filled with the specified value
 52.2111 +     * @param toIndex the index of the last element (exclusive) to be
 52.2112 +     *        filled with the specified value
 52.2113 +     * @param val the value to be stored in all elements of the array
 52.2114 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 52.2115 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 52.2116 +     *         <tt>toIndex &gt; a.length</tt>
 52.2117 +     */
 52.2118 +    public static void fill(double[] a, int fromIndex, int toIndex,double val){
 52.2119 +        rangeCheck(a.length, fromIndex, toIndex);
 52.2120 +        for (int i = fromIndex; i < toIndex; i++)
 52.2121 +            a[i] = val;
 52.2122 +    }
 52.2123 +
 52.2124 +    /**
 52.2125 +     * Assigns the specified float value to each element of the specified array
 52.2126 +     * of floats.
 52.2127 +     *
 52.2128 +     * @param a the array to be filled
 52.2129 +     * @param val the value to be stored in all elements of the array
 52.2130 +     */
 52.2131 +    public static void fill(float[] a, float val) {
 52.2132 +        for (int i = 0, len = a.length; i < len; i++)
 52.2133 +            a[i] = val;
 52.2134 +    }
 52.2135 +
 52.2136 +    /**
 52.2137 +     * Assigns the specified float value to each element of the specified
 52.2138 +     * range of the specified array of floats.  The range to be filled
 52.2139 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
 52.2140 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 52.2141 +     * range to be filled is empty.)
 52.2142 +     *
 52.2143 +     * @param a the array to be filled
 52.2144 +     * @param fromIndex the index of the first element (inclusive) to be
 52.2145 +     *        filled with the specified value
 52.2146 +     * @param toIndex the index of the last element (exclusive) to be
 52.2147 +     *        filled with the specified value
 52.2148 +     * @param val the value to be stored in all elements of the array
 52.2149 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 52.2150 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 52.2151 +     *         <tt>toIndex &gt; a.length</tt>
 52.2152 +     */
 52.2153 +    public static void fill(float[] a, int fromIndex, int toIndex, float val) {
 52.2154 +        rangeCheck(a.length, fromIndex, toIndex);
 52.2155 +        for (int i = fromIndex; i < toIndex; i++)
 52.2156 +            a[i] = val;
 52.2157 +    }
 52.2158 +
 52.2159 +    /**
 52.2160 +     * Assigns the specified Object reference to each element of the specified
 52.2161 +     * array of Objects.
 52.2162 +     *
 52.2163 +     * @param a the array to be filled
 52.2164 +     * @param val the value to be stored in all elements of the array
 52.2165 +     * @throws ArrayStoreException if the specified value is not of a
 52.2166 +     *         runtime type that can be stored in the specified array
 52.2167 +     */
 52.2168 +    public static void fill(Object[] a, Object val) {
 52.2169 +        for (int i = 0, len = a.length; i < len; i++)
 52.2170 +            a[i] = val;
 52.2171 +    }
 52.2172 +
 52.2173 +    /**
 52.2174 +     * Assigns the specified Object reference to each element of the specified
 52.2175 +     * range of the specified array of Objects.  The range to be filled
 52.2176 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
 52.2177 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 52.2178 +     * range to be filled is empty.)
 52.2179 +     *
 52.2180 +     * @param a the array to be filled
 52.2181 +     * @param fromIndex the index of the first element (inclusive) to be
 52.2182 +     *        filled with the specified value
 52.2183 +     * @param toIndex the index of the last element (exclusive) to be
 52.2184 +     *        filled with the specified value
 52.2185 +     * @param val the value to be stored in all elements of the array
 52.2186 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 52.2187 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 52.2188 +     *         <tt>toIndex &gt; a.length</tt>
 52.2189 +     * @throws ArrayStoreException if the specified value is not of a
 52.2190 +     *         runtime type that can be stored in the specified array
 52.2191 +     */
 52.2192 +    public static void fill(Object[] a, int fromIndex, int toIndex, Object val) {
 52.2193 +        rangeCheck(a.length, fromIndex, toIndex);
 52.2194 +        for (int i = fromIndex; i < toIndex; i++)
 52.2195 +            a[i] = val;
 52.2196 +    }
 52.2197 +
 52.2198 +    // Cloning
 52.2199 +
 52.2200 +    /**
 52.2201 +     * Copies the specified array, truncating or padding with nulls (if necessary)
 52.2202 +     * so the copy has the specified length.  For all indices that are
 52.2203 +     * valid in both the original array and the copy, the two arrays will
 52.2204 +     * contain identical values.  For any indices that are valid in the
 52.2205 +     * copy but not the original, the copy will contain <tt>null</tt>.
 52.2206 +     * Such indices will exist if and only if the specified length
 52.2207 +     * is greater than that of the original array.
 52.2208 +     * The resulting array is of exactly the same class as the original array.
 52.2209 +     *
 52.2210 +     * @param original the array to be copied
 52.2211 +     * @param newLength the length of the copy to be returned
 52.2212 +     * @return a copy of the original array, truncated or padded with nulls
 52.2213 +     *     to obtain the specified length
 52.2214 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 52.2215 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2216 +     * @since 1.6
 52.2217 +     */
 52.2218 +    public static <T> T[] copyOf(T[] original, int newLength) {
 52.2219 +        return (T[]) copyOf(original, newLength, original.getClass());
 52.2220 +    }
 52.2221 +
 52.2222 +    /**
 52.2223 +     * Copies the specified array, truncating or padding with nulls (if necessary)
 52.2224 +     * so the copy has the specified length.  For all indices that are
 52.2225 +     * valid in both the original array and the copy, the two arrays will
 52.2226 +     * contain identical values.  For any indices that are valid in the
 52.2227 +     * copy but not the original, the copy will contain <tt>null</tt>.
 52.2228 +     * Such indices will exist if and only if the specified length
 52.2229 +     * is greater than that of the original array.
 52.2230 +     * The resulting array is of the class <tt>newType</tt>.
 52.2231 +     *
 52.2232 +     * @param original the array to be copied
 52.2233 +     * @param newLength the length of the copy to be returned
 52.2234 +     * @param newType the class of the copy to be returned
 52.2235 +     * @return a copy of the original array, truncated or padded with nulls
 52.2236 +     *     to obtain the specified length
 52.2237 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 52.2238 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2239 +     * @throws ArrayStoreException if an element copied from
 52.2240 +     *     <tt>original</tt> is not of a runtime type that can be stored in
 52.2241 +     *     an array of class <tt>newType</tt>
 52.2242 +     * @since 1.6
 52.2243 +     */
 52.2244 +    public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {
 52.2245 +        T[] copy = ((Object)newType == (Object)Object[].class)
 52.2246 +            ? (T[]) new Object[newLength]
 52.2247 +            : (T[]) Array.newInstance(newType.getComponentType(), newLength);
 52.2248 +        System.arraycopy(original, 0, copy, 0,
 52.2249 +                         Math.min(original.length, newLength));
 52.2250 +        return copy;
 52.2251 +    }
 52.2252 +
 52.2253 +    /**
 52.2254 +     * Copies the specified array, truncating or padding with zeros (if necessary)
 52.2255 +     * so the copy has the specified length.  For all indices that are
 52.2256 +     * valid in both the original array and the copy, the two arrays will
 52.2257 +     * contain identical values.  For any indices that are valid in the
 52.2258 +     * copy but not the original, the copy will contain <tt>(byte)0</tt>.
 52.2259 +     * Such indices will exist if and only if the specified length
 52.2260 +     * is greater than that of the original array.
 52.2261 +     *
 52.2262 +     * @param original the array to be copied
 52.2263 +     * @param newLength the length of the copy to be returned
 52.2264 +     * @return a copy of the original array, truncated or padded with zeros
 52.2265 +     *     to obtain the specified length
 52.2266 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 52.2267 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2268 +     * @since 1.6
 52.2269 +     */
 52.2270 +    public static byte[] copyOf(byte[] original, int newLength) {
 52.2271 +        byte[] copy = new byte[newLength];
 52.2272 +        System.arraycopy(original, 0, copy, 0,
 52.2273 +                         Math.min(original.length, newLength));
 52.2274 +        return copy;
 52.2275 +    }
 52.2276 +
 52.2277 +    /**
 52.2278 +     * Copies the specified array, truncating or padding with zeros (if necessary)
 52.2279 +     * so the copy has the specified length.  For all indices that are
 52.2280 +     * valid in both the original array and the copy, the two arrays will
 52.2281 +     * contain identical values.  For any indices that are valid in the
 52.2282 +     * copy but not the original, the copy will contain <tt>(short)0</tt>.
 52.2283 +     * Such indices will exist if and only if the specified length
 52.2284 +     * is greater than that of the original array.
 52.2285 +     *
 52.2286 +     * @param original the array to be copied
 52.2287 +     * @param newLength the length of the copy to be returned
 52.2288 +     * @return a copy of the original array, truncated or padded with zeros
 52.2289 +     *     to obtain the specified length
 52.2290 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 52.2291 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2292 +     * @since 1.6
 52.2293 +     */
 52.2294 +    public static short[] copyOf(short[] original, int newLength) {
 52.2295 +        short[] copy = new short[newLength];
 52.2296 +        System.arraycopy(original, 0, copy, 0,
 52.2297 +                         Math.min(original.length, newLength));
 52.2298 +        return copy;
 52.2299 +    }
 52.2300 +
 52.2301 +    /**
 52.2302 +     * Copies the specified array, truncating or padding with zeros (if necessary)
 52.2303 +     * so the copy has the specified length.  For all indices that are
 52.2304 +     * valid in both the original array and the copy, the two arrays will
 52.2305 +     * contain identical values.  For any indices that are valid in the
 52.2306 +     * copy but not the original, the copy will contain <tt>0</tt>.
 52.2307 +     * Such indices will exist if and only if the specified length
 52.2308 +     * is greater than that of the original array.
 52.2309 +     *
 52.2310 +     * @param original the array to be copied
 52.2311 +     * @param newLength the length of the copy to be returned
 52.2312 +     * @return a copy of the original array, truncated or padded with zeros
 52.2313 +     *     to obtain the specified length
 52.2314 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 52.2315 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2316 +     * @since 1.6
 52.2317 +     */
 52.2318 +    public static int[] copyOf(int[] original, int newLength) {
 52.2319 +        int[] copy = new int[newLength];
 52.2320 +        System.arraycopy(original, 0, copy, 0,
 52.2321 +                         Math.min(original.length, newLength));
 52.2322 +        return copy;
 52.2323 +    }
 52.2324 +
 52.2325 +    /**
 52.2326 +     * Copies the specified array, truncating or padding with zeros (if necessary)
 52.2327 +     * so the copy has the specified length.  For all indices that are
 52.2328 +     * valid in both the original array and the copy, the two arrays will
 52.2329 +     * contain identical values.  For any indices that are valid in the
 52.2330 +     * copy but not the original, the copy will contain <tt>0L</tt>.
 52.2331 +     * Such indices will exist if and only if the specified length
 52.2332 +     * is greater than that of the original array.
 52.2333 +     *
 52.2334 +     * @param original the array to be copied
 52.2335 +     * @param newLength the length of the copy to be returned
 52.2336 +     * @return a copy of the original array, truncated or padded with zeros
 52.2337 +     *     to obtain the specified length
 52.2338 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 52.2339 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2340 +     * @since 1.6
 52.2341 +     */
 52.2342 +    public static long[] copyOf(long[] original, int newLength) {
 52.2343 +        long[] copy = new long[newLength];
 52.2344 +        System.arraycopy(original, 0, copy, 0,
 52.2345 +                         Math.min(original.length, newLength));
 52.2346 +        return copy;
 52.2347 +    }
 52.2348 +
 52.2349 +    /**
 52.2350 +     * Copies the specified array, truncating or padding with null characters (if necessary)
 52.2351 +     * so the copy has the specified length.  For all indices that are valid
 52.2352 +     * in both the original array and the copy, the two arrays will contain
 52.2353 +     * identical values.  For any indices that are valid in the copy but not
 52.2354 +     * the original, the copy will contain <tt>'\\u000'</tt>.  Such indices
 52.2355 +     * will exist if and only if the specified length is greater than that of
 52.2356 +     * the original array.
 52.2357 +     *
 52.2358 +     * @param original the array to be copied
 52.2359 +     * @param newLength the length of the copy to be returned
 52.2360 +     * @return a copy of the original array, truncated or padded with null characters
 52.2361 +     *     to obtain the specified length
 52.2362 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 52.2363 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2364 +     * @since 1.6
 52.2365 +     */
 52.2366 +    public static char[] copyOf(char[] original, int newLength) {
 52.2367 +        char[] copy = new char[newLength];
 52.2368 +        System.arraycopy(original, 0, copy, 0,
 52.2369 +                         Math.min(original.length, newLength));
 52.2370 +        return copy;
 52.2371 +    }
 52.2372 +
 52.2373 +    /**
 52.2374 +     * Copies the specified array, truncating or padding with zeros (if necessary)
 52.2375 +     * so the copy has the specified length.  For all indices that are
 52.2376 +     * valid in both the original array and the copy, the two arrays will
 52.2377 +     * contain identical values.  For any indices that are valid in the
 52.2378 +     * copy but not the original, the copy will contain <tt>0f</tt>.
 52.2379 +     * Such indices will exist if and only if the specified length
 52.2380 +     * is greater than that of the original array.
 52.2381 +     *
 52.2382 +     * @param original the array to be copied
 52.2383 +     * @param newLength the length of the copy to be returned
 52.2384 +     * @return a copy of the original array, truncated or padded with zeros
 52.2385 +     *     to obtain the specified length
 52.2386 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 52.2387 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2388 +     * @since 1.6
 52.2389 +     */
 52.2390 +    public static float[] copyOf(float[] original, int newLength) {
 52.2391 +        float[] copy = new float[newLength];
 52.2392 +        System.arraycopy(original, 0, copy, 0,
 52.2393 +                         Math.min(original.length, newLength));
 52.2394 +        return copy;
 52.2395 +    }
 52.2396 +
 52.2397 +    /**
 52.2398 +     * Copies the specified array, truncating or padding with zeros (if necessary)
 52.2399 +     * so the copy has the specified length.  For all indices that are
 52.2400 +     * valid in both the original array and the copy, the two arrays will
 52.2401 +     * contain identical values.  For any indices that are valid in the
 52.2402 +     * copy but not the original, the copy will contain <tt>0d</tt>.
 52.2403 +     * Such indices will exist if and only if the specified length
 52.2404 +     * is greater than that of the original array.
 52.2405 +     *
 52.2406 +     * @param original the array to be copied
 52.2407 +     * @param newLength the length of the copy to be returned
 52.2408 +     * @return a copy of the original array, truncated or padded with zeros
 52.2409 +     *     to obtain the specified length
 52.2410 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 52.2411 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2412 +     * @since 1.6
 52.2413 +     */
 52.2414 +    public static double[] copyOf(double[] original, int newLength) {
 52.2415 +        double[] copy = new double[newLength];
 52.2416 +        System.arraycopy(original, 0, copy, 0,
 52.2417 +                         Math.min(original.length, newLength));
 52.2418 +        return copy;
 52.2419 +    }
 52.2420 +
 52.2421 +    /**
 52.2422 +     * Copies the specified array, truncating or padding with <tt>false</tt> (if necessary)
 52.2423 +     * so the copy has the specified length.  For all indices that are
 52.2424 +     * valid in both the original array and the copy, the two arrays will
 52.2425 +     * contain identical values.  For any indices that are valid in the
 52.2426 +     * copy but not the original, the copy will contain <tt>false</tt>.
 52.2427 +     * Such indices will exist if and only if the specified length
 52.2428 +     * is greater than that of the original array.
 52.2429 +     *
 52.2430 +     * @param original the array to be copied
 52.2431 +     * @param newLength the length of the copy to be returned
 52.2432 +     * @return a copy of the original array, truncated or padded with false elements
 52.2433 +     *     to obtain the specified length
 52.2434 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 52.2435 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2436 +     * @since 1.6
 52.2437 +     */
 52.2438 +    public static boolean[] copyOf(boolean[] original, int newLength) {
 52.2439 +        boolean[] copy = new boolean[newLength];
 52.2440 +        System.arraycopy(original, 0, copy, 0,
 52.2441 +                         Math.min(original.length, newLength));
 52.2442 +        return copy;
 52.2443 +    }
 52.2444 +
 52.2445 +    /**
 52.2446 +     * Copies the specified range of the specified array into a new array.
 52.2447 +     * The initial index of the range (<tt>from</tt>) must lie between zero
 52.2448 +     * and <tt>original.length</tt>, inclusive.  The value at
 52.2449 +     * <tt>original[from]</tt> is placed into the initial element of the copy
 52.2450 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 52.2451 +     * Values from subsequent elements in the original array are placed into
 52.2452 +     * subsequent elements in the copy.  The final index of the range
 52.2453 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 52.2454 +     * may be greater than <tt>original.length</tt>, in which case
 52.2455 +     * <tt>null</tt> is placed in all elements of the copy whose index is
 52.2456 +     * greater than or equal to <tt>original.length - from</tt>.  The length
 52.2457 +     * of the returned array will be <tt>to - from</tt>.
 52.2458 +     * <p>
 52.2459 +     * The resulting array is of exactly the same class as the original array.
 52.2460 +     *
 52.2461 +     * @param original the array from which a range is to be copied
 52.2462 +     * @param from the initial index of the range to be copied, inclusive
 52.2463 +     * @param to the final index of the range to be copied, exclusive.
 52.2464 +     *     (This index may lie outside the array.)
 52.2465 +     * @return a new array containing the specified range from the original array,
 52.2466 +     *     truncated or padded with nulls to obtain the required length
 52.2467 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 52.2468 +     *     or {@code from > original.length}
 52.2469 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 52.2470 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2471 +     * @since 1.6
 52.2472 +     */
 52.2473 +    public static <T> T[] copyOfRange(T[] original, int from, int to) {
 52.2474 +        return copyOfRange(original, from, to, (Class<T[]>) original.getClass());
 52.2475 +    }
 52.2476 +
 52.2477 +    /**
 52.2478 +     * Copies the specified range of the specified array into a new array.
 52.2479 +     * The initial index of the range (<tt>from</tt>) must lie between zero
 52.2480 +     * and <tt>original.length</tt>, inclusive.  The value at
 52.2481 +     * <tt>original[from]</tt> is placed into the initial element of the copy
 52.2482 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 52.2483 +     * Values from subsequent elements in the original array are placed into
 52.2484 +     * subsequent elements in the copy.  The final index of the range
 52.2485 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 52.2486 +     * may be greater than <tt>original.length</tt>, in which case
 52.2487 +     * <tt>null</tt> is placed in all elements of the copy whose index is
 52.2488 +     * greater than or equal to <tt>original.length - from</tt>.  The length
 52.2489 +     * of the returned array will be <tt>to - from</tt>.
 52.2490 +     * The resulting array is of the class <tt>newType</tt>.
 52.2491 +     *
 52.2492 +     * @param original the array from which a range is to be copied
 52.2493 +     * @param from the initial index of the range to be copied, inclusive
 52.2494 +     * @param to the final index of the range to be copied, exclusive.
 52.2495 +     *     (This index may lie outside the array.)
 52.2496 +     * @param newType the class of the copy to be returned
 52.2497 +     * @return a new array containing the specified range from the original array,
 52.2498 +     *     truncated or padded with nulls to obtain the required length
 52.2499 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 52.2500 +     *     or {@code from > original.length}
 52.2501 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 52.2502 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2503 +     * @throws ArrayStoreException if an element copied from
 52.2504 +     *     <tt>original</tt> is not of a runtime type that can be stored in
 52.2505 +     *     an array of class <tt>newType</tt>.
 52.2506 +     * @since 1.6
 52.2507 +     */
 52.2508 +    public static <T,U> T[] copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType) {
 52.2509 +        int newLength = to - from;
 52.2510 +        if (newLength < 0)
 52.2511 +            throw new IllegalArgumentException(from + " > " + to);
 52.2512 +        T[] copy = ((Object)newType == (Object)Object[].class)
 52.2513 +            ? (T[]) new Object[newLength]
 52.2514 +            : (T[]) Array.newInstance(newType.getComponentType(), newLength);
 52.2515 +        System.arraycopy(original, from, copy, 0,
 52.2516 +                         Math.min(original.length - from, newLength));
 52.2517 +        return copy;
 52.2518 +    }
 52.2519 +
 52.2520 +    /**
 52.2521 +     * Copies the specified range of the specified array into a new array.
 52.2522 +     * The initial index of the range (<tt>from</tt>) must lie between zero
 52.2523 +     * and <tt>original.length</tt>, inclusive.  The value at
 52.2524 +     * <tt>original[from]</tt> is placed into the initial element of the copy
 52.2525 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 52.2526 +     * Values from subsequent elements in the original array are placed into
 52.2527 +     * subsequent elements in the copy.  The final index of the range
 52.2528 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 52.2529 +     * may be greater than <tt>original.length</tt>, in which case
 52.2530 +     * <tt>(byte)0</tt> is placed in all elements of the copy whose index is
 52.2531 +     * greater than or equal to <tt>original.length - from</tt>.  The length
 52.2532 +     * of the returned array will be <tt>to - from</tt>.
 52.2533 +     *
 52.2534 +     * @param original the array from which a range is to be copied
 52.2535 +     * @param from the initial index of the range to be copied, inclusive
 52.2536 +     * @param to the final index of the range to be copied, exclusive.
 52.2537 +     *     (This index may lie outside the array.)
 52.2538 +     * @return a new array containing the specified range from the original array,
 52.2539 +     *     truncated or padded with zeros to obtain the required length
 52.2540 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 52.2541 +     *     or {@code from > original.length}
 52.2542 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 52.2543 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2544 +     * @since 1.6
 52.2545 +     */
 52.2546 +    public static byte[] copyOfRange(byte[] original, int from, int to) {
 52.2547 +        int newLength = to - from;
 52.2548 +        if (newLength < 0)
 52.2549 +            throw new IllegalArgumentException(from + " > " + to);
 52.2550 +        byte[] copy = new byte[newLength];
 52.2551 +        System.arraycopy(original, from, copy, 0,
 52.2552 +                         Math.min(original.length - from, newLength));
 52.2553 +        return copy;
 52.2554 +    }
 52.2555 +
 52.2556 +    /**
 52.2557 +     * Copies the specified range of the specified array into a new array.
 52.2558 +     * The initial index of the range (<tt>from</tt>) must lie between zero
 52.2559 +     * and <tt>original.length</tt>, inclusive.  The value at
 52.2560 +     * <tt>original[from]</tt> is placed into the initial element of the copy
 52.2561 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 52.2562 +     * Values from subsequent elements in the original array are placed into
 52.2563 +     * subsequent elements in the copy.  The final index of the range
 52.2564 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 52.2565 +     * may be greater than <tt>original.length</tt>, in which case
 52.2566 +     * <tt>(short)0</tt> is placed in all elements of the copy whose index is
 52.2567 +     * greater than or equal to <tt>original.length - from</tt>.  The length
 52.2568 +     * of the returned array will be <tt>to - from</tt>.
 52.2569 +     *
 52.2570 +     * @param original the array from which a range is to be copied
 52.2571 +     * @param from the initial index of the range to be copied, inclusive
 52.2572 +     * @param to the final index of the range to be copied, exclusive.
 52.2573 +     *     (This index may lie outside the array.)
 52.2574 +     * @return a new array containing the specified range from the original array,
 52.2575 +     *     truncated or padded with zeros to obtain the required length
 52.2576 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 52.2577 +     *     or {@code from > original.length}
 52.2578 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 52.2579 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2580 +     * @since 1.6
 52.2581 +     */
 52.2582 +    public static short[] copyOfRange(short[] original, int from, int to) {
 52.2583 +        int newLength = to - from;
 52.2584 +        if (newLength < 0)
 52.2585 +            throw new IllegalArgumentException(from + " > " + to);
 52.2586 +        short[] copy = new short[newLength];
 52.2587 +        System.arraycopy(original, from, copy, 0,
 52.2588 +                         Math.min(original.length - from, newLength));
 52.2589 +        return copy;
 52.2590 +    }
 52.2591 +
 52.2592 +    /**
 52.2593 +     * Copies the specified range of the specified array into a new array.
 52.2594 +     * The initial index of the range (<tt>from</tt>) must lie between zero
 52.2595 +     * and <tt>original.length</tt>, inclusive.  The value at
 52.2596 +     * <tt>original[from]</tt> is placed into the initial element of the copy
 52.2597 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 52.2598 +     * Values from subsequent elements in the original array are placed into
 52.2599 +     * subsequent elements in the copy.  The final index of the range
 52.2600 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 52.2601 +     * may be greater than <tt>original.length</tt>, in which case
 52.2602 +     * <tt>0</tt> is placed in all elements of the copy whose index is
 52.2603 +     * greater than or equal to <tt>original.length - from</tt>.  The length
 52.2604 +     * of the returned array will be <tt>to - from</tt>.
 52.2605 +     *
 52.2606 +     * @param original the array from which a range is to be copied
 52.2607 +     * @param from the initial index of the range to be copied, inclusive
 52.2608 +     * @param to the final index of the range to be copied, exclusive.
 52.2609 +     *     (This index may lie outside the array.)
 52.2610 +     * @return a new array containing the specified range from the original array,
 52.2611 +     *     truncated or padded with zeros to obtain the required length
 52.2612 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 52.2613 +     *     or {@code from > original.length}
 52.2614 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 52.2615 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2616 +     * @since 1.6
 52.2617 +     */
 52.2618 +    public static int[] copyOfRange(int[] original, int from, int to) {
 52.2619 +        int newLength = to - from;
 52.2620 +        if (newLength < 0)
 52.2621 +            throw new IllegalArgumentException(from + " > " + to);
 52.2622 +        int[] copy = new int[newLength];
 52.2623 +        System.arraycopy(original, from, copy, 0,
 52.2624 +                         Math.min(original.length - from, newLength));
 52.2625 +        return copy;
 52.2626 +    }
 52.2627 +
 52.2628 +    /**
 52.2629 +     * Copies the specified range of the specified array into a new array.
 52.2630 +     * The initial index of the range (<tt>from</tt>) must lie between zero
 52.2631 +     * and <tt>original.length</tt>, inclusive.  The value at
 52.2632 +     * <tt>original[from]</tt> is placed into the initial element of the copy
 52.2633 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 52.2634 +     * Values from subsequent elements in the original array are placed into
 52.2635 +     * subsequent elements in the copy.  The final index of the range
 52.2636 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 52.2637 +     * may be greater than <tt>original.length</tt>, in which case
 52.2638 +     * <tt>0L</tt> is placed in all elements of the copy whose index is
 52.2639 +     * greater than or equal to <tt>original.length - from</tt>.  The length
 52.2640 +     * of the returned array will be <tt>to - from</tt>.
 52.2641 +     *
 52.2642 +     * @param original the array from which a range is to be copied
 52.2643 +     * @param from the initial index of the range to be copied, inclusive
 52.2644 +     * @param to the final index of the range to be copied, exclusive.
 52.2645 +     *     (This index may lie outside the array.)
 52.2646 +     * @return a new array containing the specified range from the original array,
 52.2647 +     *     truncated or padded with zeros to obtain the required length
 52.2648 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 52.2649 +     *     or {@code from > original.length}
 52.2650 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 52.2651 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2652 +     * @since 1.6
 52.2653 +     */
 52.2654 +    public static long[] copyOfRange(long[] original, int from, int to) {
 52.2655 +        int newLength = to - from;
 52.2656 +        if (newLength < 0)
 52.2657 +            throw new IllegalArgumentException(from + " > " + to);
 52.2658 +        long[] copy = new long[newLength];
 52.2659 +        System.arraycopy(original, from, copy, 0,
 52.2660 +                         Math.min(original.length - from, newLength));
 52.2661 +        return copy;
 52.2662 +    }
 52.2663 +
 52.2664 +    /**
 52.2665 +     * Copies the specified range of the specified array into a new array.
 52.2666 +     * The initial index of the range (<tt>from</tt>) must lie between zero
 52.2667 +     * and <tt>original.length</tt>, inclusive.  The value at
 52.2668 +     * <tt>original[from]</tt> is placed into the initial element of the copy
 52.2669 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 52.2670 +     * Values from subsequent elements in the original array are placed into
 52.2671 +     * subsequent elements in the copy.  The final index of the range
 52.2672 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 52.2673 +     * may be greater than <tt>original.length</tt>, in which case
 52.2674 +     * <tt>'\\u000'</tt> is placed in all elements of the copy whose index is
 52.2675 +     * greater than or equal to <tt>original.length - from</tt>.  The length
 52.2676 +     * of the returned array will be <tt>to - from</tt>.
 52.2677 +     *
 52.2678 +     * @param original the array from which a range is to be copied
 52.2679 +     * @param from the initial index of the range to be copied, inclusive
 52.2680 +     * @param to the final index of the range to be copied, exclusive.
 52.2681 +     *     (This index may lie outside the array.)
 52.2682 +     * @return a new array containing the specified range from the original array,
 52.2683 +     *     truncated or padded with null characters to obtain the required length
 52.2684 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 52.2685 +     *     or {@code from > original.length}
 52.2686 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 52.2687 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2688 +     * @since 1.6
 52.2689 +     */
 52.2690 +    public static char[] copyOfRange(char[] original, int from, int to) {
 52.2691 +        int newLength = to - from;
 52.2692 +        if (newLength < 0)
 52.2693 +            throw new IllegalArgumentException(from + " > " + to);
 52.2694 +        char[] copy = new char[newLength];
 52.2695 +        System.arraycopy(original, from, copy, 0,
 52.2696 +                         Math.min(original.length - from, newLength));
 52.2697 +        return copy;
 52.2698 +    }
 52.2699 +
 52.2700 +    /**
 52.2701 +     * Copies the specified range of the specified array into a new array.
 52.2702 +     * The initial index of the range (<tt>from</tt>) must lie between zero
 52.2703 +     * and <tt>original.length</tt>, inclusive.  The value at
 52.2704 +     * <tt>original[from]</tt> is placed into the initial element of the copy
 52.2705 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 52.2706 +     * Values from subsequent elements in the original array are placed into
 52.2707 +     * subsequent elements in the copy.  The final index of the range
 52.2708 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 52.2709 +     * may be greater than <tt>original.length</tt>, in which case
 52.2710 +     * <tt>0f</tt> is placed in all elements of the copy whose index is
 52.2711 +     * greater than or equal to <tt>original.length - from</tt>.  The length
 52.2712 +     * of the returned array will be <tt>to - from</tt>.
 52.2713 +     *
 52.2714 +     * @param original the array from which a range is to be copied
 52.2715 +     * @param from the initial index of the range to be copied, inclusive
 52.2716 +     * @param to the final index of the range to be copied, exclusive.
 52.2717 +     *     (This index may lie outside the array.)
 52.2718 +     * @return a new array containing the specified range from the original array,
 52.2719 +     *     truncated or padded with zeros to obtain the required length
 52.2720 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 52.2721 +     *     or {@code from > original.length}
 52.2722 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 52.2723 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2724 +     * @since 1.6
 52.2725 +     */
 52.2726 +    public static float[] copyOfRange(float[] original, int from, int to) {
 52.2727 +        int newLength = to - from;
 52.2728 +        if (newLength < 0)
 52.2729 +            throw new IllegalArgumentException(from + " > " + to);
 52.2730 +        float[] copy = new float[newLength];
 52.2731 +        System.arraycopy(original, from, copy, 0,
 52.2732 +                         Math.min(original.length - from, newLength));
 52.2733 +        return copy;
 52.2734 +    }
 52.2735 +
 52.2736 +    /**
 52.2737 +     * Copies the specified range of the specified array into a new array.
 52.2738 +     * The initial index of the range (<tt>from</tt>) must lie between zero
 52.2739 +     * and <tt>original.length</tt>, inclusive.  The value at
 52.2740 +     * <tt>original[from]</tt> is placed into the initial element of the copy
 52.2741 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 52.2742 +     * Values from subsequent elements in the original array are placed into
 52.2743 +     * subsequent elements in the copy.  The final index of the range
 52.2744 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 52.2745 +     * may be greater than <tt>original.length</tt>, in which case
 52.2746 +     * <tt>0d</tt> is placed in all elements of the copy whose index is
 52.2747 +     * greater than or equal to <tt>original.length - from</tt>.  The length
 52.2748 +     * of the returned array will be <tt>to - from</tt>.
 52.2749 +     *
 52.2750 +     * @param original the array from which a range is to be copied
 52.2751 +     * @param from the initial index of the range to be copied, inclusive
 52.2752 +     * @param to the final index of the range to be copied, exclusive.
 52.2753 +     *     (This index may lie outside the array.)
 52.2754 +     * @return a new array containing the specified range from the original array,
 52.2755 +     *     truncated or padded with zeros to obtain the required length
 52.2756 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 52.2757 +     *     or {@code from > original.length}
 52.2758 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 52.2759 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2760 +     * @since 1.6
 52.2761 +     */
 52.2762 +    public static double[] copyOfRange(double[] original, int from, int to) {
 52.2763 +        int newLength = to - from;
 52.2764 +        if (newLength < 0)
 52.2765 +            throw new IllegalArgumentException(from + " > " + to);
 52.2766 +        double[] copy = new double[newLength];
 52.2767 +        System.arraycopy(original, from, copy, 0,
 52.2768 +                         Math.min(original.length - from, newLength));
 52.2769 +        return copy;
 52.2770 +    }
 52.2771 +
 52.2772 +    /**
 52.2773 +     * Copies the specified range of the specified array into a new array.
 52.2774 +     * The initial index of the range (<tt>from</tt>) must lie between zero
 52.2775 +     * and <tt>original.length</tt>, inclusive.  The value at
 52.2776 +     * <tt>original[from]</tt> is placed into the initial element of the copy
 52.2777 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 52.2778 +     * Values from subsequent elements in the original array are placed into
 52.2779 +     * subsequent elements in the copy.  The final index of the range
 52.2780 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 52.2781 +     * may be greater than <tt>original.length</tt>, in which case
 52.2782 +     * <tt>false</tt> is placed in all elements of the copy whose index is
 52.2783 +     * greater than or equal to <tt>original.length - from</tt>.  The length
 52.2784 +     * of the returned array will be <tt>to - from</tt>.
 52.2785 +     *
 52.2786 +     * @param original the array from which a range is to be copied
 52.2787 +     * @param from the initial index of the range to be copied, inclusive
 52.2788 +     * @param to the final index of the range to be copied, exclusive.
 52.2789 +     *     (This index may lie outside the array.)
 52.2790 +     * @return a new array containing the specified range from the original array,
 52.2791 +     *     truncated or padded with false elements to obtain the required length
 52.2792 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 52.2793 +     *     or {@code from > original.length}
 52.2794 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 52.2795 +     * @throws NullPointerException if <tt>original</tt> is null
 52.2796 +     * @since 1.6
 52.2797 +     */
 52.2798 +    public static boolean[] copyOfRange(boolean[] original, int from, int to) {
 52.2799 +        int newLength = to - from;
 52.2800 +        if (newLength < 0)
 52.2801 +            throw new IllegalArgumentException(from + " > " + to);
 52.2802 +        boolean[] copy = new boolean[newLength];
 52.2803 +        System.arraycopy(original, from, copy, 0,
 52.2804 +                         Math.min(original.length - from, newLength));
 52.2805 +        return copy;
 52.2806 +    }
 52.2807 +
 52.2808 +    // Misc
 52.2809 +
 52.2810 +    /**
 52.2811 +     * Returns a fixed-size list backed by the specified array.  (Changes to
 52.2812 +     * the returned list "write through" to the array.)  This method acts
 52.2813 +     * as bridge between array-based and collection-based APIs, in
 52.2814 +     * combination with {@link Collection#toArray}.  The returned list is
 52.2815 +     * serializable and implements {@link RandomAccess}.
 52.2816 +     *
 52.2817 +     * <p>This method also provides a convenient way to create a fixed-size
 52.2818 +     * list initialized to contain several elements:
 52.2819 +     * <pre>
 52.2820 +     *     List&lt;String&gt; stooges = Arrays.asList("Larry", "Moe", "Curly");
 52.2821 +     * </pre>
 52.2822 +     *
 52.2823 +     * @param a the array by which the list will be backed
 52.2824 +     * @return a list view of the specified array
 52.2825 +     */
 52.2826 +    @SafeVarargs
 52.2827 +    public static <T> List<T> asList(T... a) {
 52.2828 +        return new ArrayList<>(a);
 52.2829 +    }
 52.2830 +
 52.2831 +    /**
 52.2832 +     * @serial include
 52.2833 +     */
 52.2834 +    private static class ArrayList<E> extends AbstractList<E>
 52.2835 +        implements RandomAccess, java.io.Serializable
 52.2836 +    {
 52.2837 +        private static final long serialVersionUID = -2764017481108945198L;
 52.2838 +        private final E[] a;
 52.2839 +
 52.2840 +        ArrayList(E[] array) {
 52.2841 +            if (array==null)
 52.2842 +                throw new NullPointerException();
 52.2843 +            a = array;
 52.2844 +        }
 52.2845 +
 52.2846 +        public int size() {
 52.2847 +            return a.length;
 52.2848 +        }
 52.2849 +
 52.2850 +        public Object[] toArray() {
 52.2851 +            return a.clone();
 52.2852 +        }
 52.2853 +
 52.2854 +        public <T> T[] toArray(T[] a) {
 52.2855 +            int size = size();
 52.2856 +            if (a.length < size)
 52.2857 +                return Arrays.copyOf(this.a, size,
 52.2858 +                                     (Class<? extends T[]>) a.getClass());
 52.2859 +            System.arraycopy(this.a, 0, a, 0, size);
 52.2860 +            if (a.length > size)
 52.2861 +                a[size] = null;
 52.2862 +            return a;
 52.2863 +        }
 52.2864 +
 52.2865 +        public E get(int index) {
 52.2866 +            return a[index];
 52.2867 +        }
 52.2868 +
 52.2869 +        public E set(int index, E element) {
 52.2870 +            E oldValue = a[index];
 52.2871 +            a[index] = element;
 52.2872 +            return oldValue;
 52.2873 +        }
 52.2874 +
 52.2875 +        public int indexOf(Object o) {
 52.2876 +            if (o==null) {
 52.2877 +                for (int i=0; i<a.length; i++)
 52.2878 +                    if (a[i]==null)
 52.2879 +                        return i;
 52.2880 +            } else {
 52.2881 +                for (int i=0; i<a.length; i++)
 52.2882 +                    if (o.equals(a[i]))
 52.2883 +                        return i;
 52.2884 +            }
 52.2885 +            return -1;
 52.2886 +        }
 52.2887 +
 52.2888 +        public boolean contains(Object o) {
 52.2889 +            return indexOf(o) != -1;
 52.2890 +        }
 52.2891 +    }
 52.2892 +
 52.2893 +    /**
 52.2894 +     * Returns a hash code based on the contents of the specified array.
 52.2895 +     * For any two <tt>long</tt> arrays <tt>a</tt> and <tt>b</tt>
 52.2896 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 52.2897 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 52.2898 +     *
 52.2899 +     * <p>The value returned by this method is the same value that would be
 52.2900 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 52.2901 +     * method on a {@link List} containing a sequence of {@link Long}
 52.2902 +     * instances representing the elements of <tt>a</tt> in the same order.
 52.2903 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 52.2904 +     *
 52.2905 +     * @param a the array whose hash value to compute
 52.2906 +     * @return a content-based hash code for <tt>a</tt>
 52.2907 +     * @since 1.5
 52.2908 +     */
 52.2909 +    public static int hashCode(long a[]) {
 52.2910 +        if (a == null)
 52.2911 +            return 0;
 52.2912 +
 52.2913 +        int result = 1;
 52.2914 +        for (long element : a) {
 52.2915 +            int elementHash = (int)(element ^ (element >>> 32));
 52.2916 +            result = 31 * result + elementHash;
 52.2917 +        }
 52.2918 +
 52.2919 +        return result;
 52.2920 +    }
 52.2921 +
 52.2922 +    /**
 52.2923 +     * Returns a hash code based on the contents of the specified array.
 52.2924 +     * For any two non-null <tt>int</tt> arrays <tt>a</tt> and <tt>b</tt>
 52.2925 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 52.2926 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 52.2927 +     *
 52.2928 +     * <p>The value returned by this method is the same value that would be
 52.2929 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 52.2930 +     * method on a {@link List} containing a sequence of {@link Integer}
 52.2931 +     * instances representing the elements of <tt>a</tt> in the same order.
 52.2932 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 52.2933 +     *
 52.2934 +     * @param a the array whose hash value to compute
 52.2935 +     * @return a content-based hash code for <tt>a</tt>
 52.2936 +     * @since 1.5
 52.2937 +     */
 52.2938 +    public static int hashCode(int a[]) {
 52.2939 +        if (a == null)
 52.2940 +            return 0;
 52.2941 +
 52.2942 +        int result = 1;
 52.2943 +        for (int element : a)
 52.2944 +            result = 31 * result + element;
 52.2945 +
 52.2946 +        return result;
 52.2947 +    }
 52.2948 +
 52.2949 +    /**
 52.2950 +     * Returns a hash code based on the contents of the specified array.
 52.2951 +     * For any two <tt>short</tt> arrays <tt>a</tt> and <tt>b</tt>
 52.2952 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 52.2953 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 52.2954 +     *
 52.2955 +     * <p>The value returned by this method is the same value that would be
 52.2956 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 52.2957 +     * method on a {@link List} containing a sequence of {@link Short}
 52.2958 +     * instances representing the elements of <tt>a</tt> in the same order.
 52.2959 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 52.2960 +     *
 52.2961 +     * @param a the array whose hash value to compute
 52.2962 +     * @return a content-based hash code for <tt>a</tt>
 52.2963 +     * @since 1.5
 52.2964 +     */
 52.2965 +    public static int hashCode(short a[]) {
 52.2966 +        if (a == null)
 52.2967 +            return 0;
 52.2968 +
 52.2969 +        int result = 1;
 52.2970 +        for (short element : a)
 52.2971 +            result = 31 * result + element;
 52.2972 +
 52.2973 +        return result;
 52.2974 +    }
 52.2975 +
 52.2976 +    /**
 52.2977 +     * Returns a hash code based on the contents of the specified array.
 52.2978 +     * For any two <tt>char</tt> arrays <tt>a</tt> and <tt>b</tt>
 52.2979 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 52.2980 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 52.2981 +     *
 52.2982 +     * <p>The value returned by this method is the same value that would be
 52.2983 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 52.2984 +     * method on a {@link List} containing a sequence of {@link Character}
 52.2985 +     * instances representing the elements of <tt>a</tt> in the same order.
 52.2986 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 52.2987 +     *
 52.2988 +     * @param a the array whose hash value to compute
 52.2989 +     * @return a content-based hash code for <tt>a</tt>
 52.2990 +     * @since 1.5
 52.2991 +     */
 52.2992 +    public static int hashCode(char a[]) {
 52.2993 +        if (a == null)
 52.2994 +            return 0;
 52.2995 +
 52.2996 +        int result = 1;
 52.2997 +        for (char element : a)
 52.2998 +            result = 31 * result + element;
 52.2999 +
 52.3000 +        return result;
 52.3001 +    }
 52.3002 +
 52.3003 +    /**
 52.3004 +     * Returns a hash code based on the contents of the specified array.
 52.3005 +     * For any two <tt>byte</tt> arrays <tt>a</tt> and <tt>b</tt>
 52.3006 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 52.3007 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 52.3008 +     *
 52.3009 +     * <p>The value returned by this method is the same value that would be
 52.3010 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 52.3011 +     * method on a {@link List} containing a sequence of {@link Byte}
 52.3012 +     * instances representing the elements of <tt>a</tt> in the same order.
 52.3013 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 52.3014 +     *
 52.3015 +     * @param a the array whose hash value to compute
 52.3016 +     * @return a content-based hash code for <tt>a</tt>
 52.3017 +     * @since 1.5
 52.3018 +     */
 52.3019 +    public static int hashCode(byte a[]) {
 52.3020 +        if (a == null)
 52.3021 +            return 0;
 52.3022 +
 52.3023 +        int result = 1;
 52.3024 +        for (byte element : a)
 52.3025 +            result = 31 * result + element;
 52.3026 +
 52.3027 +        return result;
 52.3028 +    }
 52.3029 +
 52.3030 +    /**
 52.3031 +     * Returns a hash code based on the contents of the specified array.
 52.3032 +     * For any two <tt>boolean</tt> arrays <tt>a</tt> and <tt>b</tt>
 52.3033 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 52.3034 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 52.3035 +     *
 52.3036 +     * <p>The value returned by this method is the same value that would be
 52.3037 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 52.3038 +     * method on a {@link List} containing a sequence of {@link Boolean}
 52.3039 +     * instances representing the elements of <tt>a</tt> in the same order.
 52.3040 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 52.3041 +     *
 52.3042 +     * @param a the array whose hash value to compute
 52.3043 +     * @return a content-based hash code for <tt>a</tt>
 52.3044 +     * @since 1.5
 52.3045 +     */
 52.3046 +    public static int hashCode(boolean a[]) {
 52.3047 +        if (a == null)
 52.3048 +            return 0;
 52.3049 +
 52.3050 +        int result = 1;
 52.3051 +        for (boolean element : a)
 52.3052 +            result = 31 * result + (element ? 1231 : 1237);
 52.3053 +
 52.3054 +        return result;
 52.3055 +    }
 52.3056 +
 52.3057 +    /**
 52.3058 +     * Returns a hash code based on the contents of the specified array.
 52.3059 +     * For any two <tt>float</tt> arrays <tt>a</tt> and <tt>b</tt>
 52.3060 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 52.3061 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 52.3062 +     *
 52.3063 +     * <p>The value returned by this method is the same value that would be
 52.3064 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 52.3065 +     * method on a {@link List} containing a sequence of {@link Float}
 52.3066 +     * instances representing the elements of <tt>a</tt> in the same order.
 52.3067 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 52.3068 +     *
 52.3069 +     * @param a the array whose hash value to compute
 52.3070 +     * @return a content-based hash code for <tt>a</tt>
 52.3071 +     * @since 1.5
 52.3072 +     */
 52.3073 +    public static int hashCode(float a[]) {
 52.3074 +        if (a == null)
 52.3075 +            return 0;
 52.3076 +
 52.3077 +        int result = 1;
 52.3078 +        for (float element : a)
 52.3079 +            result = 31 * result + Float.floatToIntBits(element);
 52.3080 +
 52.3081 +        return result;
 52.3082 +    }
 52.3083 +
 52.3084 +    /**
 52.3085 +     * Returns a hash code based on the contents of the specified array.
 52.3086 +     * For any two <tt>double</tt> arrays <tt>a</tt> and <tt>b</tt>
 52.3087 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 52.3088 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 52.3089 +     *
 52.3090 +     * <p>The value returned by this method is the same value that would be
 52.3091 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 52.3092 +     * method on a {@link List} containing a sequence of {@link Double}
 52.3093 +     * instances representing the elements of <tt>a</tt> in the same order.
 52.3094 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 52.3095 +     *
 52.3096 +     * @param a the array whose hash value to compute
 52.3097 +     * @return a content-based hash code for <tt>a</tt>
 52.3098 +     * @since 1.5
 52.3099 +     */
 52.3100 +    public static int hashCode(double a[]) {
 52.3101 +        if (a == null)
 52.3102 +            return 0;
 52.3103 +
 52.3104 +        int result = 1;
 52.3105 +        for (double element : a) {
 52.3106 +            long bits = Double.doubleToLongBits(element);
 52.3107 +            result = 31 * result + (int)(bits ^ (bits >>> 32));
 52.3108 +        }
 52.3109 +        return result;
 52.3110 +    }
 52.3111 +
 52.3112 +    /**
 52.3113 +     * Returns a hash code based on the contents of the specified array.  If
 52.3114 +     * the array contains other arrays as elements, the hash code is based on
 52.3115 +     * their identities rather than their contents.  It is therefore
 52.3116 +     * acceptable to invoke this method on an array that contains itself as an
 52.3117 +     * element,  either directly or indirectly through one or more levels of
 52.3118 +     * arrays.
 52.3119 +     *
 52.3120 +     * <p>For any two arrays <tt>a</tt> and <tt>b</tt> such that
 52.3121 +     * <tt>Arrays.equals(a, b)</tt>, it is also the case that
 52.3122 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 52.3123 +     *
 52.3124 +     * <p>The value returned by this method is equal to the value that would
 52.3125 +     * be returned by <tt>Arrays.asList(a).hashCode()</tt>, unless <tt>a</tt>
 52.3126 +     * is <tt>null</tt>, in which case <tt>0</tt> is returned.
 52.3127 +     *
 52.3128 +     * @param a the array whose content-based hash code to compute
 52.3129 +     * @return a content-based hash code for <tt>a</tt>
 52.3130 +     * @see #deepHashCode(Object[])
 52.3131 +     * @since 1.5
 52.3132 +     */
 52.3133 +    public static int hashCode(Object a[]) {
 52.3134 +        if (a == null)
 52.3135 +            return 0;
 52.3136 +
 52.3137 +        int result = 1;
 52.3138 +
 52.3139 +        for (Object element : a)
 52.3140 +            result = 31 * result + (element == null ? 0 : element.hashCode());
 52.3141 +
 52.3142 +        return result;
 52.3143 +    }
 52.3144 +
 52.3145 +    /**
 52.3146 +     * Returns a hash code based on the "deep contents" of the specified
 52.3147 +     * array.  If the array contains other arrays as elements, the
 52.3148 +     * hash code is based on their contents and so on, ad infinitum.
 52.3149 +     * It is therefore unacceptable to invoke this method on an array that
 52.3150 +     * contains itself as an element, either directly or indirectly through
 52.3151 +     * one or more levels of arrays.  The behavior of such an invocation is
 52.3152 +     * undefined.
 52.3153 +     *
 52.3154 +     * <p>For any two arrays <tt>a</tt> and <tt>b</tt> such that
 52.3155 +     * <tt>Arrays.deepEquals(a, b)</tt>, it is also the case that
 52.3156 +     * <tt>Arrays.deepHashCode(a) == Arrays.deepHashCode(b)</tt>.
 52.3157 +     *
 52.3158 +     * <p>The computation of the value returned by this method is similar to
 52.3159 +     * that of the value returned by {@link List#hashCode()} on a list
 52.3160 +     * containing the same elements as <tt>a</tt> in the same order, with one
 52.3161 +     * difference: If an element <tt>e</tt> of <tt>a</tt> is itself an array,
 52.3162 +     * its hash code is computed not by calling <tt>e.hashCode()</tt>, but as
 52.3163 +     * by calling the appropriate overloading of <tt>Arrays.hashCode(e)</tt>
 52.3164 +     * if <tt>e</tt> is an array of a primitive type, or as by calling
 52.3165 +     * <tt>Arrays.deepHashCode(e)</tt> recursively if <tt>e</tt> is an array
 52.3166 +     * of a reference type.  If <tt>a</tt> is <tt>null</tt>, this method
 52.3167 +     * returns 0.
 52.3168 +     *
 52.3169 +     * @param a the array whose deep-content-based hash code to compute
 52.3170 +     * @return a deep-content-based hash code for <tt>a</tt>
 52.3171 +     * @see #hashCode(Object[])
 52.3172 +     * @since 1.5
 52.3173 +     */
 52.3174 +    public static int deepHashCode(Object a[]) {
 52.3175 +        if (a == null)
 52.3176 +            return 0;
 52.3177 +
 52.3178 +        int result = 1;
 52.3179 +
 52.3180 +        for (Object element : a) {
 52.3181 +            int elementHash = 0;
 52.3182 +            if (element instanceof Object[])
 52.3183 +                elementHash = deepHashCode((Object[]) element);
 52.3184 +            else if (element instanceof byte[])
 52.3185 +                elementHash = hashCode((byte[]) element);
 52.3186 +            else if (element instanceof short[])
 52.3187 +                elementHash = hashCode((short[]) element);
 52.3188 +            else if (element instanceof int[])
 52.3189 +                elementHash = hashCode((int[]) element);
 52.3190 +            else if (element instanceof long[])
 52.3191 +                elementHash = hashCode((long[]) element);
 52.3192 +            else if (element instanceof char[])
 52.3193 +                elementHash = hashCode((char[]) element);
 52.3194 +            else if (element instanceof float[])
 52.3195 +                elementHash = hashCode((float[]) element);
 52.3196 +            else if (element instanceof double[])
 52.3197 +                elementHash = hashCode((double[]) element);
 52.3198 +            else if (element instanceof boolean[])
 52.3199 +                elementHash = hashCode((boolean[]) element);
 52.3200 +            else if (element != null)
 52.3201 +                elementHash = element.hashCode();
 52.3202 +
 52.3203 +            result = 31 * result + elementHash;
 52.3204 +        }
 52.3205 +
 52.3206 +        return result;
 52.3207 +    }
 52.3208 +
 52.3209 +    /**
 52.3210 +     * Returns <tt>true</tt> if the two specified arrays are <i>deeply
 52.3211 +     * equal</i> to one another.  Unlike the {@link #equals(Object[],Object[])}
 52.3212 +     * method, this method is appropriate for use with nested arrays of
 52.3213 +     * arbitrary depth.
 52.3214 +     *
 52.3215 +     * <p>Two array references are considered deeply equal if both
 52.3216 +     * are <tt>null</tt>, or if they refer to arrays that contain the same
 52.3217 +     * number of elements and all corresponding pairs of elements in the two
 52.3218 +     * arrays are deeply equal.
 52.3219 +     *
 52.3220 +     * <p>Two possibly <tt>null</tt> elements <tt>e1</tt> and <tt>e2</tt> are
 52.3221 +     * deeply equal if any of the following conditions hold:
 52.3222 +     * <ul>
 52.3223 +     *    <li> <tt>e1</tt> and <tt>e2</tt> are both arrays of object reference
 52.3224 +     *         types, and <tt>Arrays.deepEquals(e1, e2) would return true</tt>
 52.3225 +     *    <li> <tt>e1</tt> and <tt>e2</tt> are arrays of the same primitive
 52.3226 +     *         type, and the appropriate overloading of
 52.3227 +     *         <tt>Arrays.equals(e1, e2)</tt> would return true.
 52.3228 +     *    <li> <tt>e1 == e2</tt>
 52.3229 +     *    <li> <tt>e1.equals(e2)</tt> would return true.
 52.3230 +     * </ul>
 52.3231 +     * Note that this definition permits <tt>null</tt> elements at any depth.
 52.3232 +     *
 52.3233 +     * <p>If either of the specified arrays contain themselves as elements
 52.3234 +     * either directly or indirectly through one or more levels of arrays,
 52.3235 +     * the behavior of this method is undefined.
 52.3236 +     *
 52.3237 +     * @param a1 one array to be tested for equality
 52.3238 +     * @param a2 the other array to be tested for equality
 52.3239 +     * @return <tt>true</tt> if the two arrays are equal
 52.3240 +     * @see #equals(Object[],Object[])
 52.3241 +     * @see Objects#deepEquals(Object, Object)
 52.3242 +     * @since 1.5
 52.3243 +     */
 52.3244 +    public static boolean deepEquals(Object[] a1, Object[] a2) {
 52.3245 +        if (a1 == a2)
 52.3246 +            return true;
 52.3247 +        if (a1 == null || a2==null)
 52.3248 +            return false;
 52.3249 +        int length = a1.length;
 52.3250 +        if (a2.length != length)
 52.3251 +            return false;
 52.3252 +
 52.3253 +        for (int i = 0; i < length; i++) {
 52.3254 +            Object e1 = a1[i];
 52.3255 +            Object e2 = a2[i];
 52.3256 +
 52.3257 +            if (e1 == e2)
 52.3258 +                continue;
 52.3259 +            if (e1 == null)
 52.3260 +                return false;
 52.3261 +
 52.3262 +            // Figure out whether the two elements are equal
 52.3263 +            boolean eq = deepEquals0(e1, e2);
 52.3264 +
 52.3265 +            if (!eq)
 52.3266 +                return false;
 52.3267 +        }
 52.3268 +        return true;
 52.3269 +    }
 52.3270 +
 52.3271 +    static boolean deepEquals0(Object e1, Object e2) {
 52.3272 +        assert e1 != null;
 52.3273 +        boolean eq;
 52.3274 +        if (e1 instanceof Object[] && e2 instanceof Object[])
 52.3275 +            eq = deepEquals ((Object[]) e1, (Object[]) e2);
 52.3276 +        else if (e1 instanceof byte[] && e2 instanceof byte[])
 52.3277 +            eq = equals((byte[]) e1, (byte[]) e2);
 52.3278 +        else if (e1 instanceof short[] && e2 instanceof short[])
 52.3279 +            eq = equals((short[]) e1, (short[]) e2);
 52.3280 +        else if (e1 instanceof int[] && e2 instanceof int[])
 52.3281 +            eq = equals((int[]) e1, (int[]) e2);
 52.3282 +        else if (e1 instanceof long[] && e2 instanceof long[])
 52.3283 +            eq = equals((long[]) e1, (long[]) e2);
 52.3284 +        else if (e1 instanceof char[] && e2 instanceof char[])
 52.3285 +            eq = equals((char[]) e1, (char[]) e2);
 52.3286 +        else if (e1 instanceof float[] && e2 instanceof float[])
 52.3287 +            eq = equals((float[]) e1, (float[]) e2);
 52.3288 +        else if (e1 instanceof double[] && e2 instanceof double[])
 52.3289 +            eq = equals((double[]) e1, (double[]) e2);
 52.3290 +        else if (e1 instanceof boolean[] && e2 instanceof boolean[])
 52.3291 +            eq = equals((boolean[]) e1, (boolean[]) e2);
 52.3292 +        else
 52.3293 +            eq = e1.equals(e2);
 52.3294 +        return eq;
 52.3295 +    }
 52.3296 +
 52.3297 +    /**
 52.3298 +     * Returns a string representation of the contents of the specified array.
 52.3299 +     * The string representation consists of a list of the array's elements,
 52.3300 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 52.3301 +     * separated by the characters <tt>", "</tt> (a comma followed by a
 52.3302 +     * space).  Elements are converted to strings as by
 52.3303 +     * <tt>String.valueOf(long)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
 52.3304 +     * is <tt>null</tt>.
 52.3305 +     *
 52.3306 +     * @param a the array whose string representation to return
 52.3307 +     * @return a string representation of <tt>a</tt>
 52.3308 +     * @since 1.5
 52.3309 +     */
 52.3310 +    public static String toString(long[] a) {
 52.3311 +        if (a == null)
 52.3312 +            return "null";
 52.3313 +        int iMax = a.length - 1;
 52.3314 +        if (iMax == -1)
 52.3315 +            return "[]";
 52.3316 +
 52.3317 +        StringBuilder b = new StringBuilder();
 52.3318 +        b.append('[');
 52.3319 +        for (int i = 0; ; i++) {
 52.3320 +            b.append(a[i]);
 52.3321 +            if (i == iMax)
 52.3322 +                return b.append(']').toString();
 52.3323 +            b.append(", ");
 52.3324 +        }
 52.3325 +    }
 52.3326 +
 52.3327 +    /**
 52.3328 +     * Returns a string representation of the contents of the specified array.
 52.3329 +     * The string representation consists of a list of the array's elements,
 52.3330 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 52.3331 +     * separated by the characters <tt>", "</tt> (a comma followed by a
 52.3332 +     * space).  Elements are converted to strings as by
 52.3333 +     * <tt>String.valueOf(int)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt> is
 52.3334 +     * <tt>null</tt>.
 52.3335 +     *
 52.3336 +     * @param a the array whose string representation to return
 52.3337 +     * @return a string representation of <tt>a</tt>
 52.3338 +     * @since 1.5
 52.3339 +     */
 52.3340 +    public static String toString(int[] a) {
 52.3341 +        if (a == null)
 52.3342 +            return "null";
 52.3343 +        int iMax = a.length - 1;
 52.3344 +        if (iMax == -1)
 52.3345 +            return "[]";
 52.3346 +
 52.3347 +        StringBuilder b = new StringBuilder();
 52.3348 +        b.append('[');
 52.3349 +        for (int i = 0; ; i++) {
 52.3350 +            b.append(a[i]);
 52.3351 +            if (i == iMax)
 52.3352 +                return b.append(']').toString();
 52.3353 +            b.append(", ");
 52.3354 +        }
 52.3355 +    }
 52.3356 +
 52.3357 +    /**
 52.3358 +     * Returns a string representation of the contents of the specified array.
 52.3359 +     * The string representation consists of a list of the array's elements,
 52.3360 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 52.3361 +     * separated by the characters <tt>", "</tt> (a comma followed by a
 52.3362 +     * space).  Elements are converted to strings as by
 52.3363 +     * <tt>String.valueOf(short)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
 52.3364 +     * is <tt>null</tt>.
 52.3365 +     *
 52.3366 +     * @param a the array whose string representation to return
 52.3367 +     * @return a string representation of <tt>a</tt>
 52.3368 +     * @since 1.5
 52.3369 +     */
 52.3370 +    public static String toString(short[] a) {
 52.3371 +        if (a == null)
 52.3372 +            return "null";
 52.3373 +        int iMax = a.length - 1;
 52.3374 +        if (iMax == -1)
 52.3375 +            return "[]";
 52.3376 +
 52.3377 +        StringBuilder b = new StringBuilder();
 52.3378 +        b.append('[');
 52.3379 +        for (int i = 0; ; i++) {
 52.3380 +            b.append(a[i]);
 52.3381 +            if (i == iMax)
 52.3382 +                return b.append(']').toString();
 52.3383 +            b.append(", ");
 52.3384 +        }
 52.3385 +    }
 52.3386 +
 52.3387 +    /**
 52.3388 +     * Returns a string representation of the contents of the specified array.
 52.3389 +     * The string representation consists of a list of the array's elements,
 52.3390 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 52.3391 +     * separated by the characters <tt>", "</tt> (a comma followed by a
 52.3392 +     * space).  Elements are converted to strings as by
 52.3393 +     * <tt>String.valueOf(char)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
 52.3394 +     * is <tt>null</tt>.
 52.3395 +     *
 52.3396 +     * @param a the array whose string representation to return
 52.3397 +     * @return a string representation of <tt>a</tt>
 52.3398 +     * @since 1.5
 52.3399 +     */
 52.3400 +    public static String toString(char[] a) {
 52.3401 +        if (a == null)
 52.3402 +            return "null";
 52.3403 +        int iMax = a.length - 1;
 52.3404 +        if (iMax == -1)
 52.3405 +            return "[]";
 52.3406 +
 52.3407 +        StringBuilder b = new StringBuilder();
 52.3408 +        b.append('[');
 52.3409 +        for (int i = 0; ; i++) {
 52.3410 +            b.append(a[i]);
 52.3411 +            if (i == iMax)
 52.3412 +                return b.append(']').toString();
 52.3413 +            b.append(", ");
 52.3414 +        }
 52.3415 +    }
 52.3416 +
 52.3417 +    /**
 52.3418 +     * Returns a string representation of the contents of the specified array.
 52.3419 +     * The string representation consists of a list of the array's elements,
 52.3420 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements
 52.3421 +     * are separated by the characters <tt>", "</tt> (a comma followed
 52.3422 +     * by a space).  Elements are converted to strings as by
 52.3423 +     * <tt>String.valueOf(byte)</tt>.  Returns <tt>"null"</tt> if
 52.3424 +     * <tt>a</tt> is <tt>null</tt>.
 52.3425 +     *
 52.3426 +     * @param a the array whose string representation to return
 52.3427 +     * @return a string representation of <tt>a</tt>
 52.3428 +     * @since 1.5
 52.3429 +     */
 52.3430 +    public static String toString(byte[] a) {
 52.3431 +        if (a == null)
 52.3432 +            return "null";
 52.3433 +        int iMax = a.length - 1;
 52.3434 +        if (iMax == -1)
 52.3435 +            return "[]";
 52.3436 +
 52.3437 +        StringBuilder b = new StringBuilder();
 52.3438 +        b.append('[');
 52.3439 +        for (int i = 0; ; i++) {
 52.3440 +            b.append(a[i]);
 52.3441 +            if (i == iMax)
 52.3442 +                return b.append(']').toString();
 52.3443 +            b.append(", ");
 52.3444 +        }
 52.3445 +    }
 52.3446 +
 52.3447 +    /**
 52.3448 +     * Returns a string representation of the contents of the specified array.
 52.3449 +     * The string representation consists of a list of the array's elements,
 52.3450 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 52.3451 +     * separated by the characters <tt>", "</tt> (a comma followed by a
 52.3452 +     * space).  Elements are converted to strings as by
 52.3453 +     * <tt>String.valueOf(boolean)</tt>.  Returns <tt>"null"</tt> if
 52.3454 +     * <tt>a</tt> is <tt>null</tt>.
 52.3455 +     *
 52.3456 +     * @param a the array whose string representation to return
 52.3457 +     * @return a string representation of <tt>a</tt>
 52.3458 +     * @since 1.5
 52.3459 +     */
 52.3460 +    public static String toString(boolean[] a) {
 52.3461 +        if (a == null)
 52.3462 +            return "null";
 52.3463 +        int iMax = a.length - 1;
 52.3464 +        if (iMax == -1)
 52.3465 +            return "[]";
 52.3466 +
 52.3467 +        StringBuilder b = new StringBuilder();
 52.3468 +        b.append('[');
 52.3469 +        for (int i = 0; ; i++) {
 52.3470 +            b.append(a[i]);
 52.3471 +            if (i == iMax)
 52.3472 +                return b.append(']').toString();
 52.3473 +            b.append(", ");
 52.3474 +        }
 52.3475 +    }
 52.3476 +
 52.3477 +    /**
 52.3478 +     * Returns a string representation of the contents of the specified array.
 52.3479 +     * The string representation consists of a list of the array's elements,
 52.3480 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 52.3481 +     * separated by the characters <tt>", "</tt> (a comma followed by a
 52.3482 +     * space).  Elements are converted to strings as by
 52.3483 +     * <tt>String.valueOf(float)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
 52.3484 +     * is <tt>null</tt>.
 52.3485 +     *
 52.3486 +     * @param a the array whose string representation to return
 52.3487 +     * @return a string representation of <tt>a</tt>
 52.3488 +     * @since 1.5
 52.3489 +     */
 52.3490 +    public static String toString(float[] a) {
 52.3491 +        if (a == null)
 52.3492 +            return "null";
 52.3493 +
 52.3494 +        int iMax = a.length - 1;
 52.3495 +        if (iMax == -1)
 52.3496 +            return "[]";
 52.3497 +
 52.3498 +        StringBuilder b = new StringBuilder();
 52.3499 +        b.append('[');
 52.3500 +        for (int i = 0; ; i++) {
 52.3501 +            b.append(a[i]);
 52.3502 +            if (i == iMax)
 52.3503 +                return b.append(']').toString();
 52.3504 +            b.append(", ");
 52.3505 +        }
 52.3506 +    }
 52.3507 +
 52.3508 +    /**
 52.3509 +     * Returns a string representation of the contents of the specified array.
 52.3510 +     * The string representation consists of a list of the array's elements,
 52.3511 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 52.3512 +     * separated by the characters <tt>", "</tt> (a comma followed by a
 52.3513 +     * space).  Elements are converted to strings as by
 52.3514 +     * <tt>String.valueOf(double)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
 52.3515 +     * is <tt>null</tt>.
 52.3516 +     *
 52.3517 +     * @param a the array whose string representation to return
 52.3518 +     * @return a string representation of <tt>a</tt>
 52.3519 +     * @since 1.5
 52.3520 +     */
 52.3521 +    public static String toString(double[] a) {
 52.3522 +        if (a == null)
 52.3523 +            return "null";
 52.3524 +        int iMax = a.length - 1;
 52.3525 +        if (iMax == -1)
 52.3526 +            return "[]";
 52.3527 +
 52.3528 +        StringBuilder b = new StringBuilder();
 52.3529 +        b.append('[');
 52.3530 +        for (int i = 0; ; i++) {
 52.3531 +            b.append(a[i]);
 52.3532 +            if (i == iMax)
 52.3533 +                return b.append(']').toString();
 52.3534 +            b.append(", ");
 52.3535 +        }
 52.3536 +    }
 52.3537 +
 52.3538 +    /**
 52.3539 +     * Returns a string representation of the contents of the specified array.
 52.3540 +     * If the array contains other arrays as elements, they are converted to
 52.3541 +     * strings by the {@link Object#toString} method inherited from
 52.3542 +     * <tt>Object</tt>, which describes their <i>identities</i> rather than
 52.3543 +     * their contents.
 52.3544 +     *
 52.3545 +     * <p>The value returned by this method is equal to the value that would
 52.3546 +     * be returned by <tt>Arrays.asList(a).toString()</tt>, unless <tt>a</tt>
 52.3547 +     * is <tt>null</tt>, in which case <tt>"null"</tt> is returned.
 52.3548 +     *
 52.3549 +     * @param a the array whose string representation to return
 52.3550 +     * @return a string representation of <tt>a</tt>
 52.3551 +     * @see #deepToString(Object[])
 52.3552 +     * @since 1.5
 52.3553 +     */
 52.3554 +    public static String toString(Object[] a) {
 52.3555 +        if (a == null)
 52.3556 +            return "null";
 52.3557 +
 52.3558 +        int iMax = a.length - 1;
 52.3559 +        if (iMax == -1)
 52.3560 +            return "[]";
 52.3561 +
 52.3562 +        StringBuilder b = new StringBuilder();
 52.3563 +        b.append('[');
 52.3564 +        for (int i = 0; ; i++) {
 52.3565 +            b.append(String.valueOf(a[i]));
 52.3566 +            if (i == iMax)
 52.3567 +                return b.append(']').toString();
 52.3568 +            b.append(", ");
 52.3569 +        }
 52.3570 +    }
 52.3571 +
 52.3572 +    /**
 52.3573 +     * Returns a string representation of the "deep contents" of the specified
 52.3574 +     * array.  If the array contains other arrays as elements, the string
 52.3575 +     * representation contains their contents and so on.  This method is
 52.3576 +     * designed for converting multidimensional arrays to strings.
 52.3577 +     *
 52.3578 +     * <p>The string representation consists of a list of the array's
 52.3579 +     * elements, enclosed in square brackets (<tt>"[]"</tt>).  Adjacent
 52.3580 +     * elements are separated by the characters <tt>", "</tt> (a comma
 52.3581 +     * followed by a space).  Elements are converted to strings as by
 52.3582 +     * <tt>String.valueOf(Object)</tt>, unless they are themselves
 52.3583 +     * arrays.
 52.3584 +     *
 52.3585 +     * <p>If an element <tt>e</tt> is an array of a primitive type, it is
 52.3586 +     * converted to a string as by invoking the appropriate overloading of
 52.3587 +     * <tt>Arrays.toString(e)</tt>.  If an element <tt>e</tt> is an array of a
 52.3588 +     * reference type, it is converted to a string as by invoking
 52.3589 +     * this method recursively.
 52.3590 +     *
 52.3591 +     * <p>To avoid infinite recursion, if the specified array contains itself
 52.3592 +     * as an element, or contains an indirect reference to itself through one
 52.3593 +     * or more levels of arrays, the self-reference is converted to the string
 52.3594 +     * <tt>"[...]"</tt>.  For example, an array containing only a reference
 52.3595 +     * to itself would be rendered as <tt>"[[...]]"</tt>.
 52.3596 +     *
 52.3597 +     * <p>This method returns <tt>"null"</tt> if the specified array
 52.3598 +     * is <tt>null</tt>.
 52.3599 +     *
 52.3600 +     * @param a the array whose string representation to return
 52.3601 +     * @return a string representation of <tt>a</tt>
 52.3602 +     * @see #toString(Object[])
 52.3603 +     * @since 1.5
 52.3604 +     */
 52.3605 +    public static String deepToString(Object[] a) {
 52.3606 +        if (a == null)
 52.3607 +            return "null";
 52.3608 +
 52.3609 +        int bufLen = 20 * a.length;
 52.3610 +        if (a.length != 0 && bufLen <= 0)
 52.3611 +            bufLen = Integer.MAX_VALUE;
 52.3612 +        StringBuilder buf = new StringBuilder(bufLen);
 52.3613 +        deepToString(a, buf, new HashSet<Object[]>());
 52.3614 +        return buf.toString();
 52.3615 +    }
 52.3616 +
 52.3617 +    private static void deepToString(Object[] a, StringBuilder buf,
 52.3618 +                                     Set<Object[]> dejaVu) {
 52.3619 +        if (a == null) {
 52.3620 +            buf.append("null");
 52.3621 +            return;
 52.3622 +        }
 52.3623 +        int iMax = a.length - 1;
 52.3624 +        if (iMax == -1) {
 52.3625 +            buf.append("[]");
 52.3626 +            return;
 52.3627 +        }
 52.3628 +
 52.3629 +        dejaVu.add(a);
 52.3630 +        buf.append('[');
 52.3631 +        for (int i = 0; ; i++) {
 52.3632 +
 52.3633 +            Object element = a[i];
 52.3634 +            if (element == null) {
 52.3635 +                buf.append("null");
 52.3636 +            } else {
 52.3637 +                Class eClass = element.getClass();
 52.3638 +
 52.3639 +                if (eClass.isArray()) {
 52.3640 +                    if (eClass == byte[].class)
 52.3641 +                        buf.append(toString((byte[]) element));
 52.3642 +                    else if (eClass == short[].class)
 52.3643 +                        buf.append(toString((short[]) element));
 52.3644 +                    else if (eClass == int[].class)
 52.3645 +                        buf.append(toString((int[]) element));
 52.3646 +                    else if (eClass == long[].class)
 52.3647 +                        buf.append(toString((long[]) element));
 52.3648 +                    else if (eClass == char[].class)
 52.3649 +                        buf.append(toString((char[]) element));
 52.3650 +                    else if (eClass == float[].class)
 52.3651 +                        buf.append(toString((float[]) element));
 52.3652 +                    else if (eClass == double[].class)
 52.3653 +                        buf.append(toString((double[]) element));
 52.3654 +                    else if (eClass == boolean[].class)
 52.3655 +                        buf.append(toString((boolean[]) element));
 52.3656 +                    else { // element is an array of object references
 52.3657 +                        if (dejaVu.contains(element))
 52.3658 +                            buf.append("[...]");
 52.3659 +                        else
 52.3660 +                            deepToString((Object[])element, buf, dejaVu);
 52.3661 +                    }
 52.3662 +                } else {  // element is non-null and not an array
 52.3663 +                    buf.append(element.toString());
 52.3664 +                }
 52.3665 +            }
 52.3666 +            if (i == iMax)
 52.3667 +                break;
 52.3668 +            buf.append(", ");
 52.3669 +        }
 52.3670 +        buf.append(']');
 52.3671 +        dejaVu.remove(a);
 52.3672 +    }
 52.3673 +}
    53.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.2 +++ b/emul/compact/src/main/java/java/util/Collection.java	Sun Feb 03 07:48:42 2013 +0100
    53.3 @@ -0,0 +1,456 @@
    53.4 +/*
    53.5 + * Copyright (c) 1997, 2010, 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.util;
   53.30 +
   53.31 +/**
   53.32 + * The root interface in the <i>collection hierarchy</i>.  A collection
   53.33 + * represents a group of objects, known as its <i>elements</i>.  Some
   53.34 + * collections allow duplicate elements and others do not.  Some are ordered
   53.35 + * and others unordered.  The JDK does not provide any <i>direct</i>
   53.36 + * implementations of this interface: it provides implementations of more
   53.37 + * specific subinterfaces like <tt>Set</tt> and <tt>List</tt>.  This interface
   53.38 + * is typically used to pass collections around and manipulate them where
   53.39 + * maximum generality is desired.
   53.40 + *
   53.41 + * <p><i>Bags</i> or <i>multisets</i> (unordered collections that may contain
   53.42 + * duplicate elements) should implement this interface directly.
   53.43 + *
   53.44 + * <p>All general-purpose <tt>Collection</tt> implementation classes (which
   53.45 + * typically implement <tt>Collection</tt> indirectly through one of its
   53.46 + * subinterfaces) should provide two "standard" constructors: a void (no
   53.47 + * arguments) constructor, which creates an empty collection, and a
   53.48 + * constructor with a single argument of type <tt>Collection</tt>, which
   53.49 + * creates a new collection with the same elements as its argument.  In
   53.50 + * effect, the latter constructor allows the user to copy any collection,
   53.51 + * producing an equivalent collection of the desired implementation type.
   53.52 + * There is no way to enforce this convention (as interfaces cannot contain
   53.53 + * constructors) but all of the general-purpose <tt>Collection</tt>
   53.54 + * implementations in the Java platform libraries comply.
   53.55 + *
   53.56 + * <p>The "destructive" methods contained in this interface, that is, the
   53.57 + * methods that modify the collection on which they operate, are specified to
   53.58 + * throw <tt>UnsupportedOperationException</tt> if this collection does not
   53.59 + * support the operation.  If this is the case, these methods may, but are not
   53.60 + * required to, throw an <tt>UnsupportedOperationException</tt> if the
   53.61 + * invocation would have no effect on the collection.  For example, invoking
   53.62 + * the {@link #addAll(Collection)} method on an unmodifiable collection may,
   53.63 + * but is not required to, throw the exception if the collection to be added
   53.64 + * is empty.
   53.65 + *
   53.66 + * <p><a name="optional-restrictions"/>
   53.67 + * Some collection implementations have restrictions on the elements that
   53.68 + * they may contain.  For example, some implementations prohibit null elements,
   53.69 + * and some have restrictions on the types of their elements.  Attempting to
   53.70 + * add an ineligible element throws an unchecked exception, typically
   53.71 + * <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.  Attempting
   53.72 + * to query the presence of an ineligible element may throw an exception,
   53.73 + * or it may simply return false; some implementations will exhibit the former
   53.74 + * behavior and some will exhibit the latter.  More generally, attempting an
   53.75 + * operation on an ineligible element whose completion would not result in
   53.76 + * the insertion of an ineligible element into the collection may throw an
   53.77 + * exception or it may succeed, at the option of the implementation.
   53.78 + * Such exceptions are marked as "optional" in the specification for this
   53.79 + * interface.
   53.80 + *
   53.81 + * <p>It is up to each collection to determine its own synchronization
   53.82 + * policy.  In the absence of a stronger guarantee by the
   53.83 + * implementation, undefined behavior may result from the invocation
   53.84 + * of any method on a collection that is being mutated by another
   53.85 + * thread; this includes direct invocations, passing the collection to
   53.86 + * a method that might perform invocations, and using an existing
   53.87 + * iterator to examine the collection.
   53.88 + *
   53.89 + * <p>Many methods in Collections Framework interfaces are defined in
   53.90 + * terms of the {@link Object#equals(Object) equals} method.  For example,
   53.91 + * the specification for the {@link #contains(Object) contains(Object o)}
   53.92 + * method says: "returns <tt>true</tt> if and only if this collection
   53.93 + * contains at least one element <tt>e</tt> such that
   53.94 + * <tt>(o==null ? e==null : o.equals(e))</tt>."  This specification should
   53.95 + * <i>not</i> be construed to imply that invoking <tt>Collection.contains</tt>
   53.96 + * with a non-null argument <tt>o</tt> will cause <tt>o.equals(e)</tt> to be
   53.97 + * invoked for any element <tt>e</tt>.  Implementations are free to implement
   53.98 + * optimizations whereby the <tt>equals</tt> invocation is avoided, for
   53.99 + * example, by first comparing the hash codes of the two elements.  (The
  53.100 + * {@link Object#hashCode()} specification guarantees that two objects with
  53.101 + * unequal hash codes cannot be equal.)  More generally, implementations of
  53.102 + * the various Collections Framework interfaces are free to take advantage of
  53.103 + * the specified behavior of underlying {@link Object} methods wherever the
  53.104 + * implementor deems it appropriate.
  53.105 + *
  53.106 + * <p>This interface is a member of the
  53.107 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  53.108 + * Java Collections Framework</a>.
  53.109 + *
  53.110 + * @param <E> the type of elements in this collection
  53.111 + *
  53.112 + * @author  Josh Bloch
  53.113 + * @author  Neal Gafter
  53.114 + * @see     Set
  53.115 + * @see     List
  53.116 + * @see     Map
  53.117 + * @see     SortedSet
  53.118 + * @see     SortedMap
  53.119 + * @see     HashSet
  53.120 + * @see     TreeSet
  53.121 + * @see     ArrayList
  53.122 + * @see     LinkedList
  53.123 + * @see     Vector
  53.124 + * @see     Collections
  53.125 + * @see     Arrays
  53.126 + * @see     AbstractCollection
  53.127 + * @since 1.2
  53.128 + */
  53.129 +
  53.130 +public interface Collection<E> extends Iterable<E> {
  53.131 +    // Query Operations
  53.132 +
  53.133 +    /**
  53.134 +     * Returns the number of elements in this collection.  If this collection
  53.135 +     * contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
  53.136 +     * <tt>Integer.MAX_VALUE</tt>.
  53.137 +     *
  53.138 +     * @return the number of elements in this collection
  53.139 +     */
  53.140 +    int size();
  53.141 +
  53.142 +    /**
  53.143 +     * Returns <tt>true</tt> if this collection contains no elements.
  53.144 +     *
  53.145 +     * @return <tt>true</tt> if this collection contains no elements
  53.146 +     */
  53.147 +    boolean isEmpty();
  53.148 +
  53.149 +    /**
  53.150 +     * Returns <tt>true</tt> if this collection contains the specified element.
  53.151 +     * More formally, returns <tt>true</tt> if and only if this collection
  53.152 +     * contains at least one element <tt>e</tt> such that
  53.153 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  53.154 +     *
  53.155 +     * @param o element whose presence in this collection is to be tested
  53.156 +     * @return <tt>true</tt> if this collection contains the specified
  53.157 +     *         element
  53.158 +     * @throws ClassCastException if the type of the specified element
  53.159 +     *         is incompatible with this collection
  53.160 +     *         (<a href="#optional-restrictions">optional</a>)
  53.161 +     * @throws NullPointerException if the specified element is null and this
  53.162 +     *         collection does not permit null elements
  53.163 +     *         (<a href="#optional-restrictions">optional</a>)
  53.164 +     */
  53.165 +    boolean contains(Object o);
  53.166 +
  53.167 +    /**
  53.168 +     * Returns an iterator over the elements in this collection.  There are no
  53.169 +     * guarantees concerning the order in which the elements are returned
  53.170 +     * (unless this collection is an instance of some class that provides a
  53.171 +     * guarantee).
  53.172 +     *
  53.173 +     * @return an <tt>Iterator</tt> over the elements in this collection
  53.174 +     */
  53.175 +    Iterator<E> iterator();
  53.176 +
  53.177 +    /**
  53.178 +     * Returns an array containing all of the elements in this collection.
  53.179 +     * If this collection makes any guarantees as to what order its elements
  53.180 +     * are returned by its iterator, this method must return the elements in
  53.181 +     * the same order.
  53.182 +     *
  53.183 +     * <p>The returned array will be "safe" in that no references to it are
  53.184 +     * maintained by this collection.  (In other words, this method must
  53.185 +     * allocate a new array even if this collection is backed by an array).
  53.186 +     * The caller is thus free to modify the returned array.
  53.187 +     *
  53.188 +     * <p>This method acts as bridge between array-based and collection-based
  53.189 +     * APIs.
  53.190 +     *
  53.191 +     * @return an array containing all of the elements in this collection
  53.192 +     */
  53.193 +    Object[] toArray();
  53.194 +
  53.195 +    /**
  53.196 +     * Returns an array containing all of the elements in this collection;
  53.197 +     * the runtime type of the returned array is that of the specified array.
  53.198 +     * If the collection fits in the specified array, it is returned therein.
  53.199 +     * Otherwise, a new array is allocated with the runtime type of the
  53.200 +     * specified array and the size of this collection.
  53.201 +     *
  53.202 +     * <p>If this collection fits in the specified array with room to spare
  53.203 +     * (i.e., the array has more elements than this collection), the element
  53.204 +     * in the array immediately following the end of the collection is set to
  53.205 +     * <tt>null</tt>.  (This is useful in determining the length of this
  53.206 +     * collection <i>only</i> if the caller knows that this collection does
  53.207 +     * not contain any <tt>null</tt> elements.)
  53.208 +     *
  53.209 +     * <p>If this collection makes any guarantees as to what order its elements
  53.210 +     * are returned by its iterator, this method must return the elements in
  53.211 +     * the same order.
  53.212 +     *
  53.213 +     * <p>Like the {@link #toArray()} method, this method acts as bridge between
  53.214 +     * array-based and collection-based APIs.  Further, this method allows
  53.215 +     * precise control over the runtime type of the output array, and may,
  53.216 +     * under certain circumstances, be used to save allocation costs.
  53.217 +     *
  53.218 +     * <p>Suppose <tt>x</tt> is a collection known to contain only strings.
  53.219 +     * The following code can be used to dump the collection into a newly
  53.220 +     * allocated array of <tt>String</tt>:
  53.221 +     *
  53.222 +     * <pre>
  53.223 +     *     String[] y = x.toArray(new String[0]);</pre>
  53.224 +     *
  53.225 +     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
  53.226 +     * <tt>toArray()</tt>.
  53.227 +     *
  53.228 +     * @param a the array into which the elements of this collection are to be
  53.229 +     *        stored, if it is big enough; otherwise, a new array of the same
  53.230 +     *        runtime type is allocated for this purpose.
  53.231 +     * @return an array containing all of the elements in this collection
  53.232 +     * @throws ArrayStoreException if the runtime type of the specified array
  53.233 +     *         is not a supertype of the runtime type of every element in
  53.234 +     *         this collection
  53.235 +     * @throws NullPointerException if the specified array is null
  53.236 +     */
  53.237 +    <T> T[] toArray(T[] a);
  53.238 +
  53.239 +    // Modification Operations
  53.240 +
  53.241 +    /**
  53.242 +     * Ensures that this collection contains the specified element (optional
  53.243 +     * operation).  Returns <tt>true</tt> if this collection changed as a
  53.244 +     * result of the call.  (Returns <tt>false</tt> if this collection does
  53.245 +     * not permit duplicates and already contains the specified element.)<p>
  53.246 +     *
  53.247 +     * Collections that support this operation may place limitations on what
  53.248 +     * elements may be added to this collection.  In particular, some
  53.249 +     * collections will refuse to add <tt>null</tt> elements, and others will
  53.250 +     * impose restrictions on the type of elements that may be added.
  53.251 +     * Collection classes should clearly specify in their documentation any
  53.252 +     * restrictions on what elements may be added.<p>
  53.253 +     *
  53.254 +     * If a collection refuses to add a particular element for any reason
  53.255 +     * other than that it already contains the element, it <i>must</i> throw
  53.256 +     * an exception (rather than returning <tt>false</tt>).  This preserves
  53.257 +     * the invariant that a collection always contains the specified element
  53.258 +     * after this call returns.
  53.259 +     *
  53.260 +     * @param e element whose presence in this collection is to be ensured
  53.261 +     * @return <tt>true</tt> if this collection changed as a result of the
  53.262 +     *         call
  53.263 +     * @throws UnsupportedOperationException if the <tt>add</tt> operation
  53.264 +     *         is not supported by this collection
  53.265 +     * @throws ClassCastException if the class of the specified element
  53.266 +     *         prevents it from being added to this collection
  53.267 +     * @throws NullPointerException if the specified element is null and this
  53.268 +     *         collection does not permit null elements
  53.269 +     * @throws IllegalArgumentException if some property of the element
  53.270 +     *         prevents it from being added to this collection
  53.271 +     * @throws IllegalStateException if the element cannot be added at this
  53.272 +     *         time due to insertion restrictions
  53.273 +     */
  53.274 +    boolean add(E e);
  53.275 +
  53.276 +    /**
  53.277 +     * Removes a single instance of the specified element from this
  53.278 +     * collection, if it is present (optional operation).  More formally,
  53.279 +     * removes an element <tt>e</tt> such that
  53.280 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>, if
  53.281 +     * this collection contains one or more such elements.  Returns
  53.282 +     * <tt>true</tt> if this collection contained the specified element (or
  53.283 +     * equivalently, if this collection changed as a result of the call).
  53.284 +     *
  53.285 +     * @param o element to be removed from this collection, if present
  53.286 +     * @return <tt>true</tt> if an element was removed as a result of this call
  53.287 +     * @throws ClassCastException if the type of the specified element
  53.288 +     *         is incompatible with this collection
  53.289 +     *         (<a href="#optional-restrictions">optional</a>)
  53.290 +     * @throws NullPointerException if the specified element is null and this
  53.291 +     *         collection does not permit null elements
  53.292 +     *         (<a href="#optional-restrictions">optional</a>)
  53.293 +     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
  53.294 +     *         is not supported by this collection
  53.295 +     */
  53.296 +    boolean remove(Object o);
  53.297 +
  53.298 +
  53.299 +    // Bulk Operations
  53.300 +
  53.301 +    /**
  53.302 +     * Returns <tt>true</tt> if this collection contains all of the elements
  53.303 +     * in the specified collection.
  53.304 +     *
  53.305 +     * @param  c collection to be checked for containment in this collection
  53.306 +     * @return <tt>true</tt> if this collection contains all of the elements
  53.307 +     *         in the specified collection
  53.308 +     * @throws ClassCastException if the types of one or more elements
  53.309 +     *         in the specified collection are incompatible with this
  53.310 +     *         collection
  53.311 +     *         (<a href="#optional-restrictions">optional</a>)
  53.312 +     * @throws NullPointerException if the specified collection contains one
  53.313 +     *         or more null elements and this collection does not permit null
  53.314 +     *         elements
  53.315 +     *         (<a href="#optional-restrictions">optional</a>),
  53.316 +     *         or if the specified collection is null.
  53.317 +     * @see    #contains(Object)
  53.318 +     */
  53.319 +    boolean containsAll(Collection<?> c);
  53.320 +
  53.321 +    /**
  53.322 +     * Adds all of the elements in the specified collection to this collection
  53.323 +     * (optional operation).  The behavior of this operation is undefined if
  53.324 +     * the specified collection is modified while the operation is in progress.
  53.325 +     * (This implies that the behavior of this call is undefined if the
  53.326 +     * specified collection is this collection, and this collection is
  53.327 +     * nonempty.)
  53.328 +     *
  53.329 +     * @param c collection containing elements to be added to this collection
  53.330 +     * @return <tt>true</tt> if this collection changed as a result of the call
  53.331 +     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
  53.332 +     *         is not supported by this collection
  53.333 +     * @throws ClassCastException if the class of an element of the specified
  53.334 +     *         collection prevents it from being added to this collection
  53.335 +     * @throws NullPointerException if the specified collection contains a
  53.336 +     *         null element and this collection does not permit null elements,
  53.337 +     *         or if the specified collection is null
  53.338 +     * @throws IllegalArgumentException if some property of an element of the
  53.339 +     *         specified collection prevents it from being added to this
  53.340 +     *         collection
  53.341 +     * @throws IllegalStateException if not all the elements can be added at
  53.342 +     *         this time due to insertion restrictions
  53.343 +     * @see #add(Object)
  53.344 +     */
  53.345 +    boolean addAll(Collection<? extends E> c);
  53.346 +
  53.347 +    /**
  53.348 +     * Removes all of this collection's elements that are also contained in the
  53.349 +     * specified collection (optional operation).  After this call returns,
  53.350 +     * this collection will contain no elements in common with the specified
  53.351 +     * collection.
  53.352 +     *
  53.353 +     * @param c collection containing elements to be removed from this collection
  53.354 +     * @return <tt>true</tt> if this collection changed as a result of the
  53.355 +     *         call
  53.356 +     * @throws UnsupportedOperationException if the <tt>removeAll</tt> method
  53.357 +     *         is not supported by this collection
  53.358 +     * @throws ClassCastException if the types of one or more elements
  53.359 +     *         in this collection are incompatible with the specified
  53.360 +     *         collection
  53.361 +     *         (<a href="#optional-restrictions">optional</a>)
  53.362 +     * @throws NullPointerException if this collection contains one or more
  53.363 +     *         null elements and the specified collection does not support
  53.364 +     *         null elements
  53.365 +     *         (<a href="#optional-restrictions">optional</a>),
  53.366 +     *         or if the specified collection is null
  53.367 +     * @see #remove(Object)
  53.368 +     * @see #contains(Object)
  53.369 +     */
  53.370 +    boolean removeAll(Collection<?> c);
  53.371 +
  53.372 +    /**
  53.373 +     * Retains only the elements in this collection that are contained in the
  53.374 +     * specified collection (optional operation).  In other words, removes from
  53.375 +     * this collection all of its elements that are not contained in the
  53.376 +     * specified collection.
  53.377 +     *
  53.378 +     * @param c collection containing elements to be retained in this collection
  53.379 +     * @return <tt>true</tt> if this collection changed as a result of the call
  53.380 +     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
  53.381 +     *         is not supported by this collection
  53.382 +     * @throws ClassCastException if the types of one or more elements
  53.383 +     *         in this collection are incompatible with the specified
  53.384 +     *         collection
  53.385 +     *         (<a href="#optional-restrictions">optional</a>)
  53.386 +     * @throws NullPointerException if this collection contains one or more
  53.387 +     *         null elements and the specified collection does not permit null
  53.388 +     *         elements
  53.389 +     *         (<a href="#optional-restrictions">optional</a>),
  53.390 +     *         or if the specified collection is null
  53.391 +     * @see #remove(Object)
  53.392 +     * @see #contains(Object)
  53.393 +     */
  53.394 +    boolean retainAll(Collection<?> c);
  53.395 +
  53.396 +    /**
  53.397 +     * Removes all of the elements from this collection (optional operation).
  53.398 +     * The collection will be empty after this method returns.
  53.399 +     *
  53.400 +     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
  53.401 +     *         is not supported by this collection
  53.402 +     */
  53.403 +    void clear();
  53.404 +
  53.405 +
  53.406 +    // Comparison and hashing
  53.407 +
  53.408 +    /**
  53.409 +     * Compares the specified object with this collection for equality. <p>
  53.410 +     *
  53.411 +     * While the <tt>Collection</tt> interface adds no stipulations to the
  53.412 +     * general contract for the <tt>Object.equals</tt>, programmers who
  53.413 +     * implement the <tt>Collection</tt> interface "directly" (in other words,
  53.414 +     * create a class that is a <tt>Collection</tt> but is not a <tt>Set</tt>
  53.415 +     * or a <tt>List</tt>) must exercise care if they choose to override the
  53.416 +     * <tt>Object.equals</tt>.  It is not necessary to do so, and the simplest
  53.417 +     * course of action is to rely on <tt>Object</tt>'s implementation, but
  53.418 +     * the implementor may wish to implement a "value comparison" in place of
  53.419 +     * the default "reference comparison."  (The <tt>List</tt> and
  53.420 +     * <tt>Set</tt> interfaces mandate such value comparisons.)<p>
  53.421 +     *
  53.422 +     * The general contract for the <tt>Object.equals</tt> method states that
  53.423 +     * equals must be symmetric (in other words, <tt>a.equals(b)</tt> if and
  53.424 +     * only if <tt>b.equals(a)</tt>).  The contracts for <tt>List.equals</tt>
  53.425 +     * and <tt>Set.equals</tt> state that lists are only equal to other lists,
  53.426 +     * and sets to other sets.  Thus, a custom <tt>equals</tt> method for a
  53.427 +     * collection class that implements neither the <tt>List</tt> nor
  53.428 +     * <tt>Set</tt> interface must return <tt>false</tt> when this collection
  53.429 +     * is compared to any list or set.  (By the same logic, it is not possible
  53.430 +     * to write a class that correctly implements both the <tt>Set</tt> and
  53.431 +     * <tt>List</tt> interfaces.)
  53.432 +     *
  53.433 +     * @param o object to be compared for equality with this collection
  53.434 +     * @return <tt>true</tt> if the specified object is equal to this
  53.435 +     * collection
  53.436 +     *
  53.437 +     * @see Object#equals(Object)
  53.438 +     * @see Set#equals(Object)
  53.439 +     * @see List#equals(Object)
  53.440 +     */
  53.441 +    boolean equals(Object o);
  53.442 +
  53.443 +    /**
  53.444 +     * Returns the hash code value for this collection.  While the
  53.445 +     * <tt>Collection</tt> interface adds no stipulations to the general
  53.446 +     * contract for the <tt>Object.hashCode</tt> method, programmers should
  53.447 +     * take note that any class that overrides the <tt>Object.equals</tt>
  53.448 +     * method must also override the <tt>Object.hashCode</tt> method in order
  53.449 +     * to satisfy the general contract for the <tt>Object.hashCode</tt> method.
  53.450 +     * In particular, <tt>c1.equals(c2)</tt> implies that
  53.451 +     * <tt>c1.hashCode()==c2.hashCode()</tt>.
  53.452 +     *
  53.453 +     * @return the hash code value for this collection
  53.454 +     *
  53.455 +     * @see Object#hashCode()
  53.456 +     * @see Object#equals(Object)
  53.457 +     */
  53.458 +    int hashCode();
  53.459 +}
    54.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.2 +++ b/emul/compact/src/main/java/java/util/Collections.java	Sun Feb 03 07:48:42 2013 +0100
    54.3 @@ -0,0 +1,3953 @@
    54.4 +/*
    54.5 + * Copyright (c) 1997, 2011, 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.util;
   54.30 +import java.io.Serializable;
   54.31 +import java.io.IOException;
   54.32 +import java.lang.reflect.Array;
   54.33 +
   54.34 +/**
   54.35 + * This class consists exclusively of static methods that operate on or return
   54.36 + * collections.  It contains polymorphic algorithms that operate on
   54.37 + * collections, "wrappers", which return a new collection backed by a
   54.38 + * specified collection, and a few other odds and ends.
   54.39 + *
   54.40 + * <p>The methods of this class all throw a <tt>NullPointerException</tt>
   54.41 + * if the collections or class objects provided to them are null.
   54.42 + *
   54.43 + * <p>The documentation for the polymorphic algorithms contained in this class
   54.44 + * generally includes a brief description of the <i>implementation</i>.  Such
   54.45 + * descriptions should be regarded as <i>implementation notes</i>, rather than
   54.46 + * parts of the <i>specification</i>.  Implementors should feel free to
   54.47 + * substitute other algorithms, so long as the specification itself is adhered
   54.48 + * to.  (For example, the algorithm used by <tt>sort</tt> does not have to be
   54.49 + * a mergesort, but it does have to be <i>stable</i>.)
   54.50 + *
   54.51 + * <p>The "destructive" algorithms contained in this class, that is, the
   54.52 + * algorithms that modify the collection on which they operate, are specified
   54.53 + * to throw <tt>UnsupportedOperationException</tt> if the collection does not
   54.54 + * support the appropriate mutation primitive(s), such as the <tt>set</tt>
   54.55 + * method.  These algorithms may, but are not required to, throw this
   54.56 + * exception if an invocation would have no effect on the collection.  For
   54.57 + * example, invoking the <tt>sort</tt> method on an unmodifiable list that is
   54.58 + * already sorted may or may not throw <tt>UnsupportedOperationException</tt>.
   54.59 + *
   54.60 + * <p>This class is a member of the
   54.61 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   54.62 + * Java Collections Framework</a>.
   54.63 + *
   54.64 + * @author  Josh Bloch
   54.65 + * @author  Neal Gafter
   54.66 + * @see     Collection
   54.67 + * @see     Set
   54.68 + * @see     List
   54.69 + * @see     Map
   54.70 + * @since   1.2
   54.71 + */
   54.72 +
   54.73 +public class Collections {
   54.74 +    // Suppresses default constructor, ensuring non-instantiability.
   54.75 +    private Collections() {
   54.76 +    }
   54.77 +
   54.78 +    // Algorithms
   54.79 +
   54.80 +    /*
   54.81 +     * Tuning parameters for algorithms - Many of the List algorithms have
   54.82 +     * two implementations, one of which is appropriate for RandomAccess
   54.83 +     * lists, the other for "sequential."  Often, the random access variant
   54.84 +     * yields better performance on small sequential access lists.  The
   54.85 +     * tuning parameters below determine the cutoff point for what constitutes
   54.86 +     * a "small" sequential access list for each algorithm.  The values below
   54.87 +     * were empirically determined to work well for LinkedList. Hopefully
   54.88 +     * they should be reasonable for other sequential access List
   54.89 +     * implementations.  Those doing performance work on this code would
   54.90 +     * do well to validate the values of these parameters from time to time.
   54.91 +     * (The first word of each tuning parameter name is the algorithm to which
   54.92 +     * it applies.)
   54.93 +     */
   54.94 +    private static final int BINARYSEARCH_THRESHOLD   = 5000;
   54.95 +    private static final int REVERSE_THRESHOLD        =   18;
   54.96 +    private static final int SHUFFLE_THRESHOLD        =    5;
   54.97 +    private static final int FILL_THRESHOLD           =   25;
   54.98 +    private static final int ROTATE_THRESHOLD         =  100;
   54.99 +    private static final int COPY_THRESHOLD           =   10;
  54.100 +    private static final int REPLACEALL_THRESHOLD     =   11;
  54.101 +    private static final int INDEXOFSUBLIST_THRESHOLD =   35;
  54.102 +
  54.103 +    /**
  54.104 +     * Sorts the specified list into ascending order, according to the
  54.105 +     * {@linkplain Comparable natural ordering} of its elements.
  54.106 +     * All elements in the list must implement the {@link Comparable}
  54.107 +     * interface.  Furthermore, all elements in the list must be
  54.108 +     * <i>mutually comparable</i> (that is, {@code e1.compareTo(e2)}
  54.109 +     * must not throw a {@code ClassCastException} for any elements
  54.110 +     * {@code e1} and {@code e2} in the list).
  54.111 +     *
  54.112 +     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
  54.113 +     * not be reordered as a result of the sort.
  54.114 +     *
  54.115 +     * <p>The specified list must be modifiable, but need not be resizable.
  54.116 +     *
  54.117 +     * <p>Implementation note: This implementation is a stable, adaptive,
  54.118 +     * iterative mergesort that requires far fewer than n lg(n) comparisons
  54.119 +     * when the input array is partially sorted, while offering the
  54.120 +     * performance of a traditional mergesort when the input array is
  54.121 +     * randomly ordered.  If the input array is nearly sorted, the
  54.122 +     * implementation requires approximately n comparisons.  Temporary
  54.123 +     * storage requirements vary from a small constant for nearly sorted
  54.124 +     * input arrays to n/2 object references for randomly ordered input
  54.125 +     * arrays.
  54.126 +     *
  54.127 +     * <p>The implementation takes equal advantage of ascending and
  54.128 +     * descending order in its input array, and can take advantage of
  54.129 +     * ascending and descending order in different parts of the same
  54.130 +     * input array.  It is well-suited to merging two or more sorted arrays:
  54.131 +     * simply concatenate the arrays and sort the resulting array.
  54.132 +     *
  54.133 +     * <p>The implementation was adapted from Tim Peters's list sort for Python
  54.134 +     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
  54.135 +     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
  54.136 +     * Sorting and Information Theoretic Complexity", in Proceedings of the
  54.137 +     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
  54.138 +     * January 1993.
  54.139 +     *
  54.140 +     * <p>This implementation dumps the specified list into an array, sorts
  54.141 +     * the array, and iterates over the list resetting each element
  54.142 +     * from the corresponding position in the array.  This avoids the
  54.143 +     * n<sup>2</sup> log(n) performance that would result from attempting
  54.144 +     * to sort a linked list in place.
  54.145 +     *
  54.146 +     * @param  list the list to be sorted.
  54.147 +     * @throws ClassCastException if the list contains elements that are not
  54.148 +     *         <i>mutually comparable</i> (for example, strings and integers).
  54.149 +     * @throws UnsupportedOperationException if the specified list's
  54.150 +     *         list-iterator does not support the {@code set} operation.
  54.151 +     * @throws IllegalArgumentException (optional) if the implementation
  54.152 +     *         detects that the natural ordering of the list elements is
  54.153 +     *         found to violate the {@link Comparable} contract
  54.154 +     */
  54.155 +    public static <T extends Comparable<? super T>> void sort(List<T> list) {
  54.156 +        Object[] a = list.toArray();
  54.157 +        Arrays.sort(a);
  54.158 +        ListIterator<T> i = list.listIterator();
  54.159 +        for (int j=0; j<a.length; j++) {
  54.160 +            i.next();
  54.161 +            i.set((T)a[j]);
  54.162 +        }
  54.163 +    }
  54.164 +
  54.165 +    /**
  54.166 +     * Sorts the specified list according to the order induced by the
  54.167 +     * specified comparator.  All elements in the list must be <i>mutually
  54.168 +     * comparable</i> using the specified comparator (that is,
  54.169 +     * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException}
  54.170 +     * for any elements {@code e1} and {@code e2} in the list).
  54.171 +     *
  54.172 +     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
  54.173 +     * not be reordered as a result of the sort.
  54.174 +     *
  54.175 +     * <p>The specified list must be modifiable, but need not be resizable.
  54.176 +     *
  54.177 +     * <p>Implementation note: This implementation is a stable, adaptive,
  54.178 +     * iterative mergesort that requires far fewer than n lg(n) comparisons
  54.179 +     * when the input array is partially sorted, while offering the
  54.180 +     * performance of a traditional mergesort when the input array is
  54.181 +     * randomly ordered.  If the input array is nearly sorted, the
  54.182 +     * implementation requires approximately n comparisons.  Temporary
  54.183 +     * storage requirements vary from a small constant for nearly sorted
  54.184 +     * input arrays to n/2 object references for randomly ordered input
  54.185 +     * arrays.
  54.186 +     *
  54.187 +     * <p>The implementation takes equal advantage of ascending and
  54.188 +     * descending order in its input array, and can take advantage of
  54.189 +     * ascending and descending order in different parts of the same
  54.190 +     * input array.  It is well-suited to merging two or more sorted arrays:
  54.191 +     * simply concatenate the arrays and sort the resulting array.
  54.192 +     *
  54.193 +     * <p>The implementation was adapted from Tim Peters's list sort for Python
  54.194 +     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
  54.195 +     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
  54.196 +     * Sorting and Information Theoretic Complexity", in Proceedings of the
  54.197 +     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
  54.198 +     * January 1993.
  54.199 +     *
  54.200 +     * <p>This implementation dumps the specified list into an array, sorts
  54.201 +     * the array, and iterates over the list resetting each element
  54.202 +     * from the corresponding position in the array.  This avoids the
  54.203 +     * n<sup>2</sup> log(n) performance that would result from attempting
  54.204 +     * to sort a linked list in place.
  54.205 +     *
  54.206 +     * @param  list the list to be sorted.
  54.207 +     * @param  c the comparator to determine the order of the list.  A
  54.208 +     *        {@code null} value indicates that the elements' <i>natural
  54.209 +     *        ordering</i> should be used.
  54.210 +     * @throws ClassCastException if the list contains elements that are not
  54.211 +     *         <i>mutually comparable</i> using the specified comparator.
  54.212 +     * @throws UnsupportedOperationException if the specified list's
  54.213 +     *         list-iterator does not support the {@code set} operation.
  54.214 +     * @throws IllegalArgumentException (optional) if the comparator is
  54.215 +     *         found to violate the {@link Comparator} contract
  54.216 +     */
  54.217 +    public static <T> void sort(List<T> list, Comparator<? super T> c) {
  54.218 +        Object[] a = list.toArray();
  54.219 +        Arrays.sort(a, (Comparator)c);
  54.220 +        ListIterator i = list.listIterator();
  54.221 +        for (int j=0; j<a.length; j++) {
  54.222 +            i.next();
  54.223 +            i.set(a[j]);
  54.224 +        }
  54.225 +    }
  54.226 +
  54.227 +
  54.228 +    /**
  54.229 +     * Searches the specified list for the specified object using the binary
  54.230 +     * search algorithm.  The list must be sorted into ascending order
  54.231 +     * according to the {@linkplain Comparable natural ordering} of its
  54.232 +     * elements (as by the {@link #sort(List)} method) prior to making this
  54.233 +     * call.  If it is not sorted, the results are undefined.  If the list
  54.234 +     * contains multiple elements equal to the specified object, there is no
  54.235 +     * guarantee which one will be found.
  54.236 +     *
  54.237 +     * <p>This method runs in log(n) time for a "random access" list (which
  54.238 +     * provides near-constant-time positional access).  If the specified list
  54.239 +     * does not implement the {@link RandomAccess} interface and is large,
  54.240 +     * this method will do an iterator-based binary search that performs
  54.241 +     * O(n) link traversals and O(log n) element comparisons.
  54.242 +     *
  54.243 +     * @param  list the list to be searched.
  54.244 +     * @param  key the key to be searched for.
  54.245 +     * @return the index of the search key, if it is contained in the list;
  54.246 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  54.247 +     *         <i>insertion point</i> is defined as the point at which the
  54.248 +     *         key would be inserted into the list: the index of the first
  54.249 +     *         element greater than the key, or <tt>list.size()</tt> if all
  54.250 +     *         elements in the list are less than the specified key.  Note
  54.251 +     *         that this guarantees that the return value will be &gt;= 0 if
  54.252 +     *         and only if the key is found.
  54.253 +     * @throws ClassCastException if the list contains elements that are not
  54.254 +     *         <i>mutually comparable</i> (for example, strings and
  54.255 +     *         integers), or the search key is not mutually comparable
  54.256 +     *         with the elements of the list.
  54.257 +     */
  54.258 +    public static <T>
  54.259 +    int binarySearch(List<? extends Comparable<? super T>> list, T key) {
  54.260 +        if (list instanceof RandomAccess || list.size()<BINARYSEARCH_THRESHOLD)
  54.261 +            return Collections.indexedBinarySearch(list, key);
  54.262 +        else
  54.263 +            return Collections.iteratorBinarySearch(list, key);
  54.264 +    }
  54.265 +
  54.266 +    private static <T>
  54.267 +    int indexedBinarySearch(List<? extends Comparable<? super T>> list, T key)
  54.268 +    {
  54.269 +        int low = 0;
  54.270 +        int high = list.size()-1;
  54.271 +
  54.272 +        while (low <= high) {
  54.273 +            int mid = (low + high) >>> 1;
  54.274 +            Comparable<? super T> midVal = list.get(mid);
  54.275 +            int cmp = midVal.compareTo(key);
  54.276 +
  54.277 +            if (cmp < 0)
  54.278 +                low = mid + 1;
  54.279 +            else if (cmp > 0)
  54.280 +                high = mid - 1;
  54.281 +            else
  54.282 +                return mid; // key found
  54.283 +        }
  54.284 +        return -(low + 1);  // key not found
  54.285 +    }
  54.286 +
  54.287 +    private static <T>
  54.288 +    int iteratorBinarySearch(List<? extends Comparable<? super T>> list, T key)
  54.289 +    {
  54.290 +        int low = 0;
  54.291 +        int high = list.size()-1;
  54.292 +        ListIterator<? extends Comparable<? super T>> i = list.listIterator();
  54.293 +
  54.294 +        while (low <= high) {
  54.295 +            int mid = (low + high) >>> 1;
  54.296 +            Comparable<? super T> midVal = get(i, mid);
  54.297 +            int cmp = midVal.compareTo(key);
  54.298 +
  54.299 +            if (cmp < 0)
  54.300 +                low = mid + 1;
  54.301 +            else if (cmp > 0)
  54.302 +                high = mid - 1;
  54.303 +            else
  54.304 +                return mid; // key found
  54.305 +        }
  54.306 +        return -(low + 1);  // key not found
  54.307 +    }
  54.308 +
  54.309 +    /**
  54.310 +     * Gets the ith element from the given list by repositioning the specified
  54.311 +     * list listIterator.
  54.312 +     */
  54.313 +    private static <T> T get(ListIterator<? extends T> i, int index) {
  54.314 +        T obj = null;
  54.315 +        int pos = i.nextIndex();
  54.316 +        if (pos <= index) {
  54.317 +            do {
  54.318 +                obj = i.next();
  54.319 +            } while (pos++ < index);
  54.320 +        } else {
  54.321 +            do {
  54.322 +                obj = i.previous();
  54.323 +            } while (--pos > index);
  54.324 +        }
  54.325 +        return obj;
  54.326 +    }
  54.327 +
  54.328 +    /**
  54.329 +     * Searches the specified list for the specified object using the binary
  54.330 +     * search algorithm.  The list must be sorted into ascending order
  54.331 +     * according to the specified comparator (as by the
  54.332 +     * {@link #sort(List, Comparator) sort(List, Comparator)}
  54.333 +     * method), prior to making this call.  If it is
  54.334 +     * not sorted, the results are undefined.  If the list contains multiple
  54.335 +     * elements equal to the specified object, there is no guarantee which one
  54.336 +     * will be found.
  54.337 +     *
  54.338 +     * <p>This method runs in log(n) time for a "random access" list (which
  54.339 +     * provides near-constant-time positional access).  If the specified list
  54.340 +     * does not implement the {@link RandomAccess} interface and is large,
  54.341 +     * this method will do an iterator-based binary search that performs
  54.342 +     * O(n) link traversals and O(log n) element comparisons.
  54.343 +     *
  54.344 +     * @param  list the list to be searched.
  54.345 +     * @param  key the key to be searched for.
  54.346 +     * @param  c the comparator by which the list is ordered.
  54.347 +     *         A <tt>null</tt> value indicates that the elements'
  54.348 +     *         {@linkplain Comparable natural ordering} should be used.
  54.349 +     * @return the index of the search key, if it is contained in the list;
  54.350 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  54.351 +     *         <i>insertion point</i> is defined as the point at which the
  54.352 +     *         key would be inserted into the list: the index of the first
  54.353 +     *         element greater than the key, or <tt>list.size()</tt> if all
  54.354 +     *         elements in the list are less than the specified key.  Note
  54.355 +     *         that this guarantees that the return value will be &gt;= 0 if
  54.356 +     *         and only if the key is found.
  54.357 +     * @throws ClassCastException if the list contains elements that are not
  54.358 +     *         <i>mutually comparable</i> using the specified comparator,
  54.359 +     *         or the search key is not mutually comparable with the
  54.360 +     *         elements of the list using this comparator.
  54.361 +     */
  54.362 +    public static <T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c) {
  54.363 +        if (c==null)
  54.364 +            return binarySearch((List) list, key);
  54.365 +
  54.366 +        if (list instanceof RandomAccess || list.size()<BINARYSEARCH_THRESHOLD)
  54.367 +            return Collections.indexedBinarySearch(list, key, c);
  54.368 +        else
  54.369 +            return Collections.iteratorBinarySearch(list, key, c);
  54.370 +    }
  54.371 +
  54.372 +    private static <T> int indexedBinarySearch(List<? extends T> l, T key, Comparator<? super T> c) {
  54.373 +        int low = 0;
  54.374 +        int high = l.size()-1;
  54.375 +
  54.376 +        while (low <= high) {
  54.377 +            int mid = (low + high) >>> 1;
  54.378 +            T midVal = l.get(mid);
  54.379 +            int cmp = c.compare(midVal, key);
  54.380 +
  54.381 +            if (cmp < 0)
  54.382 +                low = mid + 1;
  54.383 +            else if (cmp > 0)
  54.384 +                high = mid - 1;
  54.385 +            else
  54.386 +                return mid; // key found
  54.387 +        }
  54.388 +        return -(low + 1);  // key not found
  54.389 +    }
  54.390 +
  54.391 +    private static <T> int iteratorBinarySearch(List<? extends T> l, T key, Comparator<? super T> c) {
  54.392 +        int low = 0;
  54.393 +        int high = l.size()-1;
  54.394 +        ListIterator<? extends T> i = l.listIterator();
  54.395 +
  54.396 +        while (low <= high) {
  54.397 +            int mid = (low + high) >>> 1;
  54.398 +            T midVal = get(i, mid);
  54.399 +            int cmp = c.compare(midVal, key);
  54.400 +
  54.401 +            if (cmp < 0)
  54.402 +                low = mid + 1;
  54.403 +            else if (cmp > 0)
  54.404 +                high = mid - 1;
  54.405 +            else
  54.406 +                return mid; // key found
  54.407 +        }
  54.408 +        return -(low + 1);  // key not found
  54.409 +    }
  54.410 +
  54.411 +    private interface SelfComparable extends Comparable<SelfComparable> {}
  54.412 +
  54.413 +
  54.414 +    /**
  54.415 +     * Reverses the order of the elements in the specified list.<p>
  54.416 +     *
  54.417 +     * This method runs in linear time.
  54.418 +     *
  54.419 +     * @param  list the list whose elements are to be reversed.
  54.420 +     * @throws UnsupportedOperationException if the specified list or
  54.421 +     *         its list-iterator does not support the <tt>set</tt> operation.
  54.422 +     */
  54.423 +    public static void reverse(List<?> list) {
  54.424 +        int size = list.size();
  54.425 +        if (size < REVERSE_THRESHOLD || list instanceof RandomAccess) {
  54.426 +            for (int i=0, mid=size>>1, j=size-1; i<mid; i++, j--)
  54.427 +                swap(list, i, j);
  54.428 +        } else {
  54.429 +            ListIterator fwd = list.listIterator();
  54.430 +            ListIterator rev = list.listIterator(size);
  54.431 +            for (int i=0, mid=list.size()>>1; i<mid; i++) {
  54.432 +                Object tmp = fwd.next();
  54.433 +                fwd.set(rev.previous());
  54.434 +                rev.set(tmp);
  54.435 +            }
  54.436 +        }
  54.437 +    }
  54.438 +
  54.439 +    /**
  54.440 +     * Randomly permutes the specified list using a default source of
  54.441 +     * randomness.  All permutations occur with approximately equal
  54.442 +     * likelihood.<p>
  54.443 +     *
  54.444 +     * The hedge "approximately" is used in the foregoing description because
  54.445 +     * default source of randomness is only approximately an unbiased source
  54.446 +     * of independently chosen bits. If it were a perfect source of randomly
  54.447 +     * chosen bits, then the algorithm would choose permutations with perfect
  54.448 +     * uniformity.<p>
  54.449 +     *
  54.450 +     * This implementation traverses the list backwards, from the last element
  54.451 +     * up to the second, repeatedly swapping a randomly selected element into
  54.452 +     * the "current position".  Elements are randomly selected from the
  54.453 +     * portion of the list that runs from the first element to the current
  54.454 +     * position, inclusive.<p>
  54.455 +     *
  54.456 +     * This method runs in linear time.  If the specified list does not
  54.457 +     * implement the {@link RandomAccess} interface and is large, this
  54.458 +     * implementation dumps the specified list into an array before shuffling
  54.459 +     * it, and dumps the shuffled array back into the list.  This avoids the
  54.460 +     * quadratic behavior that would result from shuffling a "sequential
  54.461 +     * access" list in place.
  54.462 +     *
  54.463 +     * @param  list the list to be shuffled.
  54.464 +     * @throws UnsupportedOperationException if the specified list or
  54.465 +     *         its list-iterator does not support the <tt>set</tt> operation.
  54.466 +     */
  54.467 +    public static void shuffle(List<?> list) {
  54.468 +        Random rnd = r;
  54.469 +        if (rnd == null)
  54.470 +            r = rnd = new Random();
  54.471 +        shuffle(list, rnd);
  54.472 +    }
  54.473 +    private static Random r;
  54.474 +
  54.475 +    /**
  54.476 +     * Randomly permute the specified list using the specified source of
  54.477 +     * randomness.  All permutations occur with equal likelihood
  54.478 +     * assuming that the source of randomness is fair.<p>
  54.479 +     *
  54.480 +     * This implementation traverses the list backwards, from the last element
  54.481 +     * up to the second, repeatedly swapping a randomly selected element into
  54.482 +     * the "current position".  Elements are randomly selected from the
  54.483 +     * portion of the list that runs from the first element to the current
  54.484 +     * position, inclusive.<p>
  54.485 +     *
  54.486 +     * This method runs in linear time.  If the specified list does not
  54.487 +     * implement the {@link RandomAccess} interface and is large, this
  54.488 +     * implementation dumps the specified list into an array before shuffling
  54.489 +     * it, and dumps the shuffled array back into the list.  This avoids the
  54.490 +     * quadratic behavior that would result from shuffling a "sequential
  54.491 +     * access" list in place.
  54.492 +     *
  54.493 +     * @param  list the list to be shuffled.
  54.494 +     * @param  rnd the source of randomness to use to shuffle the list.
  54.495 +     * @throws UnsupportedOperationException if the specified list or its
  54.496 +     *         list-iterator does not support the <tt>set</tt> operation.
  54.497 +     */
  54.498 +    public static void shuffle(List<?> list, Random rnd) {
  54.499 +        int size = list.size();
  54.500 +        if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) {
  54.501 +            for (int i=size; i>1; i--)
  54.502 +                swap(list, i-1, rnd.nextInt(i));
  54.503 +        } else {
  54.504 +            Object arr[] = list.toArray();
  54.505 +
  54.506 +            // Shuffle array
  54.507 +            for (int i=size; i>1; i--)
  54.508 +                swap(arr, i-1, rnd.nextInt(i));
  54.509 +
  54.510 +            // Dump array back into list
  54.511 +            ListIterator it = list.listIterator();
  54.512 +            for (int i=0; i<arr.length; i++) {
  54.513 +                it.next();
  54.514 +                it.set(arr[i]);
  54.515 +            }
  54.516 +        }
  54.517 +    }
  54.518 +
  54.519 +    /**
  54.520 +     * Swaps the elements at the specified positions in the specified list.
  54.521 +     * (If the specified positions are equal, invoking this method leaves
  54.522 +     * the list unchanged.)
  54.523 +     *
  54.524 +     * @param list The list in which to swap elements.
  54.525 +     * @param i the index of one element to be swapped.
  54.526 +     * @param j the index of the other element to be swapped.
  54.527 +     * @throws IndexOutOfBoundsException if either <tt>i</tt> or <tt>j</tt>
  54.528 +     *         is out of range (i &lt; 0 || i &gt;= list.size()
  54.529 +     *         || j &lt; 0 || j &gt;= list.size()).
  54.530 +     * @since 1.4
  54.531 +     */
  54.532 +    public static void swap(List<?> list, int i, int j) {
  54.533 +        final List l = list;
  54.534 +        l.set(i, l.set(j, l.get(i)));
  54.535 +    }
  54.536 +
  54.537 +    /**
  54.538 +     * Swaps the two specified elements in the specified array.
  54.539 +     */
  54.540 +    private static void swap(Object[] arr, int i, int j) {
  54.541 +        Object tmp = arr[i];
  54.542 +        arr[i] = arr[j];
  54.543 +        arr[j] = tmp;
  54.544 +    }
  54.545 +
  54.546 +    /**
  54.547 +     * Replaces all of the elements of the specified list with the specified
  54.548 +     * element. <p>
  54.549 +     *
  54.550 +     * This method runs in linear time.
  54.551 +     *
  54.552 +     * @param  list the list to be filled with the specified element.
  54.553 +     * @param  obj The element with which to fill the specified list.
  54.554 +     * @throws UnsupportedOperationException if the specified list or its
  54.555 +     *         list-iterator does not support the <tt>set</tt> operation.
  54.556 +     */
  54.557 +    public static <T> void fill(List<? super T> list, T obj) {
  54.558 +        int size = list.size();
  54.559 +
  54.560 +        if (size < FILL_THRESHOLD || list instanceof RandomAccess) {
  54.561 +            for (int i=0; i<size; i++)
  54.562 +                list.set(i, obj);
  54.563 +        } else {
  54.564 +            ListIterator<? super T> itr = list.listIterator();
  54.565 +            for (int i=0; i<size; i++) {
  54.566 +                itr.next();
  54.567 +                itr.set(obj);
  54.568 +            }
  54.569 +        }
  54.570 +    }
  54.571 +
  54.572 +    /**
  54.573 +     * Copies all of the elements from one list into another.  After the
  54.574 +     * operation, the index of each copied element in the destination list
  54.575 +     * will be identical to its index in the source list.  The destination
  54.576 +     * list must be at least as long as the source list.  If it is longer, the
  54.577 +     * remaining elements in the destination list are unaffected. <p>
  54.578 +     *
  54.579 +     * This method runs in linear time.
  54.580 +     *
  54.581 +     * @param  dest The destination list.
  54.582 +     * @param  src The source list.
  54.583 +     * @throws IndexOutOfBoundsException if the destination list is too small
  54.584 +     *         to contain the entire source List.
  54.585 +     * @throws UnsupportedOperationException if the destination list's
  54.586 +     *         list-iterator does not support the <tt>set</tt> operation.
  54.587 +     */
  54.588 +    public static <T> void copy(List<? super T> dest, List<? extends T> src) {
  54.589 +        int srcSize = src.size();
  54.590 +        if (srcSize > dest.size())
  54.591 +            throw new IndexOutOfBoundsException("Source does not fit in dest");
  54.592 +
  54.593 +        if (srcSize < COPY_THRESHOLD ||
  54.594 +            (src instanceof RandomAccess && dest instanceof RandomAccess)) {
  54.595 +            for (int i=0; i<srcSize; i++)
  54.596 +                dest.set(i, src.get(i));
  54.597 +        } else {
  54.598 +            ListIterator<? super T> di=dest.listIterator();
  54.599 +            ListIterator<? extends T> si=src.listIterator();
  54.600 +            for (int i=0; i<srcSize; i++) {
  54.601 +                di.next();
  54.602 +                di.set(si.next());
  54.603 +            }
  54.604 +        }
  54.605 +    }
  54.606 +
  54.607 +    /**
  54.608 +     * Returns the minimum element of the given collection, according to the
  54.609 +     * <i>natural ordering</i> of its elements.  All elements in the
  54.610 +     * collection must implement the <tt>Comparable</tt> interface.
  54.611 +     * Furthermore, all elements in the collection must be <i>mutually
  54.612 +     * comparable</i> (that is, <tt>e1.compareTo(e2)</tt> must not throw a
  54.613 +     * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
  54.614 +     * <tt>e2</tt> in the collection).<p>
  54.615 +     *
  54.616 +     * This method iterates over the entire collection, hence it requires
  54.617 +     * time proportional to the size of the collection.
  54.618 +     *
  54.619 +     * @param  coll the collection whose minimum element is to be determined.
  54.620 +     * @return the minimum element of the given collection, according
  54.621 +     *         to the <i>natural ordering</i> of its elements.
  54.622 +     * @throws ClassCastException if the collection contains elements that are
  54.623 +     *         not <i>mutually comparable</i> (for example, strings and
  54.624 +     *         integers).
  54.625 +     * @throws NoSuchElementException if the collection is empty.
  54.626 +     * @see Comparable
  54.627 +     */
  54.628 +    public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll) {
  54.629 +        Iterator<? extends T> i = coll.iterator();
  54.630 +        T candidate = i.next();
  54.631 +
  54.632 +        while (i.hasNext()) {
  54.633 +            T next = i.next();
  54.634 +            if (next.compareTo(candidate) < 0)
  54.635 +                candidate = next;
  54.636 +        }
  54.637 +        return candidate;
  54.638 +    }
  54.639 +
  54.640 +    /**
  54.641 +     * Returns the minimum element of the given collection, according to the
  54.642 +     * order induced by the specified comparator.  All elements in the
  54.643 +     * collection must be <i>mutually comparable</i> by the specified
  54.644 +     * comparator (that is, <tt>comp.compare(e1, e2)</tt> must not throw a
  54.645 +     * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
  54.646 +     * <tt>e2</tt> in the collection).<p>
  54.647 +     *
  54.648 +     * This method iterates over the entire collection, hence it requires
  54.649 +     * time proportional to the size of the collection.
  54.650 +     *
  54.651 +     * @param  coll the collection whose minimum element is to be determined.
  54.652 +     * @param  comp the comparator with which to determine the minimum element.
  54.653 +     *         A <tt>null</tt> value indicates that the elements' <i>natural
  54.654 +     *         ordering</i> should be used.
  54.655 +     * @return the minimum element of the given collection, according
  54.656 +     *         to the specified comparator.
  54.657 +     * @throws ClassCastException if the collection contains elements that are
  54.658 +     *         not <i>mutually comparable</i> using the specified comparator.
  54.659 +     * @throws NoSuchElementException if the collection is empty.
  54.660 +     * @see Comparable
  54.661 +     */
  54.662 +    public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) {
  54.663 +        if (comp==null)
  54.664 +            return (T)min((Collection<SelfComparable>) (Collection) coll);
  54.665 +
  54.666 +        Iterator<? extends T> i = coll.iterator();
  54.667 +        T candidate = i.next();
  54.668 +
  54.669 +        while (i.hasNext()) {
  54.670 +            T next = i.next();
  54.671 +            if (comp.compare(next, candidate) < 0)
  54.672 +                candidate = next;
  54.673 +        }
  54.674 +        return candidate;
  54.675 +    }
  54.676 +
  54.677 +    /**
  54.678 +     * Returns the maximum element of the given collection, according to the
  54.679 +     * <i>natural ordering</i> of its elements.  All elements in the
  54.680 +     * collection must implement the <tt>Comparable</tt> interface.
  54.681 +     * Furthermore, all elements in the collection must be <i>mutually
  54.682 +     * comparable</i> (that is, <tt>e1.compareTo(e2)</tt> must not throw a
  54.683 +     * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
  54.684 +     * <tt>e2</tt> in the collection).<p>
  54.685 +     *
  54.686 +     * This method iterates over the entire collection, hence it requires
  54.687 +     * time proportional to the size of the collection.
  54.688 +     *
  54.689 +     * @param  coll the collection whose maximum element is to be determined.
  54.690 +     * @return the maximum element of the given collection, according
  54.691 +     *         to the <i>natural ordering</i> of its elements.
  54.692 +     * @throws ClassCastException if the collection contains elements that are
  54.693 +     *         not <i>mutually comparable</i> (for example, strings and
  54.694 +     *         integers).
  54.695 +     * @throws NoSuchElementException if the collection is empty.
  54.696 +     * @see Comparable
  54.697 +     */
  54.698 +    public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) {
  54.699 +        Iterator<? extends T> i = coll.iterator();
  54.700 +        T candidate = i.next();
  54.701 +
  54.702 +        while (i.hasNext()) {
  54.703 +            T next = i.next();
  54.704 +            if (next.compareTo(candidate) > 0)
  54.705 +                candidate = next;
  54.706 +        }
  54.707 +        return candidate;
  54.708 +    }
  54.709 +
  54.710 +    /**
  54.711 +     * Returns the maximum element of the given collection, according to the
  54.712 +     * order induced by the specified comparator.  All elements in the
  54.713 +     * collection must be <i>mutually comparable</i> by the specified
  54.714 +     * comparator (that is, <tt>comp.compare(e1, e2)</tt> must not throw a
  54.715 +     * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
  54.716 +     * <tt>e2</tt> in the collection).<p>
  54.717 +     *
  54.718 +     * This method iterates over the entire collection, hence it requires
  54.719 +     * time proportional to the size of the collection.
  54.720 +     *
  54.721 +     * @param  coll the collection whose maximum element is to be determined.
  54.722 +     * @param  comp the comparator with which to determine the maximum element.
  54.723 +     *         A <tt>null</tt> value indicates that the elements' <i>natural
  54.724 +     *        ordering</i> should be used.
  54.725 +     * @return the maximum element of the given collection, according
  54.726 +     *         to the specified comparator.
  54.727 +     * @throws ClassCastException if the collection contains elements that are
  54.728 +     *         not <i>mutually comparable</i> using the specified comparator.
  54.729 +     * @throws NoSuchElementException if the collection is empty.
  54.730 +     * @see Comparable
  54.731 +     */
  54.732 +    public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp) {
  54.733 +        if (comp==null)
  54.734 +            return (T)max((Collection<SelfComparable>) (Collection) coll);
  54.735 +
  54.736 +        Iterator<? extends T> i = coll.iterator();
  54.737 +        T candidate = i.next();
  54.738 +
  54.739 +        while (i.hasNext()) {
  54.740 +            T next = i.next();
  54.741 +            if (comp.compare(next, candidate) > 0)
  54.742 +                candidate = next;
  54.743 +        }
  54.744 +        return candidate;
  54.745 +    }
  54.746 +
  54.747 +    /**
  54.748 +     * Rotates the elements in the specified list by the specified distance.
  54.749 +     * After calling this method, the element at index <tt>i</tt> will be
  54.750 +     * the element previously at index <tt>(i - distance)</tt> mod
  54.751 +     * <tt>list.size()</tt>, for all values of <tt>i</tt> between <tt>0</tt>
  54.752 +     * and <tt>list.size()-1</tt>, inclusive.  (This method has no effect on
  54.753 +     * the size of the list.)
  54.754 +     *
  54.755 +     * <p>For example, suppose <tt>list</tt> comprises<tt> [t, a, n, k, s]</tt>.
  54.756 +     * After invoking <tt>Collections.rotate(list, 1)</tt> (or
  54.757 +     * <tt>Collections.rotate(list, -4)</tt>), <tt>list</tt> will comprise
  54.758 +     * <tt>[s, t, a, n, k]</tt>.
  54.759 +     *
  54.760 +     * <p>Note that this method can usefully be applied to sublists to
  54.761 +     * move one or more elements within a list while preserving the
  54.762 +     * order of the remaining elements.  For example, the following idiom
  54.763 +     * moves the element at index <tt>j</tt> forward to position
  54.764 +     * <tt>k</tt> (which must be greater than or equal to <tt>j</tt>):
  54.765 +     * <pre>
  54.766 +     *     Collections.rotate(list.subList(j, k+1), -1);
  54.767 +     * </pre>
  54.768 +     * To make this concrete, suppose <tt>list</tt> comprises
  54.769 +     * <tt>[a, b, c, d, e]</tt>.  To move the element at index <tt>1</tt>
  54.770 +     * (<tt>b</tt>) forward two positions, perform the following invocation:
  54.771 +     * <pre>
  54.772 +     *     Collections.rotate(l.subList(1, 4), -1);
  54.773 +     * </pre>
  54.774 +     * The resulting list is <tt>[a, c, d, b, e]</tt>.
  54.775 +     *
  54.776 +     * <p>To move more than one element forward, increase the absolute value
  54.777 +     * of the rotation distance.  To move elements backward, use a positive
  54.778 +     * shift distance.
  54.779 +     *
  54.780 +     * <p>If the specified list is small or implements the {@link
  54.781 +     * RandomAccess} interface, this implementation exchanges the first
  54.782 +     * element into the location it should go, and then repeatedly exchanges
  54.783 +     * the displaced element into the location it should go until a displaced
  54.784 +     * element is swapped into the first element.  If necessary, the process
  54.785 +     * is repeated on the second and successive elements, until the rotation
  54.786 +     * is complete.  If the specified list is large and doesn't implement the
  54.787 +     * <tt>RandomAccess</tt> interface, this implementation breaks the
  54.788 +     * list into two sublist views around index <tt>-distance mod size</tt>.
  54.789 +     * Then the {@link #reverse(List)} method is invoked on each sublist view,
  54.790 +     * and finally it is invoked on the entire list.  For a more complete
  54.791 +     * description of both algorithms, see Section 2.3 of Jon Bentley's
  54.792 +     * <i>Programming Pearls</i> (Addison-Wesley, 1986).
  54.793 +     *
  54.794 +     * @param list the list to be rotated.
  54.795 +     * @param distance the distance to rotate the list.  There are no
  54.796 +     *        constraints on this value; it may be zero, negative, or
  54.797 +     *        greater than <tt>list.size()</tt>.
  54.798 +     * @throws UnsupportedOperationException if the specified list or
  54.799 +     *         its list-iterator does not support the <tt>set</tt> operation.
  54.800 +     * @since 1.4
  54.801 +     */
  54.802 +    public static void rotate(List<?> list, int distance) {
  54.803 +        if (list instanceof RandomAccess || list.size() < ROTATE_THRESHOLD)
  54.804 +            rotate1(list, distance);
  54.805 +        else
  54.806 +            rotate2(list, distance);
  54.807 +    }
  54.808 +
  54.809 +    private static <T> void rotate1(List<T> list, int distance) {
  54.810 +        int size = list.size();
  54.811 +        if (size == 0)
  54.812 +            return;
  54.813 +        distance = distance % size;
  54.814 +        if (distance < 0)
  54.815 +            distance += size;
  54.816 +        if (distance == 0)
  54.817 +            return;
  54.818 +
  54.819 +        for (int cycleStart = 0, nMoved = 0; nMoved != size; cycleStart++) {
  54.820 +            T displaced = list.get(cycleStart);
  54.821 +            int i = cycleStart;
  54.822 +            do {
  54.823 +                i += distance;
  54.824 +                if (i >= size)
  54.825 +                    i -= size;
  54.826 +                displaced = list.set(i, displaced);
  54.827 +                nMoved ++;
  54.828 +            } while (i != cycleStart);
  54.829 +        }
  54.830 +    }
  54.831 +
  54.832 +    private static void rotate2(List<?> list, int distance) {
  54.833 +        int size = list.size();
  54.834 +        if (size == 0)
  54.835 +            return;
  54.836 +        int mid =  -distance % size;
  54.837 +        if (mid < 0)
  54.838 +            mid += size;
  54.839 +        if (mid == 0)
  54.840 +            return;
  54.841 +
  54.842 +        reverse(list.subList(0, mid));
  54.843 +        reverse(list.subList(mid, size));
  54.844 +        reverse(list);
  54.845 +    }
  54.846 +
  54.847 +    /**
  54.848 +     * Replaces all occurrences of one specified value in a list with another.
  54.849 +     * More formally, replaces with <tt>newVal</tt> each element <tt>e</tt>
  54.850 +     * in <tt>list</tt> such that
  54.851 +     * <tt>(oldVal==null ? e==null : oldVal.equals(e))</tt>.
  54.852 +     * (This method has no effect on the size of the list.)
  54.853 +     *
  54.854 +     * @param list the list in which replacement is to occur.
  54.855 +     * @param oldVal the old value to be replaced.
  54.856 +     * @param newVal the new value with which <tt>oldVal</tt> is to be
  54.857 +     *        replaced.
  54.858 +     * @return <tt>true</tt> if <tt>list</tt> contained one or more elements
  54.859 +     *         <tt>e</tt> such that
  54.860 +     *         <tt>(oldVal==null ?  e==null : oldVal.equals(e))</tt>.
  54.861 +     * @throws UnsupportedOperationException if the specified list or
  54.862 +     *         its list-iterator does not support the <tt>set</tt> operation.
  54.863 +     * @since  1.4
  54.864 +     */
  54.865 +    public static <T> boolean replaceAll(List<T> list, T oldVal, T newVal) {
  54.866 +        boolean result = false;
  54.867 +        int size = list.size();
  54.868 +        if (size < REPLACEALL_THRESHOLD || list instanceof RandomAccess) {
  54.869 +            if (oldVal==null) {
  54.870 +                for (int i=0; i<size; i++) {
  54.871 +                    if (list.get(i)==null) {
  54.872 +                        list.set(i, newVal);
  54.873 +                        result = true;
  54.874 +                    }
  54.875 +                }
  54.876 +            } else {
  54.877 +                for (int i=0; i<size; i++) {
  54.878 +                    if (oldVal.equals(list.get(i))) {
  54.879 +                        list.set(i, newVal);
  54.880 +                        result = true;
  54.881 +                    }
  54.882 +                }
  54.883 +            }
  54.884 +        } else {
  54.885 +            ListIterator<T> itr=list.listIterator();
  54.886 +            if (oldVal==null) {
  54.887 +                for (int i=0; i<size; i++) {
  54.888 +                    if (itr.next()==null) {
  54.889 +                        itr.set(newVal);
  54.890 +                        result = true;
  54.891 +                    }
  54.892 +                }
  54.893 +            } else {
  54.894 +                for (int i=0; i<size; i++) {
  54.895 +                    if (oldVal.equals(itr.next())) {
  54.896 +                        itr.set(newVal);
  54.897 +                        result = true;
  54.898 +                    }
  54.899 +                }
  54.900 +            }
  54.901 +        }
  54.902 +        return result;
  54.903 +    }
  54.904 +
  54.905 +    /**
  54.906 +     * Returns the starting position of the first occurrence of the specified
  54.907 +     * target list within the specified source list, or -1 if there is no
  54.908 +     * such occurrence.  More formally, returns the lowest index <tt>i</tt>
  54.909 +     * such that <tt>source.subList(i, i+target.size()).equals(target)</tt>,
  54.910 +     * or -1 if there is no such index.  (Returns -1 if
  54.911 +     * <tt>target.size() > source.size()</tt>.)
  54.912 +     *
  54.913 +     * <p>This implementation uses the "brute force" technique of scanning
  54.914 +     * over the source list, looking for a match with the target at each
  54.915 +     * location in turn.
  54.916 +     *
  54.917 +     * @param source the list in which to search for the first occurrence
  54.918 +     *        of <tt>target</tt>.
  54.919 +     * @param target the list to search for as a subList of <tt>source</tt>.
  54.920 +     * @return the starting position of the first occurrence of the specified
  54.921 +     *         target list within the specified source list, or -1 if there
  54.922 +     *         is no such occurrence.
  54.923 +     * @since  1.4
  54.924 +     */
  54.925 +    public static int indexOfSubList(List<?> source, List<?> target) {
  54.926 +        int sourceSize = source.size();
  54.927 +        int targetSize = target.size();
  54.928 +        int maxCandidate = sourceSize - targetSize;
  54.929 +
  54.930 +        if (sourceSize < INDEXOFSUBLIST_THRESHOLD ||
  54.931 +            (source instanceof RandomAccess&&target instanceof RandomAccess)) {
  54.932 +        nextCand:
  54.933 +            for (int candidate = 0; candidate <= maxCandidate; candidate++) {
  54.934 +                for (int i=0, j=candidate; i<targetSize; i++, j++)
  54.935 +                    if (!eq(target.get(i), source.get(j)))
  54.936 +                        continue nextCand;  // Element mismatch, try next cand
  54.937 +                return candidate;  // All elements of candidate matched target
  54.938 +            }
  54.939 +        } else {  // Iterator version of above algorithm
  54.940 +            ListIterator<?> si = source.listIterator();
  54.941 +        nextCand:
  54.942 +            for (int candidate = 0; candidate <= maxCandidate; candidate++) {
  54.943 +                ListIterator<?> ti = target.listIterator();
  54.944 +                for (int i=0; i<targetSize; i++) {
  54.945 +                    if (!eq(ti.next(), si.next())) {
  54.946 +                        // Back up source iterator to next candidate
  54.947 +                        for (int j=0; j<i; j++)
  54.948 +                            si.previous();
  54.949 +                        continue nextCand;
  54.950 +                    }
  54.951 +                }
  54.952 +                return candidate;
  54.953 +            }
  54.954 +        }
  54.955 +        return -1;  // No candidate matched the target
  54.956 +    }
  54.957 +
  54.958 +    /**
  54.959 +     * Returns the starting position of the last occurrence of the specified
  54.960 +     * target list within the specified source list, or -1 if there is no such
  54.961 +     * occurrence.  More formally, returns the highest index <tt>i</tt>
  54.962 +     * such that <tt>source.subList(i, i+target.size()).equals(target)</tt>,
  54.963 +     * or -1 if there is no such index.  (Returns -1 if
  54.964 +     * <tt>target.size() > source.size()</tt>.)
  54.965 +     *
  54.966 +     * <p>This implementation uses the "brute force" technique of iterating
  54.967 +     * over the source list, looking for a match with the target at each
  54.968 +     * location in turn.
  54.969 +     *
  54.970 +     * @param source the list in which to search for the last occurrence
  54.971 +     *        of <tt>target</tt>.
  54.972 +     * @param target the list to search for as a subList of <tt>source</tt>.
  54.973 +     * @return the starting position of the last occurrence of the specified
  54.974 +     *         target list within the specified source list, or -1 if there
  54.975 +     *         is no such occurrence.
  54.976 +     * @since  1.4
  54.977 +     */
  54.978 +    public static int lastIndexOfSubList(List<?> source, List<?> target) {
  54.979 +        int sourceSize = source.size();
  54.980 +        int targetSize = target.size();
  54.981 +        int maxCandidate = sourceSize - targetSize;
  54.982 +
  54.983 +        if (sourceSize < INDEXOFSUBLIST_THRESHOLD ||
  54.984 +            source instanceof RandomAccess) {   // Index access version
  54.985 +        nextCand:
  54.986 +            for (int candidate = maxCandidate; candidate >= 0; candidate--) {
  54.987 +                for (int i=0, j=candidate; i<targetSize; i++, j++)
  54.988 +                    if (!eq(target.get(i), source.get(j)))
  54.989 +                        continue nextCand;  // Element mismatch, try next cand
  54.990 +                return candidate;  // All elements of candidate matched target
  54.991 +            }
  54.992 +        } else {  // Iterator version of above algorithm
  54.993 +            if (maxCandidate < 0)
  54.994 +                return -1;
  54.995 +            ListIterator<?> si = source.listIterator(maxCandidate);
  54.996 +        nextCand:
  54.997 +            for (int candidate = maxCandidate; candidate >= 0; candidate--) {
  54.998 +                ListIterator<?> ti = target.listIterator();
  54.999 +                for (int i=0; i<targetSize; i++) {
 54.1000 +                    if (!eq(ti.next(), si.next())) {
 54.1001 +                        if (candidate != 0) {
 54.1002 +                            // Back up source iterator to next candidate
 54.1003 +                            for (int j=0; j<=i+1; j++)
 54.1004 +                                si.previous();
 54.1005 +                        }
 54.1006 +                        continue nextCand;
 54.1007 +                    }
 54.1008 +                }
 54.1009 +                return candidate;
 54.1010 +            }
 54.1011 +        }
 54.1012 +        return -1;  // No candidate matched the target
 54.1013 +    }
 54.1014 +
 54.1015 +
 54.1016 +    // Unmodifiable Wrappers
 54.1017 +
 54.1018 +    /**
 54.1019 +     * Returns an unmodifiable view of the specified collection.  This method
 54.1020 +     * allows modules to provide users with "read-only" access to internal
 54.1021 +     * collections.  Query operations on the returned collection "read through"
 54.1022 +     * to the specified collection, and attempts to modify the returned
 54.1023 +     * collection, whether direct or via its iterator, result in an
 54.1024 +     * <tt>UnsupportedOperationException</tt>.<p>
 54.1025 +     *
 54.1026 +     * The returned collection does <i>not</i> pass the hashCode and equals
 54.1027 +     * operations through to the backing collection, but relies on
 54.1028 +     * <tt>Object</tt>'s <tt>equals</tt> and <tt>hashCode</tt> methods.  This
 54.1029 +     * is necessary to preserve the contracts of these operations in the case
 54.1030 +     * that the backing collection is a set or a list.<p>
 54.1031 +     *
 54.1032 +     * The returned collection will be serializable if the specified collection
 54.1033 +     * is serializable.
 54.1034 +     *
 54.1035 +     * @param  c the collection for which an unmodifiable view is to be
 54.1036 +     *         returned.
 54.1037 +     * @return an unmodifiable view of the specified collection.
 54.1038 +     */
 54.1039 +    public static <T> Collection<T> unmodifiableCollection(Collection<? extends T> c) {
 54.1040 +        return new UnmodifiableCollection<>(c);
 54.1041 +    }
 54.1042 +
 54.1043 +    /**
 54.1044 +     * @serial include
 54.1045 +     */
 54.1046 +    static class UnmodifiableCollection<E> implements Collection<E>, Serializable {
 54.1047 +        private static final long serialVersionUID = 1820017752578914078L;
 54.1048 +
 54.1049 +        final Collection<? extends E> c;
 54.1050 +
 54.1051 +        UnmodifiableCollection(Collection<? extends E> c) {
 54.1052 +            if (c==null)
 54.1053 +                throw new NullPointerException();
 54.1054 +            this.c = c;
 54.1055 +        }
 54.1056 +
 54.1057 +        public int size()                   {return c.size();}
 54.1058 +        public boolean isEmpty()            {return c.isEmpty();}
 54.1059 +        public boolean contains(Object o)   {return c.contains(o);}
 54.1060 +        public Object[] toArray()           {return c.toArray();}
 54.1061 +        public <T> T[] toArray(T[] a)       {return c.toArray(a);}
 54.1062 +        public String toString()            {return c.toString();}
 54.1063 +
 54.1064 +        public Iterator<E> iterator() {
 54.1065 +            return new Iterator<E>() {
 54.1066 +                private final Iterator<? extends E> i = c.iterator();
 54.1067 +
 54.1068 +                public boolean hasNext() {return i.hasNext();}
 54.1069 +                public E next()          {return i.next();}
 54.1070 +                public void remove() {
 54.1071 +                    throw new UnsupportedOperationException();
 54.1072 +                }
 54.1073 +            };
 54.1074 +        }
 54.1075 +
 54.1076 +        public boolean add(E e) {
 54.1077 +            throw new UnsupportedOperationException();
 54.1078 +        }
 54.1079 +        public boolean remove(Object o) {
 54.1080 +            throw new UnsupportedOperationException();
 54.1081 +        }
 54.1082 +
 54.1083 +        public boolean containsAll(Collection<?> coll) {
 54.1084 +            return c.containsAll(coll);
 54.1085 +        }
 54.1086 +        public boolean addAll(Collection<? extends E> coll) {
 54.1087 +            throw new UnsupportedOperationException();
 54.1088 +        }
 54.1089 +        public boolean removeAll(Collection<?> coll) {
 54.1090 +            throw new UnsupportedOperationException();
 54.1091 +        }
 54.1092 +        public boolean retainAll(Collection<?> coll) {
 54.1093 +            throw new UnsupportedOperationException();
 54.1094 +        }
 54.1095 +        public void clear() {
 54.1096 +            throw new UnsupportedOperationException();
 54.1097 +        }
 54.1098 +    }
 54.1099 +
 54.1100 +    /**
 54.1101 +     * Returns an unmodifiable view of the specified set.  This method allows
 54.1102 +     * modules to provide users with "read-only" access to internal sets.
 54.1103 +     * Query operations on the returned set "read through" to the specified
 54.1104 +     * set, and attempts to modify the returned set, whether direct or via its
 54.1105 +     * iterator, result in an <tt>UnsupportedOperationException</tt>.<p>
 54.1106 +     *
 54.1107 +     * The returned set will be serializable if the specified set
 54.1108 +     * is serializable.
 54.1109 +     *
 54.1110 +     * @param  s the set for which an unmodifiable view is to be returned.
 54.1111 +     * @return an unmodifiable view of the specified set.
 54.1112 +     */
 54.1113 +    public static <T> Set<T> unmodifiableSet(Set<? extends T> s) {
 54.1114 +        return new UnmodifiableSet<>(s);
 54.1115 +    }
 54.1116 +
 54.1117 +    /**
 54.1118 +     * @serial include
 54.1119 +     */
 54.1120 +    static class UnmodifiableSet<E> extends UnmodifiableCollection<E>
 54.1121 +                                 implements Set<E>, Serializable {
 54.1122 +        private static final long serialVersionUID = -9215047833775013803L;
 54.1123 +
 54.1124 +        UnmodifiableSet(Set<? extends E> s)     {super(s);}
 54.1125 +        public boolean equals(Object o) {return o == this || c.equals(o);}
 54.1126 +        public int hashCode()           {return c.hashCode();}
 54.1127 +    }
 54.1128 +
 54.1129 +    /**
 54.1130 +     * Returns an unmodifiable view of the specified sorted set.  This method
 54.1131 +     * allows modules to provide users with "read-only" access to internal
 54.1132 +     * sorted sets.  Query operations on the returned sorted set "read
 54.1133 +     * through" to the specified sorted set.  Attempts to modify the returned
 54.1134 +     * sorted set, whether direct, via its iterator, or via its
 54.1135 +     * <tt>subSet</tt>, <tt>headSet</tt>, or <tt>tailSet</tt> views, result in
 54.1136 +     * an <tt>UnsupportedOperationException</tt>.<p>
 54.1137 +     *
 54.1138 +     * The returned sorted set will be serializable if the specified sorted set
 54.1139 +     * is serializable.
 54.1140 +     *
 54.1141 +     * @param s the sorted set for which an unmodifiable view is to be
 54.1142 +     *        returned.
 54.1143 +     * @return an unmodifiable view of the specified sorted set.
 54.1144 +     */
 54.1145 +    public static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> s) {
 54.1146 +        return new UnmodifiableSortedSet<>(s);
 54.1147 +    }
 54.1148 +
 54.1149 +    /**
 54.1150 +     * @serial include
 54.1151 +     */
 54.1152 +    static class UnmodifiableSortedSet<E>
 54.1153 +                             extends UnmodifiableSet<E>
 54.1154 +                             implements SortedSet<E>, Serializable {
 54.1155 +        private static final long serialVersionUID = -4929149591599911165L;
 54.1156 +        private final SortedSet<E> ss;
 54.1157 +
 54.1158 +        UnmodifiableSortedSet(SortedSet<E> s) {super(s); ss = s;}
 54.1159 +
 54.1160 +        public Comparator<? super E> comparator() {return ss.comparator();}
 54.1161 +
 54.1162 +        public SortedSet<E> subSet(E fromElement, E toElement) {
 54.1163 +            return new UnmodifiableSortedSet<>(ss.subSet(fromElement,toElement));
 54.1164 +        }
 54.1165 +        public SortedSet<E> headSet(E toElement) {
 54.1166 +            return new UnmodifiableSortedSet<>(ss.headSet(toElement));
 54.1167 +        }
 54.1168 +        public SortedSet<E> tailSet(E fromElement) {
 54.1169 +            return new UnmodifiableSortedSet<>(ss.tailSet(fromElement));
 54.1170 +        }
 54.1171 +
 54.1172 +        public E first()                   {return ss.first();}
 54.1173 +        public E last()                    {return ss.last();}
 54.1174 +    }
 54.1175 +
 54.1176 +    /**
 54.1177 +     * Returns an unmodifiable view of the specified list.  This method allows
 54.1178 +     * modules to provide users with "read-only" access to internal
 54.1179 +     * lists.  Query operations on the returned list "read through" to the
 54.1180 +     * specified list, and attempts to modify the returned list, whether
 54.1181 +     * direct or via its iterator, result in an
 54.1182 +     * <tt>UnsupportedOperationException</tt>.<p>
 54.1183 +     *
 54.1184 +     * The returned list will be serializable if the specified list
 54.1185 +     * is serializable. Similarly, the returned list will implement
 54.1186 +     * {@link RandomAccess} if the specified list does.
 54.1187 +     *
 54.1188 +     * @param  list the list for which an unmodifiable view is to be returned.
 54.1189 +     * @return an unmodifiable view of the specified list.
 54.1190 +     */
 54.1191 +    public static <T> List<T> unmodifiableList(List<? extends T> list) {
 54.1192 +        return (list instanceof RandomAccess ?
 54.1193 +                new UnmodifiableRandomAccessList<>(list) :
 54.1194 +                new UnmodifiableList<>(list));
 54.1195 +    }
 54.1196 +
 54.1197 +    /**
 54.1198 +     * @serial include
 54.1199 +     */
 54.1200 +    static class UnmodifiableList<E> extends UnmodifiableCollection<E>
 54.1201 +                                  implements List<E> {
 54.1202 +        private static final long serialVersionUID = -283967356065247728L;
 54.1203 +        final List<? extends E> list;
 54.1204 +
 54.1205 +        UnmodifiableList(List<? extends E> list) {
 54.1206 +            super(list);
 54.1207 +            this.list = list;
 54.1208 +        }
 54.1209 +
 54.1210 +        public boolean equals(Object o) {return o == this || list.equals(o);}
 54.1211 +        public int hashCode()           {return list.hashCode();}
 54.1212 +
 54.1213 +        public E get(int index) {return list.get(index);}
 54.1214 +        public E set(int index, E element) {
 54.1215 +            throw new UnsupportedOperationException();
 54.1216 +        }
 54.1217 +        public void add(int index, E element) {
 54.1218 +            throw new UnsupportedOperationException();
 54.1219 +        }
 54.1220 +        public E remove(int index) {
 54.1221 +            throw new UnsupportedOperationException();
 54.1222 +        }
 54.1223 +        public int indexOf(Object o)            {return list.indexOf(o);}
 54.1224 +        public int lastIndexOf(Object o)        {return list.lastIndexOf(o);}
 54.1225 +        public boolean addAll(int index, Collection<? extends E> c) {
 54.1226 +            throw new UnsupportedOperationException();
 54.1227 +        }
 54.1228 +        public ListIterator<E> listIterator()   {return listIterator(0);}
 54.1229 +
 54.1230 +        public ListIterator<E> listIterator(final int index) {
 54.1231 +            return new ListIterator<E>() {
 54.1232 +                private final ListIterator<? extends E> i
 54.1233 +                    = list.listIterator(index);
 54.1234 +
 54.1235 +                public boolean hasNext()     {return i.hasNext();}
 54.1236 +                public E next()              {return i.next();}
 54.1237 +                public boolean hasPrevious() {return i.hasPrevious();}
 54.1238 +                public E previous()          {return i.previous();}
 54.1239 +                public int nextIndex()       {return i.nextIndex();}
 54.1240 +                public int previousIndex()   {return i.previousIndex();}
 54.1241 +
 54.1242 +                public void remove() {
 54.1243 +                    throw new UnsupportedOperationException();
 54.1244 +                }
 54.1245 +                public void set(E e) {
 54.1246 +                    throw new UnsupportedOperationException();
 54.1247 +                }
 54.1248 +                public void add(E e) {
 54.1249 +                    throw new UnsupportedOperationException();
 54.1250 +                }
 54.1251 +            };
 54.1252 +        }
 54.1253 +
 54.1254 +        public List<E> subList(int fromIndex, int toIndex) {
 54.1255 +            return new UnmodifiableList<>(list.subList(fromIndex, toIndex));
 54.1256 +        }
 54.1257 +
 54.1258 +        /**
 54.1259 +         * UnmodifiableRandomAccessList instances are serialized as
 54.1260 +         * UnmodifiableList instances to allow them to be deserialized
 54.1261 +         * in pre-1.4 JREs (which do not have UnmodifiableRandomAccessList).
 54.1262 +         * This method inverts the transformation.  As a beneficial
 54.1263 +         * side-effect, it also grafts the RandomAccess marker onto
 54.1264 +         * UnmodifiableList instances that were serialized in pre-1.4 JREs.
 54.1265 +         *
 54.1266 +         * Note: Unfortunately, UnmodifiableRandomAccessList instances
 54.1267 +         * serialized in 1.4.1 and deserialized in 1.4 will become
 54.1268 +         * UnmodifiableList instances, as this method was missing in 1.4.
 54.1269 +         */
 54.1270 +        private Object readResolve() {
 54.1271 +            return (list instanceof RandomAccess
 54.1272 +                    ? new UnmodifiableRandomAccessList<>(list)
 54.1273 +                    : this);
 54.1274 +        }
 54.1275 +    }
 54.1276 +
 54.1277 +    /**
 54.1278 +     * @serial include
 54.1279 +     */
 54.1280 +    static class UnmodifiableRandomAccessList<E> extends UnmodifiableList<E>
 54.1281 +                                              implements RandomAccess
 54.1282 +    {
 54.1283 +        UnmodifiableRandomAccessList(List<? extends E> list) {
 54.1284 +            super(list);
 54.1285 +        }
 54.1286 +
 54.1287 +        public List<E> subList(int fromIndex, int toIndex) {
 54.1288 +            return new UnmodifiableRandomAccessList<>(
 54.1289 +                list.subList(fromIndex, toIndex));
 54.1290 +        }
 54.1291 +
 54.1292 +        private static final long serialVersionUID = -2542308836966382001L;
 54.1293 +
 54.1294 +        /**
 54.1295 +         * Allows instances to be deserialized in pre-1.4 JREs (which do
 54.1296 +         * not have UnmodifiableRandomAccessList).  UnmodifiableList has
 54.1297 +         * a readResolve method that inverts this transformation upon
 54.1298 +         * deserialization.
 54.1299 +         */
 54.1300 +        private Object writeReplace() {
 54.1301 +            return new UnmodifiableList<>(list);
 54.1302 +        }
 54.1303 +    }
 54.1304 +
 54.1305 +    /**
 54.1306 +     * Returns an unmodifiable view of the specified map.  This method
 54.1307 +     * allows modules to provide users with "read-only" access to internal
 54.1308 +     * maps.  Query operations on the returned map "read through"
 54.1309 +     * to the specified map, and attempts to modify the returned
 54.1310 +     * map, whether direct or via its collection views, result in an
 54.1311 +     * <tt>UnsupportedOperationException</tt>.<p>
 54.1312 +     *
 54.1313 +     * The returned map will be serializable if the specified map
 54.1314 +     * is serializable.
 54.1315 +     *
 54.1316 +     * @param  m the map for which an unmodifiable view is to be returned.
 54.1317 +     * @return an unmodifiable view of the specified map.
 54.1318 +     */
 54.1319 +    public static <K,V> Map<K,V> unmodifiableMap(Map<? extends K, ? extends V> m) {
 54.1320 +        return new UnmodifiableMap<>(m);
 54.1321 +    }
 54.1322 +
 54.1323 +    /**
 54.1324 +     * @serial include
 54.1325 +     */
 54.1326 +    private static class UnmodifiableMap<K,V> implements Map<K,V>, Serializable {
 54.1327 +        private static final long serialVersionUID = -1034234728574286014L;
 54.1328 +
 54.1329 +        private final Map<? extends K, ? extends V> m;
 54.1330 +
 54.1331 +        UnmodifiableMap(Map<? extends K, ? extends V> m) {
 54.1332 +            if (m==null)
 54.1333 +                throw new NullPointerException();
 54.1334 +            this.m = m;
 54.1335 +        }
 54.1336 +
 54.1337 +        public int size()                        {return m.size();}
 54.1338 +        public boolean isEmpty()                 {return m.isEmpty();}
 54.1339 +        public boolean containsKey(Object key)   {return m.containsKey(key);}
 54.1340 +        public boolean containsValue(Object val) {return m.containsValue(val);}
 54.1341 +        public V get(Object key)                 {return m.get(key);}
 54.1342 +
 54.1343 +        public V put(K key, V value) {
 54.1344 +            throw new UnsupportedOperationException();
 54.1345 +        }
 54.1346 +        public V remove(Object key) {
 54.1347 +            throw new UnsupportedOperationException();
 54.1348 +        }
 54.1349 +        public void putAll(Map<? extends K, ? extends V> m) {
 54.1350 +            throw new UnsupportedOperationException();
 54.1351 +        }
 54.1352 +        public void clear() {
 54.1353 +            throw new UnsupportedOperationException();
 54.1354 +        }
 54.1355 +
 54.1356 +        private transient Set<K> keySet = null;
 54.1357 +        private transient Set<Map.Entry<K,V>> entrySet = null;
 54.1358 +        private transient Collection<V> values = null;
 54.1359 +
 54.1360 +        public Set<K> keySet() {
 54.1361 +            if (keySet==null)
 54.1362 +                keySet = unmodifiableSet(m.keySet());
 54.1363 +            return keySet;
 54.1364 +        }
 54.1365 +
 54.1366 +        public Set<Map.Entry<K,V>> entrySet() {
 54.1367 +            if (entrySet==null)
 54.1368 +                entrySet = new UnmodifiableEntrySet<>(m.entrySet());
 54.1369 +            return entrySet;
 54.1370 +        }
 54.1371 +
 54.1372 +        public Collection<V> values() {
 54.1373 +            if (values==null)
 54.1374 +                values = unmodifiableCollection(m.values());
 54.1375 +            return values;
 54.1376 +        }
 54.1377 +
 54.1378 +        public boolean equals(Object o) {return o == this || m.equals(o);}
 54.1379 +        public int hashCode()           {return m.hashCode();}
 54.1380 +        public String toString()        {return m.toString();}
 54.1381 +
 54.1382 +        /**
 54.1383 +         * We need this class in addition to UnmodifiableSet as
 54.1384 +         * Map.Entries themselves permit modification of the backing Map
 54.1385 +         * via their setValue operation.  This class is subtle: there are
 54.1386 +         * many possible attacks that must be thwarted.
 54.1387 +         *
 54.1388 +         * @serial include
 54.1389 +         */
 54.1390 +        static class UnmodifiableEntrySet<K,V>
 54.1391 +            extends UnmodifiableSet<Map.Entry<K,V>> {
 54.1392 +            private static final long serialVersionUID = 7854390611657943733L;
 54.1393 +
 54.1394 +            UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K, ? extends V>> s) {
 54.1395 +                super((Set)s);
 54.1396 +            }
 54.1397 +            public Iterator<Map.Entry<K,V>> iterator() {
 54.1398 +                return new Iterator<Map.Entry<K,V>>() {
 54.1399 +                    private final Iterator<? extends Map.Entry<? extends K, ? extends V>> i = c.iterator();
 54.1400 +
 54.1401 +                    public boolean hasNext() {
 54.1402 +                        return i.hasNext();
 54.1403 +                    }
 54.1404 +                    public Map.Entry<K,V> next() {
 54.1405 +                        return new UnmodifiableEntry<>(i.next());
 54.1406 +                    }
 54.1407 +                    public void remove() {
 54.1408 +                        throw new UnsupportedOperationException();
 54.1409 +                    }
 54.1410 +                };
 54.1411 +            }
 54.1412 +
 54.1413 +            public Object[] toArray() {
 54.1414 +                Object[] a = c.toArray();
 54.1415 +                for (int i=0; i<a.length; i++)
 54.1416 +                    a[i] = new UnmodifiableEntry<>((Map.Entry<K,V>)a[i]);
 54.1417 +                return a;
 54.1418 +            }
 54.1419 +
 54.1420 +            public <T> T[] toArray(T[] a) {
 54.1421 +                // We don't pass a to c.toArray, to avoid window of
 54.1422 +                // vulnerability wherein an unscrupulous multithreaded client
 54.1423 +                // could get his hands on raw (unwrapped) Entries from c.
 54.1424 +                Object[] arr = c.toArray(a.length==0 ? a : Arrays.copyOf(a, 0));
 54.1425 +
 54.1426 +                for (int i=0; i<arr.length; i++)
 54.1427 +                    arr[i] = new UnmodifiableEntry<>((Map.Entry<K,V>)arr[i]);
 54.1428 +
 54.1429 +                if (arr.length > a.length)
 54.1430 +                    return (T[])arr;
 54.1431 +
 54.1432 +                System.arraycopy(arr, 0, a, 0, arr.length);
 54.1433 +                if (a.length > arr.length)
 54.1434 +                    a[arr.length] = null;
 54.1435 +                return a;
 54.1436 +            }
 54.1437 +
 54.1438 +            /**
 54.1439 +             * This method is overridden to protect the backing set against
 54.1440 +             * an object with a nefarious equals function that senses
 54.1441 +             * that the equality-candidate is Map.Entry and calls its
 54.1442 +             * setValue method.
 54.1443 +             */
 54.1444 +            public boolean contains(Object o) {
 54.1445 +                if (!(o instanceof Map.Entry))
 54.1446 +                    return false;
 54.1447 +                return c.contains(
 54.1448 +                    new UnmodifiableEntry<>((Map.Entry<?,?>) o));
 54.1449 +            }
 54.1450 +
 54.1451 +            /**
 54.1452 +             * The next two methods are overridden to protect against
 54.1453 +             * an unscrupulous List whose contains(Object o) method senses
 54.1454 +             * when o is a Map.Entry, and calls o.setValue.
 54.1455 +             */
 54.1456 +            public boolean containsAll(Collection<?> coll) {
 54.1457 +                for (Object e : coll) {
 54.1458 +                    if (!contains(e)) // Invokes safe contains() above
 54.1459 +                        return false;
 54.1460 +                }
 54.1461 +                return true;
 54.1462 +            }
 54.1463 +            public boolean equals(Object o) {
 54.1464 +                if (o == this)
 54.1465 +                    return true;
 54.1466 +
 54.1467 +                if (!(o instanceof Set))
 54.1468 +                    return false;
 54.1469 +                Set s = (Set) o;
 54.1470 +                if (s.size() != c.size())
 54.1471 +                    return false;
 54.1472 +                return containsAll(s); // Invokes safe containsAll() above
 54.1473 +            }
 54.1474 +
 54.1475 +            /**
 54.1476 +             * This "wrapper class" serves two purposes: it prevents
 54.1477 +             * the client from modifying the backing Map, by short-circuiting
 54.1478 +             * the setValue method, and it protects the backing Map against
 54.1479 +             * an ill-behaved Map.Entry that attempts to modify another
 54.1480 +             * Map Entry when asked to perform an equality check.
 54.1481 +             */
 54.1482 +            private static class UnmodifiableEntry<K,V> implements Map.Entry<K,V> {
 54.1483 +                private Map.Entry<? extends K, ? extends V> e;
 54.1484 +
 54.1485 +                UnmodifiableEntry(Map.Entry<? extends K, ? extends V> e) {this.e = e;}
 54.1486 +
 54.1487 +                public K getKey()        {return e.getKey();}
 54.1488 +                public V getValue()      {return e.getValue();}
 54.1489 +                public V setValue(V value) {
 54.1490 +                    throw new UnsupportedOperationException();
 54.1491 +                }
 54.1492 +                public int hashCode()    {return e.hashCode();}
 54.1493 +                public boolean equals(Object o) {
 54.1494 +                    if (!(o instanceof Map.Entry))
 54.1495 +                        return false;
 54.1496 +                    Map.Entry t = (Map.Entry)o;
 54.1497 +                    return eq(e.getKey(),   t.getKey()) &&
 54.1498 +                           eq(e.getValue(), t.getValue());
 54.1499 +                }
 54.1500 +                public String toString() {return e.toString();}
 54.1501 +            }
 54.1502 +        }
 54.1503 +    }
 54.1504 +
 54.1505 +    /**
 54.1506 +     * Returns an unmodifiable view of the specified sorted map.  This method
 54.1507 +     * allows modules to provide users with "read-only" access to internal
 54.1508 +     * sorted maps.  Query operations on the returned sorted map "read through"
 54.1509 +     * to the specified sorted map.  Attempts to modify the returned
 54.1510 +     * sorted map, whether direct, via its collection views, or via its
 54.1511 +     * <tt>subMap</tt>, <tt>headMap</tt>, or <tt>tailMap</tt> views, result in
 54.1512 +     * an <tt>UnsupportedOperationException</tt>.<p>
 54.1513 +     *
 54.1514 +     * The returned sorted map will be serializable if the specified sorted map
 54.1515 +     * is serializable.
 54.1516 +     *
 54.1517 +     * @param m the sorted map for which an unmodifiable view is to be
 54.1518 +     *        returned.
 54.1519 +     * @return an unmodifiable view of the specified sorted map.
 54.1520 +     */
 54.1521 +    public static <K,V> SortedMap<K,V> unmodifiableSortedMap(SortedMap<K, ? extends V> m) {
 54.1522 +        return new UnmodifiableSortedMap<>(m);
 54.1523 +    }
 54.1524 +
 54.1525 +    /**
 54.1526 +     * @serial include
 54.1527 +     */
 54.1528 +    static class UnmodifiableSortedMap<K,V>
 54.1529 +          extends UnmodifiableMap<K,V>
 54.1530 +          implements SortedMap<K,V>, Serializable {
 54.1531 +        private static final long serialVersionUID = -8806743815996713206L;
 54.1532 +
 54.1533 +        private final SortedMap<K, ? extends V> sm;
 54.1534 +
 54.1535 +        UnmodifiableSortedMap(SortedMap<K, ? extends V> m) {super(m); sm = m;}
 54.1536 +
 54.1537 +        public Comparator<? super K> comparator() {return sm.comparator();}
 54.1538 +
 54.1539 +        public SortedMap<K,V> subMap(K fromKey, K toKey) {
 54.1540 +            return new UnmodifiableSortedMap<>(sm.subMap(fromKey, toKey));
 54.1541 +        }
 54.1542 +        public SortedMap<K,V> headMap(K toKey) {
 54.1543 +            return new UnmodifiableSortedMap<>(sm.headMap(toKey));
 54.1544 +        }
 54.1545 +        public SortedMap<K,V> tailMap(K fromKey) {
 54.1546 +            return new UnmodifiableSortedMap<>(sm.tailMap(fromKey));
 54.1547 +        }
 54.1548 +
 54.1549 +        public K firstKey()           {return sm.firstKey();}
 54.1550 +        public K lastKey()            {return sm.lastKey();}
 54.1551 +    }
 54.1552 +
 54.1553 +
 54.1554 +    // Synch Wrappers
 54.1555 +
 54.1556 +    /**
 54.1557 +     * Returns a synchronized (thread-safe) collection backed by the specified
 54.1558 +     * collection.  In order to guarantee serial access, it is critical that
 54.1559 +     * <strong>all</strong> access to the backing collection is accomplished
 54.1560 +     * through the returned collection.<p>
 54.1561 +     *
 54.1562 +     * It is imperative that the user manually synchronize on the returned
 54.1563 +     * collection when iterating over it:
 54.1564 +     * <pre>
 54.1565 +     *  Collection c = Collections.synchronizedCollection(myCollection);
 54.1566 +     *     ...
 54.1567 +     *  synchronized (c) {
 54.1568 +     *      Iterator i = c.iterator(); // Must be in the synchronized block
 54.1569 +     *      while (i.hasNext())
 54.1570 +     *         foo(i.next());
 54.1571 +     *  }
 54.1572 +     * </pre>
 54.1573 +     * Failure to follow this advice may result in non-deterministic behavior.
 54.1574 +     *
 54.1575 +     * <p>The returned collection does <i>not</i> pass the <tt>hashCode</tt>
 54.1576 +     * and <tt>equals</tt> operations through to the backing collection, but
 54.1577 +     * relies on <tt>Object</tt>'s equals and hashCode methods.  This is
 54.1578 +     * necessary to preserve the contracts of these operations in the case
 54.1579 +     * that the backing collection is a set or a list.<p>
 54.1580 +     *
 54.1581 +     * The returned collection will be serializable if the specified collection
 54.1582 +     * is serializable.
 54.1583 +     *
 54.1584 +     * @param  c the collection to be "wrapped" in a synchronized collection.
 54.1585 +     * @return a synchronized view of the specified collection.
 54.1586 +     */
 54.1587 +    public static <T> Collection<T> synchronizedCollection(Collection<T> c) {
 54.1588 +        return new SynchronizedCollection<>(c);
 54.1589 +    }
 54.1590 +
 54.1591 +    static <T> Collection<T> synchronizedCollection(Collection<T> c, Object mutex) {
 54.1592 +        return new SynchronizedCollection<>(c, mutex);
 54.1593 +    }
 54.1594 +
 54.1595 +    /**
 54.1596 +     * @serial include
 54.1597 +     */
 54.1598 +    static class SynchronizedCollection<E> implements Collection<E>, Serializable {
 54.1599 +        private static final long serialVersionUID = 3053995032091335093L;
 54.1600 +
 54.1601 +        final Collection<E> c;  // Backing Collection
 54.1602 +        final Object mutex;     // Object on which to synchronize
 54.1603 +
 54.1604 +        SynchronizedCollection(Collection<E> c) {
 54.1605 +            if (c==null)
 54.1606 +                throw new NullPointerException();
 54.1607 +            this.c = c;
 54.1608 +            mutex = this;
 54.1609 +        }
 54.1610 +        SynchronizedCollection(Collection<E> c, Object mutex) {
 54.1611 +            this.c = c;
 54.1612 +            this.mutex = mutex;
 54.1613 +        }
 54.1614 +
 54.1615 +        public int size() {
 54.1616 +            synchronized (mutex) {return c.size();}
 54.1617 +        }
 54.1618 +        public boolean isEmpty() {
 54.1619 +            synchronized (mutex) {return c.isEmpty();}
 54.1620 +        }
 54.1621 +        public boolean contains(Object o) {
 54.1622 +            synchronized (mutex) {return c.contains(o);}
 54.1623 +        }
 54.1624 +        public Object[] toArray() {
 54.1625 +            synchronized (mutex) {return c.toArray();}
 54.1626 +        }
 54.1627 +        public <T> T[] toArray(T[] a) {
 54.1628 +            synchronized (mutex) {return c.toArray(a);}
 54.1629 +        }
 54.1630 +
 54.1631 +        public Iterator<E> iterator() {
 54.1632 +            return c.iterator(); // Must be manually synched by user!
 54.1633 +        }
 54.1634 +
 54.1635 +        public boolean add(E e) {
 54.1636 +            synchronized (mutex) {return c.add(e);}
 54.1637 +        }
 54.1638 +        public boolean remove(Object o) {
 54.1639 +            synchronized (mutex) {return c.remove(o);}
 54.1640 +        }
 54.1641 +
 54.1642 +        public boolean containsAll(Collection<?> coll) {
 54.1643 +            synchronized (mutex) {return c.containsAll(coll);}
 54.1644 +        }
 54.1645 +        public boolean addAll(Collection<? extends E> coll) {
 54.1646 +            synchronized (mutex) {return c.addAll(coll);}
 54.1647 +        }
 54.1648 +        public boolean removeAll(Collection<?> coll) {
 54.1649 +            synchronized (mutex) {return c.removeAll(coll);}
 54.1650 +        }
 54.1651 +        public boolean retainAll(Collection<?> coll) {
 54.1652 +            synchronized (mutex) {return c.retainAll(coll);}
 54.1653 +        }
 54.1654 +        public void clear() {
 54.1655 +            synchronized (mutex) {c.clear();}
 54.1656 +        }
 54.1657 +        public String toString() {
 54.1658 +            synchronized (mutex) {return c.toString();}
 54.1659 +        }
 54.1660 +    }
 54.1661 +
 54.1662 +    /**
 54.1663 +     * Returns a synchronized (thread-safe) set backed by the specified
 54.1664 +     * set.  In order to guarantee serial access, it is critical that
 54.1665 +     * <strong>all</strong> access to the backing set is accomplished
 54.1666 +     * through the returned set.<p>
 54.1667 +     *
 54.1668 +     * It is imperative that the user manually synchronize on the returned
 54.1669 +     * set when iterating over it:
 54.1670 +     * <pre>
 54.1671 +     *  Set s = Collections.synchronizedSet(new HashSet());
 54.1672 +     *      ...
 54.1673 +     *  synchronized (s) {
 54.1674 +     *      Iterator i = s.iterator(); // Must be in the synchronized block
 54.1675 +     *      while (i.hasNext())
 54.1676 +     *          foo(i.next());
 54.1677 +     *  }
 54.1678 +     * </pre>
 54.1679 +     * Failure to follow this advice may result in non-deterministic behavior.
 54.1680 +     *
 54.1681 +     * <p>The returned set will be serializable if the specified set is
 54.1682 +     * serializable.
 54.1683 +     *
 54.1684 +     * @param  s the set to be "wrapped" in a synchronized set.
 54.1685 +     * @return a synchronized view of the specified set.
 54.1686 +     */
 54.1687 +    public static <T> Set<T> synchronizedSet(Set<T> s) {
 54.1688 +        return new SynchronizedSet<>(s);
 54.1689 +    }
 54.1690 +
 54.1691 +    static <T> Set<T> synchronizedSet(Set<T> s, Object mutex) {
 54.1692 +        return new SynchronizedSet<>(s, mutex);
 54.1693 +    }
 54.1694 +
 54.1695 +    /**
 54.1696 +     * @serial include
 54.1697 +     */
 54.1698 +    static class SynchronizedSet<E>
 54.1699 +          extends SynchronizedCollection<E>
 54.1700 +          implements Set<E> {
 54.1701 +        private static final long serialVersionUID = 487447009682186044L;
 54.1702 +
 54.1703 +        SynchronizedSet(Set<E> s) {
 54.1704 +            super(s);
 54.1705 +        }
 54.1706 +        SynchronizedSet(Set<E> s, Object mutex) {
 54.1707 +            super(s, mutex);
 54.1708 +        }
 54.1709 +
 54.1710 +        public boolean equals(Object o) {
 54.1711 +            synchronized (mutex) {return c.equals(o);}
 54.1712 +        }
 54.1713 +        public int hashCode() {
 54.1714 +            synchronized (mutex) {return c.hashCode();}
 54.1715 +        }
 54.1716 +    }
 54.1717 +
 54.1718 +    /**
 54.1719 +     * Returns a synchronized (thread-safe) sorted set backed by the specified
 54.1720 +     * sorted set.  In order to guarantee serial access, it is critical that
 54.1721 +     * <strong>all</strong> access to the backing sorted set is accomplished
 54.1722 +     * through the returned sorted set (or its views).<p>
 54.1723 +     *
 54.1724 +     * It is imperative that the user manually synchronize on the returned
 54.1725 +     * sorted set when iterating over it or any of its <tt>subSet</tt>,
 54.1726 +     * <tt>headSet</tt>, or <tt>tailSet</tt> views.
 54.1727 +     * <pre>
 54.1728 +     *  SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
 54.1729 +     *      ...
 54.1730 +     *  synchronized (s) {
 54.1731 +     *      Iterator i = s.iterator(); // Must be in the synchronized block
 54.1732 +     *      while (i.hasNext())
 54.1733 +     *          foo(i.next());
 54.1734 +     *  }
 54.1735 +     * </pre>
 54.1736 +     * or:
 54.1737 +     * <pre>
 54.1738 +     *  SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
 54.1739 +     *  SortedSet s2 = s.headSet(foo);
 54.1740 +     *      ...
 54.1741 +     *  synchronized (s) {  // Note: s, not s2!!!
 54.1742 +     *      Iterator i = s2.iterator(); // Must be in the synchronized block
 54.1743 +     *      while (i.hasNext())
 54.1744 +     *          foo(i.next());
 54.1745 +     *  }
 54.1746 +     * </pre>
 54.1747 +     * Failure to follow this advice may result in non-deterministic behavior.
 54.1748 +     *
 54.1749 +     * <p>The returned sorted set will be serializable if the specified
 54.1750 +     * sorted set is serializable.
 54.1751 +     *
 54.1752 +     * @param  s the sorted set to be "wrapped" in a synchronized sorted set.
 54.1753 +     * @return a synchronized view of the specified sorted set.
 54.1754 +     */
 54.1755 +    public static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s) {
 54.1756 +        return new SynchronizedSortedSet<>(s);
 54.1757 +    }
 54.1758 +
 54.1759 +    /**
 54.1760 +     * @serial include
 54.1761 +     */
 54.1762 +    static class SynchronizedSortedSet<E>
 54.1763 +        extends SynchronizedSet<E>
 54.1764 +        implements SortedSet<E>
 54.1765 +    {
 54.1766 +        private static final long serialVersionUID = 8695801310862127406L;
 54.1767 +
 54.1768 +        private final SortedSet<E> ss;
 54.1769 +
 54.1770 +        SynchronizedSortedSet(SortedSet<E> s) {
 54.1771 +            super(s);
 54.1772 +            ss = s;
 54.1773 +        }
 54.1774 +        SynchronizedSortedSet(SortedSet<E> s, Object mutex) {
 54.1775 +            super(s, mutex);
 54.1776 +            ss = s;
 54.1777 +        }
 54.1778 +
 54.1779 +        public Comparator<? super E> comparator() {
 54.1780 +            synchronized (mutex) {return ss.comparator();}
 54.1781 +        }
 54.1782 +
 54.1783 +        public SortedSet<E> subSet(E fromElement, E toElement) {
 54.1784 +            synchronized (mutex) {
 54.1785 +                return new SynchronizedSortedSet<>(
 54.1786 +                    ss.subSet(fromElement, toElement), mutex);
 54.1787 +            }
 54.1788 +        }
 54.1789 +        public SortedSet<E> headSet(E toElement) {
 54.1790 +            synchronized (mutex) {
 54.1791 +                return new SynchronizedSortedSet<>(ss.headSet(toElement), mutex);
 54.1792 +            }
 54.1793 +        }
 54.1794 +        public SortedSet<E> tailSet(E fromElement) {
 54.1795 +            synchronized (mutex) {
 54.1796 +               return new SynchronizedSortedSet<>(ss.tailSet(fromElement),mutex);
 54.1797 +            }
 54.1798 +        }
 54.1799 +
 54.1800 +        public E first() {
 54.1801 +            synchronized (mutex) {return ss.first();}
 54.1802 +        }
 54.1803 +        public E last() {
 54.1804 +            synchronized (mutex) {return ss.last();}
 54.1805 +        }
 54.1806 +    }
 54.1807 +
 54.1808 +    /**
 54.1809 +     * Returns a synchronized (thread-safe) list backed by the specified
 54.1810 +     * list.  In order to guarantee serial access, it is critical that
 54.1811 +     * <strong>all</strong> access to the backing list is accomplished
 54.1812 +     * through the returned list.<p>
 54.1813 +     *
 54.1814 +     * It is imperative that the user manually synchronize on the returned
 54.1815 +     * list when iterating over it:
 54.1816 +     * <pre>
 54.1817 +     *  List list = Collections.synchronizedList(new ArrayList());
 54.1818 +     *      ...
 54.1819 +     *  synchronized (list) {
 54.1820 +     *      Iterator i = list.iterator(); // Must be in synchronized block
 54.1821 +     *      while (i.hasNext())
 54.1822 +     *          foo(i.next());
 54.1823 +     *  }
 54.1824 +     * </pre>
 54.1825 +     * Failure to follow this advice may result in non-deterministic behavior.
 54.1826 +     *
 54.1827 +     * <p>The returned list will be serializable if the specified list is
 54.1828 +     * serializable.
 54.1829 +     *
 54.1830 +     * @param  list the list to be "wrapped" in a synchronized list.
 54.1831 +     * @return a synchronized view of the specified list.
 54.1832 +     */
 54.1833 +    public static <T> List<T> synchronizedList(List<T> list) {
 54.1834 +        return (list instanceof RandomAccess ?
 54.1835 +                new SynchronizedRandomAccessList<>(list) :
 54.1836 +                new SynchronizedList<>(list));
 54.1837 +    }
 54.1838 +
 54.1839 +    static <T> List<T> synchronizedList(List<T> list, Object mutex) {
 54.1840 +        return (list instanceof RandomAccess ?
 54.1841 +                new SynchronizedRandomAccessList<>(list, mutex) :
 54.1842 +                new SynchronizedList<>(list, mutex));
 54.1843 +    }
 54.1844 +
 54.1845 +    /**
 54.1846 +     * @serial include
 54.1847 +     */
 54.1848 +    static class SynchronizedList<E>
 54.1849 +        extends SynchronizedCollection<E>
 54.1850 +        implements List<E> {
 54.1851 +        private static final long serialVersionUID = -7754090372962971524L;
 54.1852 +
 54.1853 +        final List<E> list;
 54.1854 +
 54.1855 +        SynchronizedList(List<E> list) {
 54.1856 +            super(list);
 54.1857 +            this.list = list;
 54.1858 +        }
 54.1859 +        SynchronizedList(List<E> list, Object mutex) {
 54.1860 +            super(list, mutex);
 54.1861 +            this.list = list;
 54.1862 +        }
 54.1863 +
 54.1864 +        public boolean equals(Object o) {
 54.1865 +            synchronized (mutex) {return list.equals(o);}
 54.1866 +        }
 54.1867 +        public int hashCode() {
 54.1868 +            synchronized (mutex) {return list.hashCode();}
 54.1869 +        }
 54.1870 +
 54.1871 +        public E get(int index) {
 54.1872 +            synchronized (mutex) {return list.get(index);}
 54.1873 +        }
 54.1874 +        public E set(int index, E element) {
 54.1875 +            synchronized (mutex) {return list.set(index, element);}
 54.1876 +        }
 54.1877 +        public void add(int index, E element) {
 54.1878 +            synchronized (mutex) {list.add(index, element);}
 54.1879 +        }
 54.1880 +        public E remove(int index) {
 54.1881 +            synchronized (mutex) {return list.remove(index);}
 54.1882 +        }
 54.1883 +
 54.1884 +        public int indexOf(Object o) {
 54.1885 +            synchronized (mutex) {return list.indexOf(o);}
 54.1886 +        }
 54.1887 +        public int lastIndexOf(Object o) {
 54.1888 +            synchronized (mutex) {return list.lastIndexOf(o);}
 54.1889 +        }
 54.1890 +
 54.1891 +        public boolean addAll(int index, Collection<? extends E> c) {
 54.1892 +            synchronized (mutex) {return list.addAll(index, c);}
 54.1893 +        }
 54.1894 +
 54.1895 +        public ListIterator<E> listIterator() {
 54.1896 +            return list.listIterator(); // Must be manually synched by user
 54.1897 +        }
 54.1898 +
 54.1899 +        public ListIterator<E> listIterator(int index) {
 54.1900 +            return list.listIterator(index); // Must be manually synched by user
 54.1901 +        }
 54.1902 +
 54.1903 +        public List<E> subList(int fromIndex, int toIndex) {
 54.1904 +            synchronized (mutex) {
 54.1905 +                return new SynchronizedList<>(list.subList(fromIndex, toIndex),
 54.1906 +                                            mutex);
 54.1907 +            }
 54.1908 +        }
 54.1909 +
 54.1910 +        /**
 54.1911 +         * SynchronizedRandomAccessList instances are serialized as
 54.1912 +         * SynchronizedList instances to allow them to be deserialized
 54.1913 +         * in pre-1.4 JREs (which do not have SynchronizedRandomAccessList).
 54.1914 +         * This method inverts the transformation.  As a beneficial
 54.1915 +         * side-effect, it also grafts the RandomAccess marker onto
 54.1916 +         * SynchronizedList instances that were serialized in pre-1.4 JREs.
 54.1917 +         *
 54.1918 +         * Note: Unfortunately, SynchronizedRandomAccessList instances
 54.1919 +         * serialized in 1.4.1 and deserialized in 1.4 will become
 54.1920 +         * SynchronizedList instances, as this method was missing in 1.4.
 54.1921 +         */
 54.1922 +        private Object readResolve() {
 54.1923 +            return (list instanceof RandomAccess
 54.1924 +                    ? new SynchronizedRandomAccessList<>(list)
 54.1925 +                    : this);
 54.1926 +        }
 54.1927 +    }
 54.1928 +
 54.1929 +    /**
 54.1930 +     * @serial include
 54.1931 +     */
 54.1932 +    static class SynchronizedRandomAccessList<E>
 54.1933 +        extends SynchronizedList<E>
 54.1934 +        implements RandomAccess {
 54.1935 +
 54.1936 +        SynchronizedRandomAccessList(List<E> list) {
 54.1937 +            super(list);
 54.1938 +        }
 54.1939 +
 54.1940 +        SynchronizedRandomAccessList(List<E> list, Object mutex) {
 54.1941 +            super(list, mutex);
 54.1942 +        }
 54.1943 +
 54.1944 +        public List<E> subList(int fromIndex, int toIndex) {
 54.1945 +            synchronized (mutex) {
 54.1946 +                return new SynchronizedRandomAccessList<>(
 54.1947 +                    list.subList(fromIndex, toIndex), mutex);
 54.1948 +            }
 54.1949 +        }
 54.1950 +
 54.1951 +        private static final long serialVersionUID = 1530674583602358482L;
 54.1952 +
 54.1953 +        /**
 54.1954 +         * Allows instances to be deserialized in pre-1.4 JREs (which do
 54.1955 +         * not have SynchronizedRandomAccessList).  SynchronizedList has
 54.1956 +         * a readResolve method that inverts this transformation upon
 54.1957 +         * deserialization.
 54.1958 +         */
 54.1959 +        private Object writeReplace() {
 54.1960 +            return new SynchronizedList<>(list);
 54.1961 +        }
 54.1962 +    }
 54.1963 +
 54.1964 +    /**
 54.1965 +     * Returns a synchronized (thread-safe) map backed by the specified
 54.1966 +     * map.  In order to guarantee serial access, it is critical that
 54.1967 +     * <strong>all</strong> access to the backing map is accomplished
 54.1968 +     * through the returned map.<p>
 54.1969 +     *
 54.1970 +     * It is imperative that the user manually synchronize on the returned
 54.1971 +     * map when iterating over any of its collection views:
 54.1972 +     * <pre>
 54.1973 +     *  Map m = Collections.synchronizedMap(new HashMap());
 54.1974 +     *      ...
 54.1975 +     *  Set s = m.keySet();  // Needn't be in synchronized block
 54.1976 +     *      ...
 54.1977 +     *  synchronized (m) {  // Synchronizing on m, not s!
 54.1978 +     *      Iterator i = s.iterator(); // Must be in synchronized block
 54.1979 +     *      while (i.hasNext())
 54.1980 +     *          foo(i.next());
 54.1981 +     *  }
 54.1982 +     * </pre>
 54.1983 +     * Failure to follow this advice may result in non-deterministic behavior.
 54.1984 +     *
 54.1985 +     * <p>The returned map will be serializable if the specified map is
 54.1986 +     * serializable.
 54.1987 +     *
 54.1988 +     * @param  m the map to be "wrapped" in a synchronized map.
 54.1989 +     * @return a synchronized view of the specified map.
 54.1990 +     */
 54.1991 +    public static <K,V> Map<K,V> synchronizedMap(Map<K,V> m) {
 54.1992 +        return new SynchronizedMap<>(m);
 54.1993 +    }
 54.1994 +
 54.1995 +    /**
 54.1996 +     * @serial include
 54.1997 +     */
 54.1998 +    private static class SynchronizedMap<K,V>
 54.1999 +        implements Map<K,V>, Serializable {
 54.2000 +        private static final long serialVersionUID = 1978198479659022715L;
 54.2001 +
 54.2002 +        private final Map<K,V> m;     // Backing Map
 54.2003 +        final Object      mutex;        // Object on which to synchronize
 54.2004 +
 54.2005 +        SynchronizedMap(Map<K,V> m) {
 54.2006 +            if (m==null)
 54.2007 +                throw new NullPointerException();
 54.2008 +            this.m = m;
 54.2009 +            mutex = this;
 54.2010 +        }
 54.2011 +
 54.2012 +        SynchronizedMap(Map<K,V> m, Object mutex) {
 54.2013 +            this.m = m;
 54.2014 +            this.mutex = mutex;
 54.2015 +        }
 54.2016 +
 54.2017 +        public int size() {
 54.2018 +            synchronized (mutex) {return m.size();}
 54.2019 +        }
 54.2020 +        public boolean isEmpty() {
 54.2021 +            synchronized (mutex) {return m.isEmpty();}
 54.2022 +        }
 54.2023 +        public boolean containsKey(Object key) {
 54.2024 +            synchronized (mutex) {return m.containsKey(key);}
 54.2025 +        }
 54.2026 +        public boolean containsValue(Object value) {
 54.2027 +            synchronized (mutex) {return m.containsValue(value);}
 54.2028 +        }
 54.2029 +        public V get(Object key) {
 54.2030 +            synchronized (mutex) {return m.get(key);}
 54.2031 +        }
 54.2032 +
 54.2033 +        public V put(K key, V value) {
 54.2034 +            synchronized (mutex) {return m.put(key, value);}
 54.2035 +        }
 54.2036 +        public V remove(Object key) {
 54.2037 +            synchronized (mutex) {return m.remove(key);}
 54.2038 +        }
 54.2039 +        public void putAll(Map<? extends K, ? extends V> map) {
 54.2040 +            synchronized (mutex) {m.putAll(map);}
 54.2041 +        }
 54.2042 +        public void clear() {
 54.2043 +            synchronized (mutex) {m.clear();}
 54.2044 +        }
 54.2045 +
 54.2046 +        private transient Set<K> keySet = null;
 54.2047 +        private transient Set<Map.Entry<K,V>> entrySet = null;
 54.2048 +        private transient Collection<V> values = null;
 54.2049 +
 54.2050 +        public Set<K> keySet() {
 54.2051 +            synchronized (mutex) {
 54.2052 +                if (keySet==null)
 54.2053 +                    keySet = new SynchronizedSet<>(m.keySet(), mutex);
 54.2054 +                return keySet;
 54.2055 +            }
 54.2056 +        }
 54.2057 +
 54.2058 +        public Set<Map.Entry<K,V>> entrySet() {
 54.2059 +            synchronized (mutex) {
 54.2060 +                if (entrySet==null)
 54.2061 +                    entrySet = new SynchronizedSet<>(m.entrySet(), mutex);
 54.2062 +                return entrySet;
 54.2063 +            }
 54.2064 +        }
 54.2065 +
 54.2066 +        public Collection<V> values() {
 54.2067 +            synchronized (mutex) {
 54.2068 +                if (values==null)
 54.2069 +                    values = new SynchronizedCollection<>(m.values(), mutex);
 54.2070 +                return values;
 54.2071 +            }
 54.2072 +        }
 54.2073 +
 54.2074 +        public boolean equals(Object o) {
 54.2075 +            synchronized (mutex) {return m.equals(o);}
 54.2076 +        }
 54.2077 +        public int hashCode() {
 54.2078 +            synchronized (mutex) {return m.hashCode();}
 54.2079 +        }
 54.2080 +        public String toString() {
 54.2081 +            synchronized (mutex) {return m.toString();}
 54.2082 +        }
 54.2083 +    }
 54.2084 +
 54.2085 +    /**
 54.2086 +     * Returns a synchronized (thread-safe) sorted map backed by the specified
 54.2087 +     * sorted map.  In order to guarantee serial access, it is critical that
 54.2088 +     * <strong>all</strong> access to the backing sorted map is accomplished
 54.2089 +     * through the returned sorted map (or its views).<p>
 54.2090 +     *
 54.2091 +     * It is imperative that the user manually synchronize on the returned
 54.2092 +     * sorted map when iterating over any of its collection views, or the
 54.2093 +     * collections views of any of its <tt>subMap</tt>, <tt>headMap</tt> or
 54.2094 +     * <tt>tailMap</tt> views.
 54.2095 +     * <pre>
 54.2096 +     *  SortedMap m = Collections.synchronizedSortedMap(new TreeMap());
 54.2097 +     *      ...
 54.2098 +     *  Set s = m.keySet();  // Needn't be in synchronized block
 54.2099 +     *      ...
 54.2100 +     *  synchronized (m) {  // Synchronizing on m, not s!
 54.2101 +     *      Iterator i = s.iterator(); // Must be in synchronized block
 54.2102 +     *      while (i.hasNext())
 54.2103 +     *          foo(i.next());
 54.2104 +     *  }
 54.2105 +     * </pre>
 54.2106 +     * or:
 54.2107 +     * <pre>
 54.2108 +     *  SortedMap m = Collections.synchronizedSortedMap(new TreeMap());
 54.2109 +     *  SortedMap m2 = m.subMap(foo, bar);
 54.2110 +     *      ...
 54.2111 +     *  Set s2 = m2.keySet();  // Needn't be in synchronized block
 54.2112 +     *      ...
 54.2113 +     *  synchronized (m) {  // Synchronizing on m, not m2 or s2!
 54.2114 +     *      Iterator i = s.iterator(); // Must be in synchronized block
 54.2115 +     *      while (i.hasNext())
 54.2116 +     *          foo(i.next());
 54.2117 +     *  }
 54.2118 +     * </pre>
 54.2119 +     * Failure to follow this advice may result in non-deterministic behavior.
 54.2120 +     *
 54.2121 +     * <p>The returned sorted map will be serializable if the specified
 54.2122 +     * sorted map is serializable.
 54.2123 +     *
 54.2124 +     * @param  m the sorted map to be "wrapped" in a synchronized sorted map.
 54.2125 +     * @return a synchronized view of the specified sorted map.
 54.2126 +     */
 54.2127 +    public static <K,V> SortedMap<K,V> synchronizedSortedMap(SortedMap<K,V> m) {
 54.2128 +        return new SynchronizedSortedMap<>(m);
 54.2129 +    }
 54.2130 +
 54.2131 +
 54.2132 +    /**
 54.2133 +     * @serial include
 54.2134 +     */
 54.2135 +    static class SynchronizedSortedMap<K,V>
 54.2136 +        extends SynchronizedMap<K,V>
 54.2137 +        implements SortedMap<K,V>
 54.2138 +    {
 54.2139 +        private static final long serialVersionUID = -8798146769416483793L;
 54.2140 +
 54.2141 +        private final SortedMap<K,V> sm;
 54.2142 +
 54.2143 +        SynchronizedSortedMap(SortedMap<K,V> m) {
 54.2144 +            super(m);
 54.2145 +            sm = m;
 54.2146 +        }
 54.2147 +        SynchronizedSortedMap(SortedMap<K,V> m, Object mutex) {
 54.2148 +            super(m, mutex);
 54.2149 +            sm = m;
 54.2150 +        }
 54.2151 +
 54.2152 +        public Comparator<? super K> comparator() {
 54.2153 +            synchronized (mutex) {return sm.comparator();}
 54.2154 +        }
 54.2155 +
 54.2156 +        public SortedMap<K,V> subMap(K fromKey, K toKey) {
 54.2157 +            synchronized (mutex) {
 54.2158 +                return new SynchronizedSortedMap<>(
 54.2159 +                    sm.subMap(fromKey, toKey), mutex);
 54.2160 +            }
 54.2161 +        }
 54.2162 +        public SortedMap<K,V> headMap(K toKey) {
 54.2163 +            synchronized (mutex) {
 54.2164 +                return new SynchronizedSortedMap<>(sm.headMap(toKey), mutex);
 54.2165 +            }
 54.2166 +        }
 54.2167 +        public SortedMap<K,V> tailMap(K fromKey) {
 54.2168 +            synchronized (mutex) {
 54.2169 +               return new SynchronizedSortedMap<>(sm.tailMap(fromKey),mutex);
 54.2170 +            }
 54.2171 +        }
 54.2172 +
 54.2173 +        public K firstKey() {
 54.2174 +            synchronized (mutex) {return sm.firstKey();}
 54.2175 +        }
 54.2176 +        public K lastKey() {
 54.2177 +            synchronized (mutex) {return sm.lastKey();}
 54.2178 +        }
 54.2179 +    }
 54.2180 +
 54.2181 +    // Dynamically typesafe collection wrappers
 54.2182 +
 54.2183 +    /**
 54.2184 +     * Returns a dynamically typesafe view of the specified collection.
 54.2185 +     * Any attempt to insert an element of the wrong type will result in an
 54.2186 +     * immediate {@link ClassCastException}.  Assuming a collection
 54.2187 +     * contains no incorrectly typed elements prior to the time a
 54.2188 +     * dynamically typesafe view is generated, and that all subsequent
 54.2189 +     * access to the collection takes place through the view, it is
 54.2190 +     * <i>guaranteed</i> that the collection cannot contain an incorrectly
 54.2191 +     * typed element.
 54.2192 +     *
 54.2193 +     * <p>The generics mechanism in the language provides compile-time
 54.2194 +     * (static) type checking, but it is possible to defeat this mechanism
 54.2195 +     * with unchecked casts.  Usually this is not a problem, as the compiler
 54.2196 +     * issues warnings on all such unchecked operations.  There are, however,
 54.2197 +     * times when static type checking alone is not sufficient.  For example,
 54.2198 +     * suppose a collection is passed to a third-party library and it is
 54.2199 +     * imperative that the library code not corrupt the collection by
 54.2200 +     * inserting an element of the wrong type.
 54.2201 +     *
 54.2202 +     * <p>Another use of dynamically typesafe views is debugging.  Suppose a
 54.2203 +     * program fails with a {@code ClassCastException}, indicating that an
 54.2204 +     * incorrectly typed element was put into a parameterized collection.
 54.2205 +     * Unfortunately, the exception can occur at any time after the erroneous
 54.2206 +     * element is inserted, so it typically provides little or no information
 54.2207 +     * as to the real source of the problem.  If the problem is reproducible,
 54.2208 +     * one can quickly determine its source by temporarily modifying the
 54.2209 +     * program to wrap the collection with a dynamically typesafe view.
 54.2210 +     * For example, this declaration:
 54.2211 +     *  <pre> {@code
 54.2212 +     *     Collection<String> c = new HashSet<String>();
 54.2213 +     * }</pre>
 54.2214 +     * may be replaced temporarily by this one:
 54.2215 +     *  <pre> {@code
 54.2216 +     *     Collection<String> c = Collections.checkedCollection(
 54.2217 +     *         new HashSet<String>(), String.class);
 54.2218 +     * }</pre>
 54.2219 +     * Running the program again will cause it to fail at the point where
 54.2220 +     * an incorrectly typed element is inserted into the collection, clearly
 54.2221 +     * identifying the source of the problem.  Once the problem is fixed, the
 54.2222 +     * modified declaration may be reverted back to the original.
 54.2223 +     *
 54.2224 +     * <p>The returned collection does <i>not</i> pass the hashCode and equals
 54.2225 +     * operations through to the backing collection, but relies on
 54.2226 +     * {@code Object}'s {@code equals} and {@code hashCode} methods.  This
 54.2227 +     * is necessary to preserve the contracts of these operations in the case
 54.2228 +     * that the backing collection is a set or a list.
 54.2229 +     *
 54.2230 +     * <p>The returned collection will be serializable if the specified
 54.2231 +     * collection is serializable.
 54.2232 +     *
 54.2233 +     * <p>Since {@code null} is considered to be a value of any reference
 54.2234 +     * type, the returned collection permits insertion of null elements
 54.2235 +     * whenever the backing collection does.
 54.2236 +     *
 54.2237 +     * @param c the collection for which a dynamically typesafe view is to be
 54.2238 +     *          returned
 54.2239 +     * @param type the type of element that {@code c} is permitted to hold
 54.2240 +     * @return a dynamically typesafe view of the specified collection
 54.2241 +     * @since 1.5
 54.2242 +     */
 54.2243 +    public static <E> Collection<E> checkedCollection(Collection<E> c,
 54.2244 +                                                      Class<E> type) {
 54.2245 +        return new CheckedCollection<>(c, type);
 54.2246 +    }
 54.2247 +
 54.2248 +    @SuppressWarnings("unchecked")
 54.2249 +    static <T> T[] zeroLengthArray(Class<T> type) {
 54.2250 +        return (T[]) Array.newInstance(type, 0);
 54.2251 +    }
 54.2252 +
 54.2253 +    /**
 54.2254 +     * @serial include
 54.2255 +     */
 54.2256 +    static class CheckedCollection<E> implements Collection<E>, Serializable {
 54.2257 +        private static final long serialVersionUID = 1578914078182001775L;
 54.2258 +
 54.2259 +        final Collection<E> c;
 54.2260 +        final Class<E> type;
 54.2261 +
 54.2262 +        void typeCheck(Object o) {
 54.2263 +            if (o != null && !type.isInstance(o))
 54.2264 +                throw new ClassCastException(badElementMsg(o));
 54.2265 +        }
 54.2266 +
 54.2267 +        private String badElementMsg(Object o) {
 54.2268 +            return "Attempt to insert " + o.getClass() +
 54.2269 +                " element into collection with element type " + type;
 54.2270 +        }
 54.2271 +
 54.2272 +        CheckedCollection(Collection<E> c, Class<E> type) {
 54.2273 +            if (c==null || type == null)
 54.2274 +                throw new NullPointerException();
 54.2275 +            this.c = c;
 54.2276 +            this.type = type;
 54.2277 +        }
 54.2278 +
 54.2279 +        public int size()                 { return c.size(); }
 54.2280 +        public boolean isEmpty()          { return c.isEmpty(); }
 54.2281 +        public boolean contains(Object o) { return c.contains(o); }
 54.2282 +        public Object[] toArray()         { return c.toArray(); }
 54.2283 +        public <T> T[] toArray(T[] a)     { return c.toArray(a); }
 54.2284 +        public String toString()          { return c.toString(); }
 54.2285 +        public boolean remove(Object o)   { return c.remove(o); }
 54.2286 +        public void clear()               {        c.clear(); }
 54.2287 +
 54.2288 +        public boolean containsAll(Collection<?> coll) {
 54.2289 +            return c.containsAll(coll);
 54.2290 +        }
 54.2291 +        public boolean removeAll(Collection<?> coll) {
 54.2292 +            return c.removeAll(coll);
 54.2293 +        }
 54.2294 +        public boolean retainAll(Collection<?> coll) {
 54.2295 +            return c.retainAll(coll);
 54.2296 +        }
 54.2297 +
 54.2298 +        public Iterator<E> iterator() {
 54.2299 +            final Iterator<E> it = c.iterator();
 54.2300 +            return new Iterator<E>() {
 54.2301 +                public boolean hasNext() { return it.hasNext(); }
 54.2302 +                public E next()          { return it.next(); }
 54.2303 +                public void remove()     {        it.remove(); }};
 54.2304 +        }
 54.2305 +
 54.2306 +        public boolean add(E e) {
 54.2307 +            typeCheck(e);
 54.2308 +            return c.add(e);
 54.2309 +        }
 54.2310 +
 54.2311 +        private E[] zeroLengthElementArray = null; // Lazily initialized
 54.2312 +
 54.2313 +        private E[] zeroLengthElementArray() {
 54.2314 +            return zeroLengthElementArray != null ? zeroLengthElementArray :
 54.2315 +                (zeroLengthElementArray = zeroLengthArray(type));
 54.2316 +        }
 54.2317 +
 54.2318 +        @SuppressWarnings("unchecked")
 54.2319 +        Collection<E> checkedCopyOf(Collection<? extends E> coll) {
 54.2320 +            Object[] a = null;
 54.2321 +            try {
 54.2322 +                E[] z = zeroLengthElementArray();
 54.2323 +                a = coll.toArray(z);
 54.2324 +                // Defend against coll violating the toArray contract
 54.2325 +                if (a.getClass() != z.getClass())
 54.2326 +                    a = Arrays.copyOf(a, a.length, z.getClass());
 54.2327 +            } catch (ArrayStoreException ignore) {
 54.2328 +                // To get better and consistent diagnostics,
 54.2329 +                // we call typeCheck explicitly on each element.
 54.2330 +                // We call clone() to defend against coll retaining a
 54.2331 +                // reference to the returned array and storing a bad
 54.2332 +                // element into it after it has been type checked.
 54.2333 +                a = coll.toArray().clone();
 54.2334 +                for (Object o : a)
 54.2335 +                    typeCheck(o);
 54.2336 +            }
 54.2337 +            // A slight abuse of the type system, but safe here.
 54.2338 +            return (Collection<E>) Arrays.asList(a);
 54.2339 +        }
 54.2340 +
 54.2341 +        public boolean addAll(Collection<? extends E> coll) {
 54.2342 +            // Doing things this way insulates us from concurrent changes
 54.2343 +            // in the contents of coll and provides all-or-nothing
 54.2344 +            // semantics (which we wouldn't get if we type-checked each
 54.2345 +            // element as we added it)
 54.2346 +            return c.addAll(checkedCopyOf(coll));
 54.2347 +        }
 54.2348 +    }
 54.2349 +
 54.2350 +    /**
 54.2351 +     * Returns a dynamically typesafe view of the specified set.
 54.2352 +     * Any attempt to insert an element of the wrong type will result in
 54.2353 +     * an immediate {@link ClassCastException}.  Assuming a set contains
 54.2354 +     * no incorrectly typed elements prior to the time a dynamically typesafe
 54.2355 +     * view is generated, and that all subsequent access to the set
 54.2356 +     * takes place through the view, it is <i>guaranteed</i> that the
 54.2357 +     * set cannot contain an incorrectly typed element.
 54.2358 +     *
 54.2359 +     * <p>A discussion of the use of dynamically typesafe views may be
 54.2360 +     * found in the documentation for the {@link #checkedCollection
 54.2361 +     * checkedCollection} method.
 54.2362 +     *
 54.2363 +     * <p>The returned set will be serializable if the specified set is
 54.2364 +     * serializable.
 54.2365 +     *
 54.2366 +     * <p>Since {@code null} is considered to be a value of any reference
 54.2367 +     * type, the returned set permits insertion of null elements whenever
 54.2368 +     * the backing set does.
 54.2369 +     *
 54.2370 +     * @param s the set for which a dynamically typesafe view is to be
 54.2371 +     *          returned
 54.2372 +     * @param type the type of element that {@code s} is permitted to hold
 54.2373 +     * @return a dynamically typesafe view of the specified set
 54.2374 +     * @since 1.5
 54.2375 +     */
 54.2376 +    public static <E> Set<E> checkedSet(Set<E> s, Class<E> type) {
 54.2377 +        return new CheckedSet<>(s, type);
 54.2378 +    }
 54.2379 +
 54.2380 +    /**
 54.2381 +     * @serial include
 54.2382 +     */
 54.2383 +    static class CheckedSet<E> extends CheckedCollection<E>
 54.2384 +                                 implements Set<E>, Serializable
 54.2385 +    {
 54.2386 +        private static final long serialVersionUID = 4694047833775013803L;
 54.2387 +
 54.2388 +        CheckedSet(Set<E> s, Class<E> elementType) { super(s, elementType); }
 54.2389 +
 54.2390 +        public boolean equals(Object o) { return o == this || c.equals(o); }
 54.2391 +        public int hashCode()           { return c.hashCode(); }
 54.2392 +    }
 54.2393 +
 54.2394 +    /**
 54.2395 +     * Returns a dynamically typesafe view of the specified sorted set.
 54.2396 +     * Any attempt to insert an element of the wrong type will result in an
 54.2397 +     * immediate {@link ClassCastException}.  Assuming a sorted set
 54.2398 +     * contains no incorrectly typed elements prior to the time a
 54.2399 +     * dynamically typesafe view is generated, and that all subsequent
 54.2400 +     * access to the sorted set takes place through the view, it is
 54.2401 +     * <i>guaranteed</i> that the sorted set cannot contain an incorrectly
 54.2402 +     * typed element.
 54.2403 +     *
 54.2404 +     * <p>A discussion of the use of dynamically typesafe views may be
 54.2405 +     * found in the documentation for the {@link #checkedCollection
 54.2406 +     * checkedCollection} method.
 54.2407 +     *
 54.2408 +     * <p>The returned sorted set will be serializable if the specified sorted
 54.2409 +     * set is serializable.
 54.2410 +     *
 54.2411 +     * <p>Since {@code null} is considered to be a value of any reference
 54.2412 +     * type, the returned sorted set permits insertion of null elements
 54.2413 +     * whenever the backing sorted set does.
 54.2414 +     *
 54.2415 +     * @param s the sorted set for which a dynamically typesafe view is to be
 54.2416 +     *          returned
 54.2417 +     * @param type the type of element that {@code s} is permitted to hold
 54.2418 +     * @return a dynamically typesafe view of the specified sorted set
 54.2419 +     * @since 1.5
 54.2420 +     */
 54.2421 +    public static <E> SortedSet<E> checkedSortedSet(SortedSet<E> s,
 54.2422 +                                                    Class<E> type) {
 54.2423 +        return new CheckedSortedSet<>(s, type);
 54.2424 +    }
 54.2425 +
 54.2426 +    /**
 54.2427 +     * @serial include
 54.2428 +     */
 54.2429 +    static class CheckedSortedSet<E> extends CheckedSet<E>
 54.2430 +        implements SortedSet<E>, Serializable
 54.2431 +    {
 54.2432 +        private static final long serialVersionUID = 1599911165492914959L;
 54.2433 +        private final SortedSet<E> ss;
 54.2434 +
 54.2435 +        CheckedSortedSet(SortedSet<E> s, Class<E> type) {
 54.2436 +            super(s, type);
 54.2437 +            ss = s;
 54.2438 +        }
 54.2439 +
 54.2440 +        public Comparator<? super E> comparator() { return ss.comparator(); }
 54.2441 +        public E first()                   { return ss.first(); }
 54.2442 +        public E last()                    { return ss.last(); }
 54.2443 +
 54.2444 +        public SortedSet<E> subSet(E fromElement, E toElement) {
 54.2445 +            return checkedSortedSet(ss.subSet(fromElement,toElement), type);
 54.2446 +        }
 54.2447 +        public SortedSet<E> headSet(E toElement) {
 54.2448 +            return checkedSortedSet(ss.headSet(toElement), type);
 54.2449 +        }
 54.2450 +        public SortedSet<E> tailSet(E fromElement) {
 54.2451 +            return checkedSortedSet(ss.tailSet(fromElement), type);
 54.2452 +        }
 54.2453 +    }
 54.2454 +
 54.2455 +    /**
 54.2456 +     * Returns a dynamically typesafe view of the specified list.
 54.2457 +     * Any attempt to insert an element of the wrong type will result in
 54.2458 +     * an immediate {@link ClassCastException}.  Assuming a list contains
 54.2459 +     * no incorrectly typed elements prior to the time a dynamically typesafe
 54.2460 +     * view is generated, and that all subsequent access to the list
 54.2461 +     * takes place through the view, it is <i>guaranteed</i> that the
 54.2462 +     * list cannot contain an incorrectly typed element.
 54.2463 +     *
 54.2464 +     * <p>A discussion of the use of dynamically typesafe views may be
 54.2465 +     * found in the documentation for the {@link #checkedCollection
 54.2466 +     * checkedCollection} method.
 54.2467 +     *
 54.2468 +     * <p>The returned list will be serializable if the specified list
 54.2469 +     * is serializable.
 54.2470 +     *
 54.2471 +     * <p>Since {@code null} is considered to be a value of any reference
 54.2472 +     * type, the returned list permits insertion of null elements whenever
 54.2473 +     * the backing list does.
 54.2474 +     *
 54.2475 +     * @param list the list for which a dynamically typesafe view is to be
 54.2476 +     *             returned
 54.2477 +     * @param type the type of element that {@code list} is permitted to hold
 54.2478 +     * @return a dynamically typesafe view of the specified list
 54.2479 +     * @since 1.5
 54.2480 +     */
 54.2481 +    public static <E> List<E> checkedList(List<E> list, Class<E> type) {
 54.2482 +        return (list instanceof RandomAccess ?
 54.2483 +                new CheckedRandomAccessList<>(list, type) :
 54.2484 +                new CheckedList<>(list, type));
 54.2485 +    }
 54.2486 +
 54.2487 +    /**
 54.2488 +     * @serial include
 54.2489 +     */
 54.2490 +    static class CheckedList<E>
 54.2491 +        extends CheckedCollection<E>
 54.2492 +        implements List<E>
 54.2493 +    {
 54.2494 +        private static final long serialVersionUID = 65247728283967356L;
 54.2495 +        final List<E> list;
 54.2496 +
 54.2497 +        CheckedList(List<E> list, Class<E> type) {
 54.2498 +            super(list, type);
 54.2499 +            this.list = list;
 54.2500 +        }
 54.2501 +
 54.2502 +        public boolean equals(Object o)  { return o == this || list.equals(o); }
 54.2503 +        public int hashCode()            { return list.hashCode(); }
 54.2504 +        public E get(int index)          { return list.get(index); }
 54.2505 +        public E remove(int index)       { return list.remove(index); }
 54.2506 +        public int indexOf(Object o)     { return list.indexOf(o); }
 54.2507 +        public int lastIndexOf(Object o) { return list.lastIndexOf(o); }
 54.2508 +
 54.2509 +        public E set(int index, E element) {
 54.2510 +            typeCheck(element);
 54.2511 +            return list.set(index, element);
 54.2512 +        }
 54.2513 +
 54.2514 +        public void add(int index, E element) {
 54.2515 +            typeCheck(element);
 54.2516 +            list.add(index, element);
 54.2517 +        }
 54.2518 +
 54.2519 +        public boolean addAll(int index, Collection<? extends E> c) {
 54.2520 +            return list.addAll(index, checkedCopyOf(c));
 54.2521 +        }
 54.2522 +        public ListIterator<E> listIterator()   { return listIterator(0); }
 54.2523 +
 54.2524 +        public ListIterator<E> listIterator(final int index) {
 54.2525 +            final ListIterator<E> i = list.listIterator(index);
 54.2526 +
 54.2527 +            return new ListIterator<E>() {
 54.2528 +                public boolean hasNext()     { return i.hasNext(); }
 54.2529 +                public E next()              { return i.next(); }
 54.2530 +                public boolean hasPrevious() { return i.hasPrevious(); }
 54.2531 +                public E previous()          { return i.previous(); }
 54.2532 +                public int nextIndex()       { return i.nextIndex(); }
 54.2533 +                public int previousIndex()   { return i.previousIndex(); }
 54.2534 +                public void remove()         {        i.remove(); }
 54.2535 +
 54.2536 +                public void set(E e) {
 54.2537 +                    typeCheck(e);
 54.2538 +                    i.set(e);
 54.2539 +                }
 54.2540 +
 54.2541 +                public void add(E e) {
 54.2542 +                    typeCheck(e);
 54.2543 +                    i.add(e);
 54.2544 +                }
 54.2545 +            };
 54.2546 +        }
 54.2547 +
 54.2548 +        public List<E> subList(int fromIndex, int toIndex) {
 54.2549 +            return new CheckedList<>(list.subList(fromIndex, toIndex), type);
 54.2550 +        }
 54.2551 +    }
 54.2552 +
 54.2553 +    /**
 54.2554 +     * @serial include
 54.2555 +     */
 54.2556 +    static class CheckedRandomAccessList<E> extends CheckedList<E>
 54.2557 +                                            implements RandomAccess
 54.2558 +    {
 54.2559 +        private static final long serialVersionUID = 1638200125423088369L;
 54.2560 +
 54.2561 +        CheckedRandomAccessList(List<E> list, Class<E> type) {
 54.2562 +            super(list, type);
 54.2563 +        }
 54.2564 +
 54.2565 +        public List<E> subList(int fromIndex, int toIndex) {
 54.2566 +            return new CheckedRandomAccessList<>(
 54.2567 +                list.subList(fromIndex, toIndex), type);
 54.2568 +        }
 54.2569 +    }
 54.2570 +
 54.2571 +    /**
 54.2572 +     * Returns a dynamically typesafe view of the specified map.
 54.2573 +     * Any attempt to insert a mapping whose key or value have the wrong
 54.2574 +     * type will result in an immediate {@link ClassCastException}.
 54.2575 +     * Similarly, any attempt to modify the value currently associated with
 54.2576 +     * a key will result in an immediate {@link ClassCastException},
 54.2577 +     * whether the modification is attempted directly through the map
 54.2578 +     * itself, or through a {@link Map.Entry} instance obtained from the
 54.2579 +     * map's {@link Map#entrySet() entry set} view.
 54.2580 +     *
 54.2581 +     * <p>Assuming a map contains no incorrectly typed keys or values
 54.2582 +     * prior to the time a dynamically typesafe view is generated, and
 54.2583 +     * that all subsequent access to the map takes place through the view
 54.2584 +     * (or one of its collection views), it is <i>guaranteed</i> that the
 54.2585 +     * map cannot contain an incorrectly typed key or value.
 54.2586 +     *
 54.2587 +     * <p>A discussion of the use of dynamically typesafe views may be
 54.2588 +     * found in the documentation for the {@link #checkedCollection
 54.2589 +     * checkedCollection} method.
 54.2590 +     *
 54.2591 +     * <p>The returned map will be serializable if the specified map is
 54.2592 +     * serializable.
 54.2593 +     *
 54.2594 +     * <p>Since {@code null} is considered to be a value of any reference
 54.2595 +     * type, the returned map permits insertion of null keys or values
 54.2596 +     * whenever the backing map does.
 54.2597 +     *
 54.2598 +     * @param m the map for which a dynamically typesafe view is to be
 54.2599 +     *          returned
 54.2600 +     * @param keyType the type of key that {@code m} is permitted to hold
 54.2601 +     * @param valueType the type of value that {@code m} is permitted to hold
 54.2602 +     * @return a dynamically typesafe view of the specified map
 54.2603 +     * @since 1.5
 54.2604 +     */
 54.2605 +    public static <K, V> Map<K, V> checkedMap(Map<K, V> m,
 54.2606 +                                              Class<K> keyType,
 54.2607 +                                              Class<V> valueType) {
 54.2608 +        return new CheckedMap<>(m, keyType, valueType);
 54.2609 +    }
 54.2610 +
 54.2611 +
 54.2612 +    /**
 54.2613 +     * @serial include
 54.2614 +     */
 54.2615 +    private static class CheckedMap<K,V>
 54.2616 +        implements Map<K,V>, Serializable
 54.2617 +    {
 54.2618 +        private static final long serialVersionUID = 5742860141034234728L;
 54.2619 +
 54.2620 +        private final Map<K, V> m;
 54.2621 +        final Class<K> keyType;
 54.2622 +        final Class<V> valueType;
 54.2623 +
 54.2624 +        private void typeCheck(Object key, Object value) {
 54.2625 +            if (key != null && !keyType.isInstance(key))
 54.2626 +                throw new ClassCastException(badKeyMsg(key));
 54.2627 +
 54.2628 +            if (value != null && !valueType.isInstance(value))
 54.2629 +                throw new ClassCastException(badValueMsg(value));
 54.2630 +        }
 54.2631 +
 54.2632 +        private String badKeyMsg(Object key) {
 54.2633 +            return "Attempt to insert " + key.getClass() +
 54.2634 +                " key into map with key type " + keyType;
 54.2635 +        }
 54.2636 +
 54.2637 +        private String badValueMsg(Object value) {
 54.2638 +            return "Attempt to insert " + value.getClass() +
 54.2639 +                " value into map with value type " + valueType;
 54.2640 +        }
 54.2641 +
 54.2642 +        CheckedMap(Map<K, V> m, Class<K> keyType, Class<V> valueType) {
 54.2643 +            if (m == null || keyType == null || valueType == null)
 54.2644 +                throw new NullPointerException();
 54.2645 +            this.m = m;
 54.2646 +            this.keyType = keyType;
 54.2647 +            this.valueType = valueType;
 54.2648 +        }
 54.2649 +
 54.2650 +        public int size()                      { return m.size(); }
 54.2651 +        public boolean isEmpty()               { return m.isEmpty(); }
 54.2652 +        public boolean containsKey(Object key) { return m.containsKey(key); }
 54.2653 +        public boolean containsValue(Object v) { return m.containsValue(v); }
 54.2654 +        public V get(Object key)               { return m.get(key); }
 54.2655 +        public V remove(Object key)            { return m.remove(key); }
 54.2656 +        public void clear()                    { m.clear(); }
 54.2657 +        public Set<K> keySet()                 { return m.keySet(); }
 54.2658 +        public Collection<V> values()          { return m.values(); }
 54.2659 +        public boolean equals(Object o)        { return o == this || m.equals(o); }
 54.2660 +        public int hashCode()                  { return m.hashCode(); }
 54.2661 +        public String toString()               { return m.toString(); }
 54.2662 +
 54.2663 +        public V put(K key, V value) {
 54.2664 +            typeCheck(key, value);
 54.2665 +            return m.put(key, value);
 54.2666 +        }
 54.2667 +
 54.2668 +        @SuppressWarnings("unchecked")
 54.2669 +        public void putAll(Map<? extends K, ? extends V> t) {
 54.2670 +            // Satisfy the following goals:
 54.2671 +            // - good diagnostics in case of type mismatch
 54.2672 +            // - all-or-nothing semantics
 54.2673 +            // - protection from malicious t
 54.2674 +            // - correct behavior if t is a concurrent map
 54.2675 +            Object[] entries = t.entrySet().toArray();
 54.2676 +            List<Map.Entry<K,V>> checked = new ArrayList<>(entries.length);
 54.2677 +            for (Object o : entries) {
 54.2678 +                Map.Entry<?,?> e = (Map.Entry<?,?>) o;
 54.2679 +                Object k = e.getKey();
 54.2680 +                Object v = e.getValue();
 54.2681 +                typeCheck(k, v);
 54.2682 +                checked.add(
 54.2683 +                    new AbstractMap.SimpleImmutableEntry<>((K) k, (V) v));
 54.2684 +            }
 54.2685 +            for (Map.Entry<K,V> e : checked)
 54.2686 +                m.put(e.getKey(), e.getValue());
 54.2687 +        }
 54.2688 +
 54.2689 +        private transient Set<Map.Entry<K,V>> entrySet = null;
 54.2690 +
 54.2691 +        public Set<Map.Entry<K,V>> entrySet() {
 54.2692 +            if (entrySet==null)
 54.2693 +                entrySet = new CheckedEntrySet<>(m.entrySet(), valueType);
 54.2694 +            return entrySet;
 54.2695 +        }
 54.2696 +
 54.2697 +        /**
 54.2698 +         * We need this class in addition to CheckedSet as Map.Entry permits
 54.2699 +         * modification of the backing Map via the setValue operation.  This
 54.2700 +         * class is subtle: there are many possible attacks that must be
 54.2701 +         * thwarted.
 54.2702 +         *
 54.2703 +         * @serial exclude
 54.2704 +         */
 54.2705 +        static class CheckedEntrySet<K,V> implements Set<Map.Entry<K,V>> {
 54.2706 +            private final Set<Map.Entry<K,V>> s;
 54.2707 +            private final Class<V> valueType;
 54.2708 +
 54.2709 +            CheckedEntrySet(Set<Map.Entry<K, V>> s, Class<V> valueType) {
 54.2710 +                this.s = s;
 54.2711 +                this.valueType = valueType;
 54.2712 +            }
 54.2713 +
 54.2714 +            public int size()        { return s.size(); }
 54.2715 +            public boolean isEmpty() { return s.isEmpty(); }
 54.2716 +            public String toString() { return s.toString(); }
 54.2717 +            public int hashCode()    { return s.hashCode(); }
 54.2718 +            public void clear()      {        s.clear(); }
 54.2719 +
 54.2720 +            public boolean add(Map.Entry<K, V> e) {
 54.2721 +                throw new UnsupportedOperationException();
 54.2722 +            }
 54.2723 +            public boolean addAll(Collection<? extends Map.Entry<K, V>> coll) {
 54.2724 +                throw new UnsupportedOperationException();
 54.2725 +            }
 54.2726 +
 54.2727 +            public Iterator<Map.Entry<K,V>> iterator() {
 54.2728 +                final Iterator<Map.Entry<K, V>> i = s.iterator();
 54.2729 +                final Class<V> valueType = this.valueType;
 54.2730 +
 54.2731 +                return new Iterator<Map.Entry<K,V>>() {
 54.2732 +                    public boolean hasNext() { return i.hasNext(); }
 54.2733 +                    public void remove()     { i.remove(); }
 54.2734 +
 54.2735 +                    public Map.Entry<K,V> next() {
 54.2736 +                        return checkedEntry(i.next(), valueType);
 54.2737 +                    }
 54.2738 +                };
 54.2739 +            }
 54.2740 +
 54.2741 +            @SuppressWarnings("unchecked")
 54.2742 +            public Object[] toArray() {
 54.2743 +                Object[] source = s.toArray();
 54.2744 +
 54.2745 +                /*
 54.2746 +                 * Ensure that we don't get an ArrayStoreException even if
 54.2747 +                 * s.toArray returns an array of something other than Object
 54.2748 +                 */
 54.2749 +                Object[] dest = (CheckedEntry.class.isInstance(
 54.2750 +                    source.getClass().getComponentType()) ? source :
 54.2751 +                                 new Object[source.length]);
 54.2752 +
 54.2753 +                for (int i = 0; i < source.length; i++)
 54.2754 +                    dest[i] = checkedEntry((Map.Entry<K,V>)source[i],
 54.2755 +                                           valueType);
 54.2756 +                return dest;
 54.2757 +            }
 54.2758 +
 54.2759 +            @SuppressWarnings("unchecked")
 54.2760 +            public <T> T[] toArray(T[] a) {
 54.2761 +                // We don't pass a to s.toArray, to avoid window of
 54.2762 +                // vulnerability wherein an unscrupulous multithreaded client
 54.2763 +                // could get his hands on raw (unwrapped) Entries from s.
 54.2764 +                T[] arr = s.toArray(a.length==0 ? a : Arrays.copyOf(a, 0));
 54.2765 +
 54.2766 +                for (int i=0; i<arr.length; i++)
 54.2767 +                    arr[i] = (T) checkedEntry((Map.Entry<K,V>)arr[i],
 54.2768 +                                              valueType);
 54.2769 +                if (arr.length > a.length)
 54.2770 +                    return arr;
 54.2771 +
 54.2772 +                System.arraycopy(arr, 0, a, 0, arr.length);
 54.2773 +                if (a.length > arr.length)
 54.2774 +                    a[arr.length] = null;
 54.2775 +                return a;
 54.2776 +            }
 54.2777 +
 54.2778 +            /**
 54.2779 +             * This method is overridden to protect the backing set against
 54.2780 +             * an object with a nefarious equals function that senses
 54.2781 +             * that the equality-candidate is Map.Entry and calls its
 54.2782 +             * setValue method.
 54.2783 +             */
 54.2784 +            public boolean contains(Object o) {
 54.2785 +                if (!(o instanceof Map.Entry))
 54.2786 +                    return false;
 54.2787 +                Map.Entry<?,?> e = (Map.Entry<?,?>) o;
 54.2788 +                return s.contains(
 54.2789 +                    (e instanceof CheckedEntry) ? e : checkedEntry(e, valueType));
 54.2790 +            }
 54.2791 +
 54.2792 +            /**
 54.2793 +             * The bulk collection methods are overridden to protect
 54.2794 +             * against an unscrupulous collection whose contains(Object o)
 54.2795 +             * method senses when o is a Map.Entry, and calls o.setValue.
 54.2796 +             */
 54.2797 +            public boolean containsAll(Collection<?> c) {
 54.2798 +                for (Object o : c)
 54.2799 +                    if (!contains(o)) // Invokes safe contains() above
 54.2800 +                        return false;
 54.2801 +                return true;
 54.2802 +            }
 54.2803 +
 54.2804 +            public boolean remove(Object o) {
 54.2805 +                if (!(o instanceof Map.Entry))
 54.2806 +                    return false;
 54.2807 +                return s.remove(new AbstractMap.SimpleImmutableEntry
 54.2808 +                                <>((Map.Entry<?,?>)o));
 54.2809 +            }
 54.2810 +
 54.2811 +            public boolean removeAll(Collection<?> c) {
 54.2812 +                return batchRemove(c, false);
 54.2813 +            }
 54.2814 +            public boolean retainAll(Collection<?> c) {
 54.2815 +                return batchRemove(c, true);
 54.2816 +            }
 54.2817 +            private boolean batchRemove(Collection<?> c, boolean complement) {
 54.2818 +                boolean modified = false;
 54.2819 +                Iterator<Map.Entry<K,V>> it = iterator();
 54.2820 +                while (it.hasNext()) {
 54.2821 +                    if (c.contains(it.next()) != complement) {
 54.2822 +                        it.remove();
 54.2823 +                        modified = true;
 54.2824 +                    }
 54.2825 +                }
 54.2826 +                return modified;
 54.2827 +            }
 54.2828 +
 54.2829 +            public boolean equals(Object o) {
 54.2830 +                if (o == this)
 54.2831 +                    return true;
 54.2832 +                if (!(o instanceof Set))
 54.2833 +                    return false;
 54.2834 +                Set<?> that = (Set<?>) o;
 54.2835 +                return that.size() == s.size()
 54.2836 +                    && containsAll(that); // Invokes safe containsAll() above
 54.2837 +            }
 54.2838 +
 54.2839 +            static <K,V,T> CheckedEntry<K,V,T> checkedEntry(Map.Entry<K,V> e,
 54.2840 +                                                            Class<T> valueType) {
 54.2841 +                return new CheckedEntry<>(e, valueType);
 54.2842 +            }
 54.2843 +
 54.2844 +            /**
 54.2845 +             * This "wrapper class" serves two purposes: it prevents
 54.2846 +             * the client from modifying the backing Map, by short-circuiting
 54.2847 +             * the setValue method, and it protects the backing Map against
 54.2848 +             * an ill-behaved Map.Entry that attempts to modify another
 54.2849 +             * Map.Entry when asked to perform an equality check.
 54.2850 +             */
 54.2851 +            private static class CheckedEntry<K,V,T> implements Map.Entry<K,V> {
 54.2852 +                private final Map.Entry<K, V> e;
 54.2853 +                private final Class<T> valueType;
 54.2854 +
 54.2855 +                CheckedEntry(Map.Entry<K, V> e, Class<T> valueType) {
 54.2856 +                    this.e = e;
 54.2857 +                    this.valueType = valueType;
 54.2858 +                }
 54.2859 +
 54.2860 +                public K getKey()        { return e.getKey(); }
 54.2861 +                public V getValue()      { return e.getValue(); }
 54.2862 +                public int hashCode()    { return e.hashCode(); }
 54.2863 +                public String toString() { return e.toString(); }
 54.2864 +
 54.2865 +                public V setValue(V value) {
 54.2866 +                    if (value != null && !valueType.isInstance(value))
 54.2867 +                        throw new ClassCastException(badValueMsg(value));
 54.2868 +                    return e.setValue(value);
 54.2869 +                }
 54.2870 +
 54.2871 +                private String badValueMsg(Object value) {
 54.2872 +                    return "Attempt to insert " + value.getClass() +
 54.2873 +                        " value into map with value type " + valueType;
 54.2874 +                }
 54.2875 +
 54.2876 +                public boolean equals(Object o) {
 54.2877 +                    if (o == this)
 54.2878 +                        return true;
 54.2879 +                    if (!(o instanceof Map.Entry))
 54.2880 +                        return false;
 54.2881 +                    return e.equals(new AbstractMap.SimpleImmutableEntry
 54.2882 +                                    <>((Map.Entry<?,?>)o));
 54.2883 +                }
 54.2884 +            }
 54.2885 +        }
 54.2886 +    }
 54.2887 +
 54.2888 +    /**
 54.2889 +     * Returns a dynamically typesafe view of the specified sorted map.
 54.2890 +     * Any attempt to insert a mapping whose key or value have the wrong
 54.2891 +     * type will result in an immediate {@link ClassCastException}.
 54.2892 +     * Similarly, any attempt to modify the value currently associated with
 54.2893 +     * a key will result in an immediate {@link ClassCastException},
 54.2894 +     * whether the modification is attempted directly through the map
 54.2895 +     * itself, or through a {@link Map.Entry} instance obtained from the
 54.2896 +     * map's {@link Map#entrySet() entry set} view.
 54.2897 +     *
 54.2898 +     * <p>Assuming a map contains no incorrectly typed keys or values
 54.2899 +     * prior to the time a dynamically typesafe view is generated, and
 54.2900 +     * that all subsequent access to the map takes place through the view
 54.2901 +     * (or one of its collection views), it is <i>guaranteed</i> that the
 54.2902 +     * map cannot contain an incorrectly typed key or value.
 54.2903 +     *
 54.2904 +     * <p>A discussion of the use of dynamically typesafe views may be
 54.2905 +     * found in the documentation for the {@link #checkedCollection
 54.2906 +     * checkedCollection} method.
 54.2907 +     *
 54.2908 +     * <p>The returned map will be serializable if the specified map is
 54.2909 +     * serializable.
 54.2910 +     *
 54.2911 +     * <p>Since {@code null} is considered to be a value of any reference
 54.2912 +     * type, the returned map permits insertion of null keys or values
 54.2913 +     * whenever the backing map does.
 54.2914 +     *
 54.2915 +     * @param m the map for which a dynamically typesafe view is to be
 54.2916 +     *          returned
 54.2917 +     * @param keyType the type of key that {@code m} is permitted to hold
 54.2918 +     * @param valueType the type of value that {@code m} is permitted to hold
 54.2919 +     * @return a dynamically typesafe view of the specified map
 54.2920 +     * @since 1.5
 54.2921 +     */
 54.2922 +    public static <K,V> SortedMap<K,V> checkedSortedMap(SortedMap<K, V> m,
 54.2923 +                                                        Class<K> keyType,
 54.2924 +                                                        Class<V> valueType) {
 54.2925 +        return new CheckedSortedMap<>(m, keyType, valueType);
 54.2926 +    }
 54.2927 +
 54.2928 +    /**
 54.2929 +     * @serial include
 54.2930 +     */
 54.2931 +    static class CheckedSortedMap<K,V> extends CheckedMap<K,V>
 54.2932 +        implements SortedMap<K,V>, Serializable
 54.2933 +    {
 54.2934 +        private static final long serialVersionUID = 1599671320688067438L;
 54.2935 +
 54.2936 +        private final SortedMap<K, V> sm;
 54.2937 +
 54.2938 +        CheckedSortedMap(SortedMap<K, V> m,
 54.2939 +                         Class<K> keyType, Class<V> valueType) {
 54.2940 +            super(m, keyType, valueType);
 54.2941 +            sm = m;
 54.2942 +        }
 54.2943 +
 54.2944 +        public Comparator<? super K> comparator() { return sm.comparator(); }
 54.2945 +        public K firstKey()                       { return sm.firstKey(); }
 54.2946 +        public K lastKey()                        { return sm.lastKey(); }
 54.2947 +
 54.2948 +        public SortedMap<K,V> subMap(K fromKey, K toKey) {
 54.2949 +            return checkedSortedMap(sm.subMap(fromKey, toKey),
 54.2950 +                                    keyType, valueType);
 54.2951 +        }
 54.2952 +        public SortedMap<K,V> headMap(K toKey) {
 54.2953 +            return checkedSortedMap(sm.headMap(toKey), keyType, valueType);
 54.2954 +        }
 54.2955 +        public SortedMap<K,V> tailMap(K fromKey) {
 54.2956 +            return checkedSortedMap(sm.tailMap(fromKey), keyType, valueType);
 54.2957 +        }
 54.2958 +    }
 54.2959 +
 54.2960 +    // Empty collections
 54.2961 +
 54.2962 +    /**
 54.2963 +     * Returns an iterator that has no elements.  More precisely,
 54.2964 +     *
 54.2965 +     * <ul compact>
 54.2966 +     *
 54.2967 +     * <li>{@link Iterator#hasNext hasNext} always returns {@code
 54.2968 +     * false}.
 54.2969 +     *
 54.2970 +     * <li>{@link Iterator#next next} always throws {@link
 54.2971 +     * NoSuchElementException}.
 54.2972 +     *
 54.2973 +     * <li>{@link Iterator#remove remove} always throws {@link
 54.2974 +     * IllegalStateException}.
 54.2975 +     *
 54.2976 +     * </ul>
 54.2977 +     *
 54.2978 +     * <p>Implementations of this method are permitted, but not
 54.2979 +     * required, to return the same object from multiple invocations.
 54.2980 +     *
 54.2981 +     * @return an empty iterator
 54.2982 +     * @since 1.7
 54.2983 +     */
 54.2984 +    @SuppressWarnings("unchecked")
 54.2985 +    public static <T> Iterator<T> emptyIterator() {
 54.2986 +        return (Iterator<T>) EmptyIterator.EMPTY_ITERATOR;
 54.2987 +    }
 54.2988 +
 54.2989 +    private static class EmptyIterator<E> implements Iterator<E> {
 54.2990 +        static final EmptyIterator<Object> EMPTY_ITERATOR
 54.2991 +            = new EmptyIterator<>();
 54.2992 +
 54.2993 +        public boolean hasNext() { return false; }
 54.2994 +        public E next() { throw new NoSuchElementException(); }
 54.2995 +        public void remove() { throw new IllegalStateException(); }
 54.2996 +    }
 54.2997 +
 54.2998 +    /**
 54.2999 +     * Returns a list iterator that has no elements.  More precisely,
 54.3000 +     *
 54.3001 +     * <ul compact>
 54.3002 +     *
 54.3003 +     * <li>{@link Iterator#hasNext hasNext} and {@link
 54.3004 +     * ListIterator#hasPrevious hasPrevious} always return {@code
 54.3005 +     * false}.
 54.3006 +     *
 54.3007 +     * <li>{@link Iterator#next next} and {@link ListIterator#previous
 54.3008 +     * previous} always throw {@link NoSuchElementException}.
 54.3009 +     *
 54.3010 +     * <li>{@link Iterator#remove remove} and {@link ListIterator#set
 54.3011 +     * set} always throw {@link IllegalStateException}.
 54.3012 +     *
 54.3013 +     * <li>{@link ListIterator#add add} always throws {@link
 54.3014 +     * UnsupportedOperationException}.
 54.3015 +     *
 54.3016 +     * <li>{@link ListIterator#nextIndex nextIndex} always returns
 54.3017 +     * {@code 0} .
 54.3018 +     *
 54.3019 +     * <li>{@link ListIterator#previousIndex previousIndex} always
 54.3020 +     * returns {@code -1}.
 54.3021 +     *
 54.3022 +     * </ul>
 54.3023 +     *
 54.3024 +     * <p>Implementations of this method are permitted, but not
 54.3025 +     * required, to return the same object from multiple invocations.
 54.3026 +     *
 54.3027 +     * @return an empty list iterator
 54.3028 +     * @since 1.7
 54.3029 +     */
 54.3030 +    @SuppressWarnings("unchecked")
 54.3031 +    public static <T> ListIterator<T> emptyListIterator() {
 54.3032 +        return (ListIterator<T>) EmptyListIterator.EMPTY_ITERATOR;
 54.3033 +    }
 54.3034 +
 54.3035 +    private static class EmptyListIterator<E>
 54.3036 +        extends EmptyIterator<E>
 54.3037 +        implements ListIterator<E>
 54.3038 +    {
 54.3039 +        static final EmptyListIterator<Object> EMPTY_ITERATOR
 54.3040 +            = new EmptyListIterator<>();
 54.3041 +
 54.3042 +        public boolean hasPrevious() { return false; }
 54.3043 +        public E previous() { throw new NoSuchElementException(); }
 54.3044 +        public int nextIndex()     { return 0; }
 54.3045 +        public int previousIndex() { return -1; }
 54.3046 +        public void set(E e) { throw new IllegalStateException(); }
 54.3047 +        public void add(E e) { throw new UnsupportedOperationException(); }
 54.3048 +    }
 54.3049 +
 54.3050 +    /**
 54.3051 +     * Returns an enumeration that has no elements.  More precisely,
 54.3052 +     *
 54.3053 +     * <ul compact>
 54.3054 +     *
 54.3055 +     * <li>{@link Enumeration#hasMoreElements hasMoreElements} always
 54.3056 +     * returns {@code false}.
 54.3057 +     *
 54.3058 +     * <li> {@link Enumeration#nextElement nextElement} always throws
 54.3059 +     * {@link NoSuchElementException}.
 54.3060 +     *
 54.3061 +     * </ul>
 54.3062 +     *
 54.3063 +     * <p>Implementations of this method are permitted, but not
 54.3064 +     * required, to return the same object from multiple invocations.
 54.3065 +     *
 54.3066 +     * @return an empty enumeration
 54.3067 +     * @since 1.7
 54.3068 +     */
 54.3069 +    @SuppressWarnings("unchecked")
 54.3070 +    public static <T> Enumeration<T> emptyEnumeration() {
 54.3071 +        return (Enumeration<T>) EmptyEnumeration.EMPTY_ENUMERATION;
 54.3072 +    }
 54.3073 +
 54.3074 +    private static class EmptyEnumeration<E> implements Enumeration<E> {
 54.3075 +        static final EmptyEnumeration<Object> EMPTY_ENUMERATION
 54.3076 +            = new EmptyEnumeration<>();
 54.3077 +
 54.3078 +        public boolean hasMoreElements() { return false; }
 54.3079 +        public E nextElement() { throw new NoSuchElementException(); }
 54.3080 +    }
 54.3081 +
 54.3082 +    /**
 54.3083 +     * The empty set (immutable).  This set is serializable.
 54.3084 +     *
 54.3085 +     * @see #emptySet()
 54.3086 +     */
 54.3087 +    @SuppressWarnings("unchecked")
 54.3088 +    public static final Set EMPTY_SET = new EmptySet<>();
 54.3089 +
 54.3090 +    /**
 54.3091 +     * Returns the empty set (immutable).  This set is serializable.
 54.3092 +     * Unlike the like-named field, this method is parameterized.
 54.3093 +     *
 54.3094 +     * <p>This example illustrates the type-safe way to obtain an empty set:
 54.3095 +     * <pre>
 54.3096 +     *     Set&lt;String&gt; s = Collections.emptySet();
 54.3097 +     * </pre>
 54.3098 +     * Implementation note:  Implementations of this method need not
 54.3099 +     * create a separate <tt>Set</tt> object for each call.   Using this
 54.3100 +     * method is likely to have comparable cost to using the like-named
 54.3101 +     * field.  (Unlike this method, the field does not provide type safety.)
 54.3102 +     *
 54.3103 +     * @see #EMPTY_SET
 54.3104 +     * @since 1.5
 54.3105 +     */
 54.3106 +    @SuppressWarnings("unchecked")
 54.3107 +    public static final <T> Set<T> emptySet() {
 54.3108 +        return (Set<T>) EMPTY_SET;
 54.3109 +    }
 54.3110 +
 54.3111 +    /**
 54.3112 +     * @serial include
 54.3113 +     */
 54.3114 +    private static class EmptySet<E>
 54.3115 +        extends AbstractSet<E>
 54.3116 +        implements Serializable
 54.3117 +    {
 54.3118 +        private static final long serialVersionUID = 1582296315990362920L;
 54.3119 +
 54.3120 +        public Iterator<E> iterator() { return emptyIterator(); }
 54.3121 +
 54.3122 +        public int size() {return 0;}
 54.3123 +        public boolean isEmpty() {return true;}
 54.3124 +
 54.3125 +        public boolean contains(Object obj) {return false;}
 54.3126 +        public boolean containsAll(Collection<?> c) { return c.isEmpty(); }
 54.3127 +
 54.3128 +        public Object[] toArray() { return new Object[0]; }
 54.3129 +
 54.3130 +        public <T> T[] toArray(T[] a) {
 54.3131 +            if (a.length > 0)
 54.3132 +                a[0] = null;
 54.3133 +            return a;
 54.3134 +        }
 54.3135 +
 54.3136 +        // Preserves singleton property
 54.3137 +        private Object readResolve() {
 54.3138 +            return EMPTY_SET;
 54.3139 +        }
 54.3140 +    }
 54.3141 +
 54.3142 +    /**
 54.3143 +     * The empty list (immutable).  This list is serializable.
 54.3144 +     *
 54.3145 +     * @see #emptyList()
 54.3146 +     */
 54.3147 +    @SuppressWarnings("unchecked")
 54.3148 +    public static final List EMPTY_LIST = new EmptyList<>();
 54.3149 +
 54.3150 +    /**
 54.3151 +     * Returns the empty list (immutable).  This list is serializable.
 54.3152 +     *
 54.3153 +     * <p>This example illustrates the type-safe way to obtain an empty list:
 54.3154 +     * <pre>
 54.3155 +     *     List&lt;String&gt; s = Collections.emptyList();
 54.3156 +     * </pre>
 54.3157 +     * Implementation note:  Implementations of this method need not
 54.3158 +     * create a separate <tt>List</tt> object for each call.   Using this
 54.3159 +     * method is likely to have comparable cost to using the like-named
 54.3160 +     * field.  (Unlike this method, the field does not provide type safety.)
 54.3161 +     *
 54.3162 +     * @see #EMPTY_LIST
 54.3163 +     * @since 1.5
 54.3164 +     */
 54.3165 +    @SuppressWarnings("unchecked")
 54.3166 +    public static final <T> List<T> emptyList() {
 54.3167 +        return (List<T>) EMPTY_LIST;
 54.3168 +    }
 54.3169 +
 54.3170 +    /**
 54.3171 +     * @serial include
 54.3172 +     */
 54.3173 +    private static class EmptyList<E>
 54.3174 +        extends AbstractList<E>
 54.3175 +        implements RandomAccess, Serializable {
 54.3176 +        private static final long serialVersionUID = 8842843931221139166L;
 54.3177 +
 54.3178 +        public Iterator<E> iterator() {
 54.3179 +            return emptyIterator();
 54.3180 +        }
 54.3181 +        public ListIterator<E> listIterator() {
 54.3182 +            return emptyListIterator();
 54.3183 +        }
 54.3184 +
 54.3185 +        public int size() {return 0;}
 54.3186 +        public boolean isEmpty() {return true;}
 54.3187 +
 54.3188 +        public boolean contains(Object obj) {return false;}
 54.3189 +        public boolean containsAll(Collection<?> c) { return c.isEmpty(); }
 54.3190 +
 54.3191 +        public Object[] toArray() { return new Object[0]; }
 54.3192 +
 54.3193 +        public <T> T[] toArray(T[] a) {
 54.3194 +            if (a.length > 0)
 54.3195 +                a[0] = null;
 54.3196 +            return a;
 54.3197 +        }
 54.3198 +
 54.3199 +        public E get(int index) {
 54.3200 +            throw new IndexOutOfBoundsException("Index: "+index);
 54.3201 +        }
 54.3202 +
 54.3203 +        public boolean equals(Object o) {
 54.3204 +            return (o instanceof List) && ((List<?>)o).isEmpty();
 54.3205 +        }
 54.3206 +
 54.3207 +        public int hashCode() { return 1; }
 54.3208 +
 54.3209 +        // Preserves singleton property
 54.3210 +        private Object readResolve() {
 54.3211 +            return EMPTY_LIST;
 54.3212 +        }
 54.3213 +    }
 54.3214 +
 54.3215 +    /**
 54.3216 +     * The empty map (immutable).  This map is serializable.
 54.3217 +     *
 54.3218 +     * @see #emptyMap()
 54.3219 +     * @since 1.3
 54.3220 +     */
 54.3221 +    @SuppressWarnings("unchecked")
 54.3222 +    public static final Map EMPTY_MAP = new EmptyMap<>();
 54.3223 +
 54.3224 +    /**
 54.3225 +     * Returns the empty map (immutable).  This map is serializable.
 54.3226 +     *
 54.3227 +     * <p>This example illustrates the type-safe way to obtain an empty set:
 54.3228 +     * <pre>
 54.3229 +     *     Map&lt;String, Date&gt; s = Collections.emptyMap();
 54.3230 +     * </pre>
 54.3231 +     * Implementation note:  Implementations of this method need not
 54.3232 +     * create a separate <tt>Map</tt> object for each call.   Using this
 54.3233 +     * method is likely to have comparable cost to using the like-named
 54.3234 +     * field.  (Unlike this method, the field does not provide type safety.)
 54.3235 +     *
 54.3236 +     * @see #EMPTY_MAP
 54.3237 +     * @since 1.5
 54.3238 +     */
 54.3239 +    @SuppressWarnings("unchecked")
 54.3240 +    public static final <K,V> Map<K,V> emptyMap() {
 54.3241 +        return (Map<K,V>) EMPTY_MAP;
 54.3242 +    }
 54.3243 +
 54.3244 +    /**
 54.3245 +     * @serial include
 54.3246 +     */
 54.3247 +    private static class EmptyMap<K,V>
 54.3248 +        extends AbstractMap<K,V>
 54.3249 +        implements Serializable
 54.3250 +    {
 54.3251 +        private static final long serialVersionUID = 6428348081105594320L;
 54.3252 +
 54.3253 +        public int size()                          {return 0;}
 54.3254 +        public boolean isEmpty()                   {return true;}
 54.3255 +        public boolean containsKey(Object key)     {return false;}
 54.3256 +        public boolean containsValue(Object value) {return false;}
 54.3257 +        public V get(Object key)                   {return null;}
 54.3258 +        public Set<K> keySet()                     {return emptySet();}
 54.3259 +        public Collection<V> values()              {return emptySet();}
 54.3260 +        public Set<Map.Entry<K,V>> entrySet()      {return emptySet();}
 54.3261 +
 54.3262 +        public boolean equals(Object o) {
 54.3263 +            return (o instanceof Map) && ((Map<?,?>)o).isEmpty();
 54.3264 +        }
 54.3265 +
 54.3266 +        public int hashCode()                      {return 0;}
 54.3267 +
 54.3268 +        // Preserves singleton property
 54.3269 +        private Object readResolve() {
 54.3270 +            return EMPTY_MAP;
 54.3271 +        }
 54.3272 +    }
 54.3273 +
 54.3274 +    // Singleton collections
 54.3275 +
 54.3276 +    /**
 54.3277 +     * Returns an immutable set containing only the specified object.
 54.3278 +     * The returned set is serializable.
 54.3279 +     *
 54.3280 +     * @param o the sole object to be stored in the returned set.
 54.3281 +     * @return an immutable set containing only the specified object.
 54.3282 +     */
 54.3283 +    public static <T> Set<T> singleton(T o) {
 54.3284 +        return new SingletonSet<>(o);
 54.3285 +    }
 54.3286 +
 54.3287 +    static <E> Iterator<E> singletonIterator(final E e) {
 54.3288 +        return new Iterator<E>() {
 54.3289 +            private boolean hasNext = true;
 54.3290 +            public boolean hasNext() {
 54.3291 +                return hasNext;
 54.3292 +            }
 54.3293 +            public E next() {
 54.3294 +                if (hasNext) {
 54.3295 +                    hasNext = false;
 54.3296 +                    return e;
 54.3297 +                }
 54.3298 +                throw new NoSuchElementException();
 54.3299 +            }
 54.3300 +            public void remove() {
 54.3301 +                throw new UnsupportedOperationException();
 54.3302 +            }
 54.3303 +        };
 54.3304 +    }
 54.3305 +
 54.3306 +    /**
 54.3307 +     * @serial include
 54.3308 +     */
 54.3309 +    private static class SingletonSet<E>
 54.3310 +        extends AbstractSet<E>
 54.3311 +        implements Serializable
 54.3312 +    {
 54.3313 +        private static final long serialVersionUID = 3193687207550431679L;
 54.3314 +
 54.3315 +        private final E element;
 54.3316 +
 54.3317 +        SingletonSet(E e) {element = e;}
 54.3318 +
 54.3319 +        public Iterator<E> iterator() {
 54.3320 +            return singletonIterator(element);
 54.3321 +        }
 54.3322 +
 54.3323 +        public int size() {return 1;}
 54.3324 +
 54.3325 +        public boolean contains(Object o) {return eq(o, element);}
 54.3326 +    }
 54.3327 +
 54.3328 +    /**
 54.3329 +     * Returns an immutable list containing only the specified object.
 54.3330 +     * The returned list is serializable.
 54.3331 +     *
 54.3332 +     * @param o the sole object to be stored in the returned list.
 54.3333 +     * @return an immutable list containing only the specified object.
 54.3334 +     * @since 1.3
 54.3335 +     */
 54.3336 +    public static <T> List<T> singletonList(T o) {
 54.3337 +        return new SingletonList<>(o);
 54.3338 +    }
 54.3339 +
 54.3340 +    /**
 54.3341 +     * @serial include
 54.3342 +     */
 54.3343 +    private static class SingletonList<E>
 54.3344 +        extends AbstractList<E>
 54.3345 +        implements RandomAccess, Serializable {
 54.3346 +
 54.3347 +        private static final long serialVersionUID = 3093736618740652951L;
 54.3348 +
 54.3349 +        private final E element;
 54.3350 +
 54.3351 +        SingletonList(E obj)                {element = obj;}
 54.3352 +
 54.3353 +        public Iterator<E> iterator() {
 54.3354 +            return singletonIterator(element);
 54.3355 +        }
 54.3356 +
 54.3357 +        public int size()                   {return 1;}
 54.3358 +
 54.3359 +        public boolean contains(Object obj) {return eq(obj, element);}
 54.3360 +
 54.3361 +        public E get(int index) {
 54.3362 +            if (index != 0)
 54.3363 +              throw new IndexOutOfBoundsException("Index: "+index+", Size: 1");
 54.3364 +            return element;
 54.3365 +        }
 54.3366 +    }
 54.3367 +
 54.3368 +    /**
 54.3369 +     * Returns an immutable map, mapping only the specified key to the
 54.3370 +     * specified value.  The returned map is serializable.
 54.3371 +     *
 54.3372 +     * @param key the sole key to be stored in the returned map.
 54.3373 +     * @param value the value to which the returned map maps <tt>key</tt>.
 54.3374 +     * @return an immutable map containing only the specified key-value
 54.3375 +     *         mapping.
 54.3376 +     * @since 1.3
 54.3377 +     */
 54.3378 +    public static <K,V> Map<K,V> singletonMap(K key, V value) {
 54.3379 +        return new SingletonMap<>(key, value);
 54.3380 +    }
 54.3381 +
 54.3382 +    /**
 54.3383 +     * @serial include
 54.3384 +     */
 54.3385 +    private static class SingletonMap<K,V>
 54.3386 +          extends AbstractMap<K,V>
 54.3387 +          implements Serializable {
 54.3388 +        private static final long serialVersionUID = -6979724477215052911L;
 54.3389 +
 54.3390 +        private final K k;
 54.3391 +        private final V v;
 54.3392 +
 54.3393 +        SingletonMap(K key, V value) {
 54.3394 +            k = key;
 54.3395 +            v = value;
 54.3396 +        }
 54.3397 +
 54.3398 +        public int size()                          {return 1;}
 54.3399 +
 54.3400 +        public boolean isEmpty()                   {return false;}
 54.3401 +
 54.3402 +        public boolean containsKey(Object key)     {return eq(key, k);}
 54.3403 +
 54.3404 +        public boolean containsValue(Object value) {return eq(value, v);}
 54.3405 +
 54.3406 +        public V get(Object key)                   {return (eq(key, k) ? v : null);}
 54.3407 +
 54.3408 +        private transient Set<K> keySet = null;
 54.3409 +        private transient Set<Map.Entry<K,V>> entrySet = null;
 54.3410 +        private transient Collection<V> values = null;
 54.3411 +
 54.3412 +        public Set<K> keySet() {
 54.3413 +            if (keySet==null)
 54.3414 +                keySet = singleton(k);
 54.3415 +            return keySet;
 54.3416 +        }
 54.3417 +
 54.3418 +        public Set<Map.Entry<K,V>> entrySet() {
 54.3419 +            if (entrySet==null)
 54.3420 +                entrySet = Collections.<Map.Entry<K,V>>singleton(
 54.3421 +                    new SimpleImmutableEntry<>(k, v));
 54.3422 +            return entrySet;
 54.3423 +        }
 54.3424 +
 54.3425 +        public Collection<V> values() {
 54.3426 +            if (values==null)
 54.3427 +                values = singleton(v);
 54.3428 +            return values;
 54.3429 +        }
 54.3430 +
 54.3431 +    }
 54.3432 +
 54.3433 +    // Miscellaneous
 54.3434 +
 54.3435 +    /**
 54.3436 +     * Returns an immutable list consisting of <tt>n</tt> copies of the
 54.3437 +     * specified object.  The newly allocated data object is tiny (it contains
 54.3438 +     * a single reference to the data object).  This method is useful in
 54.3439 +     * combination with the <tt>List.addAll</tt> method to grow lists.
 54.3440 +     * The returned list is serializable.
 54.3441 +     *
 54.3442 +     * @param  n the number of elements in the returned list.
 54.3443 +     * @param  o the element to appear repeatedly in the returned list.
 54.3444 +     * @return an immutable list consisting of <tt>n</tt> copies of the
 54.3445 +     *         specified object.
 54.3446 +     * @throws IllegalArgumentException if {@code n < 0}
 54.3447 +     * @see    List#addAll(Collection)
 54.3448 +     * @see    List#addAll(int, Collection)
 54.3449 +     */
 54.3450 +    public static <T> List<T> nCopies(int n, T o) {
 54.3451 +        if (n < 0)
 54.3452 +            throw new IllegalArgumentException("List length = " + n);
 54.3453 +        return new CopiesList<>(n, o);
 54.3454 +    }
 54.3455 +
 54.3456 +    /**
 54.3457 +     * @serial include
 54.3458 +     */
 54.3459 +    private static class CopiesList<E>
 54.3460 +        extends AbstractList<E>
 54.3461 +        implements RandomAccess, Serializable
 54.3462 +    {
 54.3463 +        private static final long serialVersionUID = 2739099268398711800L;
 54.3464 +
 54.3465 +        final int n;
 54.3466 +        final E element;
 54.3467 +
 54.3468 +        CopiesList(int n, E e) {
 54.3469 +            assert n >= 0;
 54.3470 +            this.n = n;
 54.3471 +            element = e;
 54.3472 +        }
 54.3473 +
 54.3474 +        public int size() {
 54.3475 +            return n;
 54.3476 +        }
 54.3477 +
 54.3478 +        public boolean contains(Object obj) {
 54.3479 +            return n != 0 && eq(obj, element);
 54.3480 +        }
 54.3481 +
 54.3482 +        public int indexOf(Object o) {
 54.3483 +            return contains(o) ? 0 : -1;
 54.3484 +        }
 54.3485 +
 54.3486 +        public int lastIndexOf(Object o) {
 54.3487 +            return contains(o) ? n - 1 : -1;
 54.3488 +        }
 54.3489 +
 54.3490 +        public E get(int index) {
 54.3491 +            if (index < 0 || index >= n)
 54.3492 +                throw new IndexOutOfBoundsException("Index: "+index+
 54.3493 +                                                    ", Size: "+n);
 54.3494 +            return element;
 54.3495 +        }
 54.3496 +
 54.3497 +        public Object[] toArray() {
 54.3498 +            final Object[] a = new Object[n];
 54.3499 +            if (element != null)
 54.3500 +                Arrays.fill(a, 0, n, element);
 54.3501 +            return a;
 54.3502 +        }
 54.3503 +
 54.3504 +        public <T> T[] toArray(T[] a) {
 54.3505 +            final int n = this.n;
 54.3506 +            if (a.length < n) {
 54.3507 +                a = (T[])java.lang.reflect.Array
 54.3508 +                    .newInstance(a.getClass().getComponentType(), n);
 54.3509 +                if (element != null)
 54.3510 +                    Arrays.fill(a, 0, n, element);
 54.3511 +            } else {
 54.3512 +                Arrays.fill(a, 0, n, element);
 54.3513 +                if (a.length > n)
 54.3514 +                    a[n] = null;
 54.3515 +            }
 54.3516 +            return a;
 54.3517 +        }
 54.3518 +
 54.3519 +        public List<E> subList(int fromIndex, int toIndex) {
 54.3520 +            if (fromIndex < 0)
 54.3521 +                throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
 54.3522 +            if (toIndex > n)
 54.3523 +                throw new IndexOutOfBoundsException("toIndex = " + toIndex);
 54.3524 +            if (fromIndex > toIndex)
 54.3525 +                throw new IllegalArgumentException("fromIndex(" + fromIndex +
 54.3526 +                                                   ") > toIndex(" + toIndex + ")");
 54.3527 +            return new CopiesList<>(toIndex - fromIndex, element);
 54.3528 +        }
 54.3529 +    }
 54.3530 +
 54.3531 +    /**
 54.3532 +     * Returns a comparator that imposes the reverse of the <em>natural
 54.3533 +     * ordering</em> on a collection of objects that implement the
 54.3534 +     * {@code Comparable} interface.  (The natural ordering is the ordering
 54.3535 +     * imposed by the objects' own {@code compareTo} method.)  This enables a
 54.3536 +     * simple idiom for sorting (or maintaining) collections (or arrays) of
 54.3537 +     * objects that implement the {@code Comparable} interface in
 54.3538 +     * reverse-natural-order.  For example, suppose {@code a} is an array of
 54.3539 +     * strings. Then: <pre>
 54.3540 +     *          Arrays.sort(a, Collections.reverseOrder());
 54.3541 +     * </pre> sorts the array in reverse-lexicographic (alphabetical) order.<p>
 54.3542 +     *
 54.3543 +     * The returned comparator is serializable.
 54.3544 +     *
 54.3545 +     * @return A comparator that imposes the reverse of the <i>natural
 54.3546 +     *         ordering</i> on a collection of objects that implement
 54.3547 +     *         the <tt>Comparable</tt> interface.
 54.3548 +     * @see Comparable
 54.3549 +     */
 54.3550 +    public static <T> Comparator<T> reverseOrder() {
 54.3551 +        return (Comparator<T>) ReverseComparator.REVERSE_ORDER;
 54.3552 +    }
 54.3553 +
 54.3554 +    /**
 54.3555 +     * @serial include
 54.3556 +     */
 54.3557 +    private static class ReverseComparator
 54.3558 +        implements Comparator<Comparable<Object>>, Serializable {
 54.3559 +
 54.3560 +        private static final long serialVersionUID = 7207038068494060240L;
 54.3561 +
 54.3562 +        static final ReverseComparator REVERSE_ORDER
 54.3563 +            = new ReverseComparator();
 54.3564 +
 54.3565 +        public int compare(Comparable<Object> c1, Comparable<Object> c2) {
 54.3566 +            return c2.compareTo(c1);
 54.3567 +        }
 54.3568 +
 54.3569 +        private Object readResolve() { return reverseOrder(); }
 54.3570 +    }
 54.3571 +
 54.3572 +    /**
 54.3573 +     * Returns a comparator that imposes the reverse ordering of the specified
 54.3574 +     * comparator.  If the specified comparator is {@code null}, this method is
 54.3575 +     * equivalent to {@link #reverseOrder()} (in other words, it returns a
 54.3576 +     * comparator that imposes the reverse of the <em>natural ordering</em> on
 54.3577 +     * a collection of objects that implement the Comparable interface).
 54.3578 +     *
 54.3579 +     * <p>The returned comparator is serializable (assuming the specified
 54.3580 +     * comparator is also serializable or {@code null}).
 54.3581 +     *
 54.3582 +     * @param cmp a comparator who's ordering is to be reversed by the returned
 54.3583 +     * comparator or {@code null}
 54.3584 +     * @return A comparator that imposes the reverse ordering of the
 54.3585 +     *         specified comparator.
 54.3586 +     * @since 1.5
 54.3587 +     */
 54.3588 +    public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) {
 54.3589 +        if (cmp == null)
 54.3590 +            return reverseOrder();
 54.3591 +
 54.3592 +        if (cmp instanceof ReverseComparator2)
 54.3593 +            return ((ReverseComparator2<T>)cmp).cmp;
 54.3594 +
 54.3595 +        return new ReverseComparator2<>(cmp);
 54.3596 +    }
 54.3597 +
 54.3598 +    /**
 54.3599 +     * @serial include
 54.3600 +     */
 54.3601 +    private static class ReverseComparator2<T> implements Comparator<T>,
 54.3602 +        Serializable
 54.3603 +    {
 54.3604 +        private static final long serialVersionUID = 4374092139857L;
 54.3605 +
 54.3606 +        /**
 54.3607 +         * The comparator specified in the static factory.  This will never
 54.3608 +         * be null, as the static factory returns a ReverseComparator
 54.3609 +         * instance if its argument is null.
 54.3610 +         *
 54.3611 +         * @serial
 54.3612 +         */
 54.3613 +        final Comparator<T> cmp;
 54.3614 +
 54.3615 +        ReverseComparator2(Comparator<T> cmp) {
 54.3616 +            assert cmp != null;
 54.3617 +            this.cmp = cmp;
 54.3618 +        }
 54.3619 +
 54.3620 +        public int compare(T t1, T t2) {
 54.3621 +            return cmp.compare(t2, t1);
 54.3622 +        }
 54.3623 +
 54.3624 +        public boolean equals(Object o) {
 54.3625 +            return (o == this) ||
 54.3626 +                (o instanceof ReverseComparator2 &&
 54.3627 +                 cmp.equals(((ReverseComparator2)o).cmp));
 54.3628 +        }
 54.3629 +
 54.3630 +        public int hashCode() {
 54.3631 +            return cmp.hashCode() ^ Integer.MIN_VALUE;
 54.3632 +        }
 54.3633 +    }
 54.3634 +
 54.3635 +    /**
 54.3636 +     * Returns an enumeration over the specified collection.  This provides
 54.3637 +     * interoperability with legacy APIs that require an enumeration
 54.3638 +     * as input.
 54.3639 +     *
 54.3640 +     * @param c the collection for which an enumeration is to be returned.
 54.3641 +     * @return an enumeration over the specified collection.
 54.3642 +     * @see Enumeration
 54.3643 +     */
 54.3644 +    public static <T> Enumeration<T> enumeration(final Collection<T> c) {
 54.3645 +        return new Enumeration<T>() {
 54.3646 +            private final Iterator<T> i = c.iterator();
 54.3647 +
 54.3648 +            public boolean hasMoreElements() {
 54.3649 +                return i.hasNext();
 54.3650 +            }
 54.3651 +
 54.3652 +            public T nextElement() {
 54.3653 +                return i.next();
 54.3654 +            }
 54.3655 +        };
 54.3656 +    }
 54.3657 +
 54.3658 +    /**
 54.3659 +     * Returns an array list containing the elements returned by the
 54.3660 +     * specified enumeration in the order they are returned by the
 54.3661 +     * enumeration.  This method provides interoperability between
 54.3662 +     * legacy APIs that return enumerations and new APIs that require
 54.3663 +     * collections.
 54.3664 +     *
 54.3665 +     * @param e enumeration providing elements for the returned
 54.3666 +     *          array list
 54.3667 +     * @return an array list containing the elements returned
 54.3668 +     *         by the specified enumeration.
 54.3669 +     * @since 1.4
 54.3670 +     * @see Enumeration
 54.3671 +     * @see ArrayList
 54.3672 +     */
 54.3673 +    public static <T> ArrayList<T> list(Enumeration<T> e) {
 54.3674 +        ArrayList<T> l = new ArrayList<>();
 54.3675 +        while (e.hasMoreElements())
 54.3676 +            l.add(e.nextElement());
 54.3677 +        return l;
 54.3678 +    }
 54.3679 +
 54.3680 +    /**
 54.3681 +     * Returns true if the specified arguments are equal, or both null.
 54.3682 +     */
 54.3683 +    static boolean eq(Object o1, Object o2) {
 54.3684 +        return o1==null ? o2==null : o1.equals(o2);
 54.3685 +    }
 54.3686 +
 54.3687 +    /**
 54.3688 +     * Returns the number of elements in the specified collection equal to the
 54.3689 +     * specified object.  More formally, returns the number of elements
 54.3690 +     * <tt>e</tt> in the collection such that
 54.3691 +     * <tt>(o == null ? e == null : o.equals(e))</tt>.
 54.3692 +     *
 54.3693 +     * @param c the collection in which to determine the frequency
 54.3694 +     *     of <tt>o</tt>
 54.3695 +     * @param o the object whose frequency is to be determined
 54.3696 +     * @throws NullPointerException if <tt>c</tt> is null
 54.3697 +     * @since 1.5
 54.3698 +     */
 54.3699 +    public static int frequency(Collection<?> c, Object o) {
 54.3700 +        int result = 0;
 54.3701 +        if (o == null) {
 54.3702 +            for (Object e : c)
 54.3703 +                if (e == null)
 54.3704 +                    result++;
 54.3705 +        } else {
 54.3706 +            for (Object e : c)
 54.3707 +                if (o.equals(e))
 54.3708 +                    result++;
 54.3709 +        }
 54.3710 +        return result;
 54.3711 +    }
 54.3712 +
 54.3713 +    /**
 54.3714 +     * Returns {@code true} if the two specified collections have no
 54.3715 +     * elements in common.
 54.3716 +     *
 54.3717 +     * <p>Care must be exercised if this method is used on collections that
 54.3718 +     * do not comply with the general contract for {@code Collection}.
 54.3719 +     * Implementations may elect to iterate over either collection and test
 54.3720 +     * for containment in the other collection (or to perform any equivalent
 54.3721 +     * computation).  If either collection uses a nonstandard equality test
 54.3722 +     * (as does a {@link SortedSet} whose ordering is not <em>compatible with
 54.3723 +     * equals</em>, or the key set of an {@link IdentityHashMap}), both
 54.3724 +     * collections must use the same nonstandard equality test, or the
 54.3725 +     * result of this method is undefined.
 54.3726 +     *
 54.3727 +     * <p>Care must also be exercised when using collections that have
 54.3728 +     * restrictions on the elements that they may contain. Collection
 54.3729 +     * implementations are allowed to throw exceptions for any operation
 54.3730 +     * involving elements they deem ineligible. For absolute safety the
 54.3731 +     * specified collections should contain only elements which are
 54.3732 +     * eligible elements for both collections.
 54.3733 +     *
 54.3734 +     * <p>Note that it is permissible to pass the same collection in both
 54.3735 +     * parameters, in which case the method will return {@code true} if and
 54.3736 +     * only if the collection is empty.
 54.3737 +     *
 54.3738 +     * @param c1 a collection
 54.3739 +     * @param c2 a collection
 54.3740 +     * @return {@code true} if the two specified collections have no
 54.3741 +     * elements in common.
 54.3742 +     * @throws NullPointerException if either collection is {@code null}.
 54.3743 +     * @throws NullPointerException if one collection contains a {@code null}
 54.3744 +     * element and {@code null} is not an eligible element for the other collection.
 54.3745 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 54.3746 +     * @throws ClassCastException if one collection contains an element that is
 54.3747 +     * of a type which is ineligible for the other collection.
 54.3748 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 54.3749 +     * @since 1.5
 54.3750 +     */
 54.3751 +    public static boolean disjoint(Collection<?> c1, Collection<?> c2) {
 54.3752 +        // The collection to be used for contains(). Preference is given to
 54.3753 +        // the collection who's contains() has lower O() complexity.
 54.3754 +        Collection<?> contains = c2;
 54.3755 +        // The collection to be iterated. If the collections' contains() impl
 54.3756 +        // are of different O() complexity, the collection with slower
 54.3757 +        // contains() will be used for iteration. For collections who's
 54.3758 +        // contains() are of the same complexity then best performance is
 54.3759 +        // achieved by iterating the smaller collection.
 54.3760 +        Collection<?> iterate = c1;
 54.3761 +
 54.3762 +        // Performance optimization cases. The heuristics:
 54.3763 +        //   1. Generally iterate over c1.
 54.3764 +        //   2. If c1 is a Set then iterate over c2.
 54.3765 +        //   3. If either collection is empty then result is always true.
 54.3766 +        //   4. Iterate over the smaller Collection.
 54.3767 +        if (c1 instanceof Set) {
 54.3768 +            // Use c1 for contains as a Set's contains() is expected to perform
 54.3769 +            // better than O(N/2)
 54.3770 +            iterate = c2;
 54.3771 +            contains = c1;
 54.3772 +        } else if (!(c2 instanceof Set)) {
 54.3773 +            // Both are mere Collections. Iterate over smaller collection.
 54.3774 +            // Example: If c1 contains 3 elements and c2 contains 50 elements and
 54.3775 +            // assuming contains() requires ceiling(N/2) comparisons then
 54.3776 +            // checking for all c1 elements in c2 would require 75 comparisons
 54.3777 +            // (3 * ceiling(50/2)) vs. checking all c2 elements in c1 requiring
 54.3778 +            // 100 comparisons (50 * ceiling(3/2)).
 54.3779 +            int c1size = c1.size();
 54.3780 +            int c2size = c2.size();
 54.3781 +            if (c1size == 0 || c2size == 0) {
 54.3782 +                // At least one collection is empty. Nothing will match.
 54.3783 +                return true;
 54.3784 +            }
 54.3785 +
 54.3786 +            if (c1size > c2size) {
 54.3787 +                iterate = c2;
 54.3788 +                contains = c1;
 54.3789 +            }
 54.3790 +        }
 54.3791 +
 54.3792 +        for (Object e : iterate) {
 54.3793 +            if (contains.contains(e)) {
 54.3794 +               // Found a common element. Collections are not disjoint.
 54.3795 +                return false;
 54.3796 +            }
 54.3797 +        }
 54.3798 +
 54.3799 +        // No common elements were found.
 54.3800 +        return true;
 54.3801 +    }
 54.3802 +
 54.3803 +    /**
 54.3804 +     * Adds all of the specified elements to the specified collection.
 54.3805 +     * Elements to be added may be specified individually or as an array.
 54.3806 +     * The behavior of this convenience method is identical to that of
 54.3807 +     * <tt>c.addAll(Arrays.asList(elements))</tt>, but this method is likely
 54.3808 +     * to run significantly faster under most implementations.
 54.3809 +     *
 54.3810 +     * <p>When elements are specified individually, this method provides a
 54.3811 +     * convenient way to add a few elements to an existing collection:
 54.3812 +     * <pre>
 54.3813 +     *     Collections.addAll(flavors, "Peaches 'n Plutonium", "Rocky Racoon");
 54.3814 +     * </pre>
 54.3815 +     *
 54.3816 +     * @param c the collection into which <tt>elements</tt> are to be inserted
 54.3817 +     * @param elements the elements to insert into <tt>c</tt>
 54.3818 +     * @return <tt>true</tt> if the collection changed as a result of the call
 54.3819 +     * @throws UnsupportedOperationException if <tt>c</tt> does not support
 54.3820 +     *         the <tt>add</tt> operation
 54.3821 +     * @throws NullPointerException if <tt>elements</tt> contains one or more
 54.3822 +     *         null values and <tt>c</tt> does not permit null elements, or
 54.3823 +     *         if <tt>c</tt> or <tt>elements</tt> are <tt>null</tt>
 54.3824 +     * @throws IllegalArgumentException if some property of a value in
 54.3825 +     *         <tt>elements</tt> prevents it from being added to <tt>c</tt>
 54.3826 +     * @see Collection#addAll(Collection)
 54.3827 +     * @since 1.5
 54.3828 +     */
 54.3829 +    @SafeVarargs
 54.3830 +    public static <T> boolean addAll(Collection<? super T> c, T... elements) {
 54.3831 +        boolean result = false;
 54.3832 +        for (T element : elements)
 54.3833 +            result |= c.add(element);
 54.3834 +        return result;
 54.3835 +    }
 54.3836 +
 54.3837 +    /**
 54.3838 +     * Returns a set backed by the specified map.  The resulting set displays
 54.3839 +     * the same ordering, concurrency, and performance characteristics as the
 54.3840 +     * backing map.  In essence, this factory method provides a {@link Set}
 54.3841 +     * implementation corresponding to any {@link Map} implementation.  There
 54.3842 +     * is no need to use this method on a {@link Map} implementation that
 54.3843 +     * already has a corresponding {@link Set} implementation (such as {@link
 54.3844 +     * HashMap} or {@link TreeMap}).
 54.3845 +     *
 54.3846 +     * <p>Each method invocation on the set returned by this method results in
 54.3847 +     * exactly one method invocation on the backing map or its <tt>keySet</tt>
 54.3848 +     * view, with one exception.  The <tt>addAll</tt> method is implemented
 54.3849 +     * as a sequence of <tt>put</tt> invocations on the backing map.
 54.3850 +     *
 54.3851 +     * <p>The specified map must be empty at the time this method is invoked,
 54.3852 +     * and should not be accessed directly after this method returns.  These
 54.3853 +     * conditions are ensured if the map is created empty, passed directly
 54.3854 +     * to this method, and no reference to the map is retained, as illustrated
 54.3855 +     * in the following code fragment:
 54.3856 +     * <pre>
 54.3857 +     *    Set&lt;Object&gt; weakHashSet = Collections.newSetFromMap(
 54.3858 +     *        new WeakHashMap&lt;Object, Boolean&gt;());
 54.3859 +     * </pre>
 54.3860 +     *
 54.3861 +     * @param map the backing map
 54.3862 +     * @return the set backed by the map
 54.3863 +     * @throws IllegalArgumentException if <tt>map</tt> is not empty
 54.3864 +     * @since 1.6
 54.3865 +     */
 54.3866 +    public static <E> Set<E> newSetFromMap(Map<E, Boolean> map) {
 54.3867 +        return new SetFromMap<>(map);
 54.3868 +    }
 54.3869 +
 54.3870 +    /**
 54.3871 +     * @serial include
 54.3872 +     */
 54.3873 +    private static class SetFromMap<E> extends AbstractSet<E>
 54.3874 +        implements Set<E>, Serializable
 54.3875 +    {
 54.3876 +        private final Map<E, Boolean> m;  // The backing map
 54.3877 +        private transient Set<E> s;       // Its keySet
 54.3878 +
 54.3879 +        SetFromMap(Map<E, Boolean> map) {
 54.3880 +            if (!map.isEmpty())
 54.3881 +                throw new IllegalArgumentException("Map is non-empty");
 54.3882 +            m = map;
 54.3883 +            s = map.keySet();
 54.3884 +        }
 54.3885 +
 54.3886 +        public void clear()               {        m.clear(); }
 54.3887 +        public int size()                 { return m.size(); }
 54.3888 +        public boolean isEmpty()          { return m.isEmpty(); }
 54.3889 +        public boolean contains(Object o) { return m.containsKey(o); }
 54.3890 +        public boolean remove(Object o)   { return m.remove(o) != null; }
 54.3891 +        public boolean add(E e) { return m.put(e, Boolean.TRUE) == null; }
 54.3892 +        public Iterator<E> iterator()     { return s.iterator(); }
 54.3893 +        public Object[] toArray()         { return s.toArray(); }
 54.3894 +        public <T> T[] toArray(T[] a)     { return s.toArray(a); }
 54.3895 +        public String toString()          { return s.toString(); }
 54.3896 +        public int hashCode()             { return s.hashCode(); }
 54.3897 +        public boolean equals(Object o)   { return o == this || s.equals(o); }
 54.3898 +        public boolean containsAll(Collection<?> c) {return s.containsAll(c);}
 54.3899 +        public boolean removeAll(Collection<?> c)   {return s.removeAll(c);}
 54.3900 +        public boolean retainAll(Collection<?> c)   {return s.retainAll(c);}
 54.3901 +        // addAll is the only inherited implementation
 54.3902 +
 54.3903 +        private static final long serialVersionUID = 2454657854757543876L;
 54.3904 +
 54.3905 +    }
 54.3906 +
 54.3907 +    /**
 54.3908 +     * Returns a view of a {@link Deque} as a Last-in-first-out (Lifo)
 54.3909 +     * {@link Queue}. Method <tt>add</tt> is mapped to <tt>push</tt>,
 54.3910 +     * <tt>remove</tt> is mapped to <tt>pop</tt> and so on. This
 54.3911 +     * view can be useful when you would like to use a method
 54.3912 +     * requiring a <tt>Queue</tt> but you need Lifo ordering.
 54.3913 +     *
 54.3914 +     * <p>Each method invocation on the queue returned by this method
 54.3915 +     * results in exactly one method invocation on the backing deque, with
 54.3916 +     * one exception.  The {@link Queue#addAll addAll} method is
 54.3917 +     * implemented as a sequence of {@link Deque#addFirst addFirst}
 54.3918 +     * invocations on the backing deque.
 54.3919 +     *
 54.3920 +     * @param deque the deque
 54.3921 +     * @return the queue
 54.3922 +     * @since  1.6
 54.3923 +     */
 54.3924 +    public static <T> Queue<T> asLifoQueue(Deque<T> deque) {
 54.3925 +        return new AsLIFOQueue<>(deque);
 54.3926 +    }
 54.3927 +
 54.3928 +    /**
 54.3929 +     * @serial include
 54.3930 +     */
 54.3931 +    static class AsLIFOQueue<E> extends AbstractQueue<E>
 54.3932 +        implements Queue<E>, Serializable {
 54.3933 +        private static final long serialVersionUID = 1802017725587941708L;
 54.3934 +        private final Deque<E> q;
 54.3935 +        AsLIFOQueue(Deque<E> q)           { this.q = q; }
 54.3936 +        public boolean add(E e)           { q.addFirst(e); return true; }
 54.3937 +        public boolean offer(E e)         { return q.offerFirst(e); }
 54.3938 +        public E poll()                   { return q.pollFirst(); }
 54.3939 +        public E remove()                 { return q.removeFirst(); }
 54.3940 +        public E peek()                   { return q.peekFirst(); }
 54.3941 +        public E element()                { return q.getFirst(); }
 54.3942 +        public void clear()               {        q.clear(); }
 54.3943 +        public int size()                 { return q.size(); }
 54.3944 +        public boolean isEmpty()          { return q.isEmpty(); }
 54.3945 +        public boolean contains(Object o) { return q.contains(o); }
 54.3946 +        public boolean remove(Object o)   { return q.remove(o); }
 54.3947 +        public Iterator<E> iterator()     { return q.iterator(); }
 54.3948 +        public Object[] toArray()         { return q.toArray(); }
 54.3949 +        public <T> T[] toArray(T[] a)     { return q.toArray(a); }
 54.3950 +        public String toString()          { return q.toString(); }
 54.3951 +        public boolean containsAll(Collection<?> c) {return q.containsAll(c);}
 54.3952 +        public boolean removeAll(Collection<?> c)   {return q.removeAll(c);}
 54.3953 +        public boolean retainAll(Collection<?> c)   {return q.retainAll(c);}
 54.3954 +        // We use inherited addAll; forwarding addAll would be wrong
 54.3955 +    }
 54.3956 +}
    55.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    55.2 +++ b/emul/compact/src/main/java/java/util/ComparableTimSort.java	Sun Feb 03 07:48:42 2013 +0100
    55.3 @@ -0,0 +1,896 @@
    55.4 +/*
    55.5 + * Copyright 2009 Google Inc.  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.util;
   55.30 +
   55.31 +
   55.32 +/**
   55.33 + * This is a near duplicate of {@link TimSort}, modified for use with
   55.34 + * arrays of objects that implement {@link Comparable}, instead of using
   55.35 + * explicit comparators.
   55.36 + *
   55.37 + * <p>If you are using an optimizing VM, you may find that ComparableTimSort
   55.38 + * offers no performance benefit over TimSort in conjunction with a
   55.39 + * comparator that simply returns {@code ((Comparable)first).compareTo(Second)}.
   55.40 + * If this is the case, you are better off deleting ComparableTimSort to
   55.41 + * eliminate the code duplication.  (See Arrays.java for details.)
   55.42 + *
   55.43 + * @author Josh Bloch
   55.44 + */
   55.45 +class ComparableTimSort {
   55.46 +    /**
   55.47 +     * This is the minimum sized sequence that will be merged.  Shorter
   55.48 +     * sequences will be lengthened by calling binarySort.  If the entire
   55.49 +     * array is less than this length, no merges will be performed.
   55.50 +     *
   55.51 +     * This constant should be a power of two.  It was 64 in Tim Peter's C
   55.52 +     * implementation, but 32 was empirically determined to work better in
   55.53 +     * this implementation.  In the unlikely event that you set this constant
   55.54 +     * to be a number that's not a power of two, you'll need to change the
   55.55 +     * {@link #minRunLength} computation.
   55.56 +     *
   55.57 +     * If you decrease this constant, you must change the stackLen
   55.58 +     * computation in the TimSort constructor, or you risk an
   55.59 +     * ArrayOutOfBounds exception.  See listsort.txt for a discussion
   55.60 +     * of the minimum stack length required as a function of the length
   55.61 +     * of the array being sorted and the minimum merge sequence length.
   55.62 +     */
   55.63 +    private static final int MIN_MERGE = 32;
   55.64 +
   55.65 +    /**
   55.66 +     * The array being sorted.
   55.67 +     */
   55.68 +    private final Object[] a;
   55.69 +
   55.70 +    /**
   55.71 +     * When we get into galloping mode, we stay there until both runs win less
   55.72 +     * often than MIN_GALLOP consecutive times.
   55.73 +     */
   55.74 +    private static final int  MIN_GALLOP = 7;
   55.75 +
   55.76 +    /**
   55.77 +     * This controls when we get *into* galloping mode.  It is initialized
   55.78 +     * to MIN_GALLOP.  The mergeLo and mergeHi methods nudge it higher for
   55.79 +     * random data, and lower for highly structured data.
   55.80 +     */
   55.81 +    private int minGallop = MIN_GALLOP;
   55.82 +
   55.83 +    /**
   55.84 +     * Maximum initial size of tmp array, which is used for merging.  The array
   55.85 +     * can grow to accommodate demand.
   55.86 +     *
   55.87 +     * Unlike Tim's original C version, we do not allocate this much storage
   55.88 +     * when sorting smaller arrays.  This change was required for performance.
   55.89 +     */
   55.90 +    private static final int INITIAL_TMP_STORAGE_LENGTH = 256;
   55.91 +
   55.92 +    /**
   55.93 +     * Temp storage for merges.
   55.94 +     */
   55.95 +    private Object[] tmp;
   55.96 +
   55.97 +    /**
   55.98 +     * A stack of pending runs yet to be merged.  Run i starts at
   55.99 +     * address base[i] and extends for len[i] elements.  It's always
  55.100 +     * true (so long as the indices are in bounds) that:
  55.101 +     *
  55.102 +     *     runBase[i] + runLen[i] == runBase[i + 1]
  55.103 +     *
  55.104 +     * so we could cut the storage for this, but it's a minor amount,
  55.105 +     * and keeping all the info explicit simplifies the code.
  55.106 +     */
  55.107 +    private int stackSize = 0;  // Number of pending runs on stack
  55.108 +    private final int[] runBase;
  55.109 +    private final int[] runLen;
  55.110 +
  55.111 +    /**
  55.112 +     * Creates a TimSort instance to maintain the state of an ongoing sort.
  55.113 +     *
  55.114 +     * @param a the array to be sorted
  55.115 +     */
  55.116 +    private ComparableTimSort(Object[] a) {
  55.117 +        this.a = a;
  55.118 +
  55.119 +        // Allocate temp storage (which may be increased later if necessary)
  55.120 +        int len = a.length;
  55.121 +        @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
  55.122 +        Object[] newArray = new Object[len < 2 * INITIAL_TMP_STORAGE_LENGTH ?
  55.123 +                                       len >>> 1 : INITIAL_TMP_STORAGE_LENGTH];
  55.124 +        tmp = newArray;
  55.125 +
  55.126 +        /*
  55.127 +         * Allocate runs-to-be-merged stack (which cannot be expanded).  The
  55.128 +         * stack length requirements are described in listsort.txt.  The C
  55.129 +         * version always uses the same stack length (85), but this was
  55.130 +         * measured to be too expensive when sorting "mid-sized" arrays (e.g.,
  55.131 +         * 100 elements) in Java.  Therefore, we use smaller (but sufficiently
  55.132 +         * large) stack lengths for smaller arrays.  The "magic numbers" in the
  55.133 +         * computation below must be changed if MIN_MERGE is decreased.  See
  55.134 +         * the MIN_MERGE declaration above for more information.
  55.135 +         */
  55.136 +        int stackLen = (len <    120  ?  5 :
  55.137 +                        len <   1542  ? 10 :
  55.138 +                        len < 119151  ? 19 : 40);
  55.139 +        runBase = new int[stackLen];
  55.140 +        runLen = new int[stackLen];
  55.141 +    }
  55.142 +
  55.143 +    /*
  55.144 +     * The next two methods (which are package private and static) constitute
  55.145 +     * the entire API of this class.  Each of these methods obeys the contract
  55.146 +     * of the public method with the same signature in java.util.Arrays.
  55.147 +     */
  55.148 +
  55.149 +    static void sort(Object[] a) {
  55.150 +          sort(a, 0, a.length);
  55.151 +    }
  55.152 +
  55.153 +    static void sort(Object[] a, int lo, int hi) {
  55.154 +        rangeCheck(a.length, lo, hi);
  55.155 +        int nRemaining  = hi - lo;
  55.156 +        if (nRemaining < 2)
  55.157 +            return;  // Arrays of size 0 and 1 are always sorted
  55.158 +
  55.159 +        // If array is small, do a "mini-TimSort" with no merges
  55.160 +        if (nRemaining < MIN_MERGE) {
  55.161 +            int initRunLen = countRunAndMakeAscending(a, lo, hi);
  55.162 +            binarySort(a, lo, hi, lo + initRunLen);
  55.163 +            return;
  55.164 +        }
  55.165 +
  55.166 +        /**
  55.167 +         * March over the array once, left to right, finding natural runs,
  55.168 +         * extending short natural runs to minRun elements, and merging runs
  55.169 +         * to maintain stack invariant.
  55.170 +         */
  55.171 +        ComparableTimSort ts = new ComparableTimSort(a);
  55.172 +        int minRun = minRunLength(nRemaining);
  55.173 +        do {
  55.174 +            // Identify next run
  55.175 +            int runLen = countRunAndMakeAscending(a, lo, hi);
  55.176 +
  55.177 +            // If run is short, extend to min(minRun, nRemaining)
  55.178 +            if (runLen < minRun) {
  55.179 +                int force = nRemaining <= minRun ? nRemaining : minRun;
  55.180 +                binarySort(a, lo, lo + force, lo + runLen);
  55.181 +                runLen = force;
  55.182 +            }
  55.183 +
  55.184 +            // Push run onto pending-run stack, and maybe merge
  55.185 +            ts.pushRun(lo, runLen);
  55.186 +            ts.mergeCollapse();
  55.187 +
  55.188 +            // Advance to find next run
  55.189 +            lo += runLen;
  55.190 +            nRemaining -= runLen;
  55.191 +        } while (nRemaining != 0);
  55.192 +
  55.193 +        // Merge all remaining runs to complete sort
  55.194 +        assert lo == hi;
  55.195 +        ts.mergeForceCollapse();
  55.196 +        assert ts.stackSize == 1;
  55.197 +    }
  55.198 +
  55.199 +    /**
  55.200 +     * Sorts the specified portion of the specified array using a binary
  55.201 +     * insertion sort.  This is the best method for sorting small numbers
  55.202 +     * of elements.  It requires O(n log n) compares, but O(n^2) data
  55.203 +     * movement (worst case).
  55.204 +     *
  55.205 +     * If the initial part of the specified range is already sorted,
  55.206 +     * this method can take advantage of it: the method assumes that the
  55.207 +     * elements from index {@code lo}, inclusive, to {@code start},
  55.208 +     * exclusive are already sorted.
  55.209 +     *
  55.210 +     * @param a the array in which a range is to be sorted
  55.211 +     * @param lo the index of the first element in the range to be sorted
  55.212 +     * @param hi the index after the last element in the range to be sorted
  55.213 +     * @param start the index of the first element in the range that is
  55.214 +     *        not already known to be sorted ({@code lo <= start <= hi})
  55.215 +     */
  55.216 +    @SuppressWarnings("fallthrough")
  55.217 +    private static void binarySort(Object[] a, int lo, int hi, int start) {
  55.218 +        assert lo <= start && start <= hi;
  55.219 +        if (start == lo)
  55.220 +            start++;
  55.221 +        for ( ; start < hi; start++) {
  55.222 +            @SuppressWarnings("unchecked")
  55.223 +            Comparable<Object> pivot = (Comparable) a[start];
  55.224 +
  55.225 +            // Set left (and right) to the index where a[start] (pivot) belongs
  55.226 +            int left = lo;
  55.227 +            int right = start;
  55.228 +            assert left <= right;
  55.229 +            /*
  55.230 +             * Invariants:
  55.231 +             *   pivot >= all in [lo, left).
  55.232 +             *   pivot <  all in [right, start).
  55.233 +             */
  55.234 +            while (left < right) {
  55.235 +                int mid = (left + right) >>> 1;
  55.236 +                if (pivot.compareTo(a[mid]) < 0)
  55.237 +                    right = mid;
  55.238 +                else
  55.239 +                    left = mid + 1;
  55.240 +            }
  55.241 +            assert left == right;
  55.242 +
  55.243 +            /*
  55.244 +             * The invariants still hold: pivot >= all in [lo, left) and
  55.245 +             * pivot < all in [left, start), so pivot belongs at left.  Note
  55.246 +             * that if there are elements equal to pivot, left points to the
  55.247 +             * first slot after them -- that's why this sort is stable.
  55.248 +             * Slide elements over to make room for pivot.
  55.249 +             */
  55.250 +            int n = start - left;  // The number of elements to move
  55.251 +            // Switch is just an optimization for arraycopy in default case
  55.252 +            switch (n) {
  55.253 +                case 2:  a[left + 2] = a[left + 1];
  55.254 +                case 1:  a[left + 1] = a[left];
  55.255 +                         break;
  55.256 +                default: System.arraycopy(a, left, a, left + 1, n);
  55.257 +            }
  55.258 +            a[left] = pivot;
  55.259 +        }
  55.260 +    }
  55.261 +
  55.262 +    /**
  55.263 +     * Returns the length of the run beginning at the specified position in
  55.264 +     * the specified array and reverses the run if it is descending (ensuring
  55.265 +     * that the run will always be ascending when the method returns).
  55.266 +     *
  55.267 +     * A run is the longest ascending sequence with:
  55.268 +     *
  55.269 +     *    a[lo] <= a[lo + 1] <= a[lo + 2] <= ...
  55.270 +     *
  55.271 +     * or the longest descending sequence with:
  55.272 +     *
  55.273 +     *    a[lo] >  a[lo + 1] >  a[lo + 2] >  ...
  55.274 +     *
  55.275 +     * For its intended use in a stable mergesort, the strictness of the
  55.276 +     * definition of "descending" is needed so that the call can safely
  55.277 +     * reverse a descending sequence without violating stability.
  55.278 +     *
  55.279 +     * @param a the array in which a run is to be counted and possibly reversed
  55.280 +     * @param lo index of the first element in the run
  55.281 +     * @param hi index after the last element that may be contained in the run.
  55.282 +              It is required that {@code lo < hi}.
  55.283 +     * @return  the length of the run beginning at the specified position in
  55.284 +     *          the specified array
  55.285 +     */
  55.286 +    @SuppressWarnings("unchecked")
  55.287 +    private static int countRunAndMakeAscending(Object[] a, int lo, int hi) {
  55.288 +        assert lo < hi;
  55.289 +        int runHi = lo + 1;
  55.290 +        if (runHi == hi)
  55.291 +            return 1;
  55.292 +
  55.293 +        // Find end of run, and reverse range if descending
  55.294 +        if (((Comparable) a[runHi++]).compareTo(a[lo]) < 0) { // Descending
  55.295 +            while (runHi < hi && ((Comparable) a[runHi]).compareTo(a[runHi - 1]) < 0)
  55.296 +                runHi++;
  55.297 +            reverseRange(a, lo, runHi);
  55.298 +        } else {                              // Ascending
  55.299 +            while (runHi < hi && ((Comparable) a[runHi]).compareTo(a[runHi - 1]) >= 0)
  55.300 +                runHi++;
  55.301 +        }
  55.302 +
  55.303 +        return runHi - lo;
  55.304 +    }
  55.305 +
  55.306 +    /**
  55.307 +     * Reverse the specified range of the specified array.
  55.308 +     *
  55.309 +     * @param a the array in which a range is to be reversed
  55.310 +     * @param lo the index of the first element in the range to be reversed
  55.311 +     * @param hi the index after the last element in the range to be reversed
  55.312 +     */
  55.313 +    private static void reverseRange(Object[] a, int lo, int hi) {
  55.314 +        hi--;
  55.315 +        while (lo < hi) {
  55.316 +            Object t = a[lo];
  55.317 +            a[lo++] = a[hi];
  55.318 +            a[hi--] = t;
  55.319 +        }
  55.320 +    }
  55.321 +
  55.322 +    /**
  55.323 +     * Returns the minimum acceptable run length for an array of the specified
  55.324 +     * length. Natural runs shorter than this will be extended with
  55.325 +     * {@link #binarySort}.
  55.326 +     *
  55.327 +     * Roughly speaking, the computation is:
  55.328 +     *
  55.329 +     *  If n < MIN_MERGE, return n (it's too small to bother with fancy stuff).
  55.330 +     *  Else if n is an exact power of 2, return MIN_MERGE/2.
  55.331 +     *  Else return an int k, MIN_MERGE/2 <= k <= MIN_MERGE, such that n/k
  55.332 +     *   is close to, but strictly less than, an exact power of 2.
  55.333 +     *
  55.334 +     * For the rationale, see listsort.txt.
  55.335 +     *
  55.336 +     * @param n the length of the array to be sorted
  55.337 +     * @return the length of the minimum run to be merged
  55.338 +     */
  55.339 +    private static int minRunLength(int n) {
  55.340 +        assert n >= 0;
  55.341 +        int r = 0;      // Becomes 1 if any 1 bits are shifted off
  55.342 +        while (n >= MIN_MERGE) {
  55.343 +            r |= (n & 1);
  55.344 +            n >>= 1;
  55.345 +        }
  55.346 +        return n + r;
  55.347 +    }
  55.348 +
  55.349 +    /**
  55.350 +     * Pushes the specified run onto the pending-run stack.
  55.351 +     *
  55.352 +     * @param runBase index of the first element in the run
  55.353 +     * @param runLen  the number of elements in the run
  55.354 +     */
  55.355 +    private void pushRun(int runBase, int runLen) {
  55.356 +        this.runBase[stackSize] = runBase;
  55.357 +        this.runLen[stackSize] = runLen;
  55.358 +        stackSize++;
  55.359 +    }
  55.360 +
  55.361 +    /**
  55.362 +     * Examines the stack of runs waiting to be merged and merges adjacent runs
  55.363 +     * until the stack invariants are reestablished:
  55.364 +     *
  55.365 +     *     1. runLen[i - 3] > runLen[i - 2] + runLen[i - 1]
  55.366 +     *     2. runLen[i - 2] > runLen[i - 1]
  55.367 +     *
  55.368 +     * This method is called each time a new run is pushed onto the stack,
  55.369 +     * so the invariants are guaranteed to hold for i < stackSize upon
  55.370 +     * entry to the method.
  55.371 +     */
  55.372 +    private void mergeCollapse() {
  55.373 +        while (stackSize > 1) {
  55.374 +            int n = stackSize - 2;
  55.375 +            if (n > 0 && runLen[n-1] <= runLen[n] + runLen[n+1]) {
  55.376 +                if (runLen[n - 1] < runLen[n + 1])
  55.377 +                    n--;
  55.378 +                mergeAt(n);
  55.379 +            } else if (runLen[n] <= runLen[n + 1]) {
  55.380 +                mergeAt(n);
  55.381 +            } else {
  55.382 +                break; // Invariant is established
  55.383 +            }
  55.384 +        }
  55.385 +    }
  55.386 +
  55.387 +    /**
  55.388 +     * Merges all runs on the stack until only one remains.  This method is
  55.389 +     * called once, to complete the sort.
  55.390 +     */
  55.391 +    private void mergeForceCollapse() {
  55.392 +        while (stackSize > 1) {
  55.393 +            int n = stackSize - 2;
  55.394 +            if (n > 0 && runLen[n - 1] < runLen[n + 1])
  55.395 +                n--;
  55.396 +            mergeAt(n);
  55.397 +        }
  55.398 +    }
  55.399 +
  55.400 +    /**
  55.401 +     * Merges the two runs at stack indices i and i+1.  Run i must be
  55.402 +     * the penultimate or antepenultimate run on the stack.  In other words,
  55.403 +     * i must be equal to stackSize-2 or stackSize-3.
  55.404 +     *
  55.405 +     * @param i stack index of the first of the two runs to merge
  55.406 +     */
  55.407 +    @SuppressWarnings("unchecked")
  55.408 +    private void mergeAt(int i) {
  55.409 +        assert stackSize >= 2;
  55.410 +        assert i >= 0;
  55.411 +        assert i == stackSize - 2 || i == stackSize - 3;
  55.412 +
  55.413 +        int base1 = runBase[i];
  55.414 +        int len1 = runLen[i];
  55.415 +        int base2 = runBase[i + 1];
  55.416 +        int len2 = runLen[i + 1];
  55.417 +        assert len1 > 0 && len2 > 0;
  55.418 +        assert base1 + len1 == base2;
  55.419 +
  55.420 +        /*
  55.421 +         * Record the length of the combined runs; if i is the 3rd-last
  55.422 +         * run now, also slide over the last run (which isn't involved
  55.423 +         * in this merge).  The current run (i+1) goes away in any case.
  55.424 +         */
  55.425 +        runLen[i] = len1 + len2;
  55.426 +        if (i == stackSize - 3) {
  55.427 +            runBase[i + 1] = runBase[i + 2];
  55.428 +            runLen[i + 1] = runLen[i + 2];
  55.429 +        }
  55.430 +        stackSize--;
  55.431 +
  55.432 +        /*
  55.433 +         * Find where the first element of run2 goes in run1. Prior elements
  55.434 +         * in run1 can be ignored (because they're already in place).
  55.435 +         */
  55.436 +        int k = gallopRight((Comparable<Object>) a[base2], a, base1, len1, 0);
  55.437 +        assert k >= 0;
  55.438 +        base1 += k;
  55.439 +        len1 -= k;
  55.440 +        if (len1 == 0)
  55.441 +            return;
  55.442 +
  55.443 +        /*
  55.444 +         * Find where the last element of run1 goes in run2. Subsequent elements
  55.445 +         * in run2 can be ignored (because they're already in place).
  55.446 +         */
  55.447 +        len2 = gallopLeft((Comparable<Object>) a[base1 + len1 - 1], a,
  55.448 +                base2, len2, len2 - 1);
  55.449 +        assert len2 >= 0;
  55.450 +        if (len2 == 0)
  55.451 +            return;
  55.452 +
  55.453 +        // Merge remaining runs, using tmp array with min(len1, len2) elements
  55.454 +        if (len1 <= len2)
  55.455 +            mergeLo(base1, len1, base2, len2);
  55.456 +        else
  55.457 +            mergeHi(base1, len1, base2, len2);
  55.458 +    }
  55.459 +
  55.460 +    /**
  55.461 +     * Locates the position at which to insert the specified key into the
  55.462 +     * specified sorted range; if the range contains an element equal to key,
  55.463 +     * returns the index of the leftmost equal element.
  55.464 +     *
  55.465 +     * @param key the key whose insertion point to search for
  55.466 +     * @param a the array in which to search
  55.467 +     * @param base the index of the first element in the range
  55.468 +     * @param len the length of the range; must be > 0
  55.469 +     * @param hint the index at which to begin the search, 0 <= hint < n.
  55.470 +     *     The closer hint is to the result, the faster this method will run.
  55.471 +     * @return the int k,  0 <= k <= n such that a[b + k - 1] < key <= a[b + k],
  55.472 +     *    pretending that a[b - 1] is minus infinity and a[b + n] is infinity.
  55.473 +     *    In other words, key belongs at index b + k; or in other words,
  55.474 +     *    the first k elements of a should precede key, and the last n - k
  55.475 +     *    should follow it.
  55.476 +     */
  55.477 +    private static int gallopLeft(Comparable<Object> key, Object[] a,
  55.478 +            int base, int len, int hint) {
  55.479 +        assert len > 0 && hint >= 0 && hint < len;
  55.480 +
  55.481 +        int lastOfs = 0;
  55.482 +        int ofs = 1;
  55.483 +        if (key.compareTo(a[base + hint]) > 0) {
  55.484 +            // Gallop right until a[base+hint+lastOfs] < key <= a[base+hint+ofs]
  55.485 +            int maxOfs = len - hint;
  55.486 +            while (ofs < maxOfs && key.compareTo(a[base + hint + ofs]) > 0) {
  55.487 +                lastOfs = ofs;
  55.488 +                ofs = (ofs << 1) + 1;
  55.489 +                if (ofs <= 0)   // int overflow
  55.490 +                    ofs = maxOfs;
  55.491 +            }
  55.492 +            if (ofs > maxOfs)
  55.493 +                ofs = maxOfs;
  55.494 +
  55.495 +            // Make offsets relative to base
  55.496 +            lastOfs += hint;
  55.497 +            ofs += hint;
  55.498 +        } else { // key <= a[base + hint]
  55.499 +            // Gallop left until a[base+hint-ofs] < key <= a[base+hint-lastOfs]
  55.500 +            final int maxOfs = hint + 1;
  55.501 +            while (ofs < maxOfs && key.compareTo(a[base + hint - ofs]) <= 0) {
  55.502 +                lastOfs = ofs;
  55.503 +                ofs = (ofs << 1) + 1;
  55.504 +                if (ofs <= 0)   // int overflow
  55.505 +                    ofs = maxOfs;
  55.506 +            }
  55.507 +            if (ofs > maxOfs)
  55.508 +                ofs = maxOfs;
  55.509 +
  55.510 +            // Make offsets relative to base
  55.511 +            int tmp = lastOfs;
  55.512 +            lastOfs = hint - ofs;
  55.513 +            ofs = hint - tmp;
  55.514 +        }
  55.515 +        assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
  55.516 +
  55.517 +        /*
  55.518 +         * Now a[base+lastOfs] < key <= a[base+ofs], so key belongs somewhere
  55.519 +         * to the right of lastOfs but no farther right than ofs.  Do a binary
  55.520 +         * search, with invariant a[base + lastOfs - 1] < key <= a[base + ofs].
  55.521 +         */
  55.522 +        lastOfs++;
  55.523 +        while (lastOfs < ofs) {
  55.524 +            int m = lastOfs + ((ofs - lastOfs) >>> 1);
  55.525 +
  55.526 +            if (key.compareTo(a[base + m]) > 0)
  55.527 +                lastOfs = m + 1;  // a[base + m] < key
  55.528 +            else
  55.529 +                ofs = m;          // key <= a[base + m]
  55.530 +        }
  55.531 +        assert lastOfs == ofs;    // so a[base + ofs - 1] < key <= a[base + ofs]
  55.532 +        return ofs;
  55.533 +    }
  55.534 +
  55.535 +    /**
  55.536 +     * Like gallopLeft, except that if the range contains an element equal to
  55.537 +     * key, gallopRight returns the index after the rightmost equal element.
  55.538 +     *
  55.539 +     * @param key the key whose insertion point to search for
  55.540 +     * @param a the array in which to search
  55.541 +     * @param base the index of the first element in the range
  55.542 +     * @param len the length of the range; must be > 0
  55.543 +     * @param hint the index at which to begin the search, 0 <= hint < n.
  55.544 +     *     The closer hint is to the result, the faster this method will run.
  55.545 +     * @return the int k,  0 <= k <= n such that a[b + k - 1] <= key < a[b + k]
  55.546 +     */
  55.547 +    private static int gallopRight(Comparable<Object> key, Object[] a,
  55.548 +            int base, int len, int hint) {
  55.549 +        assert len > 0 && hint >= 0 && hint < len;
  55.550 +
  55.551 +        int ofs = 1;
  55.552 +        int lastOfs = 0;
  55.553 +        if (key.compareTo(a[base + hint]) < 0) {
  55.554 +            // Gallop left until a[b+hint - ofs] <= key < a[b+hint - lastOfs]
  55.555 +            int maxOfs = hint + 1;
  55.556 +            while (ofs < maxOfs && key.compareTo(a[base + hint - ofs]) < 0) {
  55.557 +                lastOfs = ofs;
  55.558 +                ofs = (ofs << 1) + 1;
  55.559 +                if (ofs <= 0)   // int overflow
  55.560 +                    ofs = maxOfs;
  55.561 +            }
  55.562 +            if (ofs > maxOfs)
  55.563 +                ofs = maxOfs;
  55.564 +
  55.565 +            // Make offsets relative to b
  55.566 +            int tmp = lastOfs;
  55.567 +            lastOfs = hint - ofs;
  55.568 +            ofs = hint - tmp;
  55.569 +        } else { // a[b + hint] <= key
  55.570 +            // Gallop right until a[b+hint + lastOfs] <= key < a[b+hint + ofs]
  55.571 +            int maxOfs = len - hint;
  55.572 +            while (ofs < maxOfs && key.compareTo(a[base + hint + ofs]) >= 0) {
  55.573 +                lastOfs = ofs;
  55.574 +                ofs = (ofs << 1) + 1;
  55.575 +                if (ofs <= 0)   // int overflow
  55.576 +                    ofs = maxOfs;
  55.577 +            }
  55.578 +            if (ofs > maxOfs)
  55.579 +                ofs = maxOfs;
  55.580 +
  55.581 +            // Make offsets relative to b
  55.582 +            lastOfs += hint;
  55.583 +            ofs += hint;
  55.584 +        }
  55.585 +        assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
  55.586 +
  55.587 +        /*
  55.588 +         * Now a[b + lastOfs] <= key < a[b + ofs], so key belongs somewhere to
  55.589 +         * the right of lastOfs but no farther right than ofs.  Do a binary
  55.590 +         * search, with invariant a[b + lastOfs - 1] <= key < a[b + ofs].
  55.591 +         */
  55.592 +        lastOfs++;
  55.593 +        while (lastOfs < ofs) {
  55.594 +            int m = lastOfs + ((ofs - lastOfs) >>> 1);
  55.595 +
  55.596 +            if (key.compareTo(a[base + m]) < 0)
  55.597 +                ofs = m;          // key < a[b + m]
  55.598 +            else
  55.599 +                lastOfs = m + 1;  // a[b + m] <= key
  55.600 +        }
  55.601 +        assert lastOfs == ofs;    // so a[b + ofs - 1] <= key < a[b + ofs]
  55.602 +        return ofs;
  55.603 +    }
  55.604 +
  55.605 +    /**
  55.606 +     * Merges two adjacent runs in place, in a stable fashion.  The first
  55.607 +     * element of the first run must be greater than the first element of the
  55.608 +     * second run (a[base1] > a[base2]), and the last element of the first run
  55.609 +     * (a[base1 + len1-1]) must be greater than all elements of the second run.
  55.610 +     *
  55.611 +     * For performance, this method should be called only when len1 <= len2;
  55.612 +     * its twin, mergeHi should be called if len1 >= len2.  (Either method
  55.613 +     * may be called if len1 == len2.)
  55.614 +     *
  55.615 +     * @param base1 index of first element in first run to be merged
  55.616 +     * @param len1  length of first run to be merged (must be > 0)
  55.617 +     * @param base2 index of first element in second run to be merged
  55.618 +     *        (must be aBase + aLen)
  55.619 +     * @param len2  length of second run to be merged (must be > 0)
  55.620 +     */
  55.621 +    @SuppressWarnings("unchecked")
  55.622 +    private void mergeLo(int base1, int len1, int base2, int len2) {
  55.623 +        assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
  55.624 +
  55.625 +        // Copy first run into temp array
  55.626 +        Object[] a = this.a; // For performance
  55.627 +        Object[] tmp = ensureCapacity(len1);
  55.628 +        System.arraycopy(a, base1, tmp, 0, len1);
  55.629 +
  55.630 +        int cursor1 = 0;       // Indexes into tmp array
  55.631 +        int cursor2 = base2;   // Indexes int a
  55.632 +        int dest = base1;      // Indexes int a
  55.633 +
  55.634 +        // Move first element of second run and deal with degenerate cases
  55.635 +        a[dest++] = a[cursor2++];
  55.636 +        if (--len2 == 0) {
  55.637 +            System.arraycopy(tmp, cursor1, a, dest, len1);
  55.638 +            return;
  55.639 +        }
  55.640 +        if (len1 == 1) {
  55.641 +            System.arraycopy(a, cursor2, a, dest, len2);
  55.642 +            a[dest + len2] = tmp[cursor1]; // Last elt of run 1 to end of merge
  55.643 +            return;
  55.644 +        }
  55.645 +
  55.646 +        int minGallop = this.minGallop;  // Use local variable for performance
  55.647 +    outer:
  55.648 +        while (true) {
  55.649 +            int count1 = 0; // Number of times in a row that first run won
  55.650 +            int count2 = 0; // Number of times in a row that second run won
  55.651 +
  55.652 +            /*
  55.653 +             * Do the straightforward thing until (if ever) one run starts
  55.654 +             * winning consistently.
  55.655 +             */
  55.656 +            do {
  55.657 +                assert len1 > 1 && len2 > 0;
  55.658 +                if (((Comparable) a[cursor2]).compareTo(tmp[cursor1]) < 0) {
  55.659 +                    a[dest++] = a[cursor2++];
  55.660 +                    count2++;
  55.661 +                    count1 = 0;
  55.662 +                    if (--len2 == 0)
  55.663 +                        break outer;
  55.664 +                } else {
  55.665 +                    a[dest++] = tmp[cursor1++];
  55.666 +                    count1++;
  55.667 +                    count2 = 0;
  55.668 +                    if (--len1 == 1)
  55.669 +                        break outer;
  55.670 +                }
  55.671 +            } while ((count1 | count2) < minGallop);
  55.672 +
  55.673 +            /*
  55.674 +             * One run is winning so consistently that galloping may be a
  55.675 +             * huge win. So try that, and continue galloping until (if ever)
  55.676 +             * neither run appears to be winning consistently anymore.
  55.677 +             */
  55.678 +            do {
  55.679 +                assert len1 > 1 && len2 > 0;
  55.680 +                count1 = gallopRight((Comparable) a[cursor2], tmp, cursor1, len1, 0);
  55.681 +                if (count1 != 0) {
  55.682 +                    System.arraycopy(tmp, cursor1, a, dest, count1);
  55.683 +                    dest += count1;
  55.684 +                    cursor1 += count1;
  55.685 +                    len1 -= count1;
  55.686 +                    if (len1 <= 1)  // len1 == 1 || len1 == 0
  55.687 +                        break outer;
  55.688 +                }
  55.689 +                a[dest++] = a[cursor2++];
  55.690 +                if (--len2 == 0)
  55.691 +                    break outer;
  55.692 +
  55.693 +                count2 = gallopLeft((Comparable) tmp[cursor1], a, cursor2, len2, 0);
  55.694 +                if (count2 != 0) {
  55.695 +                    System.arraycopy(a, cursor2, a, dest, count2);
  55.696 +                    dest += count2;
  55.697 +                    cursor2 += count2;
  55.698 +                    len2 -= count2;
  55.699 +                    if (len2 == 0)
  55.700 +                        break outer;
  55.701 +                }
  55.702 +                a[dest++] = tmp[cursor1++];
  55.703 +                if (--len1 == 1)
  55.704 +                    break outer;
  55.705 +                minGallop--;
  55.706 +            } while (count1 >= MIN_GALLOP | count2 >= MIN_GALLOP);
  55.707 +            if (minGallop < 0)
  55.708 +                minGallop = 0;
  55.709 +            minGallop += 2;  // Penalize for leaving gallop mode
  55.710 +        }  // End of "outer" loop
  55.711 +        this.minGallop = minGallop < 1 ? 1 : minGallop;  // Write back to field
  55.712 +
  55.713 +        if (len1 == 1) {
  55.714 +            assert len2 > 0;
  55.715 +            System.arraycopy(a, cursor2, a, dest, len2);
  55.716 +            a[dest + len2] = tmp[cursor1]; //  Last elt of run 1 to end of merge
  55.717 +        } else if (len1 == 0) {
  55.718 +            throw new IllegalArgumentException(
  55.719 +                "Comparison method violates its general contract!");
  55.720 +        } else {
  55.721 +            assert len2 == 0;
  55.722 +            assert len1 > 1;
  55.723 +            System.arraycopy(tmp, cursor1, a, dest, len1);
  55.724 +        }
  55.725 +    }
  55.726 +
  55.727 +    /**
  55.728 +     * Like mergeLo, except that this method should be called only if
  55.729 +     * len1 >= len2; mergeLo should be called if len1 <= len2.  (Either method
  55.730 +     * may be called if len1 == len2.)
  55.731 +     *
  55.732 +     * @param base1 index of first element in first run to be merged
  55.733 +     * @param len1  length of first run to be merged (must be > 0)
  55.734 +     * @param base2 index of first element in second run to be merged
  55.735 +     *        (must be aBase + aLen)
  55.736 +     * @param len2  length of second run to be merged (must be > 0)
  55.737 +     */
  55.738 +    @SuppressWarnings("unchecked")
  55.739 +    private void mergeHi(int base1, int len1, int base2, int len2) {
  55.740 +        assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
  55.741 +
  55.742 +        // Copy second run into temp array
  55.743 +        Object[] a = this.a; // For performance
  55.744 +        Object[] tmp = ensureCapacity(len2);
  55.745 +        System.arraycopy(a, base2, tmp, 0, len2);
  55.746 +
  55.747 +        int cursor1 = base1 + len1 - 1;  // Indexes into a
  55.748 +        int cursor2 = len2 - 1;          // Indexes into tmp array
  55.749 +        int dest = base2 + len2 - 1;     // Indexes into a
  55.750 +
  55.751 +        // Move last element of first run and deal with degenerate cases
  55.752 +        a[dest--] = a[cursor1--];
  55.753 +        if (--len1 == 0) {
  55.754 +            System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2);
  55.755 +            return;
  55.756 +        }
  55.757 +        if (len2 == 1) {
  55.758 +            dest -= len1;
  55.759 +            cursor1 -= len1;
  55.760 +            System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
  55.761 +            a[dest] = tmp[cursor2];
  55.762 +            return;
  55.763 +        }
  55.764 +
  55.765 +        int minGallop = this.minGallop;  // Use local variable for performance
  55.766 +    outer:
  55.767 +        while (true) {
  55.768 +            int count1 = 0; // Number of times in a row that first run won
  55.769 +            int count2 = 0; // Number of times in a row that second run won
  55.770 +
  55.771 +            /*
  55.772 +             * Do the straightforward thing until (if ever) one run
  55.773 +             * appears to win consistently.
  55.774 +             */
  55.775 +            do {
  55.776 +                assert len1 > 0 && len2 > 1;
  55.777 +                if (((Comparable) tmp[cursor2]).compareTo(a[cursor1]) < 0) {
  55.778 +                    a[dest--] = a[cursor1--];
  55.779 +                    count1++;
  55.780 +                    count2 = 0;
  55.781 +                    if (--len1 == 0)
  55.782 +                        break outer;
  55.783 +                } else {
  55.784 +                    a[dest--] = tmp[cursor2--];
  55.785 +                    count2++;
  55.786 +                    count1 = 0;
  55.787 +                    if (--len2 == 1)
  55.788 +                        break outer;
  55.789 +                }
  55.790 +            } while ((count1 | count2) < minGallop);
  55.791 +
  55.792 +            /*
  55.793 +             * One run is winning so consistently that galloping may be a
  55.794 +             * huge win. So try that, and continue galloping until (if ever)
  55.795 +             * neither run appears to be winning consistently anymore.
  55.796 +             */
  55.797 +            do {
  55.798 +                assert len1 > 0 && len2 > 1;
  55.799 +                count1 = len1 - gallopRight((Comparable) tmp[cursor2], a, base1, len1, len1 - 1);
  55.800 +                if (count1 != 0) {
  55.801 +                    dest -= count1;
  55.802 +                    cursor1 -= count1;
  55.803 +                    len1 -= count1;
  55.804 +                    System.arraycopy(a, cursor1 + 1, a, dest + 1, count1);
  55.805 +                    if (len1 == 0)
  55.806 +                        break outer;
  55.807 +                }
  55.808 +                a[dest--] = tmp[cursor2--];
  55.809 +                if (--len2 == 1)
  55.810 +                    break outer;
  55.811 +
  55.812 +                count2 = len2 - gallopLeft((Comparable) a[cursor1], tmp, 0, len2, len2 - 1);
  55.813 +                if (count2 != 0) {
  55.814 +                    dest -= count2;
  55.815 +                    cursor2 -= count2;
  55.816 +                    len2 -= count2;
  55.817 +                    System.arraycopy(tmp, cursor2 + 1, a, dest + 1, count2);
  55.818 +                    if (len2 <= 1)
  55.819 +                        break outer; // len2 == 1 || len2 == 0
  55.820 +                }
  55.821 +                a[dest--] = a[cursor1--];
  55.822 +                if (--len1 == 0)
  55.823 +                    break outer;
  55.824 +                minGallop--;
  55.825 +            } while (count1 >= MIN_GALLOP | count2 >= MIN_GALLOP);
  55.826 +            if (minGallop < 0)
  55.827 +                minGallop = 0;
  55.828 +            minGallop += 2;  // Penalize for leaving gallop mode
  55.829 +        }  // End of "outer" loop
  55.830 +        this.minGallop = minGallop < 1 ? 1 : minGallop;  // Write back to field
  55.831 +
  55.832 +        if (len2 == 1) {
  55.833 +            assert len1 > 0;
  55.834 +            dest -= len1;
  55.835 +            cursor1 -= len1;
  55.836 +            System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
  55.837 +            a[dest] = tmp[cursor2];  // Move first elt of run2 to front of merge
  55.838 +        } else if (len2 == 0) {
  55.839 +            throw new IllegalArgumentException(
  55.840 +                "Comparison method violates its general contract!");
  55.841 +        } else {
  55.842 +            assert len1 == 0;
  55.843 +            assert len2 > 0;
  55.844 +            System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2);
  55.845 +        }
  55.846 +    }
  55.847 +
  55.848 +    /**
  55.849 +     * Ensures that the external array tmp has at least the specified
  55.850 +     * number of elements, increasing its size if necessary.  The size
  55.851 +     * increases exponentially to ensure amortized linear time complexity.
  55.852 +     *
  55.853 +     * @param minCapacity the minimum required capacity of the tmp array
  55.854 +     * @return tmp, whether or not it grew
  55.855 +     */
  55.856 +    private Object[]  ensureCapacity(int minCapacity) {
  55.857 +        if (tmp.length < minCapacity) {
  55.858 +            // Compute smallest power of 2 > minCapacity
  55.859 +            int newSize = minCapacity;
  55.860 +            newSize |= newSize >> 1;
  55.861 +            newSize |= newSize >> 2;
  55.862 +            newSize |= newSize >> 4;
  55.863 +            newSize |= newSize >> 8;
  55.864 +            newSize |= newSize >> 16;
  55.865 +            newSize++;
  55.866 +
  55.867 +            if (newSize < 0) // Not bloody likely!
  55.868 +                newSize = minCapacity;
  55.869 +            else
  55.870 +                newSize = Math.min(newSize, a.length >>> 1);
  55.871 +
  55.872 +            @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
  55.873 +            Object[] newArray = new Object[newSize];
  55.874 +            tmp = newArray;
  55.875 +        }
  55.876 +        return tmp;
  55.877 +    }
  55.878 +
  55.879 +    /**
  55.880 +     * Checks that fromIndex and toIndex are in range, and throws an
  55.881 +     * appropriate exception if they aren't.
  55.882 +     *
  55.883 +     * @param arrayLen the length of the array
  55.884 +     * @param fromIndex the index of the first element of the range
  55.885 +     * @param toIndex the index after the last element of the range
  55.886 +     * @throws IllegalArgumentException if fromIndex > toIndex
  55.887 +     * @throws ArrayIndexOutOfBoundsException if fromIndex < 0
  55.888 +     *         or toIndex > arrayLen
  55.889 +     */
  55.890 +    private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) {
  55.891 +        if (fromIndex > toIndex)
  55.892 +            throw new IllegalArgumentException("fromIndex(" + fromIndex +
  55.893 +                       ") > toIndex(" + toIndex+")");
  55.894 +        if (fromIndex < 0)
  55.895 +            throw new ArrayIndexOutOfBoundsException(fromIndex);
  55.896 +        if (toIndex > arrayLen)
  55.897 +            throw new ArrayIndexOutOfBoundsException(toIndex);
  55.898 +    }
  55.899 +}
    56.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    56.2 +++ b/emul/compact/src/main/java/java/util/ConcurrentModificationException.java	Sun Feb 03 07:48:42 2013 +0100
    56.3 @@ -0,0 +1,123 @@
    56.4 +/*
    56.5 + * Copyright (c) 1997, 2010, 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.util;
   56.30 +
   56.31 +/**
   56.32 + * This exception may be thrown by methods that have detected concurrent
   56.33 + * modification of an object when such modification is not permissible.
   56.34 + * <p>
   56.35 + * For example, it is not generally permissible for one thread to modify a Collection
   56.36 + * while another thread is iterating over it.  In general, the results of the
   56.37 + * iteration are undefined under these circumstances.  Some Iterator
   56.38 + * implementations (including those of all the general purpose collection implementations
   56.39 + * provided by the JRE) may choose to throw this exception if this behavior is
   56.40 + * detected.  Iterators that do this are known as <i>fail-fast</i> iterators,
   56.41 + * as they fail quickly and cleanly, rather that risking arbitrary,
   56.42 + * non-deterministic behavior at an undetermined time in the future.
   56.43 + * <p>
   56.44 + * Note that this exception does not always indicate that an object has
   56.45 + * been concurrently modified by a <i>different</i> thread.  If a single
   56.46 + * thread issues a sequence of method invocations that violates the
   56.47 + * contract of an object, the object may throw this exception.  For
   56.48 + * example, if a thread modifies a collection directly while it is
   56.49 + * iterating over the collection with a fail-fast iterator, the iterator
   56.50 + * will throw this exception.
   56.51 + *
   56.52 + * <p>Note that fail-fast behavior cannot be guaranteed as it is, generally
   56.53 + * speaking, impossible to make any hard guarantees in the presence of
   56.54 + * unsynchronized concurrent modification.  Fail-fast operations
   56.55 + * throw {@code ConcurrentModificationException} on a best-effort basis.
   56.56 + * Therefore, it would be wrong to write a program that depended on this
   56.57 + * exception for its correctness: <i>{@code ConcurrentModificationException}
   56.58 + * should be used only to detect bugs.</i>
   56.59 + *
   56.60 + * @author  Josh Bloch
   56.61 + * @see     Collection
   56.62 + * @see     Iterator
   56.63 + * @see     ListIterator
   56.64 + * @see     Vector
   56.65 + * @see     LinkedList
   56.66 + * @see     HashSet
   56.67 + * @see     Hashtable
   56.68 + * @see     TreeMap
   56.69 + * @see     AbstractList
   56.70 + * @since   1.2
   56.71 + */
   56.72 +public class ConcurrentModificationException extends RuntimeException {
   56.73 +    private static final long serialVersionUID = -3666751008965953603L;
   56.74 +
   56.75 +    /**
   56.76 +     * Constructs a ConcurrentModificationException with no
   56.77 +     * detail message.
   56.78 +     */
   56.79 +    public ConcurrentModificationException() {
   56.80 +    }
   56.81 +
   56.82 +    /**
   56.83 +     * Constructs a {@code ConcurrentModificationException} with the
   56.84 +     * specified detail message.
   56.85 +     *
   56.86 +     * @param message the detail message pertaining to this exception.
   56.87 +     */
   56.88 +    public ConcurrentModificationException(String message) {
   56.89 +        super(message);
   56.90 +    }
   56.91 +
   56.92 +    /**
   56.93 +     * Constructs a new exception with the specified cause and a detail
   56.94 +     * message of {@code (cause==null ? null : cause.toString())} (which
   56.95 +     * typically contains the class and detail message of {@code cause}.
   56.96 +     *
   56.97 +     * @param  cause the cause (which is saved for later retrieval by the
   56.98 +     *         {@link Throwable#getCause()} method).  (A {@code null} value is
   56.99 +     *         permitted, and indicates that the cause is nonexistent or
  56.100 +     *         unknown.)
  56.101 +     * @since  1.7
  56.102 +     */
  56.103 +    public ConcurrentModificationException(Throwable cause) {
  56.104 +        super(cause);
  56.105 +    }
  56.106 +
  56.107 +    /**
  56.108 +     * Constructs a new exception with the specified detail message and
  56.109 +     * cause.
  56.110 +     *
  56.111 +     * <p>Note that the detail message associated with <code>cause</code> is
  56.112 +     * <i>not</i> automatically incorporated in this exception's detail
  56.113 +     * message.
  56.114 +     *
  56.115 +     * @param  message the detail message (which is saved for later retrieval
  56.116 +     *         by the {@link Throwable#getMessage()} method).
  56.117 +     * @param  cause the cause (which is saved for later retrieval by the
  56.118 +     *         {@link Throwable#getCause()} method).  (A {@code null} value
  56.119 +     *         is permitted, and indicates that the cause is nonexistent or
  56.120 +     *         unknown.)
  56.121 +     * @since 1.7
  56.122 +     */
  56.123 +    public ConcurrentModificationException(String message, Throwable cause) {
  56.124 +        super(message, cause);
  56.125 +    }
  56.126 +}
    57.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.2 +++ b/emul/compact/src/main/java/java/util/Deque.java	Sun Feb 03 07:48:42 2013 +0100
    57.3 @@ -0,0 +1,584 @@
    57.4 +/*
    57.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    57.6 + *
    57.7 + * This code is free software; you can redistribute it and/or modify it
    57.8 + * under the terms of the GNU General Public License version 2 only, as
    57.9 + * published by the Free Software Foundation.  Oracle designates this
   57.10 + * particular file as subject to the "Classpath" exception as provided
   57.11 + * by Oracle in the LICENSE file that accompanied this code.
   57.12 + *
   57.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
   57.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   57.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   57.16 + * version 2 for more details (a copy is included in the LICENSE file that
   57.17 + * accompanied this code).
   57.18 + *
   57.19 + * You should have received a copy of the GNU General Public License version
   57.20 + * 2 along with this work; if not, write to the Free Software Foundation,
   57.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   57.22 + *
   57.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   57.24 + * or visit www.oracle.com if you need additional information or have any
   57.25 + * questions.
   57.26 + */
   57.27 +
   57.28 +/*
   57.29 + * This file is available under and governed by the GNU General Public
   57.30 + * License version 2 only, as published by the Free Software Foundation.
   57.31 + * However, the following notice accompanied the original version of this
   57.32 + * file:
   57.33 + *
   57.34 + * Written by Doug Lea and Josh Bloch with assistance from members of
   57.35 + * JCP JSR-166 Expert Group and released to the public domain, as explained
   57.36 + * at http://creativecommons.org/publicdomain/zero/1.0/
   57.37 + */
   57.38 +
   57.39 +package java.util;
   57.40 +
   57.41 +/**
   57.42 + * A linear collection that supports element insertion and removal at
   57.43 + * both ends.  The name <i>deque</i> is short for "double ended queue"
   57.44 + * and is usually pronounced "deck".  Most <tt>Deque</tt>
   57.45 + * implementations place no fixed limits on the number of elements
   57.46 + * they may contain, but this interface supports capacity-restricted
   57.47 + * deques as well as those with no fixed size limit.
   57.48 + *
   57.49 + * <p>This interface defines methods to access the elements at both
   57.50 + * ends of the deque.  Methods are provided to insert, remove, and
   57.51 + * examine the element.  Each of these methods exists in two forms:
   57.52 + * one throws an exception if the operation fails, the other returns a
   57.53 + * special value (either <tt>null</tt> or <tt>false</tt>, depending on
   57.54 + * the operation).  The latter form of the insert operation is
   57.55 + * designed specifically for use with capacity-restricted
   57.56 + * <tt>Deque</tt> implementations; in most implementations, insert
   57.57 + * operations cannot fail.
   57.58 + *
   57.59 + * <p>The twelve methods described above are summarized in the
   57.60 + * following table:
   57.61 + *
   57.62 + * <p>
   57.63 + * <table BORDER CELLPADDING=3 CELLSPACING=1>
   57.64 + *  <tr>
   57.65 + *    <td></td>
   57.66 + *    <td ALIGN=CENTER COLSPAN = 2> <b>First Element (Head)</b></td>
   57.67 + *    <td ALIGN=CENTER COLSPAN = 2> <b>Last Element (Tail)</b></td>
   57.68 + *  </tr>
   57.69 + *  <tr>
   57.70 + *    <td></td>
   57.71 + *    <td ALIGN=CENTER><em>Throws exception</em></td>
   57.72 + *    <td ALIGN=CENTER><em>Special value</em></td>
   57.73 + *    <td ALIGN=CENTER><em>Throws exception</em></td>
   57.74 + *    <td ALIGN=CENTER><em>Special value</em></td>
   57.75 + *  </tr>
   57.76 + *  <tr>
   57.77 + *    <td><b>Insert</b></td>
   57.78 + *    <td>{@link #addFirst addFirst(e)}</td>
   57.79 + *    <td>{@link #offerFirst offerFirst(e)}</td>
   57.80 + *    <td>{@link #addLast addLast(e)}</td>
   57.81 + *    <td>{@link #offerLast offerLast(e)}</td>
   57.82 + *  </tr>
   57.83 + *  <tr>
   57.84 + *    <td><b>Remove</b></td>
   57.85 + *    <td>{@link #removeFirst removeFirst()}</td>
   57.86 + *    <td>{@link #pollFirst pollFirst()}</td>
   57.87 + *    <td>{@link #removeLast removeLast()}</td>
   57.88 + *    <td>{@link #pollLast pollLast()}</td>
   57.89 + *  </tr>
   57.90 + *  <tr>
   57.91 + *    <td><b>Examine</b></td>
   57.92 + *    <td>{@link #getFirst getFirst()}</td>
   57.93 + *    <td>{@link #peekFirst peekFirst()}</td>
   57.94 + *    <td>{@link #getLast getLast()}</td>
   57.95 + *    <td>{@link #peekLast peekLast()}</td>
   57.96 + *  </tr>
   57.97 + * </table>
   57.98 + *
   57.99 + * <p>This interface extends the {@link Queue} interface.  When a deque is
  57.100 + * used as a queue, FIFO (First-In-First-Out) behavior results.  Elements are
  57.101 + * added at the end of the deque and removed from the beginning.  The methods
  57.102 + * inherited from the <tt>Queue</tt> interface are precisely equivalent to
  57.103 + * <tt>Deque</tt> methods as indicated in the following table:
  57.104 + *
  57.105 + * <p>
  57.106 + * <table BORDER CELLPADDING=3 CELLSPACING=1>
  57.107 + *  <tr>
  57.108 + *    <td ALIGN=CENTER> <b><tt>Queue</tt> Method</b></td>
  57.109 + *    <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
  57.110 + *  </tr>
  57.111 + *  <tr>
  57.112 + *    <td>{@link java.util.Queue#add add(e)}</td>
  57.113 + *    <td>{@link #addLast addLast(e)}</td>
  57.114 + *  </tr>
  57.115 + *  <tr>
  57.116 + *    <td>{@link java.util.Queue#offer offer(e)}</td>
  57.117 + *    <td>{@link #offerLast offerLast(e)}</td>
  57.118 + *  </tr>
  57.119 + *  <tr>
  57.120 + *    <td>{@link java.util.Queue#remove remove()}</td>
  57.121 + *    <td>{@link #removeFirst removeFirst()}</td>
  57.122 + *  </tr>
  57.123 + *  <tr>
  57.124 + *    <td>{@link java.util.Queue#poll poll()}</td>
  57.125 + *    <td>{@link #pollFirst pollFirst()}</td>
  57.126 + *  </tr>
  57.127 + *  <tr>
  57.128 + *    <td>{@link java.util.Queue#element element()}</td>
  57.129 + *    <td>{@link #getFirst getFirst()}</td>
  57.130 + *  </tr>
  57.131 + *  <tr>
  57.132 + *    <td>{@link java.util.Queue#peek peek()}</td>
  57.133 + *    <td>{@link #peek peekFirst()}</td>
  57.134 + *  </tr>
  57.135 + * </table>
  57.136 + *
  57.137 + * <p>Deques can also be used as LIFO (Last-In-First-Out) stacks.  This
  57.138 + * interface should be used in preference to the legacy {@link Stack} class.
  57.139 + * When a deque is used as a stack, elements are pushed and popped from the
  57.140 + * beginning of the deque.  Stack methods are precisely equivalent to
  57.141 + * <tt>Deque</tt> methods as indicated in the table below:
  57.142 + *
  57.143 + * <p>
  57.144 + * <table BORDER CELLPADDING=3 CELLSPACING=1>
  57.145 + *  <tr>
  57.146 + *    <td ALIGN=CENTER> <b>Stack Method</b></td>
  57.147 + *    <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
  57.148 + *  </tr>
  57.149 + *  <tr>
  57.150 + *    <td>{@link #push push(e)}</td>
  57.151 + *    <td>{@link #addFirst addFirst(e)}</td>
  57.152 + *  </tr>
  57.153 + *  <tr>
  57.154 + *    <td>{@link #pop pop()}</td>
  57.155 + *    <td>{@link #removeFirst removeFirst()}</td>
  57.156 + *  </tr>
  57.157 + *  <tr>
  57.158 + *    <td>{@link #peek peek()}</td>
  57.159 + *    <td>{@link #peekFirst peekFirst()}</td>
  57.160 + *  </tr>
  57.161 + * </table>
  57.162 + *
  57.163 + * <p>Note that the {@link #peek peek} method works equally well when
  57.164 + * a deque is used as a queue or a stack; in either case, elements are
  57.165 + * drawn from the beginning of the deque.
  57.166 + *
  57.167 + * <p>This interface provides two methods to remove interior
  57.168 + * elements, {@link #removeFirstOccurrence removeFirstOccurrence} and
  57.169 + * {@link #removeLastOccurrence removeLastOccurrence}.
  57.170 + *
  57.171 + * <p>Unlike the {@link List} interface, this interface does not
  57.172 + * provide support for indexed access to elements.
  57.173 + *
  57.174 + * <p>While <tt>Deque</tt> implementations are not strictly required
  57.175 + * to prohibit the insertion of null elements, they are strongly
  57.176 + * encouraged to do so.  Users of any <tt>Deque</tt> implementations
  57.177 + * that do allow null elements are strongly encouraged <i>not</i> to
  57.178 + * take advantage of the ability to insert nulls.  This is so because
  57.179 + * <tt>null</tt> is used as a special return value by various methods
  57.180 + * to indicated that the deque is empty.
  57.181 + *
  57.182 + * <p><tt>Deque</tt> implementations generally do not define
  57.183 + * element-based versions of the <tt>equals</tt> and <tt>hashCode</tt>
  57.184 + * methods, but instead inherit the identity-based versions from class
  57.185 + * <tt>Object</tt>.
  57.186 + *
  57.187 + * <p>This interface is a member of the <a
  57.188 + * href="{@docRoot}/../technotes/guides/collections/index.html"> Java Collections
  57.189 + * Framework</a>.
  57.190 + *
  57.191 + * @author Doug Lea
  57.192 + * @author Josh Bloch
  57.193 + * @since  1.6
  57.194 + * @param <E> the type of elements held in this collection
  57.195 + */
  57.196 +
  57.197 +public interface Deque<E> extends Queue<E> {
  57.198 +    /**
  57.199 +     * Inserts the specified element at the front of this deque if it is
  57.200 +     * possible to do so immediately without violating capacity restrictions.
  57.201 +     * When using a capacity-restricted deque, it is generally preferable to
  57.202 +     * use method {@link #offerFirst}.
  57.203 +     *
  57.204 +     * @param e the element to add
  57.205 +     * @throws IllegalStateException if the element cannot be added at this
  57.206 +     *         time due to capacity restrictions
  57.207 +     * @throws ClassCastException if the class of the specified element
  57.208 +     *         prevents it from being added to this deque
  57.209 +     * @throws NullPointerException if the specified element is null and this
  57.210 +     *         deque does not permit null elements
  57.211 +     * @throws IllegalArgumentException if some property of the specified
  57.212 +     *         element prevents it from being added to this deque
  57.213 +     */
  57.214 +    void addFirst(E e);
  57.215 +
  57.216 +    /**
  57.217 +     * Inserts the specified element at the end of this deque if it is
  57.218 +     * possible to do so immediately without violating capacity restrictions.
  57.219 +     * When using a capacity-restricted deque, it is generally preferable to
  57.220 +     * use method {@link #offerLast}.
  57.221 +     *
  57.222 +     * <p>This method is equivalent to {@link #add}.
  57.223 +     *
  57.224 +     * @param e the element to add
  57.225 +     * @throws IllegalStateException if the element cannot be added at this
  57.226 +     *         time due to capacity restrictions
  57.227 +     * @throws ClassCastException if the class of the specified element
  57.228 +     *         prevents it from being added to this deque
  57.229 +     * @throws NullPointerException if the specified element is null and this
  57.230 +     *         deque does not permit null elements
  57.231 +     * @throws IllegalArgumentException if some property of the specified
  57.232 +     *         element prevents it from being added to this deque
  57.233 +     */
  57.234 +    void addLast(E e);
  57.235 +
  57.236 +    /**
  57.237 +     * Inserts the specified element at the front of this deque unless it would
  57.238 +     * violate capacity restrictions.  When using a capacity-restricted deque,
  57.239 +     * this method is generally preferable to the {@link #addFirst} method,
  57.240 +     * which can fail to insert an element only by throwing an exception.
  57.241 +     *
  57.242 +     * @param e the element to add
  57.243 +     * @return <tt>true</tt> if the element was added to this deque, else
  57.244 +     *         <tt>false</tt>
  57.245 +     * @throws ClassCastException if the class of the specified element
  57.246 +     *         prevents it from being added to this deque
  57.247 +     * @throws NullPointerException if the specified element is null and this
  57.248 +     *         deque does not permit null elements
  57.249 +     * @throws IllegalArgumentException if some property of the specified
  57.250 +     *         element prevents it from being added to this deque
  57.251 +     */
  57.252 +    boolean offerFirst(E e);
  57.253 +
  57.254 +    /**
  57.255 +     * Inserts the specified element at the end of this deque unless it would
  57.256 +     * violate capacity restrictions.  When using a capacity-restricted deque,
  57.257 +     * this method is generally preferable to the {@link #addLast} method,
  57.258 +     * which can fail to insert an element only by throwing an exception.
  57.259 +     *
  57.260 +     * @param e the element to add
  57.261 +     * @return <tt>true</tt> if the element was added to this deque, else
  57.262 +     *         <tt>false</tt>
  57.263 +     * @throws ClassCastException if the class of the specified element
  57.264 +     *         prevents it from being added to this deque
  57.265 +     * @throws NullPointerException if the specified element is null and this
  57.266 +     *         deque does not permit null elements
  57.267 +     * @throws IllegalArgumentException if some property of the specified
  57.268 +     *         element prevents it from being added to this deque
  57.269 +     */
  57.270 +    boolean offerLast(E e);
  57.271 +
  57.272 +    /**
  57.273 +     * Retrieves and removes the first element of this deque.  This method
  57.274 +     * differs from {@link #pollFirst pollFirst} only in that it throws an
  57.275 +     * exception if this deque is empty.
  57.276 +     *
  57.277 +     * @return the head of this deque
  57.278 +     * @throws NoSuchElementException if this deque is empty
  57.279 +     */
  57.280 +    E removeFirst();
  57.281 +
  57.282 +    /**
  57.283 +     * Retrieves and removes the last element of this deque.  This method
  57.284 +     * differs from {@link #pollLast pollLast} only in that it throws an
  57.285 +     * exception if this deque is empty.
  57.286 +     *
  57.287 +     * @return the tail of this deque
  57.288 +     * @throws NoSuchElementException if this deque is empty
  57.289 +     */
  57.290 +    E removeLast();
  57.291 +
  57.292 +    /**
  57.293 +     * Retrieves and removes the first element of this deque,
  57.294 +     * or returns <tt>null</tt> if this deque is empty.
  57.295 +     *
  57.296 +     * @return the head of this deque, or <tt>null</tt> if this deque is empty
  57.297 +     */
  57.298 +    E pollFirst();
  57.299 +
  57.300 +    /**
  57.301 +     * Retrieves and removes the last element of this deque,
  57.302 +     * or returns <tt>null</tt> if this deque is empty.
  57.303 +     *
  57.304 +     * @return the tail of this deque, or <tt>null</tt> if this deque is empty
  57.305 +     */
  57.306 +    E pollLast();
  57.307 +
  57.308 +    /**
  57.309 +     * Retrieves, but does not remove, the first element of this deque.
  57.310 +     *
  57.311 +     * This method differs from {@link #peekFirst peekFirst} only in that it
  57.312 +     * throws an exception if this deque is empty.
  57.313 +     *
  57.314 +     * @return the head of this deque
  57.315 +     * @throws NoSuchElementException if this deque is empty
  57.316 +     */
  57.317 +    E getFirst();
  57.318 +
  57.319 +    /**
  57.320 +     * Retrieves, but does not remove, the last element of this deque.
  57.321 +     * This method differs from {@link #peekLast peekLast} only in that it
  57.322 +     * throws an exception if this deque is empty.
  57.323 +     *
  57.324 +     * @return the tail of this deque
  57.325 +     * @throws NoSuchElementException if this deque is empty
  57.326 +     */
  57.327 +    E getLast();
  57.328 +
  57.329 +    /**
  57.330 +     * Retrieves, but does not remove, the first element of this deque,
  57.331 +     * or returns <tt>null</tt> if this deque is empty.
  57.332 +     *
  57.333 +     * @return the head of this deque, or <tt>null</tt> if this deque is empty
  57.334 +     */
  57.335 +    E peekFirst();
  57.336 +
  57.337 +    /**
  57.338 +     * Retrieves, but does not remove, the last element of this deque,
  57.339 +     * or returns <tt>null</tt> if this deque is empty.
  57.340 +     *
  57.341 +     * @return the tail of this deque, or <tt>null</tt> if this deque is empty
  57.342 +     */
  57.343 +    E peekLast();
  57.344 +
  57.345 +    /**
  57.346 +     * Removes the first occurrence of the specified element from this deque.
  57.347 +     * If the deque does not contain the element, it is unchanged.
  57.348 +     * More formally, removes the first element <tt>e</tt> such that
  57.349 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
  57.350 +     * (if such an element exists).
  57.351 +     * Returns <tt>true</tt> if this deque contained the specified element
  57.352 +     * (or equivalently, if this deque changed as a result of the call).
  57.353 +     *
  57.354 +     * @param o element to be removed from this deque, if present
  57.355 +     * @return <tt>true</tt> if an element was removed as a result of this call
  57.356 +     * @throws ClassCastException if the class of the specified element
  57.357 +     *         is incompatible with this deque
  57.358 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  57.359 +     * @throws NullPointerException if the specified element is null and this
  57.360 +     *         deque does not permit null elements
  57.361 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  57.362 +     */
  57.363 +    boolean removeFirstOccurrence(Object o);
  57.364 +
  57.365 +    /**
  57.366 +     * Removes the last occurrence of the specified element from this deque.
  57.367 +     * If the deque does not contain the element, it is unchanged.
  57.368 +     * More formally, removes the last element <tt>e</tt> such that
  57.369 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
  57.370 +     * (if such an element exists).
  57.371 +     * Returns <tt>true</tt> if this deque contained the specified element
  57.372 +     * (or equivalently, if this deque changed as a result of the call).
  57.373 +     *
  57.374 +     * @param o element to be removed from this deque, if present
  57.375 +     * @return <tt>true</tt> if an element was removed as a result of this call
  57.376 +     * @throws ClassCastException if the class of the specified element
  57.377 +     *         is incompatible with this deque
  57.378 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  57.379 +     * @throws NullPointerException if the specified element is null and this
  57.380 +     *         deque does not permit null elements
  57.381 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  57.382 +     */
  57.383 +    boolean removeLastOccurrence(Object o);
  57.384 +
  57.385 +    // *** Queue methods ***
  57.386 +
  57.387 +    /**
  57.388 +     * Inserts the specified element into the queue represented by this deque
  57.389 +     * (in other words, at the tail of this deque) if it is possible to do so
  57.390 +     * immediately without violating capacity restrictions, returning
  57.391 +     * <tt>true</tt> upon success and throwing an
  57.392 +     * <tt>IllegalStateException</tt> if no space is currently available.
  57.393 +     * When using a capacity-restricted deque, it is generally preferable to
  57.394 +     * use {@link #offer(Object) offer}.
  57.395 +     *
  57.396 +     * <p>This method is equivalent to {@link #addLast}.
  57.397 +     *
  57.398 +     * @param e the element to add
  57.399 +     * @return <tt>true</tt> (as specified by {@link Collection#add})
  57.400 +     * @throws IllegalStateException if the element cannot be added at this
  57.401 +     *         time due to capacity restrictions
  57.402 +     * @throws ClassCastException if the class of the specified element
  57.403 +     *         prevents it from being added to this deque
  57.404 +     * @throws NullPointerException if the specified element is null and this
  57.405 +     *         deque does not permit null elements
  57.406 +     * @throws IllegalArgumentException if some property of the specified
  57.407 +     *         element prevents it from being added to this deque
  57.408 +     */
  57.409 +    boolean add(E e);
  57.410 +
  57.411 +    /**
  57.412 +     * Inserts the specified element into the queue represented by this deque
  57.413 +     * (in other words, at the tail of this deque) if it is possible to do so
  57.414 +     * immediately without violating capacity restrictions, returning
  57.415 +     * <tt>true</tt> upon success and <tt>false</tt> if no space is currently
  57.416 +     * available.  When using a capacity-restricted deque, this method is
  57.417 +     * generally preferable to the {@link #add} method, which can fail to
  57.418 +     * insert an element only by throwing an exception.
  57.419 +     *
  57.420 +     * <p>This method is equivalent to {@link #offerLast}.
  57.421 +     *
  57.422 +     * @param e the element to add
  57.423 +     * @return <tt>true</tt> if the element was added to this deque, else
  57.424 +     *         <tt>false</tt>
  57.425 +     * @throws ClassCastException if the class of the specified element
  57.426 +     *         prevents it from being added to this deque
  57.427 +     * @throws NullPointerException if the specified element is null and this
  57.428 +     *         deque does not permit null elements
  57.429 +     * @throws IllegalArgumentException if some property of the specified
  57.430 +     *         element prevents it from being added to this deque
  57.431 +     */
  57.432 +    boolean offer(E e);
  57.433 +
  57.434 +    /**
  57.435 +     * Retrieves and removes the head of the queue represented by this deque
  57.436 +     * (in other words, the first element of this deque).
  57.437 +     * This method differs from {@link #poll poll} only in that it throws an
  57.438 +     * exception if this deque is empty.
  57.439 +     *
  57.440 +     * <p>This method is equivalent to {@link #removeFirst()}.
  57.441 +     *
  57.442 +     * @return the head of the queue represented by this deque
  57.443 +     * @throws NoSuchElementException if this deque is empty
  57.444 +     */
  57.445 +    E remove();
  57.446 +
  57.447 +    /**
  57.448 +     * Retrieves and removes the head of the queue represented by this deque
  57.449 +     * (in other words, the first element of this deque), or returns
  57.450 +     * <tt>null</tt> if this deque is empty.
  57.451 +     *
  57.452 +     * <p>This method is equivalent to {@link #pollFirst()}.
  57.453 +     *
  57.454 +     * @return the first element of this deque, or <tt>null</tt> if
  57.455 +     *         this deque is empty
  57.456 +     */
  57.457 +    E poll();
  57.458 +
  57.459 +    /**
  57.460 +     * Retrieves, but does not remove, the head of the queue represented by
  57.461 +     * this deque (in other words, the first element of this deque).
  57.462 +     * This method differs from {@link #peek peek} only in that it throws an
  57.463 +     * exception if this deque is empty.
  57.464 +     *
  57.465 +     * <p>This method is equivalent to {@link #getFirst()}.
  57.466 +     *
  57.467 +     * @return the head of the queue represented by this deque
  57.468 +     * @throws NoSuchElementException if this deque is empty
  57.469 +     */
  57.470 +    E element();
  57.471 +
  57.472 +    /**
  57.473 +     * Retrieves, but does not remove, the head of the queue represented by
  57.474 +     * this deque (in other words, the first element of this deque), or
  57.475 +     * returns <tt>null</tt> if this deque is empty.
  57.476 +     *
  57.477 +     * <p>This method is equivalent to {@link #peekFirst()}.
  57.478 +     *
  57.479 +     * @return the head of the queue represented by this deque, or
  57.480 +     *         <tt>null</tt> if this deque is empty
  57.481 +     */
  57.482 +    E peek();
  57.483 +
  57.484 +
  57.485 +    // *** Stack methods ***
  57.486 +
  57.487 +    /**
  57.488 +     * Pushes an element onto the stack represented by this deque (in other
  57.489 +     * words, at the head of this deque) if it is possible to do so
  57.490 +     * immediately without violating capacity restrictions, returning
  57.491 +     * <tt>true</tt> upon success and throwing an
  57.492 +     * <tt>IllegalStateException</tt> if no space is currently available.
  57.493 +     *
  57.494 +     * <p>This method is equivalent to {@link #addFirst}.
  57.495 +     *
  57.496 +     * @param e the element to push
  57.497 +     * @throws IllegalStateException if the element cannot be added at this
  57.498 +     *         time due to capacity restrictions
  57.499 +     * @throws ClassCastException if the class of the specified element
  57.500 +     *         prevents it from being added to this deque
  57.501 +     * @throws NullPointerException if the specified element is null and this
  57.502 +     *         deque does not permit null elements
  57.503 +     * @throws IllegalArgumentException if some property of the specified
  57.504 +     *         element prevents it from being added to this deque
  57.505 +     */
  57.506 +    void push(E e);
  57.507 +
  57.508 +    /**
  57.509 +     * Pops an element from the stack represented by this deque.  In other
  57.510 +     * words, removes and returns the first element of this deque.
  57.511 +     *
  57.512 +     * <p>This method is equivalent to {@link #removeFirst()}.
  57.513 +     *
  57.514 +     * @return the element at the front of this deque (which is the top
  57.515 +     *         of the stack represented by this deque)
  57.516 +     * @throws NoSuchElementException if this deque is empty
  57.517 +     */
  57.518 +    E pop();
  57.519 +
  57.520 +
  57.521 +    // *** Collection methods ***
  57.522 +
  57.523 +    /**
  57.524 +     * Removes the first occurrence of the specified element from this deque.
  57.525 +     * If the deque does not contain the element, it is unchanged.
  57.526 +     * More formally, removes the first element <tt>e</tt> such that
  57.527 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
  57.528 +     * (if such an element exists).
  57.529 +     * Returns <tt>true</tt> if this deque contained the specified element
  57.530 +     * (or equivalently, if this deque changed as a result of the call).
  57.531 +     *
  57.532 +     * <p>This method is equivalent to {@link #removeFirstOccurrence}.
  57.533 +     *
  57.534 +     * @param o element to be removed from this deque, if present
  57.535 +     * @return <tt>true</tt> if an element was removed as a result of this call
  57.536 +     * @throws ClassCastException if the class of the specified element
  57.537 +     *         is incompatible with this deque
  57.538 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  57.539 +     * @throws NullPointerException if the specified element is null and this
  57.540 +     *         deque does not permit null elements
  57.541 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  57.542 +     */
  57.543 +    boolean remove(Object o);
  57.544 +
  57.545 +    /**
  57.546 +     * Returns <tt>true</tt> if this deque contains the specified element.
  57.547 +     * More formally, returns <tt>true</tt> if and only if this deque contains
  57.548 +     * at least one element <tt>e</tt> such that
  57.549 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  57.550 +     *
  57.551 +     * @param o element whose presence in this deque is to be tested
  57.552 +     * @return <tt>true</tt> if this deque contains the specified element
  57.553 +     * @throws ClassCastException if the type of the specified element
  57.554 +     *         is incompatible with this deque
  57.555 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  57.556 +     * @throws NullPointerException if the specified element is null and this
  57.557 +     *         deque does not permit null elements
  57.558 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  57.559 +     */
  57.560 +    boolean contains(Object o);
  57.561 +
  57.562 +    /**
  57.563 +     * Returns the number of elements in this deque.
  57.564 +     *
  57.565 +     * @return the number of elements in this deque
  57.566 +     */
  57.567 +    public int size();
  57.568 +
  57.569 +    /**
  57.570 +     * Returns an iterator over the elements in this deque in proper sequence.
  57.571 +     * The elements will be returned in order from first (head) to last (tail).
  57.572 +     *
  57.573 +     * @return an iterator over the elements in this deque in proper sequence
  57.574 +     */
  57.575 +    Iterator<E> iterator();
  57.576 +
  57.577 +    /**
  57.578 +     * Returns an iterator over the elements in this deque in reverse
  57.579 +     * sequential order.  The elements will be returned in order from
  57.580 +     * last (tail) to first (head).
  57.581 +     *
  57.582 +     * @return an iterator over the elements in this deque in reverse
  57.583 +     * sequence
  57.584 +     */
  57.585 +    Iterator<E> descendingIterator();
  57.586 +
  57.587 +}
    58.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    58.2 +++ b/emul/compact/src/main/java/java/util/Dictionary.java	Sun Feb 03 07:48:42 2013 +0100
    58.3 @@ -0,0 +1,155 @@
    58.4 +/*
    58.5 + * Copyright (c) 1995, 2004, 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.util;
   58.30 +
   58.31 +/**
   58.32 + * The <code>Dictionary</code> class is the abstract parent of any
   58.33 + * class, such as <code>Hashtable</code>, which maps keys to values.
   58.34 + * Every key and every value is an object. In any one <tt>Dictionary</tt>
   58.35 + * object, every key is associated with at most one value. Given a
   58.36 + * <tt>Dictionary</tt> and a key, the associated element can be looked up.
   58.37 + * Any non-<code>null</code> object can be used as a key and as a value.
   58.38 + * <p>
   58.39 + * As a rule, the <code>equals</code> method should be used by
   58.40 + * implementations of this class to decide if two keys are the same.
   58.41 + * <p>
   58.42 + * <strong>NOTE: This class is obsolete.  New implementations should
   58.43 + * implement the Map interface, rather than extending this class.</strong>
   58.44 + *
   58.45 + * @author  unascribed
   58.46 + * @see     java.util.Map
   58.47 + * @see     java.lang.Object#equals(java.lang.Object)
   58.48 + * @see     java.lang.Object#hashCode()
   58.49 + * @see     java.util.Hashtable
   58.50 + * @since   JDK1.0
   58.51 + */
   58.52 +public abstract
   58.53 +class Dictionary<K,V> {
   58.54 +    /**
   58.55 +     * Sole constructor.  (For invocation by subclass constructors, typically
   58.56 +     * implicit.)
   58.57 +     */
   58.58 +    public Dictionary() {
   58.59 +    }
   58.60 +
   58.61 +    /**
   58.62 +     * Returns the number of entries (distinct keys) in this dictionary.
   58.63 +     *
   58.64 +     * @return  the number of keys in this dictionary.
   58.65 +     */
   58.66 +    abstract public int size();
   58.67 +
   58.68 +    /**
   58.69 +     * Tests if this dictionary maps no keys to value. The general contract
   58.70 +     * for the <tt>isEmpty</tt> method is that the result is true if and only
   58.71 +     * if this dictionary contains no entries.
   58.72 +     *
   58.73 +     * @return  <code>true</code> if this dictionary maps no keys to values;
   58.74 +     *          <code>false</code> otherwise.
   58.75 +     */
   58.76 +    abstract public boolean isEmpty();
   58.77 +
   58.78 +    /**
   58.79 +     * Returns an enumeration of the keys in this dictionary. The general
   58.80 +     * contract for the keys method is that an <tt>Enumeration</tt> object
   58.81 +     * is returned that will generate all the keys for which this dictionary
   58.82 +     * contains entries.
   58.83 +     *
   58.84 +     * @return  an enumeration of the keys in this dictionary.
   58.85 +     * @see     java.util.Dictionary#elements()
   58.86 +     * @see     java.util.Enumeration
   58.87 +     */
   58.88 +    abstract public Enumeration<K> keys();
   58.89 +
   58.90 +    /**
   58.91 +     * Returns an enumeration of the values in this dictionary. The general
   58.92 +     * contract for the <tt>elements</tt> method is that an
   58.93 +     * <tt>Enumeration</tt> is returned that will generate all the elements
   58.94 +     * contained in entries in this dictionary.
   58.95 +     *
   58.96 +     * @return  an enumeration of the values in this dictionary.
   58.97 +     * @see     java.util.Dictionary#keys()
   58.98 +     * @see     java.util.Enumeration
   58.99 +     */
  58.100 +    abstract public Enumeration<V> elements();
  58.101 +
  58.102 +    /**
  58.103 +     * Returns the value to which the key is mapped in this dictionary.
  58.104 +     * The general contract for the <tt>isEmpty</tt> method is that if this
  58.105 +     * dictionary contains an entry for the specified key, the associated
  58.106 +     * value is returned; otherwise, <tt>null</tt> is returned.
  58.107 +     *
  58.108 +     * @return  the value to which the key is mapped in this dictionary;
  58.109 +     * @param   key   a key in this dictionary.
  58.110 +     *          <code>null</code> if the key is not mapped to any value in
  58.111 +     *          this dictionary.
  58.112 +     * @exception NullPointerException if the <tt>key</tt> is <tt>null</tt>.
  58.113 +     * @see     java.util.Dictionary#put(java.lang.Object, java.lang.Object)
  58.114 +     */
  58.115 +    abstract public V get(Object key);
  58.116 +
  58.117 +    /**
  58.118 +     * Maps the specified <code>key</code> to the specified
  58.119 +     * <code>value</code> in this dictionary. Neither the key nor the
  58.120 +     * value can be <code>null</code>.
  58.121 +     * <p>
  58.122 +     * If this dictionary already contains an entry for the specified
  58.123 +     * <tt>key</tt>, the value already in this dictionary for that
  58.124 +     * <tt>key</tt> is returned, after modifying the entry to contain the
  58.125 +     *  new element. <p>If this dictionary does not already have an entry
  58.126 +     *  for the specified <tt>key</tt>, an entry is created for the
  58.127 +     *  specified <tt>key</tt> and <tt>value</tt>, and <tt>null</tt> is
  58.128 +     *  returned.
  58.129 +     * <p>
  58.130 +     * The <code>value</code> can be retrieved by calling the
  58.131 +     * <code>get</code> method with a <code>key</code> that is equal to
  58.132 +     * the original <code>key</code>.
  58.133 +     *
  58.134 +     * @param      key     the hashtable key.
  58.135 +     * @param      value   the value.
  58.136 +     * @return     the previous value to which the <code>key</code> was mapped
  58.137 +     *             in this dictionary, or <code>null</code> if the key did not
  58.138 +     *             have a previous mapping.
  58.139 +     * @exception  NullPointerException  if the <code>key</code> or
  58.140 +     *               <code>value</code> is <code>null</code>.
  58.141 +     * @see        java.lang.Object#equals(java.lang.Object)
  58.142 +     * @see        java.util.Dictionary#get(java.lang.Object)
  58.143 +     */
  58.144 +    abstract public V put(K key, V value);
  58.145 +
  58.146 +    /**
  58.147 +     * Removes the <code>key</code> (and its corresponding
  58.148 +     * <code>value</code>) from this dictionary. This method does nothing
  58.149 +     * if the <code>key</code> is not in this dictionary.
  58.150 +     *
  58.151 +     * @param   key   the key that needs to be removed.
  58.152 +     * @return  the value to which the <code>key</code> had been mapped in this
  58.153 +     *          dictionary, or <code>null</code> if the key did not have a
  58.154 +     *          mapping.
  58.155 +     * @exception NullPointerException if <tt>key</tt> is <tt>null</tt>.
  58.156 +     */
  58.157 +    abstract public V remove(Object key);
  58.158 +}
    59.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    59.2 +++ b/emul/compact/src/main/java/java/util/DualPivotQuicksort.java	Sun Feb 03 07:48:42 2013 +0100
    59.3 @@ -0,0 +1,3018 @@
    59.4 +/*
    59.5 + * Copyright (c) 2009, 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.util;
   59.30 +
   59.31 +/**
   59.32 + * This class implements the Dual-Pivot Quicksort algorithm by
   59.33 + * Vladimir Yaroslavskiy, Jon Bentley, and Josh Bloch. The algorithm
   59.34 + * offers O(n log(n)) performance on many data sets that cause other
   59.35 + * quicksorts to degrade to quadratic performance, and is typically
   59.36 + * faster than traditional (one-pivot) Quicksort implementations.
   59.37 + *
   59.38 + * @author Vladimir Yaroslavskiy
   59.39 + * @author Jon Bentley
   59.40 + * @author Josh Bloch
   59.41 + *
   59.42 + * @version 2011.02.11 m765.827.12i:5\7pm
   59.43 + * @since 1.7
   59.44 + */
   59.45 +final class DualPivotQuicksort {
   59.46 +
   59.47 +    /**
   59.48 +     * Prevents instantiation.
   59.49 +     */
   59.50 +    private DualPivotQuicksort() {}
   59.51 +
   59.52 +    /*
   59.53 +     * Tuning parameters.
   59.54 +     */
   59.55 +
   59.56 +    /**
   59.57 +     * The maximum number of runs in merge sort.
   59.58 +     */
   59.59 +    private static final int MAX_RUN_COUNT = 67;
   59.60 +
   59.61 +    /**
   59.62 +     * The maximum length of run in merge sort.
   59.63 +     */
   59.64 +    private static final int MAX_RUN_LENGTH = 33;
   59.65 +
   59.66 +    /**
   59.67 +     * If the length of an array to be sorted is less than this
   59.68 +     * constant, Quicksort is used in preference to merge sort.
   59.69 +     */
   59.70 +    private static final int QUICKSORT_THRESHOLD = 286;
   59.71 +
   59.72 +    /**
   59.73 +     * If the length of an array to be sorted is less than this
   59.74 +     * constant, insertion sort is used in preference to Quicksort.
   59.75 +     */
   59.76 +    private static final int INSERTION_SORT_THRESHOLD = 47;
   59.77 +
   59.78 +    /**
   59.79 +     * If the length of a byte array to be sorted is greater than this
   59.80 +     * constant, counting sort is used in preference to insertion sort.
   59.81 +     */
   59.82 +    private static final int COUNTING_SORT_THRESHOLD_FOR_BYTE = 29;
   59.83 +
   59.84 +    /**
   59.85 +     * If the length of a short or char array to be sorted is greater
   59.86 +     * than this constant, counting sort is used in preference to Quicksort.
   59.87 +     */
   59.88 +    private static final int COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR = 3200;
   59.89 +
   59.90 +    /*
   59.91 +     * Sorting methods for seven primitive types.
   59.92 +     */
   59.93 +
   59.94 +    /**
   59.95 +     * Sorts the specified array.
   59.96 +     *
   59.97 +     * @param a the array to be sorted
   59.98 +     */
   59.99 +    public static void sort(int[] a) {
  59.100 +        sort(a, 0, a.length - 1);
  59.101 +    }
  59.102 +
  59.103 +    /**
  59.104 +     * Sorts the specified range of the array.
  59.105 +     *
  59.106 +     * @param a the array to be sorted
  59.107 +     * @param left the index of the first element, inclusive, to be sorted
  59.108 +     * @param right the index of the last element, inclusive, to be sorted
  59.109 +     */
  59.110 +    public static void sort(int[] a, int left, int right) {
  59.111 +        // Use Quicksort on small arrays
  59.112 +        if (right - left < QUICKSORT_THRESHOLD) {
  59.113 +            sort(a, left, right, true);
  59.114 +            return;
  59.115 +        }
  59.116 +
  59.117 +        /*
  59.118 +         * Index run[i] is the start of i-th run
  59.119 +         * (ascending or descending sequence).
  59.120 +         */
  59.121 +        int[] run = new int[MAX_RUN_COUNT + 1];
  59.122 +        int count = 0; run[0] = left;
  59.123 +
  59.124 +        // Check if the array is nearly sorted
  59.125 +        for (int k = left; k < right; run[count] = k) {
  59.126 +            if (a[k] < a[k + 1]) { // ascending
  59.127 +                while (++k <= right && a[k - 1] <= a[k]);
  59.128 +            } else if (a[k] > a[k + 1]) { // descending
  59.129 +                while (++k <= right && a[k - 1] >= a[k]);
  59.130 +                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
  59.131 +                    int t = a[lo]; a[lo] = a[hi]; a[hi] = t;
  59.132 +                }
  59.133 +            } else { // equal
  59.134 +                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
  59.135 +                    if (--m == 0) {
  59.136 +                        sort(a, left, right, true);
  59.137 +                        return;
  59.138 +                    }
  59.139 +                }
  59.140 +            }
  59.141 +
  59.142 +            /*
  59.143 +             * The array is not highly structured,
  59.144 +             * use Quicksort instead of merge sort.
  59.145 +             */
  59.146 +            if (++count == MAX_RUN_COUNT) {
  59.147 +                sort(a, left, right, true);
  59.148 +                return;
  59.149 +            }
  59.150 +        }
  59.151 +
  59.152 +        // Check special cases
  59.153 +        if (run[count] == right++) { // The last run contains one element
  59.154 +            run[++count] = right;
  59.155 +        } else if (count == 1) { // The array is already sorted
  59.156 +            return;
  59.157 +        }
  59.158 +
  59.159 +        /*
  59.160 +         * Create temporary array, which is used for merging.
  59.161 +         * Implementation note: variable "right" is increased by 1.
  59.162 +         */
  59.163 +        int[] b; byte odd = 0;
  59.164 +        for (int n = 1; (n <<= 1) < count; odd ^= 1);
  59.165 +
  59.166 +        if (odd == 0) {
  59.167 +            b = a; a = new int[b.length];
  59.168 +            for (int i = left - 1; ++i < right; a[i] = b[i]);
  59.169 +        } else {
  59.170 +            b = new int[a.length];
  59.171 +        }
  59.172 +
  59.173 +        // Merging
  59.174 +        for (int last; count > 1; count = last) {
  59.175 +            for (int k = (last = 0) + 2; k <= count; k += 2) {
  59.176 +                int hi = run[k], mi = run[k - 1];
  59.177 +                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
  59.178 +                    if (q >= hi || p < mi && a[p] <= a[q]) {
  59.179 +                        b[i] = a[p++];
  59.180 +                    } else {
  59.181 +                        b[i] = a[q++];
  59.182 +                    }
  59.183 +                }
  59.184 +                run[++last] = hi;
  59.185 +            }
  59.186 +            if ((count & 1) != 0) {
  59.187 +                for (int i = right, lo = run[count - 1]; --i >= lo;
  59.188 +                    b[i] = a[i]
  59.189 +                );
  59.190 +                run[++last] = right;
  59.191 +            }
  59.192 +            int[] t = a; a = b; b = t;
  59.193 +        }
  59.194 +    }
  59.195 +
  59.196 +    /**
  59.197 +     * Sorts the specified range of the array by Dual-Pivot Quicksort.
  59.198 +     *
  59.199 +     * @param a the array to be sorted
  59.200 +     * @param left the index of the first element, inclusive, to be sorted
  59.201 +     * @param right the index of the last element, inclusive, to be sorted
  59.202 +     * @param leftmost indicates if this part is the leftmost in the range
  59.203 +     */
  59.204 +    private static void sort(int[] a, int left, int right, boolean leftmost) {
  59.205 +        int length = right - left + 1;
  59.206 +
  59.207 +        // Use insertion sort on tiny arrays
  59.208 +        if (length < INSERTION_SORT_THRESHOLD) {
  59.209 +            if (leftmost) {
  59.210 +                /*
  59.211 +                 * Traditional (without sentinel) insertion sort,
  59.212 +                 * optimized for server VM, is used in case of
  59.213 +                 * the leftmost part.
  59.214 +                 */
  59.215 +                for (int i = left, j = i; i < right; j = ++i) {
  59.216 +                    int ai = a[i + 1];
  59.217 +                    while (ai < a[j]) {
  59.218 +                        a[j + 1] = a[j];
  59.219 +                        if (j-- == left) {
  59.220 +                            break;
  59.221 +                        }
  59.222 +                    }
  59.223 +                    a[j + 1] = ai;
  59.224 +                }
  59.225 +            } else {
  59.226 +                /*
  59.227 +                 * Skip the longest ascending sequence.
  59.228 +                 */
  59.229 +                do {
  59.230 +                    if (left >= right) {
  59.231 +                        return;
  59.232 +                    }
  59.233 +                } while (a[++left] >= a[left - 1]);
  59.234 +
  59.235 +                /*
  59.236 +                 * Every element from adjoining part plays the role
  59.237 +                 * of sentinel, therefore this allows us to avoid the
  59.238 +                 * left range check on each iteration. Moreover, we use
  59.239 +                 * the more optimized algorithm, so called pair insertion
  59.240 +                 * sort, which is faster (in the context of Quicksort)
  59.241 +                 * than traditional implementation of insertion sort.
  59.242 +                 */
  59.243 +                for (int k = left; ++left <= right; k = ++left) {
  59.244 +                    int a1 = a[k], a2 = a[left];
  59.245 +
  59.246 +                    if (a1 < a2) {
  59.247 +                        a2 = a1; a1 = a[left];
  59.248 +                    }
  59.249 +                    while (a1 < a[--k]) {
  59.250 +                        a[k + 2] = a[k];
  59.251 +                    }
  59.252 +                    a[++k + 1] = a1;
  59.253 +
  59.254 +                    while (a2 < a[--k]) {
  59.255 +                        a[k + 1] = a[k];
  59.256 +                    }
  59.257 +                    a[k + 1] = a2;
  59.258 +                }
  59.259 +                int last = a[right];
  59.260 +
  59.261 +                while (last < a[--right]) {
  59.262 +                    a[right + 1] = a[right];
  59.263 +                }
  59.264 +                a[right + 1] = last;
  59.265 +            }
  59.266 +            return;
  59.267 +        }
  59.268 +
  59.269 +        // Inexpensive approximation of length / 7
  59.270 +        int seventh = (length >> 3) + (length >> 6) + 1;
  59.271 +
  59.272 +        /*
  59.273 +         * Sort five evenly spaced elements around (and including) the
  59.274 +         * center element in the range. These elements will be used for
  59.275 +         * pivot selection as described below. The choice for spacing
  59.276 +         * these elements was empirically determined to work well on
  59.277 +         * a wide variety of inputs.
  59.278 +         */
  59.279 +        int e3 = (left + right) >>> 1; // The midpoint
  59.280 +        int e2 = e3 - seventh;
  59.281 +        int e1 = e2 - seventh;
  59.282 +        int e4 = e3 + seventh;
  59.283 +        int e5 = e4 + seventh;
  59.284 +
  59.285 +        // Sort these elements using insertion sort
  59.286 +        if (a[e2] < a[e1]) { int t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
  59.287 +
  59.288 +        if (a[e3] < a[e2]) { int t = a[e3]; a[e3] = a[e2]; a[e2] = t;
  59.289 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  59.290 +        }
  59.291 +        if (a[e4] < a[e3]) { int t = a[e4]; a[e4] = a[e3]; a[e3] = t;
  59.292 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
  59.293 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  59.294 +            }
  59.295 +        }
  59.296 +        if (a[e5] < a[e4]) { int t = a[e5]; a[e5] = a[e4]; a[e4] = t;
  59.297 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
  59.298 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
  59.299 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  59.300 +                }
  59.301 +            }
  59.302 +        }
  59.303 +
  59.304 +        // Pointers
  59.305 +        int less  = left;  // The index of the first element of center part
  59.306 +        int great = right; // The index before the first element of right part
  59.307 +
  59.308 +        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
  59.309 +            /*
  59.310 +             * Use the second and fourth of the five sorted elements as pivots.
  59.311 +             * These values are inexpensive approximations of the first and
  59.312 +             * second terciles of the array. Note that pivot1 <= pivot2.
  59.313 +             */
  59.314 +            int pivot1 = a[e2];
  59.315 +            int pivot2 = a[e4];
  59.316 +
  59.317 +            /*
  59.318 +             * The first and the last elements to be sorted are moved to the
  59.319 +             * locations formerly occupied by the pivots. When partitioning
  59.320 +             * is complete, the pivots are swapped back into their final
  59.321 +             * positions, and excluded from subsequent sorting.
  59.322 +             */
  59.323 +            a[e2] = a[left];
  59.324 +            a[e4] = a[right];
  59.325 +
  59.326 +            /*
  59.327 +             * Skip elements, which are less or greater than pivot values.
  59.328 +             */
  59.329 +            while (a[++less] < pivot1);
  59.330 +            while (a[--great] > pivot2);
  59.331 +
  59.332 +            /*
  59.333 +             * Partitioning:
  59.334 +             *
  59.335 +             *   left part           center part                   right part
  59.336 +             * +--------------------------------------------------------------+
  59.337 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
  59.338 +             * +--------------------------------------------------------------+
  59.339 +             *               ^                          ^       ^
  59.340 +             *               |                          |       |
  59.341 +             *              less                        k     great
  59.342 +             *
  59.343 +             * Invariants:
  59.344 +             *
  59.345 +             *              all in (left, less)   < pivot1
  59.346 +             *    pivot1 <= all in [less, k)     <= pivot2
  59.347 +             *              all in (great, right) > pivot2
  59.348 +             *
  59.349 +             * Pointer k is the first index of ?-part.
  59.350 +             */
  59.351 +            outer:
  59.352 +            for (int k = less - 1; ++k <= great; ) {
  59.353 +                int ak = a[k];
  59.354 +                if (ak < pivot1) { // Move a[k] to left part
  59.355 +                    a[k] = a[less];
  59.356 +                    /*
  59.357 +                     * Here and below we use "a[i] = b; i++;" instead
  59.358 +                     * of "a[i++] = b;" due to performance issue.
  59.359 +                     */
  59.360 +                    a[less] = ak;
  59.361 +                    ++less;
  59.362 +                } else if (ak > pivot2) { // Move a[k] to right part
  59.363 +                    while (a[great] > pivot2) {
  59.364 +                        if (great-- == k) {
  59.365 +                            break outer;
  59.366 +                        }
  59.367 +                    }
  59.368 +                    if (a[great] < pivot1) { // a[great] <= pivot2
  59.369 +                        a[k] = a[less];
  59.370 +                        a[less] = a[great];
  59.371 +                        ++less;
  59.372 +                    } else { // pivot1 <= a[great] <= pivot2
  59.373 +                        a[k] = a[great];
  59.374 +                    }
  59.375 +                    /*
  59.376 +                     * Here and below we use "a[i] = b; i--;" instead
  59.377 +                     * of "a[i--] = b;" due to performance issue.
  59.378 +                     */
  59.379 +                    a[great] = ak;
  59.380 +                    --great;
  59.381 +                }
  59.382 +            }
  59.383 +
  59.384 +            // Swap pivots into their final positions
  59.385 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
  59.386 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
  59.387 +
  59.388 +            // Sort left and right parts recursively, excluding known pivots
  59.389 +            sort(a, left, less - 2, leftmost);
  59.390 +            sort(a, great + 2, right, false);
  59.391 +
  59.392 +            /*
  59.393 +             * If center part is too large (comprises > 4/7 of the array),
  59.394 +             * swap internal pivot values to ends.
  59.395 +             */
  59.396 +            if (less < e1 && e5 < great) {
  59.397 +                /*
  59.398 +                 * Skip elements, which are equal to pivot values.
  59.399 +                 */
  59.400 +                while (a[less] == pivot1) {
  59.401 +                    ++less;
  59.402 +                }
  59.403 +
  59.404 +                while (a[great] == pivot2) {
  59.405 +                    --great;
  59.406 +                }
  59.407 +
  59.408 +                /*
  59.409 +                 * Partitioning:
  59.410 +                 *
  59.411 +                 *   left part         center part                  right part
  59.412 +                 * +----------------------------------------------------------+
  59.413 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
  59.414 +                 * +----------------------------------------------------------+
  59.415 +                 *              ^                        ^       ^
  59.416 +                 *              |                        |       |
  59.417 +                 *             less                      k     great
  59.418 +                 *
  59.419 +                 * Invariants:
  59.420 +                 *
  59.421 +                 *              all in (*,  less) == pivot1
  59.422 +                 *     pivot1 < all in [less,  k)  < pivot2
  59.423 +                 *              all in (great, *) == pivot2
  59.424 +                 *
  59.425 +                 * Pointer k is the first index of ?-part.
  59.426 +                 */
  59.427 +                outer:
  59.428 +                for (int k = less - 1; ++k <= great; ) {
  59.429 +                    int ak = a[k];
  59.430 +                    if (ak == pivot1) { // Move a[k] to left part
  59.431 +                        a[k] = a[less];
  59.432 +                        a[less] = ak;
  59.433 +                        ++less;
  59.434 +                    } else if (ak == pivot2) { // Move a[k] to right part
  59.435 +                        while (a[great] == pivot2) {
  59.436 +                            if (great-- == k) {
  59.437 +                                break outer;
  59.438 +                            }
  59.439 +                        }
  59.440 +                        if (a[great] == pivot1) { // a[great] < pivot2
  59.441 +                            a[k] = a[less];
  59.442 +                            /*
  59.443 +                             * Even though a[great] equals to pivot1, the
  59.444 +                             * assignment a[less] = pivot1 may be incorrect,
  59.445 +                             * if a[great] and pivot1 are floating-point zeros
  59.446 +                             * of different signs. Therefore in float and
  59.447 +                             * double sorting methods we have to use more
  59.448 +                             * accurate assignment a[less] = a[great].
  59.449 +                             */
  59.450 +                            a[less] = pivot1;
  59.451 +                            ++less;
  59.452 +                        } else { // pivot1 < a[great] < pivot2
  59.453 +                            a[k] = a[great];
  59.454 +                        }
  59.455 +                        a[great] = ak;
  59.456 +                        --great;
  59.457 +                    }
  59.458 +                }
  59.459 +            }
  59.460 +
  59.461 +            // Sort center part recursively
  59.462 +            sort(a, less, great, false);
  59.463 +
  59.464 +        } else { // Partitioning with one pivot
  59.465 +            /*
  59.466 +             * Use the third of the five sorted elements as pivot.
  59.467 +             * This value is inexpensive approximation of the median.
  59.468 +             */
  59.469 +            int pivot = a[e3];
  59.470 +
  59.471 +            /*
  59.472 +             * Partitioning degenerates to the traditional 3-way
  59.473 +             * (or "Dutch National Flag") schema:
  59.474 +             *
  59.475 +             *   left part    center part              right part
  59.476 +             * +-------------------------------------------------+
  59.477 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
  59.478 +             * +-------------------------------------------------+
  59.479 +             *              ^              ^        ^
  59.480 +             *              |              |        |
  59.481 +             *             less            k      great
  59.482 +             *
  59.483 +             * Invariants:
  59.484 +             *
  59.485 +             *   all in (left, less)   < pivot
  59.486 +             *   all in [less, k)     == pivot
  59.487 +             *   all in (great, right) > pivot
  59.488 +             *
  59.489 +             * Pointer k is the first index of ?-part.
  59.490 +             */
  59.491 +            for (int k = less; k <= great; ++k) {
  59.492 +                if (a[k] == pivot) {
  59.493 +                    continue;
  59.494 +                }
  59.495 +                int ak = a[k];
  59.496 +                if (ak < pivot) { // Move a[k] to left part
  59.497 +                    a[k] = a[less];
  59.498 +                    a[less] = ak;
  59.499 +                    ++less;
  59.500 +                } else { // a[k] > pivot - Move a[k] to right part
  59.501 +                    while (a[great] > pivot) {
  59.502 +                        --great;
  59.503 +                    }
  59.504 +                    if (a[great] < pivot) { // a[great] <= pivot
  59.505 +                        a[k] = a[less];
  59.506 +                        a[less] = a[great];
  59.507 +                        ++less;
  59.508 +                    } else { // a[great] == pivot
  59.509 +                        /*
  59.510 +                         * Even though a[great] equals to pivot, the
  59.511 +                         * assignment a[k] = pivot may be incorrect,
  59.512 +                         * if a[great] and pivot are floating-point
  59.513 +                         * zeros of different signs. Therefore in float
  59.514 +                         * and double sorting methods we have to use
  59.515 +                         * more accurate assignment a[k] = a[great].
  59.516 +                         */
  59.517 +                        a[k] = pivot;
  59.518 +                    }
  59.519 +                    a[great] = ak;
  59.520 +                    --great;
  59.521 +                }
  59.522 +            }
  59.523 +
  59.524 +            /*
  59.525 +             * Sort left and right parts recursively.
  59.526 +             * All elements from center part are equal
  59.527 +             * and, therefore, already sorted.
  59.528 +             */
  59.529 +            sort(a, left, less - 1, leftmost);
  59.530 +            sort(a, great + 1, right, false);
  59.531 +        }
  59.532 +    }
  59.533 +
  59.534 +    /**
  59.535 +     * Sorts the specified array.
  59.536 +     *
  59.537 +     * @param a the array to be sorted
  59.538 +     */
  59.539 +    public static void sort(long[] a) {
  59.540 +        sort(a, 0, a.length - 1);
  59.541 +    }
  59.542 +
  59.543 +    /**
  59.544 +     * Sorts the specified range of the array.
  59.545 +     *
  59.546 +     * @param a the array to be sorted
  59.547 +     * @param left the index of the first element, inclusive, to be sorted
  59.548 +     * @param right the index of the last element, inclusive, to be sorted
  59.549 +     */
  59.550 +    public static void sort(long[] a, int left, int right) {
  59.551 +        // Use Quicksort on small arrays
  59.552 +        if (right - left < QUICKSORT_THRESHOLD) {
  59.553 +            sort(a, left, right, true);
  59.554 +            return;
  59.555 +        }
  59.556 +
  59.557 +        /*
  59.558 +         * Index run[i] is the start of i-th run
  59.559 +         * (ascending or descending sequence).
  59.560 +         */
  59.561 +        int[] run = new int[MAX_RUN_COUNT + 1];
  59.562 +        int count = 0; run[0] = left;
  59.563 +
  59.564 +        // Check if the array is nearly sorted
  59.565 +        for (int k = left; k < right; run[count] = k) {
  59.566 +            if (a[k] < a[k + 1]) { // ascending
  59.567 +                while (++k <= right && a[k - 1] <= a[k]);
  59.568 +            } else if (a[k] > a[k + 1]) { // descending
  59.569 +                while (++k <= right && a[k - 1] >= a[k]);
  59.570 +                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
  59.571 +                    long t = a[lo]; a[lo] = a[hi]; a[hi] = t;
  59.572 +                }
  59.573 +            } else { // equal
  59.574 +                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
  59.575 +                    if (--m == 0) {
  59.576 +                        sort(a, left, right, true);
  59.577 +                        return;
  59.578 +                    }
  59.579 +                }
  59.580 +            }
  59.581 +
  59.582 +            /*
  59.583 +             * The array is not highly structured,
  59.584 +             * use Quicksort instead of merge sort.
  59.585 +             */
  59.586 +            if (++count == MAX_RUN_COUNT) {
  59.587 +                sort(a, left, right, true);
  59.588 +                return;
  59.589 +            }
  59.590 +        }
  59.591 +
  59.592 +        // Check special cases
  59.593 +        if (run[count] == right++) { // The last run contains one element
  59.594 +            run[++count] = right;
  59.595 +        } else if (count == 1) { // The array is already sorted
  59.596 +            return;
  59.597 +        }
  59.598 +
  59.599 +        /*
  59.600 +         * Create temporary array, which is used for merging.
  59.601 +         * Implementation note: variable "right" is increased by 1.
  59.602 +         */
  59.603 +        long[] b; byte odd = 0;
  59.604 +        for (int n = 1; (n <<= 1) < count; odd ^= 1);
  59.605 +
  59.606 +        if (odd == 0) {
  59.607 +            b = a; a = new long[b.length];
  59.608 +            for (int i = left - 1; ++i < right; a[i] = b[i]);
  59.609 +        } else {
  59.610 +            b = new long[a.length];
  59.611 +        }
  59.612 +
  59.613 +        // Merging
  59.614 +        for (int last; count > 1; count = last) {
  59.615 +            for (int k = (last = 0) + 2; k <= count; k += 2) {
  59.616 +                int hi = run[k], mi = run[k - 1];
  59.617 +                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
  59.618 +                    if (q >= hi || p < mi && a[p] <= a[q]) {
  59.619 +                        b[i] = a[p++];
  59.620 +                    } else {
  59.621 +                        b[i] = a[q++];
  59.622 +                    }
  59.623 +                }
  59.624 +                run[++last] = hi;
  59.625 +            }
  59.626 +            if ((count & 1) != 0) {
  59.627 +                for (int i = right, lo = run[count - 1]; --i >= lo;
  59.628 +                    b[i] = a[i]
  59.629 +                );
  59.630 +                run[++last] = right;
  59.631 +            }
  59.632 +            long[] t = a; a = b; b = t;
  59.633 +        }
  59.634 +    }
  59.635 +
  59.636 +    /**
  59.637 +     * Sorts the specified range of the array by Dual-Pivot Quicksort.
  59.638 +     *
  59.639 +     * @param a the array to be sorted
  59.640 +     * @param left the index of the first element, inclusive, to be sorted
  59.641 +     * @param right the index of the last element, inclusive, to be sorted
  59.642 +     * @param leftmost indicates if this part is the leftmost in the range
  59.643 +     */
  59.644 +    private static void sort(long[] a, int left, int right, boolean leftmost) {
  59.645 +        int length = right - left + 1;
  59.646 +
  59.647 +        // Use insertion sort on tiny arrays
  59.648 +        if (length < INSERTION_SORT_THRESHOLD) {
  59.649 +            if (leftmost) {
  59.650 +                /*
  59.651 +                 * Traditional (without sentinel) insertion sort,
  59.652 +                 * optimized for server VM, is used in case of
  59.653 +                 * the leftmost part.
  59.654 +                 */
  59.655 +                for (int i = left, j = i; i < right; j = ++i) {
  59.656 +                    long ai = a[i + 1];
  59.657 +                    while (ai < a[j]) {
  59.658 +                        a[j + 1] = a[j];
  59.659 +                        if (j-- == left) {
  59.660 +                            break;
  59.661 +                        }
  59.662 +                    }
  59.663 +                    a[j + 1] = ai;
  59.664 +                }
  59.665 +            } else {
  59.666 +                /*
  59.667 +                 * Skip the longest ascending sequence.
  59.668 +                 */
  59.669 +                do {
  59.670 +                    if (left >= right) {
  59.671 +                        return;
  59.672 +                    }
  59.673 +                } while (a[++left] >= a[left - 1]);
  59.674 +
  59.675 +                /*
  59.676 +                 * Every element from adjoining part plays the role
  59.677 +                 * of sentinel, therefore this allows us to avoid the
  59.678 +                 * left range check on each iteration. Moreover, we use
  59.679 +                 * the more optimized algorithm, so called pair insertion
  59.680 +                 * sort, which is faster (in the context of Quicksort)
  59.681 +                 * than traditional implementation of insertion sort.
  59.682 +                 */
  59.683 +                for (int k = left; ++left <= right; k = ++left) {
  59.684 +                    long a1 = a[k], a2 = a[left];
  59.685 +
  59.686 +                    if (a1 < a2) {
  59.687 +                        a2 = a1; a1 = a[left];
  59.688 +                    }
  59.689 +                    while (a1 < a[--k]) {
  59.690 +                        a[k + 2] = a[k];
  59.691 +                    }
  59.692 +                    a[++k + 1] = a1;
  59.693 +
  59.694 +                    while (a2 < a[--k]) {
  59.695 +                        a[k + 1] = a[k];
  59.696 +                    }
  59.697 +                    a[k + 1] = a2;
  59.698 +                }
  59.699 +                long last = a[right];
  59.700 +
  59.701 +                while (last < a[--right]) {
  59.702 +                    a[right + 1] = a[right];
  59.703 +                }
  59.704 +                a[right + 1] = last;
  59.705 +            }
  59.706 +            return;
  59.707 +        }
  59.708 +
  59.709 +        // Inexpensive approximation of length / 7
  59.710 +        int seventh = (length >> 3) + (length >> 6) + 1;
  59.711 +
  59.712 +        /*
  59.713 +         * Sort five evenly spaced elements around (and including) the
  59.714 +         * center element in the range. These elements will be used for
  59.715 +         * pivot selection as described below. The choice for spacing
  59.716 +         * these elements was empirically determined to work well on
  59.717 +         * a wide variety of inputs.
  59.718 +         */
  59.719 +        int e3 = (left + right) >>> 1; // The midpoint
  59.720 +        int e2 = e3 - seventh;
  59.721 +        int e1 = e2 - seventh;
  59.722 +        int e4 = e3 + seventh;
  59.723 +        int e5 = e4 + seventh;
  59.724 +
  59.725 +        // Sort these elements using insertion sort
  59.726 +        if (a[e2] < a[e1]) { long t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
  59.727 +
  59.728 +        if (a[e3] < a[e2]) { long t = a[e3]; a[e3] = a[e2]; a[e2] = t;
  59.729 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  59.730 +        }
  59.731 +        if (a[e4] < a[e3]) { long t = a[e4]; a[e4] = a[e3]; a[e3] = t;
  59.732 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
  59.733 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  59.734 +            }
  59.735 +        }
  59.736 +        if (a[e5] < a[e4]) { long t = a[e5]; a[e5] = a[e4]; a[e4] = t;
  59.737 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
  59.738 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
  59.739 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  59.740 +                }
  59.741 +            }
  59.742 +        }
  59.743 +
  59.744 +        // Pointers
  59.745 +        int less  = left;  // The index of the first element of center part
  59.746 +        int great = right; // The index before the first element of right part
  59.747 +
  59.748 +        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
  59.749 +            /*
  59.750 +             * Use the second and fourth of the five sorted elements as pivots.
  59.751 +             * These values are inexpensive approximations of the first and
  59.752 +             * second terciles of the array. Note that pivot1 <= pivot2.
  59.753 +             */
  59.754 +            long pivot1 = a[e2];
  59.755 +            long pivot2 = a[e4];
  59.756 +
  59.757 +            /*
  59.758 +             * The first and the last elements to be sorted are moved to the
  59.759 +             * locations formerly occupied by the pivots. When partitioning
  59.760 +             * is complete, the pivots are swapped back into their final
  59.761 +             * positions, and excluded from subsequent sorting.
  59.762 +             */
  59.763 +            a[e2] = a[left];
  59.764 +            a[e4] = a[right];
  59.765 +
  59.766 +            /*
  59.767 +             * Skip elements, which are less or greater than pivot values.
  59.768 +             */
  59.769 +            while (a[++less] < pivot1);
  59.770 +            while (a[--great] > pivot2);
  59.771 +
  59.772 +            /*
  59.773 +             * Partitioning:
  59.774 +             *
  59.775 +             *   left part           center part                   right part
  59.776 +             * +--------------------------------------------------------------+
  59.777 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
  59.778 +             * +--------------------------------------------------------------+
  59.779 +             *               ^                          ^       ^
  59.780 +             *               |                          |       |
  59.781 +             *              less                        k     great
  59.782 +             *
  59.783 +             * Invariants:
  59.784 +             *
  59.785 +             *              all in (left, less)   < pivot1
  59.786 +             *    pivot1 <= all in [less, k)     <= pivot2
  59.787 +             *              all in (great, right) > pivot2
  59.788 +             *
  59.789 +             * Pointer k is the first index of ?-part.
  59.790 +             */
  59.791 +            outer:
  59.792 +            for (int k = less - 1; ++k <= great; ) {
  59.793 +                long ak = a[k];
  59.794 +                if (ak < pivot1) { // Move a[k] to left part
  59.795 +                    a[k] = a[less];
  59.796 +                    /*
  59.797 +                     * Here and below we use "a[i] = b; i++;" instead
  59.798 +                     * of "a[i++] = b;" due to performance issue.
  59.799 +                     */
  59.800 +                    a[less] = ak;
  59.801 +                    ++less;
  59.802 +                } else if (ak > pivot2) { // Move a[k] to right part
  59.803 +                    while (a[great] > pivot2) {
  59.804 +                        if (great-- == k) {
  59.805 +                            break outer;
  59.806 +                        }
  59.807 +                    }
  59.808 +                    if (a[great] < pivot1) { // a[great] <= pivot2
  59.809 +                        a[k] = a[less];
  59.810 +                        a[less] = a[great];
  59.811 +                        ++less;
  59.812 +                    } else { // pivot1 <= a[great] <= pivot2
  59.813 +                        a[k] = a[great];
  59.814 +                    }
  59.815 +                    /*
  59.816 +                     * Here and below we use "a[i] = b; i--;" instead
  59.817 +                     * of "a[i--] = b;" due to performance issue.
  59.818 +                     */
  59.819 +                    a[great] = ak;
  59.820 +                    --great;
  59.821 +                }
  59.822 +            }
  59.823 +
  59.824 +            // Swap pivots into their final positions
  59.825 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
  59.826 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
  59.827 +
  59.828 +            // Sort left and right parts recursively, excluding known pivots
  59.829 +            sort(a, left, less - 2, leftmost);
  59.830 +            sort(a, great + 2, right, false);
  59.831 +
  59.832 +            /*
  59.833 +             * If center part is too large (comprises > 4/7 of the array),
  59.834 +             * swap internal pivot values to ends.
  59.835 +             */
  59.836 +            if (less < e1 && e5 < great) {
  59.837 +                /*
  59.838 +                 * Skip elements, which are equal to pivot values.
  59.839 +                 */
  59.840 +                while (a[less] == pivot1) {
  59.841 +                    ++less;
  59.842 +                }
  59.843 +
  59.844 +                while (a[great] == pivot2) {
  59.845 +                    --great;
  59.846 +                }
  59.847 +
  59.848 +                /*
  59.849 +                 * Partitioning:
  59.850 +                 *
  59.851 +                 *   left part         center part                  right part
  59.852 +                 * +----------------------------------------------------------+
  59.853 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
  59.854 +                 * +----------------------------------------------------------+
  59.855 +                 *              ^                        ^       ^
  59.856 +                 *              |                        |       |
  59.857 +                 *             less                      k     great
  59.858 +                 *
  59.859 +                 * Invariants:
  59.860 +                 *
  59.861 +                 *              all in (*,  less) == pivot1
  59.862 +                 *     pivot1 < all in [less,  k)  < pivot2
  59.863 +                 *              all in (great, *) == pivot2
  59.864 +                 *
  59.865 +                 * Pointer k is the first index of ?-part.
  59.866 +                 */
  59.867 +                outer:
  59.868 +                for (int k = less - 1; ++k <= great; ) {
  59.869 +                    long ak = a[k];
  59.870 +                    if (ak == pivot1) { // Move a[k] to left part
  59.871 +                        a[k] = a[less];
  59.872 +                        a[less] = ak;
  59.873 +                        ++less;
  59.874 +                    } else if (ak == pivot2) { // Move a[k] to right part
  59.875 +                        while (a[great] == pivot2) {
  59.876 +                            if (great-- == k) {
  59.877 +                                break outer;
  59.878 +                            }
  59.879 +                        }
  59.880 +                        if (a[great] == pivot1) { // a[great] < pivot2
  59.881 +                            a[k] = a[less];
  59.882 +                            /*
  59.883 +                             * Even though a[great] equals to pivot1, the
  59.884 +                             * assignment a[less] = pivot1 may be incorrect,
  59.885 +                             * if a[great] and pivot1 are floating-point zeros
  59.886 +                             * of different signs. Therefore in float and
  59.887 +                             * double sorting methods we have to use more
  59.888 +                             * accurate assignment a[less] = a[great].
  59.889 +                             */
  59.890 +                            a[less] = pivot1;
  59.891 +                            ++less;
  59.892 +                        } else { // pivot1 < a[great] < pivot2
  59.893 +                            a[k] = a[great];
  59.894 +                        }
  59.895 +                        a[great] = ak;
  59.896 +                        --great;
  59.897 +                    }
  59.898 +                }
  59.899 +            }
  59.900 +
  59.901 +            // Sort center part recursively
  59.902 +            sort(a, less, great, false);
  59.903 +
  59.904 +        } else { // Partitioning with one pivot
  59.905 +            /*
  59.906 +             * Use the third of the five sorted elements as pivot.
  59.907 +             * This value is inexpensive approximation of the median.
  59.908 +             */
  59.909 +            long pivot = a[e3];
  59.910 +
  59.911 +            /*
  59.912 +             * Partitioning degenerates to the traditional 3-way
  59.913 +             * (or "Dutch National Flag") schema:
  59.914 +             *
  59.915 +             *   left part    center part              right part
  59.916 +             * +-------------------------------------------------+
  59.917 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
  59.918 +             * +-------------------------------------------------+
  59.919 +             *              ^              ^        ^
  59.920 +             *              |              |        |
  59.921 +             *             less            k      great
  59.922 +             *
  59.923 +             * Invariants:
  59.924 +             *
  59.925 +             *   all in (left, less)   < pivot
  59.926 +             *   all in [less, k)     == pivot
  59.927 +             *   all in (great, right) > pivot
  59.928 +             *
  59.929 +             * Pointer k is the first index of ?-part.
  59.930 +             */
  59.931 +            for (int k = less; k <= great; ++k) {
  59.932 +                if (a[k] == pivot) {
  59.933 +                    continue;
  59.934 +                }
  59.935 +                long ak = a[k];
  59.936 +                if (ak < pivot) { // Move a[k] to left part
  59.937 +                    a[k] = a[less];
  59.938 +                    a[less] = ak;
  59.939 +                    ++less;
  59.940 +                } else { // a[k] > pivot - Move a[k] to right part
  59.941 +                    while (a[great] > pivot) {
  59.942 +                        --great;
  59.943 +                    }
  59.944 +                    if (a[great] < pivot) { // a[great] <= pivot
  59.945 +                        a[k] = a[less];
  59.946 +                        a[less] = a[great];
  59.947 +                        ++less;
  59.948 +                    } else { // a[great] == pivot
  59.949 +                        /*
  59.950 +                         * Even though a[great] equals to pivot, the
  59.951 +                         * assignment a[k] = pivot may be incorrect,
  59.952 +                         * if a[great] and pivot are floating-point
  59.953 +                         * zeros of different signs. Therefore in float
  59.954 +                         * and double sorting methods we have to use
  59.955 +                         * more accurate assignment a[k] = a[great].
  59.956 +                         */
  59.957 +                        a[k] = pivot;
  59.958 +                    }
  59.959 +                    a[great] = ak;
  59.960 +                    --great;
  59.961 +                }
  59.962 +            }
  59.963 +
  59.964 +            /*
  59.965 +             * Sort left and right parts recursively.
  59.966 +             * All elements from center part are equal
  59.967 +             * and, therefore, already sorted.
  59.968 +             */
  59.969 +            sort(a, left, less - 1, leftmost);
  59.970 +            sort(a, great + 1, right, false);
  59.971 +        }
  59.972 +    }
  59.973 +
  59.974 +    /**
  59.975 +     * Sorts the specified array.
  59.976 +     *
  59.977 +     * @param a the array to be sorted
  59.978 +     */
  59.979 +    public static void sort(short[] a) {
  59.980 +        sort(a, 0, a.length - 1);
  59.981 +    }
  59.982 +
  59.983 +    /**
  59.984 +     * Sorts the specified range of the array.
  59.985 +     *
  59.986 +     * @param a the array to be sorted
  59.987 +     * @param left the index of the first element, inclusive, to be sorted
  59.988 +     * @param right the index of the last element, inclusive, to be sorted
  59.989 +     */
  59.990 +    public static void sort(short[] a, int left, int right) {
  59.991 +        // Use counting sort on large arrays
  59.992 +        if (right - left > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
  59.993 +            int[] count = new int[NUM_SHORT_VALUES];
  59.994 +
  59.995 +            for (int i = left - 1; ++i <= right;
  59.996 +                count[a[i] - Short.MIN_VALUE]++
  59.997 +            );
  59.998 +            for (int i = NUM_SHORT_VALUES, k = right + 1; k > left; ) {
  59.999 +                while (count[--i] == 0);
 59.1000 +                short value = (short) (i + Short.MIN_VALUE);
 59.1001 +                int s = count[i];
 59.1002 +
 59.1003 +                do {
 59.1004 +                    a[--k] = value;
 59.1005 +                } while (--s > 0);
 59.1006 +            }
 59.1007 +        } else { // Use Dual-Pivot Quicksort on small arrays
 59.1008 +            doSort(a, left, right);
 59.1009 +        }
 59.1010 +    }
 59.1011 +
 59.1012 +    /** The number of distinct short values. */
 59.1013 +    private static final int NUM_SHORT_VALUES = 1 << 16;
 59.1014 +
 59.1015 +    /**
 59.1016 +     * Sorts the specified range of the array.
 59.1017 +     *
 59.1018 +     * @param a the array to be sorted
 59.1019 +     * @param left the index of the first element, inclusive, to be sorted
 59.1020 +     * @param right the index of the last element, inclusive, to be sorted
 59.1021 +     */
 59.1022 +    private static void doSort(short[] a, int left, int right) {
 59.1023 +        // Use Quicksort on small arrays
 59.1024 +        if (right - left < QUICKSORT_THRESHOLD) {
 59.1025 +            sort(a, left, right, true);
 59.1026 +            return;
 59.1027 +        }
 59.1028 +
 59.1029 +        /*
 59.1030 +         * Index run[i] is the start of i-th run
 59.1031 +         * (ascending or descending sequence).
 59.1032 +         */
 59.1033 +        int[] run = new int[MAX_RUN_COUNT + 1];
 59.1034 +        int count = 0; run[0] = left;
 59.1035 +
 59.1036 +        // Check if the array is nearly sorted
 59.1037 +        for (int k = left; k < right; run[count] = k) {
 59.1038 +            if (a[k] < a[k + 1]) { // ascending
 59.1039 +                while (++k <= right && a[k - 1] <= a[k]);
 59.1040 +            } else if (a[k] > a[k + 1]) { // descending
 59.1041 +                while (++k <= right && a[k - 1] >= a[k]);
 59.1042 +                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
 59.1043 +                    short t = a[lo]; a[lo] = a[hi]; a[hi] = t;
 59.1044 +                }
 59.1045 +            } else { // equal
 59.1046 +                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
 59.1047 +                    if (--m == 0) {
 59.1048 +                        sort(a, left, right, true);
 59.1049 +                        return;
 59.1050 +                    }
 59.1051 +                }
 59.1052 +            }
 59.1053 +
 59.1054 +            /*
 59.1055 +             * The array is not highly structured,
 59.1056 +             * use Quicksort instead of merge sort.
 59.1057 +             */
 59.1058 +            if (++count == MAX_RUN_COUNT) {
 59.1059 +                sort(a, left, right, true);
 59.1060 +                return;
 59.1061 +            }
 59.1062 +        }
 59.1063 +
 59.1064 +        // Check special cases
 59.1065 +        if (run[count] == right++) { // The last run contains one element
 59.1066 +            run[++count] = right;
 59.1067 +        } else if (count == 1) { // The array is already sorted
 59.1068 +            return;
 59.1069 +        }
 59.1070 +
 59.1071 +        /*
 59.1072 +         * Create temporary array, which is used for merging.
 59.1073 +         * Implementation note: variable "right" is increased by 1.
 59.1074 +         */
 59.1075 +        short[] b; byte odd = 0;
 59.1076 +        for (int n = 1; (n <<= 1) < count; odd ^= 1);
 59.1077 +
 59.1078 +        if (odd == 0) {
 59.1079 +            b = a; a = new short[b.length];
 59.1080 +            for (int i = left - 1; ++i < right; a[i] = b[i]);
 59.1081 +        } else {
 59.1082 +            b = new short[a.length];
 59.1083 +        }
 59.1084 +
 59.1085 +        // Merging
 59.1086 +        for (int last; count > 1; count = last) {
 59.1087 +            for (int k = (last = 0) + 2; k <= count; k += 2) {
 59.1088 +                int hi = run[k], mi = run[k - 1];
 59.1089 +                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
 59.1090 +                    if (q >= hi || p < mi && a[p] <= a[q]) {
 59.1091 +                        b[i] = a[p++];
 59.1092 +                    } else {
 59.1093 +                        b[i] = a[q++];
 59.1094 +                    }
 59.1095 +                }
 59.1096 +                run[++last] = hi;
 59.1097 +            }
 59.1098 +            if ((count & 1) != 0) {
 59.1099 +                for (int i = right, lo = run[count - 1]; --i >= lo;
 59.1100 +                    b[i] = a[i]
 59.1101 +                );
 59.1102 +                run[++last] = right;
 59.1103 +            }
 59.1104 +            short[] t = a; a = b; b = t;
 59.1105 +        }
 59.1106 +    }
 59.1107 +
 59.1108 +    /**
 59.1109 +     * Sorts the specified range of the array by Dual-Pivot Quicksort.
 59.1110 +     *
 59.1111 +     * @param a the array to be sorted
 59.1112 +     * @param left the index of the first element, inclusive, to be sorted
 59.1113 +     * @param right the index of the last element, inclusive, to be sorted
 59.1114 +     * @param leftmost indicates if this part is the leftmost in the range
 59.1115 +     */
 59.1116 +    private static void sort(short[] a, int left, int right, boolean leftmost) {
 59.1117 +        int length = right - left + 1;
 59.1118 +
 59.1119 +        // Use insertion sort on tiny arrays
 59.1120 +        if (length < INSERTION_SORT_THRESHOLD) {
 59.1121 +            if (leftmost) {
 59.1122 +                /*
 59.1123 +                 * Traditional (without sentinel) insertion sort,
 59.1124 +                 * optimized for server VM, is used in case of
 59.1125 +                 * the leftmost part.
 59.1126 +                 */
 59.1127 +                for (int i = left, j = i; i < right; j = ++i) {
 59.1128 +                    short ai = a[i + 1];
 59.1129 +                    while (ai < a[j]) {
 59.1130 +                        a[j + 1] = a[j];
 59.1131 +                        if (j-- == left) {
 59.1132 +                            break;
 59.1133 +                        }
 59.1134 +                    }
 59.1135 +                    a[j + 1] = ai;
 59.1136 +                }
 59.1137 +            } else {
 59.1138 +                /*
 59.1139 +                 * Skip the longest ascending sequence.
 59.1140 +                 */
 59.1141 +                do {
 59.1142 +                    if (left >= right) {
 59.1143 +                        return;
 59.1144 +                    }
 59.1145 +                } while (a[++left] >= a[left - 1]);
 59.1146 +
 59.1147 +                /*
 59.1148 +                 * Every element from adjoining part plays the role
 59.1149 +                 * of sentinel, therefore this allows us to avoid the
 59.1150 +                 * left range check on each iteration. Moreover, we use
 59.1151 +                 * the more optimized algorithm, so called pair insertion
 59.1152 +                 * sort, which is faster (in the context of Quicksort)
 59.1153 +                 * than traditional implementation of insertion sort.
 59.1154 +                 */
 59.1155 +                for (int k = left; ++left <= right; k = ++left) {
 59.1156 +                    short a1 = a[k], a2 = a[left];
 59.1157 +
 59.1158 +                    if (a1 < a2) {
 59.1159 +                        a2 = a1; a1 = a[left];
 59.1160 +                    }
 59.1161 +                    while (a1 < a[--k]) {
 59.1162 +                        a[k + 2] = a[k];
 59.1163 +                    }
 59.1164 +                    a[++k + 1] = a1;
 59.1165 +
 59.1166 +                    while (a2 < a[--k]) {
 59.1167 +                        a[k + 1] = a[k];
 59.1168 +                    }
 59.1169 +                    a[k + 1] = a2;
 59.1170 +                }
 59.1171 +                short last = a[right];
 59.1172 +
 59.1173 +                while (last < a[--right]) {
 59.1174 +                    a[right + 1] = a[right];
 59.1175 +                }
 59.1176 +                a[right + 1] = last;
 59.1177 +            }
 59.1178 +            return;
 59.1179 +        }
 59.1180 +
 59.1181 +        // Inexpensive approximation of length / 7
 59.1182 +        int seventh = (length >> 3) + (length >> 6) + 1;
 59.1183 +
 59.1184 +        /*
 59.1185 +         * Sort five evenly spaced elements around (and including) the
 59.1186 +         * center element in the range. These elements will be used for
 59.1187 +         * pivot selection as described below. The choice for spacing
 59.1188 +         * these elements was empirically determined to work well on
 59.1189 +         * a wide variety of inputs.
 59.1190 +         */
 59.1191 +        int e3 = (left + right) >>> 1; // The midpoint
 59.1192 +        int e2 = e3 - seventh;
 59.1193 +        int e1 = e2 - seventh;
 59.1194 +        int e4 = e3 + seventh;
 59.1195 +        int e5 = e4 + seventh;
 59.1196 +
 59.1197 +        // Sort these elements using insertion sort
 59.1198 +        if (a[e2] < a[e1]) { short t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 59.1199 +
 59.1200 +        if (a[e3] < a[e2]) { short t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 59.1201 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 59.1202 +        }
 59.1203 +        if (a[e4] < a[e3]) { short t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 59.1204 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 59.1205 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 59.1206 +            }
 59.1207 +        }
 59.1208 +        if (a[e5] < a[e4]) { short t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 59.1209 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 59.1210 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 59.1211 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 59.1212 +                }
 59.1213 +            }
 59.1214 +        }
 59.1215 +
 59.1216 +        // Pointers
 59.1217 +        int less  = left;  // The index of the first element of center part
 59.1218 +        int great = right; // The index before the first element of right part
 59.1219 +
 59.1220 +        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
 59.1221 +            /*
 59.1222 +             * Use the second and fourth of the five sorted elements as pivots.
 59.1223 +             * These values are inexpensive approximations of the first and
 59.1224 +             * second terciles of the array. Note that pivot1 <= pivot2.
 59.1225 +             */
 59.1226 +            short pivot1 = a[e2];
 59.1227 +            short pivot2 = a[e4];
 59.1228 +
 59.1229 +            /*
 59.1230 +             * The first and the last elements to be sorted are moved to the
 59.1231 +             * locations formerly occupied by the pivots. When partitioning
 59.1232 +             * is complete, the pivots are swapped back into their final
 59.1233 +             * positions, and excluded from subsequent sorting.
 59.1234 +             */
 59.1235 +            a[e2] = a[left];
 59.1236 +            a[e4] = a[right];
 59.1237 +
 59.1238 +            /*
 59.1239 +             * Skip elements, which are less or greater than pivot values.
 59.1240 +             */
 59.1241 +            while (a[++less] < pivot1);
 59.1242 +            while (a[--great] > pivot2);
 59.1243 +
 59.1244 +            /*
 59.1245 +             * Partitioning:
 59.1246 +             *
 59.1247 +             *   left part           center part                   right part
 59.1248 +             * +--------------------------------------------------------------+
 59.1249 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 59.1250 +             * +--------------------------------------------------------------+
 59.1251 +             *               ^                          ^       ^
 59.1252 +             *               |                          |       |
 59.1253 +             *              less                        k     great
 59.1254 +             *
 59.1255 +             * Invariants:
 59.1256 +             *
 59.1257 +             *              all in (left, less)   < pivot1
 59.1258 +             *    pivot1 <= all in [less, k)     <= pivot2
 59.1259 +             *              all in (great, right) > pivot2
 59.1260 +             *
 59.1261 +             * Pointer k is the first index of ?-part.
 59.1262 +             */
 59.1263 +            outer:
 59.1264 +            for (int k = less - 1; ++k <= great; ) {
 59.1265 +                short ak = a[k];
 59.1266 +                if (ak < pivot1) { // Move a[k] to left part
 59.1267 +                    a[k] = a[less];
 59.1268 +                    /*
 59.1269 +                     * Here and below we use "a[i] = b; i++;" instead
 59.1270 +                     * of "a[i++] = b;" due to performance issue.
 59.1271 +                     */
 59.1272 +                    a[less] = ak;
 59.1273 +                    ++less;
 59.1274 +                } else if (ak > pivot2) { // Move a[k] to right part
 59.1275 +                    while (a[great] > pivot2) {
 59.1276 +                        if (great-- == k) {
 59.1277 +                            break outer;
 59.1278 +                        }
 59.1279 +                    }
 59.1280 +                    if (a[great] < pivot1) { // a[great] <= pivot2
 59.1281 +                        a[k] = a[less];
 59.1282 +                        a[less] = a[great];
 59.1283 +                        ++less;
 59.1284 +                    } else { // pivot1 <= a[great] <= pivot2
 59.1285 +                        a[k] = a[great];
 59.1286 +                    }
 59.1287 +                    /*
 59.1288 +                     * Here and below we use "a[i] = b; i--;" instead
 59.1289 +                     * of "a[i--] = b;" due to performance issue.
 59.1290 +                     */
 59.1291 +                    a[great] = ak;
 59.1292 +                    --great;
 59.1293 +                }
 59.1294 +            }
 59.1295 +
 59.1296 +            // Swap pivots into their final positions
 59.1297 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 59.1298 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
 59.1299 +
 59.1300 +            // Sort left and right parts recursively, excluding known pivots
 59.1301 +            sort(a, left, less - 2, leftmost);
 59.1302 +            sort(a, great + 2, right, false);
 59.1303 +
 59.1304 +            /*
 59.1305 +             * If center part is too large (comprises > 4/7 of the array),
 59.1306 +             * swap internal pivot values to ends.
 59.1307 +             */
 59.1308 +            if (less < e1 && e5 < great) {
 59.1309 +                /*
 59.1310 +                 * Skip elements, which are equal to pivot values.
 59.1311 +                 */
 59.1312 +                while (a[less] == pivot1) {
 59.1313 +                    ++less;
 59.1314 +                }
 59.1315 +
 59.1316 +                while (a[great] == pivot2) {
 59.1317 +                    --great;
 59.1318 +                }
 59.1319 +
 59.1320 +                /*
 59.1321 +                 * Partitioning:
 59.1322 +                 *
 59.1323 +                 *   left part         center part                  right part
 59.1324 +                 * +----------------------------------------------------------+
 59.1325 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 59.1326 +                 * +----------------------------------------------------------+
 59.1327 +                 *              ^                        ^       ^
 59.1328 +                 *              |                        |       |
 59.1329 +                 *             less                      k     great
 59.1330 +                 *
 59.1331 +                 * Invariants:
 59.1332 +                 *
 59.1333 +                 *              all in (*,  less) == pivot1
 59.1334 +                 *     pivot1 < all in [less,  k)  < pivot2
 59.1335 +                 *              all in (great, *) == pivot2
 59.1336 +                 *
 59.1337 +                 * Pointer k is the first index of ?-part.
 59.1338 +                 */
 59.1339 +                outer:
 59.1340 +                for (int k = less - 1; ++k <= great; ) {
 59.1341 +                    short ak = a[k];
 59.1342 +                    if (ak == pivot1) { // Move a[k] to left part
 59.1343 +                        a[k] = a[less];
 59.1344 +                        a[less] = ak;
 59.1345 +                        ++less;
 59.1346 +                    } else if (ak == pivot2) { // Move a[k] to right part
 59.1347 +                        while (a[great] == pivot2) {
 59.1348 +                            if (great-- == k) {
 59.1349 +                                break outer;
 59.1350 +                            }
 59.1351 +                        }
 59.1352 +                        if (a[great] == pivot1) { // a[great] < pivot2
 59.1353 +                            a[k] = a[less];
 59.1354 +                            /*
 59.1355 +                             * Even though a[great] equals to pivot1, the
 59.1356 +                             * assignment a[less] = pivot1 may be incorrect,
 59.1357 +                             * if a[great] and pivot1 are floating-point zeros
 59.1358 +                             * of different signs. Therefore in float and
 59.1359 +                             * double sorting methods we have to use more
 59.1360 +                             * accurate assignment a[less] = a[great].
 59.1361 +                             */
 59.1362 +                            a[less] = pivot1;
 59.1363 +                            ++less;
 59.1364 +                        } else { // pivot1 < a[great] < pivot2
 59.1365 +                            a[k] = a[great];
 59.1366 +                        }
 59.1367 +                        a[great] = ak;
 59.1368 +                        --great;
 59.1369 +                    }
 59.1370 +                }
 59.1371 +            }
 59.1372 +
 59.1373 +            // Sort center part recursively
 59.1374 +            sort(a, less, great, false);
 59.1375 +
 59.1376 +        } else { // Partitioning with one pivot
 59.1377 +            /*
 59.1378 +             * Use the third of the five sorted elements as pivot.
 59.1379 +             * This value is inexpensive approximation of the median.
 59.1380 +             */
 59.1381 +            short pivot = a[e3];
 59.1382 +
 59.1383 +            /*
 59.1384 +             * Partitioning degenerates to the traditional 3-way
 59.1385 +             * (or "Dutch National Flag") schema:
 59.1386 +             *
 59.1387 +             *   left part    center part              right part
 59.1388 +             * +-------------------------------------------------+
 59.1389 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 59.1390 +             * +-------------------------------------------------+
 59.1391 +             *              ^              ^        ^
 59.1392 +             *              |              |        |
 59.1393 +             *             less            k      great
 59.1394 +             *
 59.1395 +             * Invariants:
 59.1396 +             *
 59.1397 +             *   all in (left, less)   < pivot
 59.1398 +             *   all in [less, k)     == pivot
 59.1399 +             *   all in (great, right) > pivot
 59.1400 +             *
 59.1401 +             * Pointer k is the first index of ?-part.
 59.1402 +             */
 59.1403 +            for (int k = less; k <= great; ++k) {
 59.1404 +                if (a[k] == pivot) {
 59.1405 +                    continue;
 59.1406 +                }
 59.1407 +                short ak = a[k];
 59.1408 +                if (ak < pivot) { // Move a[k] to left part
 59.1409 +                    a[k] = a[less];
 59.1410 +                    a[less] = ak;
 59.1411 +                    ++less;
 59.1412 +                } else { // a[k] > pivot - Move a[k] to right part
 59.1413 +                    while (a[great] > pivot) {
 59.1414 +                        --great;
 59.1415 +                    }
 59.1416 +                    if (a[great] < pivot) { // a[great] <= pivot
 59.1417 +                        a[k] = a[less];
 59.1418 +                        a[less] = a[great];
 59.1419 +                        ++less;
 59.1420 +                    } else { // a[great] == pivot
 59.1421 +                        /*
 59.1422 +                         * Even though a[great] equals to pivot, the
 59.1423 +                         * assignment a[k] = pivot may be incorrect,
 59.1424 +                         * if a[great] and pivot are floating-point
 59.1425 +                         * zeros of different signs. Therefore in float
 59.1426 +                         * and double sorting methods we have to use
 59.1427 +                         * more accurate assignment a[k] = a[great].
 59.1428 +                         */
 59.1429 +                        a[k] = pivot;
 59.1430 +                    }
 59.1431 +                    a[great] = ak;
 59.1432 +                    --great;
 59.1433 +                }
 59.1434 +            }
 59.1435 +
 59.1436 +            /*
 59.1437 +             * Sort left and right parts recursively.
 59.1438 +             * All elements from center part are equal
 59.1439 +             * and, therefore, already sorted.
 59.1440 +             */
 59.1441 +            sort(a, left, less - 1, leftmost);
 59.1442 +            sort(a, great + 1, right, false);
 59.1443 +        }
 59.1444 +    }
 59.1445 +
 59.1446 +    /**
 59.1447 +     * Sorts the specified array.
 59.1448 +     *
 59.1449 +     * @param a the array to be sorted
 59.1450 +     */
 59.1451 +    public static void sort(char[] a) {
 59.1452 +        sort(a, 0, a.length - 1);
 59.1453 +    }
 59.1454 +
 59.1455 +    /**
 59.1456 +     * Sorts the specified range of the array.
 59.1457 +     *
 59.1458 +     * @param a the array to be sorted
 59.1459 +     * @param left the index of the first element, inclusive, to be sorted
 59.1460 +     * @param right the index of the last element, inclusive, to be sorted
 59.1461 +     */
 59.1462 +    public static void sort(char[] a, int left, int right) {
 59.1463 +        // Use counting sort on large arrays
 59.1464 +        if (right - left > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
 59.1465 +            int[] count = new int[NUM_CHAR_VALUES];
 59.1466 +
 59.1467 +            for (int i = left - 1; ++i <= right;
 59.1468 +                count[a[i]]++
 59.1469 +            );
 59.1470 +            for (int i = NUM_CHAR_VALUES, k = right + 1; k > left; ) {
 59.1471 +                while (count[--i] == 0);
 59.1472 +                char value = (char) i;
 59.1473 +                int s = count[i];
 59.1474 +
 59.1475 +                do {
 59.1476 +                    a[--k] = value;
 59.1477 +                } while (--s > 0);
 59.1478 +            }
 59.1479 +        } else { // Use Dual-Pivot Quicksort on small arrays
 59.1480 +            doSort(a, left, right);
 59.1481 +        }
 59.1482 +    }
 59.1483 +
 59.1484 +    /** The number of distinct char values. */
 59.1485 +    private static final int NUM_CHAR_VALUES = 1 << 16;
 59.1486 +
 59.1487 +    /**
 59.1488 +     * Sorts the specified range of the array.
 59.1489 +     *
 59.1490 +     * @param a the array to be sorted
 59.1491 +     * @param left the index of the first element, inclusive, to be sorted
 59.1492 +     * @param right the index of the last element, inclusive, to be sorted
 59.1493 +     */
 59.1494 +    private static void doSort(char[] a, int left, int right) {
 59.1495 +        // Use Quicksort on small arrays
 59.1496 +        if (right - left < QUICKSORT_THRESHOLD) {
 59.1497 +            sort(a, left, right, true);
 59.1498 +            return;
 59.1499 +        }
 59.1500 +
 59.1501 +        /*
 59.1502 +         * Index run[i] is the start of i-th run
 59.1503 +         * (ascending or descending sequence).
 59.1504 +         */
 59.1505 +        int[] run = new int[MAX_RUN_COUNT + 1];
 59.1506 +        int count = 0; run[0] = left;
 59.1507 +
 59.1508 +        // Check if the array is nearly sorted
 59.1509 +        for (int k = left; k < right; run[count] = k) {
 59.1510 +            if (a[k] < a[k + 1]) { // ascending
 59.1511 +                while (++k <= right && a[k - 1] <= a[k]);
 59.1512 +            } else if (a[k] > a[k + 1]) { // descending
 59.1513 +                while (++k <= right && a[k - 1] >= a[k]);
 59.1514 +                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
 59.1515 +                    char t = a[lo]; a[lo] = a[hi]; a[hi] = t;
 59.1516 +                }
 59.1517 +            } else { // equal
 59.1518 +                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
 59.1519 +                    if (--m == 0) {
 59.1520 +                        sort(a, left, right, true);
 59.1521 +                        return;
 59.1522 +                    }
 59.1523 +                }
 59.1524 +            }
 59.1525 +
 59.1526 +            /*
 59.1527 +             * The array is not highly structured,
 59.1528 +             * use Quicksort instead of merge sort.
 59.1529 +             */
 59.1530 +            if (++count == MAX_RUN_COUNT) {
 59.1531 +                sort(a, left, right, true);
 59.1532 +                return;
 59.1533 +            }
 59.1534 +        }
 59.1535 +
 59.1536 +        // Check special cases
 59.1537 +        if (run[count] == right++) { // The last run contains one element
 59.1538 +            run[++count] = right;
 59.1539 +        } else if (count == 1) { // The array is already sorted
 59.1540 +            return;
 59.1541 +        }
 59.1542 +
 59.1543 +        /*
 59.1544 +         * Create temporary array, which is used for merging.
 59.1545 +         * Implementation note: variable "right" is increased by 1.
 59.1546 +         */
 59.1547 +        char[] b; byte odd = 0;
 59.1548 +        for (int n = 1; (n <<= 1) < count; odd ^= 1);
 59.1549 +
 59.1550 +        if (odd == 0) {
 59.1551 +            b = a; a = new char[b.length];
 59.1552 +            for (int i = left - 1; ++i < right; a[i] = b[i]);
 59.1553 +        } else {
 59.1554 +            b = new char[a.length];
 59.1555 +        }
 59.1556 +
 59.1557 +        // Merging
 59.1558 +        for (int last; count > 1; count = last) {
 59.1559 +            for (int k = (last = 0) + 2; k <= count; k += 2) {
 59.1560 +                int hi = run[k], mi = run[k - 1];
 59.1561 +                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
 59.1562 +                    if (q >= hi || p < mi && a[p] <= a[q]) {
 59.1563 +                        b[i] = a[p++];
 59.1564 +                    } else {
 59.1565 +                        b[i] = a[q++];
 59.1566 +                    }
 59.1567 +                }
 59.1568 +                run[++last] = hi;
 59.1569 +            }
 59.1570 +            if ((count & 1) != 0) {
 59.1571 +                for (int i = right, lo = run[count - 1]; --i >= lo;
 59.1572 +                    b[i] = a[i]
 59.1573 +                );
 59.1574 +                run[++last] = right;
 59.1575 +            }
 59.1576 +            char[] t = a; a = b; b = t;
 59.1577 +        }
 59.1578 +    }
 59.1579 +
 59.1580 +    /**
 59.1581 +     * Sorts the specified range of the array by Dual-Pivot Quicksort.
 59.1582 +     *
 59.1583 +     * @param a the array to be sorted
 59.1584 +     * @param left the index of the first element, inclusive, to be sorted
 59.1585 +     * @param right the index of the last element, inclusive, to be sorted
 59.1586 +     * @param leftmost indicates if this part is the leftmost in the range
 59.1587 +     */
 59.1588 +    private static void sort(char[] a, int left, int right, boolean leftmost) {
 59.1589 +        int length = right - left + 1;
 59.1590 +
 59.1591 +        // Use insertion sort on tiny arrays
 59.1592 +        if (length < INSERTION_SORT_THRESHOLD) {
 59.1593 +            if (leftmost) {
 59.1594 +                /*
 59.1595 +                 * Traditional (without sentinel) insertion sort,
 59.1596 +                 * optimized for server VM, is used in case of
 59.1597 +                 * the leftmost part.
 59.1598 +                 */
 59.1599 +                for (int i = left, j = i; i < right; j = ++i) {
 59.1600 +                    char ai = a[i + 1];
 59.1601 +                    while (ai < a[j]) {
 59.1602 +                        a[j + 1] = a[j];
 59.1603 +                        if (j-- == left) {
 59.1604 +                            break;
 59.1605 +                        }
 59.1606 +                    }
 59.1607 +                    a[j + 1] = ai;
 59.1608 +                }
 59.1609 +            } else {
 59.1610 +                /*
 59.1611 +                 * Skip the longest ascending sequence.
 59.1612 +                 */
 59.1613 +                do {
 59.1614 +                    if (left >= right) {
 59.1615 +                        return;
 59.1616 +                    }
 59.1617 +                } while (a[++left] >= a[left - 1]);
 59.1618 +
 59.1619 +                /*
 59.1620 +                 * Every element from adjoining part plays the role
 59.1621 +                 * of sentinel, therefore this allows us to avoid the
 59.1622 +                 * left range check on each iteration. Moreover, we use
 59.1623 +                 * the more optimized algorithm, so called pair insertion
 59.1624 +                 * sort, which is faster (in the context of Quicksort)
 59.1625 +                 * than traditional implementation of insertion sort.
 59.1626 +                 */
 59.1627 +                for (int k = left; ++left <= right; k = ++left) {
 59.1628 +                    char a1 = a[k], a2 = a[left];
 59.1629 +
 59.1630 +                    if (a1 < a2) {
 59.1631 +                        a2 = a1; a1 = a[left];
 59.1632 +                    }
 59.1633 +                    while (a1 < a[--k]) {
 59.1634 +                        a[k + 2] = a[k];
 59.1635 +                    }
 59.1636 +                    a[++k + 1] = a1;
 59.1637 +
 59.1638 +                    while (a2 < a[--k]) {
 59.1639 +                        a[k + 1] = a[k];
 59.1640 +                    }
 59.1641 +                    a[k + 1] = a2;
 59.1642 +                }
 59.1643 +                char last = a[right];
 59.1644 +
 59.1645 +                while (last < a[--right]) {
 59.1646 +                    a[right + 1] = a[right];
 59.1647 +                }
 59.1648 +                a[right + 1] = last;
 59.1649 +            }
 59.1650 +            return;
 59.1651 +        }
 59.1652 +
 59.1653 +        // Inexpensive approximation of length / 7
 59.1654 +        int seventh = (length >> 3) + (length >> 6) + 1;
 59.1655 +
 59.1656 +        /*
 59.1657 +         * Sort five evenly spaced elements around (and including) the
 59.1658 +         * center element in the range. These elements will be used for
 59.1659 +         * pivot selection as described below. The choice for spacing
 59.1660 +         * these elements was empirically determined to work well on
 59.1661 +         * a wide variety of inputs.
 59.1662 +         */
 59.1663 +        int e3 = (left + right) >>> 1; // The midpoint
 59.1664 +        int e2 = e3 - seventh;
 59.1665 +        int e1 = e2 - seventh;
 59.1666 +        int e4 = e3 + seventh;
 59.1667 +        int e5 = e4 + seventh;
 59.1668 +
 59.1669 +        // Sort these elements using insertion sort
 59.1670 +        if (a[e2] < a[e1]) { char t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 59.1671 +
 59.1672 +        if (a[e3] < a[e2]) { char t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 59.1673 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 59.1674 +        }
 59.1675 +        if (a[e4] < a[e3]) { char t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 59.1676 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 59.1677 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 59.1678 +            }
 59.1679 +        }
 59.1680 +        if (a[e5] < a[e4]) { char t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 59.1681 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 59.1682 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 59.1683 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 59.1684 +                }
 59.1685 +            }
 59.1686 +        }
 59.1687 +
 59.1688 +        // Pointers
 59.1689 +        int less  = left;  // The index of the first element of center part
 59.1690 +        int great = right; // The index before the first element of right part
 59.1691 +
 59.1692 +        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
 59.1693 +            /*
 59.1694 +             * Use the second and fourth of the five sorted elements as pivots.
 59.1695 +             * These values are inexpensive approximations of the first and
 59.1696 +             * second terciles of the array. Note that pivot1 <= pivot2.
 59.1697 +             */
 59.1698 +            char pivot1 = a[e2];
 59.1699 +            char pivot2 = a[e4];
 59.1700 +
 59.1701 +            /*
 59.1702 +             * The first and the last elements to be sorted are moved to the
 59.1703 +             * locations formerly occupied by the pivots. When partitioning
 59.1704 +             * is complete, the pivots are swapped back into their final
 59.1705 +             * positions, and excluded from subsequent sorting.
 59.1706 +             */
 59.1707 +            a[e2] = a[left];
 59.1708 +            a[e4] = a[right];
 59.1709 +
 59.1710 +            /*
 59.1711 +             * Skip elements, which are less or greater than pivot values.
 59.1712 +             */
 59.1713 +            while (a[++less] < pivot1);
 59.1714 +            while (a[--great] > pivot2);
 59.1715 +
 59.1716 +            /*
 59.1717 +             * Partitioning:
 59.1718 +             *
 59.1719 +             *   left part           center part                   right part
 59.1720 +             * +--------------------------------------------------------------+
 59.1721 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 59.1722 +             * +--------------------------------------------------------------+
 59.1723 +             *               ^                          ^       ^
 59.1724 +             *               |                          |       |
 59.1725 +             *              less                        k     great
 59.1726 +             *
 59.1727 +             * Invariants:
 59.1728 +             *
 59.1729 +             *              all in (left, less)   < pivot1
 59.1730 +             *    pivot1 <= all in [less, k)     <= pivot2
 59.1731 +             *              all in (great, right) > pivot2
 59.1732 +             *
 59.1733 +             * Pointer k is the first index of ?-part.
 59.1734 +             */
 59.1735 +            outer:
 59.1736 +            for (int k = less - 1; ++k <= great; ) {
 59.1737 +                char ak = a[k];
 59.1738 +                if (ak < pivot1) { // Move a[k] to left part
 59.1739 +                    a[k] = a[less];
 59.1740 +                    /*
 59.1741 +                     * Here and below we use "a[i] = b; i++;" instead
 59.1742 +                     * of "a[i++] = b;" due to performance issue.
 59.1743 +                     */
 59.1744 +                    a[less] = ak;
 59.1745 +                    ++less;
 59.1746 +                } else if (ak > pivot2) { // Move a[k] to right part
 59.1747 +                    while (a[great] > pivot2) {
 59.1748 +                        if (great-- == k) {
 59.1749 +                            break outer;
 59.1750 +                        }
 59.1751 +                    }
 59.1752 +                    if (a[great] < pivot1) { // a[great] <= pivot2
 59.1753 +                        a[k] = a[less];
 59.1754 +                        a[less] = a[great];
 59.1755 +                        ++less;
 59.1756 +                    } else { // pivot1 <= a[great] <= pivot2
 59.1757 +                        a[k] = a[great];
 59.1758 +                    }
 59.1759 +                    /*
 59.1760 +                     * Here and below we use "a[i] = b; i--;" instead
 59.1761 +                     * of "a[i--] = b;" due to performance issue.
 59.1762 +                     */
 59.1763 +                    a[great] = ak;
 59.1764 +                    --great;
 59.1765 +                }
 59.1766 +            }
 59.1767 +
 59.1768 +            // Swap pivots into their final positions
 59.1769 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 59.1770 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
 59.1771 +
 59.1772 +            // Sort left and right parts recursively, excluding known pivots
 59.1773 +            sort(a, left, less - 2, leftmost);
 59.1774 +            sort(a, great + 2, right, false);
 59.1775 +
 59.1776 +            /*
 59.1777 +             * If center part is too large (comprises > 4/7 of the array),
 59.1778 +             * swap internal pivot values to ends.
 59.1779 +             */
 59.1780 +            if (less < e1 && e5 < great) {
 59.1781 +                /*
 59.1782 +                 * Skip elements, which are equal to pivot values.
 59.1783 +                 */
 59.1784 +                while (a[less] == pivot1) {
 59.1785 +                    ++less;
 59.1786 +                }
 59.1787 +
 59.1788 +                while (a[great] == pivot2) {
 59.1789 +                    --great;
 59.1790 +                }
 59.1791 +
 59.1792 +                /*
 59.1793 +                 * Partitioning:
 59.1794 +                 *
 59.1795 +                 *   left part         center part                  right part
 59.1796 +                 * +----------------------------------------------------------+
 59.1797 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 59.1798 +                 * +----------------------------------------------------------+
 59.1799 +                 *              ^                        ^       ^
 59.1800 +                 *              |                        |       |
 59.1801 +                 *             less                      k     great
 59.1802 +                 *
 59.1803 +                 * Invariants:
 59.1804 +                 *
 59.1805 +                 *              all in (*,  less) == pivot1
 59.1806 +                 *     pivot1 < all in [less,  k)  < pivot2
 59.1807 +                 *              all in (great, *) == pivot2
 59.1808 +                 *
 59.1809 +                 * Pointer k is the first index of ?-part.
 59.1810 +                 */
 59.1811 +                outer:
 59.1812 +                for (int k = less - 1; ++k <= great; ) {
 59.1813 +                    char ak = a[k];
 59.1814 +                    if (ak == pivot1) { // Move a[k] to left part
 59.1815 +                        a[k] = a[less];
 59.1816 +                        a[less] = ak;
 59.1817 +                        ++less;
 59.1818 +                    } else if (ak == pivot2) { // Move a[k] to right part
 59.1819 +                        while (a[great] == pivot2) {
 59.1820 +                            if (great-- == k) {
 59.1821 +                                break outer;
 59.1822 +                            }
 59.1823 +                        }
 59.1824 +                        if (a[great] == pivot1) { // a[great] < pivot2
 59.1825 +                            a[k] = a[less];
 59.1826 +                            /*
 59.1827 +                             * Even though a[great] equals to pivot1, the
 59.1828 +                             * assignment a[less] = pivot1 may be incorrect,
 59.1829 +                             * if a[great] and pivot1 are floating-point zeros
 59.1830 +                             * of different signs. Therefore in float and
 59.1831 +                             * double sorting methods we have to use more
 59.1832 +                             * accurate assignment a[less] = a[great].
 59.1833 +                             */
 59.1834 +                            a[less] = pivot1;
 59.1835 +                            ++less;
 59.1836 +                        } else { // pivot1 < a[great] < pivot2
 59.1837 +                            a[k] = a[great];
 59.1838 +                        }
 59.1839 +                        a[great] = ak;
 59.1840 +                        --great;
 59.1841 +                    }
 59.1842 +                }
 59.1843 +            }
 59.1844 +
 59.1845 +            // Sort center part recursively
 59.1846 +            sort(a, less, great, false);
 59.1847 +
 59.1848 +        } else { // Partitioning with one pivot
 59.1849 +            /*
 59.1850 +             * Use the third of the five sorted elements as pivot.
 59.1851 +             * This value is inexpensive approximation of the median.
 59.1852 +             */
 59.1853 +            char pivot = a[e3];
 59.1854 +
 59.1855 +            /*
 59.1856 +             * Partitioning degenerates to the traditional 3-way
 59.1857 +             * (or "Dutch National Flag") schema:
 59.1858 +             *
 59.1859 +             *   left part    center part              right part
 59.1860 +             * +-------------------------------------------------+
 59.1861 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 59.1862 +             * +-------------------------------------------------+
 59.1863 +             *              ^              ^        ^
 59.1864 +             *              |              |        |
 59.1865 +             *             less            k      great
 59.1866 +             *
 59.1867 +             * Invariants:
 59.1868 +             *
 59.1869 +             *   all in (left, less)   < pivot
 59.1870 +             *   all in [less, k)     == pivot
 59.1871 +             *   all in (great, right) > pivot
 59.1872 +             *
 59.1873 +             * Pointer k is the first index of ?-part.
 59.1874 +             */
 59.1875 +            for (int k = less; k <= great; ++k) {
 59.1876 +                if (a[k] == pivot) {
 59.1877 +                    continue;
 59.1878 +                }
 59.1879 +                char ak = a[k];
 59.1880 +                if (ak < pivot) { // Move a[k] to left part
 59.1881 +                    a[k] = a[less];
 59.1882 +                    a[less] = ak;
 59.1883 +                    ++less;
 59.1884 +                } else { // a[k] > pivot - Move a[k] to right part
 59.1885 +                    while (a[great] > pivot) {
 59.1886 +                        --great;
 59.1887 +                    }
 59.1888 +                    if (a[great] < pivot) { // a[great] <= pivot
 59.1889 +                        a[k] = a[less];
 59.1890 +                        a[less] = a[great];
 59.1891 +                        ++less;
 59.1892 +                    } else { // a[great] == pivot
 59.1893 +                        /*
 59.1894 +                         * Even though a[great] equals to pivot, the
 59.1895 +                         * assignment a[k] = pivot may be incorrect,
 59.1896 +                         * if a[great] and pivot are floating-point
 59.1897 +                         * zeros of different signs. Therefore in float
 59.1898 +                         * and double sorting methods we have to use
 59.1899 +                         * more accurate assignment a[k] = a[great].
 59.1900 +                         */
 59.1901 +                        a[k] = pivot;
 59.1902 +                    }
 59.1903 +                    a[great] = ak;
 59.1904 +                    --great;
 59.1905 +                }
 59.1906 +            }
 59.1907 +
 59.1908 +            /*
 59.1909 +             * Sort left and right parts recursively.
 59.1910 +             * All elements from center part are equal
 59.1911 +             * and, therefore, already sorted.
 59.1912 +             */
 59.1913 +            sort(a, left, less - 1, leftmost);
 59.1914 +            sort(a, great + 1, right, false);
 59.1915 +        }
 59.1916 +    }
 59.1917 +
 59.1918 +    /** The number of distinct byte values. */
 59.1919 +    private static final int NUM_BYTE_VALUES = 1 << 8;
 59.1920 +
 59.1921 +    /**
 59.1922 +     * Sorts the specified array.
 59.1923 +     *
 59.1924 +     * @param a the array to be sorted
 59.1925 +     */
 59.1926 +    public static void sort(byte[] a) {
 59.1927 +        sort(a, 0, a.length - 1);
 59.1928 +    }
 59.1929 +
 59.1930 +    /**
 59.1931 +     * Sorts the specified range of the array.
 59.1932 +     *
 59.1933 +     * @param a the array to be sorted
 59.1934 +     * @param left the index of the first element, inclusive, to be sorted
 59.1935 +     * @param right the index of the last element, inclusive, to be sorted
 59.1936 +     */
 59.1937 +    public static void sort(byte[] a, int left, int right) {
 59.1938 +        // Use counting sort on large arrays
 59.1939 +        if (right - left > COUNTING_SORT_THRESHOLD_FOR_BYTE) {
 59.1940 +            int[] count = new int[NUM_BYTE_VALUES];
 59.1941 +
 59.1942 +            for (int i = left - 1; ++i <= right;
 59.1943 +                count[a[i] - Byte.MIN_VALUE]++
 59.1944 +            );
 59.1945 +            for (int i = NUM_BYTE_VALUES, k = right + 1; k > left; ) {
 59.1946 +                while (count[--i] == 0);
 59.1947 +                byte value = (byte) (i + Byte.MIN_VALUE);
 59.1948 +                int s = count[i];
 59.1949 +
 59.1950 +                do {
 59.1951 +                    a[--k] = value;
 59.1952 +                } while (--s > 0);
 59.1953 +            }
 59.1954 +        } else { // Use insertion sort on small arrays
 59.1955 +            for (int i = left, j = i; i < right; j = ++i) {
 59.1956 +                byte ai = a[i + 1];
 59.1957 +                while (ai < a[j]) {
 59.1958 +                    a[j + 1] = a[j];
 59.1959 +                    if (j-- == left) {
 59.1960 +                        break;
 59.1961 +                    }
 59.1962 +                }
 59.1963 +                a[j + 1] = ai;
 59.1964 +            }
 59.1965 +        }
 59.1966 +    }
 59.1967 +
 59.1968 +    /**
 59.1969 +     * Sorts the specified array.
 59.1970 +     *
 59.1971 +     * @param a the array to be sorted
 59.1972 +     */
 59.1973 +    public static void sort(float[] a) {
 59.1974 +        sort(a, 0, a.length - 1);
 59.1975 +    }
 59.1976 +
 59.1977 +    /**
 59.1978 +     * Sorts the specified range of the array.
 59.1979 +     *
 59.1980 +     * @param a the array to be sorted
 59.1981 +     * @param left the index of the first element, inclusive, to be sorted
 59.1982 +     * @param right the index of the last element, inclusive, to be sorted
 59.1983 +     */
 59.1984 +    public static void sort(float[] a, int left, int right) {
 59.1985 +        /*
 59.1986 +         * Phase 1: Move NaNs to the end of the array.
 59.1987 +         */
 59.1988 +        while (left <= right && Float.isNaN(a[right])) {
 59.1989 +            --right;
 59.1990 +        }
 59.1991 +        for (int k = right; --k >= left; ) {
 59.1992 +            float ak = a[k];
 59.1993 +            if (ak != ak) { // a[k] is NaN
 59.1994 +                a[k] = a[right];
 59.1995 +                a[right] = ak;
 59.1996 +                --right;
 59.1997 +            }
 59.1998 +        }
 59.1999 +
 59.2000 +        /*
 59.2001 +         * Phase 2: Sort everything except NaNs (which are already in place).
 59.2002 +         */
 59.2003 +        doSort(a, left, right);
 59.2004 +
 59.2005 +        /*
 59.2006 +         * Phase 3: Place negative zeros before positive zeros.
 59.2007 +         */
 59.2008 +        int hi = right;
 59.2009 +
 59.2010 +        /*
 59.2011 +         * Find the first zero, or first positive, or last negative element.
 59.2012 +         */
 59.2013 +        while (left < hi) {
 59.2014 +            int middle = (left + hi) >>> 1;
 59.2015 +            float middleValue = a[middle];
 59.2016 +
 59.2017 +            if (middleValue < 0.0f) {
 59.2018 +                left = middle + 1;
 59.2019 +            } else {
 59.2020 +                hi = middle;
 59.2021 +            }
 59.2022 +        }
 59.2023 +
 59.2024 +        /*
 59.2025 +         * Skip the last negative value (if any) or all leading negative zeros.
 59.2026 +         */
 59.2027 +        while (left <= right && Float.floatToRawIntBits(a[left]) < 0) {
 59.2028 +            ++left;
 59.2029 +        }
 59.2030 +
 59.2031 +        /*
 59.2032 +         * Move negative zeros to the beginning of the sub-range.
 59.2033 +         *
 59.2034 +         * Partitioning:
 59.2035 +         *
 59.2036 +         * +----------------------------------------------------+
 59.2037 +         * |   < 0.0   |   -0.0   |   0.0   |   ?  ( >= 0.0 )   |
 59.2038 +         * +----------------------------------------------------+
 59.2039 +         *              ^          ^         ^
 59.2040 +         *              |          |         |
 59.2041 +         *             left        p         k
 59.2042 +         *
 59.2043 +         * Invariants:
 59.2044 +         *
 59.2045 +         *   all in (*,  left)  <  0.0
 59.2046 +         *   all in [left,  p) == -0.0
 59.2047 +         *   all in [p,     k) ==  0.0
 59.2048 +         *   all in [k, right] >=  0.0
 59.2049 +         *
 59.2050 +         * Pointer k is the first index of ?-part.
 59.2051 +         */
 59.2052 +        for (int k = left, p = left - 1; ++k <= right; ) {
 59.2053 +            float ak = a[k];
 59.2054 +            if (ak != 0.0f) {
 59.2055 +                break;
 59.2056 +            }
 59.2057 +            if (Float.floatToRawIntBits(ak) < 0) { // ak is -0.0f
 59.2058 +                a[k] = 0.0f;
 59.2059 +                a[++p] = -0.0f;
 59.2060 +            }
 59.2061 +        }
 59.2062 +    }
 59.2063 +
 59.2064 +    /**
 59.2065 +     * Sorts the specified range of the array.
 59.2066 +     *
 59.2067 +     * @param a the array to be sorted
 59.2068 +     * @param left the index of the first element, inclusive, to be sorted
 59.2069 +     * @param right the index of the last element, inclusive, to be sorted
 59.2070 +     */
 59.2071 +    private static void doSort(float[] a, int left, int right) {
 59.2072 +        // Use Quicksort on small arrays
 59.2073 +        if (right - left < QUICKSORT_THRESHOLD) {
 59.2074 +            sort(a, left, right, true);
 59.2075 +            return;
 59.2076 +        }
 59.2077 +
 59.2078 +        /*
 59.2079 +         * Index run[i] is the start of i-th run
 59.2080 +         * (ascending or descending sequence).
 59.2081 +         */
 59.2082 +        int[] run = new int[MAX_RUN_COUNT + 1];
 59.2083 +        int count = 0; run[0] = left;
 59.2084 +
 59.2085 +        // Check if the array is nearly sorted
 59.2086 +        for (int k = left; k < right; run[count] = k) {
 59.2087 +            if (a[k] < a[k + 1]) { // ascending
 59.2088 +                while (++k <= right && a[k - 1] <= a[k]);
 59.2089 +            } else if (a[k] > a[k + 1]) { // descending
 59.2090 +                while (++k <= right && a[k - 1] >= a[k]);
 59.2091 +                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
 59.2092 +                    float t = a[lo]; a[lo] = a[hi]; a[hi] = t;
 59.2093 +                }
 59.2094 +            } else { // equal
 59.2095 +                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
 59.2096 +                    if (--m == 0) {
 59.2097 +                        sort(a, left, right, true);
 59.2098 +                        return;
 59.2099 +                    }
 59.2100 +                }
 59.2101 +            }
 59.2102 +
 59.2103 +            /*
 59.2104 +             * The array is not highly structured,
 59.2105 +             * use Quicksort instead of merge sort.
 59.2106 +             */
 59.2107 +            if (++count == MAX_RUN_COUNT) {
 59.2108 +                sort(a, left, right, true);
 59.2109 +                return;
 59.2110 +            }
 59.2111 +        }
 59.2112 +
 59.2113 +        // Check special cases
 59.2114 +        if (run[count] == right++) { // The last run contains one element
 59.2115 +            run[++count] = right;
 59.2116 +        } else if (count == 1) { // The array is already sorted
 59.2117 +            return;
 59.2118 +        }
 59.2119 +
 59.2120 +        /*
 59.2121 +         * Create temporary array, which is used for merging.
 59.2122 +         * Implementation note: variable "right" is increased by 1.
 59.2123 +         */
 59.2124 +        float[] b; byte odd = 0;
 59.2125 +        for (int n = 1; (n <<= 1) < count; odd ^= 1);
 59.2126 +
 59.2127 +        if (odd == 0) {
 59.2128 +            b = a; a = new float[b.length];
 59.2129 +            for (int i = left - 1; ++i < right; a[i] = b[i]);
 59.2130 +        } else {
 59.2131 +            b = new float[a.length];
 59.2132 +        }
 59.2133 +
 59.2134 +        // Merging
 59.2135 +        for (int last; count > 1; count = last) {
 59.2136 +            for (int k = (last = 0) + 2; k <= count; k += 2) {
 59.2137 +                int hi = run[k], mi = run[k - 1];
 59.2138 +                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
 59.2139 +                    if (q >= hi || p < mi && a[p] <= a[q]) {
 59.2140 +                        b[i] = a[p++];
 59.2141 +                    } else {
 59.2142 +                        b[i] = a[q++];
 59.2143 +                    }
 59.2144 +                }
 59.2145 +                run[++last] = hi;
 59.2146 +            }
 59.2147 +            if ((count & 1) != 0) {
 59.2148 +                for (int i = right, lo = run[count - 1]; --i >= lo;
 59.2149 +                    b[i] = a[i]
 59.2150 +                );
 59.2151 +                run[++last] = right;
 59.2152 +            }
 59.2153 +            float[] t = a; a = b; b = t;
 59.2154 +        }
 59.2155 +    }
 59.2156 +
 59.2157 +    /**
 59.2158 +     * Sorts the specified range of the array by Dual-Pivot Quicksort.
 59.2159 +     *
 59.2160 +     * @param a the array to be sorted
 59.2161 +     * @param left the index of the first element, inclusive, to be sorted
 59.2162 +     * @param right the index of the last element, inclusive, to be sorted
 59.2163 +     * @param leftmost indicates if this part is the leftmost in the range
 59.2164 +     */
 59.2165 +    private static void sort(float[] a, int left, int right, boolean leftmost) {
 59.2166 +        int length = right - left + 1;
 59.2167 +
 59.2168 +        // Use insertion sort on tiny arrays
 59.2169 +        if (length < INSERTION_SORT_THRESHOLD) {
 59.2170 +            if (leftmost) {
 59.2171 +                /*
 59.2172 +                 * Traditional (without sentinel) insertion sort,
 59.2173 +                 * optimized for server VM, is used in case of
 59.2174 +                 * the leftmost part.
 59.2175 +                 */
 59.2176 +                for (int i = left, j = i; i < right; j = ++i) {
 59.2177 +                    float ai = a[i + 1];
 59.2178 +                    while (ai < a[j]) {
 59.2179 +                        a[j + 1] = a[j];
 59.2180 +                        if (j-- == left) {
 59.2181 +                            break;
 59.2182 +                        }
 59.2183 +                    }
 59.2184 +                    a[j + 1] = ai;
 59.2185 +                }
 59.2186 +            } else {
 59.2187 +                /*
 59.2188 +                 * Skip the longest ascending sequence.
 59.2189 +                 */
 59.2190 +                do {
 59.2191 +                    if (left >= right) {
 59.2192 +                        return;
 59.2193 +                    }
 59.2194 +                } while (a[++left] >= a[left - 1]);
 59.2195 +
 59.2196 +                /*
 59.2197 +                 * Every element from adjoining part plays the role
 59.2198 +                 * of sentinel, therefore this allows us to avoid the
 59.2199 +                 * left range check on each iteration. Moreover, we use
 59.2200 +                 * the more optimized algorithm, so called pair insertion
 59.2201 +                 * sort, which is faster (in the context of Quicksort)
 59.2202 +                 * than traditional implementation of insertion sort.
 59.2203 +                 */
 59.2204 +                for (int k = left; ++left <= right; k = ++left) {
 59.2205 +                    float a1 = a[k], a2 = a[left];
 59.2206 +
 59.2207 +                    if (a1 < a2) {
 59.2208 +                        a2 = a1; a1 = a[left];
 59.2209 +                    }
 59.2210 +                    while (a1 < a[--k]) {
 59.2211 +                        a[k + 2] = a[k];
 59.2212 +                    }
 59.2213 +                    a[++k + 1] = a1;
 59.2214 +
 59.2215 +                    while (a2 < a[--k]) {
 59.2216 +                        a[k + 1] = a[k];
 59.2217 +                    }
 59.2218 +                    a[k + 1] = a2;
 59.2219 +                }
 59.2220 +                float last = a[right];
 59.2221 +
 59.2222 +                while (last < a[--right]) {
 59.2223 +                    a[right + 1] = a[right];
 59.2224 +                }
 59.2225 +                a[right + 1] = last;
 59.2226 +            }
 59.2227 +            return;
 59.2228 +        }
 59.2229 +
 59.2230 +        // Inexpensive approximation of length / 7
 59.2231 +        int seventh = (length >> 3) + (length >> 6) + 1;
 59.2232 +
 59.2233 +        /*
 59.2234 +         * Sort five evenly spaced elements around (and including) the
 59.2235 +         * center element in the range. These elements will be used for
 59.2236 +         * pivot selection as described below. The choice for spacing
 59.2237 +         * these elements was empirically determined to work well on
 59.2238 +         * a wide variety of inputs.
 59.2239 +         */
 59.2240 +        int e3 = (left + right) >>> 1; // The midpoint
 59.2241 +        int e2 = e3 - seventh;
 59.2242 +        int e1 = e2 - seventh;
 59.2243 +        int e4 = e3 + seventh;
 59.2244 +        int e5 = e4 + seventh;
 59.2245 +
 59.2246 +        // Sort these elements using insertion sort
 59.2247 +        if (a[e2] < a[e1]) { float t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 59.2248 +
 59.2249 +        if (a[e3] < a[e2]) { float t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 59.2250 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 59.2251 +        }
 59.2252 +        if (a[e4] < a[e3]) { float t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 59.2253 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 59.2254 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 59.2255 +            }
 59.2256 +        }
 59.2257 +        if (a[e5] < a[e4]) { float t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 59.2258 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 59.2259 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 59.2260 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 59.2261 +                }
 59.2262 +            }
 59.2263 +        }
 59.2264 +
 59.2265 +        // Pointers
 59.2266 +        int less  = left;  // The index of the first element of center part
 59.2267 +        int great = right; // The index before the first element of right part
 59.2268 +
 59.2269 +        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
 59.2270 +            /*
 59.2271 +             * Use the second and fourth of the five sorted elements as pivots.
 59.2272 +             * These values are inexpensive approximations of the first and
 59.2273 +             * second terciles of the array. Note that pivot1 <= pivot2.
 59.2274 +             */
 59.2275 +            float pivot1 = a[e2];
 59.2276 +            float pivot2 = a[e4];
 59.2277 +
 59.2278 +            /*
 59.2279 +             * The first and the last elements to be sorted are moved to the
 59.2280 +             * locations formerly occupied by the pivots. When partitioning
 59.2281 +             * is complete, the pivots are swapped back into their final
 59.2282 +             * positions, and excluded from subsequent sorting.
 59.2283 +             */
 59.2284 +            a[e2] = a[left];
 59.2285 +            a[e4] = a[right];
 59.2286 +
 59.2287 +            /*
 59.2288 +             * Skip elements, which are less or greater than pivot values.
 59.2289 +             */
 59.2290 +            while (a[++less] < pivot1);
 59.2291 +            while (a[--great] > pivot2);
 59.2292 +
 59.2293 +            /*
 59.2294 +             * Partitioning:
 59.2295 +             *
 59.2296 +             *   left part           center part                   right part
 59.2297 +             * +--------------------------------------------------------------+
 59.2298 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 59.2299 +             * +--------------------------------------------------------------+
 59.2300 +             *               ^                          ^       ^
 59.2301 +             *               |                          |       |
 59.2302 +             *              less                        k     great
 59.2303 +             *
 59.2304 +             * Invariants:
 59.2305 +             *
 59.2306 +             *              all in (left, less)   < pivot1
 59.2307 +             *    pivot1 <= all in [less, k)     <= pivot2
 59.2308 +             *              all in (great, right) > pivot2
 59.2309 +             *
 59.2310 +             * Pointer k is the first index of ?-part.
 59.2311 +             */
 59.2312 +            outer:
 59.2313 +            for (int k = less - 1; ++k <= great; ) {
 59.2314 +                float ak = a[k];
 59.2315 +                if (ak < pivot1) { // Move a[k] to left part
 59.2316 +                    a[k] = a[less];
 59.2317 +                    /*
 59.2318 +                     * Here and below we use "a[i] = b; i++;" instead
 59.2319 +                     * of "a[i++] = b;" due to performance issue.
 59.2320 +                     */
 59.2321 +                    a[less] = ak;
 59.2322 +                    ++less;
 59.2323 +                } else if (ak > pivot2) { // Move a[k] to right part
 59.2324 +                    while (a[great] > pivot2) {
 59.2325 +                        if (great-- == k) {
 59.2326 +                            break outer;
 59.2327 +                        }
 59.2328 +                    }
 59.2329 +                    if (a[great] < pivot1) { // a[great] <= pivot2
 59.2330 +                        a[k] = a[less];
 59.2331 +                        a[less] = a[great];
 59.2332 +                        ++less;
 59.2333 +                    } else { // pivot1 <= a[great] <= pivot2
 59.2334 +                        a[k] = a[great];
 59.2335 +                    }
 59.2336 +                    /*
 59.2337 +                     * Here and below we use "a[i] = b; i--;" instead
 59.2338 +                     * of "a[i--] = b;" due to performance issue.
 59.2339 +                     */
 59.2340 +                    a[great] = ak;
 59.2341 +                    --great;
 59.2342 +                }
 59.2343 +            }
 59.2344 +
 59.2345 +            // Swap pivots into their final positions
 59.2346 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 59.2347 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
 59.2348 +
 59.2349 +            // Sort left and right parts recursively, excluding known pivots
 59.2350 +            sort(a, left, less - 2, leftmost);
 59.2351 +            sort(a, great + 2, right, false);
 59.2352 +
 59.2353 +            /*
 59.2354 +             * If center part is too large (comprises > 4/7 of the array),
 59.2355 +             * swap internal pivot values to ends.
 59.2356 +             */
 59.2357 +            if (less < e1 && e5 < great) {
 59.2358 +                /*
 59.2359 +                 * Skip elements, which are equal to pivot values.
 59.2360 +                 */
 59.2361 +                while (a[less] == pivot1) {
 59.2362 +                    ++less;
 59.2363 +                }
 59.2364 +
 59.2365 +                while (a[great] == pivot2) {
 59.2366 +                    --great;
 59.2367 +                }
 59.2368 +
 59.2369 +                /*
 59.2370 +                 * Partitioning:
 59.2371 +                 *
 59.2372 +                 *   left part         center part                  right part
 59.2373 +                 * +----------------------------------------------------------+
 59.2374 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 59.2375 +                 * +----------------------------------------------------------+
 59.2376 +                 *              ^                        ^       ^
 59.2377 +                 *              |                        |       |
 59.2378 +                 *             less                      k     great
 59.2379 +                 *
 59.2380 +                 * Invariants:
 59.2381 +                 *
 59.2382 +                 *              all in (*,  less) == pivot1
 59.2383 +                 *     pivot1 < all in [less,  k)  < pivot2
 59.2384 +                 *              all in (great, *) == pivot2
 59.2385 +                 *
 59.2386 +                 * Pointer k is the first index of ?-part.
 59.2387 +                 */
 59.2388 +                outer:
 59.2389 +                for (int k = less - 1; ++k <= great; ) {
 59.2390 +                    float ak = a[k];
 59.2391 +                    if (ak == pivot1) { // Move a[k] to left part
 59.2392 +                        a[k] = a[less];
 59.2393 +                        a[less] = ak;
 59.2394 +                        ++less;
 59.2395 +                    } else if (ak == pivot2) { // Move a[k] to right part
 59.2396 +                        while (a[great] == pivot2) {
 59.2397 +                            if (great-- == k) {
 59.2398 +                                break outer;
 59.2399 +                            }
 59.2400 +                        }
 59.2401 +                        if (a[great] == pivot1) { // a[great] < pivot2
 59.2402 +                            a[k] = a[less];
 59.2403 +                            /*
 59.2404 +                             * Even though a[great] equals to pivot1, the
 59.2405 +                             * assignment a[less] = pivot1 may be incorrect,
 59.2406 +                             * if a[great] and pivot1 are floating-point zeros
 59.2407 +                             * of different signs. Therefore in float and
 59.2408 +                             * double sorting methods we have to use more
 59.2409 +                             * accurate assignment a[less] = a[great].
 59.2410 +                             */
 59.2411 +                            a[less] = a[great];
 59.2412 +                            ++less;
 59.2413 +                        } else { // pivot1 < a[great] < pivot2
 59.2414 +                            a[k] = a[great];
 59.2415 +                        }
 59.2416 +                        a[great] = ak;
 59.2417 +                        --great;
 59.2418 +                    }
 59.2419 +                }
 59.2420 +            }
 59.2421 +
 59.2422 +            // Sort center part recursively
 59.2423 +            sort(a, less, great, false);
 59.2424 +
 59.2425 +        } else { // Partitioning with one pivot
 59.2426 +            /*
 59.2427 +             * Use the third of the five sorted elements as pivot.
 59.2428 +             * This value is inexpensive approximation of the median.
 59.2429 +             */
 59.2430 +            float pivot = a[e3];
 59.2431 +
 59.2432 +            /*
 59.2433 +             * Partitioning degenerates to the traditional 3-way
 59.2434 +             * (or "Dutch National Flag") schema:
 59.2435 +             *
 59.2436 +             *   left part    center part              right part
 59.2437 +             * +-------------------------------------------------+
 59.2438 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 59.2439 +             * +-------------------------------------------------+
 59.2440 +             *              ^              ^        ^
 59.2441 +             *              |              |        |
 59.2442 +             *             less            k      great
 59.2443 +             *
 59.2444 +             * Invariants:
 59.2445 +             *
 59.2446 +             *   all in (left, less)   < pivot
 59.2447 +             *   all in [less, k)     == pivot
 59.2448 +             *   all in (great, right) > pivot
 59.2449 +             *
 59.2450 +             * Pointer k is the first index of ?-part.
 59.2451 +             */
 59.2452 +            for (int k = less; k <= great; ++k) {
 59.2453 +                if (a[k] == pivot) {
 59.2454 +                    continue;
 59.2455 +                }
 59.2456 +                float ak = a[k];
 59.2457 +                if (ak < pivot) { // Move a[k] to left part
 59.2458 +                    a[k] = a[less];
 59.2459 +                    a[less] = ak;
 59.2460 +                    ++less;
 59.2461 +                } else { // a[k] > pivot - Move a[k] to right part
 59.2462 +                    while (a[great] > pivot) {
 59.2463 +                        --great;
 59.2464 +                    }
 59.2465 +                    if (a[great] < pivot) { // a[great] <= pivot
 59.2466 +                        a[k] = a[less];
 59.2467 +                        a[less] = a[great];
 59.2468 +                        ++less;
 59.2469 +                    } else { // a[great] == pivot
 59.2470 +                        /*
 59.2471 +                         * Even though a[great] equals to pivot, the
 59.2472 +                         * assignment a[k] = pivot may be incorrect,
 59.2473 +                         * if a[great] and pivot are floating-point
 59.2474 +                         * zeros of different signs. Therefore in float
 59.2475 +                         * and double sorting methods we have to use
 59.2476 +                         * more accurate assignment a[k] = a[great].
 59.2477 +                         */
 59.2478 +                        a[k] = a[great];
 59.2479 +                    }
 59.2480 +                    a[great] = ak;
 59.2481 +                    --great;
 59.2482 +                }
 59.2483 +            }
 59.2484 +
 59.2485 +            /*
 59.2486 +             * Sort left and right parts recursively.
 59.2487 +             * All elements from center part are equal
 59.2488 +             * and, therefore, already sorted.
 59.2489 +             */
 59.2490 +            sort(a, left, less - 1, leftmost);
 59.2491 +            sort(a, great + 1, right, false);
 59.2492 +        }
 59.2493 +    }
 59.2494 +
 59.2495 +    /**
 59.2496 +     * Sorts the specified array.
 59.2497 +     *
 59.2498 +     * @param a the array to be sorted
 59.2499 +     */
 59.2500 +    public static void sort(double[] a) {
 59.2501 +        sort(a, 0, a.length - 1);
 59.2502 +    }
 59.2503 +
 59.2504 +    /**
 59.2505 +     * Sorts the specified range of the array.
 59.2506 +     *
 59.2507 +     * @param a the array to be sorted
 59.2508 +     * @param left the index of the first element, inclusive, to be sorted
 59.2509 +     * @param right the index of the last element, inclusive, to be sorted
 59.2510 +     */
 59.2511 +    public static void sort(double[] a, int left, int right) {
 59.2512 +        /*
 59.2513 +         * Phase 1: Move NaNs to the end of the array.
 59.2514 +         */
 59.2515 +        while (left <= right && Double.isNaN(a[right])) {
 59.2516 +            --right;
 59.2517 +        }
 59.2518 +        for (int k = right; --k >= left; ) {
 59.2519 +            double ak = a[k];
 59.2520 +            if (ak != ak) { // a[k] is NaN
 59.2521 +                a[k] = a[right];
 59.2522 +                a[right] = ak;
 59.2523 +                --right;
 59.2524 +            }
 59.2525 +        }
 59.2526 +
 59.2527 +        /*
 59.2528 +         * Phase 2: Sort everything except NaNs (which are already in place).
 59.2529 +         */
 59.2530 +        doSort(a, left, right);
 59.2531 +
 59.2532 +        /*
 59.2533 +         * Phase 3: Place negative zeros before positive zeros.
 59.2534 +         */
 59.2535 +        int hi = right;
 59.2536 +
 59.2537 +        /*
 59.2538 +         * Find the first zero, or first positive, or last negative element.
 59.2539 +         */
 59.2540 +        while (left < hi) {
 59.2541 +            int middle = (left + hi) >>> 1;
 59.2542 +            double middleValue = a[middle];
 59.2543 +
 59.2544 +            if (middleValue < 0.0d) {
 59.2545 +                left = middle + 1;
 59.2546 +            } else {
 59.2547 +                hi = middle;
 59.2548 +            }
 59.2549 +        }
 59.2550 +
 59.2551 +        /*
 59.2552 +         * Skip the last negative value (if any) or all leading negative zeros.
 59.2553 +         */
 59.2554 +        while (left <= right && Double.doubleToRawLongBits(a[left]) < 0) {
 59.2555 +            ++left;
 59.2556 +        }
 59.2557 +
 59.2558 +        /*
 59.2559 +         * Move negative zeros to the beginning of the sub-range.
 59.2560 +         *
 59.2561 +         * Partitioning:
 59.2562 +         *
 59.2563 +         * +----------------------------------------------------+
 59.2564 +         * |   < 0.0   |   -0.0   |   0.0   |   ?  ( >= 0.0 )   |
 59.2565 +         * +----------------------------------------------------+
 59.2566 +         *              ^          ^         ^
 59.2567 +         *              |          |         |
 59.2568 +         *             left        p         k
 59.2569 +         *
 59.2570 +         * Invariants:
 59.2571 +         *
 59.2572 +         *   all in (*,  left)  <  0.0
 59.2573 +         *   all in [left,  p) == -0.0
 59.2574 +         *   all in [p,     k) ==  0.0
 59.2575 +         *   all in [k, right] >=  0.0
 59.2576 +         *
 59.2577 +         * Pointer k is the first index of ?-part.
 59.2578 +         */
 59.2579 +        for (int k = left, p = left - 1; ++k <= right; ) {
 59.2580 +            double ak = a[k];
 59.2581 +            if (ak != 0.0d) {
 59.2582 +                break;
 59.2583 +            }
 59.2584 +            if (Double.doubleToRawLongBits(ak) < 0) { // ak is -0.0d
 59.2585 +                a[k] = 0.0d;
 59.2586 +                a[++p] = -0.0d;
 59.2587 +            }
 59.2588 +        }
 59.2589 +    }
 59.2590 +
 59.2591 +    /**
 59.2592 +     * Sorts the specified range of the array.
 59.2593 +     *
 59.2594 +     * @param a the array to be sorted
 59.2595 +     * @param left the index of the first element, inclusive, to be sorted
 59.2596 +     * @param right the index of the last element, inclusive, to be sorted
 59.2597 +     */
 59.2598 +    private static void doSort(double[] a, int left, int right) {
 59.2599 +        // Use Quicksort on small arrays
 59.2600 +        if (right - left < QUICKSORT_THRESHOLD) {
 59.2601 +            sort(a, left, right, true);
 59.2602 +            return;
 59.2603 +        }
 59.2604 +
 59.2605 +        /*
 59.2606 +         * Index run[i] is the start of i-th run
 59.2607 +         * (ascending or descending sequence).
 59.2608 +         */
 59.2609 +        int[] run = new int[MAX_RUN_COUNT + 1];
 59.2610 +        int count = 0; run[0] = left;
 59.2611 +
 59.2612 +        // Check if the array is nearly sorted
 59.2613 +        for (int k = left; k < right; run[count] = k) {
 59.2614 +            if (a[k] < a[k + 1]) { // ascending
 59.2615 +                while (++k <= right && a[k - 1] <= a[k]);
 59.2616 +            } else if (a[k] > a[k + 1]) { // descending
 59.2617 +                while (++k <= right && a[k - 1] >= a[k]);
 59.2618 +                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
 59.2619 +                    double t = a[lo]; a[lo] = a[hi]; a[hi] = t;
 59.2620 +                }
 59.2621 +            } else { // equal
 59.2622 +                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
 59.2623 +                    if (--m == 0) {
 59.2624 +                        sort(a, left, right, true);
 59.2625 +                        return;
 59.2626 +                    }
 59.2627 +                }
 59.2628 +            }
 59.2629 +
 59.2630 +            /*
 59.2631 +             * The array is not highly structured,
 59.2632 +             * use Quicksort instead of merge sort.
 59.2633 +             */
 59.2634 +            if (++count == MAX_RUN_COUNT) {
 59.2635 +                sort(a, left, right, true);
 59.2636 +                return;
 59.2637 +            }
 59.2638 +        }
 59.2639 +
 59.2640 +        // Check special cases
 59.2641 +        if (run[count] == right++) { // The last run contains one element
 59.2642 +            run[++count] = right;
 59.2643 +        } else if (count == 1) { // The array is already sorted
 59.2644 +            return;
 59.2645 +        }
 59.2646 +
 59.2647 +        /*
 59.2648 +         * Create temporary array, which is used for merging.
 59.2649 +         * Implementation note: variable "right" is increased by 1.
 59.2650 +         */
 59.2651 +        double[] b; byte odd = 0;
 59.2652 +        for (int n = 1; (n <<= 1) < count; odd ^= 1);
 59.2653 +
 59.2654 +        if (odd == 0) {
 59.2655 +            b = a; a = new double[b.length];
 59.2656 +            for (int i = left - 1; ++i < right; a[i] = b[i]);
 59.2657 +        } else {
 59.2658 +            b = new double[a.length];
 59.2659 +        }
 59.2660 +
 59.2661 +        // Merging
 59.2662 +        for (int last; count > 1; count = last) {
 59.2663 +            for (int k = (last = 0) + 2; k <= count; k += 2) {
 59.2664 +                int hi = run[k], mi = run[k - 1];
 59.2665 +                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
 59.2666 +                    if (q >= hi || p < mi && a[p] <= a[q]) {
 59.2667 +                        b[i] = a[p++];
 59.2668 +                    } else {
 59.2669 +                        b[i] = a[q++];
 59.2670 +                    }
 59.2671 +                }
 59.2672 +                run[++last] = hi;
 59.2673 +            }
 59.2674 +            if ((count & 1) != 0) {
 59.2675 +                for (int i = right, lo = run[count - 1]; --i >= lo;
 59.2676 +                    b[i] = a[i]
 59.2677 +                );
 59.2678 +                run[++last] = right;
 59.2679 +            }
 59.2680 +            double[] t = a; a = b; b = t;
 59.2681 +        }
 59.2682 +    }
 59.2683 +
 59.2684 +    /**
 59.2685 +     * Sorts the specified range of the array by Dual-Pivot Quicksort.
 59.2686 +     *
 59.2687 +     * @param a the array to be sorted
 59.2688 +     * @param left the index of the first element, inclusive, to be sorted
 59.2689 +     * @param right the index of the last element, inclusive, to be sorted
 59.2690 +     * @param leftmost indicates if this part is the leftmost in the range
 59.2691 +     */
 59.2692 +    private static void sort(double[] a, int left, int right, boolean leftmost) {
 59.2693 +        int length = right - left + 1;
 59.2694 +
 59.2695 +        // Use insertion sort on tiny arrays
 59.2696 +        if (length < INSERTION_SORT_THRESHOLD) {
 59.2697 +            if (leftmost) {
 59.2698 +                /*
 59.2699 +                 * Traditional (without sentinel) insertion sort,
 59.2700 +                 * optimized for server VM, is used in case of
 59.2701 +                 * the leftmost part.
 59.2702 +                 */
 59.2703 +                for (int i = left, j = i; i < right; j = ++i) {
 59.2704 +                    double ai = a[i + 1];
 59.2705 +                    while (ai < a[j]) {
 59.2706 +                        a[j + 1] = a[j];
 59.2707 +                        if (j-- == left) {
 59.2708 +                            break;
 59.2709 +                        }
 59.2710 +                    }
 59.2711 +                    a[j + 1] = ai;
 59.2712 +                }
 59.2713 +            } else {
 59.2714 +                /*
 59.2715 +                 * Skip the longest ascending sequence.
 59.2716 +                 */
 59.2717 +                do {
 59.2718 +                    if (left >= right) {
 59.2719 +                        return;
 59.2720 +                    }
 59.2721 +                } while (a[++left] >= a[left - 1]);
 59.2722 +
 59.2723 +                /*
 59.2724 +                 * Every element from adjoining part plays the role
 59.2725 +                 * of sentinel, therefore this allows us to avoid the
 59.2726 +                 * left range check on each iteration. Moreover, we use
 59.2727 +                 * the more optimized algorithm, so called pair insertion
 59.2728 +                 * sort, which is faster (in the context of Quicksort)
 59.2729 +                 * than traditional implementation of insertion sort.
 59.2730 +                 */
 59.2731 +                for (int k = left; ++left <= right; k = ++left) {
 59.2732 +                    double a1 = a[k], a2 = a[left];
 59.2733 +
 59.2734 +                    if (a1 < a2) {
 59.2735 +                        a2 = a1; a1 = a[left];
 59.2736 +                    }
 59.2737 +                    while (a1 < a[--k]) {
 59.2738 +                        a[k + 2] = a[k];
 59.2739 +                    }
 59.2740 +                    a[++k + 1] = a1;
 59.2741 +
 59.2742 +                    while (a2 < a[--k]) {
 59.2743 +                        a[k + 1] = a[k];
 59.2744 +                    }
 59.2745 +                    a[k + 1] = a2;
 59.2746 +                }
 59.2747 +                double last = a[right];
 59.2748 +
 59.2749 +                while (last < a[--right]) {
 59.2750 +                    a[right + 1] = a[right];
 59.2751 +                }
 59.2752 +                a[right + 1] = last;
 59.2753 +            }
 59.2754 +            return;
 59.2755 +        }
 59.2756 +
 59.2757 +        // Inexpensive approximation of length / 7
 59.2758 +        int seventh = (length >> 3) + (length >> 6) + 1;
 59.2759 +
 59.2760 +        /*
 59.2761 +         * Sort five evenly spaced elements around (and including) the
 59.2762 +         * center element in the range. These elements will be used for
 59.2763 +         * pivot selection as described below. The choice for spacing
 59.2764 +         * these elements was empirically determined to work well on
 59.2765 +         * a wide variety of inputs.
 59.2766 +         */
 59.2767 +        int e3 = (left + right) >>> 1; // The midpoint
 59.2768 +        int e2 = e3 - seventh;
 59.2769 +        int e1 = e2 - seventh;
 59.2770 +        int e4 = e3 + seventh;
 59.2771 +        int e5 = e4 + seventh;
 59.2772 +
 59.2773 +        // Sort these elements using insertion sort
 59.2774 +        if (a[e2] < a[e1]) { double t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 59.2775 +
 59.2776 +        if (a[e3] < a[e2]) { double t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 59.2777 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 59.2778 +        }
 59.2779 +        if (a[e4] < a[e3]) { double t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 59.2780 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 59.2781 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 59.2782 +            }
 59.2783 +        }
 59.2784 +        if (a[e5] < a[e4]) { double t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 59.2785 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 59.2786 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 59.2787 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 59.2788 +                }
 59.2789 +            }
 59.2790 +        }
 59.2791 +
 59.2792 +        // Pointers
 59.2793 +        int less  = left;  // The index of the first element of center part
 59.2794 +        int great = right; // The index before the first element of right part
 59.2795 +
 59.2796 +        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
 59.2797 +            /*
 59.2798 +             * Use the second and fourth of the five sorted elements as pivots.
 59.2799 +             * These values are inexpensive approximations of the first and
 59.2800 +             * second terciles of the array. Note that pivot1 <= pivot2.
 59.2801 +             */
 59.2802 +            double pivot1 = a[e2];
 59.2803 +            double pivot2 = a[e4];
 59.2804 +
 59.2805 +            /*
 59.2806 +             * The first and the last elements to be sorted are moved to the
 59.2807 +             * locations formerly occupied by the pivots. When partitioning
 59.2808 +             * is complete, the pivots are swapped back into their final
 59.2809 +             * positions, and excluded from subsequent sorting.
 59.2810 +             */
 59.2811 +            a[e2] = a[left];
 59.2812 +            a[e4] = a[right];
 59.2813 +
 59.2814 +            /*
 59.2815 +             * Skip elements, which are less or greater than pivot values.
 59.2816 +             */
 59.2817 +            while (a[++less] < pivot1);
 59.2818 +            while (a[--great] > pivot2);
 59.2819 +
 59.2820 +            /*
 59.2821 +             * Partitioning:
 59.2822 +             *
 59.2823 +             *   left part           center part                   right part
 59.2824 +             * +--------------------------------------------------------------+
 59.2825 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 59.2826 +             * +--------------------------------------------------------------+
 59.2827 +             *               ^                          ^       ^
 59.2828 +             *               |                          |       |
 59.2829 +             *              less                        k     great
 59.2830 +             *
 59.2831 +             * Invariants:
 59.2832 +             *
 59.2833 +             *              all in (left, less)   < pivot1
 59.2834 +             *    pivot1 <= all in [less, k)     <= pivot2
 59.2835 +             *              all in (great, right) > pivot2
 59.2836 +             *
 59.2837 +             * Pointer k is the first index of ?-part.
 59.2838 +             */
 59.2839 +            outer:
 59.2840 +            for (int k = less - 1; ++k <= great; ) {
 59.2841 +                double ak = a[k];
 59.2842 +                if (ak < pivot1) { // Move a[k] to left part
 59.2843 +                    a[k] = a[less];
 59.2844 +                    /*
 59.2845 +                     * Here and below we use "a[i] = b; i++;" instead
 59.2846 +                     * of "a[i++] = b;" due to performance issue.
 59.2847 +                     */
 59.2848 +                    a[less] = ak;
 59.2849 +                    ++less;
 59.2850 +                } else if (ak > pivot2) { // Move a[k] to right part
 59.2851 +                    while (a[great] > pivot2) {
 59.2852 +                        if (great-- == k) {
 59.2853 +                            break outer;
 59.2854 +                        }
 59.2855 +                    }
 59.2856 +                    if (a[great] < pivot1) { // a[great] <= pivot2
 59.2857 +                        a[k] = a[less];
 59.2858 +                        a[less] = a[great];
 59.2859 +                        ++less;
 59.2860 +                    } else { // pivot1 <= a[great] <= pivot2
 59.2861 +                        a[k] = a[great];
 59.2862 +                    }
 59.2863 +                    /*
 59.2864 +                     * Here and below we use "a[i] = b; i--;" instead
 59.2865 +                     * of "a[i--] = b;" due to performance issue.
 59.2866 +                     */
 59.2867 +                    a[great] = ak;
 59.2868 +                    --great;
 59.2869 +                }
 59.2870 +            }
 59.2871 +
 59.2872 +            // Swap pivots into their final positions
 59.2873 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 59.2874 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
 59.2875 +
 59.2876 +            // Sort left and right parts recursively, excluding known pivots
 59.2877 +            sort(a, left, less - 2, leftmost);
 59.2878 +            sort(a, great + 2, right, false);
 59.2879 +
 59.2880 +            /*
 59.2881 +             * If center part is too large (comprises > 4/7 of the array),
 59.2882 +             * swap internal pivot values to ends.
 59.2883 +             */
 59.2884 +            if (less < e1 && e5 < great) {
 59.2885 +                /*
 59.2886 +                 * Skip elements, which are equal to pivot values.
 59.2887 +                 */
 59.2888 +                while (a[less] == pivot1) {
 59.2889 +                    ++less;
 59.2890 +                }
 59.2891 +
 59.2892 +                while (a[great] == pivot2) {
 59.2893 +                    --great;
 59.2894 +                }
 59.2895 +
 59.2896 +                /*
 59.2897 +                 * Partitioning:
 59.2898 +                 *
 59.2899 +                 *   left part         center part                  right part
 59.2900 +                 * +----------------------------------------------------------+
 59.2901 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 59.2902 +                 * +----------------------------------------------------------+
 59.2903 +                 *              ^                        ^       ^
 59.2904 +                 *              |                        |       |
 59.2905 +                 *             less                      k     great
 59.2906 +                 *
 59.2907 +                 * Invariants:
 59.2908 +                 *
 59.2909 +                 *              all in (*,  less) == pivot1
 59.2910 +                 *     pivot1 < all in [less,  k)  < pivot2
 59.2911 +                 *              all in (great, *) == pivot2
 59.2912 +                 *
 59.2913 +                 * Pointer k is the first index of ?-part.
 59.2914 +                 */
 59.2915 +                outer:
 59.2916 +                for (int k = less - 1; ++k <= great; ) {
 59.2917 +                    double ak = a[k];
 59.2918 +                    if (ak == pivot1) { // Move a[k] to left part
 59.2919 +                        a[k] = a[less];
 59.2920 +                        a[less] = ak;
 59.2921 +                        ++less;
 59.2922 +                    } else if (ak == pivot2) { // Move a[k] to right part
 59.2923 +                        while (a[great] == pivot2) {
 59.2924 +                            if (great-- == k) {
 59.2925 +                                break outer;
 59.2926 +                            }
 59.2927 +                        }
 59.2928 +                        if (a[great] == pivot1) { // a[great] < pivot2
 59.2929 +                            a[k] = a[less];
 59.2930 +                            /*
 59.2931 +                             * Even though a[great] equals to pivot1, the
 59.2932 +                             * assignment a[less] = pivot1 may be incorrect,
 59.2933 +                             * if a[great] and pivot1 are floating-point zeros
 59.2934 +                             * of different signs. Therefore in float and
 59.2935 +                             * double sorting methods we have to use more
 59.2936 +                             * accurate assignment a[less] = a[great].
 59.2937 +                             */
 59.2938 +                            a[less] = a[great];
 59.2939 +                            ++less;
 59.2940 +                        } else { // pivot1 < a[great] < pivot2
 59.2941 +                            a[k] = a[great];
 59.2942 +                        }
 59.2943 +                        a[great] = ak;
 59.2944 +                        --great;
 59.2945 +                    }
 59.2946 +                }
 59.2947 +            }
 59.2948 +
 59.2949 +            // Sort center part recursively
 59.2950 +            sort(a, less, great, false);
 59.2951 +
 59.2952 +        } else { // Partitioning with one pivot
 59.2953 +            /*
 59.2954 +             * Use the third of the five sorted elements as pivot.
 59.2955 +             * This value is inexpensive approximation of the median.
 59.2956 +             */
 59.2957 +            double pivot = a[e3];
 59.2958 +
 59.2959 +            /*
 59.2960 +             * Partitioning degenerates to the traditional 3-way
 59.2961 +             * (or "Dutch National Flag") schema:
 59.2962 +             *
 59.2963 +             *   left part    center part              right part
 59.2964 +             * +-------------------------------------------------+
 59.2965 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 59.2966 +             * +-------------------------------------------------+
 59.2967 +             *              ^              ^        ^
 59.2968 +             *              |              |        |
 59.2969 +             *             less            k      great
 59.2970 +             *
 59.2971 +             * Invariants:
 59.2972 +             *
 59.2973 +             *   all in (left, less)   < pivot
 59.2974 +             *   all in [less, k)     == pivot
 59.2975 +             *   all in (great, right) > pivot
 59.2976 +             *
 59.2977 +             * Pointer k is the first index of ?-part.
 59.2978 +             */
 59.2979 +            for (int k = less; k <= great; ++k) {
 59.2980 +                if (a[k] == pivot) {
 59.2981 +                    continue;
 59.2982 +                }
 59.2983 +                double ak = a[k];
 59.2984 +                if (ak < pivot) { // Move a[k] to left part
 59.2985 +                    a[k] = a[less];
 59.2986 +                    a[less] = ak;
 59.2987 +                    ++less;
 59.2988 +                } else { // a[k] > pivot - Move a[k] to right part
 59.2989 +                    while (a[great] > pivot) {
 59.2990 +                        --great;
 59.2991 +                    }
 59.2992 +                    if (a[great] < pivot) { // a[great] <= pivot
 59.2993 +                        a[k] = a[less];
 59.2994 +                        a[less] = a[great];
 59.2995 +                        ++less;
 59.2996 +                    } else { // a[great] == pivot
 59.2997 +                        /*
 59.2998 +                         * Even though a[great] equals to pivot, the
 59.2999 +                         * assignment a[k] = pivot may be incorrect,
 59.3000 +                         * if a[great] and pivot are floating-point
 59.3001 +                         * zeros of different signs. Therefore in float
 59.3002 +                         * and double sorting methods we have to use
 59.3003 +                         * more accurate assignment a[k] = a[great].
 59.3004 +                         */
 59.3005 +                        a[k] = a[great];
 59.3006 +                    }
 59.3007 +                    a[great] = ak;
 59.3008 +                    --great;
 59.3009 +                }
 59.3010 +            }
 59.3011 +
 59.3012 +            /*
 59.3013 +             * Sort left and right parts recursively.
 59.3014 +             * All elements from center part are equal
 59.3015 +             * and, therefore, already sorted.
 59.3016 +             */
 59.3017 +            sort(a, left, less - 1, leftmost);
 59.3018 +            sort(a, great + 1, right, false);
 59.3019 +        }
 59.3020 +    }
 59.3021 +}
    60.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    60.2 +++ b/emul/compact/src/main/java/java/util/EmptyStackException.java	Sun Feb 03 07:48:42 2013 +0100
    60.3 @@ -0,0 +1,46 @@
    60.4 +/*
    60.5 + * Copyright (c) 1994, 2008, 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.util;
   60.30 +
   60.31 +/**
   60.32 + * Thrown by methods in the <code>Stack</code> class to indicate
   60.33 + * that the stack is empty.
   60.34 + *
   60.35 + * @author  Jonathan Payne
   60.36 + * @see     java.util.Stack
   60.37 + * @since   JDK1.0
   60.38 + */
   60.39 +public
   60.40 +class EmptyStackException extends RuntimeException {
   60.41 +    private static final long serialVersionUID = 5084686378493302095L;
   60.42 +
   60.43 +    /**
   60.44 +     * Constructs a new <code>EmptyStackException</code> with <tt>null</tt>
   60.45 +     * as its error message string.
   60.46 +     */
   60.47 +    public EmptyStackException() {
   60.48 +    }
   60.49 +}
    61.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.2 +++ b/emul/compact/src/main/java/java/util/EventListener.java	Sun Feb 03 07:48:42 2013 +0100
    61.3 @@ -0,0 +1,33 @@
    61.4 +/*
    61.5 + * Copyright (c) 1996, 1999, 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.util;
   61.30 +
   61.31 +/**
   61.32 + * A tagging interface that all event listener interfaces must extend.
   61.33 + * @since JDK1.1
   61.34 + */
   61.35 +public interface EventListener {
   61.36 +}
    62.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.2 +++ b/emul/compact/src/main/java/java/util/EventObject.java	Sun Feb 03 07:48:42 2013 +0100
    62.3 @@ -0,0 +1,78 @@
    62.4 +/*
    62.5 + * Copyright (c) 1996, 2003, 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.util;
   62.30 +
   62.31 +/**
   62.32 + * <p>
   62.33 + * The root class from which all event state objects shall be derived.
   62.34 + * <p>
   62.35 + * All Events are constructed with a reference to the object, the "source",
   62.36 + * that is logically deemed to be the object upon which the Event in question
   62.37 + * initially occurred upon.
   62.38 + *
   62.39 + * @since JDK1.1
   62.40 + */
   62.41 +
   62.42 +public class EventObject implements java.io.Serializable {
   62.43 +
   62.44 +    private static final long serialVersionUID = 5516075349620653480L;
   62.45 +
   62.46 +    /**
   62.47 +     * The object on which the Event initially occurred.
   62.48 +     */
   62.49 +    protected transient Object  source;
   62.50 +
   62.51 +    /**
   62.52 +     * Constructs a prototypical Event.
   62.53 +     *
   62.54 +     * @param    source    The object on which the Event initially occurred.
   62.55 +     * @exception  IllegalArgumentException  if source is null.
   62.56 +     */
   62.57 +    public EventObject(Object source) {
   62.58 +        if (source == null)
   62.59 +            throw new IllegalArgumentException("null source");
   62.60 +
   62.61 +        this.source = source;
   62.62 +    }
   62.63 +
   62.64 +    /**
   62.65 +     * The object on which the Event initially occurred.
   62.66 +     *
   62.67 +     * @return   The object on which the Event initially occurred.
   62.68 +     */
   62.69 +    public Object getSource() {
   62.70 +        return source;
   62.71 +    }
   62.72 +
   62.73 +    /**
   62.74 +     * Returns a String representation of this EventObject.
   62.75 +     *
   62.76 +     * @return  A a String representation of this EventObject.
   62.77 +     */
   62.78 +    public String toString() {
   62.79 +        return getClass().getName() + "[source=" + source + "]";
   62.80 +    }
   62.81 +}
    63.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.2 +++ b/emul/compact/src/main/java/java/util/HashMap.java	Sun Feb 03 07:48:42 2013 +0100
    63.3 @@ -0,0 +1,990 @@
    63.4 +/*
    63.5 + * Copyright (c) 1997, 2010, 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.util;
   63.30 +import java.io.*;
   63.31 +
   63.32 +/**
   63.33 + * Hash table based implementation of the <tt>Map</tt> interface.  This
   63.34 + * implementation provides all of the optional map operations, and permits
   63.35 + * <tt>null</tt> values and the <tt>null</tt> key.  (The <tt>HashMap</tt>
   63.36 + * class is roughly equivalent to <tt>Hashtable</tt>, except that it is
   63.37 + * unsynchronized and permits nulls.)  This class makes no guarantees as to
   63.38 + * the order of the map; in particular, it does not guarantee that the order
   63.39 + * will remain constant over time.
   63.40 + *
   63.41 + * <p>This implementation provides constant-time performance for the basic
   63.42 + * operations (<tt>get</tt> and <tt>put</tt>), assuming the hash function
   63.43 + * disperses the elements properly among the buckets.  Iteration over
   63.44 + * collection views requires time proportional to the "capacity" of the
   63.45 + * <tt>HashMap</tt> instance (the number of buckets) plus its size (the number
   63.46 + * of key-value mappings).  Thus, it's very important not to set the initial
   63.47 + * capacity too high (or the load factor too low) if iteration performance is
   63.48 + * important.
   63.49 + *
   63.50 + * <p>An instance of <tt>HashMap</tt> has two parameters that affect its
   63.51 + * performance: <i>initial capacity</i> and <i>load factor</i>.  The
   63.52 + * <i>capacity</i> is the number of buckets in the hash table, and the initial
   63.53 + * capacity is simply the capacity at the time the hash table is created.  The
   63.54 + * <i>load factor</i> is a measure of how full the hash table is allowed to
   63.55 + * get before its capacity is automatically increased.  When the number of
   63.56 + * entries in the hash table exceeds the product of the load factor and the
   63.57 + * current capacity, the hash table is <i>rehashed</i> (that is, internal data
   63.58 + * structures are rebuilt) so that the hash table has approximately twice the
   63.59 + * number of buckets.
   63.60 + *
   63.61 + * <p>As a general rule, the default load factor (.75) offers a good tradeoff
   63.62 + * between time and space costs.  Higher values decrease the space overhead
   63.63 + * but increase the lookup cost (reflected in most of the operations of the
   63.64 + * <tt>HashMap</tt> class, including <tt>get</tt> and <tt>put</tt>).  The
   63.65 + * expected number of entries in the map and its load factor should be taken
   63.66 + * into account when setting its initial capacity, so as to minimize the
   63.67 + * number of rehash operations.  If the initial capacity is greater
   63.68 + * than the maximum number of entries divided by the load factor, no
   63.69 + * rehash operations will ever occur.
   63.70 + *
   63.71 + * <p>If many mappings are to be stored in a <tt>HashMap</tt> instance,
   63.72 + * creating it with a sufficiently large capacity will allow the mappings to
   63.73 + * be stored more efficiently than letting it perform automatic rehashing as
   63.74 + * needed to grow the table.
   63.75 + *
   63.76 + * <p><strong>Note that this implementation is not synchronized.</strong>
   63.77 + * If multiple threads access a hash map concurrently, and at least one of
   63.78 + * the threads modifies the map structurally, it <i>must</i> be
   63.79 + * synchronized externally.  (A structural modification is any operation
   63.80 + * that adds or deletes one or more mappings; merely changing the value
   63.81 + * associated with a key that an instance already contains is not a
   63.82 + * structural modification.)  This is typically accomplished by
   63.83 + * synchronizing on some object that naturally encapsulates the map.
   63.84 + *
   63.85 + * If no such object exists, the map should be "wrapped" using the
   63.86 + * {@link Collections#synchronizedMap Collections.synchronizedMap}
   63.87 + * method.  This is best done at creation time, to prevent accidental
   63.88 + * unsynchronized access to the map:<pre>
   63.89 + *   Map m = Collections.synchronizedMap(new HashMap(...));</pre>
   63.90 + *
   63.91 + * <p>The iterators returned by all of this class's "collection view methods"
   63.92 + * are <i>fail-fast</i>: if the map is structurally modified at any time after
   63.93 + * the iterator is created, in any way except through the iterator's own
   63.94 + * <tt>remove</tt> method, the iterator will throw a
   63.95 + * {@link ConcurrentModificationException}.  Thus, in the face of concurrent
   63.96 + * modification, the iterator fails quickly and cleanly, rather than risking
   63.97 + * arbitrary, non-deterministic behavior at an undetermined time in the
   63.98 + * future.
   63.99 + *
  63.100 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
  63.101 + * as it is, generally speaking, impossible to make any hard guarantees in the
  63.102 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
  63.103 + * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
  63.104 + * Therefore, it would be wrong to write a program that depended on this
  63.105 + * exception for its correctness: <i>the fail-fast behavior of iterators
  63.106 + * should be used only to detect bugs.</i>
  63.107 + *
  63.108 + * <p>This class is a member of the
  63.109 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  63.110 + * Java Collections Framework</a>.
  63.111 + *
  63.112 + * @param <K> the type of keys maintained by this map
  63.113 + * @param <V> the type of mapped values
  63.114 + *
  63.115 + * @author  Doug Lea
  63.116 + * @author  Josh Bloch
  63.117 + * @author  Arthur van Hoff
  63.118 + * @author  Neal Gafter
  63.119 + * @see     Object#hashCode()
  63.120 + * @see     Collection
  63.121 + * @see     Map
  63.122 + * @see     TreeMap
  63.123 + * @see     Hashtable
  63.124 + * @since   1.2
  63.125 + */
  63.126 +
  63.127 +public class HashMap<K,V>
  63.128 +    extends AbstractMap<K,V>
  63.129 +    implements Map<K,V>, Cloneable, Serializable
  63.130 +{
  63.131 +
  63.132 +    /**
  63.133 +     * The default initial capacity - MUST be a power of two.
  63.134 +     */
  63.135 +    static final int DEFAULT_INITIAL_CAPACITY = 16;
  63.136 +
  63.137 +    /**
  63.138 +     * The maximum capacity, used if a higher value is implicitly specified
  63.139 +     * by either of the constructors with arguments.
  63.140 +     * MUST be a power of two <= 1<<30.
  63.141 +     */
  63.142 +    static final int MAXIMUM_CAPACITY = 1 << 30;
  63.143 +
  63.144 +    /**
  63.145 +     * The load factor used when none specified in constructor.
  63.146 +     */
  63.147 +    static final float DEFAULT_LOAD_FACTOR = 0.75f;
  63.148 +
  63.149 +    /**
  63.150 +     * The table, resized as necessary. Length MUST Always be a power of two.
  63.151 +     */
  63.152 +    transient Entry[] table;
  63.153 +
  63.154 +    /**
  63.155 +     * The number of key-value mappings contained in this map.
  63.156 +     */
  63.157 +    transient int size;
  63.158 +
  63.159 +    /**
  63.160 +     * The next size value at which to resize (capacity * load factor).
  63.161 +     * @serial
  63.162 +     */
  63.163 +    int threshold;
  63.164 +
  63.165 +    /**
  63.166 +     * The load factor for the hash table.
  63.167 +     *
  63.168 +     * @serial
  63.169 +     */
  63.170 +    final float loadFactor;
  63.171 +
  63.172 +    /**
  63.173 +     * The number of times this HashMap has been structurally modified
  63.174 +     * Structural modifications are those that change the number of mappings in
  63.175 +     * the HashMap or otherwise modify its internal structure (e.g.,
  63.176 +     * rehash).  This field is used to make iterators on Collection-views of
  63.177 +     * the HashMap fail-fast.  (See ConcurrentModificationException).
  63.178 +     */
  63.179 +    transient int modCount;
  63.180 +
  63.181 +    /**
  63.182 +     * Constructs an empty <tt>HashMap</tt> with the specified initial
  63.183 +     * capacity and load factor.
  63.184 +     *
  63.185 +     * @param  initialCapacity the initial capacity
  63.186 +     * @param  loadFactor      the load factor
  63.187 +     * @throws IllegalArgumentException if the initial capacity is negative
  63.188 +     *         or the load factor is nonpositive
  63.189 +     */
  63.190 +    public HashMap(int initialCapacity, float loadFactor) {
  63.191 +        if (initialCapacity < 0)
  63.192 +            throw new IllegalArgumentException("Illegal initial capacity: " +
  63.193 +                                               initialCapacity);
  63.194 +        if (initialCapacity > MAXIMUM_CAPACITY)
  63.195 +            initialCapacity = MAXIMUM_CAPACITY;
  63.196 +        if (loadFactor <= 0 || Float.isNaN(loadFactor))
  63.197 +            throw new IllegalArgumentException("Illegal load factor: " +
  63.198 +                                               loadFactor);
  63.199 +
  63.200 +        // Find a power of 2 >= initialCapacity
  63.201 +        int capacity = 1;
  63.202 +        while (capacity < initialCapacity)
  63.203 +            capacity <<= 1;
  63.204 +
  63.205 +        this.loadFactor = loadFactor;
  63.206 +        threshold = (int)(capacity * loadFactor);
  63.207 +        table = new Entry[capacity];
  63.208 +        init();
  63.209 +    }
  63.210 +
  63.211 +    /**
  63.212 +     * Constructs an empty <tt>HashMap</tt> with the specified initial
  63.213 +     * capacity and the default load factor (0.75).
  63.214 +     *
  63.215 +     * @param  initialCapacity the initial capacity.
  63.216 +     * @throws IllegalArgumentException if the initial capacity is negative.
  63.217 +     */
  63.218 +    public HashMap(int initialCapacity) {
  63.219 +        this(initialCapacity, DEFAULT_LOAD_FACTOR);
  63.220 +    }
  63.221 +
  63.222 +    /**
  63.223 +     * Constructs an empty <tt>HashMap</tt> with the default initial capacity
  63.224 +     * (16) and the default load factor (0.75).
  63.225 +     */
  63.226 +    public HashMap() {
  63.227 +        this.loadFactor = DEFAULT_LOAD_FACTOR;
  63.228 +        threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
  63.229 +        table = new Entry[DEFAULT_INITIAL_CAPACITY];
  63.230 +        init();
  63.231 +    }
  63.232 +
  63.233 +    /**
  63.234 +     * Constructs a new <tt>HashMap</tt> with the same mappings as the
  63.235 +     * specified <tt>Map</tt>.  The <tt>HashMap</tt> is created with
  63.236 +     * default load factor (0.75) and an initial capacity sufficient to
  63.237 +     * hold the mappings in the specified <tt>Map</tt>.
  63.238 +     *
  63.239 +     * @param   m the map whose mappings are to be placed in this map
  63.240 +     * @throws  NullPointerException if the specified map is null
  63.241 +     */
  63.242 +    public HashMap(Map<? extends K, ? extends V> m) {
  63.243 +        this(Math.max((int) (m.size() / DEFAULT_LOAD_FACTOR) + 1,
  63.244 +                      DEFAULT_INITIAL_CAPACITY), DEFAULT_LOAD_FACTOR);
  63.245 +        putAllForCreate(m);
  63.246 +    }
  63.247 +
  63.248 +    // internal utilities
  63.249 +
  63.250 +    /**
  63.251 +     * Initialization hook for subclasses. This method is called
  63.252 +     * in all constructors and pseudo-constructors (clone, readObject)
  63.253 +     * after HashMap has been initialized but before any entries have
  63.254 +     * been inserted.  (In the absence of this method, readObject would
  63.255 +     * require explicit knowledge of subclasses.)
  63.256 +     */
  63.257 +    void init() {
  63.258 +    }
  63.259 +
  63.260 +    /**
  63.261 +     * Applies a supplemental hash function to a given hashCode, which
  63.262 +     * defends against poor quality hash functions.  This is critical
  63.263 +     * because HashMap uses power-of-two length hash tables, that
  63.264 +     * otherwise encounter collisions for hashCodes that do not differ
  63.265 +     * in lower bits. Note: Null keys always map to hash 0, thus index 0.
  63.266 +     */
  63.267 +    static int hash(int h) {
  63.268 +        // This function ensures that hashCodes that differ only by
  63.269 +        // constant multiples at each bit position have a bounded
  63.270 +        // number of collisions (approximately 8 at default load factor).
  63.271 +        h ^= (h >>> 20) ^ (h >>> 12);
  63.272 +        return h ^ (h >>> 7) ^ (h >>> 4);
  63.273 +    }
  63.274 +
  63.275 +    /**
  63.276 +     * Returns index for hash code h.
  63.277 +     */
  63.278 +    static int indexFor(int h, int length) {
  63.279 +        return h & (length-1);
  63.280 +    }
  63.281 +
  63.282 +    /**
  63.283 +     * Returns the number of key-value mappings in this map.
  63.284 +     *
  63.285 +     * @return the number of key-value mappings in this map
  63.286 +     */
  63.287 +    public int size() {
  63.288 +        return size;
  63.289 +    }
  63.290 +
  63.291 +    /**
  63.292 +     * Returns <tt>true</tt> if this map contains no key-value mappings.
  63.293 +     *
  63.294 +     * @return <tt>true</tt> if this map contains no key-value mappings
  63.295 +     */
  63.296 +    public boolean isEmpty() {
  63.297 +        return size == 0;
  63.298 +    }
  63.299 +
  63.300 +    /**
  63.301 +     * Returns the value to which the specified key is mapped,
  63.302 +     * or {@code null} if this map contains no mapping for the key.
  63.303 +     *
  63.304 +     * <p>More formally, if this map contains a mapping from a key
  63.305 +     * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
  63.306 +     * key.equals(k))}, then this method returns {@code v}; otherwise
  63.307 +     * it returns {@code null}.  (There can be at most one such mapping.)
  63.308 +     *
  63.309 +     * <p>A return value of {@code null} does not <i>necessarily</i>
  63.310 +     * indicate that the map contains no mapping for the key; it's also
  63.311 +     * possible that the map explicitly maps the key to {@code null}.
  63.312 +     * The {@link #containsKey containsKey} operation may be used to
  63.313 +     * distinguish these two cases.
  63.314 +     *
  63.315 +     * @see #put(Object, Object)
  63.316 +     */
  63.317 +    public V get(Object key) {
  63.318 +        if (key == null)
  63.319 +            return getForNullKey();
  63.320 +        int hash = hash(key.hashCode());
  63.321 +        for (Entry<K,V> e = table[indexFor(hash, table.length)];
  63.322 +             e != null;
  63.323 +             e = e.next) {
  63.324 +            Object k;
  63.325 +            if (e.hash == hash && ((k = e.key) == key || key.equals(k)))
  63.326 +                return e.value;
  63.327 +        }
  63.328 +        return null;
  63.329 +    }
  63.330 +
  63.331 +    /**
  63.332 +     * Offloaded version of get() to look up null keys.  Null keys map
  63.333 +     * to index 0.  This null case is split out into separate methods
  63.334 +     * for the sake of performance in the two most commonly used
  63.335 +     * operations (get and put), but incorporated with conditionals in
  63.336 +     * others.
  63.337 +     */
  63.338 +    private V getForNullKey() {
  63.339 +        for (Entry<K,V> e = table[0]; e != null; e = e.next) {
  63.340 +            if (e.key == null)
  63.341 +                return e.value;
  63.342 +        }
  63.343 +        return null;
  63.344 +    }
  63.345 +
  63.346 +    /**
  63.347 +     * Returns <tt>true</tt> if this map contains a mapping for the
  63.348 +     * specified key.
  63.349 +     *
  63.350 +     * @param   key   The key whose presence in this map is to be tested
  63.351 +     * @return <tt>true</tt> if this map contains a mapping for the specified
  63.352 +     * key.
  63.353 +     */
  63.354 +    public boolean containsKey(Object key) {
  63.355 +        return getEntry(key) != null;
  63.356 +    }
  63.357 +
  63.358 +    /**
  63.359 +     * Returns the entry associated with the specified key in the
  63.360 +     * HashMap.  Returns null if the HashMap contains no mapping
  63.361 +     * for the key.
  63.362 +     */
  63.363 +    final Entry<K,V> getEntry(Object key) {
  63.364 +        int hash = (key == null) ? 0 : hash(key.hashCode());
  63.365 +        for (Entry<K,V> e = table[indexFor(hash, table.length)];
  63.366 +             e != null;
  63.367 +             e = e.next) {
  63.368 +            Object k;
  63.369 +            if (e.hash == hash &&
  63.370 +                ((k = e.key) == key || (key != null && key.equals(k))))
  63.371 +                return e;
  63.372 +        }
  63.373 +        return null;
  63.374 +    }
  63.375 +
  63.376 +
  63.377 +    /**
  63.378 +     * Associates the specified value with the specified key in this map.
  63.379 +     * If the map previously contained a mapping for the key, the old
  63.380 +     * value is replaced.
  63.381 +     *
  63.382 +     * @param key key with which the specified value is to be associated
  63.383 +     * @param value value to be associated with the specified key
  63.384 +     * @return the previous value associated with <tt>key</tt>, or
  63.385 +     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
  63.386 +     *         (A <tt>null</tt> return can also indicate that the map
  63.387 +     *         previously associated <tt>null</tt> with <tt>key</tt>.)
  63.388 +     */
  63.389 +    public V put(K key, V value) {
  63.390 +        if (key == null)
  63.391 +            return putForNullKey(value);
  63.392 +        int hash = hash(key.hashCode());
  63.393 +        int i = indexFor(hash, table.length);
  63.394 +        for (Entry<K,V> e = table[i]; e != null; e = e.next) {
  63.395 +            Object k;
  63.396 +            if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
  63.397 +                V oldValue = e.value;
  63.398 +                e.value = value;
  63.399 +                e.recordAccess(this);
  63.400 +                return oldValue;
  63.401 +            }
  63.402 +        }
  63.403 +
  63.404 +        modCount++;
  63.405 +        addEntry(hash, key, value, i);
  63.406 +        return null;
  63.407 +    }
  63.408 +
  63.409 +    /**
  63.410 +     * Offloaded version of put for null keys
  63.411 +     */
  63.412 +    private V putForNullKey(V value) {
  63.413 +        for (Entry<K,V> e = table[0]; e != null; e = e.next) {
  63.414 +            if (e.key == null) {
  63.415 +                V oldValue = e.value;
  63.416 +                e.value = value;
  63.417 +                e.recordAccess(this);
  63.418 +                return oldValue;
  63.419 +            }
  63.420 +        }
  63.421 +        modCount++;
  63.422 +        addEntry(0, null, value, 0);
  63.423 +        return null;
  63.424 +    }
  63.425 +
  63.426 +    /**
  63.427 +     * This method is used instead of put by constructors and
  63.428 +     * pseudoconstructors (clone, readObject).  It does not resize the table,
  63.429 +     * check for comodification, etc.  It calls createEntry rather than
  63.430 +     * addEntry.
  63.431 +     */
  63.432 +    private void putForCreate(K key, V value) {
  63.433 +        int hash = (key == null) ? 0 : hash(key.hashCode());
  63.434 +        int i = indexFor(hash, table.length);
  63.435 +
  63.436 +        /**
  63.437 +         * Look for preexisting entry for key.  This will never happen for
  63.438 +         * clone or deserialize.  It will only happen for construction if the
  63.439 +         * input Map is a sorted map whose ordering is inconsistent w/ equals.
  63.440 +         */
  63.441 +        for (Entry<K,V> e = table[i]; e != null; e = e.next) {
  63.442 +            Object k;
  63.443 +            if (e.hash == hash &&
  63.444 +                ((k = e.key) == key || (key != null && key.equals(k)))) {
  63.445 +                e.value = value;
  63.446 +                return;
  63.447 +            }
  63.448 +        }
  63.449 +
  63.450 +        createEntry(hash, key, value, i);
  63.451 +    }
  63.452 +
  63.453 +    private void putAllForCreate(Map<? extends K, ? extends V> m) {
  63.454 +        for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
  63.455 +            putForCreate(e.getKey(), e.getValue());
  63.456 +    }
  63.457 +
  63.458 +    /**
  63.459 +     * Rehashes the contents of this map into a new array with a
  63.460 +     * larger capacity.  This method is called automatically when the
  63.461 +     * number of keys in this map reaches its threshold.
  63.462 +     *
  63.463 +     * If current capacity is MAXIMUM_CAPACITY, this method does not
  63.464 +     * resize the map, but sets threshold to Integer.MAX_VALUE.
  63.465 +     * This has the effect of preventing future calls.
  63.466 +     *
  63.467 +     * @param newCapacity the new capacity, MUST be a power of two;
  63.468 +     *        must be greater than current capacity unless current
  63.469 +     *        capacity is MAXIMUM_CAPACITY (in which case value
  63.470 +     *        is irrelevant).
  63.471 +     */
  63.472 +    void resize(int newCapacity) {
  63.473 +        Entry[] oldTable = table;
  63.474 +        int oldCapacity = oldTable.length;
  63.475 +        if (oldCapacity == MAXIMUM_CAPACITY) {
  63.476 +            threshold = Integer.MAX_VALUE;
  63.477 +            return;
  63.478 +        }
  63.479 +
  63.480 +        Entry[] newTable = new Entry[newCapacity];
  63.481 +        transfer(newTable);
  63.482 +        table = newTable;
  63.483 +        threshold = (int)(newCapacity * loadFactor);
  63.484 +    }
  63.485 +
  63.486 +    /**
  63.487 +     * Transfers all entries from current table to newTable.
  63.488 +     */
  63.489 +    void transfer(Entry[] newTable) {
  63.490 +        Entry[] src = table;
  63.491 +        int newCapacity = newTable.length;
  63.492 +        for (int j = 0; j < src.length; j++) {
  63.493 +            Entry<K,V> e = src[j];
  63.494 +            if (e != null) {
  63.495 +                src[j] = null;
  63.496 +                do {
  63.497 +                    Entry<K,V> next = e.next;
  63.498 +                    int i = indexFor(e.hash, newCapacity);
  63.499 +                    e.next = newTable[i];
  63.500 +                    newTable[i] = e;
  63.501 +                    e = next;
  63.502 +                } while (e != null);
  63.503 +            }
  63.504 +        }
  63.505 +    }
  63.506 +
  63.507 +    /**
  63.508 +     * Copies all of the mappings from the specified map to this map.
  63.509 +     * These mappings will replace any mappings that this map had for
  63.510 +     * any of the keys currently in the specified map.
  63.511 +     *
  63.512 +     * @param m mappings to be stored in this map
  63.513 +     * @throws NullPointerException if the specified map is null
  63.514 +     */
  63.515 +    public void putAll(Map<? extends K, ? extends V> m) {
  63.516 +        int numKeysToBeAdded = m.size();
  63.517 +        if (numKeysToBeAdded == 0)
  63.518 +            return;
  63.519 +
  63.520 +        /*
  63.521 +         * Expand the map if the map if the number of mappings to be added
  63.522 +         * is greater than or equal to threshold.  This is conservative; the
  63.523 +         * obvious condition is (m.size() + size) >= threshold, but this
  63.524 +         * condition could result in a map with twice the appropriate capacity,
  63.525 +         * if the keys to be added overlap with the keys already in this map.
  63.526 +         * By using the conservative calculation, we subject ourself
  63.527 +         * to at most one extra resize.
  63.528 +         */
  63.529 +        if (numKeysToBeAdded > threshold) {
  63.530 +            int targetCapacity = (int)(numKeysToBeAdded / loadFactor + 1);
  63.531 +            if (targetCapacity > MAXIMUM_CAPACITY)
  63.532 +                targetCapacity = MAXIMUM_CAPACITY;
  63.533 +            int newCapacity = table.length;
  63.534 +            while (newCapacity < targetCapacity)
  63.535 +                newCapacity <<= 1;
  63.536 +            if (newCapacity > table.length)
  63.537 +                resize(newCapacity);
  63.538 +        }
  63.539 +
  63.540 +        for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
  63.541 +            put(e.getKey(), e.getValue());
  63.542 +    }
  63.543 +
  63.544 +    /**
  63.545 +     * Removes the mapping for the specified key from this map if present.
  63.546 +     *
  63.547 +     * @param  key key whose mapping is to be removed from the map
  63.548 +     * @return the previous value associated with <tt>key</tt>, or
  63.549 +     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
  63.550 +     *         (A <tt>null</tt> return can also indicate that the map
  63.551 +     *         previously associated <tt>null</tt> with <tt>key</tt>.)
  63.552 +     */
  63.553 +    public V remove(Object key) {
  63.554 +        Entry<K,V> e = removeEntryForKey(key);
  63.555 +        return (e == null ? null : e.value);
  63.556 +    }
  63.557 +
  63.558 +    /**
  63.559 +     * Removes and returns the entry associated with the specified key
  63.560 +     * in the HashMap.  Returns null if the HashMap contains no mapping
  63.561 +     * for this key.
  63.562 +     */
  63.563 +    final Entry<K,V> removeEntryForKey(Object key) {
  63.564 +        int hash = (key == null) ? 0 : hash(key.hashCode());
  63.565 +        int i = indexFor(hash, table.length);
  63.566 +        Entry<K,V> prev = table[i];
  63.567 +        Entry<K,V> e = prev;
  63.568 +
  63.569 +        while (e != null) {
  63.570 +            Entry<K,V> next = e.next;
  63.571 +            Object k;
  63.572 +            if (e.hash == hash &&
  63.573 +                ((k = e.key) == key || (key != null && key.equals(k)))) {
  63.574 +                modCount++;
  63.575 +                size--;
  63.576 +                if (prev == e)
  63.577 +                    table[i] = next;
  63.578 +                else
  63.579 +                    prev.next = next;
  63.580 +                e.recordRemoval(this);
  63.581 +                return e;
  63.582 +            }
  63.583 +            prev = e;
  63.584 +            e = next;
  63.585 +        }
  63.586 +
  63.587 +        return e;
  63.588 +    }
  63.589 +
  63.590 +    /**
  63.591 +     * Special version of remove for EntrySet.
  63.592 +     */
  63.593 +    final Entry<K,V> removeMapping(Object o) {
  63.594 +        if (!(o instanceof Map.Entry))
  63.595 +            return null;
  63.596 +
  63.597 +        Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
  63.598 +        Object key = entry.getKey();
  63.599 +        int hash = (key == null) ? 0 : hash(key.hashCode());
  63.600 +        int i = indexFor(hash, table.length);
  63.601 +        Entry<K,V> prev = table[i];
  63.602 +        Entry<K,V> e = prev;
  63.603 +
  63.604 +        while (e != null) {
  63.605 +            Entry<K,V> next = e.next;
  63.606 +            if (e.hash == hash && e.equals(entry)) {
  63.607 +                modCount++;
  63.608 +                size--;
  63.609 +                if (prev == e)
  63.610 +                    table[i] = next;
  63.611 +                else
  63.612 +                    prev.next = next;
  63.613 +                e.recordRemoval(this);
  63.614 +                return e;
  63.615 +            }
  63.616 +            prev = e;
  63.617 +            e = next;
  63.618 +        }
  63.619 +
  63.620 +        return e;
  63.621 +    }
  63.622 +
  63.623 +    /**
  63.624 +     * Removes all of the mappings from this map.
  63.625 +     * The map will be empty after this call returns.
  63.626 +     */
  63.627 +    public void clear() {
  63.628 +        modCount++;
  63.629 +        Entry[] tab = table;
  63.630 +        for (int i = 0; i < tab.length; i++)
  63.631 +            tab[i] = null;
  63.632 +        size = 0;
  63.633 +    }
  63.634 +
  63.635 +    /**
  63.636 +     * Returns <tt>true</tt> if this map maps one or more keys to the
  63.637 +     * specified value.
  63.638 +     *
  63.639 +     * @param value value whose presence in this map is to be tested
  63.640 +     * @return <tt>true</tt> if this map maps one or more keys to the
  63.641 +     *         specified value
  63.642 +     */
  63.643 +    public boolean containsValue(Object value) {
  63.644 +        if (value == null)
  63.645 +            return containsNullValue();
  63.646 +
  63.647 +        Entry[] tab = table;
  63.648 +        for (int i = 0; i < tab.length ; i++)
  63.649 +            for (Entry e = tab[i] ; e != null ; e = e.next)
  63.650 +                if (value.equals(e.value))
  63.651 +                    return true;
  63.652 +        return false;
  63.653 +    }
  63.654 +
  63.655 +    /**
  63.656 +     * Special-case code for containsValue with null argument
  63.657 +     */
  63.658 +    private boolean containsNullValue() {
  63.659 +        Entry[] tab = table;
  63.660 +        for (int i = 0; i < tab.length ; i++)
  63.661 +            for (Entry e = tab[i] ; e != null ; e = e.next)
  63.662 +                if (e.value == null)
  63.663 +                    return true;
  63.664 +        return false;
  63.665 +    }
  63.666 +
  63.667 +    /**
  63.668 +     * Returns a shallow copy of this <tt>HashMap</tt> instance: the keys and
  63.669 +     * values themselves are not cloned.
  63.670 +     *
  63.671 +     * @return a shallow copy of this map
  63.672 +     */
  63.673 +    public Object clone() {
  63.674 +        HashMap<K,V> result = null;
  63.675 +        try {
  63.676 +            result = (HashMap<K,V>)super.clone();
  63.677 +        } catch (CloneNotSupportedException e) {
  63.678 +            // assert false;
  63.679 +        }
  63.680 +        result.table = new Entry[table.length];
  63.681 +        result.entrySet = null;
  63.682 +        result.modCount = 0;
  63.683 +        result.size = 0;
  63.684 +        result.init();
  63.685 +        result.putAllForCreate(this);
  63.686 +
  63.687 +        return result;
  63.688 +    }
  63.689 +
  63.690 +    static class Entry<K,V> implements Map.Entry<K,V> {
  63.691 +        final K key;
  63.692 +        V value;
  63.693 +        Entry<K,V> next;
  63.694 +        final int hash;
  63.695 +
  63.696 +        /**
  63.697 +         * Creates new entry.
  63.698 +         */
  63.699 +        Entry(int h, K k, V v, Entry<K,V> n) {
  63.700 +            value = v;
  63.701 +            next = n;
  63.702 +            key = k;
  63.703 +            hash = h;
  63.704 +        }
  63.705 +
  63.706 +        public final K getKey() {
  63.707 +            return key;
  63.708 +        }
  63.709 +
  63.710 +        public final V getValue() {
  63.711 +            return value;
  63.712 +        }
  63.713 +
  63.714 +        public final V setValue(V newValue) {
  63.715 +            V oldValue = value;
  63.716 +            value = newValue;
  63.717 +            return oldValue;
  63.718 +        }
  63.719 +
  63.720 +        public final boolean equals(Object o) {
  63.721 +            if (!(o instanceof Map.Entry))
  63.722 +                return false;
  63.723 +            Map.Entry e = (Map.Entry)o;
  63.724 +            Object k1 = getKey();
  63.725 +            Object k2 = e.getKey();
  63.726 +            if (k1 == k2 || (k1 != null && k1.equals(k2))) {
  63.727 +                Object v1 = getValue();
  63.728 +                Object v2 = e.getValue();
  63.729 +                if (v1 == v2 || (v1 != null && v1.equals(v2)))
  63.730 +                    return true;
  63.731 +            }
  63.732 +            return false;
  63.733 +        }
  63.734 +
  63.735 +        public final int hashCode() {
  63.736 +            return (key==null   ? 0 : key.hashCode()) ^
  63.737 +                   (value==null ? 0 : value.hashCode());
  63.738 +        }
  63.739 +
  63.740 +        public final String toString() {
  63.741 +            return getKey() + "=" + getValue();
  63.742 +        }
  63.743 +
  63.744 +        /**
  63.745 +         * This method is invoked whenever the value in an entry is
  63.746 +         * overwritten by an invocation of put(k,v) for a key k that's already
  63.747 +         * in the HashMap.
  63.748 +         */
  63.749 +        void recordAccess(HashMap<K,V> m) {
  63.750 +        }
  63.751 +
  63.752 +        /**
  63.753 +         * This method is invoked whenever the entry is
  63.754 +         * removed from the table.
  63.755 +         */
  63.756 +        void recordRemoval(HashMap<K,V> m) {
  63.757 +        }
  63.758 +    }
  63.759 +
  63.760 +    /**
  63.761 +     * Adds a new entry with the specified key, value and hash code to
  63.762 +     * the specified bucket.  It is the responsibility of this
  63.763 +     * method to resize the table if appropriate.
  63.764 +     *
  63.765 +     * Subclass overrides this to alter the behavior of put method.
  63.766 +     */
  63.767 +    void addEntry(int hash, K key, V value, int bucketIndex) {
  63.768 +        Entry<K,V> e = table[bucketIndex];
  63.769 +        table[bucketIndex] = new Entry<>(hash, key, value, e);
  63.770 +        if (size++ >= threshold)
  63.771 +            resize(2 * table.length);
  63.772 +    }
  63.773 +
  63.774 +    /**
  63.775 +     * Like addEntry except that this version is used when creating entries
  63.776 +     * as part of Map construction or "pseudo-construction" (cloning,
  63.777 +     * deserialization).  This version needn't worry about resizing the table.
  63.778 +     *
  63.779 +     * Subclass overrides this to alter the behavior of HashMap(Map),
  63.780 +     * clone, and readObject.
  63.781 +     */
  63.782 +    void createEntry(int hash, K key, V value, int bucketIndex) {
  63.783 +        Entry<K,V> e = table[bucketIndex];
  63.784 +        table[bucketIndex] = new Entry<>(hash, key, value, e);
  63.785 +        size++;
  63.786 +    }
  63.787 +
  63.788 +    private abstract class HashIterator<E> implements Iterator<E> {
  63.789 +        Entry<K,V> next;        // next entry to return
  63.790 +        int expectedModCount;   // For fast-fail
  63.791 +        int index;              // current slot
  63.792 +        Entry<K,V> current;     // current entry
  63.793 +
  63.794 +        HashIterator() {
  63.795 +            expectedModCount = modCount;
  63.796 +            if (size > 0) { // advance to first entry
  63.797 +                Entry[] t = table;
  63.798 +                while (index < t.length && (next = t[index++]) == null)
  63.799 +                    ;
  63.800 +            }
  63.801 +        }
  63.802 +
  63.803 +        public final boolean hasNext() {
  63.804 +            return next != null;
  63.805 +        }
  63.806 +
  63.807 +        final Entry<K,V> nextEntry() {
  63.808 +            if (modCount != expectedModCount)
  63.809 +                throw new ConcurrentModificationException();
  63.810 +            Entry<K,V> e = next;
  63.811 +            if (e == null)
  63.812 +                throw new NoSuchElementException();
  63.813 +
  63.814 +            if ((next = e.next) == null) {
  63.815 +                Entry[] t = table;
  63.816 +                while (index < t.length && (next = t[index++]) == null)
  63.817 +                    ;
  63.818 +            }
  63.819 +            current = e;
  63.820 +            return e;
  63.821 +        }
  63.822 +
  63.823 +        public void remove() {
  63.824 +            if (current == null)
  63.825 +                throw new IllegalStateException();
  63.826 +            if (modCount != expectedModCount)
  63.827 +                throw new ConcurrentModificationException();
  63.828 +            Object k = current.key;
  63.829 +            current = null;
  63.830 +            HashMap.this.removeEntryForKey(k);
  63.831 +            expectedModCount = modCount;
  63.832 +        }
  63.833 +
  63.834 +    }
  63.835 +
  63.836 +    private final class ValueIterator extends HashIterator<V> {
  63.837 +        public V next() {
  63.838 +            return nextEntry().value;
  63.839 +        }
  63.840 +    }
  63.841 +
  63.842 +    private final class KeyIterator extends HashIterator<K> {
  63.843 +        public K next() {
  63.844 +            return nextEntry().getKey();
  63.845 +        }
  63.846 +    }
  63.847 +
  63.848 +    private final class EntryIterator extends HashIterator<Map.Entry<K,V>> {
  63.849 +        public Map.Entry<K,V> next() {
  63.850 +            return nextEntry();
  63.851 +        }
  63.852 +    }
  63.853 +
  63.854 +    // Subclass overrides these to alter behavior of views' iterator() method
  63.855 +    Iterator<K> newKeyIterator()   {
  63.856 +        return new KeyIterator();
  63.857 +    }
  63.858 +    Iterator<V> newValueIterator()   {
  63.859 +        return new ValueIterator();
  63.860 +    }
  63.861 +    Iterator<Map.Entry<K,V>> newEntryIterator()   {
  63.862 +        return new EntryIterator();
  63.863 +    }
  63.864 +
  63.865 +
  63.866 +    // Views
  63.867 +
  63.868 +    private transient Set<Map.Entry<K,V>> entrySet = null;
  63.869 +
  63.870 +    /**
  63.871 +     * Returns a {@link Set} view of the keys contained in this map.
  63.872 +     * The set is backed by the map, so changes to the map are
  63.873 +     * reflected in the set, and vice-versa.  If the map is modified
  63.874 +     * while an iteration over the set is in progress (except through
  63.875 +     * the iterator's own <tt>remove</tt> operation), the results of
  63.876 +     * the iteration are undefined.  The set supports element removal,
  63.877 +     * which removes the corresponding mapping from the map, via the
  63.878 +     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
  63.879 +     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
  63.880 +     * operations.  It does not support the <tt>add</tt> or <tt>addAll</tt>
  63.881 +     * operations.
  63.882 +     */
  63.883 +    public Set<K> keySet() {
  63.884 +        Set<K> ks = keySet;
  63.885 +        return (ks != null ? ks : (keySet = new KeySet()));
  63.886 +    }
  63.887 +
  63.888 +    private final class KeySet extends AbstractSet<K> {
  63.889 +        public Iterator<K> iterator() {
  63.890 +            return newKeyIterator();
  63.891 +        }
  63.892 +        public int size() {
  63.893 +            return size;
  63.894 +        }
  63.895 +        public boolean contains(Object o) {
  63.896 +            return containsKey(o);
  63.897 +        }
  63.898 +        public boolean remove(Object o) {
  63.899 +            return HashMap.this.removeEntryForKey(o) != null;
  63.900 +        }
  63.901 +        public void clear() {
  63.902 +            HashMap.this.clear();
  63.903 +        }
  63.904 +    }
  63.905 +
  63.906 +    /**
  63.907 +     * Returns a {@link Collection} view of the values contained in this map.
  63.908 +     * The collection is backed by the map, so changes to the map are
  63.909 +     * reflected in the collection, and vice-versa.  If the map is
  63.910 +     * modified while an iteration over the collection is in progress
  63.911 +     * (except through the iterator's own <tt>remove</tt> operation),
  63.912 +     * the results of the iteration are undefined.  The collection
  63.913 +     * supports element removal, which removes the corresponding
  63.914 +     * mapping from the map, via the <tt>Iterator.remove</tt>,
  63.915 +     * <tt>Collection.remove</tt>, <tt>removeAll</tt>,
  63.916 +     * <tt>retainAll</tt> and <tt>clear</tt> operations.  It does not
  63.917 +     * support the <tt>add</tt> or <tt>addAll</tt> operations.
  63.918 +     */
  63.919 +    public Collection<V> values() {
  63.920 +        Collection<V> vs = values;
  63.921 +        return (vs != null ? vs : (values = new Values()));
  63.922 +    }
  63.923 +
  63.924 +    private final class Values extends AbstractCollection<V> {
  63.925 +        public Iterator<V> iterator() {
  63.926 +            return newValueIterator();
  63.927 +        }
  63.928 +        public int size() {
  63.929 +            return size;
  63.930 +        }
  63.931 +        public boolean contains(Object o) {
  63.932 +            return containsValue(o);
  63.933 +        }
  63.934 +        public void clear() {
  63.935 +            HashMap.this.clear();
  63.936 +        }
  63.937 +    }
  63.938 +
  63.939 +    /**
  63.940 +     * Returns a {@link Set} view of the mappings contained in this map.
  63.941 +     * The set is backed by the map, so changes to the map are
  63.942 +     * reflected in the set, and vice-versa.  If the map is modified
  63.943 +     * while an iteration over the set is in progress (except through
  63.944 +     * the iterator's own <tt>remove</tt> operation, or through the
  63.945 +     * <tt>setValue</tt> operation on a map entry returned by the
  63.946 +     * iterator) the results of the iteration are undefined.  The set
  63.947 +     * supports element removal, which removes the corresponding
  63.948 +     * mapping from the map, via the <tt>Iterator.remove</tt>,
  63.949 +     * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
  63.950 +     * <tt>clear</tt> operations.  It does not support the
  63.951 +     * <tt>add</tt> or <tt>addAll</tt> operations.
  63.952 +     *
  63.953 +     * @return a set view of the mappings contained in this map
  63.954 +     */
  63.955 +    public Set<Map.Entry<K,V>> entrySet() {
  63.956 +        return entrySet0();
  63.957 +    }
  63.958 +
  63.959 +    private Set<Map.Entry<K,V>> entrySet0() {
  63.960 +        Set<Map.Entry<K,V>> es = entrySet;
  63.961 +        return es != null ? es : (entrySet = new EntrySet());
  63.962 +    }
  63.963 +
  63.964 +    private final class EntrySet extends AbstractSet<Map.Entry<K,V>> {
  63.965 +        public Iterator<Map.Entry<K,V>> iterator() {
  63.966 +            return newEntryIterator();
  63.967 +        }
  63.968 +        public boolean contains(Object o) {
  63.969 +            if (!(o instanceof Map.Entry))
  63.970 +                return false;
  63.971 +            Map.Entry<K,V> e = (Map.Entry<K,V>) o;
  63.972 +            Entry<K,V> candidate = getEntry(e.getKey());
  63.973 +            return candidate != null && candidate.equals(e);
  63.974 +        }
  63.975 +        public boolean remove(Object o) {
  63.976 +            return removeMapping(o) != null;
  63.977 +        }
  63.978 +        public int size() {
  63.979 +            return size;
  63.980 +        }
  63.981 +        public void clear() {
  63.982 +            HashMap.this.clear();
  63.983 +        }
  63.984 +    }
  63.985 +
  63.986 +
  63.987 +    private static final long serialVersionUID = 362498820763181265L;
  63.988 +
  63.989 +
  63.990 +    // These methods are used when serializing HashSets
  63.991 +    int   capacity()     { return table.length; }
  63.992 +    float loadFactor()   { return loadFactor;   }
  63.993 +}
    64.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    64.2 +++ b/emul/compact/src/main/java/java/util/HashSet.java	Sun Feb 03 07:48:42 2013 +0100
    64.3 @@ -0,0 +1,260 @@
    64.4 +/*
    64.5 + * Copyright (c) 1997, 2010, 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.util;
   64.30 +
   64.31 +/**
   64.32 + * This class implements the <tt>Set</tt> interface, backed by a hash table
   64.33 + * (actually a <tt>HashMap</tt> instance).  It makes no guarantees as to the
   64.34 + * iteration order of the set; in particular, it does not guarantee that the
   64.35 + * order will remain constant over time.  This class permits the <tt>null</tt>
   64.36 + * element.
   64.37 + *
   64.38 + * <p>This class offers constant time performance for the basic operations
   64.39 + * (<tt>add</tt>, <tt>remove</tt>, <tt>contains</tt> and <tt>size</tt>),
   64.40 + * assuming the hash function disperses the elements properly among the
   64.41 + * buckets.  Iterating over this set requires time proportional to the sum of
   64.42 + * the <tt>HashSet</tt> instance's size (the number of elements) plus the
   64.43 + * "capacity" of the backing <tt>HashMap</tt> instance (the number of
   64.44 + * buckets).  Thus, it's very important not to set the initial capacity too
   64.45 + * high (or the load factor too low) if iteration performance is important.
   64.46 + *
   64.47 + * <p><strong>Note that this implementation is not synchronized.</strong>
   64.48 + * If multiple threads access a hash set concurrently, and at least one of
   64.49 + * the threads modifies the set, it <i>must</i> be synchronized externally.
   64.50 + * This is typically accomplished by synchronizing on some object that
   64.51 + * naturally encapsulates the set.
   64.52 + *
   64.53 + * If no such object exists, the set should be "wrapped" using the
   64.54 + * {@link Collections#synchronizedSet Collections.synchronizedSet}
   64.55 + * method.  This is best done at creation time, to prevent accidental
   64.56 + * unsynchronized access to the set:<pre>
   64.57 + *   Set s = Collections.synchronizedSet(new HashSet(...));</pre>
   64.58 + *
   64.59 + * <p>The iterators returned by this class's <tt>iterator</tt> method are
   64.60 + * <i>fail-fast</i>: if the set is modified at any time after the iterator is
   64.61 + * created, in any way except through the iterator's own <tt>remove</tt>
   64.62 + * method, the Iterator throws a {@link ConcurrentModificationException}.
   64.63 + * Thus, in the face of concurrent modification, the iterator fails quickly
   64.64 + * and cleanly, rather than risking arbitrary, non-deterministic behavior at
   64.65 + * an undetermined time in the future.
   64.66 + *
   64.67 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
   64.68 + * as it is, generally speaking, impossible to make any hard guarantees in the
   64.69 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
   64.70 + * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
   64.71 + * Therefore, it would be wrong to write a program that depended on this
   64.72 + * exception for its correctness: <i>the fail-fast behavior of iterators
   64.73 + * should be used only to detect bugs.</i>
   64.74 + *
   64.75 + * <p>This class is a member of the
   64.76 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   64.77 + * Java Collections Framework</a>.
   64.78 + *
   64.79 + * @param <E> the type of elements maintained by this set
   64.80 + *
   64.81 + * @author  Josh Bloch
   64.82 + * @author  Neal Gafter
   64.83 + * @see     Collection
   64.84 + * @see     Set
   64.85 + * @see     TreeSet
   64.86 + * @see     HashMap
   64.87 + * @since   1.2
   64.88 + */
   64.89 +
   64.90 +public class HashSet<E>
   64.91 +    extends AbstractSet<E>
   64.92 +    implements Set<E>, Cloneable, java.io.Serializable
   64.93 +{
   64.94 +    static final long serialVersionUID = -5024744406713321676L;
   64.95 +
   64.96 +    private transient HashMap<E,Object> map;
   64.97 +
   64.98 +    // Dummy value to associate with an Object in the backing Map
   64.99 +    private static final Object PRESENT = new Object();
  64.100 +
  64.101 +    /**
  64.102 +     * Constructs a new, empty set; the backing <tt>HashMap</tt> instance has
  64.103 +     * default initial capacity (16) and load factor (0.75).
  64.104 +     */
  64.105 +    public HashSet() {
  64.106 +        map = new HashMap<>();
  64.107 +    }
  64.108 +
  64.109 +    /**
  64.110 +     * Constructs a new set containing the elements in the specified
  64.111 +     * collection.  The <tt>HashMap</tt> is created with default load factor
  64.112 +     * (0.75) and an initial capacity sufficient to contain the elements in
  64.113 +     * the specified collection.
  64.114 +     *
  64.115 +     * @param c the collection whose elements are to be placed into this set
  64.116 +     * @throws NullPointerException if the specified collection is null
  64.117 +     */
  64.118 +    public HashSet(Collection<? extends E> c) {
  64.119 +        map = new HashMap<>(Math.max((int) (c.size()/.75f) + 1, 16));
  64.120 +        addAll(c);
  64.121 +    }
  64.122 +
  64.123 +    /**
  64.124 +     * Constructs a new, empty set; the backing <tt>HashMap</tt> instance has
  64.125 +     * the specified initial capacity and the specified load factor.
  64.126 +     *
  64.127 +     * @param      initialCapacity   the initial capacity of the hash map
  64.128 +     * @param      loadFactor        the load factor of the hash map
  64.129 +     * @throws     IllegalArgumentException if the initial capacity is less
  64.130 +     *             than zero, or if the load factor is nonpositive
  64.131 +     */
  64.132 +    public HashSet(int initialCapacity, float loadFactor) {
  64.133 +        map = new HashMap<>(initialCapacity, loadFactor);
  64.134 +    }
  64.135 +
  64.136 +    /**
  64.137 +     * Constructs a new, empty set; the backing <tt>HashMap</tt> instance has
  64.138 +     * the specified initial capacity and default load factor (0.75).
  64.139 +     *
  64.140 +     * @param      initialCapacity   the initial capacity of the hash table
  64.141 +     * @throws     IllegalArgumentException if the initial capacity is less
  64.142 +     *             than zero
  64.143 +     */
  64.144 +    public HashSet(int initialCapacity) {
  64.145 +        map = new HashMap<>(initialCapacity);
  64.146 +    }
  64.147 +
  64.148 +    /**
  64.149 +     * Constructs a new, empty linked hash set.  (This package private
  64.150 +     * constructor is only used by LinkedHashSet.) The backing
  64.151 +     * HashMap instance is a LinkedHashMap with the specified initial
  64.152 +     * capacity and the specified load factor.
  64.153 +     *
  64.154 +     * @param      initialCapacity   the initial capacity of the hash map
  64.155 +     * @param      loadFactor        the load factor of the hash map
  64.156 +     * @param      dummy             ignored (distinguishes this
  64.157 +     *             constructor from other int, float constructor.)
  64.158 +     * @throws     IllegalArgumentException if the initial capacity is less
  64.159 +     *             than zero, or if the load factor is nonpositive
  64.160 +     */
  64.161 +    HashSet(int initialCapacity, float loadFactor, boolean dummy) {
  64.162 +        map = new LinkedHashMap<>(initialCapacity, loadFactor);
  64.163 +    }
  64.164 +
  64.165 +    /**
  64.166 +     * Returns an iterator over the elements in this set.  The elements
  64.167 +     * are returned in no particular order.
  64.168 +     *
  64.169 +     * @return an Iterator over the elements in this set
  64.170 +     * @see ConcurrentModificationException
  64.171 +     */
  64.172 +    public Iterator<E> iterator() {
  64.173 +        return map.keySet().iterator();
  64.174 +    }
  64.175 +
  64.176 +    /**
  64.177 +     * Returns the number of elements in this set (its cardinality).
  64.178 +     *
  64.179 +     * @return the number of elements in this set (its cardinality)
  64.180 +     */
  64.181 +    public int size() {
  64.182 +        return map.size();
  64.183 +    }
  64.184 +
  64.185 +    /**
  64.186 +     * Returns <tt>true</tt> if this set contains no elements.
  64.187 +     *
  64.188 +     * @return <tt>true</tt> if this set contains no elements
  64.189 +     */
  64.190 +    public boolean isEmpty() {
  64.191 +        return map.isEmpty();
  64.192 +    }
  64.193 +
  64.194 +    /**
  64.195 +     * Returns <tt>true</tt> if this set contains the specified element.
  64.196 +     * More formally, returns <tt>true</tt> if and only if this set
  64.197 +     * contains an element <tt>e</tt> such that
  64.198 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  64.199 +     *
  64.200 +     * @param o element whose presence in this set is to be tested
  64.201 +     * @return <tt>true</tt> if this set contains the specified element
  64.202 +     */
  64.203 +    public boolean contains(Object o) {
  64.204 +        return map.containsKey(o);
  64.205 +    }
  64.206 +
  64.207 +    /**
  64.208 +     * Adds the specified element to this set if it is not already present.
  64.209 +     * More formally, adds the specified element <tt>e</tt> to this set if
  64.210 +     * this set contains no element <tt>e2</tt> such that
  64.211 +     * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
  64.212 +     * If this set already contains the element, the call leaves the set
  64.213 +     * unchanged and returns <tt>false</tt>.
  64.214 +     *
  64.215 +     * @param e element to be added to this set
  64.216 +     * @return <tt>true</tt> if this set did not already contain the specified
  64.217 +     * element
  64.218 +     */
  64.219 +    public boolean add(E e) {
  64.220 +        return map.put(e, PRESENT)==null;
  64.221 +    }
  64.222 +
  64.223 +    /**
  64.224 +     * Removes the specified element from this set if it is present.
  64.225 +     * More formally, removes an element <tt>e</tt> such that
  64.226 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>,
  64.227 +     * if this set contains such an element.  Returns <tt>true</tt> if
  64.228 +     * this set contained the element (or equivalently, if this set
  64.229 +     * changed as a result of the call).  (This set will not contain the
  64.230 +     * element once the call returns.)
  64.231 +     *
  64.232 +     * @param o object to be removed from this set, if present
  64.233 +     * @return <tt>true</tt> if the set contained the specified element
  64.234 +     */
  64.235 +    public boolean remove(Object o) {
  64.236 +        return map.remove(o)==PRESENT;
  64.237 +    }
  64.238 +
  64.239 +    /**
  64.240 +     * Removes all of the elements from this set.
  64.241 +     * The set will be empty after this call returns.
  64.242 +     */
  64.243 +    public void clear() {
  64.244 +        map.clear();
  64.245 +    }
  64.246 +
  64.247 +    /**
  64.248 +     * Returns a shallow copy of this <tt>HashSet</tt> instance: the elements
  64.249 +     * themselves are not cloned.
  64.250 +     *
  64.251 +     * @return a shallow copy of this set
  64.252 +     */
  64.253 +    public Object clone() {
  64.254 +        try {
  64.255 +            HashSet<E> newSet = (HashSet<E>) super.clone();
  64.256 +            newSet.map = (HashMap<E, Object>) map.clone();
  64.257 +            return newSet;
  64.258 +        } catch (CloneNotSupportedException e) {
  64.259 +            throw new InternalError();
  64.260 +        }
  64.261 +    }
  64.262 +
  64.263 +}
    65.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    65.2 +++ b/emul/compact/src/main/java/java/util/Hashtable.java	Sun Feb 03 07:48:42 2013 +0100
    65.3 @@ -0,0 +1,1005 @@
    65.4 +/*
    65.5 + * Copyright (c) 1994, 2011, 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.util;
   65.30 +import java.io.*;
   65.31 +
   65.32 +/**
   65.33 + * This class implements a hash table, which maps keys to values. Any
   65.34 + * non-<code>null</code> object can be used as a key or as a value. <p>
   65.35 + *
   65.36 + * To successfully store and retrieve objects from a hashtable, the
   65.37 + * objects used as keys must implement the <code>hashCode</code>
   65.38 + * method and the <code>equals</code> method. <p>
   65.39 + *
   65.40 + * An instance of <code>Hashtable</code> has two parameters that affect its
   65.41 + * performance: <i>initial capacity</i> and <i>load factor</i>.  The
   65.42 + * <i>capacity</i> is the number of <i>buckets</i> in the hash table, and the
   65.43 + * <i>initial capacity</i> is simply the capacity at the time the hash table
   65.44 + * is created.  Note that the hash table is <i>open</i>: in the case of a "hash
   65.45 + * collision", a single bucket stores multiple entries, which must be searched
   65.46 + * sequentially.  The <i>load factor</i> is a measure of how full the hash
   65.47 + * table is allowed to get before its capacity is automatically increased.
   65.48 + * The initial capacity and load factor parameters are merely hints to
   65.49 + * the implementation.  The exact details as to when and whether the rehash
   65.50 + * method is invoked are implementation-dependent.<p>
   65.51 + *
   65.52 + * Generally, the default load factor (.75) offers a good tradeoff between
   65.53 + * time and space costs.  Higher values decrease the space overhead but
   65.54 + * increase the time cost to look up an entry (which is reflected in most
   65.55 + * <tt>Hashtable</tt> operations, including <tt>get</tt> and <tt>put</tt>).<p>
   65.56 + *
   65.57 + * The initial capacity controls a tradeoff between wasted space and the
   65.58 + * need for <code>rehash</code> operations, which are time-consuming.
   65.59 + * No <code>rehash</code> operations will <i>ever</i> occur if the initial
   65.60 + * capacity is greater than the maximum number of entries the
   65.61 + * <tt>Hashtable</tt> will contain divided by its load factor.  However,
   65.62 + * setting the initial capacity too high can waste space.<p>
   65.63 + *
   65.64 + * If many entries are to be made into a <code>Hashtable</code>,
   65.65 + * creating it with a sufficiently large capacity may allow the
   65.66 + * entries to be inserted more efficiently than letting it perform
   65.67 + * automatic rehashing as needed to grow the table. <p>
   65.68 + *
   65.69 + * This example creates a hashtable of numbers. It uses the names of
   65.70 + * the numbers as keys:
   65.71 + * <pre>   {@code
   65.72 + *   Hashtable<String, Integer> numbers
   65.73 + *     = new Hashtable<String, Integer>();
   65.74 + *   numbers.put("one", 1);
   65.75 + *   numbers.put("two", 2);
   65.76 + *   numbers.put("three", 3);}</pre>
   65.77 + *
   65.78 + * <p>To retrieve a number, use the following code:
   65.79 + * <pre>   {@code
   65.80 + *   Integer n = numbers.get("two");
   65.81 + *   if (n != null) {
   65.82 + *     System.out.println("two = " + n);
   65.83 + *   }}</pre>
   65.84 + *
   65.85 + * <p>The iterators returned by the <tt>iterator</tt> method of the collections
   65.86 + * returned by all of this class's "collection view methods" are
   65.87 + * <em>fail-fast</em>: if the Hashtable is structurally modified at any time
   65.88 + * after the iterator is created, in any way except through the iterator's own
   65.89 + * <tt>remove</tt> method, the iterator will throw a {@link
   65.90 + * ConcurrentModificationException}.  Thus, in the face of concurrent
   65.91 + * modification, the iterator fails quickly and cleanly, rather than risking
   65.92 + * arbitrary, non-deterministic behavior at an undetermined time in the future.
   65.93 + * The Enumerations returned by Hashtable's keys and elements methods are
   65.94 + * <em>not</em> fail-fast.
   65.95 + *
   65.96 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
   65.97 + * as it is, generally speaking, impossible to make any hard guarantees in the
   65.98 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
   65.99 + * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
  65.100 + * Therefore, it would be wrong to write a program that depended on this
  65.101 + * exception for its correctness: <i>the fail-fast behavior of iterators
  65.102 + * should be used only to detect bugs.</i>
  65.103 + *
  65.104 + * <p>As of the Java 2 platform v1.2, this class was retrofitted to
  65.105 + * implement the {@link Map} interface, making it a member of the
  65.106 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  65.107 + *
  65.108 + * Java Collections Framework</a>.  Unlike the new collection
  65.109 + * implementations, {@code Hashtable} is synchronized.  If a
  65.110 + * thread-safe implementation is not needed, it is recommended to use
  65.111 + * {@link HashMap} in place of {@code Hashtable}.  If a thread-safe
  65.112 + * highly-concurrent implementation is desired, then it is recommended
  65.113 + * to use {@link java.util.concurrent.ConcurrentHashMap} in place of
  65.114 + * {@code Hashtable}.
  65.115 + *
  65.116 + * @author  Arthur van Hoff
  65.117 + * @author  Josh Bloch
  65.118 + * @author  Neal Gafter
  65.119 + * @see     Object#equals(java.lang.Object)
  65.120 + * @see     Object#hashCode()
  65.121 + * @see     Hashtable#rehash()
  65.122 + * @see     Collection
  65.123 + * @see     Map
  65.124 + * @see     HashMap
  65.125 + * @see     TreeMap
  65.126 + * @since JDK1.0
  65.127 + */
  65.128 +public class Hashtable<K,V>
  65.129 +    extends Dictionary<K,V>
  65.130 +    implements Map<K,V>, Cloneable, java.io.Serializable {
  65.131 +
  65.132 +    /**
  65.133 +     * The hash table data.
  65.134 +     */
  65.135 +    private transient Entry[] table;
  65.136 +
  65.137 +    /**
  65.138 +     * The total number of entries in the hash table.
  65.139 +     */
  65.140 +    private transient int count;
  65.141 +
  65.142 +    /**
  65.143 +     * The table is rehashed when its size exceeds this threshold.  (The
  65.144 +     * value of this field is (int)(capacity * loadFactor).)
  65.145 +     *
  65.146 +     * @serial
  65.147 +     */
  65.148 +    private int threshold;
  65.149 +
  65.150 +    /**
  65.151 +     * The load factor for the hashtable.
  65.152 +     *
  65.153 +     * @serial
  65.154 +     */
  65.155 +    private float loadFactor;
  65.156 +
  65.157 +    /**
  65.158 +     * The number of times this Hashtable has been structurally modified
  65.159 +     * Structural modifications are those that change the number of entries in
  65.160 +     * the Hashtable or otherwise modify its internal structure (e.g.,
  65.161 +     * rehash).  This field is used to make iterators on Collection-views of
  65.162 +     * the Hashtable fail-fast.  (See ConcurrentModificationException).
  65.163 +     */
  65.164 +    private transient int modCount = 0;
  65.165 +
  65.166 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
  65.167 +    private static final long serialVersionUID = 1421746759512286392L;
  65.168 +
  65.169 +    /**
  65.170 +     * Constructs a new, empty hashtable with the specified initial
  65.171 +     * capacity and the specified load factor.
  65.172 +     *
  65.173 +     * @param      initialCapacity   the initial capacity of the hashtable.
  65.174 +     * @param      loadFactor        the load factor of the hashtable.
  65.175 +     * @exception  IllegalArgumentException  if the initial capacity is less
  65.176 +     *             than zero, or if the load factor is nonpositive.
  65.177 +     */
  65.178 +    public Hashtable(int initialCapacity, float loadFactor) {
  65.179 +        if (initialCapacity < 0)
  65.180 +            throw new IllegalArgumentException("Illegal Capacity: "+
  65.181 +                                               initialCapacity);
  65.182 +        if (loadFactor <= 0 || Float.isNaN(loadFactor))
  65.183 +            throw new IllegalArgumentException("Illegal Load: "+loadFactor);
  65.184 +
  65.185 +        if (initialCapacity==0)
  65.186 +            initialCapacity = 1;
  65.187 +        this.loadFactor = loadFactor;
  65.188 +        table = new Entry[initialCapacity];
  65.189 +        threshold = (int)(initialCapacity * loadFactor);
  65.190 +    }
  65.191 +
  65.192 +    /**
  65.193 +     * Constructs a new, empty hashtable with the specified initial capacity
  65.194 +     * and default load factor (0.75).
  65.195 +     *
  65.196 +     * @param     initialCapacity   the initial capacity of the hashtable.
  65.197 +     * @exception IllegalArgumentException if the initial capacity is less
  65.198 +     *              than zero.
  65.199 +     */
  65.200 +    public Hashtable(int initialCapacity) {
  65.201 +        this(initialCapacity, 0.75f);
  65.202 +    }
  65.203 +
  65.204 +    /**
  65.205 +     * Constructs a new, empty hashtable with a default initial capacity (11)
  65.206 +     * and load factor (0.75).
  65.207 +     */
  65.208 +    public Hashtable() {
  65.209 +        this(11, 0.75f);
  65.210 +    }
  65.211 +
  65.212 +    /**
  65.213 +     * Constructs a new hashtable with the same mappings as the given
  65.214 +     * Map.  The hashtable is created with an initial capacity sufficient to
  65.215 +     * hold the mappings in the given Map and a default load factor (0.75).
  65.216 +     *
  65.217 +     * @param t the map whose mappings are to be placed in this map.
  65.218 +     * @throws NullPointerException if the specified map is null.
  65.219 +     * @since   1.2
  65.220 +     */
  65.221 +    public Hashtable(Map<? extends K, ? extends V> t) {
  65.222 +        this(Math.max(2*t.size(), 11), 0.75f);
  65.223 +        putAll(t);
  65.224 +    }
  65.225 +
  65.226 +    /**
  65.227 +     * Returns the number of keys in this hashtable.
  65.228 +     *
  65.229 +     * @return  the number of keys in this hashtable.
  65.230 +     */
  65.231 +    public synchronized int size() {
  65.232 +        return count;
  65.233 +    }
  65.234 +
  65.235 +    /**
  65.236 +     * Tests if this hashtable maps no keys to values.
  65.237 +     *
  65.238 +     * @return  <code>true</code> if this hashtable maps no keys to values;
  65.239 +     *          <code>false</code> otherwise.
  65.240 +     */
  65.241 +    public synchronized boolean isEmpty() {
  65.242 +        return count == 0;
  65.243 +    }
  65.244 +
  65.245 +    /**
  65.246 +     * Returns an enumeration of the keys in this hashtable.
  65.247 +     *
  65.248 +     * @return  an enumeration of the keys in this hashtable.
  65.249 +     * @see     Enumeration
  65.250 +     * @see     #elements()
  65.251 +     * @see     #keySet()
  65.252 +     * @see     Map
  65.253 +     */
  65.254 +    public synchronized Enumeration<K> keys() {
  65.255 +        return this.<K>getEnumeration(KEYS);
  65.256 +    }
  65.257 +
  65.258 +    /**
  65.259 +     * Returns an enumeration of the values in this hashtable.
  65.260 +     * Use the Enumeration methods on the returned object to fetch the elements
  65.261 +     * sequentially.
  65.262 +     *
  65.263 +     * @return  an enumeration of the values in this hashtable.
  65.264 +     * @see     java.util.Enumeration
  65.265 +     * @see     #keys()
  65.266 +     * @see     #values()
  65.267 +     * @see     Map
  65.268 +     */
  65.269 +    public synchronized Enumeration<V> elements() {
  65.270 +        return this.<V>getEnumeration(VALUES);
  65.271 +    }
  65.272 +
  65.273 +    /**
  65.274 +     * Tests if some key maps into the specified value in this hashtable.
  65.275 +     * This operation is more expensive than the {@link #containsKey
  65.276 +     * containsKey} method.
  65.277 +     *
  65.278 +     * <p>Note that this method is identical in functionality to
  65.279 +     * {@link #containsValue containsValue}, (which is part of the
  65.280 +     * {@link Map} interface in the collections framework).
  65.281 +     *
  65.282 +     * @param      value   a value to search for
  65.283 +     * @return     <code>true</code> if and only if some key maps to the
  65.284 +     *             <code>value</code> argument in this hashtable as
  65.285 +     *             determined by the <tt>equals</tt> method;
  65.286 +     *             <code>false</code> otherwise.
  65.287 +     * @exception  NullPointerException  if the value is <code>null</code>
  65.288 +     */
  65.289 +    public synchronized boolean contains(Object value) {
  65.290 +        if (value == null) {
  65.291 +            throw new NullPointerException();
  65.292 +        }
  65.293 +
  65.294 +        Entry tab[] = table;
  65.295 +        for (int i = tab.length ; i-- > 0 ;) {
  65.296 +            for (Entry<K,V> e = tab[i] ; e != null ; e = e.next) {
  65.297 +                if (e.value.equals(value)) {
  65.298 +                    return true;
  65.299 +                }
  65.300 +            }
  65.301 +        }
  65.302 +        return false;
  65.303 +    }
  65.304 +
  65.305 +    /**
  65.306 +     * Returns true if this hashtable maps one or more keys to this value.
  65.307 +     *
  65.308 +     * <p>Note that this method is identical in functionality to {@link
  65.309 +     * #contains contains} (which predates the {@link Map} interface).
  65.310 +     *
  65.311 +     * @param value value whose presence in this hashtable is to be tested
  65.312 +     * @return <tt>true</tt> if this map maps one or more keys to the
  65.313 +     *         specified value
  65.314 +     * @throws NullPointerException  if the value is <code>null</code>
  65.315 +     * @since 1.2
  65.316 +     */
  65.317 +    public boolean containsValue(Object value) {
  65.318 +        return contains(value);
  65.319 +    }
  65.320 +
  65.321 +    /**
  65.322 +     * Tests if the specified object is a key in this hashtable.
  65.323 +     *
  65.324 +     * @param   key   possible key
  65.325 +     * @return  <code>true</code> if and only if the specified object
  65.326 +     *          is a key in this hashtable, as determined by the
  65.327 +     *          <tt>equals</tt> method; <code>false</code> otherwise.
  65.328 +     * @throws  NullPointerException  if the key is <code>null</code>
  65.329 +     * @see     #contains(Object)
  65.330 +     */
  65.331 +    public synchronized boolean containsKey(Object key) {
  65.332 +        Entry tab[] = table;
  65.333 +        int hash = key.hashCode();
  65.334 +        int index = (hash & 0x7FFFFFFF) % tab.length;
  65.335 +        for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
  65.336 +            if ((e.hash == hash) && e.key.equals(key)) {
  65.337 +                return true;
  65.338 +            }
  65.339 +        }
  65.340 +        return false;
  65.341 +    }
  65.342 +
  65.343 +    /**
  65.344 +     * Returns the value to which the specified key is mapped,
  65.345 +     * or {@code null} if this map contains no mapping for the key.
  65.346 +     *
  65.347 +     * <p>More formally, if this map contains a mapping from a key
  65.348 +     * {@code k} to a value {@code v} such that {@code (key.equals(k))},
  65.349 +     * then this method returns {@code v}; otherwise it returns
  65.350 +     * {@code null}.  (There can be at most one such mapping.)
  65.351 +     *
  65.352 +     * @param key the key whose associated value is to be returned
  65.353 +     * @return the value to which the specified key is mapped, or
  65.354 +     *         {@code null} if this map contains no mapping for the key
  65.355 +     * @throws NullPointerException if the specified key is null
  65.356 +     * @see     #put(Object, Object)
  65.357 +     */
  65.358 +    public synchronized V get(Object key) {
  65.359 +        Entry tab[] = table;
  65.360 +        int hash = key.hashCode();
  65.361 +        int index = (hash & 0x7FFFFFFF) % tab.length;
  65.362 +        for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
  65.363 +            if ((e.hash == hash) && e.key.equals(key)) {
  65.364 +                return e.value;
  65.365 +            }
  65.366 +        }
  65.367 +        return null;
  65.368 +    }
  65.369 +
  65.370 +    /**
  65.371 +     * The maximum size of array to allocate.
  65.372 +     * Some VMs reserve some header words in an array.
  65.373 +     * Attempts to allocate larger arrays may result in
  65.374 +     * OutOfMemoryError: Requested array size exceeds VM limit
  65.375 +     */
  65.376 +    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
  65.377 +
  65.378 +    /**
  65.379 +     * Increases the capacity of and internally reorganizes this
  65.380 +     * hashtable, in order to accommodate and access its entries more
  65.381 +     * efficiently.  This method is called automatically when the
  65.382 +     * number of keys in the hashtable exceeds this hashtable's capacity
  65.383 +     * and load factor.
  65.384 +     */
  65.385 +    protected void rehash() {
  65.386 +        int oldCapacity = table.length;
  65.387 +        Entry[] oldMap = table;
  65.388 +
  65.389 +        // overflow-conscious code
  65.390 +        int newCapacity = (oldCapacity << 1) + 1;
  65.391 +        if (newCapacity - MAX_ARRAY_SIZE > 0) {
  65.392 +            if (oldCapacity == MAX_ARRAY_SIZE)
  65.393 +                // Keep running with MAX_ARRAY_SIZE buckets
  65.394 +                return;
  65.395 +            newCapacity = MAX_ARRAY_SIZE;
  65.396 +        }
  65.397 +        Entry[] newMap = new Entry[newCapacity];
  65.398 +
  65.399 +        modCount++;
  65.400 +        threshold = (int)(newCapacity * loadFactor);
  65.401 +        table = newMap;
  65.402 +
  65.403 +        for (int i = oldCapacity ; i-- > 0 ;) {
  65.404 +            for (Entry<K,V> old = oldMap[i] ; old != null ; ) {
  65.405 +                Entry<K,V> e = old;
  65.406 +                old = old.next;
  65.407 +
  65.408 +                int index = (e.hash & 0x7FFFFFFF) % newCapacity;
  65.409 +                e.next = newMap[index];
  65.410 +                newMap[index] = e;
  65.411 +            }
  65.412 +        }
  65.413 +    }
  65.414 +
  65.415 +    /**
  65.416 +     * Maps the specified <code>key</code> to the specified
  65.417 +     * <code>value</code> in this hashtable. Neither the key nor the
  65.418 +     * value can be <code>null</code>. <p>
  65.419 +     *
  65.420 +     * The value can be retrieved by calling the <code>get</code> method
  65.421 +     * with a key that is equal to the original key.
  65.422 +     *
  65.423 +     * @param      key     the hashtable key
  65.424 +     * @param      value   the value
  65.425 +     * @return     the previous value of the specified key in this hashtable,
  65.426 +     *             or <code>null</code> if it did not have one
  65.427 +     * @exception  NullPointerException  if the key or value is
  65.428 +     *               <code>null</code>
  65.429 +     * @see     Object#equals(Object)
  65.430 +     * @see     #get(Object)
  65.431 +     */
  65.432 +    public synchronized V put(K key, V value) {
  65.433 +        // Make sure the value is not null
  65.434 +        if (value == null) {
  65.435 +            throw new NullPointerException();
  65.436 +        }
  65.437 +
  65.438 +        // Makes sure the key is not already in the hashtable.
  65.439 +        Entry tab[] = table;
  65.440 +        int hash = key.hashCode();
  65.441 +        int index = (hash & 0x7FFFFFFF) % tab.length;
  65.442 +        for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
  65.443 +            if ((e.hash == hash) && e.key.equals(key)) {
  65.444 +                V old = e.value;
  65.445 +                e.value = value;
  65.446 +                return old;
  65.447 +            }
  65.448 +        }
  65.449 +
  65.450 +        modCount++;
  65.451 +        if (count >= threshold) {
  65.452 +            // Rehash the table if the threshold is exceeded
  65.453 +            rehash();
  65.454 +
  65.455 +            tab = table;
  65.456 +            index = (hash & 0x7FFFFFFF) % tab.length;
  65.457 +        }
  65.458 +
  65.459 +        // Creates the new entry.
  65.460 +        Entry<K,V> e = tab[index];
  65.461 +        tab[index] = new Entry<>(hash, key, value, e);
  65.462 +        count++;
  65.463 +        return null;
  65.464 +    }
  65.465 +
  65.466 +    /**
  65.467 +     * Removes the key (and its corresponding value) from this
  65.468 +     * hashtable. This method does nothing if the key is not in the hashtable.
  65.469 +     *
  65.470 +     * @param   key   the key that needs to be removed
  65.471 +     * @return  the value to which the key had been mapped in this hashtable,
  65.472 +     *          or <code>null</code> if the key did not have a mapping
  65.473 +     * @throws  NullPointerException  if the key is <code>null</code>
  65.474 +     */
  65.475 +    public synchronized V remove(Object key) {
  65.476 +        Entry tab[] = table;
  65.477 +        int hash = key.hashCode();
  65.478 +        int index = (hash & 0x7FFFFFFF) % tab.length;
  65.479 +        for (Entry<K,V> e = tab[index], prev = null ; e != null ; prev = e, e = e.next) {
  65.480 +            if ((e.hash == hash) && e.key.equals(key)) {
  65.481 +                modCount++;
  65.482 +                if (prev != null) {
  65.483 +                    prev.next = e.next;
  65.484 +                } else {
  65.485 +                    tab[index] = e.next;
  65.486 +                }
  65.487 +                count--;
  65.488 +                V oldValue = e.value;
  65.489 +                e.value = null;
  65.490 +                return oldValue;
  65.491 +            }
  65.492 +        }
  65.493 +        return null;
  65.494 +    }
  65.495 +
  65.496 +    /**
  65.497 +     * Copies all of the mappings from the specified map to this hashtable.
  65.498 +     * These mappings will replace any mappings that this hashtable had for any
  65.499 +     * of the keys currently in the specified map.
  65.500 +     *
  65.501 +     * @param t mappings to be stored in this map
  65.502 +     * @throws NullPointerException if the specified map is null
  65.503 +     * @since 1.2
  65.504 +     */
  65.505 +    public synchronized void putAll(Map<? extends K, ? extends V> t) {
  65.506 +        for (Map.Entry<? extends K, ? extends V> e : t.entrySet())
  65.507 +            put(e.getKey(), e.getValue());
  65.508 +    }
  65.509 +
  65.510 +    /**
  65.511 +     * Clears this hashtable so that it contains no keys.
  65.512 +     */
  65.513 +    public synchronized void clear() {
  65.514 +        Entry tab[] = table;
  65.515 +        modCount++;
  65.516 +        for (int index = tab.length; --index >= 0; )
  65.517 +            tab[index] = null;
  65.518 +        count = 0;
  65.519 +    }
  65.520 +
  65.521 +    /**
  65.522 +     * Creates a shallow copy of this hashtable. All the structure of the
  65.523 +     * hashtable itself is copied, but the keys and values are not cloned.
  65.524 +     * This is a relatively expensive operation.
  65.525 +     *
  65.526 +     * @return  a clone of the hashtable
  65.527 +     */
  65.528 +    public synchronized Object clone() {
  65.529 +        try {
  65.530 +            Hashtable<K,V> t = (Hashtable<K,V>) super.clone();
  65.531 +            t.table = new Entry[table.length];
  65.532 +            for (int i = table.length ; i-- > 0 ; ) {
  65.533 +                t.table[i] = (table[i] != null)
  65.534 +                    ? (Entry<K,V>) table[i].clone() : null;
  65.535 +            }
  65.536 +            t.keySet = null;
  65.537 +            t.entrySet = null;
  65.538 +            t.values = null;
  65.539 +            t.modCount = 0;
  65.540 +            return t;
  65.541 +        } catch (CloneNotSupportedException e) {
  65.542 +            // this shouldn't happen, since we are Cloneable
  65.543 +            throw new InternalError();
  65.544 +        }
  65.545 +    }
  65.546 +
  65.547 +    /**
  65.548 +     * Returns a string representation of this <tt>Hashtable</tt> object
  65.549 +     * in the form of a set of entries, enclosed in braces and separated
  65.550 +     * by the ASCII characters "<tt>,&nbsp;</tt>" (comma and space). Each
  65.551 +     * entry is rendered as the key, an equals sign <tt>=</tt>, and the
  65.552 +     * associated element, where the <tt>toString</tt> method is used to
  65.553 +     * convert the key and element to strings.
  65.554 +     *
  65.555 +     * @return  a string representation of this hashtable
  65.556 +     */
  65.557 +    public synchronized String toString() {
  65.558 +        int max = size() - 1;
  65.559 +        if (max == -1)
  65.560 +            return "{}";
  65.561 +
  65.562 +        StringBuilder sb = new StringBuilder();
  65.563 +        Iterator<Map.Entry<K,V>> it = entrySet().iterator();
  65.564 +
  65.565 +        sb.append('{');
  65.566 +        for (int i = 0; ; i++) {
  65.567 +            Map.Entry<K,V> e = it.next();
  65.568 +            K key = e.getKey();
  65.569 +            V value = e.getValue();
  65.570 +            sb.append(key   == this ? "(this Map)" : key.toString());
  65.571 +            sb.append('=');
  65.572 +            sb.append(value == this ? "(this Map)" : value.toString());
  65.573 +
  65.574 +            if (i == max)
  65.575 +                return sb.append('}').toString();
  65.576 +            sb.append(", ");
  65.577 +        }
  65.578 +    }
  65.579 +
  65.580 +
  65.581 +    private <T> Enumeration<T> getEnumeration(int type) {
  65.582 +        if (count == 0) {
  65.583 +            return Collections.emptyEnumeration();
  65.584 +        } else {
  65.585 +            return new Enumerator<>(type, false);
  65.586 +        }
  65.587 +    }
  65.588 +
  65.589 +    private <T> Iterator<T> getIterator(int type) {
  65.590 +        if (count == 0) {
  65.591 +            return Collections.emptyIterator();
  65.592 +        } else {
  65.593 +            return new Enumerator<>(type, true);
  65.594 +        }
  65.595 +    }
  65.596 +
  65.597 +    // Views
  65.598 +
  65.599 +    /**
  65.600 +     * Each of these fields are initialized to contain an instance of the
  65.601 +     * appropriate view the first time this view is requested.  The views are
  65.602 +     * stateless, so there's no reason to create more than one of each.
  65.603 +     */
  65.604 +    private transient volatile Set<K> keySet = null;
  65.605 +    private transient volatile Set<Map.Entry<K,V>> entrySet = null;
  65.606 +    private transient volatile Collection<V> values = null;
  65.607 +
  65.608 +    /**
  65.609 +     * Returns a {@link Set} view of the keys contained in this map.
  65.610 +     * The set is backed by the map, so changes to the map are
  65.611 +     * reflected in the set, and vice-versa.  If the map is modified
  65.612 +     * while an iteration over the set is in progress (except through
  65.613 +     * the iterator's own <tt>remove</tt> operation), the results of
  65.614 +     * the iteration are undefined.  The set supports element removal,
  65.615 +     * which removes the corresponding mapping from the map, via the
  65.616 +     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
  65.617 +     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
  65.618 +     * operations.  It does not support the <tt>add</tt> or <tt>addAll</tt>
  65.619 +     * operations.
  65.620 +     *
  65.621 +     * @since 1.2
  65.622 +     */
  65.623 +    public Set<K> keySet() {
  65.624 +        if (keySet == null)
  65.625 +            keySet = Collections.synchronizedSet(new KeySet(), this);
  65.626 +        return keySet;
  65.627 +    }
  65.628 +
  65.629 +    private class KeySet extends AbstractSet<K> {
  65.630 +        public Iterator<K> iterator() {
  65.631 +            return getIterator(KEYS);
  65.632 +        }
  65.633 +        public int size() {
  65.634 +            return count;
  65.635 +        }
  65.636 +        public boolean contains(Object o) {
  65.637 +            return containsKey(o);
  65.638 +        }
  65.639 +        public boolean remove(Object o) {
  65.640 +            return Hashtable.this.remove(o) != null;
  65.641 +        }
  65.642 +        public void clear() {
  65.643 +            Hashtable.this.clear();
  65.644 +        }
  65.645 +    }
  65.646 +
  65.647 +    /**
  65.648 +     * Returns a {@link Set} view of the mappings contained in this map.
  65.649 +     * The set is backed by the map, so changes to the map are
  65.650 +     * reflected in the set, and vice-versa.  If the map is modified
  65.651 +     * while an iteration over the set is in progress (except through
  65.652 +     * the iterator's own <tt>remove</tt> operation, or through the
  65.653 +     * <tt>setValue</tt> operation on a map entry returned by the
  65.654 +     * iterator) the results of the iteration are undefined.  The set
  65.655 +     * supports element removal, which removes the corresponding
  65.656 +     * mapping from the map, via the <tt>Iterator.remove</tt>,
  65.657 +     * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
  65.658 +     * <tt>clear</tt> operations.  It does not support the
  65.659 +     * <tt>add</tt> or <tt>addAll</tt> operations.
  65.660 +     *
  65.661 +     * @since 1.2
  65.662 +     */
  65.663 +    public Set<Map.Entry<K,V>> entrySet() {
  65.664 +        if (entrySet==null)
  65.665 +            entrySet = Collections.synchronizedSet(new EntrySet(), this);
  65.666 +        return entrySet;
  65.667 +    }
  65.668 +
  65.669 +    private class EntrySet extends AbstractSet<Map.Entry<K,V>> {
  65.670 +        public Iterator<Map.Entry<K,V>> iterator() {
  65.671 +            return getIterator(ENTRIES);
  65.672 +        }
  65.673 +
  65.674 +        public boolean add(Map.Entry<K,V> o) {
  65.675 +            return super.add(o);
  65.676 +        }
  65.677 +
  65.678 +        public boolean contains(Object o) {
  65.679 +            if (!(o instanceof Map.Entry))
  65.680 +                return false;
  65.681 +            Map.Entry entry = (Map.Entry)o;
  65.682 +            Object key = entry.getKey();
  65.683 +            Entry[] tab = table;
  65.684 +            int hash = key.hashCode();
  65.685 +            int index = (hash & 0x7FFFFFFF) % tab.length;
  65.686 +
  65.687 +            for (Entry e = tab[index]; e != null; e = e.next)
  65.688 +                if (e.hash==hash && e.equals(entry))
  65.689 +                    return true;
  65.690 +            return false;
  65.691 +        }
  65.692 +
  65.693 +        public boolean remove(Object o) {
  65.694 +            if (!(o instanceof Map.Entry))
  65.695 +                return false;
  65.696 +            Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
  65.697 +            K key = entry.getKey();
  65.698 +            Entry[] tab = table;
  65.699 +            int hash = key.hashCode();
  65.700 +            int index = (hash & 0x7FFFFFFF) % tab.length;
  65.701 +
  65.702 +            for (Entry<K,V> e = tab[index], prev = null; e != null;
  65.703 +                 prev = e, e = e.next) {
  65.704 +                if (e.hash==hash && e.equals(entry)) {
  65.705 +                    modCount++;
  65.706 +                    if (prev != null)
  65.707 +                        prev.next = e.next;
  65.708 +                    else
  65.709 +                        tab[index] = e.next;
  65.710 +
  65.711 +                    count--;
  65.712 +                    e.value = null;
  65.713 +                    return true;
  65.714 +                }
  65.715 +            }
  65.716 +            return false;
  65.717 +        }
  65.718 +
  65.719 +        public int size() {
  65.720 +            return count;
  65.721 +        }
  65.722 +
  65.723 +        public void clear() {
  65.724 +            Hashtable.this.clear();
  65.725 +        }
  65.726 +    }
  65.727 +
  65.728 +    /**
  65.729 +     * Returns a {@link Collection} view of the values contained in this map.
  65.730 +     * The collection is backed by the map, so changes to the map are
  65.731 +     * reflected in the collection, and vice-versa.  If the map is
  65.732 +     * modified while an iteration over the collection is in progress
  65.733 +     * (except through the iterator's own <tt>remove</tt> operation),
  65.734 +     * the results of the iteration are undefined.  The collection
  65.735 +     * supports element removal, which removes the corresponding
  65.736 +     * mapping from the map, via the <tt>Iterator.remove</tt>,
  65.737 +     * <tt>Collection.remove</tt>, <tt>removeAll</tt>,
  65.738 +     * <tt>retainAll</tt> and <tt>clear</tt> operations.  It does not
  65.739 +     * support the <tt>add</tt> or <tt>addAll</tt> operations.
  65.740 +     *
  65.741 +     * @since 1.2
  65.742 +     */
  65.743 +    public Collection<V> values() {
  65.744 +        if (values==null)
  65.745 +            values = Collections.synchronizedCollection(new ValueCollection(),
  65.746 +                                                        this);
  65.747 +        return values;
  65.748 +    }
  65.749 +
  65.750 +    private class ValueCollection extends AbstractCollection<V> {
  65.751 +        public Iterator<V> iterator() {
  65.752 +            return getIterator(VALUES);
  65.753 +        }
  65.754 +        public int size() {
  65.755 +            return count;
  65.756 +        }
  65.757 +        public boolean contains(Object o) {
  65.758 +            return containsValue(o);
  65.759 +        }
  65.760 +        public void clear() {
  65.761 +            Hashtable.this.clear();
  65.762 +        }
  65.763 +    }
  65.764 +
  65.765 +    // Comparison and hashing
  65.766 +
  65.767 +    /**
  65.768 +     * Compares the specified Object with this Map for equality,
  65.769 +     * as per the definition in the Map interface.
  65.770 +     *
  65.771 +     * @param  o object to be compared for equality with this hashtable
  65.772 +     * @return true if the specified Object is equal to this Map
  65.773 +     * @see Map#equals(Object)
  65.774 +     * @since 1.2
  65.775 +     */
  65.776 +    public synchronized boolean equals(Object o) {
  65.777 +        if (o == this)
  65.778 +            return true;
  65.779 +
  65.780 +        if (!(o instanceof Map))
  65.781 +            return false;
  65.782 +        Map<K,V> t = (Map<K,V>) o;
  65.783 +        if (t.size() != size())
  65.784 +            return false;
  65.785 +
  65.786 +        try {
  65.787 +            Iterator<Map.Entry<K,V>> i = entrySet().iterator();
  65.788 +            while (i.hasNext()) {
  65.789 +                Map.Entry<K,V> e = i.next();
  65.790 +                K key = e.getKey();
  65.791 +                V value = e.getValue();
  65.792 +                if (value == null) {
  65.793 +                    if (!(t.get(key)==null && t.containsKey(key)))
  65.794 +                        return false;
  65.795 +                } else {
  65.796 +                    if (!value.equals(t.get(key)))
  65.797 +                        return false;
  65.798 +                }
  65.799 +            }
  65.800 +        } catch (ClassCastException unused)   {
  65.801 +            return false;
  65.802 +        } catch (NullPointerException unused) {
  65.803 +            return false;
  65.804 +        }
  65.805 +
  65.806 +        return true;
  65.807 +    }
  65.808 +
  65.809 +    /**
  65.810 +     * Returns the hash code value for this Map as per the definition in the
  65.811 +     * Map interface.
  65.812 +     *
  65.813 +     * @see Map#hashCode()
  65.814 +     * @since 1.2
  65.815 +     */
  65.816 +    public synchronized int hashCode() {
  65.817 +        /*
  65.818 +         * This code detects the recursion caused by computing the hash code
  65.819 +         * of a self-referential hash table and prevents the stack overflow
  65.820 +         * that would otherwise result.  This allows certain 1.1-era
  65.821 +         * applets with self-referential hash tables to work.  This code
  65.822 +         * abuses the loadFactor field to do double-duty as a hashCode
  65.823 +         * in progress flag, so as not to worsen the space performance.
  65.824 +         * A negative load factor indicates that hash code computation is
  65.825 +         * in progress.
  65.826 +         */
  65.827 +        int h = 0;
  65.828 +        if (count == 0 || loadFactor < 0)
  65.829 +            return h;  // Returns zero
  65.830 +
  65.831 +        loadFactor = -loadFactor;  // Mark hashCode computation in progress
  65.832 +        Entry[] tab = table;
  65.833 +        for (int i = 0; i < tab.length; i++)
  65.834 +            for (Entry e = tab[i]; e != null; e = e.next)
  65.835 +                h += e.key.hashCode() ^ e.value.hashCode();
  65.836 +        loadFactor = -loadFactor;  // Mark hashCode computation complete
  65.837 +
  65.838 +        return h;
  65.839 +    }
  65.840 +
  65.841 +    /**
  65.842 +     * Hashtable collision list.
  65.843 +     */
  65.844 +    private static class Entry<K,V> implements Map.Entry<K,V> {
  65.845 +        int hash;
  65.846 +        K key;
  65.847 +        V value;
  65.848 +        Entry<K,V> next;
  65.849 +
  65.850 +        protected Entry(int hash, K key, V value, Entry<K,V> next) {
  65.851 +            this.hash = hash;
  65.852 +            this.key = key;
  65.853 +            this.value = value;
  65.854 +            this.next = next;
  65.855 +        }
  65.856 +
  65.857 +        protected Object clone() {
  65.858 +            return new Entry<>(hash, key, value,
  65.859 +                                  (next==null ? null : (Entry<K,V>) next.clone()));
  65.860 +        }
  65.861 +
  65.862 +        // Map.Entry Ops
  65.863 +
  65.864 +        public K getKey() {
  65.865 +            return key;
  65.866 +        }
  65.867 +
  65.868 +        public V getValue() {
  65.869 +            return value;
  65.870 +        }
  65.871 +
  65.872 +        public V setValue(V value) {
  65.873 +            if (value == null)
  65.874 +                throw new NullPointerException();
  65.875 +
  65.876 +            V oldValue = this.value;
  65.877 +            this.value = value;
  65.878 +            return oldValue;
  65.879 +        }
  65.880 +
  65.881 +        public boolean equals(Object o) {
  65.882 +            if (!(o instanceof Map.Entry))
  65.883 +                return false;
  65.884 +            Map.Entry e = (Map.Entry)o;
  65.885 +
  65.886 +            return (key==null ? e.getKey()==null : key.equals(e.getKey())) &&
  65.887 +               (value==null ? e.getValue()==null : value.equals(e.getValue()));
  65.888 +        }
  65.889 +
  65.890 +        public int hashCode() {
  65.891 +            return hash ^ (value==null ? 0 : value.hashCode());
  65.892 +        }
  65.893 +
  65.894 +        public String toString() {
  65.895 +            return key.toString()+"="+value.toString();
  65.896 +        }
  65.897 +    }
  65.898 +
  65.899 +    // Types of Enumerations/Iterations
  65.900 +    private static final int KEYS = 0;
  65.901 +    private static final int VALUES = 1;
  65.902 +    private static final int ENTRIES = 2;
  65.903 +
  65.904 +    /**
  65.905 +     * A hashtable enumerator class.  This class implements both the
  65.906 +     * Enumeration and Iterator interfaces, but individual instances
  65.907 +     * can be created with the Iterator methods disabled.  This is necessary
  65.908 +     * to avoid unintentionally increasing the capabilities granted a user
  65.909 +     * by passing an Enumeration.
  65.910 +     */
  65.911 +    private class Enumerator<T> implements Enumeration<T>, Iterator<T> {
  65.912 +        Entry[] table = Hashtable.this.table;
  65.913 +        int index = table.length;
  65.914 +        Entry<K,V> entry = null;
  65.915 +        Entry<K,V> lastReturned = null;
  65.916 +        int type;
  65.917 +
  65.918 +        /**
  65.919 +         * Indicates whether this Enumerator is serving as an Iterator
  65.920 +         * or an Enumeration.  (true -> Iterator).
  65.921 +         */
  65.922 +        boolean iterator;
  65.923 +
  65.924 +        /**
  65.925 +         * The modCount value that the iterator believes that the backing
  65.926 +         * Hashtable should have.  If this expectation is violated, the iterator
  65.927 +         * has detected concurrent modification.
  65.928 +         */
  65.929 +        protected int expectedModCount = modCount;
  65.930 +
  65.931 +        Enumerator(int type, boolean iterator) {
  65.932 +            this.type = type;
  65.933 +            this.iterator = iterator;
  65.934 +        }
  65.935 +
  65.936 +        public boolean hasMoreElements() {
  65.937 +            Entry<K,V> e = entry;
  65.938 +            int i = index;
  65.939 +            Entry[] t = table;
  65.940 +            /* Use locals for faster loop iteration */
  65.941 +            while (e == null && i > 0) {
  65.942 +                e = t[--i];
  65.943 +            }
  65.944 +            entry = e;
  65.945 +            index = i;
  65.946 +            return e != null;
  65.947 +        }
  65.948 +
  65.949 +        public T nextElement() {
  65.950 +            Entry<K,V> et = entry;
  65.951 +            int i = index;
  65.952 +            Entry[] t = table;
  65.953 +            /* Use locals for faster loop iteration */
  65.954 +            while (et == null && i > 0) {
  65.955 +                et = t[--i];
  65.956 +            }
  65.957 +            entry = et;
  65.958 +            index = i;
  65.959 +            if (et != null) {
  65.960 +                Entry<K,V> e = lastReturned = entry;
  65.961 +                entry = e.next;
  65.962 +                return type == KEYS ? (T)e.key : (type == VALUES ? (T)e.value : (T)e);
  65.963 +            }
  65.964 +            throw new NoSuchElementException("Hashtable Enumerator");
  65.965 +        }
  65.966 +
  65.967 +        // Iterator methods
  65.968 +        public boolean hasNext() {
  65.969 +            return hasMoreElements();
  65.970 +        }
  65.971 +
  65.972 +        public T next() {
  65.973 +            if (modCount != expectedModCount)
  65.974 +                throw new ConcurrentModificationException();
  65.975 +            return nextElement();
  65.976 +        }
  65.977 +
  65.978 +        public void remove() {
  65.979 +            if (!iterator)
  65.980 +                throw new UnsupportedOperationException();
  65.981 +            if (lastReturned == null)
  65.982 +                throw new IllegalStateException("Hashtable Enumerator");
  65.983 +            if (modCount != expectedModCount)
  65.984 +                throw new ConcurrentModificationException();
  65.985 +
  65.986 +            synchronized(Hashtable.this) {
  65.987 +                Entry[] tab = Hashtable.this.table;
  65.988 +                int index = (lastReturned.hash & 0x7FFFFFFF) % tab.length;
  65.989 +
  65.990 +                for (Entry<K,V> e = tab[index], prev = null; e != null;
  65.991 +                     prev = e, e = e.next) {
  65.992 +                    if (e == lastReturned) {
  65.993 +                        modCount++;
  65.994 +                        expectedModCount++;
  65.995 +                        if (prev == null)
  65.996 +                            tab[index] = e.next;
  65.997 +                        else
  65.998 +                            prev.next = e.next;
  65.999 +                        count--;
 65.1000 +                        lastReturned = null;
 65.1001 +                        return;
 65.1002 +                    }
 65.1003 +                }
 65.1004 +                throw new ConcurrentModificationException();
 65.1005 +            }
 65.1006 +        }
 65.1007 +    }
 65.1008 +}
    66.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    66.2 +++ b/emul/compact/src/main/java/java/util/Iterator.java	Sun Feb 03 07:48:42 2013 +0100
    66.3 @@ -0,0 +1,87 @@
    66.4 +/*
    66.5 + * Copyright (c) 1997, 2010, 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.util;
   66.30 +
   66.31 +/**
   66.32 + * An iterator over a collection.  {@code Iterator} takes the place of
   66.33 + * {@link Enumeration} in the Java Collections Framework.  Iterators
   66.34 + * differ from enumerations in two ways:
   66.35 + *
   66.36 + * <ul>
   66.37 + *      <li> Iterators allow the caller to remove elements from the
   66.38 + *           underlying collection during the iteration with well-defined
   66.39 + *           semantics.
   66.40 + *      <li> Method names have been improved.
   66.41 + * </ul>
   66.42 + *
   66.43 + * <p>This interface is a member of the
   66.44 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   66.45 + * Java Collections Framework</a>.
   66.46 + *
   66.47 + * @param <E> the type of elements returned by this iterator
   66.48 + *
   66.49 + * @author  Josh Bloch
   66.50 + * @see Collection
   66.51 + * @see ListIterator
   66.52 + * @see Iterable
   66.53 + * @since 1.2
   66.54 + */
   66.55 +public interface Iterator<E> {
   66.56 +    /**
   66.57 +     * Returns {@code true} if the iteration has more elements.
   66.58 +     * (In other words, returns {@code true} if {@link #next} would
   66.59 +     * return an element rather than throwing an exception.)
   66.60 +     *
   66.61 +     * @return {@code true} if the iteration has more elements
   66.62 +     */
   66.63 +    boolean hasNext();
   66.64 +
   66.65 +    /**
   66.66 +     * Returns the next element in the iteration.
   66.67 +     *
   66.68 +     * @return the next element in the iteration
   66.69 +     * @throws NoSuchElementException if the iteration has no more elements
   66.70 +     */
   66.71 +    E next();
   66.72 +
   66.73 +    /**
   66.74 +     * Removes from the underlying collection the last element returned
   66.75 +     * by this iterator (optional operation).  This method can be called
   66.76 +     * only once per call to {@link #next}.  The behavior of an iterator
   66.77 +     * is unspecified if the underlying collection is modified while the
   66.78 +     * iteration is in progress in any way other than by calling this
   66.79 +     * method.
   66.80 +     *
   66.81 +     * @throws UnsupportedOperationException if the {@code remove}
   66.82 +     *         operation is not supported by this iterator
   66.83 +     *
   66.84 +     * @throws IllegalStateException if the {@code next} method has not
   66.85 +     *         yet been called, or the {@code remove} method has already
   66.86 +     *         been called after the last call to the {@code next}
   66.87 +     *         method
   66.88 +     */
   66.89 +    void remove();
   66.90 +}
    67.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    67.2 +++ b/emul/compact/src/main/java/java/util/LinkedHashMap.java	Sun Feb 03 07:48:42 2013 +0100
    67.3 @@ -0,0 +1,491 @@
    67.4 +/*
    67.5 + * Copyright (c) 2000, 2010, 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.util;
   67.30 +import java.io.*;
   67.31 +
   67.32 +/**
   67.33 + * <p>Hash table and linked list implementation of the <tt>Map</tt> interface,
   67.34 + * with predictable iteration order.  This implementation differs from
   67.35 + * <tt>HashMap</tt> in that it maintains a doubly-linked list running through
   67.36 + * all of its entries.  This linked list defines the iteration ordering,
   67.37 + * which is normally the order in which keys were inserted into the map
   67.38 + * (<i>insertion-order</i>).  Note that insertion order is not affected
   67.39 + * if a key is <i>re-inserted</i> into the map.  (A key <tt>k</tt> is
   67.40 + * reinserted into a map <tt>m</tt> if <tt>m.put(k, v)</tt> is invoked when
   67.41 + * <tt>m.containsKey(k)</tt> would return <tt>true</tt> immediately prior to
   67.42 + * the invocation.)
   67.43 + *
   67.44 + * <p>This implementation spares its clients from the unspecified, generally
   67.45 + * chaotic ordering provided by {@link HashMap} (and {@link Hashtable}),
   67.46 + * without incurring the increased cost associated with {@link TreeMap}.  It
   67.47 + * can be used to produce a copy of a map that has the same order as the
   67.48 + * original, regardless of the original map's implementation:
   67.49 + * <pre>
   67.50 + *     void foo(Map m) {
   67.51 + *         Map copy = new LinkedHashMap(m);
   67.52 + *         ...
   67.53 + *     }
   67.54 + * </pre>
   67.55 + * This technique is particularly useful if a module takes a map on input,
   67.56 + * copies it, and later returns results whose order is determined by that of
   67.57 + * the copy.  (Clients generally appreciate having things returned in the same
   67.58 + * order they were presented.)
   67.59 + *
   67.60 + * <p>A special {@link #LinkedHashMap(int,float,boolean) constructor} is
   67.61 + * provided to create a linked hash map whose order of iteration is the order
   67.62 + * in which its entries were last accessed, from least-recently accessed to
   67.63 + * most-recently (<i>access-order</i>).  This kind of map is well-suited to
   67.64 + * building LRU caches.  Invoking the <tt>put</tt> or <tt>get</tt> method
   67.65 + * results in an access to the corresponding entry (assuming it exists after
   67.66 + * the invocation completes).  The <tt>putAll</tt> method generates one entry
   67.67 + * access for each mapping in the specified map, in the order that key-value
   67.68 + * mappings are provided by the specified map's entry set iterator.  <i>No
   67.69 + * other methods generate entry accesses.</i> In particular, operations on
   67.70 + * collection-views do <i>not</i> affect the order of iteration of the backing
   67.71 + * map.
   67.72 + *
   67.73 + * <p>The {@link #removeEldestEntry(Map.Entry)} method may be overridden to
   67.74 + * impose a policy for removing stale mappings automatically when new mappings
   67.75 + * are added to the map.
   67.76 + *
   67.77 + * <p>This class provides all of the optional <tt>Map</tt> operations, and
   67.78 + * permits null elements.  Like <tt>HashMap</tt>, it provides constant-time
   67.79 + * performance for the basic operations (<tt>add</tt>, <tt>contains</tt> and
   67.80 + * <tt>remove</tt>), assuming the hash function disperses elements
   67.81 + * properly among the buckets.  Performance is likely to be just slightly
   67.82 + * below that of <tt>HashMap</tt>, due to the added expense of maintaining the
   67.83 + * linked list, with one exception: Iteration over the collection-views
   67.84 + * of a <tt>LinkedHashMap</tt> requires time proportional to the <i>size</i>
   67.85 + * of the map, regardless of its capacity.  Iteration over a <tt>HashMap</tt>
   67.86 + * is likely to be more expensive, requiring time proportional to its
   67.87 + * <i>capacity</i>.
   67.88 + *
   67.89 + * <p>A linked hash map has two parameters that affect its performance:
   67.90 + * <i>initial capacity</i> and <i>load factor</i>.  They are defined precisely
   67.91 + * as for <tt>HashMap</tt>.  Note, however, that the penalty for choosing an
   67.92 + * excessively high value for initial capacity is less severe for this class
   67.93 + * than for <tt>HashMap</tt>, as iteration times for this class are unaffected
   67.94 + * by capacity.
   67.95 + *
   67.96 + * <p><strong>Note that this implementation is not synchronized.</strong>
   67.97 + * If multiple threads access a linked hash map concurrently, and at least
   67.98 + * one of the threads modifies the map structurally, it <em>must</em> be
   67.99 + * synchronized externally.  This is typically accomplished by
  67.100 + * synchronizing on some object that naturally encapsulates the map.
  67.101 + *
  67.102 + * If no such object exists, the map should be "wrapped" using the
  67.103 + * {@link Collections#synchronizedMap Collections.synchronizedMap}
  67.104 + * method.  This is best done at creation time, to prevent accidental
  67.105 + * unsynchronized access to the map:<pre>
  67.106 + *   Map m = Collections.synchronizedMap(new LinkedHashMap(...));</pre>
  67.107 + *
  67.108 + * A structural modification is any operation that adds or deletes one or more
  67.109 + * mappings or, in the case of access-ordered linked hash maps, affects
  67.110 + * iteration order.  In insertion-ordered linked hash maps, merely changing
  67.111 + * the value associated with a key that is already contained in the map is not
  67.112 + * a structural modification.  <strong>In access-ordered linked hash maps,
  67.113 + * merely querying the map with <tt>get</tt> is a structural
  67.114 + * modification.</strong>)
  67.115 + *
  67.116 + * <p>The iterators returned by the <tt>iterator</tt> method of the collections
  67.117 + * returned by all of this class's collection view methods are
  67.118 + * <em>fail-fast</em>: if the map is structurally modified at any time after
  67.119 + * the iterator is created, in any way except through the iterator's own
  67.120 + * <tt>remove</tt> method, the iterator will throw a {@link
  67.121 + * ConcurrentModificationException}.  Thus, in the face of concurrent
  67.122 + * modification, the iterator fails quickly and cleanly, rather than risking
  67.123 + * arbitrary, non-deterministic behavior at an undetermined time in the future.
  67.124 + *
  67.125 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
  67.126 + * as it is, generally speaking, impossible to make any hard guarantees in the
  67.127 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
  67.128 + * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
  67.129 + * Therefore, it would be wrong to write a program that depended on this
  67.130 + * exception for its correctness:   <i>the fail-fast behavior of iterators
  67.131 + * should be used only to detect bugs.</i>
  67.132 + *
  67.133 + * <p>This class is a member of the
  67.134 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  67.135 + * Java Collections Framework</a>.
  67.136 + *
  67.137 + * @param <K> the type of keys maintained by this map
  67.138 + * @param <V> the type of mapped values
  67.139 + *
  67.140 + * @author  Josh Bloch
  67.141 + * @see     Object#hashCode()
  67.142 + * @see     Collection
  67.143 + * @see     Map
  67.144 + * @see     HashMap
  67.145 + * @see     TreeMap
  67.146 + * @see     Hashtable
  67.147 + * @since   1.4
  67.148 + */
  67.149 +
  67.150 +public class LinkedHashMap<K,V>
  67.151 +    extends HashMap<K,V>
  67.152 +    implements Map<K,V>
  67.153 +{
  67.154 +
  67.155 +    private static final long serialVersionUID = 3801124242820219131L;
  67.156 +
  67.157 +    /**
  67.158 +     * The head of the doubly linked list.
  67.159 +     */
  67.160 +    private transient Entry<K,V> header;
  67.161 +
  67.162 +    /**
  67.163 +     * The iteration ordering method for this linked hash map: <tt>true</tt>
  67.164 +     * for access-order, <tt>false</tt> for insertion-order.
  67.165 +     *
  67.166 +     * @serial
  67.167 +     */
  67.168 +    private final boolean accessOrder;
  67.169 +
  67.170 +    /**
  67.171 +     * Constructs an empty insertion-ordered <tt>LinkedHashMap</tt> instance
  67.172 +     * with the specified initial capacity and load factor.
  67.173 +     *
  67.174 +     * @param  initialCapacity the initial capacity
  67.175 +     * @param  loadFactor      the load factor
  67.176 +     * @throws IllegalArgumentException if the initial capacity is negative
  67.177 +     *         or the load factor is nonpositive
  67.178 +     */
  67.179 +    public LinkedHashMap(int initialCapacity, float loadFactor) {
  67.180 +        super(initialCapacity, loadFactor);
  67.181 +        accessOrder = false;
  67.182 +    }
  67.183 +
  67.184 +    /**
  67.185 +     * Constructs an empty insertion-ordered <tt>LinkedHashMap</tt> instance
  67.186 +     * with the specified initial capacity and a default load factor (0.75).
  67.187 +     *
  67.188 +     * @param  initialCapacity the initial capacity
  67.189 +     * @throws IllegalArgumentException if the initial capacity is negative
  67.190 +     */
  67.191 +    public LinkedHashMap(int initialCapacity) {
  67.192 +        super(initialCapacity);
  67.193 +        accessOrder = false;
  67.194 +    }
  67.195 +
  67.196 +    /**
  67.197 +     * Constructs an empty insertion-ordered <tt>LinkedHashMap</tt> instance
  67.198 +     * with the default initial capacity (16) and load factor (0.75).
  67.199 +     */
  67.200 +    public LinkedHashMap() {
  67.201 +        super();
  67.202 +        accessOrder = false;
  67.203 +    }
  67.204 +
  67.205 +    /**
  67.206 +     * Constructs an insertion-ordered <tt>LinkedHashMap</tt> instance with
  67.207 +     * the same mappings as the specified map.  The <tt>LinkedHashMap</tt>
  67.208 +     * instance is created with a default load factor (0.75) and an initial
  67.209 +     * capacity sufficient to hold the mappings in the specified map.
  67.210 +     *
  67.211 +     * @param  m the map whose mappings are to be placed in this map
  67.212 +     * @throws NullPointerException if the specified map is null
  67.213 +     */
  67.214 +    public LinkedHashMap(Map<? extends K, ? extends V> m) {
  67.215 +        super(m);
  67.216 +        accessOrder = false;
  67.217 +    }
  67.218 +
  67.219 +    /**
  67.220 +     * Constructs an empty <tt>LinkedHashMap</tt> instance with the
  67.221 +     * specified initial capacity, load factor and ordering mode.
  67.222 +     *
  67.223 +     * @param  initialCapacity the initial capacity
  67.224 +     * @param  loadFactor      the load factor
  67.225 +     * @param  accessOrder     the ordering mode - <tt>true</tt> for
  67.226 +     *         access-order, <tt>false</tt> for insertion-order
  67.227 +     * @throws IllegalArgumentException if the initial capacity is negative
  67.228 +     *         or the load factor is nonpositive
  67.229 +     */
  67.230 +    public LinkedHashMap(int initialCapacity,
  67.231 +                         float loadFactor,
  67.232 +                         boolean accessOrder) {
  67.233 +        super(initialCapacity, loadFactor);
  67.234 +        this.accessOrder = accessOrder;
  67.235 +    }
  67.236 +
  67.237 +    /**
  67.238 +     * Called by superclass constructors and pseudoconstructors (clone,
  67.239 +     * readObject) before any entries are inserted into the map.  Initializes
  67.240 +     * the chain.
  67.241 +     */
  67.242 +    void init() {
  67.243 +        header = new Entry<>(-1, null, null, null);
  67.244 +        header.before = header.after = header;
  67.245 +    }
  67.246 +
  67.247 +    /**
  67.248 +     * Transfers all entries to new table array.  This method is called
  67.249 +     * by superclass resize.  It is overridden for performance, as it is
  67.250 +     * faster to iterate using our linked list.
  67.251 +     */
  67.252 +    void transfer(HashMap.Entry[] newTable) {
  67.253 +        int newCapacity = newTable.length;
  67.254 +        for (Entry<K,V> e = header.after; e != header; e = e.after) {
  67.255 +            int index = indexFor(e.hash, newCapacity);
  67.256 +            e.next = newTable[index];
  67.257 +            newTable[index] = e;
  67.258 +        }
  67.259 +    }
  67.260 +
  67.261 +
  67.262 +    /**
  67.263 +     * Returns <tt>true</tt> if this map maps one or more keys to the
  67.264 +     * specified value.
  67.265 +     *
  67.266 +     * @param value value whose presence in this map is to be tested
  67.267 +     * @return <tt>true</tt> if this map maps one or more keys to the
  67.268 +     *         specified value
  67.269 +     */
  67.270 +    public boolean containsValue(Object value) {
  67.271 +        // Overridden to take advantage of faster iterator
  67.272 +        if (value==null) {
  67.273 +            for (Entry e = header.after; e != header; e = e.after)
  67.274 +                if (e.value==null)
  67.275 +                    return true;
  67.276 +        } else {
  67.277 +            for (Entry e = header.after; e != header; e = e.after)
  67.278 +                if (value.equals(e.value))
  67.279 +                    return true;
  67.280 +        }
  67.281 +        return false;
  67.282 +    }
  67.283 +
  67.284 +    /**
  67.285 +     * Returns the value to which the specified key is mapped,
  67.286 +     * or {@code null} if this map contains no mapping for the key.
  67.287 +     *
  67.288 +     * <p>More formally, if this map contains a mapping from a key
  67.289 +     * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
  67.290 +     * key.equals(k))}, then this method returns {@code v}; otherwise
  67.291 +     * it returns {@code null}.  (There can be at most one such mapping.)
  67.292 +     *
  67.293 +     * <p>A return value of {@code null} does not <i>necessarily</i>
  67.294 +     * indicate that the map contains no mapping for the key; it's also
  67.295 +     * possible that the map explicitly maps the key to {@code null}.
  67.296 +     * The {@link #containsKey containsKey} operation may be used to
  67.297 +     * distinguish these two cases.
  67.298 +     */
  67.299 +    public V get(Object key) {
  67.300 +        Entry<K,V> e = (Entry<K,V>)getEntry(key);
  67.301 +        if (e == null)
  67.302 +            return null;
  67.303 +        e.recordAccess(this);
  67.304 +        return e.value;
  67.305 +    }
  67.306 +
  67.307 +    /**
  67.308 +     * Removes all of the mappings from this map.
  67.309 +     * The map will be empty after this call returns.
  67.310 +     */
  67.311 +    public void clear() {
  67.312 +        super.clear();
  67.313 +        header.before = header.after = header;
  67.314 +    }
  67.315 +
  67.316 +    /**
  67.317 +     * LinkedHashMap entry.
  67.318 +     */
  67.319 +    private static class Entry<K,V> extends HashMap.Entry<K,V> {
  67.320 +        // These fields comprise the doubly linked list used for iteration.
  67.321 +        Entry<K,V> before, after;
  67.322 +
  67.323 +        Entry(int hash, K key, V value, HashMap.Entry<K,V> next) {
  67.324 +            super(hash, key, value, next);
  67.325 +        }
  67.326 +
  67.327 +        /**
  67.328 +         * Removes this entry from the linked list.
  67.329 +         */
  67.330 +        private void remove() {
  67.331 +            before.after = after;
  67.332 +            after.before = before;
  67.333 +        }
  67.334 +
  67.335 +        /**
  67.336 +         * Inserts this entry before the specified existing entry in the list.
  67.337 +         */
  67.338 +        private void addBefore(Entry<K,V> existingEntry) {
  67.339 +            after  = existingEntry;
  67.340 +            before = existingEntry.before;
  67.341 +            before.after = this;
  67.342 +            after.before = this;
  67.343 +        }
  67.344 +
  67.345 +        /**
  67.346 +         * This method is invoked by the superclass whenever the value
  67.347 +         * of a pre-existing entry is read by Map.get or modified by Map.set.
  67.348 +         * If the enclosing Map is access-ordered, it moves the entry
  67.349 +         * to the end of the list; otherwise, it does nothing.
  67.350 +         */
  67.351 +        void recordAccess(HashMap<K,V> m) {
  67.352 +            LinkedHashMap<K,V> lm = (LinkedHashMap<K,V>)m;
  67.353 +            if (lm.accessOrder) {
  67.354 +                lm.modCount++;
  67.355 +                remove();
  67.356 +                addBefore(lm.header);
  67.357 +            }
  67.358 +        }
  67.359 +
  67.360 +        void recordRemoval(HashMap<K,V> m) {
  67.361 +            remove();
  67.362 +        }
  67.363 +    }
  67.364 +
  67.365 +    private abstract class LinkedHashIterator<T> implements Iterator<T> {
  67.366 +        Entry<K,V> nextEntry    = header.after;
  67.367 +        Entry<K,V> lastReturned = null;
  67.368 +
  67.369 +        /**
  67.370 +         * The modCount value that the iterator believes that the backing
  67.371 +         * List should have.  If this expectation is violated, the iterator
  67.372 +         * has detected concurrent modification.
  67.373 +         */
  67.374 +        int expectedModCount = modCount;
  67.375 +
  67.376 +        public boolean hasNext() {
  67.377 +            return nextEntry != header;
  67.378 +        }
  67.379 +
  67.380 +        public void remove() {
  67.381 +            if (lastReturned == null)
  67.382 +                throw new IllegalStateException();
  67.383 +            if (modCount != expectedModCount)
  67.384 +                throw new ConcurrentModificationException();
  67.385 +
  67.386 +            LinkedHashMap.this.remove(lastReturned.key);
  67.387 +            lastReturned = null;
  67.388 +            expectedModCount = modCount;
  67.389 +        }
  67.390 +
  67.391 +        Entry<K,V> nextEntry() {
  67.392 +            if (modCount != expectedModCount)
  67.393 +                throw new ConcurrentModificationException();
  67.394 +            if (nextEntry == header)
  67.395 +                throw new NoSuchElementException();
  67.396 +
  67.397 +            Entry<K,V> e = lastReturned = nextEntry;
  67.398 +            nextEntry = e.after;
  67.399 +            return e;
  67.400 +        }
  67.401 +    }
  67.402 +
  67.403 +    private class KeyIterator extends LinkedHashIterator<K> {
  67.404 +        public K next() { return nextEntry().getKey(); }
  67.405 +    }
  67.406 +
  67.407 +    private class ValueIterator extends LinkedHashIterator<V> {
  67.408 +        public V next() { return nextEntry().value; }
  67.409 +    }
  67.410 +
  67.411 +    private class EntryIterator extends LinkedHashIterator<Map.Entry<K,V>> {
  67.412 +        public Map.Entry<K,V> next() { return nextEntry(); }
  67.413 +    }
  67.414 +
  67.415 +    // These Overrides alter the behavior of superclass view iterator() methods
  67.416 +    Iterator<K> newKeyIterator()   { return new KeyIterator();   }
  67.417 +    Iterator<V> newValueIterator() { return new ValueIterator(); }
  67.418 +    Iterator<Map.Entry<K,V>> newEntryIterator() { return new EntryIterator(); }
  67.419 +
  67.420 +    /**
  67.421 +     * This override alters behavior of superclass put method. It causes newly
  67.422 +     * allocated entry to get inserted at the end of the linked list and
  67.423 +     * removes the eldest entry if appropriate.
  67.424 +     */
  67.425 +    void addEntry(int hash, K key, V value, int bucketIndex) {
  67.426 +        createEntry(hash, key, value, bucketIndex);
  67.427 +
  67.428 +        // Remove eldest entry if instructed, else grow capacity if appropriate
  67.429 +        Entry<K,V> eldest = header.after;
  67.430 +        if (removeEldestEntry(eldest)) {
  67.431 +            removeEntryForKey(eldest.key);
  67.432 +        } else {
  67.433 +            if (size >= threshold)
  67.434 +                resize(2 * table.length);
  67.435 +        }
  67.436 +    }
  67.437 +
  67.438 +    /**
  67.439 +     * This override differs from addEntry in that it doesn't resize the
  67.440 +     * table or remove the eldest entry.
  67.441 +     */
  67.442 +    void createEntry(int hash, K key, V value, int bucketIndex) {
  67.443 +        HashMap.Entry<K,V> old = table[bucketIndex];
  67.444 +        Entry<K,V> e = new Entry<>(hash, key, value, old);
  67.445 +        table[bucketIndex] = e;
  67.446 +        e.addBefore(header);
  67.447 +        size++;
  67.448 +    }
  67.449 +
  67.450 +    /**
  67.451 +     * Returns <tt>true</tt> if this map should remove its eldest entry.
  67.452 +     * This method is invoked by <tt>put</tt> and <tt>putAll</tt> after
  67.453 +     * inserting a new entry into the map.  It provides the implementor
  67.454 +     * with the opportunity to remove the eldest entry each time a new one
  67.455 +     * is added.  This is useful if the map represents a cache: it allows
  67.456 +     * the map to reduce memory consumption by deleting stale entries.
  67.457 +     *
  67.458 +     * <p>Sample use: this override will allow the map to grow up to 100
  67.459 +     * entries and then delete the eldest entry each time a new entry is
  67.460 +     * added, maintaining a steady state of 100 entries.
  67.461 +     * <pre>
  67.462 +     *     private static final int MAX_ENTRIES = 100;
  67.463 +     *
  67.464 +     *     protected boolean removeEldestEntry(Map.Entry eldest) {
  67.465 +     *        return size() > MAX_ENTRIES;
  67.466 +     *     }
  67.467 +     * </pre>
  67.468 +     *
  67.469 +     * <p>This method typically does not modify the map in any way,
  67.470 +     * instead allowing the map to modify itself as directed by its
  67.471 +     * return value.  It <i>is</i> permitted for this method to modify
  67.472 +     * the map directly, but if it does so, it <i>must</i> return
  67.473 +     * <tt>false</tt> (indicating that the map should not attempt any
  67.474 +     * further modification).  The effects of returning <tt>true</tt>
  67.475 +     * after modifying the map from within this method are unspecified.
  67.476 +     *
  67.477 +     * <p>This implementation merely returns <tt>false</tt> (so that this
  67.478 +     * map acts like a normal map - the eldest element is never removed).
  67.479 +     *
  67.480 +     * @param    eldest The least recently inserted entry in the map, or if
  67.481 +     *           this is an access-ordered map, the least recently accessed
  67.482 +     *           entry.  This is the entry that will be removed it this
  67.483 +     *           method returns <tt>true</tt>.  If the map was empty prior
  67.484 +     *           to the <tt>put</tt> or <tt>putAll</tt> invocation resulting
  67.485 +     *           in this invocation, this will be the entry that was just
  67.486 +     *           inserted; in other words, if the map contains a single
  67.487 +     *           entry, the eldest entry is also the newest.
  67.488 +     * @return   <tt>true</tt> if the eldest entry should be removed
  67.489 +     *           from the map; <tt>false</tt> if it should be retained.
  67.490 +     */
  67.491 +    protected boolean removeEldestEntry(Map.Entry<K,V> eldest) {
  67.492 +        return false;
  67.493 +    }
  67.494 +}
    68.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    68.2 +++ b/emul/compact/src/main/java/java/util/LinkedList.java	Sun Feb 03 07:48:42 2013 +0100
    68.3 @@ -0,0 +1,1100 @@
    68.4 +/*
    68.5 + * Copyright (c) 1997, 2011, 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.util;
   68.30 +
   68.31 +/**
   68.32 + * Doubly-linked list implementation of the {@code List} and {@code Deque}
   68.33 + * interfaces.  Implements all optional list operations, and permits all
   68.34 + * elements (including {@code null}).
   68.35 + *
   68.36 + * <p>All of the operations perform as could be expected for a doubly-linked
   68.37 + * list.  Operations that index into the list will traverse the list from
   68.38 + * the beginning or the end, whichever is closer to the specified index.
   68.39 + *
   68.40 + * <p><strong>Note that this implementation is not synchronized.</strong>
   68.41 + * If multiple threads access a linked list concurrently, and at least
   68.42 + * one of the threads modifies the list structurally, it <i>must</i> be
   68.43 + * synchronized externally.  (A structural modification is any operation
   68.44 + * that adds or deletes one or more elements; merely setting the value of
   68.45 + * an element is not a structural modification.)  This is typically
   68.46 + * accomplished by synchronizing on some object that naturally
   68.47 + * encapsulates the list.
   68.48 + *
   68.49 + * If no such object exists, the list should be "wrapped" using the
   68.50 + * {@link Collections#synchronizedList Collections.synchronizedList}
   68.51 + * method.  This is best done at creation time, to prevent accidental
   68.52 + * unsynchronized access to the list:<pre>
   68.53 + *   List list = Collections.synchronizedList(new LinkedList(...));</pre>
   68.54 + *
   68.55 + * <p>The iterators returned by this class's {@code iterator} and
   68.56 + * {@code listIterator} methods are <i>fail-fast</i>: if the list is
   68.57 + * structurally modified at any time after the iterator is created, in
   68.58 + * any way except through the Iterator's own {@code remove} or
   68.59 + * {@code add} methods, the iterator will throw a {@link
   68.60 + * ConcurrentModificationException}.  Thus, in the face of concurrent
   68.61 + * modification, the iterator fails quickly and cleanly, rather than
   68.62 + * risking arbitrary, non-deterministic behavior at an undetermined
   68.63 + * time in the future.
   68.64 + *
   68.65 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
   68.66 + * as it is, generally speaking, impossible to make any hard guarantees in the
   68.67 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
   68.68 + * throw {@code ConcurrentModificationException} on a best-effort basis.
   68.69 + * Therefore, it would be wrong to write a program that depended on this
   68.70 + * exception for its correctness:   <i>the fail-fast behavior of iterators
   68.71 + * should be used only to detect bugs.</i>
   68.72 + *
   68.73 + * <p>This class is a member of the
   68.74 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   68.75 + * Java Collections Framework</a>.
   68.76 + *
   68.77 + * @author  Josh Bloch
   68.78 + * @see     List
   68.79 + * @see     ArrayList
   68.80 + * @since 1.2
   68.81 + * @param <E> the type of elements held in this collection
   68.82 + */
   68.83 +
   68.84 +public class LinkedList<E>
   68.85 +    extends AbstractSequentialList<E>
   68.86 +    implements List<E>, Deque<E>, Cloneable, java.io.Serializable
   68.87 +{
   68.88 +    transient int size = 0;
   68.89 +
   68.90 +    /**
   68.91 +     * Pointer to first node.
   68.92 +     * Invariant: (first == null && last == null) ||
   68.93 +     *            (first.prev == null && first.item != null)
   68.94 +     */
   68.95 +    transient Node<E> first;
   68.96 +
   68.97 +    /**
   68.98 +     * Pointer to last node.
   68.99 +     * Invariant: (first == null && last == null) ||
  68.100 +     *            (last.next == null && last.item != null)
  68.101 +     */
  68.102 +    transient Node<E> last;
  68.103 +
  68.104 +    /**
  68.105 +     * Constructs an empty list.
  68.106 +     */
  68.107 +    public LinkedList() {
  68.108 +    }
  68.109 +
  68.110 +    /**
  68.111 +     * Constructs a list containing the elements of the specified
  68.112 +     * collection, in the order they are returned by the collection's
  68.113 +     * iterator.
  68.114 +     *
  68.115 +     * @param  c the collection whose elements are to be placed into this list
  68.116 +     * @throws NullPointerException if the specified collection is null
  68.117 +     */
  68.118 +    public LinkedList(Collection<? extends E> c) {
  68.119 +        this();
  68.120 +        addAll(c);
  68.121 +    }
  68.122 +
  68.123 +    /**
  68.124 +     * Links e as first element.
  68.125 +     */
  68.126 +    private void linkFirst(E e) {
  68.127 +        final Node<E> f = first;
  68.128 +        final Node<E> newNode = new Node<>(null, e, f);
  68.129 +        first = newNode;
  68.130 +        if (f == null)
  68.131 +            last = newNode;
  68.132 +        else
  68.133 +            f.prev = newNode;
  68.134 +        size++;
  68.135 +        modCount++;
  68.136 +    }
  68.137 +
  68.138 +    /**
  68.139 +     * Links e as last element.
  68.140 +     */
  68.141 +    void linkLast(E e) {
  68.142 +        final Node<E> l = last;
  68.143 +        final Node<E> newNode = new Node<>(l, e, null);
  68.144 +        last = newNode;
  68.145 +        if (l == null)
  68.146 +            first = newNode;
  68.147 +        else
  68.148 +            l.next = newNode;
  68.149 +        size++;
  68.150 +        modCount++;
  68.151 +    }
  68.152 +
  68.153 +    /**
  68.154 +     * Inserts element e before non-null Node succ.
  68.155 +     */
  68.156 +    void linkBefore(E e, Node<E> succ) {
  68.157 +        // assert succ != null;
  68.158 +        final Node<E> pred = succ.prev;
  68.159 +        final Node<E> newNode = new Node<>(pred, e, succ);
  68.160 +        succ.prev = newNode;
  68.161 +        if (pred == null)
  68.162 +            first = newNode;
  68.163 +        else
  68.164 +            pred.next = newNode;
  68.165 +        size++;
  68.166 +        modCount++;
  68.167 +    }
  68.168 +
  68.169 +    /**
  68.170 +     * Unlinks non-null first node f.
  68.171 +     */
  68.172 +    private E unlinkFirst(Node<E> f) {
  68.173 +        // assert f == first && f != null;
  68.174 +        final E element = f.item;
  68.175 +        final Node<E> next = f.next;
  68.176 +        f.item = null;
  68.177 +        f.next = null; // help GC
  68.178 +        first = next;
  68.179 +        if (next == null)
  68.180 +            last = null;
  68.181 +        else
  68.182 +            next.prev = null;
  68.183 +        size--;
  68.184 +        modCount++;
  68.185 +        return element;
  68.186 +    }
  68.187 +
  68.188 +    /**
  68.189 +     * Unlinks non-null last node l.
  68.190 +     */
  68.191 +    private E unlinkLast(Node<E> l) {
  68.192 +        // assert l == last && l != null;
  68.193 +        final E element = l.item;
  68.194 +        final Node<E> prev = l.prev;
  68.195 +        l.item = null;
  68.196 +        l.prev = null; // help GC
  68.197 +        last = prev;
  68.198 +        if (prev == null)
  68.199 +            first = null;
  68.200 +        else
  68.201 +            prev.next = null;
  68.202 +        size--;
  68.203 +        modCount++;
  68.204 +        return element;
  68.205 +    }
  68.206 +
  68.207 +    /**
  68.208 +     * Unlinks non-null node x.
  68.209 +     */
  68.210 +    E unlink(Node<E> x) {
  68.211 +        // assert x != null;
  68.212 +        final E element = x.item;
  68.213 +        final Node<E> next = x.next;
  68.214 +        final Node<E> prev = x.prev;
  68.215 +
  68.216 +        if (prev == null) {
  68.217 +            first = next;
  68.218 +        } else {
  68.219 +            prev.next = next;
  68.220 +            x.prev = null;
  68.221 +        }
  68.222 +
  68.223 +        if (next == null) {
  68.224 +            last = prev;
  68.225 +        } else {
  68.226 +            next.prev = prev;
  68.227 +            x.next = null;
  68.228 +        }
  68.229 +
  68.230 +        x.item = null;
  68.231 +        size--;
  68.232 +        modCount++;
  68.233 +        return element;
  68.234 +    }
  68.235 +
  68.236 +    /**
  68.237 +     * Returns the first element in this list.
  68.238 +     *
  68.239 +     * @return the first element in this list
  68.240 +     * @throws NoSuchElementException if this list is empty
  68.241 +     */
  68.242 +    public E getFirst() {
  68.243 +        final Node<E> f = first;
  68.244 +        if (f == null)
  68.245 +            throw new NoSuchElementException();
  68.246 +        return f.item;
  68.247 +    }
  68.248 +
  68.249 +    /**
  68.250 +     * Returns the last element in this list.
  68.251 +     *
  68.252 +     * @return the last element in this list
  68.253 +     * @throws NoSuchElementException if this list is empty
  68.254 +     */
  68.255 +    public E getLast() {
  68.256 +        final Node<E> l = last;
  68.257 +        if (l == null)
  68.258 +            throw new NoSuchElementException();
  68.259 +        return l.item;
  68.260 +    }
  68.261 +
  68.262 +    /**
  68.263 +     * Removes and returns the first element from this list.
  68.264 +     *
  68.265 +     * @return the first element from this list
  68.266 +     * @throws NoSuchElementException if this list is empty
  68.267 +     */
  68.268 +    public E removeFirst() {
  68.269 +        final Node<E> f = first;
  68.270 +        if (f == null)
  68.271 +            throw new NoSuchElementException();
  68.272 +        return unlinkFirst(f);
  68.273 +    }
  68.274 +
  68.275 +    /**
  68.276 +     * Removes and returns the last element from this list.
  68.277 +     *
  68.278 +     * @return the last element from this list
  68.279 +     * @throws NoSuchElementException if this list is empty
  68.280 +     */
  68.281 +    public E removeLast() {
  68.282 +        final Node<E> l = last;
  68.283 +        if (l == null)
  68.284 +            throw new NoSuchElementException();
  68.285 +        return unlinkLast(l);
  68.286 +    }
  68.287 +
  68.288 +    /**
  68.289 +     * Inserts the specified element at the beginning of this list.
  68.290 +     *
  68.291 +     * @param e the element to add
  68.292 +     */
  68.293 +    public void addFirst(E e) {
  68.294 +        linkFirst(e);
  68.295 +    }
  68.296 +
  68.297 +    /**
  68.298 +     * Appends the specified element to the end of this list.
  68.299 +     *
  68.300 +     * <p>This method is equivalent to {@link #add}.
  68.301 +     *
  68.302 +     * @param e the element to add
  68.303 +     */
  68.304 +    public void addLast(E e) {
  68.305 +        linkLast(e);
  68.306 +    }
  68.307 +
  68.308 +    /**
  68.309 +     * Returns {@code true} if this list contains the specified element.
  68.310 +     * More formally, returns {@code true} if and only if this list contains
  68.311 +     * at least one element {@code e} such that
  68.312 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  68.313 +     *
  68.314 +     * @param o element whose presence in this list is to be tested
  68.315 +     * @return {@code true} if this list contains the specified element
  68.316 +     */
  68.317 +    public boolean contains(Object o) {
  68.318 +        return indexOf(o) != -1;
  68.319 +    }
  68.320 +
  68.321 +    /**
  68.322 +     * Returns the number of elements in this list.
  68.323 +     *
  68.324 +     * @return the number of elements in this list
  68.325 +     */
  68.326 +    public int size() {
  68.327 +        return size;
  68.328 +    }
  68.329 +
  68.330 +    /**
  68.331 +     * Appends the specified element to the end of this list.
  68.332 +     *
  68.333 +     * <p>This method is equivalent to {@link #addLast}.
  68.334 +     *
  68.335 +     * @param e element to be appended to this list
  68.336 +     * @return {@code true} (as specified by {@link Collection#add})
  68.337 +     */
  68.338 +    public boolean add(E e) {
  68.339 +        linkLast(e);
  68.340 +        return true;
  68.341 +    }
  68.342 +
  68.343 +    /**
  68.344 +     * Removes the first occurrence of the specified element from this list,
  68.345 +     * if it is present.  If this list does not contain the element, it is
  68.346 +     * unchanged.  More formally, removes the element with the lowest index
  68.347 +     * {@code i} such that
  68.348 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
  68.349 +     * (if such an element exists).  Returns {@code true} if this list
  68.350 +     * contained the specified element (or equivalently, if this list
  68.351 +     * changed as a result of the call).
  68.352 +     *
  68.353 +     * @param o element to be removed from this list, if present
  68.354 +     * @return {@code true} if this list contained the specified element
  68.355 +     */
  68.356 +    public boolean remove(Object o) {
  68.357 +        if (o == null) {
  68.358 +            for (Node<E> x = first; x != null; x = x.next) {
  68.359 +                if (x.item == null) {
  68.360 +                    unlink(x);
  68.361 +                    return true;
  68.362 +                }
  68.363 +            }
  68.364 +        } else {
  68.365 +            for (Node<E> x = first; x != null; x = x.next) {
  68.366 +                if (o.equals(x.item)) {
  68.367 +                    unlink(x);
  68.368 +                    return true;
  68.369 +                }
  68.370 +            }
  68.371 +        }
  68.372 +        return false;
  68.373 +    }
  68.374 +
  68.375 +    /**
  68.376 +     * Appends all of the elements in the specified collection to the end of
  68.377 +     * this list, in the order that they are returned by the specified
  68.378 +     * collection's iterator.  The behavior of this operation is undefined if
  68.379 +     * the specified collection is modified while the operation is in
  68.380 +     * progress.  (Note that this will occur if the specified collection is
  68.381 +     * this list, and it's nonempty.)
  68.382 +     *
  68.383 +     * @param c collection containing elements to be added to this list
  68.384 +     * @return {@code true} if this list changed as a result of the call
  68.385 +     * @throws NullPointerException if the specified collection is null
  68.386 +     */
  68.387 +    public boolean addAll(Collection<? extends E> c) {
  68.388 +        return addAll(size, c);
  68.389 +    }
  68.390 +
  68.391 +    /**
  68.392 +     * Inserts all of the elements in the specified collection into this
  68.393 +     * list, starting at the specified position.  Shifts the element
  68.394 +     * currently at that position (if any) and any subsequent elements to
  68.395 +     * the right (increases their indices).  The new elements will appear
  68.396 +     * in the list in the order that they are returned by the
  68.397 +     * specified collection's iterator.
  68.398 +     *
  68.399 +     * @param index index at which to insert the first element
  68.400 +     *              from the specified collection
  68.401 +     * @param c collection containing elements to be added to this list
  68.402 +     * @return {@code true} if this list changed as a result of the call
  68.403 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  68.404 +     * @throws NullPointerException if the specified collection is null
  68.405 +     */
  68.406 +    public boolean addAll(int index, Collection<? extends E> c) {
  68.407 +        checkPositionIndex(index);
  68.408 +
  68.409 +        Object[] a = c.toArray();
  68.410 +        int numNew = a.length;
  68.411 +        if (numNew == 0)
  68.412 +            return false;
  68.413 +
  68.414 +        Node<E> pred, succ;
  68.415 +        if (index == size) {
  68.416 +            succ = null;
  68.417 +            pred = last;
  68.418 +        } else {
  68.419 +            succ = node(index);
  68.420 +            pred = succ.prev;
  68.421 +        }
  68.422 +
  68.423 +        for (Object o : a) {
  68.424 +            @SuppressWarnings("unchecked") E e = (E) o;
  68.425 +            Node<E> newNode = new Node<>(pred, e, null);
  68.426 +            if (pred == null)
  68.427 +                first = newNode;
  68.428 +            else
  68.429 +                pred.next = newNode;
  68.430 +            pred = newNode;
  68.431 +        }
  68.432 +
  68.433 +        if (succ == null) {
  68.434 +            last = pred;
  68.435 +        } else {
  68.436 +            pred.next = succ;
  68.437 +            succ.prev = pred;
  68.438 +        }
  68.439 +
  68.440 +        size += numNew;
  68.441 +        modCount++;
  68.442 +        return true;
  68.443 +    }
  68.444 +
  68.445 +    /**
  68.446 +     * Removes all of the elements from this list.
  68.447 +     * The list will be empty after this call returns.
  68.448 +     */
  68.449 +    public void clear() {
  68.450 +        // Clearing all of the links between nodes is "unnecessary", but:
  68.451 +        // - helps a generational GC if the discarded nodes inhabit
  68.452 +        //   more than one generation
  68.453 +        // - is sure to free memory even if there is a reachable Iterator
  68.454 +        for (Node<E> x = first; x != null; ) {
  68.455 +            Node<E> next = x.next;
  68.456 +            x.item = null;
  68.457 +            x.next = null;
  68.458 +            x.prev = null;
  68.459 +            x = next;
  68.460 +        }
  68.461 +        first = last = null;
  68.462 +        size = 0;
  68.463 +        modCount++;
  68.464 +    }
  68.465 +
  68.466 +
  68.467 +    // Positional Access Operations
  68.468 +
  68.469 +    /**
  68.470 +     * Returns the element at the specified position in this list.
  68.471 +     *
  68.472 +     * @param index index of the element to return
  68.473 +     * @return the element at the specified position in this list
  68.474 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  68.475 +     */
  68.476 +    public E get(int index) {
  68.477 +        checkElementIndex(index);
  68.478 +        return node(index).item;
  68.479 +    }
  68.480 +
  68.481 +    /**
  68.482 +     * Replaces the element at the specified position in this list with the
  68.483 +     * specified element.
  68.484 +     *
  68.485 +     * @param index index of the element to replace
  68.486 +     * @param element element to be stored at the specified position
  68.487 +     * @return the element previously at the specified position
  68.488 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  68.489 +     */
  68.490 +    public E set(int index, E element) {
  68.491 +        checkElementIndex(index);
  68.492 +        Node<E> x = node(index);
  68.493 +        E oldVal = x.item;
  68.494 +        x.item = element;
  68.495 +        return oldVal;
  68.496 +    }
  68.497 +
  68.498 +    /**
  68.499 +     * Inserts the specified element at the specified position in this list.
  68.500 +     * Shifts the element currently at that position (if any) and any
  68.501 +     * subsequent elements to the right (adds one to their indices).
  68.502 +     *
  68.503 +     * @param index index at which the specified element is to be inserted
  68.504 +     * @param element element to be inserted
  68.505 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  68.506 +     */
  68.507 +    public void add(int index, E element) {
  68.508 +        checkPositionIndex(index);
  68.509 +
  68.510 +        if (index == size)
  68.511 +            linkLast(element);
  68.512 +        else
  68.513 +            linkBefore(element, node(index));
  68.514 +    }
  68.515 +
  68.516 +    /**
  68.517 +     * Removes the element at the specified position in this list.  Shifts any
  68.518 +     * subsequent elements to the left (subtracts one from their indices).
  68.519 +     * Returns the element that was removed from the list.
  68.520 +     *
  68.521 +     * @param index the index of the element to be removed
  68.522 +     * @return the element previously at the specified position
  68.523 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  68.524 +     */
  68.525 +    public E remove(int index) {
  68.526 +        checkElementIndex(index);
  68.527 +        return unlink(node(index));
  68.528 +    }
  68.529 +
  68.530 +    /**
  68.531 +     * Tells if the argument is the index of an existing element.
  68.532 +     */
  68.533 +    private boolean isElementIndex(int index) {
  68.534 +        return index >= 0 && index < size;
  68.535 +    }
  68.536 +
  68.537 +    /**
  68.538 +     * Tells if the argument is the index of a valid position for an
  68.539 +     * iterator or an add operation.
  68.540 +     */
  68.541 +    private boolean isPositionIndex(int index) {
  68.542 +        return index >= 0 && index <= size;
  68.543 +    }
  68.544 +
  68.545 +    /**
  68.546 +     * Constructs an IndexOutOfBoundsException detail message.
  68.547 +     * Of the many possible refactorings of the error handling code,
  68.548 +     * this "outlining" performs best with both server and client VMs.
  68.549 +     */
  68.550 +    private String outOfBoundsMsg(int index) {
  68.551 +        return "Index: "+index+", Size: "+size;
  68.552 +    }
  68.553 +
  68.554 +    private void checkElementIndex(int index) {
  68.555 +        if (!isElementIndex(index))
  68.556 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  68.557 +    }
  68.558 +
  68.559 +    private void checkPositionIndex(int index) {
  68.560 +        if (!isPositionIndex(index))
  68.561 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  68.562 +    }
  68.563 +
  68.564 +    /**
  68.565 +     * Returns the (non-null) Node at the specified element index.
  68.566 +     */
  68.567 +    Node<E> node(int index) {
  68.568 +        // assert isElementIndex(index);
  68.569 +
  68.570 +        if (index < (size >> 1)) {
  68.571 +            Node<E> x = first;
  68.572 +            for (int i = 0; i < index; i++)
  68.573 +                x = x.next;
  68.574 +            return x;
  68.575 +        } else {
  68.576 +            Node<E> x = last;
  68.577 +            for (int i = size - 1; i > index; i--)
  68.578 +                x = x.prev;
  68.579 +            return x;
  68.580 +        }
  68.581 +    }
  68.582 +
  68.583 +    // Search Operations
  68.584 +
  68.585 +    /**
  68.586 +     * Returns the index of the first occurrence of the specified element
  68.587 +     * in this list, or -1 if this list does not contain the element.
  68.588 +     * More formally, returns the lowest index {@code i} such that
  68.589 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  68.590 +     * or -1 if there is no such index.
  68.591 +     *
  68.592 +     * @param o element to search for
  68.593 +     * @return the index of the first occurrence of the specified element in
  68.594 +     *         this list, or -1 if this list does not contain the element
  68.595 +     */
  68.596 +    public int indexOf(Object o) {
  68.597 +        int index = 0;
  68.598 +        if (o == null) {
  68.599 +            for (Node<E> x = first; x != null; x = x.next) {
  68.600 +                if (x.item == null)
  68.601 +                    return index;
  68.602 +                index++;
  68.603 +            }
  68.604 +        } else {
  68.605 +            for (Node<E> x = first; x != null; x = x.next) {
  68.606 +                if (o.equals(x.item))
  68.607 +                    return index;
  68.608 +                index++;
  68.609 +            }
  68.610 +        }
  68.611 +        return -1;
  68.612 +    }
  68.613 +
  68.614 +    /**
  68.615 +     * Returns the index of the last occurrence of the specified element
  68.616 +     * in this list, or -1 if this list does not contain the element.
  68.617 +     * More formally, returns the highest index {@code i} such that
  68.618 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  68.619 +     * or -1 if there is no such index.
  68.620 +     *
  68.621 +     * @param o element to search for
  68.622 +     * @return the index of the last occurrence of the specified element in
  68.623 +     *         this list, or -1 if this list does not contain the element
  68.624 +     */
  68.625 +    public int lastIndexOf(Object o) {
  68.626 +        int index = size;
  68.627 +        if (o == null) {
  68.628 +            for (Node<E> x = last; x != null; x = x.prev) {
  68.629 +                index--;
  68.630 +                if (x.item == null)
  68.631 +                    return index;
  68.632 +            }
  68.633 +        } else {
  68.634 +            for (Node<E> x = last; x != null; x = x.prev) {
  68.635 +                index--;
  68.636 +                if (o.equals(x.item))
  68.637 +                    return index;
  68.638 +            }
  68.639 +        }
  68.640 +        return -1;
  68.641 +    }
  68.642 +
  68.643 +    // Queue operations.
  68.644 +
  68.645 +    /**
  68.646 +     * Retrieves, but does not remove, the head (first element) of this list.
  68.647 +     *
  68.648 +     * @return the head of this list, or {@code null} if this list is empty
  68.649 +     * @since 1.5
  68.650 +     */
  68.651 +    public E peek() {
  68.652 +        final Node<E> f = first;
  68.653 +        return (f == null) ? null : f.item;
  68.654 +    }
  68.655 +
  68.656 +    /**
  68.657 +     * Retrieves, but does not remove, the head (first element) of this list.
  68.658 +     *
  68.659 +     * @return the head of this list
  68.660 +     * @throws NoSuchElementException if this list is empty
  68.661 +     * @since 1.5
  68.662 +     */
  68.663 +    public E element() {
  68.664 +        return getFirst();
  68.665 +    }
  68.666 +
  68.667 +    /**
  68.668 +     * Retrieves and removes the head (first element) of this list.
  68.669 +     *
  68.670 +     * @return the head of this list, or {@code null} if this list is empty
  68.671 +     * @since 1.5
  68.672 +     */
  68.673 +    public E poll() {
  68.674 +        final Node<E> f = first;
  68.675 +        return (f == null) ? null : unlinkFirst(f);
  68.676 +    }
  68.677 +
  68.678 +    /**
  68.679 +     * Retrieves and removes the head (first element) of this list.
  68.680 +     *
  68.681 +     * @return the head of this list
  68.682 +     * @throws NoSuchElementException if this list is empty
  68.683 +     * @since 1.5
  68.684 +     */
  68.685 +    public E remove() {
  68.686 +        return removeFirst();
  68.687 +    }
  68.688 +
  68.689 +    /**
  68.690 +     * Adds the specified element as the tail (last element) of this list.
  68.691 +     *
  68.692 +     * @param e the element to add
  68.693 +     * @return {@code true} (as specified by {@link Queue#offer})
  68.694 +     * @since 1.5
  68.695 +     */
  68.696 +    public boolean offer(E e) {
  68.697 +        return add(e);
  68.698 +    }
  68.699 +
  68.700 +    // Deque operations
  68.701 +    /**
  68.702 +     * Inserts the specified element at the front of this list.
  68.703 +     *
  68.704 +     * @param e the element to insert
  68.705 +     * @return {@code true} (as specified by {@link Deque#offerFirst})
  68.706 +     * @since 1.6
  68.707 +     */
  68.708 +    public boolean offerFirst(E e) {
  68.709 +        addFirst(e);
  68.710 +        return true;
  68.711 +    }
  68.712 +
  68.713 +    /**
  68.714 +     * Inserts the specified element at the end of this list.
  68.715 +     *
  68.716 +     * @param e the element to insert
  68.717 +     * @return {@code true} (as specified by {@link Deque#offerLast})
  68.718 +     * @since 1.6
  68.719 +     */
  68.720 +    public boolean offerLast(E e) {
  68.721 +        addLast(e);
  68.722 +        return true;
  68.723 +    }
  68.724 +
  68.725 +    /**
  68.726 +     * Retrieves, but does not remove, the first element of this list,
  68.727 +     * or returns {@code null} if this list is empty.
  68.728 +     *
  68.729 +     * @return the first element of this list, or {@code null}
  68.730 +     *         if this list is empty
  68.731 +     * @since 1.6
  68.732 +     */
  68.733 +    public E peekFirst() {
  68.734 +        final Node<E> f = first;
  68.735 +        return (f == null) ? null : f.item;
  68.736 +     }
  68.737 +
  68.738 +    /**
  68.739 +     * Retrieves, but does not remove, the last element of this list,
  68.740 +     * or returns {@code null} if this list is empty.
  68.741 +     *
  68.742 +     * @return the last element of this list, or {@code null}
  68.743 +     *         if this list is empty
  68.744 +     * @since 1.6
  68.745 +     */
  68.746 +    public E peekLast() {
  68.747 +        final Node<E> l = last;
  68.748 +        return (l == null) ? null : l.item;
  68.749 +    }
  68.750 +
  68.751 +    /**
  68.752 +     * Retrieves and removes the first element of this list,
  68.753 +     * or returns {@code null} if this list is empty.
  68.754 +     *
  68.755 +     * @return the first element of this list, or {@code null} if
  68.756 +     *     this list is empty
  68.757 +     * @since 1.6
  68.758 +     */
  68.759 +    public E pollFirst() {
  68.760 +        final Node<E> f = first;
  68.761 +        return (f == null) ? null : unlinkFirst(f);
  68.762 +    }
  68.763 +
  68.764 +    /**
  68.765 +     * Retrieves and removes the last element of this list,
  68.766 +     * or returns {@code null} if this list is empty.
  68.767 +     *
  68.768 +     * @return the last element of this list, or {@code null} if
  68.769 +     *     this list is empty
  68.770 +     * @since 1.6
  68.771 +     */
  68.772 +    public E pollLast() {
  68.773 +        final Node<E> l = last;
  68.774 +        return (l == null) ? null : unlinkLast(l);
  68.775 +    }
  68.776 +
  68.777 +    /**
  68.778 +     * Pushes an element onto the stack represented by this list.  In other
  68.779 +     * words, inserts the element at the front of this list.
  68.780 +     *
  68.781 +     * <p>This method is equivalent to {@link #addFirst}.
  68.782 +     *
  68.783 +     * @param e the element to push
  68.784 +     * @since 1.6
  68.785 +     */
  68.786 +    public void push(E e) {
  68.787 +        addFirst(e);
  68.788 +    }
  68.789 +
  68.790 +    /**
  68.791 +     * Pops an element from the stack represented by this list.  In other
  68.792 +     * words, removes and returns the first element of this list.
  68.793 +     *
  68.794 +     * <p>This method is equivalent to {@link #removeFirst()}.
  68.795 +     *
  68.796 +     * @return the element at the front of this list (which is the top
  68.797 +     *         of the stack represented by this list)
  68.798 +     * @throws NoSuchElementException if this list is empty
  68.799 +     * @since 1.6
  68.800 +     */
  68.801 +    public E pop() {
  68.802 +        return removeFirst();
  68.803 +    }
  68.804 +
  68.805 +    /**
  68.806 +     * Removes the first occurrence of the specified element in this
  68.807 +     * list (when traversing the list from head to tail).  If the list
  68.808 +     * does not contain the element, it is unchanged.
  68.809 +     *
  68.810 +     * @param o element to be removed from this list, if present
  68.811 +     * @return {@code true} if the list contained the specified element
  68.812 +     * @since 1.6
  68.813 +     */
  68.814 +    public boolean removeFirstOccurrence(Object o) {
  68.815 +        return remove(o);
  68.816 +    }
  68.817 +
  68.818 +    /**
  68.819 +     * Removes the last occurrence of the specified element in this
  68.820 +     * list (when traversing the list from head to tail).  If the list
  68.821 +     * does not contain the element, it is unchanged.
  68.822 +     *
  68.823 +     * @param o element to be removed from this list, if present
  68.824 +     * @return {@code true} if the list contained the specified element
  68.825 +     * @since 1.6
  68.826 +     */
  68.827 +    public boolean removeLastOccurrence(Object o) {
  68.828 +        if (o == null) {
  68.829 +            for (Node<E> x = last; x != null; x = x.prev) {
  68.830 +                if (x.item == null) {
  68.831 +                    unlink(x);
  68.832 +                    return true;
  68.833 +                }
  68.834 +            }
  68.835 +        } else {
  68.836 +            for (Node<E> x = last; x != null; x = x.prev) {
  68.837 +                if (o.equals(x.item)) {
  68.838 +                    unlink(x);
  68.839 +                    return true;
  68.840 +                }
  68.841 +            }
  68.842 +        }
  68.843 +        return false;
  68.844 +    }
  68.845 +
  68.846 +    /**
  68.847 +     * Returns a list-iterator of the elements in this list (in proper
  68.848 +     * sequence), starting at the specified position in the list.
  68.849 +     * Obeys the general contract of {@code List.listIterator(int)}.<p>
  68.850 +     *
  68.851 +     * The list-iterator is <i>fail-fast</i>: if the list is structurally
  68.852 +     * modified at any time after the Iterator is created, in any way except
  68.853 +     * through the list-iterator's own {@code remove} or {@code add}
  68.854 +     * methods, the list-iterator will throw a
  68.855 +     * {@code ConcurrentModificationException}.  Thus, in the face of
  68.856 +     * concurrent modification, the iterator fails quickly and cleanly, rather
  68.857 +     * than risking arbitrary, non-deterministic behavior at an undetermined
  68.858 +     * time in the future.
  68.859 +     *
  68.860 +     * @param index index of the first element to be returned from the
  68.861 +     *              list-iterator (by a call to {@code next})
  68.862 +     * @return a ListIterator of the elements in this list (in proper
  68.863 +     *         sequence), starting at the specified position in the list
  68.864 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  68.865 +     * @see List#listIterator(int)
  68.866 +     */
  68.867 +    public ListIterator<E> listIterator(int index) {
  68.868 +        checkPositionIndex(index);
  68.869 +        return new ListItr(index);
  68.870 +    }
  68.871 +
  68.872 +    private class ListItr implements ListIterator<E> {
  68.873 +        private Node<E> lastReturned = null;
  68.874 +        private Node<E> next;
  68.875 +        private int nextIndex;
  68.876 +        private int expectedModCount = modCount;
  68.877 +
  68.878 +        ListItr(int index) {
  68.879 +            // assert isPositionIndex(index);
  68.880 +            next = (index == size) ? null : node(index);
  68.881 +            nextIndex = index;
  68.882 +        }
  68.883 +
  68.884 +        public boolean hasNext() {
  68.885 +            return nextIndex < size;
  68.886 +        }
  68.887 +
  68.888 +        public E next() {
  68.889 +            checkForComodification();
  68.890 +            if (!hasNext())
  68.891 +                throw new NoSuchElementException();
  68.892 +
  68.893 +            lastReturned = next;
  68.894 +            next = next.next;
  68.895 +            nextIndex++;
  68.896 +            return lastReturned.item;
  68.897 +        }
  68.898 +
  68.899 +        public boolean hasPrevious() {
  68.900 +            return nextIndex > 0;
  68.901 +        }
  68.902 +
  68.903 +        public E previous() {
  68.904 +            checkForComodification();
  68.905 +            if (!hasPrevious())
  68.906 +                throw new NoSuchElementException();
  68.907 +
  68.908 +            lastReturned = next = (next == null) ? last : next.prev;
  68.909 +            nextIndex--;
  68.910 +            return lastReturned.item;
  68.911 +        }
  68.912 +
  68.913 +        public int nextIndex() {
  68.914 +            return nextIndex;
  68.915 +        }
  68.916 +
  68.917 +        public int previousIndex() {
  68.918 +            return nextIndex - 1;
  68.919 +        }
  68.920 +
  68.921 +        public void remove() {
  68.922 +            checkForComodification();
  68.923 +            if (lastReturned == null)
  68.924 +                throw new IllegalStateException();
  68.925 +
  68.926 +            Node<E> lastNext = lastReturned.next;
  68.927 +            unlink(lastReturned);
  68.928 +            if (next == lastReturned)
  68.929 +                next = lastNext;
  68.930 +            else
  68.931 +                nextIndex--;
  68.932 +            lastReturned = null;
  68.933 +            expectedModCount++;
  68.934 +        }
  68.935 +
  68.936 +        public void set(E e) {
  68.937 +            if (lastReturned == null)
  68.938 +                throw new IllegalStateException();
  68.939 +            checkForComodification();
  68.940 +            lastReturned.item = e;
  68.941 +        }
  68.942 +
  68.943 +        public void add(E e) {
  68.944 +            checkForComodification();
  68.945 +            lastReturned = null;
  68.946 +            if (next == null)
  68.947 +                linkLast(e);
  68.948 +            else
  68.949 +                linkBefore(e, next);
  68.950 +            nextIndex++;
  68.951 +            expectedModCount++;
  68.952 +        }
  68.953 +
  68.954 +        final void checkForComodification() {
  68.955 +            if (modCount != expectedModCount)
  68.956 +                throw new ConcurrentModificationException();
  68.957 +        }
  68.958 +    }
  68.959 +
  68.960 +    private static class Node<E> {
  68.961 +        E item;
  68.962 +        Node<E> next;
  68.963 +        Node<E> prev;
  68.964 +
  68.965 +        Node(Node<E> prev, E element, Node<E> next) {
  68.966 +            this.item = element;
  68.967 +            this.next = next;
  68.968 +            this.prev = prev;
  68.969 +        }
  68.970 +    }
  68.971 +
  68.972 +    /**
  68.973 +     * @since 1.6
  68.974 +     */
  68.975 +    public Iterator<E> descendingIterator() {
  68.976 +        return new DescendingIterator();
  68.977 +    }
  68.978 +
  68.979 +    /**
  68.980 +     * Adapter to provide descending iterators via ListItr.previous
  68.981 +     */
  68.982 +    private class DescendingIterator implements Iterator<E> {
  68.983 +        private final ListItr itr = new ListItr(size());
  68.984 +        public boolean hasNext() {
  68.985 +            return itr.hasPrevious();
  68.986 +        }
  68.987 +        public E next() {
  68.988 +            return itr.previous();
  68.989 +        }
  68.990 +        public void remove() {
  68.991 +            itr.remove();
  68.992 +        }
  68.993 +    }
  68.994 +
  68.995 +    @SuppressWarnings("unchecked")
  68.996 +    private LinkedList<E> superClone() {
  68.997 +        try {
  68.998 +            return (LinkedList<E>) super.clone();
  68.999 +        } catch (CloneNotSupportedException e) {
 68.1000 +            throw new InternalError();
 68.1001 +        }
 68.1002 +    }
 68.1003 +
 68.1004 +    /**
 68.1005 +     * Returns a shallow copy of this {@code LinkedList}. (The elements
 68.1006 +     * themselves are not cloned.)
 68.1007 +     *
 68.1008 +     * @return a shallow copy of this {@code LinkedList} instance
 68.1009 +     */
 68.1010 +    public Object clone() {
 68.1011 +        LinkedList<E> clone = superClone();
 68.1012 +
 68.1013 +        // Put clone into "virgin" state
 68.1014 +        clone.first = clone.last = null;
 68.1015 +        clone.size = 0;
 68.1016 +        clone.modCount = 0;
 68.1017 +
 68.1018 +        // Initialize clone with our elements
 68.1019 +        for (Node<E> x = first; x != null; x = x.next)
 68.1020 +            clone.add(x.item);
 68.1021 +
 68.1022 +        return clone;
 68.1023 +    }
 68.1024 +
 68.1025 +    /**
 68.1026 +     * Returns an array containing all of the elements in this list
 68.1027 +     * in proper sequence (from first to last element).
 68.1028 +     *
 68.1029 +     * <p>The returned array will be "safe" in that no references to it are
 68.1030 +     * maintained by this list.  (In other words, this method must allocate
 68.1031 +     * a new array).  The caller is thus free to modify the returned array.
 68.1032 +     *
 68.1033 +     * <p>This method acts as bridge between array-based and collection-based
 68.1034 +     * APIs.
 68.1035 +     *
 68.1036 +     * @return an array containing all of the elements in this list
 68.1037 +     *         in proper sequence
 68.1038 +     */
 68.1039 +    public Object[] toArray() {
 68.1040 +        Object[] result = new Object[size];
 68.1041 +        int i = 0;
 68.1042 +        for (Node<E> x = first; x != null; x = x.next)
 68.1043 +            result[i++] = x.item;
 68.1044 +        return result;
 68.1045 +    }
 68.1046 +
 68.1047 +    /**
 68.1048 +     * Returns an array containing all of the elements in this list in
 68.1049 +     * proper sequence (from first to last element); the runtime type of
 68.1050 +     * the returned array is that of the specified array.  If the list fits
 68.1051 +     * in the specified array, it is returned therein.  Otherwise, a new
 68.1052 +     * array is allocated with the runtime type of the specified array and
 68.1053 +     * the size of this list.
 68.1054 +     *
 68.1055 +     * <p>If the list fits in the specified array with room to spare (i.e.,
 68.1056 +     * the array has more elements than the list), the element in the array
 68.1057 +     * immediately following the end of the list is set to {@code null}.
 68.1058 +     * (This is useful in determining the length of the list <i>only</i> if
 68.1059 +     * the caller knows that the list does not contain any null elements.)
 68.1060 +     *
 68.1061 +     * <p>Like the {@link #toArray()} method, this method acts as bridge between
 68.1062 +     * array-based and collection-based APIs.  Further, this method allows
 68.1063 +     * precise control over the runtime type of the output array, and may,
 68.1064 +     * under certain circumstances, be used to save allocation costs.
 68.1065 +     *
 68.1066 +     * <p>Suppose {@code x} is a list known to contain only strings.
 68.1067 +     * The following code can be used to dump the list into a newly
 68.1068 +     * allocated array of {@code String}:
 68.1069 +     *
 68.1070 +     * <pre>
 68.1071 +     *     String[] y = x.toArray(new String[0]);</pre>
 68.1072 +     *
 68.1073 +     * Note that {@code toArray(new Object[0])} is identical in function to
 68.1074 +     * {@code toArray()}.
 68.1075 +     *
 68.1076 +     * @param a the array into which the elements of the list are to
 68.1077 +     *          be stored, if it is big enough; otherwise, a new array of the
 68.1078 +     *          same runtime type is allocated for this purpose.
 68.1079 +     * @return an array containing the elements of the list
 68.1080 +     * @throws ArrayStoreException if the runtime type of the specified array
 68.1081 +     *         is not a supertype of the runtime type of every element in
 68.1082 +     *         this list
 68.1083 +     * @throws NullPointerException if the specified array is null
 68.1084 +     */
 68.1085 +    @SuppressWarnings("unchecked")
 68.1086 +    public <T> T[] toArray(T[] a) {
 68.1087 +        if (a.length < size)
 68.1088 +            a = (T[])java.lang.reflect.Array.newInstance(
 68.1089 +                                a.getClass().getComponentType(), size);
 68.1090 +        int i = 0;
 68.1091 +        Object[] result = a;
 68.1092 +        for (Node<E> x = first; x != null; x = x.next)
 68.1093 +            result[i++] = x.item;
 68.1094 +
 68.1095 +        if (a.length > size)
 68.1096 +            a[size] = null;
 68.1097 +
 68.1098 +        return a;
 68.1099 +    }
 68.1100 +
 68.1101 +    private static final long serialVersionUID = 876323262645176354L;
 68.1102 +
 68.1103 +}
    69.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    69.2 +++ b/emul/compact/src/main/java/java/util/List.java	Sun Feb 03 07:48:42 2013 +0100
    69.3 @@ -0,0 +1,600 @@
    69.4 +/*
    69.5 + * Copyright (c) 1997, 2010, 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.util;
   69.30 +
   69.31 +/**
   69.32 + * An ordered collection (also known as a <i>sequence</i>).  The user of this
   69.33 + * interface has precise control over where in the list each element is
   69.34 + * inserted.  The user can access elements by their integer index (position in
   69.35 + * the list), and search for elements in the list.<p>
   69.36 + *
   69.37 + * Unlike sets, lists typically allow duplicate elements.  More formally,
   69.38 + * lists typically allow pairs of elements <tt>e1</tt> and <tt>e2</tt>
   69.39 + * such that <tt>e1.equals(e2)</tt>, and they typically allow multiple
   69.40 + * null elements if they allow null elements at all.  It is not inconceivable
   69.41 + * that someone might wish to implement a list that prohibits duplicates, by
   69.42 + * throwing runtime exceptions when the user attempts to insert them, but we
   69.43 + * expect this usage to be rare.<p>
   69.44 + *
   69.45 + * The <tt>List</tt> interface places additional stipulations, beyond those
   69.46 + * specified in the <tt>Collection</tt> interface, on the contracts of the
   69.47 + * <tt>iterator</tt>, <tt>add</tt>, <tt>remove</tt>, <tt>equals</tt>, and
   69.48 + * <tt>hashCode</tt> methods.  Declarations for other inherited methods are
   69.49 + * also included here for convenience.<p>
   69.50 + *
   69.51 + * The <tt>List</tt> interface provides four methods for positional (indexed)
   69.52 + * access to list elements.  Lists (like Java arrays) are zero based.  Note
   69.53 + * that these operations may execute in time proportional to the index value
   69.54 + * for some implementations (the <tt>LinkedList</tt> class, for
   69.55 + * example). Thus, iterating over the elements in a list is typically
   69.56 + * preferable to indexing through it if the caller does not know the
   69.57 + * implementation.<p>
   69.58 + *
   69.59 + * The <tt>List</tt> interface provides a special iterator, called a
   69.60 + * <tt>ListIterator</tt>, that allows element insertion and replacement, and
   69.61 + * bidirectional access in addition to the normal operations that the
   69.62 + * <tt>Iterator</tt> interface provides.  A method is provided to obtain a
   69.63 + * list iterator that starts at a specified position in the list.<p>
   69.64 + *
   69.65 + * The <tt>List</tt> interface provides two methods to search for a specified
   69.66 + * object.  From a performance standpoint, these methods should be used with
   69.67 + * caution.  In many implementations they will perform costly linear
   69.68 + * searches.<p>
   69.69 + *
   69.70 + * The <tt>List</tt> interface provides two methods to efficiently insert and
   69.71 + * remove multiple elements at an arbitrary point in the list.<p>
   69.72 + *
   69.73 + * Note: While it is permissible for lists to contain themselves as elements,
   69.74 + * extreme caution is advised: the <tt>equals</tt> and <tt>hashCode</tt>
   69.75 + * methods are no longer well defined on such a list.
   69.76 + *
   69.77 + * <p>Some list implementations have restrictions on the elements that
   69.78 + * they may contain.  For example, some implementations prohibit null elements,
   69.79 + * and some have restrictions on the types of their elements.  Attempting to
   69.80 + * add an ineligible element throws an unchecked exception, typically
   69.81 + * <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.  Attempting
   69.82 + * to query the presence of an ineligible element may throw an exception,
   69.83 + * or it may simply return false; some implementations will exhibit the former
   69.84 + * behavior and some will exhibit the latter.  More generally, attempting an
   69.85 + * operation on an ineligible element whose completion would not result in
   69.86 + * the insertion of an ineligible element into the list may throw an
   69.87 + * exception or it may succeed, at the option of the implementation.
   69.88 + * Such exceptions are marked as "optional" in the specification for this
   69.89 + * interface.
   69.90 + *
   69.91 + * <p>This interface is a member of the
   69.92 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   69.93 + * Java Collections Framework</a>.
   69.94 + *
   69.95 + * @param <E> the type of elements in this list
   69.96 + *
   69.97 + * @author  Josh Bloch
   69.98 + * @author  Neal Gafter
   69.99 + * @see Collection
  69.100 + * @see Set
  69.101 + * @see ArrayList
  69.102 + * @see LinkedList
  69.103 + * @see Vector
  69.104 + * @see Arrays#asList(Object[])
  69.105 + * @see Collections#nCopies(int, Object)
  69.106 + * @see Collections#EMPTY_LIST
  69.107 + * @see AbstractList
  69.108 + * @see AbstractSequentialList
  69.109 + * @since 1.2
  69.110 + */
  69.111 +
  69.112 +public interface List<E> extends Collection<E> {
  69.113 +    // Query Operations
  69.114 +
  69.115 +    /**
  69.116 +     * Returns the number of elements in this list.  If this list contains
  69.117 +     * more than <tt>Integer.MAX_VALUE</tt> elements, returns
  69.118 +     * <tt>Integer.MAX_VALUE</tt>.
  69.119 +     *
  69.120 +     * @return the number of elements in this list
  69.121 +     */
  69.122 +    int size();
  69.123 +
  69.124 +    /**
  69.125 +     * Returns <tt>true</tt> if this list contains no elements.
  69.126 +     *
  69.127 +     * @return <tt>true</tt> if this list contains no elements
  69.128 +     */
  69.129 +    boolean isEmpty();
  69.130 +
  69.131 +    /**
  69.132 +     * Returns <tt>true</tt> if this list contains the specified element.
  69.133 +     * More formally, returns <tt>true</tt> if and only if this list contains
  69.134 +     * at least one element <tt>e</tt> such that
  69.135 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  69.136 +     *
  69.137 +     * @param o element whose presence in this list is to be tested
  69.138 +     * @return <tt>true</tt> if this list contains the specified element
  69.139 +     * @throws ClassCastException if the type of the specified element
  69.140 +     *         is incompatible with this list
  69.141 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  69.142 +     * @throws NullPointerException if the specified element is null and this
  69.143 +     *         list does not permit null elements
  69.144 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  69.145 +     */
  69.146 +    boolean contains(Object o);
  69.147 +
  69.148 +    /**
  69.149 +     * Returns an iterator over the elements in this list in proper sequence.
  69.150 +     *
  69.151 +     * @return an iterator over the elements in this list in proper sequence
  69.152 +     */
  69.153 +    Iterator<E> iterator();
  69.154 +
  69.155 +    /**
  69.156 +     * Returns an array containing all of the elements in this list in proper
  69.157 +     * sequence (from first to last element).
  69.158 +     *
  69.159 +     * <p>The returned array will be "safe" in that no references to it are
  69.160 +     * maintained by this list.  (In other words, this method must
  69.161 +     * allocate a new array even if this list is backed by an array).
  69.162 +     * The caller is thus free to modify the returned array.
  69.163 +     *
  69.164 +     * <p>This method acts as bridge between array-based and collection-based
  69.165 +     * APIs.
  69.166 +     *
  69.167 +     * @return an array containing all of the elements in this list in proper
  69.168 +     *         sequence
  69.169 +     * @see Arrays#asList(Object[])
  69.170 +     */
  69.171 +    Object[] toArray();
  69.172 +
  69.173 +    /**
  69.174 +     * Returns an array containing all of the elements in this list in
  69.175 +     * proper sequence (from first to last element); the runtime type of
  69.176 +     * the returned array is that of the specified array.  If the list fits
  69.177 +     * in the specified array, it is returned therein.  Otherwise, a new
  69.178 +     * array is allocated with the runtime type of the specified array and
  69.179 +     * the size of this list.
  69.180 +     *
  69.181 +     * <p>If the list fits in the specified array with room to spare (i.e.,
  69.182 +     * the array has more elements than the list), the element in the array
  69.183 +     * immediately following the end of the list is set to <tt>null</tt>.
  69.184 +     * (This is useful in determining the length of the list <i>only</i> if
  69.185 +     * the caller knows that the list does not contain any null elements.)
  69.186 +     *
  69.187 +     * <p>Like the {@link #toArray()} method, this method acts as bridge between
  69.188 +     * array-based and collection-based APIs.  Further, this method allows
  69.189 +     * precise control over the runtime type of the output array, and may,
  69.190 +     * under certain circumstances, be used to save allocation costs.
  69.191 +     *
  69.192 +     * <p>Suppose <tt>x</tt> is a list known to contain only strings.
  69.193 +     * The following code can be used to dump the list into a newly
  69.194 +     * allocated array of <tt>String</tt>:
  69.195 +     *
  69.196 +     * <pre>
  69.197 +     *     String[] y = x.toArray(new String[0]);</pre>
  69.198 +     *
  69.199 +     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
  69.200 +     * <tt>toArray()</tt>.
  69.201 +     *
  69.202 +     * @param a the array into which the elements of this list are to
  69.203 +     *          be stored, if it is big enough; otherwise, a new array of the
  69.204 +     *          same runtime type is allocated for this purpose.
  69.205 +     * @return an array containing the elements of this list
  69.206 +     * @throws ArrayStoreException if the runtime type of the specified array
  69.207 +     *         is not a supertype of the runtime type of every element in
  69.208 +     *         this list
  69.209 +     * @throws NullPointerException if the specified array is null
  69.210 +     */
  69.211 +    <T> T[] toArray(T[] a);
  69.212 +
  69.213 +
  69.214 +    // Modification Operations
  69.215 +
  69.216 +    /**
  69.217 +     * Appends the specified element to the end of this list (optional
  69.218 +     * operation).
  69.219 +     *
  69.220 +     * <p>Lists that support this operation may place limitations on what
  69.221 +     * elements may be added to this list.  In particular, some
  69.222 +     * lists will refuse to add null elements, and others will impose
  69.223 +     * restrictions on the type of elements that may be added.  List
  69.224 +     * classes should clearly specify in their documentation any restrictions
  69.225 +     * on what elements may be added.
  69.226 +     *
  69.227 +     * @param e element to be appended to this list
  69.228 +     * @return <tt>true</tt> (as specified by {@link Collection#add})
  69.229 +     * @throws UnsupportedOperationException if the <tt>add</tt> operation
  69.230 +     *         is not supported by this list
  69.231 +     * @throws ClassCastException if the class of the specified element
  69.232 +     *         prevents it from being added to this list
  69.233 +     * @throws NullPointerException if the specified element is null and this
  69.234 +     *         list does not permit null elements
  69.235 +     * @throws IllegalArgumentException if some property of this element
  69.236 +     *         prevents it from being added to this list
  69.237 +     */
  69.238 +    boolean add(E e);
  69.239 +
  69.240 +    /**
  69.241 +     * Removes the first occurrence of the specified element from this list,
  69.242 +     * if it is present (optional operation).  If this list does not contain
  69.243 +     * the element, it is unchanged.  More formally, removes the element with
  69.244 +     * the lowest index <tt>i</tt> such that
  69.245 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
  69.246 +     * (if such an element exists).  Returns <tt>true</tt> if this list
  69.247 +     * contained the specified element (or equivalently, if this list changed
  69.248 +     * as a result of the call).
  69.249 +     *
  69.250 +     * @param o element to be removed from this list, if present
  69.251 +     * @return <tt>true</tt> if this list contained the specified element
  69.252 +     * @throws ClassCastException if the type of the specified element
  69.253 +     *         is incompatible with this list
  69.254 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  69.255 +     * @throws NullPointerException if the specified element is null and this
  69.256 +     *         list does not permit null elements
  69.257 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  69.258 +     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
  69.259 +     *         is not supported by this list
  69.260 +     */
  69.261 +    boolean remove(Object o);
  69.262 +
  69.263 +
  69.264 +    // Bulk Modification Operations
  69.265 +
  69.266 +    /**
  69.267 +     * Returns <tt>true</tt> if this list contains all of the elements of the
  69.268 +     * specified collection.
  69.269 +     *
  69.270 +     * @param  c collection to be checked for containment in this list
  69.271 +     * @return <tt>true</tt> if this list contains all of the elements of the
  69.272 +     *         specified collection
  69.273 +     * @throws ClassCastException if the types of one or more elements
  69.274 +     *         in the specified collection are incompatible with this
  69.275 +     *         list
  69.276 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  69.277 +     * @throws NullPointerException if the specified collection contains one
  69.278 +     *         or more null elements and this list does not permit null
  69.279 +     *         elements
  69.280 +     *         (<a href="Collection.html#optional-restrictions">optional</a>),
  69.281 +     *         or if the specified collection is null
  69.282 +     * @see #contains(Object)
  69.283 +     */
  69.284 +    boolean containsAll(Collection<?> c);
  69.285 +
  69.286 +    /**
  69.287 +     * Appends all of the elements in the specified collection to the end of
  69.288 +     * this list, in the order that they are returned by the specified
  69.289 +     * collection's iterator (optional operation).  The behavior of this
  69.290 +     * operation is undefined if the specified collection is modified while
  69.291 +     * the operation is in progress.  (Note that this will occur if the
  69.292 +     * specified collection is this list, and it's nonempty.)
  69.293 +     *
  69.294 +     * @param c collection containing elements to be added to this list
  69.295 +     * @return <tt>true</tt> if this list changed as a result of the call
  69.296 +     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
  69.297 +     *         is not supported by this list
  69.298 +     * @throws ClassCastException if the class of an element of the specified
  69.299 +     *         collection prevents it from being added to this list
  69.300 +     * @throws NullPointerException if the specified collection contains one
  69.301 +     *         or more null elements and this list does not permit null
  69.302 +     *         elements, or if the specified collection is null
  69.303 +     * @throws IllegalArgumentException if some property of an element of the
  69.304 +     *         specified collection prevents it from being added to this list
  69.305 +     * @see #add(Object)
  69.306 +     */
  69.307 +    boolean addAll(Collection<? extends E> c);
  69.308 +
  69.309 +    /**
  69.310 +     * Inserts all of the elements in the specified collection into this
  69.311 +     * list at the specified position (optional operation).  Shifts the
  69.312 +     * element currently at that position (if any) and any subsequent
  69.313 +     * elements to the right (increases their indices).  The new elements
  69.314 +     * will appear in this list in the order that they are returned by the
  69.315 +     * specified collection's iterator.  The behavior of this operation is
  69.316 +     * undefined if the specified collection is modified while the
  69.317 +     * operation is in progress.  (Note that this will occur if the specified
  69.318 +     * collection is this list, and it's nonempty.)
  69.319 +     *
  69.320 +     * @param index index at which to insert the first element from the
  69.321 +     *              specified collection
  69.322 +     * @param c collection containing elements to be added to this list
  69.323 +     * @return <tt>true</tt> if this list changed as a result of the call
  69.324 +     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
  69.325 +     *         is not supported by this list
  69.326 +     * @throws ClassCastException if the class of an element of the specified
  69.327 +     *         collection prevents it from being added to this list
  69.328 +     * @throws NullPointerException if the specified collection contains one
  69.329 +     *         or more null elements and this list does not permit null
  69.330 +     *         elements, or if the specified collection is null
  69.331 +     * @throws IllegalArgumentException if some property of an element of the
  69.332 +     *         specified collection prevents it from being added to this list
  69.333 +     * @throws IndexOutOfBoundsException if the index is out of range
  69.334 +     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
  69.335 +     */
  69.336 +    boolean addAll(int index, Collection<? extends E> c);
  69.337 +
  69.338 +    /**
  69.339 +     * Removes from this list all of its elements that are contained in the
  69.340 +     * specified collection (optional operation).
  69.341 +     *
  69.342 +     * @param c collection containing elements to be removed from this list
  69.343 +     * @return <tt>true</tt> if this list changed as a result of the call
  69.344 +     * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
  69.345 +     *         is not supported by this list
  69.346 +     * @throws ClassCastException if the class of an element of this list
  69.347 +     *         is incompatible with the specified collection
  69.348 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  69.349 +     * @throws NullPointerException if this list contains a null element and the
  69.350 +     *         specified collection does not permit null elements
  69.351 +     *         (<a href="Collection.html#optional-restrictions">optional</a>),
  69.352 +     *         or if the specified collection is null
  69.353 +     * @see #remove(Object)
  69.354 +     * @see #contains(Object)
  69.355 +     */
  69.356 +    boolean removeAll(Collection<?> c);
  69.357 +
  69.358 +    /**
  69.359 +     * Retains only the elements in this list that are contained in the
  69.360 +     * specified collection (optional operation).  In other words, removes
  69.361 +     * from this list all of its elements that are not contained in the
  69.362 +     * specified collection.
  69.363 +     *
  69.364 +     * @param c collection containing elements to be retained in this list
  69.365 +     * @return <tt>true</tt> if this list changed as a result of the call
  69.366 +     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
  69.367 +     *         is not supported by this list
  69.368 +     * @throws ClassCastException if the class of an element of this list
  69.369 +     *         is incompatible with the specified collection
  69.370 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  69.371 +     * @throws NullPointerException if this list contains a null element and the
  69.372 +     *         specified collection does not permit null elements
  69.373 +     *         (<a href="Collection.html#optional-restrictions">optional</a>),
  69.374 +     *         or if the specified collection is null
  69.375 +     * @see #remove(Object)
  69.376 +     * @see #contains(Object)
  69.377 +     */
  69.378 +    boolean retainAll(Collection<?> c);
  69.379 +
  69.380 +    /**
  69.381 +     * Removes all of the elements from this list (optional operation).
  69.382 +     * The list will be empty after this call returns.
  69.383 +     *
  69.384 +     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
  69.385 +     *         is not supported by this list
  69.386 +     */
  69.387 +    void clear();
  69.388 +
  69.389 +
  69.390 +    // Comparison and hashing
  69.391 +
  69.392 +    /**
  69.393 +     * Compares the specified object with this list for equality.  Returns
  69.394 +     * <tt>true</tt> if and only if the specified object is also a list, both
  69.395 +     * lists have the same size, and all corresponding pairs of elements in
  69.396 +     * the two lists are <i>equal</i>.  (Two elements <tt>e1</tt> and
  69.397 +     * <tt>e2</tt> are <i>equal</i> if <tt>(e1==null ? e2==null :
  69.398 +     * e1.equals(e2))</tt>.)  In other words, two lists are defined to be
  69.399 +     * equal if they contain the same elements in the same order.  This
  69.400 +     * definition ensures that the equals method works properly across
  69.401 +     * different implementations of the <tt>List</tt> interface.
  69.402 +     *
  69.403 +     * @param o the object to be compared for equality with this list
  69.404 +     * @return <tt>true</tt> if the specified object is equal to this list
  69.405 +     */
  69.406 +    boolean equals(Object o);
  69.407 +
  69.408 +    /**
  69.409 +     * Returns the hash code value for this list.  The hash code of a list
  69.410 +     * is defined to be the result of the following calculation:
  69.411 +     * <pre>
  69.412 +     *  int hashCode = 1;
  69.413 +     *  for (E e : list)
  69.414 +     *      hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
  69.415 +     * </pre>
  69.416 +     * This ensures that <tt>list1.equals(list2)</tt> implies that
  69.417 +     * <tt>list1.hashCode()==list2.hashCode()</tt> for any two lists,
  69.418 +     * <tt>list1</tt> and <tt>list2</tt>, as required by the general
  69.419 +     * contract of {@link Object#hashCode}.
  69.420 +     *
  69.421 +     * @return the hash code value for this list
  69.422 +     * @see Object#equals(Object)
  69.423 +     * @see #equals(Object)
  69.424 +     */
  69.425 +    int hashCode();
  69.426 +
  69.427 +
  69.428 +    // Positional Access Operations
  69.429 +
  69.430 +    /**
  69.431 +     * Returns the element at the specified position in this list.
  69.432 +     *
  69.433 +     * @param index index of the element to return
  69.434 +     * @return the element at the specified position in this list
  69.435 +     * @throws IndexOutOfBoundsException if the index is out of range
  69.436 +     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
  69.437 +     */
  69.438 +    E get(int index);
  69.439 +
  69.440 +    /**
  69.441 +     * Replaces the element at the specified position in this list with the
  69.442 +     * specified element (optional operation).
  69.443 +     *
  69.444 +     * @param index index of the element to replace
  69.445 +     * @param element element to be stored at the specified position
  69.446 +     * @return the element previously at the specified position
  69.447 +     * @throws UnsupportedOperationException if the <tt>set</tt> operation
  69.448 +     *         is not supported by this list
  69.449 +     * @throws ClassCastException if the class of the specified element
  69.450 +     *         prevents it from being added to this list
  69.451 +     * @throws NullPointerException if the specified element is null and
  69.452 +     *         this list does not permit null elements
  69.453 +     * @throws IllegalArgumentException if some property of the specified
  69.454 +     *         element prevents it from being added to this list
  69.455 +     * @throws IndexOutOfBoundsException if the index is out of range
  69.456 +     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
  69.457 +     */
  69.458 +    E set(int index, E element);
  69.459 +
  69.460 +    /**
  69.461 +     * Inserts the specified element at the specified position in this list
  69.462 +     * (optional operation).  Shifts the element currently at that position
  69.463 +     * (if any) and any subsequent elements to the right (adds one to their
  69.464 +     * indices).
  69.465 +     *
  69.466 +     * @param index index at which the specified element is to be inserted
  69.467 +     * @param element element to be inserted
  69.468 +     * @throws UnsupportedOperationException if the <tt>add</tt> operation
  69.469 +     *         is not supported by this list
  69.470 +     * @throws ClassCastException if the class of the specified element
  69.471 +     *         prevents it from being added to this list
  69.472 +     * @throws NullPointerException if the specified element is null and
  69.473 +     *         this list does not permit null elements
  69.474 +     * @throws IllegalArgumentException if some property of the specified
  69.475 +     *         element prevents it from being added to this list
  69.476 +     * @throws IndexOutOfBoundsException if the index is out of range
  69.477 +     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
  69.478 +     */
  69.479 +    void add(int index, E element);
  69.480 +
  69.481 +    /**
  69.482 +     * Removes the element at the specified position in this list (optional
  69.483 +     * operation).  Shifts any subsequent elements to the left (subtracts one
  69.484 +     * from their indices).  Returns the element that was removed from the
  69.485 +     * list.
  69.486 +     *
  69.487 +     * @param index the index of the element to be removed
  69.488 +     * @return the element previously at the specified position
  69.489 +     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
  69.490 +     *         is not supported by this list
  69.491 +     * @throws IndexOutOfBoundsException if the index is out of range
  69.492 +     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
  69.493 +     */
  69.494 +    E remove(int index);
  69.495 +
  69.496 +
  69.497 +    // Search Operations
  69.498 +
  69.499 +    /**
  69.500 +     * Returns the index of the first occurrence of the specified element
  69.501 +     * in this list, or -1 if this list does not contain the element.
  69.502 +     * More formally, returns the lowest index <tt>i</tt> such that
  69.503 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  69.504 +     * or -1 if there is no such index.
  69.505 +     *
  69.506 +     * @param o element to search for
  69.507 +     * @return the index of the first occurrence of the specified element in
  69.508 +     *         this list, or -1 if this list does not contain the element
  69.509 +     * @throws ClassCastException if the type of the specified element
  69.510 +     *         is incompatible with this list
  69.511 +     *         (<a href="Collection.html#optional-restrictions">optional</a>)
  69.512 +     * @throws NullPointerException if the specified element is null and this
  69.513 +     *         list does not permit null elements
  69.514 +     *         (<a href="Collection.html#optional-restrictions">optional</a>)
  69.515 +     */
  69.516 +    int indexOf(Object o);
  69.517 +
  69.518 +    /**
  69.519 +     * Returns the index of the last occurrence of the specified element
  69.520 +     * in this list, or -1 if this list does not contain the element.
  69.521 +     * More formally, returns the highest index <tt>i</tt> such that
  69.522 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  69.523 +     * or -1 if there is no such index.
  69.524 +     *
  69.525 +     * @param o element to search for
  69.526 +     * @return the index of the last occurrence of the specified element in
  69.527 +     *         this list, or -1 if this list does not contain the element
  69.528 +     * @throws ClassCastException if the type of the specified element
  69.529 +     *         is incompatible with this list
  69.530 +     *         (<a href="Collection.html#optional-restrictions">optional</a>)
  69.531 +     * @throws NullPointerException if the specified element is null and this
  69.532 +     *         list does not permit null elements
  69.533 +     *         (<a href="Collection.html#optional-restrictions">optional</a>)
  69.534 +     */
  69.535 +    int lastIndexOf(Object o);
  69.536 +
  69.537 +
  69.538 +    // List Iterators
  69.539 +
  69.540 +    /**
  69.541 +     * Returns a list iterator over the elements in this list (in proper
  69.542 +     * sequence).
  69.543 +     *
  69.544 +     * @return a list iterator over the elements in this list (in proper
  69.545 +     *         sequence)
  69.546 +     */
  69.547 +    ListIterator<E> listIterator();
  69.548 +
  69.549 +    /**
  69.550 +     * Returns a list iterator over the elements in this list (in proper
  69.551 +     * sequence), starting at the specified position in the list.
  69.552 +     * The specified index indicates the first element that would be
  69.553 +     * returned by an initial call to {@link ListIterator#next next}.
  69.554 +     * An initial call to {@link ListIterator#previous previous} would
  69.555 +     * return the element with the specified index minus one.
  69.556 +     *
  69.557 +     * @param index index of the first element to be returned from the
  69.558 +     *        list iterator (by a call to {@link ListIterator#next next})
  69.559 +     * @return a list iterator over the elements in this list (in proper
  69.560 +     *         sequence), starting at the specified position in the list
  69.561 +     * @throws IndexOutOfBoundsException if the index is out of range
  69.562 +     *         ({@code index < 0 || index > size()})
  69.563 +     */
  69.564 +    ListIterator<E> listIterator(int index);
  69.565 +
  69.566 +    // View
  69.567 +
  69.568 +    /**
  69.569 +     * Returns a view of the portion of this list between the specified
  69.570 +     * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.  (If
  69.571 +     * <tt>fromIndex</tt> and <tt>toIndex</tt> are equal, the returned list is
  69.572 +     * empty.)  The returned list is backed by this list, so non-structural
  69.573 +     * changes in the returned list are reflected in this list, and vice-versa.
  69.574 +     * The returned list supports all of the optional list operations supported
  69.575 +     * by this list.<p>
  69.576 +     *
  69.577 +     * This method eliminates the need for explicit range operations (of
  69.578 +     * the sort that commonly exist for arrays).  Any operation that expects
  69.579 +     * a list can be used as a range operation by passing a subList view
  69.580 +     * instead of a whole list.  For example, the following idiom
  69.581 +     * removes a range of elements from a list:
  69.582 +     * <pre>
  69.583 +     *      list.subList(from, to).clear();
  69.584 +     * </pre>
  69.585 +     * Similar idioms may be constructed for <tt>indexOf</tt> and
  69.586 +     * <tt>lastIndexOf</tt>, and all of the algorithms in the
  69.587 +     * <tt>Collections</tt> class can be applied to a subList.<p>
  69.588 +     *
  69.589 +     * The semantics of the list returned by this method become undefined if
  69.590 +     * the backing list (i.e., this list) is <i>structurally modified</i> in
  69.591 +     * any way other than via the returned list.  (Structural modifications are
  69.592 +     * those that change the size of this list, or otherwise perturb it in such
  69.593 +     * a fashion that iterations in progress may yield incorrect results.)
  69.594 +     *
  69.595 +     * @param fromIndex low endpoint (inclusive) of the subList
  69.596 +     * @param toIndex high endpoint (exclusive) of the subList
  69.597 +     * @return a view of the specified range within this list
  69.598 +     * @throws IndexOutOfBoundsException for an illegal endpoint index value
  69.599 +     *         (<tt>fromIndex &lt; 0 || toIndex &gt; size ||
  69.600 +     *         fromIndex &gt; toIndex</tt>)
  69.601 +     */
  69.602 +    List<E> subList(int fromIndex, int toIndex);
  69.603 +}
    70.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    70.2 +++ b/emul/compact/src/main/java/java/util/ListIterator.java	Sun Feb 03 07:48:42 2013 +0100
    70.3 @@ -0,0 +1,195 @@
    70.4 +/*
    70.5 + * Copyright (c) 1997, 2007, 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.util;
   70.30 +
   70.31 +/**
   70.32 + * An iterator for lists that allows the programmer
   70.33 + * to traverse the list in either direction, modify
   70.34 + * the list during iteration, and obtain the iterator's
   70.35 + * current position in the list. A {@code ListIterator}
   70.36 + * has no current element; its <I>cursor position</I> always
   70.37 + * lies between the element that would be returned by a call
   70.38 + * to {@code previous()} and the element that would be
   70.39 + * returned by a call to {@code next()}.
   70.40 + * An iterator for a list of length {@code n} has {@code n+1} possible
   70.41 + * cursor positions, as illustrated by the carets ({@code ^}) below:
   70.42 + * <PRE>
   70.43 + *                      Element(0)   Element(1)   Element(2)   ... Element(n-1)
   70.44 + * cursor positions:  ^            ^            ^            ^                  ^
   70.45 + * </PRE>
   70.46 + * Note that the {@link #remove} and {@link #set(Object)} methods are
   70.47 + * <i>not</i> defined in terms of the cursor position;  they are defined to
   70.48 + * operate on the last element returned by a call to {@link #next} or
   70.49 + * {@link #previous()}.
   70.50 + *
   70.51 + * <p>This interface is a member of the
   70.52 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   70.53 + * Java Collections Framework</a>.
   70.54 + *
   70.55 + * @author  Josh Bloch
   70.56 + * @see Collection
   70.57 + * @see List
   70.58 + * @see Iterator
   70.59 + * @see Enumeration
   70.60 + * @see List#listIterator()
   70.61 + * @since   1.2
   70.62 + */
   70.63 +public interface ListIterator<E> extends Iterator<E> {
   70.64 +    // Query Operations
   70.65 +
   70.66 +    /**
   70.67 +     * Returns {@code true} if this list iterator has more elements when
   70.68 +     * traversing the list in the forward direction. (In other words,
   70.69 +     * returns {@code true} if {@link #next} would return an element rather
   70.70 +     * than throwing an exception.)
   70.71 +     *
   70.72 +     * @return {@code true} if the list iterator has more elements when
   70.73 +     *         traversing the list in the forward direction
   70.74 +     */
   70.75 +    boolean hasNext();
   70.76 +
   70.77 +    /**
   70.78 +     * Returns the next element in the list and advances the cursor position.
   70.79 +     * This method may be called repeatedly to iterate through the list,
   70.80 +     * or intermixed with calls to {@link #previous} to go back and forth.
   70.81 +     * (Note that alternating calls to {@code next} and {@code previous}
   70.82 +     * will return the same element repeatedly.)
   70.83 +     *
   70.84 +     * @return the next element in the list
   70.85 +     * @throws NoSuchElementException if the iteration has no next element
   70.86 +     */
   70.87 +    E next();
   70.88 +
   70.89 +    /**
   70.90 +     * Returns {@code true} if this list iterator has more elements when
   70.91 +     * traversing the list in the reverse direction.  (In other words,
   70.92 +     * returns {@code true} if {@link #previous} would return an element
   70.93 +     * rather than throwing an exception.)
   70.94 +     *
   70.95 +     * @return {@code true} if the list iterator has more elements when
   70.96 +     *         traversing the list in the reverse direction
   70.97 +     */
   70.98 +    boolean hasPrevious();
   70.99 +
  70.100 +    /**
  70.101 +     * Returns the previous element in the list and moves the cursor
  70.102 +     * position backwards.  This method may be called repeatedly to
  70.103 +     * iterate through the list backwards, or intermixed with calls to
  70.104 +     * {@link #next} to go back and forth.  (Note that alternating calls
  70.105 +     * to {@code next} and {@code previous} will return the same
  70.106 +     * element repeatedly.)
  70.107 +     *
  70.108 +     * @return the previous element in the list
  70.109 +     * @throws NoSuchElementException if the iteration has no previous
  70.110 +     *         element
  70.111 +     */
  70.112 +    E previous();
  70.113 +
  70.114 +    /**
  70.115 +     * Returns the index of the element that would be returned by a
  70.116 +     * subsequent call to {@link #next}. (Returns list size if the list
  70.117 +     * iterator is at the end of the list.)
  70.118 +     *
  70.119 +     * @return the index of the element that would be returned by a
  70.120 +     *         subsequent call to {@code next}, or list size if the list
  70.121 +     *         iterator is at the end of the list
  70.122 +     */
  70.123 +    int nextIndex();
  70.124 +
  70.125 +    /**
  70.126 +     * Returns the index of the element that would be returned by a
  70.127 +     * subsequent call to {@link #previous}. (Returns -1 if the list
  70.128 +     * iterator is at the beginning of the list.)
  70.129 +     *
  70.130 +     * @return the index of the element that would be returned by a
  70.131 +     *         subsequent call to {@code previous}, or -1 if the list
  70.132 +     *         iterator is at the beginning of the list
  70.133 +     */
  70.134 +    int previousIndex();
  70.135 +
  70.136 +
  70.137 +    // Modification Operations
  70.138 +
  70.139 +    /**
  70.140 +     * Removes from the list the last element that was returned by {@link
  70.141 +     * #next} or {@link #previous} (optional operation).  This call can
  70.142 +     * only be made once per call to {@code next} or {@code previous}.
  70.143 +     * It can be made only if {@link #add} has not been
  70.144 +     * called after the last call to {@code next} or {@code previous}.
  70.145 +     *
  70.146 +     * @throws UnsupportedOperationException if the {@code remove}
  70.147 +     *         operation is not supported by this list iterator
  70.148 +     * @throws IllegalStateException if neither {@code next} nor
  70.149 +     *         {@code previous} have been called, or {@code remove} or
  70.150 +     *         {@code add} have been called after the last call to
  70.151 +     *         {@code next} or {@code previous}
  70.152 +     */
  70.153 +    void remove();
  70.154 +
  70.155 +    /**
  70.156 +     * Replaces the last element returned by {@link #next} or
  70.157 +     * {@link #previous} with the specified element (optional operation).
  70.158 +     * This call can be made only if neither {@link #remove} nor {@link
  70.159 +     * #add} have been called after the last call to {@code next} or
  70.160 +     * {@code previous}.
  70.161 +     *
  70.162 +     * @param e the element with which to replace the last element returned by
  70.163 +     *          {@code next} or {@code previous}
  70.164 +     * @throws UnsupportedOperationException if the {@code set} operation
  70.165 +     *         is not supported by this list iterator
  70.166 +     * @throws ClassCastException if the class of the specified element
  70.167 +     *         prevents it from being added to this list
  70.168 +     * @throws IllegalArgumentException if some aspect of the specified
  70.169 +     *         element prevents it from being added to this list
  70.170 +     * @throws IllegalStateException if neither {@code next} nor
  70.171 +     *         {@code previous} have been called, or {@code remove} or
  70.172 +     *         {@code add} have been called after the last call to
  70.173 +     *         {@code next} or {@code previous}
  70.174 +     */
  70.175 +    void set(E e);
  70.176 +
  70.177 +    /**
  70.178 +     * Inserts the specified element into the list (optional operation).
  70.179 +     * The element is inserted immediately before the element that
  70.180 +     * would be returned by {@link #next}, if any, and after the element
  70.181 +     * that would be returned by {@link #previous}, if any.  (If the
  70.182 +     * list contains no elements, the new element becomes the sole element
  70.183 +     * on the list.)  The new element is inserted before the implicit
  70.184 +     * cursor: a subsequent call to {@code next} would be unaffected, and a
  70.185 +     * subsequent call to {@code previous} would return the new element.
  70.186 +     * (This call increases by one the value that would be returned by a
  70.187 +     * call to {@code nextIndex} or {@code previousIndex}.)
  70.188 +     *
  70.189 +     * @param e the element to insert
  70.190 +     * @throws UnsupportedOperationException if the {@code add} method is
  70.191 +     *         not supported by this list iterator
  70.192 +     * @throws ClassCastException if the class of the specified element
  70.193 +     *         prevents it from being added to this list
  70.194 +     * @throws IllegalArgumentException if some aspect of this element
  70.195 +     *         prevents it from being added to this list
  70.196 +     */
  70.197 +    void add(E e);
  70.198 +}
    71.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    71.2 +++ b/emul/compact/src/main/java/java/util/Map.java	Sun Feb 03 07:48:42 2013 +0100
    71.3 @@ -0,0 +1,478 @@
    71.4 +/*
    71.5 + * Copyright (c) 1997, 2006, 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.util;
   71.30 +
   71.31 +/**
   71.32 + * An object that maps keys to values.  A map cannot contain duplicate keys;
   71.33 + * each key can map to at most one value.
   71.34 + *
   71.35 + * <p>This interface takes the place of the <tt>Dictionary</tt> class, which
   71.36 + * was a totally abstract class rather than an interface.
   71.37 + *
   71.38 + * <p>The <tt>Map</tt> interface provides three <i>collection views</i>, which
   71.39 + * allow a map's contents to be viewed as a set of keys, collection of values,
   71.40 + * or set of key-value mappings.  The <i>order</i> of a map is defined as
   71.41 + * the order in which the iterators on the map's collection views return their
   71.42 + * elements.  Some map implementations, like the <tt>TreeMap</tt> class, make
   71.43 + * specific guarantees as to their order; others, like the <tt>HashMap</tt>
   71.44 + * class, do not.
   71.45 + *
   71.46 + * <p>Note: great care must be exercised if mutable objects are used as map
   71.47 + * keys.  The behavior of a map is not specified if the value of an object is
   71.48 + * changed in a manner that affects <tt>equals</tt> comparisons while the
   71.49 + * object is a key in the map.  A special case of this prohibition is that it
   71.50 + * is not permissible for a map to contain itself as a key.  While it is
   71.51 + * permissible for a map to contain itself as a value, extreme caution is
   71.52 + * advised: the <tt>equals</tt> and <tt>hashCode</tt> methods are no longer
   71.53 + * well defined on such a map.
   71.54 + *
   71.55 + * <p>All general-purpose map implementation classes should provide two
   71.56 + * "standard" constructors: a void (no arguments) constructor which creates an
   71.57 + * empty map, and a constructor with a single argument of type <tt>Map</tt>,
   71.58 + * which creates a new map with the same key-value mappings as its argument.
   71.59 + * In effect, the latter constructor allows the user to copy any map,
   71.60 + * producing an equivalent map of the desired class.  There is no way to
   71.61 + * enforce this recommendation (as interfaces cannot contain constructors) but
   71.62 + * all of the general-purpose map implementations in the JDK comply.
   71.63 + *
   71.64 + * <p>The "destructive" methods contained in this interface, that is, the
   71.65 + * methods that modify the map on which they operate, are specified to throw
   71.66 + * <tt>UnsupportedOperationException</tt> if this map does not support the
   71.67 + * operation.  If this is the case, these methods may, but are not required
   71.68 + * to, throw an <tt>UnsupportedOperationException</tt> if the invocation would
   71.69 + * have no effect on the map.  For example, invoking the {@link #putAll(Map)}
   71.70 + * method on an unmodifiable map may, but is not required to, throw the
   71.71 + * exception if the map whose mappings are to be "superimposed" is empty.
   71.72 + *
   71.73 + * <p>Some map implementations have restrictions on the keys and values they
   71.74 + * may contain.  For example, some implementations prohibit null keys and
   71.75 + * values, and some have restrictions on the types of their keys.  Attempting
   71.76 + * to insert an ineligible key or value throws an unchecked exception,
   71.77 + * typically <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.
   71.78 + * Attempting to query the presence of an ineligible key or value may throw an
   71.79 + * exception, or it may simply return false; some implementations will exhibit
   71.80 + * the former behavior and some will exhibit the latter.  More generally,
   71.81 + * attempting an operation on an ineligible key or value whose completion
   71.82 + * would not result in the insertion of an ineligible element into the map may
   71.83 + * throw an exception or it may succeed, at the option of the implementation.
   71.84 + * Such exceptions are marked as "optional" in the specification for this
   71.85 + * interface.
   71.86 + *
   71.87 + * <p>This interface is a member of the
   71.88 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   71.89 + * Java Collections Framework</a>.
   71.90 + *
   71.91 + * <p>Many methods in Collections Framework interfaces are defined
   71.92 + * in terms of the {@link Object#equals(Object) equals} method.  For
   71.93 + * example, the specification for the {@link #containsKey(Object)
   71.94 + * containsKey(Object key)} method says: "returns <tt>true</tt> if and
   71.95 + * only if this map contains a mapping for a key <tt>k</tt> such that
   71.96 + * <tt>(key==null ? k==null : key.equals(k))</tt>." This specification should
   71.97 + * <i>not</i> be construed to imply that invoking <tt>Map.containsKey</tt>
   71.98 + * with a non-null argument <tt>key</tt> will cause <tt>key.equals(k)</tt> to
   71.99 + * be invoked for any key <tt>k</tt>.  Implementations are free to
  71.100 + * implement optimizations whereby the <tt>equals</tt> invocation is avoided,
  71.101 + * for example, by first comparing the hash codes of the two keys.  (The
  71.102 + * {@link Object#hashCode()} specification guarantees that two objects with
  71.103 + * unequal hash codes cannot be equal.)  More generally, implementations of
  71.104 + * the various Collections Framework interfaces are free to take advantage of
  71.105 + * the specified behavior of underlying {@link Object} methods wherever the
  71.106 + * implementor deems it appropriate.
  71.107 + *
  71.108 + * @param <K> the type of keys maintained by this map
  71.109 + * @param <V> the type of mapped values
  71.110 + *
  71.111 + * @author  Josh Bloch
  71.112 + * @see HashMap
  71.113 + * @see TreeMap
  71.114 + * @see Hashtable
  71.115 + * @see SortedMap
  71.116 + * @see Collection
  71.117 + * @see Set
  71.118 + * @since 1.2
  71.119 + */
  71.120 +public interface Map<K,V> {
  71.121 +    // Query Operations
  71.122 +
  71.123 +    /**
  71.124 +     * Returns the number of key-value mappings in this map.  If the
  71.125 +     * map contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
  71.126 +     * <tt>Integer.MAX_VALUE</tt>.
  71.127 +     *
  71.128 +     * @return the number of key-value mappings in this map
  71.129 +     */
  71.130 +    int size();
  71.131 +
  71.132 +    /**
  71.133 +     * Returns <tt>true</tt> if this map contains no key-value mappings.
  71.134 +     *
  71.135 +     * @return <tt>true</tt> if this map contains no key-value mappings
  71.136 +     */
  71.137 +    boolean isEmpty();
  71.138 +
  71.139 +    /**
  71.140 +     * Returns <tt>true</tt> if this map contains a mapping for the specified
  71.141 +     * key.  More formally, returns <tt>true</tt> if and only if
  71.142 +     * this map contains a mapping for a key <tt>k</tt> such that
  71.143 +     * <tt>(key==null ? k==null : key.equals(k))</tt>.  (There can be
  71.144 +     * at most one such mapping.)
  71.145 +     *
  71.146 +     * @param key key whose presence in this map is to be tested
  71.147 +     * @return <tt>true</tt> if this map contains a mapping for the specified
  71.148 +     *         key
  71.149 +     * @throws ClassCastException if the key is of an inappropriate type for
  71.150 +     *         this map
  71.151 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  71.152 +     * @throws NullPointerException if the specified key is null and this map
  71.153 +     *         does not permit null keys
  71.154 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  71.155 +     */
  71.156 +    boolean containsKey(Object key);
  71.157 +
  71.158 +    /**
  71.159 +     * Returns <tt>true</tt> if this map maps one or more keys to the
  71.160 +     * specified value.  More formally, returns <tt>true</tt> if and only if
  71.161 +     * this map contains at least one mapping to a value <tt>v</tt> such that
  71.162 +     * <tt>(value==null ? v==null : value.equals(v))</tt>.  This operation
  71.163 +     * will probably require time linear in the map size for most
  71.164 +     * implementations of the <tt>Map</tt> interface.
  71.165 +     *
  71.166 +     * @param value value whose presence in this map is to be tested
  71.167 +     * @return <tt>true</tt> if this map maps one or more keys to the
  71.168 +     *         specified value
  71.169 +     * @throws ClassCastException if the value is of an inappropriate type for
  71.170 +     *         this map
  71.171 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  71.172 +     * @throws NullPointerException if the specified value is null and this
  71.173 +     *         map does not permit null values
  71.174 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  71.175 +     */
  71.176 +    boolean containsValue(Object value);
  71.177 +
  71.178 +    /**
  71.179 +     * Returns the value to which the specified key is mapped,
  71.180 +     * or {@code null} if this map contains no mapping for the key.
  71.181 +     *
  71.182 +     * <p>More formally, if this map contains a mapping from a key
  71.183 +     * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
  71.184 +     * key.equals(k))}, then this method returns {@code v}; otherwise
  71.185 +     * it returns {@code null}.  (There can be at most one such mapping.)
  71.186 +     *
  71.187 +     * <p>If this map permits null values, then a return value of
  71.188 +     * {@code null} does not <i>necessarily</i> indicate that the map
  71.189 +     * contains no mapping for the key; it's also possible that the map
  71.190 +     * explicitly maps the key to {@code null}.  The {@link #containsKey
  71.191 +     * containsKey} operation may be used to distinguish these two cases.
  71.192 +     *
  71.193 +     * @param key the key whose associated value is to be returned
  71.194 +     * @return the value to which the specified key is mapped, or
  71.195 +     *         {@code null} if this map contains no mapping for the key
  71.196 +     * @throws ClassCastException if the key is of an inappropriate type for
  71.197 +     *         this map
  71.198 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  71.199 +     * @throws NullPointerException if the specified key is null and this map
  71.200 +     *         does not permit null keys
  71.201 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  71.202 +     */
  71.203 +    V get(Object key);
  71.204 +
  71.205 +    // Modification Operations
  71.206 +
  71.207 +    /**
  71.208 +     * Associates the specified value with the specified key in this map
  71.209 +     * (optional operation).  If the map previously contained a mapping for
  71.210 +     * the key, the old value is replaced by the specified value.  (A map
  71.211 +     * <tt>m</tt> is said to contain a mapping for a key <tt>k</tt> if and only
  71.212 +     * if {@link #containsKey(Object) m.containsKey(k)} would return
  71.213 +     * <tt>true</tt>.)
  71.214 +     *
  71.215 +     * @param key key with which the specified value is to be associated
  71.216 +     * @param value value to be associated with the specified key
  71.217 +     * @return the previous value associated with <tt>key</tt>, or
  71.218 +     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
  71.219 +     *         (A <tt>null</tt> return can also indicate that the map
  71.220 +     *         previously associated <tt>null</tt> with <tt>key</tt>,
  71.221 +     *         if the implementation supports <tt>null</tt> values.)
  71.222 +     * @throws UnsupportedOperationException if the <tt>put</tt> operation
  71.223 +     *         is not supported by this map
  71.224 +     * @throws ClassCastException if the class of the specified key or value
  71.225 +     *         prevents it from being stored in this map
  71.226 +     * @throws NullPointerException if the specified key or value is null
  71.227 +     *         and this map does not permit null keys or values
  71.228 +     * @throws IllegalArgumentException if some property of the specified key
  71.229 +     *         or value prevents it from being stored in this map
  71.230 +     */
  71.231 +    V put(K key, V value);
  71.232 +
  71.233 +    /**
  71.234 +     * Removes the mapping for a key from this map if it is present
  71.235 +     * (optional operation).   More formally, if this map contains a mapping
  71.236 +     * from key <tt>k</tt> to value <tt>v</tt> such that
  71.237 +     * <code>(key==null ?  k==null : key.equals(k))</code>, that mapping
  71.238 +     * is removed.  (The map can contain at most one such mapping.)
  71.239 +     *
  71.240 +     * <p>Returns the value to which this map previously associated the key,
  71.241 +     * or <tt>null</tt> if the map contained no mapping for the key.
  71.242 +     *
  71.243 +     * <p>If this map permits null values, then a return value of
  71.244 +     * <tt>null</tt> does not <i>necessarily</i> indicate that the map
  71.245 +     * contained no mapping for the key; it's also possible that the map
  71.246 +     * explicitly mapped the key to <tt>null</tt>.
  71.247 +     *
  71.248 +     * <p>The map will not contain a mapping for the specified key once the
  71.249 +     * call returns.
  71.250 +     *
  71.251 +     * @param key key whose mapping is to be removed from the map
  71.252 +     * @return the previous value associated with <tt>key</tt>, or
  71.253 +     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
  71.254 +     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
  71.255 +     *         is not supported by this map
  71.256 +     * @throws ClassCastException if the key is of an inappropriate type for
  71.257 +     *         this map
  71.258 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  71.259 +     * @throws NullPointerException if the specified key is null and this
  71.260 +     *         map does not permit null keys
  71.261 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  71.262 +     */
  71.263 +    V remove(Object key);
  71.264 +
  71.265 +
  71.266 +    // Bulk Operations
  71.267 +
  71.268 +    /**
  71.269 +     * Copies all of the mappings from the specified map to this map
  71.270 +     * (optional operation).  The effect of this call is equivalent to that
  71.271 +     * of calling {@link #put(Object,Object) put(k, v)} on this map once
  71.272 +     * for each mapping from key <tt>k</tt> to value <tt>v</tt> in the
  71.273 +     * specified map.  The behavior of this operation is undefined if the
  71.274 +     * specified map is modified while the operation is in progress.
  71.275 +     *
  71.276 +     * @param m mappings to be stored in this map
  71.277 +     * @throws UnsupportedOperationException if the <tt>putAll</tt> operation
  71.278 +     *         is not supported by this map
  71.279 +     * @throws ClassCastException if the class of a key or value in the
  71.280 +     *         specified map prevents it from being stored in this map
  71.281 +     * @throws NullPointerException if the specified map is null, or if
  71.282 +     *         this map does not permit null keys or values, and the
  71.283 +     *         specified map contains null keys or values
  71.284 +     * @throws IllegalArgumentException if some property of a key or value in
  71.285 +     *         the specified map prevents it from being stored in this map
  71.286 +     */
  71.287 +    void putAll(Map<? extends K, ? extends V> m);
  71.288 +
  71.289 +    /**
  71.290 +     * Removes all of the mappings from this map (optional operation).
  71.291 +     * The map will be empty after this call returns.
  71.292 +     *
  71.293 +     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
  71.294 +     *         is not supported by this map
  71.295 +     */
  71.296 +    void clear();
  71.297 +
  71.298 +
  71.299 +    // Views
  71.300 +
  71.301 +    /**
  71.302 +     * Returns a {@link Set} view of the keys contained in this map.
  71.303 +     * The set is backed by the map, so changes to the map are
  71.304 +     * reflected in the set, and vice-versa.  If the map is modified
  71.305 +     * while an iteration over the set is in progress (except through
  71.306 +     * the iterator's own <tt>remove</tt> operation), the results of
  71.307 +     * the iteration are undefined.  The set supports element removal,
  71.308 +     * which removes the corresponding mapping from the map, via the
  71.309 +     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
  71.310 +     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
  71.311 +     * operations.  It does not support the <tt>add</tt> or <tt>addAll</tt>
  71.312 +     * operations.
  71.313 +     *
  71.314 +     * @return a set view of the keys contained in this map
  71.315 +     */
  71.316 +    Set<K> keySet();
  71.317 +
  71.318 +    /**
  71.319 +     * Returns a {@link Collection} view of the values contained in this map.
  71.320 +     * The collection is backed by the map, so changes to the map are
  71.321 +     * reflected in the collection, and vice-versa.  If the map is
  71.322 +     * modified while an iteration over the collection is in progress
  71.323 +     * (except through the iterator's own <tt>remove</tt> operation),
  71.324 +     * the results of the iteration are undefined.  The collection
  71.325 +     * supports element removal, which removes the corresponding
  71.326 +     * mapping from the map, via the <tt>Iterator.remove</tt>,
  71.327 +     * <tt>Collection.remove</tt>, <tt>removeAll</tt>,
  71.328 +     * <tt>retainAll</tt> and <tt>clear</tt> operations.  It does not
  71.329 +     * support the <tt>add</tt> or <tt>addAll</tt> operations.
  71.330 +     *
  71.331 +     * @return a collection view of the values contained in this map
  71.332 +     */
  71.333 +    Collection<V> values();
  71.334 +
  71.335 +    /**
  71.336 +     * Returns a {@link Set} view of the mappings contained in this map.
  71.337 +     * The set is backed by the map, so changes to the map are
  71.338 +     * reflected in the set, and vice-versa.  If the map is modified
  71.339 +     * while an iteration over the set is in progress (except through
  71.340 +     * the iterator's own <tt>remove</tt> operation, or through the
  71.341 +     * <tt>setValue</tt> operation on a map entry returned by the
  71.342 +     * iterator) the results of the iteration are undefined.  The set
  71.343 +     * supports element removal, which removes the corresponding
  71.344 +     * mapping from the map, via the <tt>Iterator.remove</tt>,
  71.345 +     * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
  71.346 +     * <tt>clear</tt> operations.  It does not support the
  71.347 +     * <tt>add</tt> or <tt>addAll</tt> operations.
  71.348 +     *
  71.349 +     * @return a set view of the mappings contained in this map
  71.350 +     */
  71.351 +    Set<Map.Entry<K, V>> entrySet();
  71.352 +
  71.353 +    /**
  71.354 +     * A map entry (key-value pair).  The <tt>Map.entrySet</tt> method returns
  71.355 +     * a collection-view of the map, whose elements are of this class.  The
  71.356 +     * <i>only</i> way to obtain a reference to a map entry is from the
  71.357 +     * iterator of this collection-view.  These <tt>Map.Entry</tt> objects are
  71.358 +     * valid <i>only</i> for the duration of the iteration; more formally,
  71.359 +     * the behavior of a map entry is undefined if the backing map has been
  71.360 +     * modified after the entry was returned by the iterator, except through
  71.361 +     * the <tt>setValue</tt> operation on the map entry.
  71.362 +     *
  71.363 +     * @see Map#entrySet()
  71.364 +     * @since 1.2
  71.365 +     */
  71.366 +    interface Entry<K,V> {
  71.367 +        /**
  71.368 +         * Returns the key corresponding to this entry.
  71.369 +         *
  71.370 +         * @return the key corresponding to this entry
  71.371 +         * @throws IllegalStateException implementations may, but are not
  71.372 +         *         required to, throw this exception if the entry has been
  71.373 +         *         removed from the backing map.
  71.374 +         */
  71.375 +        K getKey();
  71.376 +
  71.377 +        /**
  71.378 +         * Returns the value corresponding to this entry.  If the mapping
  71.379 +         * has been removed from the backing map (by the iterator's
  71.380 +         * <tt>remove</tt> operation), the results of this call are undefined.
  71.381 +         *
  71.382 +         * @return the value corresponding to this entry
  71.383 +         * @throws IllegalStateException implementations may, but are not
  71.384 +         *         required to, throw this exception if the entry has been
  71.385 +         *         removed from the backing map.
  71.386 +         */
  71.387 +        V getValue();
  71.388 +
  71.389 +        /**
  71.390 +         * Replaces the value corresponding to this entry with the specified
  71.391 +         * value (optional operation).  (Writes through to the map.)  The
  71.392 +         * behavior of this call is undefined if the mapping has already been
  71.393 +         * removed from the map (by the iterator's <tt>remove</tt> operation).
  71.394 +         *
  71.395 +         * @param value new value to be stored in this entry
  71.396 +         * @return old value corresponding to the entry
  71.397 +         * @throws UnsupportedOperationException if the <tt>put</tt> operation
  71.398 +         *         is not supported by the backing map
  71.399 +         * @throws ClassCastException if the class of the specified value
  71.400 +         *         prevents it from being stored in the backing map
  71.401 +         * @throws NullPointerException if the backing map does not permit
  71.402 +         *         null values, and the specified value is null
  71.403 +         * @throws IllegalArgumentException if some property of this value
  71.404 +         *         prevents it from being stored in the backing map
  71.405 +         * @throws IllegalStateException implementations may, but are not
  71.406 +         *         required to, throw this exception if the entry has been
  71.407 +         *         removed from the backing map.
  71.408 +         */
  71.409 +        V setValue(V value);
  71.410 +
  71.411 +        /**
  71.412 +         * Compares the specified object with this entry for equality.
  71.413 +         * Returns <tt>true</tt> if the given object is also a map entry and
  71.414 +         * the two entries represent the same mapping.  More formally, two
  71.415 +         * entries <tt>e1</tt> and <tt>e2</tt> represent the same mapping
  71.416 +         * if<pre>
  71.417 +         *     (e1.getKey()==null ?
  71.418 +         *      e2.getKey()==null : e1.getKey().equals(e2.getKey()))  &amp;&amp;
  71.419 +         *     (e1.getValue()==null ?
  71.420 +         *      e2.getValue()==null : e1.getValue().equals(e2.getValue()))
  71.421 +         * </pre>
  71.422 +         * This ensures that the <tt>equals</tt> method works properly across
  71.423 +         * different implementations of the <tt>Map.Entry</tt> interface.
  71.424 +         *
  71.425 +         * @param o object to be compared for equality with this map entry
  71.426 +         * @return <tt>true</tt> if the specified object is equal to this map
  71.427 +         *         entry
  71.428 +         */
  71.429 +        boolean equals(Object o);
  71.430 +
  71.431 +        /**
  71.432 +         * Returns the hash code value for this map entry.  The hash code
  71.433 +         * of a map entry <tt>e</tt> is defined to be: <pre>
  71.434 +         *     (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
  71.435 +         *     (e.getValue()==null ? 0 : e.getValue().hashCode())
  71.436 +         * </pre>
  71.437 +         * This ensures that <tt>e1.equals(e2)</tt> implies that
  71.438 +         * <tt>e1.hashCode()==e2.hashCode()</tt> for any two Entries
  71.439 +         * <tt>e1</tt> and <tt>e2</tt>, as required by the general
  71.440 +         * contract of <tt>Object.hashCode</tt>.
  71.441 +         *
  71.442 +         * @return the hash code value for this map entry
  71.443 +         * @see Object#hashCode()
  71.444 +         * @see Object#equals(Object)
  71.445 +         * @see #equals(Object)
  71.446 +         */
  71.447 +        int hashCode();
  71.448 +    }
  71.449 +
  71.450 +    // Comparison and hashing
  71.451 +
  71.452 +    /**
  71.453 +     * Compares the specified object with this map for equality.  Returns
  71.454 +     * <tt>true</tt> if the given object is also a map and the two maps
  71.455 +     * represent the same mappings.  More formally, two maps <tt>m1</tt> and
  71.456 +     * <tt>m2</tt> represent the same mappings if
  71.457 +     * <tt>m1.entrySet().equals(m2.entrySet())</tt>.  This ensures that the
  71.458 +     * <tt>equals</tt> method works properly across different implementations
  71.459 +     * of the <tt>Map</tt> interface.
  71.460 +     *
  71.461 +     * @param o object to be compared for equality with this map
  71.462 +     * @return <tt>true</tt> if the specified object is equal to this map
  71.463 +     */
  71.464 +    boolean equals(Object o);
  71.465 +
  71.466 +    /**
  71.467 +     * Returns the hash code value for this map.  The hash code of a map is
  71.468 +     * defined to be the sum of the hash codes of each entry in the map's
  71.469 +     * <tt>entrySet()</tt> view.  This ensures that <tt>m1.equals(m2)</tt>
  71.470 +     * implies that <tt>m1.hashCode()==m2.hashCode()</tt> for any two maps
  71.471 +     * <tt>m1</tt> and <tt>m2</tt>, as required by the general contract of
  71.472 +     * {@link Object#hashCode}.
  71.473 +     *
  71.474 +     * @return the hash code value for this map
  71.475 +     * @see Map.Entry#hashCode()
  71.476 +     * @see Object#equals(Object)
  71.477 +     * @see #equals(Object)
  71.478 +     */
  71.479 +    int hashCode();
  71.480 +
  71.481 +}
    72.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    72.2 +++ b/emul/compact/src/main/java/java/util/PriorityQueue.java	Sun Feb 03 07:48:42 2013 +0100
    72.3 @@ -0,0 +1,731 @@
    72.4 +/*
    72.5 + * Copyright (c) 2003, 2010, 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.util;
   72.30 +
   72.31 +
   72.32 +/**
   72.33 + * An unbounded priority {@linkplain Queue queue} based on a priority heap.
   72.34 + * The elements of the priority queue are ordered according to their
   72.35 + * {@linkplain Comparable natural ordering}, or by a {@link Comparator}
   72.36 + * provided at queue construction time, depending on which constructor is
   72.37 + * used.  A priority queue does not permit {@code null} elements.
   72.38 + * A priority queue relying on natural ordering also does not permit
   72.39 + * insertion of non-comparable objects (doing so may result in
   72.40 + * {@code ClassCastException}).
   72.41 + *
   72.42 + * <p>The <em>head</em> of this queue is the <em>least</em> element
   72.43 + * with respect to the specified ordering.  If multiple elements are
   72.44 + * tied for least value, the head is one of those elements -- ties are
   72.45 + * broken arbitrarily.  The queue retrieval operations {@code poll},
   72.46 + * {@code remove}, {@code peek}, and {@code element} access the
   72.47 + * element at the head of the queue.
   72.48 + *
   72.49 + * <p>A priority queue is unbounded, but has an internal
   72.50 + * <i>capacity</i> governing the size of an array used to store the
   72.51 + * elements on the queue.  It is always at least as large as the queue
   72.52 + * size.  As elements are added to a priority queue, its capacity
   72.53 + * grows automatically.  The details of the growth policy are not
   72.54 + * specified.
   72.55 + *
   72.56 + * <p>This class and its iterator implement all of the
   72.57 + * <em>optional</em> methods of the {@link Collection} and {@link
   72.58 + * Iterator} interfaces.  The Iterator provided in method {@link
   72.59 + * #iterator()} is <em>not</em> guaranteed to traverse the elements of
   72.60 + * the priority queue in any particular order. If you need ordered
   72.61 + * traversal, consider using {@code Arrays.sort(pq.toArray())}.
   72.62 + *
   72.63 + * <p> <strong>Note that this implementation is not synchronized.</strong>
   72.64 + * Multiple threads should not access a {@code PriorityQueue}
   72.65 + * instance concurrently if any of the threads modifies the queue.
   72.66 + * Instead, use the thread-safe {@link
   72.67 + * java.util.concurrent.PriorityBlockingQueue} class.
   72.68 + *
   72.69 + * <p>Implementation note: this implementation provides
   72.70 + * O(log(n)) time for the enqueing and dequeing methods
   72.71 + * ({@code offer}, {@code poll}, {@code remove()} and {@code add});
   72.72 + * linear time for the {@code remove(Object)} and {@code contains(Object)}
   72.73 + * methods; and constant time for the retrieval methods
   72.74 + * ({@code peek}, {@code element}, and {@code size}).
   72.75 + *
   72.76 + * <p>This class is a member of the
   72.77 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   72.78 + * Java Collections Framework</a>.
   72.79 + *
   72.80 + * @since 1.5
   72.81 + * @author Josh Bloch, Doug Lea
   72.82 + * @param <E> the type of elements held in this collection
   72.83 + */
   72.84 +public class PriorityQueue<E> extends AbstractQueue<E>
   72.85 +    implements java.io.Serializable {
   72.86 +
   72.87 +    private static final long serialVersionUID = -7720805057305804111L;
   72.88 +
   72.89 +    private static final int DEFAULT_INITIAL_CAPACITY = 11;
   72.90 +
   72.91 +    /**
   72.92 +     * Priority queue represented as a balanced binary heap: the two
   72.93 +     * children of queue[n] are queue[2*n+1] and queue[2*(n+1)].  The
   72.94 +     * priority queue is ordered by comparator, or by the elements'
   72.95 +     * natural ordering, if comparator is null: For each node n in the
   72.96 +     * heap and each descendant d of n, n <= d.  The element with the
   72.97 +     * lowest value is in queue[0], assuming the queue is nonempty.
   72.98 +     */
   72.99 +    private transient Object[] queue;
  72.100 +
  72.101 +    /**
  72.102 +     * The number of elements in the priority queue.
  72.103 +     */
  72.104 +    private int size = 0;
  72.105 +
  72.106 +    /**
  72.107 +     * The comparator, or null if priority queue uses elements'
  72.108 +     * natural ordering.
  72.109 +     */
  72.110 +    private final Comparator<? super E> comparator;
  72.111 +
  72.112 +    /**
  72.113 +     * The number of times this priority queue has been
  72.114 +     * <i>structurally modified</i>.  See AbstractList for gory details.
  72.115 +     */
  72.116 +    private transient int modCount = 0;
  72.117 +
  72.118 +    /**
  72.119 +     * Creates a {@code PriorityQueue} with the default initial
  72.120 +     * capacity (11) that orders its elements according to their
  72.121 +     * {@linkplain Comparable natural ordering}.
  72.122 +     */
  72.123 +    public PriorityQueue() {
  72.124 +        this(DEFAULT_INITIAL_CAPACITY, null);
  72.125 +    }
  72.126 +
  72.127 +    /**
  72.128 +     * Creates a {@code PriorityQueue} with the specified initial
  72.129 +     * capacity that orders its elements according to their
  72.130 +     * {@linkplain Comparable natural ordering}.
  72.131 +     *
  72.132 +     * @param initialCapacity the initial capacity for this priority queue
  72.133 +     * @throws IllegalArgumentException if {@code initialCapacity} is less
  72.134 +     *         than 1
  72.135 +     */
  72.136 +    public PriorityQueue(int initialCapacity) {
  72.137 +        this(initialCapacity, null);
  72.138 +    }
  72.139 +
  72.140 +    /**
  72.141 +     * Creates a {@code PriorityQueue} with the specified initial capacity
  72.142 +     * that orders its elements according to the specified comparator.
  72.143 +     *
  72.144 +     * @param  initialCapacity the initial capacity for this priority queue
  72.145 +     * @param  comparator the comparator that will be used to order this
  72.146 +     *         priority queue.  If {@code null}, the {@linkplain Comparable
  72.147 +     *         natural ordering} of the elements will be used.
  72.148 +     * @throws IllegalArgumentException if {@code initialCapacity} is
  72.149 +     *         less than 1
  72.150 +     */
  72.151 +    public PriorityQueue(int initialCapacity,
  72.152 +                         Comparator<? super E> comparator) {
  72.153 +        // Note: This restriction of at least one is not actually needed,
  72.154 +        // but continues for 1.5 compatibility
  72.155 +        if (initialCapacity < 1)
  72.156 +            throw new IllegalArgumentException();
  72.157 +        this.queue = new Object[initialCapacity];
  72.158 +        this.comparator = comparator;
  72.159 +    }
  72.160 +
  72.161 +    /**
  72.162 +     * Creates a {@code PriorityQueue} containing the elements in the
  72.163 +     * specified collection.  If the specified collection is an instance of
  72.164 +     * a {@link SortedSet} or is another {@code PriorityQueue}, this
  72.165 +     * priority queue will be ordered according to the same ordering.
  72.166 +     * Otherwise, this priority queue will be ordered according to the
  72.167 +     * {@linkplain Comparable natural ordering} of its elements.
  72.168 +     *
  72.169 +     * @param  c the collection whose elements are to be placed
  72.170 +     *         into this priority queue
  72.171 +     * @throws ClassCastException if elements of the specified collection
  72.172 +     *         cannot be compared to one another according to the priority
  72.173 +     *         queue's ordering
  72.174 +     * @throws NullPointerException if the specified collection or any
  72.175 +     *         of its elements are null
  72.176 +     */
  72.177 +    @SuppressWarnings("unchecked")
  72.178 +    public PriorityQueue(Collection<? extends E> c) {
  72.179 +        if (c instanceof SortedSet<?>) {
  72.180 +            SortedSet<? extends E> ss = (SortedSet<? extends E>) c;
  72.181 +            this.comparator = (Comparator<? super E>) ss.comparator();
  72.182 +            initElementsFromCollection(ss);
  72.183 +        }
  72.184 +        else if (c instanceof PriorityQueue<?>) {
  72.185 +            PriorityQueue<? extends E> pq = (PriorityQueue<? extends E>) c;
  72.186 +            this.comparator = (Comparator<? super E>) pq.comparator();
  72.187 +            initFromPriorityQueue(pq);
  72.188 +        }
  72.189 +        else {
  72.190 +            this.comparator = null;
  72.191 +            initFromCollection(c);
  72.192 +        }
  72.193 +    }
  72.194 +
  72.195 +    /**
  72.196 +     * Creates a {@code PriorityQueue} containing the elements in the
  72.197 +     * specified priority queue.  This priority queue will be
  72.198 +     * ordered according to the same ordering as the given priority
  72.199 +     * queue.
  72.200 +     *
  72.201 +     * @param  c the priority queue whose elements are to be placed
  72.202 +     *         into this priority queue
  72.203 +     * @throws ClassCastException if elements of {@code c} cannot be
  72.204 +     *         compared to one another according to {@code c}'s
  72.205 +     *         ordering
  72.206 +     * @throws NullPointerException if the specified priority queue or any
  72.207 +     *         of its elements are null
  72.208 +     */
  72.209 +    @SuppressWarnings("unchecked")
  72.210 +    public PriorityQueue(PriorityQueue<? extends E> c) {
  72.211 +        this.comparator = (Comparator<? super E>) c.comparator();
  72.212 +        initFromPriorityQueue(c);
  72.213 +    }
  72.214 +
  72.215 +    /**
  72.216 +     * Creates a {@code PriorityQueue} containing the elements in the
  72.217 +     * specified sorted set.   This priority queue will be ordered
  72.218 +     * according to the same ordering as the given sorted set.
  72.219 +     *
  72.220 +     * @param  c the sorted set whose elements are to be placed
  72.221 +     *         into this priority queue
  72.222 +     * @throws ClassCastException if elements of the specified sorted
  72.223 +     *         set cannot be compared to one another according to the
  72.224 +     *         sorted set's ordering
  72.225 +     * @throws NullPointerException if the specified sorted set or any
  72.226 +     *         of its elements are null
  72.227 +     */
  72.228 +    @SuppressWarnings("unchecked")
  72.229 +    public PriorityQueue(SortedSet<? extends E> c) {
  72.230 +        this.comparator = (Comparator<? super E>) c.comparator();
  72.231 +        initElementsFromCollection(c);
  72.232 +    }
  72.233 +
  72.234 +    private void initFromPriorityQueue(PriorityQueue<? extends E> c) {
  72.235 +        if (c.getClass() == PriorityQueue.class) {
  72.236 +            this.queue = c.toArray();
  72.237 +            this.size = c.size();
  72.238 +        } else {
  72.239 +            initFromCollection(c);
  72.240 +        }
  72.241 +    }
  72.242 +
  72.243 +    private void initElementsFromCollection(Collection<? extends E> c) {
  72.244 +        Object[] a = c.toArray();
  72.245 +        // If c.toArray incorrectly doesn't return Object[], copy it.
  72.246 +        if (a.getClass() != Object[].class)
  72.247 +            a = Arrays.copyOf(a, a.length, Object[].class);
  72.248 +        int len = a.length;
  72.249 +        if (len == 1 || this.comparator != null)
  72.250 +            for (int i = 0; i < len; i++)
  72.251 +                if (a[i] == null)
  72.252 +                    throw new NullPointerException();
  72.253 +        this.queue = a;
  72.254 +        this.size = a.length;
  72.255 +    }
  72.256 +
  72.257 +    /**
  72.258 +     * Initializes queue array with elements from the given Collection.
  72.259 +     *
  72.260 +     * @param c the collection
  72.261 +     */
  72.262 +    private void initFromCollection(Collection<? extends E> c) {
  72.263 +        initElementsFromCollection(c);
  72.264 +        heapify();
  72.265 +    }
  72.266 +
  72.267 +    /**
  72.268 +     * The maximum size of array to allocate.
  72.269 +     * Some VMs reserve some header words in an array.
  72.270 +     * Attempts to allocate larger arrays may result in
  72.271 +     * OutOfMemoryError: Requested array size exceeds VM limit
  72.272 +     */
  72.273 +    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
  72.274 +
  72.275 +    /**
  72.276 +     * Increases the capacity of the array.
  72.277 +     *
  72.278 +     * @param minCapacity the desired minimum capacity
  72.279 +     */
  72.280 +    private void grow(int minCapacity) {
  72.281 +        int oldCapacity = queue.length;
  72.282 +        // Double size if small; else grow by 50%
  72.283 +        int newCapacity = oldCapacity + ((oldCapacity < 64) ?
  72.284 +                                         (oldCapacity + 2) :
  72.285 +                                         (oldCapacity >> 1));
  72.286 +        // overflow-conscious code
  72.287 +        if (newCapacity - MAX_ARRAY_SIZE > 0)
  72.288 +            newCapacity = hugeCapacity(minCapacity);
  72.289 +        queue = Arrays.copyOf(queue, newCapacity);
  72.290 +    }
  72.291 +
  72.292 +    private static int hugeCapacity(int minCapacity) {
  72.293 +        if (minCapacity < 0) // overflow
  72.294 +            throw new OutOfMemoryError();
  72.295 +        return (minCapacity > MAX_ARRAY_SIZE) ?
  72.296 +            Integer.MAX_VALUE :
  72.297 +            MAX_ARRAY_SIZE;
  72.298 +    }
  72.299 +
  72.300 +    /**
  72.301 +     * Inserts the specified element into this priority queue.
  72.302 +     *
  72.303 +     * @return {@code true} (as specified by {@link Collection#add})
  72.304 +     * @throws ClassCastException if the specified element cannot be
  72.305 +     *         compared with elements currently in this priority queue
  72.306 +     *         according to the priority queue's ordering
  72.307 +     * @throws NullPointerException if the specified element is null
  72.308 +     */
  72.309 +    public boolean add(E e) {
  72.310 +        return offer(e);
  72.311 +    }
  72.312 +
  72.313 +    /**
  72.314 +     * Inserts the specified element into this priority queue.
  72.315 +     *
  72.316 +     * @return {@code true} (as specified by {@link Queue#offer})
  72.317 +     * @throws ClassCastException if the specified element cannot be
  72.318 +     *         compared with elements currently in this priority queue
  72.319 +     *         according to the priority queue's ordering
  72.320 +     * @throws NullPointerException if the specified element is null
  72.321 +     */
  72.322 +    public boolean offer(E e) {
  72.323 +        if (e == null)
  72.324 +            throw new NullPointerException();
  72.325 +        modCount++;
  72.326 +        int i = size;
  72.327 +        if (i >= queue.length)
  72.328 +            grow(i + 1);
  72.329 +        size = i + 1;
  72.330 +        if (i == 0)
  72.331 +            queue[0] = e;
  72.332 +        else
  72.333 +            siftUp(i, e);
  72.334 +        return true;
  72.335 +    }
  72.336 +
  72.337 +    public E peek() {
  72.338 +        if (size == 0)
  72.339 +            return null;
  72.340 +        return (E) queue[0];
  72.341 +    }
  72.342 +
  72.343 +    private int indexOf(Object o) {
  72.344 +        if (o != null) {
  72.345 +            for (int i = 0; i < size; i++)
  72.346 +                if (o.equals(queue[i]))
  72.347 +                    return i;
  72.348 +        }
  72.349 +        return -1;
  72.350 +    }
  72.351 +
  72.352 +    /**
  72.353 +     * Removes a single instance of the specified element from this queue,
  72.354 +     * if it is present.  More formally, removes an element {@code e} such
  72.355 +     * that {@code o.equals(e)}, if this queue contains one or more such
  72.356 +     * elements.  Returns {@code true} if and only if this queue contained
  72.357 +     * the specified element (or equivalently, if this queue changed as a
  72.358 +     * result of the call).
  72.359 +     *
  72.360 +     * @param o element to be removed from this queue, if present
  72.361 +     * @return {@code true} if this queue changed as a result of the call
  72.362 +     */
  72.363 +    public boolean remove(Object o) {
  72.364 +        int i = indexOf(o);
  72.365 +        if (i == -1)
  72.366 +            return false;
  72.367 +        else {
  72.368 +            removeAt(i);
  72.369 +            return true;
  72.370 +        }
  72.371 +    }
  72.372 +
  72.373 +    /**
  72.374 +     * Version of remove using reference equality, not equals.
  72.375 +     * Needed by iterator.remove.
  72.376 +     *
  72.377 +     * @param o element to be removed from this queue, if present
  72.378 +     * @return {@code true} if removed
  72.379 +     */
  72.380 +    boolean removeEq(Object o) {
  72.381 +        for (int i = 0; i < size; i++) {
  72.382 +            if (o == queue[i]) {
  72.383 +                removeAt(i);
  72.384 +                return true;
  72.385 +            }
  72.386 +        }
  72.387 +        return false;
  72.388 +    }
  72.389 +
  72.390 +    /**
  72.391 +     * Returns {@code true} if this queue contains the specified element.
  72.392 +     * More formally, returns {@code true} if and only if this queue contains
  72.393 +     * at least one element {@code e} such that {@code o.equals(e)}.
  72.394 +     *
  72.395 +     * @param o object to be checked for containment in this queue
  72.396 +     * @return {@code true} if this queue contains the specified element
  72.397 +     */
  72.398 +    public boolean contains(Object o) {
  72.399 +        return indexOf(o) != -1;
  72.400 +    }
  72.401 +
  72.402 +    /**
  72.403 +     * Returns an array containing all of the elements in this queue.
  72.404 +     * The elements are in no particular order.
  72.405 +     *
  72.406 +     * <p>The returned array will be "safe" in that no references to it are
  72.407 +     * maintained by this queue.  (In other words, this method must allocate
  72.408 +     * a new array).  The caller is thus free to modify the returned array.
  72.409 +     *
  72.410 +     * <p>This method acts as bridge between array-based and collection-based
  72.411 +     * APIs.
  72.412 +     *
  72.413 +     * @return an array containing all of the elements in this queue
  72.414 +     */
  72.415 +    public Object[] toArray() {
  72.416 +        return Arrays.copyOf(queue, size);
  72.417 +    }
  72.418 +
  72.419 +    /**
  72.420 +     * Returns an array containing all of the elements in this queue; the
  72.421 +     * runtime type of the returned array is that of the specified array.
  72.422 +     * The returned array elements are in no particular order.
  72.423 +     * If the queue fits in the specified array, it is returned therein.
  72.424 +     * Otherwise, a new array is allocated with the runtime type of the
  72.425 +     * specified array and the size of this queue.
  72.426 +     *
  72.427 +     * <p>If the queue fits in the specified array with room to spare
  72.428 +     * (i.e., the array has more elements than the queue), the element in
  72.429 +     * the array immediately following the end of the collection is set to
  72.430 +     * {@code null}.
  72.431 +     *
  72.432 +     * <p>Like the {@link #toArray()} method, this method acts as bridge between
  72.433 +     * array-based and collection-based APIs.  Further, this method allows
  72.434 +     * precise control over the runtime type of the output array, and may,
  72.435 +     * under certain circumstances, be used to save allocation costs.
  72.436 +     *
  72.437 +     * <p>Suppose <tt>x</tt> is a queue known to contain only strings.
  72.438 +     * The following code can be used to dump the queue into a newly
  72.439 +     * allocated array of <tt>String</tt>:
  72.440 +     *
  72.441 +     * <pre>
  72.442 +     *     String[] y = x.toArray(new String[0]);</pre>
  72.443 +     *
  72.444 +     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
  72.445 +     * <tt>toArray()</tt>.
  72.446 +     *
  72.447 +     * @param a the array into which the elements of the queue are to
  72.448 +     *          be stored, if it is big enough; otherwise, a new array of the
  72.449 +     *          same runtime type is allocated for this purpose.
  72.450 +     * @return an array containing all of the elements in this queue
  72.451 +     * @throws ArrayStoreException if the runtime type of the specified array
  72.452 +     *         is not a supertype of the runtime type of every element in
  72.453 +     *         this queue
  72.454 +     * @throws NullPointerException if the specified array is null
  72.455 +     */
  72.456 +    public <T> T[] toArray(T[] a) {
  72.457 +        if (a.length < size)
  72.458 +            // Make a new array of a's runtime type, but my contents:
  72.459 +            return (T[]) Arrays.copyOf(queue, size, a.getClass());
  72.460 +        System.arraycopy(queue, 0, a, 0, size);
  72.461 +        if (a.length > size)
  72.462 +            a[size] = null;
  72.463 +        return a;
  72.464 +    }
  72.465 +
  72.466 +    /**
  72.467 +     * Returns an iterator over the elements in this queue. The iterator
  72.468 +     * does not return the elements in any particular order.
  72.469 +     *
  72.470 +     * @return an iterator over the elements in this queue
  72.471 +     */
  72.472 +    public Iterator<E> iterator() {
  72.473 +        return new Itr();
  72.474 +    }
  72.475 +
  72.476 +    private final class Itr implements Iterator<E> {
  72.477 +        /**
  72.478 +         * Index (into queue array) of element to be returned by
  72.479 +         * subsequent call to next.
  72.480 +         */
  72.481 +        private int cursor = 0;
  72.482 +
  72.483 +        /**
  72.484 +         * Index of element returned by most recent call to next,
  72.485 +         * unless that element came from the forgetMeNot list.
  72.486 +         * Set to -1 if element is deleted by a call to remove.
  72.487 +         */
  72.488 +        private int lastRet = -1;
  72.489 +
  72.490 +        /**
  72.491 +         * A queue of elements that were moved from the unvisited portion of
  72.492 +         * the heap into the visited portion as a result of "unlucky" element
  72.493 +         * removals during the iteration.  (Unlucky element removals are those
  72.494 +         * that require a siftup instead of a siftdown.)  We must visit all of
  72.495 +         * the elements in this list to complete the iteration.  We do this
  72.496 +         * after we've completed the "normal" iteration.
  72.497 +         *
  72.498 +         * We expect that most iterations, even those involving removals,
  72.499 +         * will not need to store elements in this field.
  72.500 +         */
  72.501 +        private ArrayDeque<E> forgetMeNot = null;
  72.502 +
  72.503 +        /**
  72.504 +         * Element returned by the most recent call to next iff that
  72.505 +         * element was drawn from the forgetMeNot list.
  72.506 +         */
  72.507 +        private E lastRetElt = null;
  72.508 +
  72.509 +        /**
  72.510 +         * The modCount value that the iterator believes that the backing
  72.511 +         * Queue should have.  If this expectation is violated, the iterator
  72.512 +         * has detected concurrent modification.
  72.513 +         */
  72.514 +        private int expectedModCount = modCount;
  72.515 +
  72.516 +        public boolean hasNext() {
  72.517 +            return cursor < size ||
  72.518 +                (forgetMeNot != null && !forgetMeNot.isEmpty());
  72.519 +        }
  72.520 +
  72.521 +        public E next() {
  72.522 +            if (expectedModCount != modCount)
  72.523 +                throw new ConcurrentModificationException();
  72.524 +            if (cursor < size)
  72.525 +                return (E) queue[lastRet = cursor++];
  72.526 +            if (forgetMeNot != null) {
  72.527 +                lastRet = -1;
  72.528 +                lastRetElt = forgetMeNot.poll();
  72.529 +                if (lastRetElt != null)
  72.530 +                    return lastRetElt;
  72.531 +            }
  72.532 +            throw new NoSuchElementException();
  72.533 +        }
  72.534 +
  72.535 +        public void remove() {
  72.536 +            if (expectedModCount != modCount)
  72.537 +                throw new ConcurrentModificationException();
  72.538 +            if (lastRet != -1) {
  72.539 +                E moved = PriorityQueue.this.removeAt(lastRet);
  72.540 +                lastRet = -1;
  72.541 +                if (moved == null)
  72.542 +                    cursor--;
  72.543 +                else {
  72.544 +                    if (forgetMeNot == null)
  72.545 +                        forgetMeNot = new ArrayDeque<>();
  72.546 +                    forgetMeNot.add(moved);
  72.547 +                }
  72.548 +            } else if (lastRetElt != null) {
  72.549 +                PriorityQueue.this.removeEq(lastRetElt);
  72.550 +                lastRetElt = null;
  72.551 +            } else {
  72.552 +                throw new IllegalStateException();
  72.553 +            }
  72.554 +            expectedModCount = modCount;
  72.555 +        }
  72.556 +    }
  72.557 +
  72.558 +    public int size() {
  72.559 +        return size;
  72.560 +    }
  72.561 +
  72.562 +    /**
  72.563 +     * Removes all of the elements from this priority queue.
  72.564 +     * The queue will be empty after this call returns.
  72.565 +     */
  72.566 +    public void clear() {
  72.567 +        modCount++;
  72.568 +        for (int i = 0; i < size; i++)
  72.569 +            queue[i] = null;
  72.570 +        size = 0;
  72.571 +    }
  72.572 +
  72.573 +    public E poll() {
  72.574 +        if (size == 0)
  72.575 +            return null;
  72.576 +        int s = --size;
  72.577 +        modCount++;
  72.578 +        E result = (E) queue[0];
  72.579 +        E x = (E) queue[s];
  72.580 +        queue[s] = null;
  72.581 +        if (s != 0)
  72.582 +            siftDown(0, x);
  72.583 +        return result;
  72.584 +    }
  72.585 +
  72.586 +    /**
  72.587 +     * Removes the ith element from queue.
  72.588 +     *
  72.589 +     * Normally this method leaves the elements at up to i-1,
  72.590 +     * inclusive, untouched.  Under these circumstances, it returns
  72.591 +     * null.  Occasionally, in order to maintain the heap invariant,
  72.592 +     * it must swap a later element of the list with one earlier than
  72.593 +     * i.  Under these circumstances, this method returns the element
  72.594 +     * that was previously at the end of the list and is now at some
  72.595 +     * position before i. This fact is used by iterator.remove so as to
  72.596 +     * avoid missing traversing elements.
  72.597 +     */
  72.598 +    private E removeAt(int i) {
  72.599 +        assert i >= 0 && i < size;
  72.600 +        modCount++;
  72.601 +        int s = --size;
  72.602 +        if (s == i) // removed last element
  72.603 +            queue[i] = null;
  72.604 +        else {
  72.605 +            E moved = (E) queue[s];
  72.606 +            queue[s] = null;
  72.607 +            siftDown(i, moved);
  72.608 +            if (queue[i] == moved) {
  72.609 +                siftUp(i, moved);
  72.610 +                if (queue[i] != moved)
  72.611 +                    return moved;
  72.612 +            }
  72.613 +        }
  72.614 +        return null;
  72.615 +    }
  72.616 +
  72.617 +    /**
  72.618 +     * Inserts item x at position k, maintaining heap invariant by
  72.619 +     * promoting x up the tree until it is greater than or equal to
  72.620 +     * its parent, or is the root.
  72.621 +     *
  72.622 +     * To simplify and speed up coercions and comparisons. the
  72.623 +     * Comparable and Comparator versions are separated into different
  72.624 +     * methods that are otherwise identical. (Similarly for siftDown.)
  72.625 +     *
  72.626 +     * @param k the position to fill
  72.627 +     * @param x the item to insert
  72.628 +     */
  72.629 +    private void siftUp(int k, E x) {
  72.630 +        if (comparator != null)
  72.631 +            siftUpUsingComparator(k, x);
  72.632 +        else
  72.633 +            siftUpComparable(k, x);
  72.634 +    }
  72.635 +
  72.636 +    private void siftUpComparable(int k, E x) {
  72.637 +        Comparable<? super E> key = (Comparable<? super E>) x;
  72.638 +        while (k > 0) {
  72.639 +            int parent = (k - 1) >>> 1;
  72.640 +            Object e = queue[parent];
  72.641 +            if (key.compareTo((E) e) >= 0)
  72.642 +                break;
  72.643 +            queue[k] = e;
  72.644 +            k = parent;
  72.645 +        }
  72.646 +        queue[k] = key;
  72.647 +    }
  72.648 +
  72.649 +    private void siftUpUsingComparator(int k, E x) {
  72.650 +        while (k > 0) {
  72.651 +            int parent = (k - 1) >>> 1;
  72.652 +            Object e = queue[parent];
  72.653 +            if (comparator.compare(x, (E) e) >= 0)
  72.654 +                break;
  72.655 +            queue[k] = e;
  72.656 +            k = parent;
  72.657 +        }
  72.658 +        queue[k] = x;
  72.659 +    }
  72.660 +
  72.661 +    /**
  72.662 +     * Inserts item x at position k, maintaining heap invariant by
  72.663 +     * demoting x down the tree repeatedly until it is less than or
  72.664 +     * equal to its children or is a leaf.
  72.665 +     *
  72.666 +     * @param k the position to fill
  72.667 +     * @param x the item to insert
  72.668 +     */
  72.669 +    private void siftDown(int k, E x) {
  72.670 +        if (comparator != null)
  72.671 +            siftDownUsingComparator(k, x);
  72.672 +        else
  72.673 +            siftDownComparable(k, x);
  72.674 +    }
  72.675 +
  72.676 +    private void siftDownComparable(int k, E x) {
  72.677 +        Comparable<? super E> key = (Comparable<? super E>)x;
  72.678 +        int half = size >>> 1;        // loop while a non-leaf
  72.679 +        while (k < half) {
  72.680 +            int child = (k << 1) + 1; // assume left child is least
  72.681 +            Object c = queue[child];
  72.682 +            int right = child + 1;
  72.683 +            if (right < size &&
  72.684 +                ((Comparable<? super E>) c).compareTo((E) queue[right]) > 0)
  72.685 +                c = queue[child = right];
  72.686 +            if (key.compareTo((E) c) <= 0)
  72.687 +                break;
  72.688 +            queue[k] = c;
  72.689 +            k = child;
  72.690 +        }
  72.691 +        queue[k] = key;
  72.692 +    }
  72.693 +
  72.694 +    private void siftDownUsingComparator(int k, E x) {
  72.695 +        int half = size >>> 1;
  72.696 +        while (k < half) {
  72.697 +            int child = (k << 1) + 1;
  72.698 +            Object c = queue[child];
  72.699 +            int right = child + 1;
  72.700 +            if (right < size &&
  72.701 +                comparator.compare((E) c, (E) queue[right]) > 0)
  72.702 +                c = queue[child = right];
  72.703 +            if (comparator.compare(x, (E) c) <= 0)
  72.704 +                break;
  72.705 +            queue[k] = c;
  72.706 +            k = child;
  72.707 +        }
  72.708 +        queue[k] = x;
  72.709 +    }
  72.710 +
  72.711 +    /**
  72.712 +     * Establishes the heap invariant (described above) in the entire tree,
  72.713 +     * assuming nothing about the order of the elements prior to the call.
  72.714 +     */
  72.715 +    private void heapify() {
  72.716 +        for (int i = (size >>> 1) - 1; i >= 0; i--)
  72.717 +            siftDown(i, (E) queue[i]);
  72.718 +    }
  72.719 +
  72.720 +    /**
  72.721 +     * Returns the comparator used to order the elements in this
  72.722 +     * queue, or {@code null} if this queue is sorted according to
  72.723 +     * the {@linkplain Comparable natural ordering} of its elements.
  72.724 +     *
  72.725 +     * @return the comparator used to order this queue, or
  72.726 +     *         {@code null} if this queue is sorted according to the
  72.727 +     *         natural ordering of its elements
  72.728 +     */
  72.729 +    public Comparator<? super E> comparator() {
  72.730 +        return comparator;
  72.731 +    }
  72.732 +
  72.733 +
  72.734 +}
    73.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.2 +++ b/emul/compact/src/main/java/java/util/Queue.java	Sun Feb 03 07:48:42 2013 +0100
    73.3 @@ -0,0 +1,218 @@
    73.4 +/*
    73.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    73.6 + *
    73.7 + * This code is free software; you can redistribute it and/or modify it
    73.8 + * under the terms of the GNU General Public License version 2 only, as
    73.9 + * published by the Free Software Foundation.  Oracle designates this
   73.10 + * particular file as subject to the "Classpath" exception as provided
   73.11 + * by Oracle in the LICENSE file that accompanied this code.
   73.12 + *
   73.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
   73.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   73.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   73.16 + * version 2 for more details (a copy is included in the LICENSE file that
   73.17 + * accompanied this code).
   73.18 + *
   73.19 + * You should have received a copy of the GNU General Public License version
   73.20 + * 2 along with this work; if not, write to the Free Software Foundation,
   73.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   73.22 + *
   73.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   73.24 + * or visit www.oracle.com if you need additional information or have any
   73.25 + * questions.
   73.26 + */
   73.27 +
   73.28 +/*
   73.29 + * This file is available under and governed by the GNU General Public
   73.30 + * License version 2 only, as published by the Free Software Foundation.
   73.31 + * However, the following notice accompanied the original version of this
   73.32 + * file:
   73.33 + *
   73.34 + * Written by Doug Lea with assistance from members of JCP JSR-166
   73.35 + * Expert Group and released to the public domain, as explained at
   73.36 + * http://creativecommons.org/publicdomain/zero/1.0/
   73.37 + */
   73.38 +
   73.39 +package java.util;
   73.40 +
   73.41 +/**
   73.42 + * A collection designed for holding elements prior to processing.
   73.43 + * Besides basic {@link java.util.Collection Collection} operations,
   73.44 + * queues provide additional insertion, extraction, and inspection
   73.45 + * operations.  Each of these methods exists in two forms: one throws
   73.46 + * an exception if the operation fails, the other returns a special
   73.47 + * value (either <tt>null</tt> or <tt>false</tt>, depending on the
   73.48 + * operation).  The latter form of the insert operation is designed
   73.49 + * specifically for use with capacity-restricted <tt>Queue</tt>
   73.50 + * implementations; in most implementations, insert operations cannot
   73.51 + * fail.
   73.52 + *
   73.53 + * <p>
   73.54 + * <table BORDER CELLPADDING=3 CELLSPACING=1>
   73.55 + *  <tr>
   73.56 + *    <td></td>
   73.57 + *    <td ALIGN=CENTER><em>Throws exception</em></td>
   73.58 + *    <td ALIGN=CENTER><em>Returns special value</em></td>
   73.59 + *  </tr>
   73.60 + *  <tr>
   73.61 + *    <td><b>Insert</b></td>
   73.62 + *    <td>{@link #add add(e)}</td>
   73.63 + *    <td>{@link #offer offer(e)}</td>
   73.64 + *  </tr>
   73.65 + *  <tr>
   73.66 + *    <td><b>Remove</b></td>
   73.67 + *    <td>{@link #remove remove()}</td>
   73.68 + *    <td>{@link #poll poll()}</td>
   73.69 + *  </tr>
   73.70 + *  <tr>
   73.71 + *    <td><b>Examine</b></td>
   73.72 + *    <td>{@link #element element()}</td>
   73.73 + *    <td>{@link #peek peek()}</td>
   73.74 + *  </tr>
   73.75 + * </table>
   73.76 + *
   73.77 + * <p>Queues typically, but do not necessarily, order elements in a
   73.78 + * FIFO (first-in-first-out) manner.  Among the exceptions are
   73.79 + * priority queues, which order elements according to a supplied
   73.80 + * comparator, or the elements' natural ordering, and LIFO queues (or
   73.81 + * stacks) which order the elements LIFO (last-in-first-out).
   73.82 + * Whatever the ordering used, the <em>head</em> of the queue is that
   73.83 + * element which would be removed by a call to {@link #remove() } or
   73.84 + * {@link #poll()}.  In a FIFO queue, all new elements are inserted at
   73.85 + * the <em> tail</em> of the queue. Other kinds of queues may use
   73.86 + * different placement rules.  Every <tt>Queue</tt> implementation
   73.87 + * must specify its ordering properties.
   73.88 + *
   73.89 + * <p>The {@link #offer offer} method inserts an element if possible,
   73.90 + * otherwise returning <tt>false</tt>.  This differs from the {@link
   73.91 + * java.util.Collection#add Collection.add} method, which can fail to
   73.92 + * add an element only by throwing an unchecked exception.  The
   73.93 + * <tt>offer</tt> method is designed for use when failure is a normal,
   73.94 + * rather than exceptional occurrence, for example, in fixed-capacity
   73.95 + * (or &quot;bounded&quot;) queues.
   73.96 + *
   73.97 + * <p>The {@link #remove()} and {@link #poll()} methods remove and
   73.98 + * return the head of the queue.
   73.99 + * Exactly which element is removed from the queue is a
  73.100 + * function of the queue's ordering policy, which differs from
  73.101 + * implementation to implementation. The <tt>remove()</tt> and
  73.102 + * <tt>poll()</tt> methods differ only in their behavior when the
  73.103 + * queue is empty: the <tt>remove()</tt> method throws an exception,
  73.104 + * while the <tt>poll()</tt> method returns <tt>null</tt>.
  73.105 + *
  73.106 + * <p>The {@link #element()} and {@link #peek()} methods return, but do
  73.107 + * not remove, the head of the queue.
  73.108 + *
  73.109 + * <p>The <tt>Queue</tt> interface does not define the <i>blocking queue
  73.110 + * methods</i>, which are common in concurrent programming.  These methods,
  73.111 + * which wait for elements to appear or for space to become available, are
  73.112 + * defined in the {@link java.util.concurrent.BlockingQueue} interface, which
  73.113 + * extends this interface.
  73.114 + *
  73.115 + * <p><tt>Queue</tt> implementations generally do not allow insertion
  73.116 + * of <tt>null</tt> elements, although some implementations, such as
  73.117 + * {@link LinkedList}, do not prohibit insertion of <tt>null</tt>.
  73.118 + * Even in the implementations that permit it, <tt>null</tt> should
  73.119 + * not be inserted into a <tt>Queue</tt>, as <tt>null</tt> is also
  73.120 + * used as a special return value by the <tt>poll</tt> method to
  73.121 + * indicate that the queue contains no elements.
  73.122 + *
  73.123 + * <p><tt>Queue</tt> implementations generally do not define
  73.124 + * element-based versions of methods <tt>equals</tt> and
  73.125 + * <tt>hashCode</tt> but instead inherit the identity based versions
  73.126 + * from class <tt>Object</tt>, because element-based equality is not
  73.127 + * always well-defined for queues with the same elements but different
  73.128 + * ordering properties.
  73.129 + *
  73.130 + *
  73.131 + * <p>This interface is a member of the
  73.132 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  73.133 + * Java Collections Framework</a>.
  73.134 + *
  73.135 + * @see java.util.Collection
  73.136 + * @see LinkedList
  73.137 + * @see PriorityQueue
  73.138 + * @see java.util.concurrent.LinkedBlockingQueue
  73.139 + * @see java.util.concurrent.BlockingQueue
  73.140 + * @see java.util.concurrent.ArrayBlockingQueue
  73.141 + * @see java.util.concurrent.LinkedBlockingQueue
  73.142 + * @see java.util.concurrent.PriorityBlockingQueue
  73.143 + * @since 1.5
  73.144 + * @author Doug Lea
  73.145 + * @param <E> the type of elements held in this collection
  73.146 + */
  73.147 +public interface Queue<E> extends Collection<E> {
  73.148 +    /**
  73.149 +     * Inserts the specified element into this queue if it is possible to do so
  73.150 +     * immediately without violating capacity restrictions, returning
  73.151 +     * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt>
  73.152 +     * if no space is currently available.
  73.153 +     *
  73.154 +     * @param e the element to add
  73.155 +     * @return <tt>true</tt> (as specified by {@link Collection#add})
  73.156 +     * @throws IllegalStateException if the element cannot be added at this
  73.157 +     *         time due to capacity restrictions
  73.158 +     * @throws ClassCastException if the class of the specified element
  73.159 +     *         prevents it from being added to this queue
  73.160 +     * @throws NullPointerException if the specified element is null and
  73.161 +     *         this queue does not permit null elements
  73.162 +     * @throws IllegalArgumentException if some property of this element
  73.163 +     *         prevents it from being added to this queue
  73.164 +     */
  73.165 +    boolean add(E e);
  73.166 +
  73.167 +    /**
  73.168 +     * Inserts the specified element into this queue if it is possible to do
  73.169 +     * so immediately without violating capacity restrictions.
  73.170 +     * When using a capacity-restricted queue, this method is generally
  73.171 +     * preferable to {@link #add}, which can fail to insert an element only
  73.172 +     * by throwing an exception.
  73.173 +     *
  73.174 +     * @param e the element to add
  73.175 +     * @return <tt>true</tt> if the element was added to this queue, else
  73.176 +     *         <tt>false</tt>
  73.177 +     * @throws ClassCastException if the class of the specified element
  73.178 +     *         prevents it from being added to this queue
  73.179 +     * @throws NullPointerException if the specified element is null and
  73.180 +     *         this queue does not permit null elements
  73.181 +     * @throws IllegalArgumentException if some property of this element
  73.182 +     *         prevents it from being added to this queue
  73.183 +     */
  73.184 +    boolean offer(E e);
  73.185 +
  73.186 +    /**
  73.187 +     * Retrieves and removes the head of this queue.  This method differs
  73.188 +     * from {@link #poll poll} only in that it throws an exception if this
  73.189 +     * queue is empty.
  73.190 +     *
  73.191 +     * @return the head of this queue
  73.192 +     * @throws NoSuchElementException if this queue is empty
  73.193 +     */
  73.194 +    E remove();
  73.195 +
  73.196 +    /**
  73.197 +     * Retrieves and removes the head of this queue,
  73.198 +     * or returns <tt>null</tt> if this queue is empty.
  73.199 +     *
  73.200 +     * @return the head of this queue, or <tt>null</tt> if this queue is empty
  73.201 +     */
  73.202 +    E poll();
  73.203 +
  73.204 +    /**
  73.205 +     * Retrieves, but does not remove, the head of this queue.  This method
  73.206 +     * differs from {@link #peek peek} only in that it throws an exception
  73.207 +     * if this queue is empty.
  73.208 +     *
  73.209 +     * @return the head of this queue
  73.210 +     * @throws NoSuchElementException if this queue is empty
  73.211 +     */
  73.212 +    E element();
  73.213 +
  73.214 +    /**
  73.215 +     * Retrieves, but does not remove, the head of this queue,
  73.216 +     * or returns <tt>null</tt> if this queue is empty.
  73.217 +     *
  73.218 +     * @return the head of this queue, or <tt>null</tt> if this queue is empty
  73.219 +     */
  73.220 +    E peek();
  73.221 +}
    74.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    74.2 +++ b/emul/compact/src/main/java/java/util/Random.java	Sun Feb 03 07:48:42 2013 +0100
    74.3 @@ -0,0 +1,503 @@
    74.4 +/*
    74.5 + * Copyright (c) 1995, 2010, 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.util;
   74.30 +
   74.31 +import org.apidesign.bck2brwsr.emul.lang.System;
   74.32 +
   74.33 +/**
   74.34 + * An instance of this class is used to generate a stream of
   74.35 + * pseudorandom numbers. The class uses a 48-bit seed, which is
   74.36 + * modified using a linear congruential formula. (See Donald Knuth,
   74.37 + * <i>The Art of Computer Programming, Volume 2</i>, Section 3.2.1.)
   74.38 + * <p>
   74.39 + * If two instances of {@code Random} are created with the same
   74.40 + * seed, and the same sequence of method calls is made for each, they
   74.41 + * will generate and return identical sequences of numbers. In order to
   74.42 + * guarantee this property, particular algorithms are specified for the
   74.43 + * class {@code Random}. Java implementations must use all the algorithms
   74.44 + * shown here for the class {@code Random}, for the sake of absolute
   74.45 + * portability of Java code. However, subclasses of class {@code Random}
   74.46 + * are permitted to use other algorithms, so long as they adhere to the
   74.47 + * general contracts for all the methods.
   74.48 + * <p>
   74.49 + * The algorithms implemented by class {@code Random} use a
   74.50 + * {@code protected} utility method that on each invocation can supply
   74.51 + * up to 32 pseudorandomly generated bits.
   74.52 + * <p>
   74.53 + * Many applications will find the method {@link Math#random} simpler to use.
   74.54 + *
   74.55 + * <p>Instances of {@code java.util.Random} are threadsafe.
   74.56 + * However, the concurrent use of the same {@code java.util.Random}
   74.57 + * instance across threads may encounter contention and consequent
   74.58 + * poor performance. Consider instead using
   74.59 + * {@link java.util.concurrent.ThreadLocalRandom} in multithreaded
   74.60 + * designs.
   74.61 + *
   74.62 + * <p>Instances of {@code java.util.Random} are not cryptographically
   74.63 + * secure.  Consider instead using {@link java.security.SecureRandom} to
   74.64 + * get a cryptographically secure pseudo-random number generator for use
   74.65 + * by security-sensitive applications.
   74.66 + *
   74.67 + * @author  Frank Yellin
   74.68 + * @since   1.0
   74.69 + */
   74.70 +public
   74.71 +class Random implements java.io.Serializable {
   74.72 +    /** use serialVersionUID from JDK 1.1 for interoperability */
   74.73 +    static final long serialVersionUID = 3905348978240129619L;
   74.74 +
   74.75 +    /**
   74.76 +     * The internal state associated with this pseudorandom number generator.
   74.77 +     * (The specs for the methods in this class describe the ongoing
   74.78 +     * computation of this value.)
   74.79 +     */
   74.80 +    private long seed;
   74.81 +
   74.82 +    private static final long multiplier = 0x5DEECE66DL;
   74.83 +    private static final long addend = 0xBL;
   74.84 +    private static final long mask = (1L << 48) - 1;
   74.85 +
   74.86 +    /**
   74.87 +     * Creates a new random number generator. This constructor sets
   74.88 +     * the seed of the random number generator to a value very likely
   74.89 +     * to be distinct from any other invocation of this constructor.
   74.90 +     */
   74.91 +    public Random() {
   74.92 +        this(seedUniquifier() ^ System.nanoTime());
   74.93 +    }
   74.94 +    
   74.95 +    private static synchronized long seedUniquifier() {
   74.96 +        // L'Ecuyer, "Tables of Linear Congruential Generators of
   74.97 +        // Different Sizes and Good Lattice Structure", 1999
   74.98 +        long current = seedUniquifier;
   74.99 +        long next = current * 181783497276652981L;
  74.100 +        seedUniquifier = next;
  74.101 +        return next;
  74.102 +    }
  74.103 +
  74.104 +    private static long seedUniquifier = 8682522807148012L;
  74.105 +
  74.106 +    /**
  74.107 +     * Creates a new random number generator using a single {@code long} seed.
  74.108 +     * The seed is the initial value of the internal state of the pseudorandom
  74.109 +     * number generator which is maintained by method {@link #next}.
  74.110 +     *
  74.111 +     * <p>The invocation {@code new Random(seed)} is equivalent to:
  74.112 +     *  <pre> {@code
  74.113 +     * Random rnd = new Random();
  74.114 +     * rnd.setSeed(seed);}</pre>
  74.115 +     *
  74.116 +     * @param seed the initial seed
  74.117 +     * @see   #setSeed(long)
  74.118 +     */
  74.119 +    public Random(long seed) {
  74.120 +        this.seed = initialScramble(seed);
  74.121 +    }
  74.122 +
  74.123 +    private static long initialScramble(long seed) {
  74.124 +        return (seed ^ multiplier) & mask;
  74.125 +    }
  74.126 +
  74.127 +    /**
  74.128 +     * Sets the seed of this random number generator using a single
  74.129 +     * {@code long} seed. The general contract of {@code setSeed} is
  74.130 +     * that it alters the state of this random number generator object
  74.131 +     * so as to be in exactly the same state as if it had just been
  74.132 +     * created with the argument {@code seed} as a seed. The method
  74.133 +     * {@code setSeed} is implemented by class {@code Random} by
  74.134 +     * atomically updating the seed to
  74.135 +     *  <pre>{@code (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1)}</pre>
  74.136 +     * and clearing the {@code haveNextNextGaussian} flag used by {@link
  74.137 +     * #nextGaussian}.
  74.138 +     *
  74.139 +     * <p>The implementation of {@code setSeed} by class {@code Random}
  74.140 +     * happens to use only 48 bits of the given seed. In general, however,
  74.141 +     * an overriding method may use all 64 bits of the {@code long}
  74.142 +     * argument as a seed value.
  74.143 +     *
  74.144 +     * @param seed the initial seed
  74.145 +     */
  74.146 +    synchronized public void setSeed(long seed) {
  74.147 +        this.seed = initialScramble(seed);
  74.148 +        haveNextNextGaussian = false;
  74.149 +    }
  74.150 +
  74.151 +    /**
  74.152 +     * Generates the next pseudorandom number. Subclasses should
  74.153 +     * override this, as this is used by all other methods.
  74.154 +     *
  74.155 +     * <p>The general contract of {@code next} is that it returns an
  74.156 +     * {@code int} value and if the argument {@code bits} is between
  74.157 +     * {@code 1} and {@code 32} (inclusive), then that many low-order
  74.158 +     * bits of the returned value will be (approximately) independently
  74.159 +     * chosen bit values, each of which is (approximately) equally
  74.160 +     * likely to be {@code 0} or {@code 1}. The method {@code next} is
  74.161 +     * implemented by class {@code Random} by atomically updating the seed to
  74.162 +     *  <pre>{@code (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1)}</pre>
  74.163 +     * and returning
  74.164 +     *  <pre>{@code (int)(seed >>> (48 - bits))}.</pre>
  74.165 +     *
  74.166 +     * This is a linear congruential pseudorandom number generator, as
  74.167 +     * defined by D. H. Lehmer and described by Donald E. Knuth in
  74.168 +     * <i>The Art of Computer Programming,</i> Volume 3:
  74.169 +     * <i>Seminumerical Algorithms</i>, section 3.2.1.
  74.170 +     *
  74.171 +     * @param  bits random bits
  74.172 +     * @return the next pseudorandom value from this random number
  74.173 +     *         generator's sequence
  74.174 +     * @since  1.1
  74.175 +     */
  74.176 +    protected synchronized int next(int bits) {
  74.177 +        long oldseed, nextseed;
  74.178 +        long seed = this.seed;
  74.179 +        oldseed = seed;
  74.180 +        nextseed = (oldseed * multiplier + addend) & mask;
  74.181 +        this.seed = nextseed;
  74.182 +        return (int)(nextseed >>> (48 - bits));
  74.183 +    }
  74.184 +
  74.185 +    /**
  74.186 +     * Generates random bytes and places them into a user-supplied
  74.187 +     * byte array.  The number of random bytes produced is equal to
  74.188 +     * the length of the byte array.
  74.189 +     *
  74.190 +     * <p>The method {@code nextBytes} is implemented by class {@code Random}
  74.191 +     * as if by:
  74.192 +     *  <pre> {@code
  74.193 +     * public void nextBytes(byte[] bytes) {
  74.194 +     *   for (int i = 0; i < bytes.length; )
  74.195 +     *     for (int rnd = nextInt(), n = Math.min(bytes.length - i, 4);
  74.196 +     *          n-- > 0; rnd >>= 8)
  74.197 +     *       bytes[i++] = (byte)rnd;
  74.198 +     * }}</pre>
  74.199 +     *
  74.200 +     * @param  bytes the byte array to fill with random bytes
  74.201 +     * @throws NullPointerException if the byte array is null
  74.202 +     * @since  1.1
  74.203 +     */
  74.204 +    public void nextBytes(byte[] bytes) {
  74.205 +        for (int i = 0, len = bytes.length; i < len; )
  74.206 +            for (int rnd = nextInt(),
  74.207 +                     n = Math.min(len - i, Integer.SIZE/Byte.SIZE);
  74.208 +                 n-- > 0; rnd >>= Byte.SIZE)
  74.209 +                bytes[i++] = (byte)rnd;
  74.210 +    }
  74.211 +
  74.212 +    /**
  74.213 +     * Returns the next pseudorandom, uniformly distributed {@code int}
  74.214 +     * value from this random number generator's sequence. The general
  74.215 +     * contract of {@code nextInt} is that one {@code int} value is
  74.216 +     * pseudorandomly generated and returned. All 2<font size="-1"><sup>32
  74.217 +     * </sup></font> possible {@code int} values are produced with
  74.218 +     * (approximately) equal probability.
  74.219 +     *
  74.220 +     * <p>The method {@code nextInt} is implemented by class {@code Random}
  74.221 +     * as if by:
  74.222 +     *  <pre> {@code
  74.223 +     * public int nextInt() {
  74.224 +     *   return next(32);
  74.225 +     * }}</pre>
  74.226 +     *
  74.227 +     * @return the next pseudorandom, uniformly distributed {@code int}
  74.228 +     *         value from this random number generator's sequence
  74.229 +     */
  74.230 +    public int nextInt() {
  74.231 +        return next(32);
  74.232 +    }
  74.233 +
  74.234 +    /**
  74.235 +     * Returns a pseudorandom, uniformly distributed {@code int} value
  74.236 +     * between 0 (inclusive) and the specified value (exclusive), drawn from
  74.237 +     * this random number generator's sequence.  The general contract of
  74.238 +     * {@code nextInt} is that one {@code int} value in the specified range
  74.239 +     * is pseudorandomly generated and returned.  All {@code n} possible
  74.240 +     * {@code int} values are produced with (approximately) equal
  74.241 +     * probability.  The method {@code nextInt(int n)} is implemented by
  74.242 +     * class {@code Random} as if by:
  74.243 +     *  <pre> {@code
  74.244 +     * public int nextInt(int n) {
  74.245 +     *   if (n <= 0)
  74.246 +     *     throw new IllegalArgumentException("n must be positive");
  74.247 +     *
  74.248 +     *   if ((n & -n) == n)  // i.e., n is a power of 2
  74.249 +     *     return (int)((n * (long)next(31)) >> 31);
  74.250 +     *
  74.251 +     *   int bits, val;
  74.252 +     *   do {
  74.253 +     *       bits = next(31);
  74.254 +     *       val = bits % n;
  74.255 +     *   } while (bits - val + (n-1) < 0);
  74.256 +     *   return val;
  74.257 +     * }}</pre>
  74.258 +     *
  74.259 +     * <p>The hedge "approximately" is used in the foregoing description only
  74.260 +     * because the next method is only approximately an unbiased source of
  74.261 +     * independently chosen bits.  If it were a perfect source of randomly
  74.262 +     * chosen bits, then the algorithm shown would choose {@code int}
  74.263 +     * values from the stated range with perfect uniformity.
  74.264 +     * <p>
  74.265 +     * The algorithm is slightly tricky.  It rejects values that would result
  74.266 +     * in an uneven distribution (due to the fact that 2^31 is not divisible
  74.267 +     * by n). The probability of a value being rejected depends on n.  The
  74.268 +     * worst case is n=2^30+1, for which the probability of a reject is 1/2,
  74.269 +     * and the expected number of iterations before the loop terminates is 2.
  74.270 +     * <p>
  74.271 +     * The algorithm treats the case where n is a power of two specially: it
  74.272 +     * returns the correct number of high-order bits from the underlying
  74.273 +     * pseudo-random number generator.  In the absence of special treatment,
  74.274 +     * the correct number of <i>low-order</i> bits would be returned.  Linear
  74.275 +     * congruential pseudo-random number generators such as the one
  74.276 +     * implemented by this class are known to have short periods in the
  74.277 +     * sequence of values of their low-order bits.  Thus, this special case
  74.278 +     * greatly increases the length of the sequence of values returned by
  74.279 +     * successive calls to this method if n is a small power of two.
  74.280 +     *
  74.281 +     * @param n the bound on the random number to be returned.  Must be
  74.282 +     *        positive.
  74.283 +     * @return the next pseudorandom, uniformly distributed {@code int}
  74.284 +     *         value between {@code 0} (inclusive) and {@code n} (exclusive)
  74.285 +     *         from this random number generator's sequence
  74.286 +     * @throws IllegalArgumentException if n is not positive
  74.287 +     * @since 1.2
  74.288 +     */
  74.289 +
  74.290 +    public int nextInt(int n) {
  74.291 +        if (n <= 0)
  74.292 +            throw new IllegalArgumentException("n must be positive");
  74.293 +
  74.294 +        if ((n & -n) == n)  // i.e., n is a power of 2
  74.295 +            return (int)((n * (long)next(31)) >> 31);
  74.296 +
  74.297 +        int bits, val;
  74.298 +        do {
  74.299 +            bits = next(31);
  74.300 +            val = bits % n;
  74.301 +        } while (bits - val + (n-1) < 0);
  74.302 +        return val;
  74.303 +    }
  74.304 +
  74.305 +    /**
  74.306 +     * Returns the next pseudorandom, uniformly distributed {@code long}
  74.307 +     * value from this random number generator's sequence. The general
  74.308 +     * contract of {@code nextLong} is that one {@code long} value is
  74.309 +     * pseudorandomly generated and returned.
  74.310 +     *
  74.311 +     * <p>The method {@code nextLong} is implemented by class {@code Random}
  74.312 +     * as if by:
  74.313 +     *  <pre> {@code
  74.314 +     * public long nextLong() {
  74.315 +     *   return ((long)next(32) << 32) + next(32);
  74.316 +     * }}</pre>
  74.317 +     *
  74.318 +     * Because class {@code Random} uses a seed with only 48 bits,
  74.319 +     * this algorithm will not return all possible {@code long} values.
  74.320 +     *
  74.321 +     * @return the next pseudorandom, uniformly distributed {@code long}
  74.322 +     *         value from this random number generator's sequence
  74.323 +     */
  74.324 +    public long nextLong() {
  74.325 +        // it's okay that the bottom word remains signed.
  74.326 +        return ((long)(next(32)) << 32) + next(32);
  74.327 +    }
  74.328 +
  74.329 +    /**
  74.330 +     * Returns the next pseudorandom, uniformly distributed
  74.331 +     * {@code boolean} value from this random number generator's
  74.332 +     * sequence. The general contract of {@code nextBoolean} is that one
  74.333 +     * {@code boolean} value is pseudorandomly generated and returned.  The
  74.334 +     * values {@code true} and {@code false} are produced with
  74.335 +     * (approximately) equal probability.
  74.336 +     *
  74.337 +     * <p>The method {@code nextBoolean} is implemented by class {@code Random}
  74.338 +     * as if by:
  74.339 +     *  <pre> {@code
  74.340 +     * public boolean nextBoolean() {
  74.341 +     *   return next(1) != 0;
  74.342 +     * }}</pre>
  74.343 +     *
  74.344 +     * @return the next pseudorandom, uniformly distributed
  74.345 +     *         {@code boolean} value from this random number generator's
  74.346 +     *         sequence
  74.347 +     * @since 1.2
  74.348 +     */
  74.349 +    public boolean nextBoolean() {
  74.350 +        return next(1) != 0;
  74.351 +    }
  74.352 +
  74.353 +    /**
  74.354 +     * Returns the next pseudorandom, uniformly distributed {@code float}
  74.355 +     * value between {@code 0.0} and {@code 1.0} from this random
  74.356 +     * number generator's sequence.
  74.357 +     *
  74.358 +     * <p>The general contract of {@code nextFloat} is that one
  74.359 +     * {@code float} value, chosen (approximately) uniformly from the
  74.360 +     * range {@code 0.0f} (inclusive) to {@code 1.0f} (exclusive), is
  74.361 +     * pseudorandomly generated and returned. All 2<font
  74.362 +     * size="-1"><sup>24</sup></font> possible {@code float} values
  74.363 +     * of the form <i>m&nbsp;x&nbsp</i>2<font
  74.364 +     * size="-1"><sup>-24</sup></font>, where <i>m</i> is a positive
  74.365 +     * integer less than 2<font size="-1"><sup>24</sup> </font>, are
  74.366 +     * produced with (approximately) equal probability.
  74.367 +     *
  74.368 +     * <p>The method {@code nextFloat} is implemented by class {@code Random}
  74.369 +     * as if by:
  74.370 +     *  <pre> {@code
  74.371 +     * public float nextFloat() {
  74.372 +     *   return next(24) / ((float)(1 << 24));
  74.373 +     * }}</pre>
  74.374 +     *
  74.375 +     * <p>The hedge "approximately" is used in the foregoing description only
  74.376 +     * because the next method is only approximately an unbiased source of
  74.377 +     * independently chosen bits. If it were a perfect source of randomly
  74.378 +     * chosen bits, then the algorithm shown would choose {@code float}
  74.379 +     * values from the stated range with perfect uniformity.<p>
  74.380 +     * [In early versions of Java, the result was incorrectly calculated as:
  74.381 +     *  <pre> {@code
  74.382 +     *   return next(30) / ((float)(1 << 30));}</pre>
  74.383 +     * This might seem to be equivalent, if not better, but in fact it
  74.384 +     * introduced a slight nonuniformity because of the bias in the rounding
  74.385 +     * of floating-point numbers: it was slightly more likely that the
  74.386 +     * low-order bit of the significand would be 0 than that it would be 1.]
  74.387 +     *
  74.388 +     * @return the next pseudorandom, uniformly distributed {@code float}
  74.389 +     *         value between {@code 0.0} and {@code 1.0} from this
  74.390 +     *         random number generator's sequence
  74.391 +     */
  74.392 +    public float nextFloat() {
  74.393 +        return next(24) / ((float)(1 << 24));
  74.394 +    }
  74.395 +
  74.396 +    /**
  74.397 +     * Returns the next pseudorandom, uniformly distributed
  74.398 +     * {@code double} value between {@code 0.0} and
  74.399 +     * {@code 1.0} from this random number generator's sequence.
  74.400 +     *
  74.401 +     * <p>The general contract of {@code nextDouble} is that one
  74.402 +     * {@code double} value, chosen (approximately) uniformly from the
  74.403 +     * range {@code 0.0d} (inclusive) to {@code 1.0d} (exclusive), is
  74.404 +     * pseudorandomly generated and returned.
  74.405 +     *
  74.406 +     * <p>The method {@code nextDouble} is implemented by class {@code Random}
  74.407 +     * as if by:
  74.408 +     *  <pre> {@code
  74.409 +     * public double nextDouble() {
  74.410 +     *   return (((long)next(26) << 27) + next(27))
  74.411 +     *     / (double)(1L << 53);
  74.412 +     * }}</pre>
  74.413 +     *
  74.414 +     * <p>The hedge "approximately" is used in the foregoing description only
  74.415 +     * because the {@code next} method is only approximately an unbiased
  74.416 +     * source of independently chosen bits. If it were a perfect source of
  74.417 +     * randomly chosen bits, then the algorithm shown would choose
  74.418 +     * {@code double} values from the stated range with perfect uniformity.
  74.419 +     * <p>[In early versions of Java, the result was incorrectly calculated as:
  74.420 +     *  <pre> {@code
  74.421 +     *   return (((long)next(27) << 27) + next(27))
  74.422 +     *     / (double)(1L << 54);}</pre>
  74.423 +     * This might seem to be equivalent, if not better, but in fact it
  74.424 +     * introduced a large nonuniformity because of the bias in the rounding
  74.425 +     * of floating-point numbers: it was three times as likely that the
  74.426 +     * low-order bit of the significand would be 0 than that it would be 1!
  74.427 +     * This nonuniformity probably doesn't matter much in practice, but we
  74.428 +     * strive for perfection.]
  74.429 +     *
  74.430 +     * @return the next pseudorandom, uniformly distributed {@code double}
  74.431 +     *         value between {@code 0.0} and {@code 1.0} from this
  74.432 +     *         random number generator's sequence
  74.433 +     * @see Math#random
  74.434 +     */
  74.435 +    public double nextDouble() {
  74.436 +        return (((long)(next(26)) << 27) + next(27))
  74.437 +            / (double)(1L << 53);
  74.438 +    }
  74.439 +
  74.440 +    private double nextNextGaussian;
  74.441 +    private boolean haveNextNextGaussian = false;
  74.442 +
  74.443 +    /**
  74.444 +     * Returns the next pseudorandom, Gaussian ("normally") distributed
  74.445 +     * {@code double} value with mean {@code 0.0} and standard
  74.446 +     * deviation {@code 1.0} from this random number generator's sequence.
  74.447 +     * <p>
  74.448 +     * The general contract of {@code nextGaussian} is that one
  74.449 +     * {@code double} value, chosen from (approximately) the usual
  74.450 +     * normal distribution with mean {@code 0.0} and standard deviation
  74.451 +     * {@code 1.0}, is pseudorandomly generated and returned.
  74.452 +     *
  74.453 +     * <p>The method {@code nextGaussian} is implemented by class
  74.454 +     * {@code Random} as if by a threadsafe version of the following:
  74.455 +     *  <pre> {@code
  74.456 +     * private double nextNextGaussian;
  74.457 +     * private boolean haveNextNextGaussian = false;
  74.458 +     *
  74.459 +     * public double nextGaussian() {
  74.460 +     *   if (haveNextNextGaussian) {
  74.461 +     *     haveNextNextGaussian = false;
  74.462 +     *     return nextNextGaussian;
  74.463 +     *   } else {
  74.464 +     *     double v1, v2, s;
  74.465 +     *     do {
  74.466 +     *       v1 = 2 * nextDouble() - 1;   // between -1.0 and 1.0
  74.467 +     *       v2 = 2 * nextDouble() - 1;   // between -1.0 and 1.0
  74.468 +     *       s = v1 * v1 + v2 * v2;
  74.469 +     *     } while (s >= 1 || s == 0);
  74.470 +     *     double multiplier = StrictMath.sqrt(-2 * StrictMath.log(s)/s);
  74.471 +     *     nextNextGaussian = v2 * multiplier;
  74.472 +     *     haveNextNextGaussian = true;
  74.473 +     *     return v1 * multiplier;
  74.474 +     *   }
  74.475 +     * }}</pre>
  74.476 +     * This uses the <i>polar method</i> of G. E. P. Box, M. E. Muller, and
  74.477 +     * G. Marsaglia, as described by Donald E. Knuth in <i>The Art of
  74.478 +     * Computer Programming</i>, Volume 3: <i>Seminumerical Algorithms</i>,
  74.479 +     * section 3.4.1, subsection C, algorithm P. Note that it generates two
  74.480 +     * independent values at the cost of only one call to {@code StrictMath.log}
  74.481 +     * and one call to {@code StrictMath.sqrt}.
  74.482 +     *
  74.483 +     * @return the next pseudorandom, Gaussian ("normally") distributed
  74.484 +     *         {@code double} value with mean {@code 0.0} and
  74.485 +     *         standard deviation {@code 1.0} from this random number
  74.486 +     *         generator's sequence
  74.487 +     */
  74.488 +    synchronized public double nextGaussian() {
  74.489 +        // See Knuth, ACP, Section 3.4.1 Algorithm C.
  74.490 +        if (haveNextNextGaussian) {
  74.491 +            haveNextNextGaussian = false;
  74.492 +            return nextNextGaussian;
  74.493 +        } else {
  74.494 +            double v1, v2, s;
  74.495 +            do {
  74.496 +                v1 = 2 * nextDouble() - 1; // between -1 and 1
  74.497 +                v2 = 2 * nextDouble() - 1; // between -1 and 1
  74.498 +                s = v1 * v1 + v2 * v2;
  74.499 +            } while (s >= 1 || s == 0);
  74.500 +            double multiplier = Math.sqrt(-2 * Math.log(s)/s);
  74.501 +            nextNextGaussian = v2 * multiplier;
  74.502 +            haveNextNextGaussian = true;
  74.503 +            return v1 * multiplier;
  74.504 +        }
  74.505 +    }
  74.506 +}
    75.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    75.2 +++ b/emul/compact/src/main/java/java/util/RandomAccess.java	Sun Feb 03 07:48:42 2013 +0100
    75.3 @@ -0,0 +1,68 @@
    75.4 +/*
    75.5 + * Copyright (c) 2000, 2006, 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.util;
   75.30 +
   75.31 +/**
   75.32 + * Marker interface used by <tt>List</tt> implementations to indicate that
   75.33 + * they support fast (generally constant time) random access.  The primary
   75.34 + * purpose of this interface is to allow generic algorithms to alter their
   75.35 + * behavior to provide good performance when applied to either random or
   75.36 + * sequential access lists.
   75.37 + *
   75.38 + * <p>The best algorithms for manipulating random access lists (such as
   75.39 + * <tt>ArrayList</tt>) can produce quadratic behavior when applied to
   75.40 + * sequential access lists (such as <tt>LinkedList</tt>).  Generic list
   75.41 + * algorithms are encouraged to check whether the given list is an
   75.42 + * <tt>instanceof</tt> this interface before applying an algorithm that would
   75.43 + * provide poor performance if it were applied to a sequential access list,
   75.44 + * and to alter their behavior if necessary to guarantee acceptable
   75.45 + * performance.
   75.46 + *
   75.47 + * <p>It is recognized that the distinction between random and sequential
   75.48 + * access is often fuzzy.  For example, some <tt>List</tt> implementations
   75.49 + * provide asymptotically linear access times if they get huge, but constant
   75.50 + * access times in practice.  Such a <tt>List</tt> implementation
   75.51 + * should generally implement this interface.  As a rule of thumb, a
   75.52 + * <tt>List</tt> implementation should implement this interface if,
   75.53 + * for typical instances of the class, this loop:
   75.54 + * <pre>
   75.55 + *     for (int i=0, n=list.size(); i &lt; n; i++)
   75.56 + *         list.get(i);
   75.57 + * </pre>
   75.58 + * runs faster than this loop:
   75.59 + * <pre>
   75.60 + *     for (Iterator i=list.iterator(); i.hasNext(); )
   75.61 + *         i.next();
   75.62 + * </pre>
   75.63 + *
   75.64 + * <p>This interface is a member of the
   75.65 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   75.66 + * Java Collections Framework</a>.
   75.67 + *
   75.68 + * @since 1.4
   75.69 + */
   75.70 +public interface RandomAccess {
   75.71 +}
    76.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    76.2 +++ b/emul/compact/src/main/java/java/util/ServiceConfigurationError.java	Sun Feb 03 07:48:42 2013 +0100
    76.3 @@ -0,0 +1,87 @@
    76.4 +/*
    76.5 + * Copyright (c) 2005, 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.util;
   76.30 +
   76.31 +
   76.32 +/**
   76.33 + * Error thrown when something goes wrong while loading a service provider.
   76.34 + *
   76.35 + * <p> This error will be thrown in the following situations:
   76.36 + *
   76.37 + * <ul>
   76.38 + *
   76.39 + *   <li> The format of a provider-configuration file violates the <a
   76.40 + *   href="ServiceLoader.html#format">specification</a>; </li>
   76.41 + *
   76.42 + *   <li> An {@link java.io.IOException IOException} occurs while reading a
   76.43 + *   provider-configuration file; </li>
   76.44 + *
   76.45 + *   <li> A concrete provider class named in a provider-configuration file
   76.46 + *   cannot be found; </li>
   76.47 + *
   76.48 + *   <li> A concrete provider class is not a subclass of the service class;
   76.49 + *   </li>
   76.50 + *
   76.51 + *   <li> A concrete provider class cannot be instantiated; or
   76.52 + *
   76.53 + *   <li> Some other kind of error occurs. </li>
   76.54 + *
   76.55 + * </ul>
   76.56 + *
   76.57 + *
   76.58 + * @author Mark Reinhold
   76.59 + * @since 1.6
   76.60 + */
   76.61 +
   76.62 +public class ServiceConfigurationError
   76.63 +    extends Error
   76.64 +{
   76.65 +
   76.66 +    private static final long serialVersionUID = 74132770414881L;
   76.67 +
   76.68 +    /**
   76.69 +     * Constructs a new instance with the specified message.
   76.70 +     *
   76.71 +     * @param  msg  The message, or <tt>null</tt> if there is no message
   76.72 +     *
   76.73 +     */
   76.74 +    public ServiceConfigurationError(String msg) {
   76.75 +        super(msg);
   76.76 +    }
   76.77 +
   76.78 +    /**
   76.79 +     * Constructs a new instance with the specified message and cause.
   76.80 +     *
   76.81 +     * @param  msg  The message, or <tt>null</tt> if there is no message
   76.82 +     *
   76.83 +     * @param  cause  The cause, or <tt>null</tt> if the cause is nonexistent
   76.84 +     *                or unknown
   76.85 +     */
   76.86 +    public ServiceConfigurationError(String msg, Throwable cause) {
   76.87 +        super(msg, cause);
   76.88 +    }
   76.89 +
   76.90 +}
    77.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    77.2 +++ b/emul/compact/src/main/java/java/util/ServiceLoader.java	Sun Feb 03 07:48:42 2013 +0100
    77.3 @@ -0,0 +1,538 @@
    77.4 +/*
    77.5 + * Copyright (c) 2005, 2010, 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.util;
   77.30 +
   77.31 +import java.io.BufferedReader;
   77.32 +import java.io.IOException;
   77.33 +import java.io.InputStream;
   77.34 +import java.io.InputStreamReader;
   77.35 +import java.net.URL;
   77.36 +import java.util.ArrayList;
   77.37 +import java.util.Enumeration;
   77.38 +import java.util.Iterator;
   77.39 +import java.util.List;
   77.40 +import java.util.NoSuchElementException;
   77.41 +
   77.42 +
   77.43 +/**
   77.44 + * A simple service-provider loading facility.
   77.45 + *
   77.46 + * <p> A <i>service</i> is a well-known set of interfaces and (usually
   77.47 + * abstract) classes.  A <i>service provider</i> is a specific implementation
   77.48 + * of a service.  The classes in a provider typically implement the interfaces
   77.49 + * and subclass the classes defined in the service itself.  Service providers
   77.50 + * can be installed in an implementation of the Java platform in the form of
   77.51 + * extensions, that is, jar files placed into any of the usual extension
   77.52 + * directories.  Providers can also be made available by adding them to the
   77.53 + * application's class path or by some other platform-specific means.
   77.54 + *
   77.55 + * <p> For the purpose of loading, a service is represented by a single type,
   77.56 + * that is, a single interface or abstract class.  (A concrete class can be
   77.57 + * used, but this is not recommended.)  A provider of a given service contains
   77.58 + * one or more concrete classes that extend this <i>service type</i> with data
   77.59 + * and code specific to the provider.  The <i>provider class</i> is typically
   77.60 + * not the entire provider itself but rather a proxy which contains enough
   77.61 + * information to decide whether the provider is able to satisfy a particular
   77.62 + * request together with code that can create the actual provider on demand.
   77.63 + * The details of provider classes tend to be highly service-specific; no
   77.64 + * single class or interface could possibly unify them, so no such type is
   77.65 + * defined here.  The only requirement enforced by this facility is that
   77.66 + * provider classes must have a zero-argument constructor so that they can be
   77.67 + * instantiated during loading.
   77.68 + *
   77.69 + * <p><a name="format"> A service provider is identified by placing a
   77.70 + * <i>provider-configuration file</i> in the resource directory
   77.71 + * <tt>META-INF/services</tt>.  The file's name is the fully-qualified <a
   77.72 + * href="../lang/ClassLoader.html#name">binary name</a> of the service's type.
   77.73 + * The file contains a list of fully-qualified binary names of concrete
   77.74 + * provider classes, one per line.  Space and tab characters surrounding each
   77.75 + * name, as well as blank lines, are ignored.  The comment character is
   77.76 + * <tt>'#'</tt> (<tt>'&#92;u0023'</tt>, <font size="-1">NUMBER SIGN</font>); on
   77.77 + * each line all characters following the first comment character are ignored.
   77.78 + * The file must be encoded in UTF-8.
   77.79 + *
   77.80 + * <p> If a particular concrete provider class is named in more than one
   77.81 + * configuration file, or is named in the same configuration file more than
   77.82 + * once, then the duplicates are ignored.  The configuration file naming a
   77.83 + * particular provider need not be in the same jar file or other distribution
   77.84 + * unit as the provider itself.  The provider must be accessible from the same
   77.85 + * class loader that was initially queried to locate the configuration file;
   77.86 + * note that this is not necessarily the class loader from which the file was
   77.87 + * actually loaded.
   77.88 + *
   77.89 + * <p> Providers are located and instantiated lazily, that is, on demand.  A
   77.90 + * service loader maintains a cache of the providers that have been loaded so
   77.91 + * far.  Each invocation of the {@link #iterator iterator} method returns an
   77.92 + * iterator that first yields all of the elements of the cache, in
   77.93 + * instantiation order, and then lazily locates and instantiates any remaining
   77.94 + * providers, adding each one to the cache in turn.  The cache can be cleared
   77.95 + * via the {@link #reload reload} method.
   77.96 + *
   77.97 + * <p> Service loaders always execute in the security context of the caller.
   77.98 + * Trusted system code should typically invoke the methods in this class, and
   77.99 + * the methods of the iterators which they return, from within a privileged
  77.100 + * security context.
  77.101 + *
  77.102 + * <p> Instances of this class are not safe for use by multiple concurrent
  77.103 + * threads.
  77.104 + *
  77.105 + * <p> Unless otherwise specified, passing a <tt>null</tt> argument to any
  77.106 + * method in this class will cause a {@link NullPointerException} to be thrown.
  77.107 + *
  77.108 + *
  77.109 + * <p><span style="font-weight: bold; padding-right: 1em">Example</span>
  77.110 + * Suppose we have a service type <tt>com.example.CodecSet</tt> which is
  77.111 + * intended to represent sets of encoder/decoder pairs for some protocol.  In
  77.112 + * this case it is an abstract class with two abstract methods:
  77.113 + *
  77.114 + * <blockquote><pre>
  77.115 + * public abstract Encoder getEncoder(String encodingName);
  77.116 + * public abstract Decoder getDecoder(String encodingName);</pre></blockquote>
  77.117 + *
  77.118 + * Each method returns an appropriate object or <tt>null</tt> if the provider
  77.119 + * does not support the given encoding.  Typical providers support more than
  77.120 + * one encoding.
  77.121 + *
  77.122 + * <p> If <tt>com.example.impl.StandardCodecs</tt> is an implementation of the
  77.123 + * <tt>CodecSet</tt> service then its jar file also contains a file named
  77.124 + *
  77.125 + * <blockquote><pre>
  77.126 + * META-INF/services/com.example.CodecSet</pre></blockquote>
  77.127 + *
  77.128 + * <p> This file contains the single line:
  77.129 + *
  77.130 + * <blockquote><pre>
  77.131 + * com.example.impl.StandardCodecs    # Standard codecs</pre></blockquote>
  77.132 + *
  77.133 + * <p> The <tt>CodecSet</tt> class creates and saves a single service instance
  77.134 + * at initialization:
  77.135 + *
  77.136 + * <blockquote><pre>
  77.137 + * private static ServiceLoader&lt;CodecSet&gt; codecSetLoader
  77.138 + *     = ServiceLoader.load(CodecSet.class);</pre></blockquote>
  77.139 + *
  77.140 + * <p> To locate an encoder for a given encoding name it defines a static
  77.141 + * factory method which iterates through the known and available providers,
  77.142 + * returning only when it has located a suitable encoder or has run out of
  77.143 + * providers.
  77.144 + *
  77.145 + * <blockquote><pre>
  77.146 + * public static Encoder getEncoder(String encodingName) {
  77.147 + *     for (CodecSet cp : codecSetLoader) {
  77.148 + *         Encoder enc = cp.getEncoder(encodingName);
  77.149 + *         if (enc != null)
  77.150 + *             return enc;
  77.151 + *     }
  77.152 + *     return null;
  77.153 + * }</pre></blockquote>
  77.154 + *
  77.155 + * <p> A <tt>getDecoder</tt> method is defined similarly.
  77.156 + *
  77.157 + *
  77.158 + * <p><span style="font-weight: bold; padding-right: 1em">Usage Note</span> If
  77.159 + * the class path of a class loader that is used for provider loading includes
  77.160 + * remote network URLs then those URLs will be dereferenced in the process of
  77.161 + * searching for provider-configuration files.
  77.162 + *
  77.163 + * <p> This activity is normal, although it may cause puzzling entries to be
  77.164 + * created in web-server logs.  If a web server is not configured correctly,
  77.165 + * however, then this activity may cause the provider-loading algorithm to fail
  77.166 + * spuriously.
  77.167 + *
  77.168 + * <p> A web server should return an HTTP 404 (Not Found) response when a
  77.169 + * requested resource does not exist.  Sometimes, however, web servers are
  77.170 + * erroneously configured to return an HTTP 200 (OK) response along with a
  77.171 + * helpful HTML error page in such cases.  This will cause a {@link
  77.172 + * ServiceConfigurationError} to be thrown when this class attempts to parse
  77.173 + * the HTML page as a provider-configuration file.  The best solution to this
  77.174 + * problem is to fix the misconfigured web server to return the correct
  77.175 + * response code (HTTP 404) along with the HTML error page.
  77.176 + *
  77.177 + * @param  <S>
  77.178 + *         The type of the service to be loaded by this loader
  77.179 + *
  77.180 + * @author Mark Reinhold
  77.181 + * @since 1.6
  77.182 + */
  77.183 +
  77.184 +public final class ServiceLoader<S>
  77.185 +    implements Iterable<S>
  77.186 +{
  77.187 +
  77.188 +    private static final String PREFIX = "META-INF/services/";
  77.189 +
  77.190 +    // The class or interface representing the service being loaded
  77.191 +    private Class<S> service;
  77.192 +
  77.193 +    // The class loader used to locate, load, and instantiate providers
  77.194 +    private ClassLoader loader;
  77.195 +
  77.196 +    // Cached providers, in instantiation order
  77.197 +    private LinkedHashMap<String,S> providers = new LinkedHashMap<>();
  77.198 +
  77.199 +    // The current lazy-lookup iterator
  77.200 +    private LazyIterator lookupIterator;
  77.201 +
  77.202 +    /**
  77.203 +     * Clear this loader's provider cache so that all providers will be
  77.204 +     * reloaded.
  77.205 +     *
  77.206 +     * <p> After invoking this method, subsequent invocations of the {@link
  77.207 +     * #iterator() iterator} method will lazily look up and instantiate
  77.208 +     * providers from scratch, just as is done by a newly-created loader.
  77.209 +     *
  77.210 +     * <p> This method is intended for use in situations in which new providers
  77.211 +     * can be installed into a running Java virtual machine.
  77.212 +     */
  77.213 +    public void reload() {
  77.214 +        providers.clear();
  77.215 +        lookupIterator = new LazyIterator(service, loader);
  77.216 +    }
  77.217 +
  77.218 +    private ServiceLoader(Class<S> svc, ClassLoader cl) {
  77.219 +        service = svc;
  77.220 +        loader = cl;
  77.221 +        reload();
  77.222 +    }
  77.223 +
  77.224 +    private static void fail(Class service, String msg, Throwable cause)
  77.225 +        throws ServiceConfigurationError
  77.226 +    {
  77.227 +        throw new ServiceConfigurationError(service.getName() + ": " + msg,
  77.228 +                                            cause);
  77.229 +    }
  77.230 +
  77.231 +    private static void fail(Class service, String msg)
  77.232 +        throws ServiceConfigurationError
  77.233 +    {
  77.234 +        throw new ServiceConfigurationError(service.getName() + ": " + msg);
  77.235 +    }
  77.236 +
  77.237 +    private static void fail(Class service, URL u, int line, String msg)
  77.238 +        throws ServiceConfigurationError
  77.239 +    {
  77.240 +        fail(service, u + ":" + line + ": " + msg);
  77.241 +    }
  77.242 +
  77.243 +    // Parse a single line from the given configuration file, adding the name
  77.244 +    // on the line to the names list.
  77.245 +    //
  77.246 +    private int parseLine(Class service, URL u, BufferedReader r, int lc,
  77.247 +                          List<String> names)
  77.248 +        throws IOException, ServiceConfigurationError
  77.249 +    {
  77.250 +        String ln = r.readLine();
  77.251 +        if (ln == null) {
  77.252 +            return -1;
  77.253 +        }
  77.254 +        int ci = ln.indexOf('#');
  77.255 +        if (ci >= 0) ln = ln.substring(0, ci);
  77.256 +        ln = ln.trim();
  77.257 +        int n = ln.length();
  77.258 +        if (n != 0) {
  77.259 +            if ((ln.indexOf(' ') >= 0) || (ln.indexOf('\t') >= 0))
  77.260 +                fail(service, u, lc, "Illegal configuration-file syntax");
  77.261 +            int cp = ln.codePointAt(0);
  77.262 +            if (!Character.isJavaIdentifierStart(cp))
  77.263 +                fail(service, u, lc, "Illegal provider-class name: " + ln);
  77.264 +            for (int i = Character.charCount(cp); i < n; i += Character.charCount(cp)) {
  77.265 +                cp = ln.codePointAt(i);
  77.266 +                if (!Character.isJavaIdentifierPart(cp) && (cp != '.'))
  77.267 +                    fail(service, u, lc, "Illegal provider-class name: " + ln);
  77.268 +            }
  77.269 +            if (!providers.containsKey(ln) && !names.contains(ln))
  77.270 +                names.add(ln);
  77.271 +        }
  77.272 +        return lc + 1;
  77.273 +    }
  77.274 +
  77.275 +    // Parse the content of the given URL as a provider-configuration file.
  77.276 +    //
  77.277 +    // @param  service
  77.278 +    //         The service type for which providers are being sought;
  77.279 +    //         used to construct error detail strings
  77.280 +    //
  77.281 +    // @param  u
  77.282 +    //         The URL naming the configuration file to be parsed
  77.283 +    //
  77.284 +    // @return A (possibly empty) iterator that will yield the provider-class
  77.285 +    //         names in the given configuration file that are not yet members
  77.286 +    //         of the returned set
  77.287 +    //
  77.288 +    // @throws ServiceConfigurationError
  77.289 +    //         If an I/O error occurs while reading from the given URL, or
  77.290 +    //         if a configuration-file format error is detected
  77.291 +    //
  77.292 +    private Iterator<String> parse(Class service, URL u)
  77.293 +        throws ServiceConfigurationError
  77.294 +    {
  77.295 +        InputStream in = null;
  77.296 +        BufferedReader r = null;
  77.297 +        ArrayList<String> names = new ArrayList<>();
  77.298 +        try {
  77.299 +            in = u.openStream();
  77.300 +            r = new BufferedReader(new InputStreamReader(in, "utf-8"));
  77.301 +            int lc = 1;
  77.302 +            while ((lc = parseLine(service, u, r, lc, names)) >= 0);
  77.303 +        } catch (IOException x) {
  77.304 +            fail(service, "Error reading configuration file", x);
  77.305 +        } finally {
  77.306 +            try {
  77.307 +                if (r != null) r.close();
  77.308 +                if (in != null) in.close();
  77.309 +            } catch (IOException y) {
  77.310 +                fail(service, "Error closing configuration file", y);
  77.311 +            }
  77.312 +        }
  77.313 +        return names.iterator();
  77.314 +    }
  77.315 +
  77.316 +    // Private inner class implementing fully-lazy provider lookup
  77.317 +    //
  77.318 +    private class LazyIterator
  77.319 +        implements Iterator<S>
  77.320 +    {
  77.321 +
  77.322 +        Class<S> service;
  77.323 +        ClassLoader loader;
  77.324 +        Enumeration<URL> configs = null;
  77.325 +        Iterator<String> pending = null;
  77.326 +        String nextName = null;
  77.327 +
  77.328 +        private LazyIterator(Class<S> service, ClassLoader loader) {
  77.329 +            this.service = service;
  77.330 +            this.loader = loader;
  77.331 +        }
  77.332 +
  77.333 +        public boolean hasNext() {
  77.334 +            if (nextName != null) {
  77.335 +                return true;
  77.336 +            }
  77.337 +            if (configs == null) {
  77.338 +                try {
  77.339 +                    String fullName = PREFIX + service.getName();
  77.340 +                    if (loader == null)
  77.341 +                        configs = ClassLoader.getSystemResources(fullName);
  77.342 +                    else
  77.343 +                        configs = loader.getResources(fullName);
  77.344 +                } catch (IOException x) {
  77.345 +                    fail(service, "Error locating configuration files", x);
  77.346 +                }
  77.347 +            }
  77.348 +            while ((pending == null) || !pending.hasNext()) {
  77.349 +                if (!configs.hasMoreElements()) {
  77.350 +                    return false;
  77.351 +                }
  77.352 +                pending = parse(service, configs.nextElement());
  77.353 +            }
  77.354 +            nextName = pending.next();
  77.355 +            return true;
  77.356 +        }
  77.357 +
  77.358 +        public S next() {
  77.359 +            if (!hasNext()) {
  77.360 +                throw new NoSuchElementException();
  77.361 +            }
  77.362 +            String cn = nextName;
  77.363 +            nextName = null;
  77.364 +            try {
  77.365 +                S p = service.cast(Class.forName(cn, true, loader)
  77.366 +                                   .newInstance());
  77.367 +                providers.put(cn, p);
  77.368 +                return p;
  77.369 +            } catch (ClassNotFoundException x) {
  77.370 +                fail(service,
  77.371 +                     "Provider " + cn + " not found");
  77.372 +            } catch (Throwable x) {
  77.373 +                fail(service,
  77.374 +                     "Provider " + cn + " could not be instantiated: " + x,
  77.375 +                     x);
  77.376 +            }
  77.377 +            throw new Error();          // This cannot happen
  77.378 +        }
  77.379 +
  77.380 +        public void remove() {
  77.381 +            throw new UnsupportedOperationException();
  77.382 +        }
  77.383 +
  77.384 +    }
  77.385 +
  77.386 +    /**
  77.387 +     * Lazily loads the available providers of this loader's service.
  77.388 +     *
  77.389 +     * <p> The iterator returned by this method first yields all of the
  77.390 +     * elements of the provider cache, in instantiation order.  It then lazily
  77.391 +     * loads and instantiates any remaining providers, adding each one to the
  77.392 +     * cache in turn.
  77.393 +     *
  77.394 +     * <p> To achieve laziness the actual work of parsing the available
  77.395 +     * provider-configuration files and instantiating providers must be done by
  77.396 +     * the iterator itself.  Its {@link java.util.Iterator#hasNext hasNext} and
  77.397 +     * {@link java.util.Iterator#next next} methods can therefore throw a
  77.398 +     * {@link ServiceConfigurationError} if a provider-configuration file
  77.399 +     * violates the specified format, or if it names a provider class that
  77.400 +     * cannot be found and instantiated, or if the result of instantiating the
  77.401 +     * class is not assignable to the service type, or if any other kind of
  77.402 +     * exception or error is thrown as the next provider is located and
  77.403 +     * instantiated.  To write robust code it is only necessary to catch {@link
  77.404 +     * ServiceConfigurationError} when using a service iterator.
  77.405 +     *
  77.406 +     * <p> If such an error is thrown then subsequent invocations of the
  77.407 +     * iterator will make a best effort to locate and instantiate the next
  77.408 +     * available provider, but in general such recovery cannot be guaranteed.
  77.409 +     *
  77.410 +     * <blockquote style="font-size: smaller; line-height: 1.2"><span
  77.411 +     * style="padding-right: 1em; font-weight: bold">Design Note</span>
  77.412 +     * Throwing an error in these cases may seem extreme.  The rationale for
  77.413 +     * this behavior is that a malformed provider-configuration file, like a
  77.414 +     * malformed class file, indicates a serious problem with the way the Java
  77.415 +     * virtual machine is configured or is being used.  As such it is
  77.416 +     * preferable to throw an error rather than try to recover or, even worse,
  77.417 +     * fail silently.</blockquote>
  77.418 +     *
  77.419 +     * <p> The iterator returned by this method does not support removal.
  77.420 +     * Invoking its {@link java.util.Iterator#remove() remove} method will
  77.421 +     * cause an {@link UnsupportedOperationException} to be thrown.
  77.422 +     *
  77.423 +     * @return  An iterator that lazily loads providers for this loader's
  77.424 +     *          service
  77.425 +     */
  77.426 +    public Iterator<S> iterator() {
  77.427 +        return new Iterator<S>() {
  77.428 +
  77.429 +            Iterator<Map.Entry<String,S>> knownProviders
  77.430 +                = providers.entrySet().iterator();
  77.431 +
  77.432 +            public boolean hasNext() {
  77.433 +                if (knownProviders.hasNext())
  77.434 +                    return true;
  77.435 +                return lookupIterator.hasNext();
  77.436 +            }
  77.437 +
  77.438 +            public S next() {
  77.439 +                if (knownProviders.hasNext())
  77.440 +                    return knownProviders.next().getValue();
  77.441 +                return lookupIterator.next();
  77.442 +            }
  77.443 +
  77.444 +            public void remove() {
  77.445 +                throw new UnsupportedOperationException();
  77.446 +            }
  77.447 +
  77.448 +        };
  77.449 +    }
  77.450 +
  77.451 +    /**
  77.452 +     * Creates a new service loader for the given service type and class
  77.453 +     * loader.
  77.454 +     *
  77.455 +     * @param  service
  77.456 +     *         The interface or abstract class representing the service
  77.457 +     *
  77.458 +     * @param  loader
  77.459 +     *         The class loader to be used to load provider-configuration files
  77.460 +     *         and provider classes, or <tt>null</tt> if the system class
  77.461 +     *         loader (or, failing that, the bootstrap class loader) is to be
  77.462 +     *         used
  77.463 +     *
  77.464 +     * @return A new service loader
  77.465 +     */
  77.466 +    public static <S> ServiceLoader<S> load(Class<S> service,
  77.467 +                                            ClassLoader loader)
  77.468 +    {
  77.469 +        return new ServiceLoader<>(service, loader);
  77.470 +    }
  77.471 +
  77.472 +    /**
  77.473 +     * Creates a new service loader for the given service type, using the
  77.474 +     * current thread's {@linkplain java.lang.Thread#getContextClassLoader
  77.475 +     * context class loader}.
  77.476 +     *
  77.477 +     * <p> An invocation of this convenience method of the form
  77.478 +     *
  77.479 +     * <blockquote><pre>
  77.480 +     * ServiceLoader.load(<i>service</i>)</pre></blockquote>
  77.481 +     *
  77.482 +     * is equivalent to
  77.483 +     *
  77.484 +     * <blockquote><pre>
  77.485 +     * ServiceLoader.load(<i>service</i>,
  77.486 +     *                    Thread.currentThread().getContextClassLoader())</pre></blockquote>
  77.487 +     *
  77.488 +     * @param  service
  77.489 +     *         The interface or abstract class representing the service
  77.490 +     *
  77.491 +     * @return A new service loader
  77.492 +     */
  77.493 +    public static <S> ServiceLoader<S> load(Class<S> service) {
  77.494 +        ClassLoader cl = null; // XXX: Thread.currentThread().getContextClassLoader();
  77.495 +        return ServiceLoader.load(service, cl);
  77.496 +    }
  77.497 +
  77.498 +    /**
  77.499 +     * Creates a new service loader for the given service type, using the
  77.500 +     * extension class loader.
  77.501 +     *
  77.502 +     * <p> This convenience method simply locates the extension class loader,
  77.503 +     * call it <tt><i>extClassLoader</i></tt>, and then returns
  77.504 +     *
  77.505 +     * <blockquote><pre>
  77.506 +     * ServiceLoader.load(<i>service</i>, <i>extClassLoader</i>)</pre></blockquote>
  77.507 +     *
  77.508 +     * <p> If the extension class loader cannot be found then the system class
  77.509 +     * loader is used; if there is no system class loader then the bootstrap
  77.510 +     * class loader is used.
  77.511 +     *
  77.512 +     * <p> This method is intended for use when only installed providers are
  77.513 +     * desired.  The resulting service will only find and load providers that
  77.514 +     * have been installed into the current Java virtual machine; providers on
  77.515 +     * the application's class path will be ignored.
  77.516 +     *
  77.517 +     * @param  service
  77.518 +     *         The interface or abstract class representing the service
  77.519 +     *
  77.520 +     * @return A new service loader
  77.521 +     */
  77.522 +    public static <S> ServiceLoader<S> loadInstalled(Class<S> service) {
  77.523 +        ClassLoader cl = ClassLoader.getSystemClassLoader();
  77.524 +        ClassLoader prev = null;
  77.525 +        while (cl != null) {
  77.526 +            prev = cl;
  77.527 +            cl = cl.getParent();
  77.528 +        }
  77.529 +        return ServiceLoader.load(service, prev);
  77.530 +    }
  77.531 +
  77.532 +    /**
  77.533 +     * Returns a string describing this service.
  77.534 +     *
  77.535 +     * @return  A descriptive string
  77.536 +     */
  77.537 +    public String toString() {
  77.538 +        return "java.util.ServiceLoader[" + service.getName() + "]";
  77.539 +    }
  77.540 +
  77.541 +}
    78.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    78.2 +++ b/emul/compact/src/main/java/java/util/Set.java	Sun Feb 03 07:48:42 2013 +0100
    78.3 @@ -0,0 +1,385 @@
    78.4 +/*
    78.5 + * Copyright (c) 1997, 2006, 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.util;
   78.30 +
   78.31 +/**
   78.32 + * A collection that contains no duplicate elements.  More formally, sets
   78.33 + * contain no pair of elements <code>e1</code> and <code>e2</code> such that
   78.34 + * <code>e1.equals(e2)</code>, and at most one null element.  As implied by
   78.35 + * its name, this interface models the mathematical <i>set</i> abstraction.
   78.36 + *
   78.37 + * <p>The <tt>Set</tt> interface places additional stipulations, beyond those
   78.38 + * inherited from the <tt>Collection</tt> interface, on the contracts of all
   78.39 + * constructors and on the contracts of the <tt>add</tt>, <tt>equals</tt> and
   78.40 + * <tt>hashCode</tt> methods.  Declarations for other inherited methods are
   78.41 + * also included here for convenience.  (The specifications accompanying these
   78.42 + * declarations have been tailored to the <tt>Set</tt> interface, but they do
   78.43 + * not contain any additional stipulations.)
   78.44 + *
   78.45 + * <p>The additional stipulation on constructors is, not surprisingly,
   78.46 + * that all constructors must create a set that contains no duplicate elements
   78.47 + * (as defined above).
   78.48 + *
   78.49 + * <p>Note: Great care must be exercised if mutable objects are used as set
   78.50 + * elements.  The behavior of a set is not specified if the value of an object
   78.51 + * is changed in a manner that affects <tt>equals</tt> comparisons while the
   78.52 + * object is an element in the set.  A special case of this prohibition is
   78.53 + * that it is not permissible for a set to contain itself as an element.
   78.54 + *
   78.55 + * <p>Some set implementations have restrictions on the elements that
   78.56 + * they may contain.  For example, some implementations prohibit null elements,
   78.57 + * and some have restrictions on the types of their elements.  Attempting to
   78.58 + * add an ineligible element throws an unchecked exception, typically
   78.59 + * <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.  Attempting
   78.60 + * to query the presence of an ineligible element may throw an exception,
   78.61 + * or it may simply return false; some implementations will exhibit the former
   78.62 + * behavior and some will exhibit the latter.  More generally, attempting an
   78.63 + * operation on an ineligible element whose completion would not result in
   78.64 + * the insertion of an ineligible element into the set may throw an
   78.65 + * exception or it may succeed, at the option of the implementation.
   78.66 + * Such exceptions are marked as "optional" in the specification for this
   78.67 + * interface.
   78.68 + *
   78.69 + * <p>This interface is a member of the
   78.70 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   78.71 + * Java Collections Framework</a>.
   78.72 + *
   78.73 + * @param <E> the type of elements maintained by this set
   78.74 + *
   78.75 + * @author  Josh Bloch
   78.76 + * @author  Neal Gafter
   78.77 + * @see Collection
   78.78 + * @see List
   78.79 + * @see SortedSet
   78.80 + * @see HashSet
   78.81 + * @see TreeSet
   78.82 + * @see AbstractSet
   78.83 + * @see Collections#singleton(java.lang.Object)
   78.84 + * @see Collections#EMPTY_SET
   78.85 + * @since 1.2
   78.86 + */
   78.87 +
   78.88 +public interface Set<E> extends Collection<E> {
   78.89 +    // Query Operations
   78.90 +
   78.91 +    /**
   78.92 +     * Returns the number of elements in this set (its cardinality).  If this
   78.93 +     * set contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
   78.94 +     * <tt>Integer.MAX_VALUE</tt>.
   78.95 +     *
   78.96 +     * @return the number of elements in this set (its cardinality)
   78.97 +     */
   78.98 +    int size();
   78.99 +
  78.100 +    /**
  78.101 +     * Returns <tt>true</tt> if this set contains no elements.
  78.102 +     *
  78.103 +     * @return <tt>true</tt> if this set contains no elements
  78.104 +     */
  78.105 +    boolean isEmpty();
  78.106 +
  78.107 +    /**
  78.108 +     * Returns <tt>true</tt> if this set contains the specified element.
  78.109 +     * More formally, returns <tt>true</tt> if and only if this set
  78.110 +     * contains an element <tt>e</tt> such that
  78.111 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  78.112 +     *
  78.113 +     * @param o element whose presence in this set is to be tested
  78.114 +     * @return <tt>true</tt> if this set contains the specified element
  78.115 +     * @throws ClassCastException if the type of the specified element
  78.116 +     *         is incompatible with this set
  78.117 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  78.118 +     * @throws NullPointerException if the specified element is null and this
  78.119 +     *         set does not permit null elements
  78.120 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  78.121 +     */
  78.122 +    boolean contains(Object o);
  78.123 +
  78.124 +    /**
  78.125 +     * Returns an iterator over the elements in this set.  The elements are
  78.126 +     * returned in no particular order (unless this set is an instance of some
  78.127 +     * class that provides a guarantee).
  78.128 +     *
  78.129 +     * @return an iterator over the elements in this set
  78.130 +     */
  78.131 +    Iterator<E> iterator();
  78.132 +
  78.133 +    /**
  78.134 +     * Returns an array containing all of the elements in this set.
  78.135 +     * If this set makes any guarantees as to what order its elements
  78.136 +     * are returned by its iterator, this method must return the
  78.137 +     * elements in the same order.
  78.138 +     *
  78.139 +     * <p>The returned array will be "safe" in that no references to it
  78.140 +     * are maintained by this set.  (In other words, this method must
  78.141 +     * allocate a new array even if this set is backed by an array).
  78.142 +     * The caller is thus free to modify the returned array.
  78.143 +     *
  78.144 +     * <p>This method acts as bridge between array-based and collection-based
  78.145 +     * APIs.
  78.146 +     *
  78.147 +     * @return an array containing all the elements in this set
  78.148 +     */
  78.149 +    Object[] toArray();
  78.150 +
  78.151 +    /**
  78.152 +     * Returns an array containing all of the elements in this set; the
  78.153 +     * runtime type of the returned array is that of the specified array.
  78.154 +     * If the set fits in the specified array, it is returned therein.
  78.155 +     * Otherwise, a new array is allocated with the runtime type of the
  78.156 +     * specified array and the size of this set.
  78.157 +     *
  78.158 +     * <p>If this set fits in the specified array with room to spare
  78.159 +     * (i.e., the array has more elements than this set), the element in
  78.160 +     * the array immediately following the end of the set is set to
  78.161 +     * <tt>null</tt>.  (This is useful in determining the length of this
  78.162 +     * set <i>only</i> if the caller knows that this set does not contain
  78.163 +     * any null elements.)
  78.164 +     *
  78.165 +     * <p>If this set makes any guarantees as to what order its elements
  78.166 +     * are returned by its iterator, this method must return the elements
  78.167 +     * in the same order.
  78.168 +     *
  78.169 +     * <p>Like the {@link #toArray()} method, this method acts as bridge between
  78.170 +     * array-based and collection-based APIs.  Further, this method allows
  78.171 +     * precise control over the runtime type of the output array, and may,
  78.172 +     * under certain circumstances, be used to save allocation costs.
  78.173 +     *
  78.174 +     * <p>Suppose <tt>x</tt> is a set known to contain only strings.
  78.175 +     * The following code can be used to dump the set into a newly allocated
  78.176 +     * array of <tt>String</tt>:
  78.177 +     *
  78.178 +     * <pre>
  78.179 +     *     String[] y = x.toArray(new String[0]);</pre>
  78.180 +     *
  78.181 +     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
  78.182 +     * <tt>toArray()</tt>.
  78.183 +     *
  78.184 +     * @param a the array into which the elements of this set are to be
  78.185 +     *        stored, if it is big enough; otherwise, a new array of the same
  78.186 +     *        runtime type is allocated for this purpose.
  78.187 +     * @return an array containing all the elements in this set
  78.188 +     * @throws ArrayStoreException if the runtime type of the specified array
  78.189 +     *         is not a supertype of the runtime type of every element in this
  78.190 +     *         set
  78.191 +     * @throws NullPointerException if the specified array is null
  78.192 +     */
  78.193 +    <T> T[] toArray(T[] a);
  78.194 +
  78.195 +
  78.196 +    // Modification Operations
  78.197 +
  78.198 +    /**
  78.199 +     * Adds the specified element to this set if it is not already present
  78.200 +     * (optional operation).  More formally, adds the specified element
  78.201 +     * <tt>e</tt> to this set if the set contains no element <tt>e2</tt>
  78.202 +     * such that
  78.203 +     * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
  78.204 +     * If this set already contains the element, the call leaves the set
  78.205 +     * unchanged and returns <tt>false</tt>.  In combination with the
  78.206 +     * restriction on constructors, this ensures that sets never contain
  78.207 +     * duplicate elements.
  78.208 +     *
  78.209 +     * <p>The stipulation above does not imply that sets must accept all
  78.210 +     * elements; sets may refuse to add any particular element, including
  78.211 +     * <tt>null</tt>, and throw an exception, as described in the
  78.212 +     * specification for {@link Collection#add Collection.add}.
  78.213 +     * Individual set implementations should clearly document any
  78.214 +     * restrictions on the elements that they may contain.
  78.215 +     *
  78.216 +     * @param e element to be added to this set
  78.217 +     * @return <tt>true</tt> if this set did not already contain the specified
  78.218 +     *         element
  78.219 +     * @throws UnsupportedOperationException if the <tt>add</tt> operation
  78.220 +     *         is not supported by this set
  78.221 +     * @throws ClassCastException if the class of the specified element
  78.222 +     *         prevents it from being added to this set
  78.223 +     * @throws NullPointerException if the specified element is null and this
  78.224 +     *         set does not permit null elements
  78.225 +     * @throws IllegalArgumentException if some property of the specified element
  78.226 +     *         prevents it from being added to this set
  78.227 +     */
  78.228 +    boolean add(E e);
  78.229 +
  78.230 +
  78.231 +    /**
  78.232 +     * Removes the specified element from this set if it is present
  78.233 +     * (optional operation).  More formally, removes an element <tt>e</tt>
  78.234 +     * such that
  78.235 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>, if
  78.236 +     * this set contains such an element.  Returns <tt>true</tt> if this set
  78.237 +     * contained the element (or equivalently, if this set changed as a
  78.238 +     * result of the call).  (This set will not contain the element once the
  78.239 +     * call returns.)
  78.240 +     *
  78.241 +     * @param o object to be removed from this set, if present
  78.242 +     * @return <tt>true</tt> if this set contained the specified element
  78.243 +     * @throws ClassCastException if the type of the specified element
  78.244 +     *         is incompatible with this set
  78.245 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  78.246 +     * @throws NullPointerException if the specified element is null and this
  78.247 +     *         set does not permit null elements
  78.248 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  78.249 +     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
  78.250 +     *         is not supported by this set
  78.251 +     */
  78.252 +    boolean remove(Object o);
  78.253 +
  78.254 +
  78.255 +    // Bulk Operations
  78.256 +
  78.257 +    /**
  78.258 +     * Returns <tt>true</tt> if this set contains all of the elements of the
  78.259 +     * specified collection.  If the specified collection is also a set, this
  78.260 +     * method returns <tt>true</tt> if it is a <i>subset</i> of this set.
  78.261 +     *
  78.262 +     * @param  c collection to be checked for containment in this set
  78.263 +     * @return <tt>true</tt> if this set contains all of the elements of the
  78.264 +     *         specified collection
  78.265 +     * @throws ClassCastException if the types of one or more elements
  78.266 +     *         in the specified collection are incompatible with this
  78.267 +     *         set
  78.268 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  78.269 +     * @throws NullPointerException if the specified collection contains one
  78.270 +     *         or more null elements and this set does not permit null
  78.271 +     *         elements
  78.272 +     * (<a href="Collection.html#optional-restrictions">optional</a>),
  78.273 +     *         or if the specified collection is null
  78.274 +     * @see    #contains(Object)
  78.275 +     */
  78.276 +    boolean containsAll(Collection<?> c);
  78.277 +
  78.278 +    /**
  78.279 +     * Adds all of the elements in the specified collection to this set if
  78.280 +     * they're not already present (optional operation).  If the specified
  78.281 +     * collection is also a set, the <tt>addAll</tt> operation effectively
  78.282 +     * modifies this set so that its value is the <i>union</i> of the two
  78.283 +     * sets.  The behavior of this operation is undefined if the specified
  78.284 +     * collection is modified while the operation is in progress.
  78.285 +     *
  78.286 +     * @param  c collection containing elements to be added to this set
  78.287 +     * @return <tt>true</tt> if this set changed as a result of the call
  78.288 +     *
  78.289 +     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
  78.290 +     *         is not supported by this set
  78.291 +     * @throws ClassCastException if the class of an element of the
  78.292 +     *         specified collection prevents it from being added to this set
  78.293 +     * @throws NullPointerException if the specified collection contains one
  78.294 +     *         or more null elements and this set does not permit null
  78.295 +     *         elements, or if the specified collection is null
  78.296 +     * @throws IllegalArgumentException if some property of an element of the
  78.297 +     *         specified collection prevents it from being added to this set
  78.298 +     * @see #add(Object)
  78.299 +     */
  78.300 +    boolean addAll(Collection<? extends E> c);
  78.301 +
  78.302 +    /**
  78.303 +     * Retains only the elements in this set that are contained in the
  78.304 +     * specified collection (optional operation).  In other words, removes
  78.305 +     * from this set all of its elements that are not contained in the
  78.306 +     * specified collection.  If the specified collection is also a set, this
  78.307 +     * operation effectively modifies this set so that its value is the
  78.308 +     * <i>intersection</i> of the two sets.
  78.309 +     *
  78.310 +     * @param  c collection containing elements to be retained in this set
  78.311 +     * @return <tt>true</tt> if this set changed as a result of the call
  78.312 +     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
  78.313 +     *         is not supported by this set
  78.314 +     * @throws ClassCastException if the class of an element of this set
  78.315 +     *         is incompatible with the specified collection
  78.316 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  78.317 +     * @throws NullPointerException if this set contains a null element and the
  78.318 +     *         specified collection does not permit null elements
  78.319 +     *         (<a href="Collection.html#optional-restrictions">optional</a>),
  78.320 +     *         or if the specified collection is null
  78.321 +     * @see #remove(Object)
  78.322 +     */
  78.323 +    boolean retainAll(Collection<?> c);
  78.324 +
  78.325 +    /**
  78.326 +     * Removes from this set all of its elements that are contained in the
  78.327 +     * specified collection (optional operation).  If the specified
  78.328 +     * collection is also a set, this operation effectively modifies this
  78.329 +     * set so that its value is the <i>asymmetric set difference</i> of
  78.330 +     * the two sets.
  78.331 +     *
  78.332 +     * @param  c collection containing elements to be removed from this set
  78.333 +     * @return <tt>true</tt> if this set changed as a result of the call
  78.334 +     * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
  78.335 +     *         is not supported by this set
  78.336 +     * @throws ClassCastException if the class of an element of this set
  78.337 +     *         is incompatible with the specified collection
  78.338 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  78.339 +     * @throws NullPointerException if this set contains a null element and the
  78.340 +     *         specified collection does not permit null elements
  78.341 +     *         (<a href="Collection.html#optional-restrictions">optional</a>),
  78.342 +     *         or if the specified collection is null
  78.343 +     * @see #remove(Object)
  78.344 +     * @see #contains(Object)
  78.345 +     */
  78.346 +    boolean removeAll(Collection<?> c);
  78.347 +
  78.348 +    /**
  78.349 +     * Removes all of the elements from this set (optional operation).
  78.350 +     * The set will be empty after this call returns.
  78.351 +     *
  78.352 +     * @throws UnsupportedOperationException if the <tt>clear</tt> method
  78.353 +     *         is not supported by this set
  78.354 +     */
  78.355 +    void clear();
  78.356 +
  78.357 +
  78.358 +    // Comparison and hashing
  78.359 +
  78.360 +    /**
  78.361 +     * Compares the specified object with this set for equality.  Returns
  78.362 +     * <tt>true</tt> if the specified object is also a set, the two sets
  78.363 +     * have the same size, and every member of the specified set is
  78.364 +     * contained in this set (or equivalently, every member of this set is
  78.365 +     * contained in the specified set).  This definition ensures that the
  78.366 +     * equals method works properly across different implementations of the
  78.367 +     * set interface.
  78.368 +     *
  78.369 +     * @param o object to be compared for equality with this set
  78.370 +     * @return <tt>true</tt> if the specified object is equal to this set
  78.371 +     */
  78.372 +    boolean equals(Object o);
  78.373 +
  78.374 +    /**
  78.375 +     * Returns the hash code value for this set.  The hash code of a set is
  78.376 +     * defined to be the sum of the hash codes of the elements in the set,
  78.377 +     * where the hash code of a <tt>null</tt> element is defined to be zero.
  78.378 +     * This ensures that <tt>s1.equals(s2)</tt> implies that
  78.379 +     * <tt>s1.hashCode()==s2.hashCode()</tt> for any two sets <tt>s1</tt>
  78.380 +     * and <tt>s2</tt>, as required by the general contract of
  78.381 +     * {@link Object#hashCode}.
  78.382 +     *
  78.383 +     * @return the hash code value for this set
  78.384 +     * @see Object#equals(Object)
  78.385 +     * @see Set#equals(Object)
  78.386 +     */
  78.387 +    int hashCode();
  78.388 +}
    79.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    79.2 +++ b/emul/compact/src/main/java/java/util/SortedMap.java	Sun Feb 03 07:48:42 2013 +0100
    79.3 @@ -0,0 +1,284 @@
    79.4 +/*
    79.5 + * Copyright (c) 1998, 2006, 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.util;
   79.30 +
   79.31 +/**
   79.32 + * A {@link Map} that further provides a <em>total ordering</em> on its keys.
   79.33 + * The map is ordered according to the {@linkplain Comparable natural
   79.34 + * ordering} of its keys, or by a {@link Comparator} typically
   79.35 + * provided at sorted map creation time.  This order is reflected when
   79.36 + * iterating over the sorted map's collection views (returned by the
   79.37 + * {@code entrySet}, {@code keySet} and {@code values} methods).
   79.38 + * Several additional operations are provided to take advantage of the
   79.39 + * ordering.  (This interface is the map analogue of {@link SortedSet}.)
   79.40 + *
   79.41 + * <p>All keys inserted into a sorted map must implement the {@code Comparable}
   79.42 + * interface (or be accepted by the specified comparator).  Furthermore, all
   79.43 + * such keys must be <em>mutually comparable</em>: {@code k1.compareTo(k2)} (or
   79.44 + * {@code comparator.compare(k1, k2)}) must not throw a
   79.45 + * {@code ClassCastException} for any keys {@code k1} and {@code k2} in
   79.46 + * the sorted map.  Attempts to violate this restriction will cause the
   79.47 + * offending method or constructor invocation to throw a
   79.48 + * {@code ClassCastException}.
   79.49 + *
   79.50 + * <p>Note that the ordering maintained by a sorted map (whether or not an
   79.51 + * explicit comparator is provided) must be <em>consistent with equals</em> if
   79.52 + * the sorted map is to correctly implement the {@code Map} interface.  (See
   79.53 + * the {@code Comparable} interface or {@code Comparator} interface for a
   79.54 + * precise definition of <em>consistent with equals</em>.)  This is so because
   79.55 + * the {@code Map} interface is defined in terms of the {@code equals}
   79.56 + * operation, but a sorted map performs all key comparisons using its
   79.57 + * {@code compareTo} (or {@code compare}) method, so two keys that are
   79.58 + * deemed equal by this method are, from the standpoint of the sorted map,
   79.59 + * equal.  The behavior of a tree map <em>is</em> well-defined even if its
   79.60 + * ordering is inconsistent with equals; it just fails to obey the general
   79.61 + * contract of the {@code Map} interface.
   79.62 + *
   79.63 + * <p>All general-purpose sorted map implementation classes should provide four
   79.64 + * "standard" constructors. It is not possible to enforce this recommendation
   79.65 + * though as required constructors cannot be specified by interfaces. The
   79.66 + * expected "standard" constructors for all sorted map implementations are:
   79.67 + * <ol>
   79.68 + *   <li>A void (no arguments) constructor, which creates an empty sorted map
   79.69 + *   sorted according to the natural ordering of its keys.</li>
   79.70 + *   <li>A constructor with a single argument of type {@code Comparator}, which
   79.71 + *   creates an empty sorted map sorted according to the specified comparator.</li>
   79.72 + *   <li>A constructor with a single argument of type {@code Map}, which creates
   79.73 + *   a new map with the same key-value mappings as its argument, sorted
   79.74 + *   according to the keys' natural ordering.</li>
   79.75 + *   <li>A constructor with a single argument of type {@code SortedMap}, which
   79.76 + *   creates a new sorted map with the same key-value mappings and the same
   79.77 + *   ordering as the input sorted map.</li>
   79.78 + * </ol>
   79.79 + *
   79.80 + * <p><strong>Note</strong>: several methods return submaps with restricted key
   79.81 + * ranges. Such ranges are <em>half-open</em>, that is, they include their low
   79.82 + * endpoint but not their high endpoint (where applicable).  If you need a
   79.83 + * <em>closed range</em> (which includes both endpoints), and the key type
   79.84 + * allows for calculation of the successor of a given key, merely request
   79.85 + * the subrange from {@code lowEndpoint} to
   79.86 + * {@code successor(highEndpoint)}.  For example, suppose that {@code m}
   79.87 + * is a map whose keys are strings.  The following idiom obtains a view
   79.88 + * containing all of the key-value mappings in {@code m} whose keys are
   79.89 + * between {@code low} and {@code high}, inclusive:<pre>
   79.90 + *   SortedMap&lt;String, V&gt; sub = m.subMap(low, high+"\0");</pre>
   79.91 + *
   79.92 + * A similar technique can be used to generate an <em>open range</em>
   79.93 + * (which contains neither endpoint).  The following idiom obtains a
   79.94 + * view containing all of the key-value mappings in {@code m} whose keys
   79.95 + * are between {@code low} and {@code high}, exclusive:<pre>
   79.96 + *   SortedMap&lt;String, V&gt; sub = m.subMap(low+"\0", high);</pre>
   79.97 + *
   79.98 + * <p>This interface is a member of the
   79.99 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  79.100 + * Java Collections Framework</a>.
  79.101 + *
  79.102 + * @param <K> the type of keys maintained by this map
  79.103 + * @param <V> the type of mapped values
  79.104 + *
  79.105 + * @author  Josh Bloch
  79.106 + * @see Map
  79.107 + * @see TreeMap
  79.108 + * @see SortedSet
  79.109 + * @see Comparator
  79.110 + * @see Comparable
  79.111 + * @see Collection
  79.112 + * @see ClassCastException
  79.113 + * @since 1.2
  79.114 + */
  79.115 +
  79.116 +public interface SortedMap<K,V> extends Map<K,V> {
  79.117 +    /**
  79.118 +     * Returns the comparator used to order the keys in this map, or
  79.119 +     * {@code null} if this map uses the {@linkplain Comparable
  79.120 +     * natural ordering} of its keys.
  79.121 +     *
  79.122 +     * @return the comparator used to order the keys in this map,
  79.123 +     *         or {@code null} if this map uses the natural ordering
  79.124 +     *         of its keys
  79.125 +     */
  79.126 +    Comparator<? super K> comparator();
  79.127 +
  79.128 +    /**
  79.129 +     * Returns a view of the portion of this map whose keys range from
  79.130 +     * {@code fromKey}, inclusive, to {@code toKey}, exclusive.  (If
  79.131 +     * {@code fromKey} and {@code toKey} are equal, the returned map
  79.132 +     * is empty.)  The returned map is backed by this map, so changes
  79.133 +     * in the returned map are reflected in this map, and vice-versa.
  79.134 +     * The returned map supports all optional map operations that this
  79.135 +     * map supports.
  79.136 +     *
  79.137 +     * <p>The returned map will throw an {@code IllegalArgumentException}
  79.138 +     * on an attempt to insert a key outside its range.
  79.139 +     *
  79.140 +     * @param fromKey low endpoint (inclusive) of the keys in the returned map
  79.141 +     * @param toKey high endpoint (exclusive) of the keys in the returned map
  79.142 +     * @return a view of the portion of this map whose keys range from
  79.143 +     *         {@code fromKey}, inclusive, to {@code toKey}, exclusive
  79.144 +     * @throws ClassCastException if {@code fromKey} and {@code toKey}
  79.145 +     *         cannot be compared to one another using this map's comparator
  79.146 +     *         (or, if the map has no comparator, using natural ordering).
  79.147 +     *         Implementations may, but are not required to, throw this
  79.148 +     *         exception if {@code fromKey} or {@code toKey}
  79.149 +     *         cannot be compared to keys currently in the map.
  79.150 +     * @throws NullPointerException if {@code fromKey} or {@code toKey}
  79.151 +     *         is null and this map does not permit null keys
  79.152 +     * @throws IllegalArgumentException if {@code fromKey} is greater than
  79.153 +     *         {@code toKey}; or if this map itself has a restricted
  79.154 +     *         range, and {@code fromKey} or {@code toKey} lies
  79.155 +     *         outside the bounds of the range
  79.156 +     */
  79.157 +    SortedMap<K,V> subMap(K fromKey, K toKey);
  79.158 +
  79.159 +    /**
  79.160 +     * Returns a view of the portion of this map whose keys are
  79.161 +     * strictly less than {@code toKey}.  The returned map is backed
  79.162 +     * by this map, so changes in the returned map are reflected in
  79.163 +     * this map, and vice-versa.  The returned map supports all
  79.164 +     * optional map operations that this map supports.
  79.165 +     *
  79.166 +     * <p>The returned map will throw an {@code IllegalArgumentException}
  79.167 +     * on an attempt to insert a key outside its range.
  79.168 +     *
  79.169 +     * @param toKey high endpoint (exclusive) of the keys in the returned map
  79.170 +     * @return a view of the portion of this map whose keys are strictly
  79.171 +     *         less than {@code toKey}
  79.172 +     * @throws ClassCastException if {@code toKey} is not compatible
  79.173 +     *         with this map's comparator (or, if the map has no comparator,
  79.174 +     *         if {@code toKey} does not implement {@link Comparable}).
  79.175 +     *         Implementations may, but are not required to, throw this
  79.176 +     *         exception if {@code toKey} cannot be compared to keys
  79.177 +     *         currently in the map.
  79.178 +     * @throws NullPointerException if {@code toKey} is null and
  79.179 +     *         this map does not permit null keys
  79.180 +     * @throws IllegalArgumentException if this map itself has a
  79.181 +     *         restricted range, and {@code toKey} lies outside the
  79.182 +     *         bounds of the range
  79.183 +     */
  79.184 +    SortedMap<K,V> headMap(K toKey);
  79.185 +
  79.186 +    /**
  79.187 +     * Returns a view of the portion of this map whose keys are
  79.188 +     * greater than or equal to {@code fromKey}.  The returned map is
  79.189 +     * backed by this map, so changes in the returned map are
  79.190 +     * reflected in this map, and vice-versa.  The returned map
  79.191 +     * supports all optional map operations that this map supports.
  79.192 +     *
  79.193 +     * <p>The returned map will throw an {@code IllegalArgumentException}
  79.194 +     * on an attempt to insert a key outside its range.
  79.195 +     *
  79.196 +     * @param fromKey low endpoint (inclusive) of the keys in the returned map
  79.197 +     * @return a view of the portion of this map whose keys are greater
  79.198 +     *         than or equal to {@code fromKey}
  79.199 +     * @throws ClassCastException if {@code fromKey} is not compatible
  79.200 +     *         with this map's comparator (or, if the map has no comparator,
  79.201 +     *         if {@code fromKey} does not implement {@link Comparable}).
  79.202 +     *         Implementations may, but are not required to, throw this
  79.203 +     *         exception if {@code fromKey} cannot be compared to keys
  79.204 +     *         currently in the map.
  79.205 +     * @throws NullPointerException if {@code fromKey} is null and
  79.206 +     *         this map does not permit null keys
  79.207 +     * @throws IllegalArgumentException if this map itself has a
  79.208 +     *         restricted range, and {@code fromKey} lies outside the
  79.209 +     *         bounds of the range
  79.210 +     */
  79.211 +    SortedMap<K,V> tailMap(K fromKey);
  79.212 +
  79.213 +    /**
  79.214 +     * Returns the first (lowest) key currently in this map.
  79.215 +     *
  79.216 +     * @return the first (lowest) key currently in this map
  79.217 +     * @throws NoSuchElementException if this map is empty
  79.218 +     */
  79.219 +    K firstKey();
  79.220 +
  79.221 +    /**
  79.222 +     * Returns the last (highest) key currently in this map.
  79.223 +     *
  79.224 +     * @return the last (highest) key currently in this map
  79.225 +     * @throws NoSuchElementException if this map is empty
  79.226 +     */
  79.227 +    K lastKey();
  79.228 +
  79.229 +    /**
  79.230 +     * Returns a {@link Set} view of the keys contained in this map.
  79.231 +     * The set's iterator returns the keys in ascending order.
  79.232 +     * The set is backed by the map, so changes to the map are
  79.233 +     * reflected in the set, and vice-versa.  If the map is modified
  79.234 +     * while an iteration over the set is in progress (except through
  79.235 +     * the iterator's own {@code remove} operation), the results of
  79.236 +     * the iteration are undefined.  The set supports element removal,
  79.237 +     * which removes the corresponding mapping from the map, via the
  79.238 +     * {@code Iterator.remove}, {@code Set.remove},
  79.239 +     * {@code removeAll}, {@code retainAll}, and {@code clear}
  79.240 +     * operations.  It does not support the {@code add} or {@code addAll}
  79.241 +     * operations.
  79.242 +     *
  79.243 +     * @return a set view of the keys contained in this map, sorted in
  79.244 +     *         ascending order
  79.245 +     */
  79.246 +    Set<K> keySet();
  79.247 +
  79.248 +    /**
  79.249 +     * Returns a {@link Collection} view of the values contained in this map.
  79.250 +     * The collection's iterator returns the values in ascending order
  79.251 +     * of the corresponding keys.
  79.252 +     * The collection is backed by the map, so changes to the map are
  79.253 +     * reflected in the collection, and vice-versa.  If the map is
  79.254 +     * modified while an iteration over the collection is in progress
  79.255 +     * (except through the iterator's own {@code remove} operation),
  79.256 +     * the results of the iteration are undefined.  The collection
  79.257 +     * supports element removal, which removes the corresponding
  79.258 +     * mapping from the map, via the {@code Iterator.remove},
  79.259 +     * {@code Collection.remove}, {@code removeAll},
  79.260 +     * {@code retainAll} and {@code clear} operations.  It does not
  79.261 +     * support the {@code add} or {@code addAll} operations.
  79.262 +     *
  79.263 +     * @return a collection view of the values contained in this map,
  79.264 +     *         sorted in ascending key order
  79.265 +     */
  79.266 +    Collection<V> values();
  79.267 +
  79.268 +    /**
  79.269 +     * Returns a {@link Set} view of the mappings contained in this map.
  79.270 +     * The set's iterator returns the entries in ascending key order.
  79.271 +     * The set is backed by the map, so changes to the map are
  79.272 +     * reflected in the set, and vice-versa.  If the map is modified
  79.273 +     * while an iteration over the set is in progress (except through
  79.274 +     * the iterator's own {@code remove} operation, or through the
  79.275 +     * {@code setValue} operation on a map entry returned by the
  79.276 +     * iterator) the results of the iteration are undefined.  The set
  79.277 +     * supports element removal, which removes the corresponding
  79.278 +     * mapping from the map, via the {@code Iterator.remove},
  79.279 +     * {@code Set.remove}, {@code removeAll}, {@code retainAll} and
  79.280 +     * {@code clear} operations.  It does not support the
  79.281 +     * {@code add} or {@code addAll} operations.
  79.282 +     *
  79.283 +     * @return a set view of the mappings contained in this map,
  79.284 +     *         sorted in ascending key order
  79.285 +     */
  79.286 +    Set<Map.Entry<K, V>> entrySet();
  79.287 +}
    80.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    80.2 +++ b/emul/compact/src/main/java/java/util/SortedSet.java	Sun Feb 03 07:48:42 2013 +0100
    80.3 @@ -0,0 +1,222 @@
    80.4 +/*
    80.5 + * Copyright (c) 1998, 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.util;
   80.30 +
   80.31 +/**
   80.32 + * A {@link Set} that further provides a <i>total ordering</i> on its elements.
   80.33 + * The elements are ordered using their {@linkplain Comparable natural
   80.34 + * ordering}, or by a {@link Comparator} typically provided at sorted
   80.35 + * set creation time.  The set's iterator will traverse the set in
   80.36 + * ascending element order. Several additional operations are provided
   80.37 + * to take advantage of the ordering.  (This interface is the set
   80.38 + * analogue of {@link SortedMap}.)
   80.39 + *
   80.40 + * <p>All elements inserted into a sorted set must implement the <tt>Comparable</tt>
   80.41 + * interface (or be accepted by the specified comparator).  Furthermore, all
   80.42 + * such elements must be <i>mutually comparable</i>: <tt>e1.compareTo(e2)</tt>
   80.43 + * (or <tt>comparator.compare(e1, e2)</tt>) must not throw a
   80.44 + * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and <tt>e2</tt> in
   80.45 + * the sorted set.  Attempts to violate this restriction will cause the
   80.46 + * offending method or constructor invocation to throw a
   80.47 + * <tt>ClassCastException</tt>.
   80.48 + *
   80.49 + * <p>Note that the ordering maintained by a sorted set (whether or not an
   80.50 + * explicit comparator is provided) must be <i>consistent with equals</i> if
   80.51 + * the sorted set is to correctly implement the <tt>Set</tt> interface.  (See
   80.52 + * the <tt>Comparable</tt> interface or <tt>Comparator</tt> interface for a
   80.53 + * precise definition of <i>consistent with equals</i>.)  This is so because
   80.54 + * the <tt>Set</tt> interface is defined in terms of the <tt>equals</tt>
   80.55 + * operation, but a sorted set performs all element comparisons using its
   80.56 + * <tt>compareTo</tt> (or <tt>compare</tt>) method, so two elements that are
   80.57 + * deemed equal by this method are, from the standpoint of the sorted set,
   80.58 + * equal.  The behavior of a sorted set <i>is</i> well-defined even if its
   80.59 + * ordering is inconsistent with equals; it just fails to obey the general
   80.60 + * contract of the <tt>Set</tt> interface.
   80.61 + *
   80.62 + * <p>All general-purpose sorted set implementation classes should
   80.63 + * provide four "standard" constructors: 1) A void (no arguments)
   80.64 + * constructor, which creates an empty sorted set sorted according to
   80.65 + * the natural ordering of its elements.  2) A constructor with a
   80.66 + * single argument of type <tt>Comparator</tt>, which creates an empty
   80.67 + * sorted set sorted according to the specified comparator.  3) A
   80.68 + * constructor with a single argument of type <tt>Collection</tt>,
   80.69 + * which creates a new sorted set with the same elements as its
   80.70 + * argument, sorted according to the natural ordering of the elements.
   80.71 + * 4) A constructor with a single argument of type <tt>SortedSet</tt>,
   80.72 + * which creates a new sorted set with the same elements and the same
   80.73 + * ordering as the input sorted set.  There is no way to enforce this
   80.74 + * recommendation, as interfaces cannot contain constructors.
   80.75 + *
   80.76 + * <p>Note: several methods return subsets with restricted ranges.
   80.77 + * Such ranges are <i>half-open</i>, that is, they include their low
   80.78 + * endpoint but not their high endpoint (where applicable).
   80.79 + * If you need a <i>closed range</i> (which includes both endpoints), and
   80.80 + * the element type allows for calculation of the successor of a given
   80.81 + * value, merely request the subrange from <tt>lowEndpoint</tt> to
   80.82 + * <tt>successor(highEndpoint)</tt>.  For example, suppose that <tt>s</tt>
   80.83 + * is a sorted set of strings.  The following idiom obtains a view
   80.84 + * containing all of the strings in <tt>s</tt> from <tt>low</tt> to
   80.85 + * <tt>high</tt>, inclusive:<pre>
   80.86 + *   SortedSet&lt;String&gt; sub = s.subSet(low, high+"\0");</pre>
   80.87 + *
   80.88 + * A similar technique can be used to generate an <i>open range</i> (which
   80.89 + * contains neither endpoint).  The following idiom obtains a view
   80.90 + * containing all of the Strings in <tt>s</tt> from <tt>low</tt> to
   80.91 + * <tt>high</tt>, exclusive:<pre>
   80.92 + *   SortedSet&lt;String&gt; sub = s.subSet(low+"\0", high);</pre>
   80.93 + *
   80.94 + * <p>This interface is a member of the
   80.95 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   80.96 + * Java Collections Framework</a>.
   80.97 + *
   80.98 + * @param <E> the type of elements maintained by this set
   80.99 + *
  80.100 + * @author  Josh Bloch
  80.101 + * @see Set
  80.102 + * @see TreeSet
  80.103 + * @see SortedMap
  80.104 + * @see Collection
  80.105 + * @see Comparable
  80.106 + * @see Comparator
  80.107 + * @see ClassCastException
  80.108 + * @since 1.2
  80.109 + */
  80.110 +
  80.111 +public interface SortedSet<E> extends Set<E> {
  80.112 +    /**
  80.113 +     * Returns the comparator used to order the elements in this set,
  80.114 +     * or <tt>null</tt> if this set uses the {@linkplain Comparable
  80.115 +     * natural ordering} of its elements.
  80.116 +     *
  80.117 +     * @return the comparator used to order the elements in this set,
  80.118 +     *         or <tt>null</tt> if this set uses the natural ordering
  80.119 +     *         of its elements
  80.120 +     */
  80.121 +    Comparator<? super E> comparator();
  80.122 +
  80.123 +    /**
  80.124 +     * Returns a view of the portion of this set whose elements range
  80.125 +     * from <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>,
  80.126 +     * exclusive.  (If <tt>fromElement</tt> and <tt>toElement</tt> are
  80.127 +     * equal, the returned set is empty.)  The returned set is backed
  80.128 +     * by this set, so changes in the returned set are reflected in
  80.129 +     * this set, and vice-versa.  The returned set supports all
  80.130 +     * optional set operations that this set supports.
  80.131 +     *
  80.132 +     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
  80.133 +     * on an attempt to insert an element outside its range.
  80.134 +     *
  80.135 +     * @param fromElement low endpoint (inclusive) of the returned set
  80.136 +     * @param toElement high endpoint (exclusive) of the returned set
  80.137 +     * @return a view of the portion of this set whose elements range from
  80.138 +     *         <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive
  80.139 +     * @throws ClassCastException if <tt>fromElement</tt> and
  80.140 +     *         <tt>toElement</tt> cannot be compared to one another using this
  80.141 +     *         set's comparator (or, if the set has no comparator, using
  80.142 +     *         natural ordering).  Implementations may, but are not required
  80.143 +     *         to, throw this exception if <tt>fromElement</tt> or
  80.144 +     *         <tt>toElement</tt> cannot be compared to elements currently in
  80.145 +     *         the set.
  80.146 +     * @throws NullPointerException if <tt>fromElement</tt> or
  80.147 +     *         <tt>toElement</tt> is null and this set does not permit null
  80.148 +     *         elements
  80.149 +     * @throws IllegalArgumentException if <tt>fromElement</tt> is
  80.150 +     *         greater than <tt>toElement</tt>; or if this set itself
  80.151 +     *         has a restricted range, and <tt>fromElement</tt> or
  80.152 +     *         <tt>toElement</tt> lies outside the bounds of the range
  80.153 +     */
  80.154 +    SortedSet<E> subSet(E fromElement, E toElement);
  80.155 +
  80.156 +    /**
  80.157 +     * Returns a view of the portion of this set whose elements are
  80.158 +     * strictly less than <tt>toElement</tt>.  The returned set is
  80.159 +     * backed by this set, so changes in the returned set are
  80.160 +     * reflected in this set, and vice-versa.  The returned set
  80.161 +     * supports all optional set operations that this set supports.
  80.162 +     *
  80.163 +     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
  80.164 +     * on an attempt to insert an element outside its range.
  80.165 +     *
  80.166 +     * @param toElement high endpoint (exclusive) of the returned set
  80.167 +     * @return a view of the portion of this set whose elements are strictly
  80.168 +     *         less than <tt>toElement</tt>
  80.169 +     * @throws ClassCastException if <tt>toElement</tt> is not compatible
  80.170 +     *         with this set's comparator (or, if the set has no comparator,
  80.171 +     *         if <tt>toElement</tt> does not implement {@link Comparable}).
  80.172 +     *         Implementations may, but are not required to, throw this
  80.173 +     *         exception if <tt>toElement</tt> cannot be compared to elements
  80.174 +     *         currently in the set.
  80.175 +     * @throws NullPointerException if <tt>toElement</tt> is null and
  80.176 +     *         this set does not permit null elements
  80.177 +     * @throws IllegalArgumentException if this set itself has a
  80.178 +     *         restricted range, and <tt>toElement</tt> lies outside the
  80.179 +     *         bounds of the range
  80.180 +     */
  80.181 +    SortedSet<E> headSet(E toElement);
  80.182 +
  80.183 +    /**
  80.184 +     * Returns a view of the portion of this set whose elements are
  80.185 +     * greater than or equal to <tt>fromElement</tt>.  The returned
  80.186 +     * set is backed by this set, so changes in the returned set are
  80.187 +     * reflected in this set, and vice-versa.  The returned set
  80.188 +     * supports all optional set operations that this set supports.
  80.189 +     *
  80.190 +     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
  80.191 +     * on an attempt to insert an element outside its range.
  80.192 +     *
  80.193 +     * @param fromElement low endpoint (inclusive) of the returned set
  80.194 +     * @return a view of the portion of this set whose elements are greater
  80.195 +     *         than or equal to <tt>fromElement</tt>
  80.196 +     * @throws ClassCastException if <tt>fromElement</tt> is not compatible
  80.197 +     *         with this set's comparator (or, if the set has no comparator,
  80.198 +     *         if <tt>fromElement</tt> does not implement {@link Comparable}).
  80.199 +     *         Implementations may, but are not required to, throw this
  80.200 +     *         exception if <tt>fromElement</tt> cannot be compared to elements
  80.201 +     *         currently in the set.
  80.202 +     * @throws NullPointerException if <tt>fromElement</tt> is null
  80.203 +     *         and this set does not permit null elements
  80.204 +     * @throws IllegalArgumentException if this set itself has a
  80.205 +     *         restricted range, and <tt>fromElement</tt> lies outside the
  80.206 +     *         bounds of the range
  80.207 +     */
  80.208 +    SortedSet<E> tailSet(E fromElement);
  80.209 +
  80.210 +    /**
  80.211 +     * Returns the first (lowest) element currently in this set.
  80.212 +     *
  80.213 +     * @return the first (lowest) element currently in this set
  80.214 +     * @throws NoSuchElementException if this set is empty
  80.215 +     */
  80.216 +    E first();
  80.217 +
  80.218 +    /**
  80.219 +     * Returns the last (highest) element currently in this set.
  80.220 +     *
  80.221 +     * @return the last (highest) element currently in this set
  80.222 +     * @throws NoSuchElementException if this set is empty
  80.223 +     */
  80.224 +    E last();
  80.225 +}
    81.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    81.2 +++ b/emul/compact/src/main/java/java/util/Stack.java	Sun Feb 03 07:48:42 2013 +0100
    81.3 @@ -0,0 +1,141 @@
    81.4 +/*
    81.5 + * Copyright (c) 1994, 2010, 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.util;
   81.30 +
   81.31 +/**
   81.32 + * The <code>Stack</code> class represents a last-in-first-out
   81.33 + * (LIFO) stack of objects. It extends class <tt>Vector</tt> with five
   81.34 + * operations that allow a vector to be treated as a stack. The usual
   81.35 + * <tt>push</tt> and <tt>pop</tt> operations are provided, as well as a
   81.36 + * method to <tt>peek</tt> at the top item on the stack, a method to test
   81.37 + * for whether the stack is <tt>empty</tt>, and a method to <tt>search</tt>
   81.38 + * the stack for an item and discover how far it is from the top.
   81.39 + * <p>
   81.40 + * When a stack is first created, it contains no items.
   81.41 + *
   81.42 + * <p>A more complete and consistent set of LIFO stack operations is
   81.43 + * provided by the {@link Deque} interface and its implementations, which
   81.44 + * should be used in preference to this class.  For example:
   81.45 + * <pre>   {@code
   81.46 + *   Deque<Integer> stack = new ArrayDeque<Integer>();}</pre>
   81.47 + *
   81.48 + * @author  Jonathan Payne
   81.49 + * @since   JDK1.0
   81.50 + */
   81.51 +public
   81.52 +class Stack<E> extends Vector<E> {
   81.53 +    /**
   81.54 +     * Creates an empty Stack.
   81.55 +     */
   81.56 +    public Stack() {
   81.57 +    }
   81.58 +
   81.59 +    /**
   81.60 +     * Pushes an item onto the top of this stack. This has exactly
   81.61 +     * the same effect as:
   81.62 +     * <blockquote><pre>
   81.63 +     * addElement(item)</pre></blockquote>
   81.64 +     *
   81.65 +     * @param   item   the item to be pushed onto this stack.
   81.66 +     * @return  the <code>item</code> argument.
   81.67 +     * @see     java.util.Vector#addElement
   81.68 +     */
   81.69 +    public E push(E item) {
   81.70 +        addElement(item);
   81.71 +
   81.72 +        return item;
   81.73 +    }
   81.74 +
   81.75 +    /**
   81.76 +     * Removes the object at the top of this stack and returns that
   81.77 +     * object as the value of this function.
   81.78 +     *
   81.79 +     * @return  The object at the top of this stack (the last item
   81.80 +     *          of the <tt>Vector</tt> object).
   81.81 +     * @throws  EmptyStackException  if this stack is empty.
   81.82 +     */
   81.83 +    public synchronized E pop() {
   81.84 +        E       obj;
   81.85 +        int     len = size();
   81.86 +
   81.87 +        obj = peek();
   81.88 +        removeElementAt(len - 1);
   81.89 +
   81.90 +        return obj;
   81.91 +    }
   81.92 +
   81.93 +    /**
   81.94 +     * Looks at the object at the top of this stack without removing it
   81.95 +     * from the stack.
   81.96 +     *
   81.97 +     * @return  the object at the top of this stack (the last item
   81.98 +     *          of the <tt>Vector</tt> object).
   81.99 +     * @throws  EmptyStackException  if this stack is empty.
  81.100 +     */
  81.101 +    public synchronized E peek() {
  81.102 +        int     len = size();
  81.103 +
  81.104 +        if (len == 0)
  81.105 +            throw new EmptyStackException();
  81.106 +        return elementAt(len - 1);
  81.107 +    }
  81.108 +
  81.109 +    /**
  81.110 +     * Tests if this stack is empty.
  81.111 +     *
  81.112 +     * @return  <code>true</code> if and only if this stack contains
  81.113 +     *          no items; <code>false</code> otherwise.
  81.114 +     */
  81.115 +    public boolean empty() {
  81.116 +        return size() == 0;
  81.117 +    }
  81.118 +
  81.119 +    /**
  81.120 +     * Returns the 1-based position where an object is on this stack.
  81.121 +     * If the object <tt>o</tt> occurs as an item in this stack, this
  81.122 +     * method returns the distance from the top of the stack of the
  81.123 +     * occurrence nearest the top of the stack; the topmost item on the
  81.124 +     * stack is considered to be at distance <tt>1</tt>. The <tt>equals</tt>
  81.125 +     * method is used to compare <tt>o</tt> to the
  81.126 +     * items in this stack.
  81.127 +     *
  81.128 +     * @param   o   the desired object.
  81.129 +     * @return  the 1-based position from the top of the stack where
  81.130 +     *          the object is located; the return value <code>-1</code>
  81.131 +     *          indicates that the object is not on the stack.
  81.132 +     */
  81.133 +    public synchronized int search(Object o) {
  81.134 +        int i = lastIndexOf(o);
  81.135 +
  81.136 +        if (i >= 0) {
  81.137 +            return size() - i;
  81.138 +        }
  81.139 +        return -1;
  81.140 +    }
  81.141 +
  81.142 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
  81.143 +    private static final long serialVersionUID = 1224463164541339165L;
  81.144 +}
    82.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    82.2 +++ b/emul/compact/src/main/java/java/util/StringTokenizer.java	Sun Feb 03 07:48:42 2013 +0100
    82.3 @@ -0,0 +1,431 @@
    82.4 +/*
    82.5 + * Copyright (c) 1994, 2004, 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.util;
   82.30 +
   82.31 +import java.lang.*;
   82.32 +
   82.33 +/**
   82.34 + * The string tokenizer class allows an application to break a
   82.35 + * string into tokens. The tokenization method is much simpler than
   82.36 + * the one used by the <code>StreamTokenizer</code> class. The
   82.37 + * <code>StringTokenizer</code> methods do not distinguish among
   82.38 + * identifiers, numbers, and quoted strings, nor do they recognize
   82.39 + * and skip comments.
   82.40 + * <p>
   82.41 + * The set of delimiters (the characters that separate tokens) may
   82.42 + * be specified either at creation time or on a per-token basis.
   82.43 + * <p>
   82.44 + * An instance of <code>StringTokenizer</code> behaves in one of two
   82.45 + * ways, depending on whether it was created with the
   82.46 + * <code>returnDelims</code> flag having the value <code>true</code>
   82.47 + * or <code>false</code>:
   82.48 + * <ul>
   82.49 + * <li>If the flag is <code>false</code>, delimiter characters serve to
   82.50 + *     separate tokens. A token is a maximal sequence of consecutive
   82.51 + *     characters that are not delimiters.
   82.52 + * <li>If the flag is <code>true</code>, delimiter characters are themselves
   82.53 + *     considered to be tokens. A token is thus either one delimiter
   82.54 + *     character, or a maximal sequence of consecutive characters that are
   82.55 + *     not delimiters.
   82.56 + * </ul><p>
   82.57 + * A <tt>StringTokenizer</tt> object internally maintains a current
   82.58 + * position within the string to be tokenized. Some operations advance this
   82.59 + * current position past the characters processed.<p>
   82.60 + * A token is returned by taking a substring of the string that was used to
   82.61 + * create the <tt>StringTokenizer</tt> object.
   82.62 + * <p>
   82.63 + * The following is one example of the use of the tokenizer. The code:
   82.64 + * <blockquote><pre>
   82.65 + *     StringTokenizer st = new StringTokenizer("this is a test");
   82.66 + *     while (st.hasMoreTokens()) {
   82.67 + *         System.out.println(st.nextToken());
   82.68 + *     }
   82.69 + * </pre></blockquote>
   82.70 + * <p>
   82.71 + * prints the following output:
   82.72 + * <blockquote><pre>
   82.73 + *     this
   82.74 + *     is
   82.75 + *     a
   82.76 + *     test
   82.77 + * </pre></blockquote>
   82.78 + *
   82.79 + * <p>
   82.80 + * <tt>StringTokenizer</tt> is a legacy class that is retained for
   82.81 + * compatibility reasons although its use is discouraged in new code. It is
   82.82 + * recommended that anyone seeking this functionality use the <tt>split</tt>
   82.83 + * method of <tt>String</tt> or the java.util.regex package instead.
   82.84 + * <p>
   82.85 + * The following example illustrates how the <tt>String.split</tt>
   82.86 + * method can be used to break up a string into its basic tokens:
   82.87 + * <blockquote><pre>
   82.88 + *     String[] result = "this is a test".split("\\s");
   82.89 + *     for (int x=0; x&lt;result.length; x++)
   82.90 + *         System.out.println(result[x]);
   82.91 + * </pre></blockquote>
   82.92 + * <p>
   82.93 + * prints the following output:
   82.94 + * <blockquote><pre>
   82.95 + *     this
   82.96 + *     is
   82.97 + *     a
   82.98 + *     test
   82.99 + * </pre></blockquote>
  82.100 + *
  82.101 + * @author  unascribed
  82.102 + * @see     java.io.StreamTokenizer
  82.103 + * @since   JDK1.0
  82.104 + */
  82.105 +public
  82.106 +class StringTokenizer implements Enumeration<Object> {
  82.107 +    private int currentPosition;
  82.108 +    private int newPosition;
  82.109 +    private int maxPosition;
  82.110 +    private String str;
  82.111 +    private String delimiters;
  82.112 +    private boolean retDelims;
  82.113 +    private boolean delimsChanged;
  82.114 +
  82.115 +    /**
  82.116 +     * maxDelimCodePoint stores the value of the delimiter character with the
  82.117 +     * highest value. It is used to optimize the detection of delimiter
  82.118 +     * characters.
  82.119 +     *
  82.120 +     * It is unlikely to provide any optimization benefit in the
  82.121 +     * hasSurrogates case because most string characters will be
  82.122 +     * smaller than the limit, but we keep it so that the two code
  82.123 +     * paths remain similar.
  82.124 +     */
  82.125 +    private int maxDelimCodePoint;
  82.126 +
  82.127 +    /**
  82.128 +     * If delimiters include any surrogates (including surrogate
  82.129 +     * pairs), hasSurrogates is true and the tokenizer uses the
  82.130 +     * different code path. This is because String.indexOf(int)
  82.131 +     * doesn't handle unpaired surrogates as a single character.
  82.132 +     */
  82.133 +    private boolean hasSurrogates = false;
  82.134 +
  82.135 +    /**
  82.136 +     * When hasSurrogates is true, delimiters are converted to code
  82.137 +     * points and isDelimiter(int) is used to determine if the given
  82.138 +     * codepoint is a delimiter.
  82.139 +     */
  82.140 +    private int[] delimiterCodePoints;
  82.141 +
  82.142 +    /**
  82.143 +     * Set maxDelimCodePoint to the highest char in the delimiter set.
  82.144 +     */
  82.145 +    private void setMaxDelimCodePoint() {
  82.146 +        if (delimiters == null) {
  82.147 +            maxDelimCodePoint = 0;
  82.148 +            return;
  82.149 +        }
  82.150 +
  82.151 +        int m = 0;
  82.152 +        int c;
  82.153 +        int count = 0;
  82.154 +        for (int i = 0; i < delimiters.length(); i += Character.charCount(c)) {
  82.155 +            c = delimiters.charAt(i);
  82.156 +            if (c >= Character.MIN_HIGH_SURROGATE && c <= Character.MAX_LOW_SURROGATE) {
  82.157 +                c = delimiters.codePointAt(i);
  82.158 +                hasSurrogates = true;
  82.159 +            }
  82.160 +            if (m < c)
  82.161 +                m = c;
  82.162 +            count++;
  82.163 +        }
  82.164 +        maxDelimCodePoint = m;
  82.165 +
  82.166 +        if (hasSurrogates) {
  82.167 +            delimiterCodePoints = new int[count];
  82.168 +            for (int i = 0, j = 0; i < count; i++, j += Character.charCount(c)) {
  82.169 +                c = delimiters.codePointAt(j);
  82.170 +                delimiterCodePoints[i] = c;
  82.171 +            }
  82.172 +        }
  82.173 +    }
  82.174 +
  82.175 +    /**
  82.176 +     * Constructs a string tokenizer for the specified string. All
  82.177 +     * characters in the <code>delim</code> argument are the delimiters
  82.178 +     * for separating tokens.
  82.179 +     * <p>
  82.180 +     * If the <code>returnDelims</code> flag is <code>true</code>, then
  82.181 +     * the delimiter characters are also returned as tokens. Each
  82.182 +     * delimiter is returned as a string of length one. If the flag is
  82.183 +     * <code>false</code>, the delimiter characters are skipped and only
  82.184 +     * serve as separators between tokens.
  82.185 +     * <p>
  82.186 +     * Note that if <tt>delim</tt> is <tt>null</tt>, this constructor does
  82.187 +     * not throw an exception. However, trying to invoke other methods on the
  82.188 +     * resulting <tt>StringTokenizer</tt> may result in a
  82.189 +     * <tt>NullPointerException</tt>.
  82.190 +     *
  82.191 +     * @param   str            a string to be parsed.
  82.192 +     * @param   delim          the delimiters.
  82.193 +     * @param   returnDelims   flag indicating whether to return the delimiters
  82.194 +     *                         as tokens.
  82.195 +     * @exception NullPointerException if str is <CODE>null</CODE>
  82.196 +     */
  82.197 +    public StringTokenizer(String str, String delim, boolean returnDelims) {
  82.198 +        currentPosition = 0;
  82.199 +        newPosition = -1;
  82.200 +        delimsChanged = false;
  82.201 +        this.str = str;
  82.202 +        maxPosition = str.length();
  82.203 +        delimiters = delim;
  82.204 +        retDelims = returnDelims;
  82.205 +        setMaxDelimCodePoint();
  82.206 +    }
  82.207 +
  82.208 +    /**
  82.209 +     * Constructs a string tokenizer for the specified string. The
  82.210 +     * characters in the <code>delim</code> argument are the delimiters
  82.211 +     * for separating tokens. Delimiter characters themselves will not
  82.212 +     * be treated as tokens.
  82.213 +     * <p>
  82.214 +     * Note that if <tt>delim</tt> is <tt>null</tt>, this constructor does
  82.215 +     * not throw an exception. However, trying to invoke other methods on the
  82.216 +     * resulting <tt>StringTokenizer</tt> may result in a
  82.217 +     * <tt>NullPointerException</tt>.
  82.218 +     *
  82.219 +     * @param   str     a string to be parsed.
  82.220 +     * @param   delim   the delimiters.
  82.221 +     * @exception NullPointerException if str is <CODE>null</CODE>
  82.222 +     */
  82.223 +    public StringTokenizer(String str, String delim) {
  82.224 +        this(str, delim, false);
  82.225 +    }
  82.226 +
  82.227 +    /**
  82.228 +     * Constructs a string tokenizer for the specified string. The
  82.229 +     * tokenizer uses the default delimiter set, which is
  82.230 +     * <code>"&nbsp;&#92;t&#92;n&#92;r&#92;f"</code>: the space character,
  82.231 +     * the tab character, the newline character, the carriage-return character,
  82.232 +     * and the form-feed character. Delimiter characters themselves will
  82.233 +     * not be treated as tokens.
  82.234 +     *
  82.235 +     * @param   str   a string to be parsed.
  82.236 +     * @exception NullPointerException if str is <CODE>null</CODE>
  82.237 +     */
  82.238 +    public StringTokenizer(String str) {
  82.239 +        this(str, " \t\n\r\f", false);
  82.240 +    }
  82.241 +
  82.242 +    /**
  82.243 +     * Skips delimiters starting from the specified position. If retDelims
  82.244 +     * is false, returns the index of the first non-delimiter character at or
  82.245 +     * after startPos. If retDelims is true, startPos is returned.
  82.246 +     */
  82.247 +    private int skipDelimiters(int startPos) {
  82.248 +        if (delimiters == null)
  82.249 +            throw new NullPointerException();
  82.250 +
  82.251 +        int position = startPos;
  82.252 +        while (!retDelims && position < maxPosition) {
  82.253 +            if (!hasSurrogates) {
  82.254 +                char c = str.charAt(position);
  82.255 +                if ((c > maxDelimCodePoint) || (delimiters.indexOf(c) < 0))
  82.256 +                    break;
  82.257 +                position++;
  82.258 +            } else {
  82.259 +                int c = str.codePointAt(position);
  82.260 +                if ((c > maxDelimCodePoint) || !isDelimiter(c)) {
  82.261 +                    break;
  82.262 +                }
  82.263 +                position += Character.charCount(c);
  82.264 +            }
  82.265 +        }
  82.266 +        return position;
  82.267 +    }
  82.268 +
  82.269 +    /**
  82.270 +     * Skips ahead from startPos and returns the index of the next delimiter
  82.271 +     * character encountered, or maxPosition if no such delimiter is found.
  82.272 +     */
  82.273 +    private int scanToken(int startPos) {
  82.274 +        int position = startPos;
  82.275 +        while (position < maxPosition) {
  82.276 +            if (!hasSurrogates) {
  82.277 +                char c = str.charAt(position);
  82.278 +                if ((c <= maxDelimCodePoint) && (delimiters.indexOf(c) >= 0))
  82.279 +                    break;
  82.280 +                position++;
  82.281 +            } else {
  82.282 +                int c = str.codePointAt(position);
  82.283 +                if ((c <= maxDelimCodePoint) && isDelimiter(c))
  82.284 +                    break;
  82.285 +                position += Character.charCount(c);
  82.286 +            }
  82.287 +        }
  82.288 +        if (retDelims && (startPos == position)) {
  82.289 +            if (!hasSurrogates) {
  82.290 +                char c = str.charAt(position);
  82.291 +                if ((c <= maxDelimCodePoint) && (delimiters.indexOf(c) >= 0))
  82.292 +                    position++;
  82.293 +            } else {
  82.294 +                int c = str.codePointAt(position);
  82.295 +                if ((c <= maxDelimCodePoint) && isDelimiter(c))
  82.296 +                    position += Character.charCount(c);
  82.297 +            }
  82.298 +        }
  82.299 +        return position;
  82.300 +    }
  82.301 +
  82.302 +    private boolean isDelimiter(int codePoint) {
  82.303 +        for (int i = 0; i < delimiterCodePoints.length; i++) {
  82.304 +            if (delimiterCodePoints[i] == codePoint) {
  82.305 +                return true;
  82.306 +            }
  82.307 +        }
  82.308 +        return false;
  82.309 +    }
  82.310 +
  82.311 +    /**
  82.312 +     * Tests if there are more tokens available from this tokenizer's string.
  82.313 +     * If this method returns <tt>true</tt>, then a subsequent call to
  82.314 +     * <tt>nextToken</tt> with no argument will successfully return a token.
  82.315 +     *
  82.316 +     * @return  <code>true</code> if and only if there is at least one token
  82.317 +     *          in the string after the current position; <code>false</code>
  82.318 +     *          otherwise.
  82.319 +     */
  82.320 +    public boolean hasMoreTokens() {
  82.321 +        /*
  82.322 +         * Temporarily store this position and use it in the following
  82.323 +         * nextToken() method only if the delimiters haven't been changed in
  82.324 +         * that nextToken() invocation.
  82.325 +         */
  82.326 +        newPosition = skipDelimiters(currentPosition);
  82.327 +        return (newPosition < maxPosition);
  82.328 +    }
  82.329 +
  82.330 +    /**
  82.331 +     * Returns the next token from this string tokenizer.
  82.332 +     *
  82.333 +     * @return     the next token from this string tokenizer.
  82.334 +     * @exception  NoSuchElementException  if there are no more tokens in this
  82.335 +     *               tokenizer's string.
  82.336 +     */
  82.337 +    public String nextToken() {
  82.338 +        /*
  82.339 +         * If next position already computed in hasMoreElements() and
  82.340 +         * delimiters have changed between the computation and this invocation,
  82.341 +         * then use the computed value.
  82.342 +         */
  82.343 +
  82.344 +        currentPosition = (newPosition >= 0 && !delimsChanged) ?
  82.345 +            newPosition : skipDelimiters(currentPosition);
  82.346 +
  82.347 +        /* Reset these anyway */
  82.348 +        delimsChanged = false;
  82.349 +        newPosition = -1;
  82.350 +
  82.351 +        if (currentPosition >= maxPosition)
  82.352 +            throw new NoSuchElementException();
  82.353 +        int start = currentPosition;
  82.354 +        currentPosition = scanToken(currentPosition);
  82.355 +        return str.substring(start, currentPosition);
  82.356 +    }
  82.357 +
  82.358 +    /**
  82.359 +     * Returns the next token in this string tokenizer's string. First,
  82.360 +     * the set of characters considered to be delimiters by this
  82.361 +     * <tt>StringTokenizer</tt> object is changed to be the characters in
  82.362 +     * the string <tt>delim</tt>. Then the next token in the string
  82.363 +     * after the current position is returned. The current position is
  82.364 +     * advanced beyond the recognized token.  The new delimiter set
  82.365 +     * remains the default after this call.
  82.366 +     *
  82.367 +     * @param      delim   the new delimiters.
  82.368 +     * @return     the next token, after switching to the new delimiter set.
  82.369 +     * @exception  NoSuchElementException  if there are no more tokens in this
  82.370 +     *               tokenizer's string.
  82.371 +     * @exception NullPointerException if delim is <CODE>null</CODE>
  82.372 +     */
  82.373 +    public String nextToken(String delim) {
  82.374 +        delimiters = delim;
  82.375 +
  82.376 +        /* delimiter string specified, so set the appropriate flag. */
  82.377 +        delimsChanged = true;
  82.378 +
  82.379 +        setMaxDelimCodePoint();
  82.380 +        return nextToken();
  82.381 +    }
  82.382 +
  82.383 +    /**
  82.384 +     * Returns the same value as the <code>hasMoreTokens</code>
  82.385 +     * method. It exists so that this class can implement the
  82.386 +     * <code>Enumeration</code> interface.
  82.387 +     *
  82.388 +     * @return  <code>true</code> if there are more tokens;
  82.389 +     *          <code>false</code> otherwise.
  82.390 +     * @see     java.util.Enumeration
  82.391 +     * @see     java.util.StringTokenizer#hasMoreTokens()
  82.392 +     */
  82.393 +    public boolean hasMoreElements() {
  82.394 +        return hasMoreTokens();
  82.395 +    }
  82.396 +
  82.397 +    /**
  82.398 +     * Returns the same value as the <code>nextToken</code> method,
  82.399 +     * except that its declared return value is <code>Object</code> rather than
  82.400 +     * <code>String</code>. It exists so that this class can implement the
  82.401 +     * <code>Enumeration</code> interface.
  82.402 +     *
  82.403 +     * @return     the next token in the string.
  82.404 +     * @exception  NoSuchElementException  if there are no more tokens in this
  82.405 +     *               tokenizer's string.
  82.406 +     * @see        java.util.Enumeration
  82.407 +     * @see        java.util.StringTokenizer#nextToken()
  82.408 +     */
  82.409 +    public Object nextElement() {
  82.410 +        return nextToken();
  82.411 +    }
  82.412 +
  82.413 +    /**
  82.414 +     * Calculates the number of times that this tokenizer's
  82.415 +     * <code>nextToken</code> method can be called before it generates an
  82.416 +     * exception. The current position is not advanced.
  82.417 +     *
  82.418 +     * @return  the number of tokens remaining in the string using the current
  82.419 +     *          delimiter set.
  82.420 +     * @see     java.util.StringTokenizer#nextToken()
  82.421 +     */
  82.422 +    public int countTokens() {
  82.423 +        int count = 0;
  82.424 +        int currpos = currentPosition;
  82.425 +        while (currpos < maxPosition) {
  82.426 +            currpos = skipDelimiters(currpos);
  82.427 +            if (currpos >= maxPosition)
  82.428 +                break;
  82.429 +            currpos = scanToken(currpos);
  82.430 +            count++;
  82.431 +        }
  82.432 +        return count;
  82.433 +    }
  82.434 +}
    83.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    83.2 +++ b/emul/compact/src/main/java/java/util/TimSort.java	Sun Feb 03 07:48:42 2013 +0100
    83.3 @@ -0,0 +1,929 @@
    83.4 +/*
    83.5 + * Copyright 2009 Google Inc.  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.util;
   83.30 +
   83.31 +
   83.32 +/**
   83.33 + * A stable, adaptive, iterative mergesort that requires far fewer than
   83.34 + * n lg(n) comparisons when running on partially sorted arrays, while
   83.35 + * offering performance comparable to a traditional mergesort when run
   83.36 + * on random arrays.  Like all proper mergesorts, this sort is stable and
   83.37 + * runs O(n log n) time (worst case).  In the worst case, this sort requires
   83.38 + * temporary storage space for n/2 object references; in the best case,
   83.39 + * it requires only a small constant amount of space.
   83.40 + *
   83.41 + * This implementation was adapted from Tim Peters's list sort for
   83.42 + * Python, which is described in detail here:
   83.43 + *
   83.44 + *   http://svn.python.org/projects/python/trunk/Objects/listsort.txt
   83.45 + *
   83.46 + * Tim's C code may be found here:
   83.47 + *
   83.48 + *   http://svn.python.org/projects/python/trunk/Objects/listobject.c
   83.49 + *
   83.50 + * The underlying techniques are described in this paper (and may have
   83.51 + * even earlier origins):
   83.52 + *
   83.53 + *  "Optimistic Sorting and Information Theoretic Complexity"
   83.54 + *  Peter McIlroy
   83.55 + *  SODA (Fourth Annual ACM-SIAM Symposium on Discrete Algorithms),
   83.56 + *  pp 467-474, Austin, Texas, 25-27 January 1993.
   83.57 + *
   83.58 + * While the API to this class consists solely of static methods, it is
   83.59 + * (privately) instantiable; a TimSort instance holds the state of an ongoing
   83.60 + * sort, assuming the input array is large enough to warrant the full-blown
   83.61 + * TimSort. Small arrays are sorted in place, using a binary insertion sort.
   83.62 + *
   83.63 + * @author Josh Bloch
   83.64 + */
   83.65 +class TimSort<T> {
   83.66 +    /**
   83.67 +     * This is the minimum sized sequence that will be merged.  Shorter
   83.68 +     * sequences will be lengthened by calling binarySort.  If the entire
   83.69 +     * array is less than this length, no merges will be performed.
   83.70 +     *
   83.71 +     * This constant should be a power of two.  It was 64 in Tim Peter's C
   83.72 +     * implementation, but 32 was empirically determined to work better in
   83.73 +     * this implementation.  In the unlikely event that you set this constant
   83.74 +     * to be a number that's not a power of two, you'll need to change the
   83.75 +     * {@link #minRunLength} computation.
   83.76 +     *
   83.77 +     * If you decrease this constant, you must change the stackLen
   83.78 +     * computation in the TimSort constructor, or you risk an
   83.79 +     * ArrayOutOfBounds exception.  See listsort.txt for a discussion
   83.80 +     * of the minimum stack length required as a function of the length
   83.81 +     * of the array being sorted and the minimum merge sequence length.
   83.82 +     */
   83.83 +    private static final int MIN_MERGE = 32;
   83.84 +
   83.85 +    /**
   83.86 +     * The array being sorted.
   83.87 +     */
   83.88 +    private final T[] a;
   83.89 +
   83.90 +    /**
   83.91 +     * The comparator for this sort.
   83.92 +     */
   83.93 +    private final Comparator<? super T> c;
   83.94 +
   83.95 +    /**
   83.96 +     * When we get into galloping mode, we stay there until both runs win less
   83.97 +     * often than MIN_GALLOP consecutive times.
   83.98 +     */
   83.99 +    private static final int  MIN_GALLOP = 7;
  83.100 +
  83.101 +    /**
  83.102 +     * This controls when we get *into* galloping mode.  It is initialized
  83.103 +     * to MIN_GALLOP.  The mergeLo and mergeHi methods nudge it higher for
  83.104 +     * random data, and lower for highly structured data.
  83.105 +     */
  83.106 +    private int minGallop = MIN_GALLOP;
  83.107 +
  83.108 +    /**
  83.109 +     * Maximum initial size of tmp array, which is used for merging.  The array
  83.110 +     * can grow to accommodate demand.
  83.111 +     *
  83.112 +     * Unlike Tim's original C version, we do not allocate this much storage
  83.113 +     * when sorting smaller arrays.  This change was required for performance.
  83.114 +     */
  83.115 +    private static final int INITIAL_TMP_STORAGE_LENGTH = 256;
  83.116 +
  83.117 +    /**
  83.118 +     * Temp storage for merges.
  83.119 +     */
  83.120 +    private T[] tmp; // Actual runtime type will be Object[], regardless of T
  83.121 +
  83.122 +    /**
  83.123 +     * A stack of pending runs yet to be merged.  Run i starts at
  83.124 +     * address base[i] and extends for len[i] elements.  It's always
  83.125 +     * true (so long as the indices are in bounds) that:
  83.126 +     *
  83.127 +     *     runBase[i] + runLen[i] == runBase[i + 1]
  83.128 +     *
  83.129 +     * so we could cut the storage for this, but it's a minor amount,
  83.130 +     * and keeping all the info explicit simplifies the code.
  83.131 +     */
  83.132 +    private int stackSize = 0;  // Number of pending runs on stack
  83.133 +    private final int[] runBase;
  83.134 +    private final int[] runLen;
  83.135 +
  83.136 +    /**
  83.137 +     * Creates a TimSort instance to maintain the state of an ongoing sort.
  83.138 +     *
  83.139 +     * @param a the array to be sorted
  83.140 +     * @param c the comparator to determine the order of the sort
  83.141 +     */
  83.142 +    private TimSort(T[] a, Comparator<? super T> c) {
  83.143 +        this.a = a;
  83.144 +        this.c = c;
  83.145 +
  83.146 +        // Allocate temp storage (which may be increased later if necessary)
  83.147 +        int len = a.length;
  83.148 +        @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
  83.149 +        T[] newArray = (T[]) new Object[len < 2 * INITIAL_TMP_STORAGE_LENGTH ?
  83.150 +                                        len >>> 1 : INITIAL_TMP_STORAGE_LENGTH];
  83.151 +        tmp = newArray;
  83.152 +
  83.153 +        /*
  83.154 +         * Allocate runs-to-be-merged stack (which cannot be expanded).  The
  83.155 +         * stack length requirements are described in listsort.txt.  The C
  83.156 +         * version always uses the same stack length (85), but this was
  83.157 +         * measured to be too expensive when sorting "mid-sized" arrays (e.g.,
  83.158 +         * 100 elements) in Java.  Therefore, we use smaller (but sufficiently
  83.159 +         * large) stack lengths for smaller arrays.  The "magic numbers" in the
  83.160 +         * computation below must be changed if MIN_MERGE is decreased.  See
  83.161 +         * the MIN_MERGE declaration above for more information.
  83.162 +         */
  83.163 +        int stackLen = (len <    120  ?  5 :
  83.164 +                        len <   1542  ? 10 :
  83.165 +                        len < 119151  ? 19 : 40);
  83.166 +        runBase = new int[stackLen];
  83.167 +        runLen = new int[stackLen];
  83.168 +    }
  83.169 +
  83.170 +    /*
  83.171 +     * The next two methods (which are package private and static) constitute
  83.172 +     * the entire API of this class.  Each of these methods obeys the contract
  83.173 +     * of the public method with the same signature in java.util.Arrays.
  83.174 +     */
  83.175 +
  83.176 +    static <T> void sort(T[] a, Comparator<? super T> c) {
  83.177 +        sort(a, 0, a.length, c);
  83.178 +    }
  83.179 +
  83.180 +    static <T> void sort(T[] a, int lo, int hi, Comparator<? super T> c) {
  83.181 +        if (c == null) {
  83.182 +            Arrays.sort(a, lo, hi);
  83.183 +            return;
  83.184 +        }
  83.185 +
  83.186 +        rangeCheck(a.length, lo, hi);
  83.187 +        int nRemaining  = hi - lo;
  83.188 +        if (nRemaining < 2)
  83.189 +            return;  // Arrays of size 0 and 1 are always sorted
  83.190 +
  83.191 +        // If array is small, do a "mini-TimSort" with no merges
  83.192 +        if (nRemaining < MIN_MERGE) {
  83.193 +            int initRunLen = countRunAndMakeAscending(a, lo, hi, c);
  83.194 +            binarySort(a, lo, hi, lo + initRunLen, c);
  83.195 +            return;
  83.196 +        }
  83.197 +
  83.198 +        /**
  83.199 +         * March over the array once, left to right, finding natural runs,
  83.200 +         * extending short natural runs to minRun elements, and merging runs
  83.201 +         * to maintain stack invariant.
  83.202 +         */
  83.203 +        TimSort<T> ts = new TimSort<>(a, c);
  83.204 +        int minRun = minRunLength(nRemaining);
  83.205 +        do {
  83.206 +            // Identify next run
  83.207 +            int runLen = countRunAndMakeAscending(a, lo, hi, c);
  83.208 +
  83.209 +            // If run is short, extend to min(minRun, nRemaining)
  83.210 +            if (runLen < minRun) {
  83.211 +                int force = nRemaining <= minRun ? nRemaining : minRun;
  83.212 +                binarySort(a, lo, lo + force, lo + runLen, c);
  83.213 +                runLen = force;
  83.214 +            }
  83.215 +
  83.216 +            // Push run onto pending-run stack, and maybe merge
  83.217 +            ts.pushRun(lo, runLen);
  83.218 +            ts.mergeCollapse();
  83.219 +
  83.220 +            // Advance to find next run
  83.221 +            lo += runLen;
  83.222 +            nRemaining -= runLen;
  83.223 +        } while (nRemaining != 0);
  83.224 +
  83.225 +        // Merge all remaining runs to complete sort
  83.226 +        assert lo == hi;
  83.227 +        ts.mergeForceCollapse();
  83.228 +        assert ts.stackSize == 1;
  83.229 +    }
  83.230 +
  83.231 +    /**
  83.232 +     * Sorts the specified portion of the specified array using a binary
  83.233 +     * insertion sort.  This is the best method for sorting small numbers
  83.234 +     * of elements.  It requires O(n log n) compares, but O(n^2) data
  83.235 +     * movement (worst case).
  83.236 +     *
  83.237 +     * If the initial part of the specified range is already sorted,
  83.238 +     * this method can take advantage of it: the method assumes that the
  83.239 +     * elements from index {@code lo}, inclusive, to {@code start},
  83.240 +     * exclusive are already sorted.
  83.241 +     *
  83.242 +     * @param a the array in which a range is to be sorted
  83.243 +     * @param lo the index of the first element in the range to be sorted
  83.244 +     * @param hi the index after the last element in the range to be sorted
  83.245 +     * @param start the index of the first element in the range that is
  83.246 +     *        not already known to be sorted ({@code lo <= start <= hi})
  83.247 +     * @param c comparator to used for the sort
  83.248 +     */
  83.249 +    @SuppressWarnings("fallthrough")
  83.250 +    private static <T> void binarySort(T[] a, int lo, int hi, int start,
  83.251 +                                       Comparator<? super T> c) {
  83.252 +        assert lo <= start && start <= hi;
  83.253 +        if (start == lo)
  83.254 +            start++;
  83.255 +        for ( ; start < hi; start++) {
  83.256 +            T pivot = a[start];
  83.257 +
  83.258 +            // Set left (and right) to the index where a[start] (pivot) belongs
  83.259 +            int left = lo;
  83.260 +            int right = start;
  83.261 +            assert left <= right;
  83.262 +            /*
  83.263 +             * Invariants:
  83.264 +             *   pivot >= all in [lo, left).
  83.265 +             *   pivot <  all in [right, start).
  83.266 +             */
  83.267 +            while (left < right) {
  83.268 +                int mid = (left + right) >>> 1;
  83.269 +                if (c.compare(pivot, a[mid]) < 0)
  83.270 +                    right = mid;
  83.271 +                else
  83.272 +                    left = mid + 1;
  83.273 +            }
  83.274 +            assert left == right;
  83.275 +
  83.276 +            /*
  83.277 +             * The invariants still hold: pivot >= all in [lo, left) and
  83.278 +             * pivot < all in [left, start), so pivot belongs at left.  Note
  83.279 +             * that if there are elements equal to pivot, left points to the
  83.280 +             * first slot after them -- that's why this sort is stable.
  83.281 +             * Slide elements over to make room for pivot.
  83.282 +             */
  83.283 +            int n = start - left;  // The number of elements to move
  83.284 +            // Switch is just an optimization for arraycopy in default case
  83.285 +            switch (n) {
  83.286 +                case 2:  a[left + 2] = a[left + 1];
  83.287 +                case 1:  a[left + 1] = a[left];
  83.288 +                         break;
  83.289 +                default: System.arraycopy(a, left, a, left + 1, n);
  83.290 +            }
  83.291 +            a[left] = pivot;
  83.292 +        }
  83.293 +    }
  83.294 +
  83.295 +    /**
  83.296 +     * Returns the length of the run beginning at the specified position in
  83.297 +     * the specified array and reverses the run if it is descending (ensuring
  83.298 +     * that the run will always be ascending when the method returns).
  83.299 +     *
  83.300 +     * A run is the longest ascending sequence with:
  83.301 +     *
  83.302 +     *    a[lo] <= a[lo + 1] <= a[lo + 2] <= ...
  83.303 +     *
  83.304 +     * or the longest descending sequence with:
  83.305 +     *
  83.306 +     *    a[lo] >  a[lo + 1] >  a[lo + 2] >  ...
  83.307 +     *
  83.308 +     * For its intended use in a stable mergesort, the strictness of the
  83.309 +     * definition of "descending" is needed so that the call can safely
  83.310 +     * reverse a descending sequence without violating stability.
  83.311 +     *
  83.312 +     * @param a the array in which a run is to be counted and possibly reversed
  83.313 +     * @param lo index of the first element in the run
  83.314 +     * @param hi index after the last element that may be contained in the run.
  83.315 +              It is required that {@code lo < hi}.
  83.316 +     * @param c the comparator to used for the sort
  83.317 +     * @return  the length of the run beginning at the specified position in
  83.318 +     *          the specified array
  83.319 +     */
  83.320 +    private static <T> int countRunAndMakeAscending(T[] a, int lo, int hi,
  83.321 +                                                    Comparator<? super T> c) {
  83.322 +        assert lo < hi;
  83.323 +        int runHi = lo + 1;
  83.324 +        if (runHi == hi)
  83.325 +            return 1;
  83.326 +
  83.327 +        // Find end of run, and reverse range if descending
  83.328 +        if (c.compare(a[runHi++], a[lo]) < 0) { // Descending
  83.329 +            while (runHi < hi && c.compare(a[runHi], a[runHi - 1]) < 0)
  83.330 +                runHi++;
  83.331 +            reverseRange(a, lo, runHi);
  83.332 +        } else {                              // Ascending
  83.333 +            while (runHi < hi && c.compare(a[runHi], a[runHi - 1]) >= 0)
  83.334 +                runHi++;
  83.335 +        }
  83.336 +
  83.337 +        return runHi - lo;
  83.338 +    }
  83.339 +
  83.340 +    /**
  83.341 +     * Reverse the specified range of the specified array.
  83.342 +     *
  83.343 +     * @param a the array in which a range is to be reversed
  83.344 +     * @param lo the index of the first element in the range to be reversed
  83.345 +     * @param hi the index after the last element in the range to be reversed
  83.346 +     */
  83.347 +    private static void reverseRange(Object[] a, int lo, int hi) {
  83.348 +        hi--;
  83.349 +        while (lo < hi) {
  83.350 +            Object t = a[lo];
  83.351 +            a[lo++] = a[hi];
  83.352 +            a[hi--] = t;
  83.353 +        }
  83.354 +    }
  83.355 +
  83.356 +    /**
  83.357 +     * Returns the minimum acceptable run length for an array of the specified
  83.358 +     * length. Natural runs shorter than this will be extended with
  83.359 +     * {@link #binarySort}.
  83.360 +     *
  83.361 +     * Roughly speaking, the computation is:
  83.362 +     *
  83.363 +     *  If n < MIN_MERGE, return n (it's too small to bother with fancy stuff).
  83.364 +     *  Else if n is an exact power of 2, return MIN_MERGE/2.
  83.365 +     *  Else return an int k, MIN_MERGE/2 <= k <= MIN_MERGE, such that n/k
  83.366 +     *   is close to, but strictly less than, an exact power of 2.
  83.367 +     *
  83.368 +     * For the rationale, see listsort.txt.
  83.369 +     *
  83.370 +     * @param n the length of the array to be sorted
  83.371 +     * @return the length of the minimum run to be merged
  83.372 +     */
  83.373 +    private static int minRunLength(int n) {
  83.374 +        assert n >= 0;
  83.375 +        int r = 0;      // Becomes 1 if any 1 bits are shifted off
  83.376 +        while (n >= MIN_MERGE) {
  83.377 +            r |= (n & 1);
  83.378 +            n >>= 1;
  83.379 +        }
  83.380 +        return n + r;
  83.381 +    }
  83.382 +
  83.383 +    /**
  83.384 +     * Pushes the specified run onto the pending-run stack.
  83.385 +     *
  83.386 +     * @param runBase index of the first element in the run
  83.387 +     * @param runLen  the number of elements in the run
  83.388 +     */
  83.389 +    private void pushRun(int runBase, int runLen) {
  83.390 +        this.runBase[stackSize] = runBase;
  83.391 +        this.runLen[stackSize] = runLen;
  83.392 +        stackSize++;
  83.393 +    }
  83.394 +
  83.395 +    /**
  83.396 +     * Examines the stack of runs waiting to be merged and merges adjacent runs
  83.397 +     * until the stack invariants are reestablished:
  83.398 +     *
  83.399 +     *     1. runLen[i - 3] > runLen[i - 2] + runLen[i - 1]
  83.400 +     *     2. runLen[i - 2] > runLen[i - 1]
  83.401 +     *
  83.402 +     * This method is called each time a new run is pushed onto the stack,
  83.403 +     * so the invariants are guaranteed to hold for i < stackSize upon
  83.404 +     * entry to the method.
  83.405 +     */
  83.406 +    private void mergeCollapse() {
  83.407 +        while (stackSize > 1) {
  83.408 +            int n = stackSize - 2;
  83.409 +            if (n > 0 && runLen[n-1] <= runLen[n] + runLen[n+1]) {
  83.410 +                if (runLen[n - 1] < runLen[n + 1])
  83.411 +                    n--;
  83.412 +                mergeAt(n);
  83.413 +            } else if (runLen[n] <= runLen[n + 1]) {
  83.414 +                mergeAt(n);
  83.415 +            } else {
  83.416 +                break; // Invariant is established
  83.417 +            }
  83.418 +        }
  83.419 +    }
  83.420 +
  83.421 +    /**
  83.422 +     * Merges all runs on the stack until only one remains.  This method is
  83.423 +     * called once, to complete the sort.
  83.424 +     */
  83.425 +    private void mergeForceCollapse() {
  83.426 +        while (stackSize > 1) {
  83.427 +            int n = stackSize - 2;
  83.428 +            if (n > 0 && runLen[n - 1] < runLen[n + 1])
  83.429 +                n--;
  83.430 +            mergeAt(n);
  83.431 +        }
  83.432 +    }
  83.433 +
  83.434 +    /**
  83.435 +     * Merges the two runs at stack indices i and i+1.  Run i must be
  83.436 +     * the penultimate or antepenultimate run on the stack.  In other words,
  83.437 +     * i must be equal to stackSize-2 or stackSize-3.
  83.438 +     *
  83.439 +     * @param i stack index of the first of the two runs to merge
  83.440 +     */
  83.441 +    private void mergeAt(int i) {
  83.442 +        assert stackSize >= 2;
  83.443 +        assert i >= 0;
  83.444 +        assert i == stackSize - 2 || i == stackSize - 3;
  83.445 +
  83.446 +        int base1 = runBase[i];
  83.447 +        int len1 = runLen[i];
  83.448 +        int base2 = runBase[i + 1];
  83.449 +        int len2 = runLen[i + 1];
  83.450 +        assert len1 > 0 && len2 > 0;
  83.451 +        assert base1 + len1 == base2;
  83.452 +
  83.453 +        /*
  83.454 +         * Record the length of the combined runs; if i is the 3rd-last
  83.455 +         * run now, also slide over the last run (which isn't involved
  83.456 +         * in this merge).  The current run (i+1) goes away in any case.
  83.457 +         */
  83.458 +        runLen[i] = len1 + len2;
  83.459 +        if (i == stackSize - 3) {
  83.460 +            runBase[i + 1] = runBase[i + 2];
  83.461 +            runLen[i + 1] = runLen[i + 2];
  83.462 +        }
  83.463 +        stackSize--;
  83.464 +
  83.465 +        /*
  83.466 +         * Find where the first element of run2 goes in run1. Prior elements
  83.467 +         * in run1 can be ignored (because they're already in place).
  83.468 +         */
  83.469 +        int k = gallopRight(a[base2], a, base1, len1, 0, c);
  83.470 +        assert k >= 0;
  83.471 +        base1 += k;
  83.472 +        len1 -= k;
  83.473 +        if (len1 == 0)
  83.474 +            return;
  83.475 +
  83.476 +        /*
  83.477 +         * Find where the last element of run1 goes in run2. Subsequent elements
  83.478 +         * in run2 can be ignored (because they're already in place).
  83.479 +         */
  83.480 +        len2 = gallopLeft(a[base1 + len1 - 1], a, base2, len2, len2 - 1, c);
  83.481 +        assert len2 >= 0;
  83.482 +        if (len2 == 0)
  83.483 +            return;
  83.484 +
  83.485 +        // Merge remaining runs, using tmp array with min(len1, len2) elements
  83.486 +        if (len1 <= len2)
  83.487 +            mergeLo(base1, len1, base2, len2);
  83.488 +        else
  83.489 +            mergeHi(base1, len1, base2, len2);
  83.490 +    }
  83.491 +
  83.492 +    /**
  83.493 +     * Locates the position at which to insert the specified key into the
  83.494 +     * specified sorted range; if the range contains an element equal to key,
  83.495 +     * returns the index of the leftmost equal element.
  83.496 +     *
  83.497 +     * @param key the key whose insertion point to search for
  83.498 +     * @param a the array in which to search
  83.499 +     * @param base the index of the first element in the range
  83.500 +     * @param len the length of the range; must be > 0
  83.501 +     * @param hint the index at which to begin the search, 0 <= hint < n.
  83.502 +     *     The closer hint is to the result, the faster this method will run.
  83.503 +     * @param c the comparator used to order the range, and to search
  83.504 +     * @return the int k,  0 <= k <= n such that a[b + k - 1] < key <= a[b + k],
  83.505 +     *    pretending that a[b - 1] is minus infinity and a[b + n] is infinity.
  83.506 +     *    In other words, key belongs at index b + k; or in other words,
  83.507 +     *    the first k elements of a should precede key, and the last n - k
  83.508 +     *    should follow it.
  83.509 +     */
  83.510 +    private static <T> int gallopLeft(T key, T[] a, int base, int len, int hint,
  83.511 +                                      Comparator<? super T> c) {
  83.512 +        assert len > 0 && hint >= 0 && hint < len;
  83.513 +        int lastOfs = 0;
  83.514 +        int ofs = 1;
  83.515 +        if (c.compare(key, a[base + hint]) > 0) {
  83.516 +            // Gallop right until a[base+hint+lastOfs] < key <= a[base+hint+ofs]
  83.517 +            int maxOfs = len - hint;
  83.518 +            while (ofs < maxOfs && c.compare(key, a[base + hint + ofs]) > 0) {
  83.519 +                lastOfs = ofs;
  83.520 +                ofs = (ofs << 1) + 1;
  83.521 +                if (ofs <= 0)   // int overflow
  83.522 +                    ofs = maxOfs;
  83.523 +            }
  83.524 +            if (ofs > maxOfs)
  83.525 +                ofs = maxOfs;
  83.526 +
  83.527 +            // Make offsets relative to base
  83.528 +            lastOfs += hint;
  83.529 +            ofs += hint;
  83.530 +        } else { // key <= a[base + hint]
  83.531 +            // Gallop left until a[base+hint-ofs] < key <= a[base+hint-lastOfs]
  83.532 +            final int maxOfs = hint + 1;
  83.533 +            while (ofs < maxOfs && c.compare(key, a[base + hint - ofs]) <= 0) {
  83.534 +                lastOfs = ofs;
  83.535 +                ofs = (ofs << 1) + 1;
  83.536 +                if (ofs <= 0)   // int overflow
  83.537 +                    ofs = maxOfs;
  83.538 +            }
  83.539 +            if (ofs > maxOfs)
  83.540 +                ofs = maxOfs;
  83.541 +
  83.542 +            // Make offsets relative to base
  83.543 +            int tmp = lastOfs;
  83.544 +            lastOfs = hint - ofs;
  83.545 +            ofs = hint - tmp;
  83.546 +        }
  83.547 +        assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
  83.548 +
  83.549 +        /*
  83.550 +         * Now a[base+lastOfs] < key <= a[base+ofs], so key belongs somewhere
  83.551 +         * to the right of lastOfs but no farther right than ofs.  Do a binary
  83.552 +         * search, with invariant a[base + lastOfs - 1] < key <= a[base + ofs].
  83.553 +         */
  83.554 +        lastOfs++;
  83.555 +        while (lastOfs < ofs) {
  83.556 +            int m = lastOfs + ((ofs - lastOfs) >>> 1);
  83.557 +
  83.558 +            if (c.compare(key, a[base + m]) > 0)
  83.559 +                lastOfs = m + 1;  // a[base + m] < key
  83.560 +            else
  83.561 +                ofs = m;          // key <= a[base + m]
  83.562 +        }
  83.563 +        assert lastOfs == ofs;    // so a[base + ofs - 1] < key <= a[base + ofs]
  83.564 +        return ofs;
  83.565 +    }
  83.566 +
  83.567 +    /**
  83.568 +     * Like gallopLeft, except that if the range contains an element equal to
  83.569 +     * key, gallopRight returns the index after the rightmost equal element.
  83.570 +     *
  83.571 +     * @param key the key whose insertion point to search for
  83.572 +     * @param a the array in which to search
  83.573 +     * @param base the index of the first element in the range
  83.574 +     * @param len the length of the range; must be > 0
  83.575 +     * @param hint the index at which to begin the search, 0 <= hint < n.
  83.576 +     *     The closer hint is to the result, the faster this method will run.
  83.577 +     * @param c the comparator used to order the range, and to search
  83.578 +     * @return the int k,  0 <= k <= n such that a[b + k - 1] <= key < a[b + k]
  83.579 +     */
  83.580 +    private static <T> int gallopRight(T key, T[] a, int base, int len,
  83.581 +                                       int hint, Comparator<? super T> c) {
  83.582 +        assert len > 0 && hint >= 0 && hint < len;
  83.583 +
  83.584 +        int ofs = 1;
  83.585 +        int lastOfs = 0;
  83.586 +        if (c.compare(key, a[base + hint]) < 0) {
  83.587 +            // Gallop left until a[b+hint - ofs] <= key < a[b+hint - lastOfs]
  83.588 +            int maxOfs = hint + 1;
  83.589 +            while (ofs < maxOfs && c.compare(key, a[base + hint - ofs]) < 0) {
  83.590 +                lastOfs = ofs;
  83.591 +                ofs = (ofs << 1) + 1;
  83.592 +                if (ofs <= 0)   // int overflow
  83.593 +                    ofs = maxOfs;
  83.594 +            }
  83.595 +            if (ofs > maxOfs)
  83.596 +                ofs = maxOfs;
  83.597 +
  83.598 +            // Make offsets relative to b
  83.599 +            int tmp = lastOfs;
  83.600 +            lastOfs = hint - ofs;
  83.601 +            ofs = hint - tmp;
  83.602 +        } else { // a[b + hint] <= key
  83.603 +            // Gallop right until a[b+hint + lastOfs] <= key < a[b+hint + ofs]
  83.604 +            int maxOfs = len - hint;
  83.605 +            while (ofs < maxOfs && c.compare(key, a[base + hint + ofs]) >= 0) {
  83.606 +                lastOfs = ofs;
  83.607 +                ofs = (ofs << 1) + 1;
  83.608 +                if (ofs <= 0)   // int overflow
  83.609 +                    ofs = maxOfs;
  83.610 +            }
  83.611 +            if (ofs > maxOfs)
  83.612 +                ofs = maxOfs;
  83.613 +
  83.614 +            // Make offsets relative to b
  83.615 +            lastOfs += hint;
  83.616 +            ofs += hint;
  83.617 +        }
  83.618 +        assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
  83.619 +
  83.620 +        /*
  83.621 +         * Now a[b + lastOfs] <= key < a[b + ofs], so key belongs somewhere to
  83.622 +         * the right of lastOfs but no farther right than ofs.  Do a binary
  83.623 +         * search, with invariant a[b + lastOfs - 1] <= key < a[b + ofs].
  83.624 +         */
  83.625 +        lastOfs++;
  83.626 +        while (lastOfs < ofs) {
  83.627 +            int m = lastOfs + ((ofs - lastOfs) >>> 1);
  83.628 +
  83.629 +            if (c.compare(key, a[base + m]) < 0)
  83.630 +                ofs = m;          // key < a[b + m]
  83.631 +            else
  83.632 +                lastOfs = m + 1;  // a[b + m] <= key
  83.633 +        }
  83.634 +        assert lastOfs == ofs;    // so a[b + ofs - 1] <= key < a[b + ofs]
  83.635 +        return ofs;
  83.636 +    }
  83.637 +
  83.638 +    /**
  83.639 +     * Merges two adjacent runs in place, in a stable fashion.  The first
  83.640 +     * element of the first run must be greater than the first element of the
  83.641 +     * second run (a[base1] > a[base2]), and the last element of the first run
  83.642 +     * (a[base1 + len1-1]) must be greater than all elements of the second run.
  83.643 +     *
  83.644 +     * For performance, this method should be called only when len1 <= len2;
  83.645 +     * its twin, mergeHi should be called if len1 >= len2.  (Either method
  83.646 +     * may be called if len1 == len2.)
  83.647 +     *
  83.648 +     * @param base1 index of first element in first run to be merged
  83.649 +     * @param len1  length of first run to be merged (must be > 0)
  83.650 +     * @param base2 index of first element in second run to be merged
  83.651 +     *        (must be aBase + aLen)
  83.652 +     * @param len2  length of second run to be merged (must be > 0)
  83.653 +     */
  83.654 +    private void mergeLo(int base1, int len1, int base2, int len2) {
  83.655 +        assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
  83.656 +
  83.657 +        // Copy first run into temp array
  83.658 +        T[] a = this.a; // For performance
  83.659 +        T[] tmp = ensureCapacity(len1);
  83.660 +        System.arraycopy(a, base1, tmp, 0, len1);
  83.661 +
  83.662 +        int cursor1 = 0;       // Indexes into tmp array
  83.663 +        int cursor2 = base2;   // Indexes int a
  83.664 +        int dest = base1;      // Indexes int a
  83.665 +
  83.666 +        // Move first element of second run and deal with degenerate cases
  83.667 +        a[dest++] = a[cursor2++];
  83.668 +        if (--len2 == 0) {
  83.669 +            System.arraycopy(tmp, cursor1, a, dest, len1);
  83.670 +            return;
  83.671 +        }
  83.672 +        if (len1 == 1) {
  83.673 +            System.arraycopy(a, cursor2, a, dest, len2);
  83.674 +            a[dest + len2] = tmp[cursor1]; // Last elt of run 1 to end of merge
  83.675 +            return;
  83.676 +        }
  83.677 +
  83.678 +        Comparator<? super T> c = this.c;  // Use local variable for performance
  83.679 +        int minGallop = this.minGallop;    //  "    "       "     "      "
  83.680 +    outer:
  83.681 +        while (true) {
  83.682 +            int count1 = 0; // Number of times in a row that first run won
  83.683 +            int count2 = 0; // Number of times in a row that second run won
  83.684 +
  83.685 +            /*
  83.686 +             * Do the straightforward thing until (if ever) one run starts
  83.687 +             * winning consistently.
  83.688 +             */
  83.689 +            do {
  83.690 +                assert len1 > 1 && len2 > 0;
  83.691 +                if (c.compare(a[cursor2], tmp[cursor1]) < 0) {
  83.692 +                    a[dest++] = a[cursor2++];
  83.693 +                    count2++;
  83.694 +                    count1 = 0;
  83.695 +                    if (--len2 == 0)
  83.696 +                        break outer;
  83.697 +                } else {
  83.698 +                    a[dest++] = tmp[cursor1++];
  83.699 +                    count1++;
  83.700 +                    count2 = 0;
  83.701 +                    if (--len1 == 1)
  83.702 +                        break outer;
  83.703 +                }
  83.704 +            } while ((count1 | count2) < minGallop);
  83.705 +
  83.706 +            /*
  83.707 +             * One run is winning so consistently that galloping may be a
  83.708 +             * huge win. So try that, and continue galloping until (if ever)
  83.709 +             * neither run appears to be winning consistently anymore.
  83.710 +             */
  83.711 +            do {
  83.712 +                assert len1 > 1 && len2 > 0;
  83.713 +                count1 = gallopRight(a[cursor2], tmp, cursor1, len1, 0, c);
  83.714 +                if (count1 != 0) {
  83.715 +                    System.arraycopy(tmp, cursor1, a, dest, count1);
  83.716 +                    dest += count1;
  83.717 +                    cursor1 += count1;
  83.718 +                    len1 -= count1;
  83.719 +                    if (len1 <= 1) // len1 == 1 || len1 == 0
  83.720 +                        break outer;
  83.721 +                }
  83.722 +                a[dest++] = a[cursor2++];
  83.723 +                if (--len2 == 0)
  83.724 +                    break outer;
  83.725 +
  83.726 +                count2 = gallopLeft(tmp[cursor1], a, cursor2, len2, 0, c);
  83.727 +                if (count2 != 0) {
  83.728 +                    System.arraycopy(a, cursor2, a, dest, count2);
  83.729 +                    dest += count2;
  83.730 +                    cursor2 += count2;
  83.731 +                    len2 -= count2;
  83.732 +                    if (len2 == 0)
  83.733 +                        break outer;
  83.734 +                }
  83.735 +                a[dest++] = tmp[cursor1++];
  83.736 +                if (--len1 == 1)
  83.737 +                    break outer;
  83.738 +                minGallop--;
  83.739 +            } while (count1 >= MIN_GALLOP | count2 >= MIN_GALLOP);
  83.740 +            if (minGallop < 0)
  83.741 +                minGallop = 0;
  83.742 +            minGallop += 2;  // Penalize for leaving gallop mode
  83.743 +        }  // End of "outer" loop
  83.744 +        this.minGallop = minGallop < 1 ? 1 : minGallop;  // Write back to field
  83.745 +
  83.746 +        if (len1 == 1) {
  83.747 +            assert len2 > 0;
  83.748 +            System.arraycopy(a, cursor2, a, dest, len2);
  83.749 +            a[dest + len2] = tmp[cursor1]; //  Last elt of run 1 to end of merge
  83.750 +        } else if (len1 == 0) {
  83.751 +            throw new IllegalArgumentException(
  83.752 +                "Comparison method violates its general contract!");
  83.753 +        } else {
  83.754 +            assert len2 == 0;
  83.755 +            assert len1 > 1;
  83.756 +            System.arraycopy(tmp, cursor1, a, dest, len1);
  83.757 +        }
  83.758 +    }
  83.759 +
  83.760 +    /**
  83.761 +     * Like mergeLo, except that this method should be called only if
  83.762 +     * len1 >= len2; mergeLo should be called if len1 <= len2.  (Either method
  83.763 +     * may be called if len1 == len2.)
  83.764 +     *
  83.765 +     * @param base1 index of first element in first run to be merged
  83.766 +     * @param len1  length of first run to be merged (must be > 0)
  83.767 +     * @param base2 index of first element in second run to be merged
  83.768 +     *        (must be aBase + aLen)
  83.769 +     * @param len2  length of second run to be merged (must be > 0)
  83.770 +     */
  83.771 +    private void mergeHi(int base1, int len1, int base2, int len2) {
  83.772 +        assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
  83.773 +
  83.774 +        // Copy second run into temp array
  83.775 +        T[] a = this.a; // For performance
  83.776 +        T[] tmp = ensureCapacity(len2);
  83.777 +        System.arraycopy(a, base2, tmp, 0, len2);
  83.778 +
  83.779 +        int cursor1 = base1 + len1 - 1;  // Indexes into a
  83.780 +        int cursor2 = len2 - 1;          // Indexes into tmp array
  83.781 +        int dest = base2 + len2 - 1;     // Indexes into a
  83.782 +
  83.783 +        // Move last element of first run and deal with degenerate cases
  83.784 +        a[dest--] = a[cursor1--];
  83.785 +        if (--len1 == 0) {
  83.786 +            System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2);
  83.787 +            return;
  83.788 +        }
  83.789 +        if (len2 == 1) {
  83.790 +            dest -= len1;
  83.791 +            cursor1 -= len1;
  83.792 +            System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
  83.793 +            a[dest] = tmp[cursor2];
  83.794 +            return;
  83.795 +        }
  83.796 +
  83.797 +        Comparator<? super T> c = this.c;  // Use local variable for performance
  83.798 +        int minGallop = this.minGallop;    //  "    "       "     "      "
  83.799 +    outer:
  83.800 +        while (true) {
  83.801 +            int count1 = 0; // Number of times in a row that first run won
  83.802 +            int count2 = 0; // Number of times in a row that second run won
  83.803 +
  83.804 +            /*
  83.805 +             * Do the straightforward thing until (if ever) one run
  83.806 +             * appears to win consistently.
  83.807 +             */
  83.808 +            do {
  83.809 +                assert len1 > 0 && len2 > 1;
  83.810 +                if (c.compare(tmp[cursor2], a[cursor1]) < 0) {
  83.811 +                    a[dest--] = a[cursor1--];
  83.812 +                    count1++;
  83.813 +                    count2 = 0;
  83.814 +                    if (--len1 == 0)
  83.815 +                        break outer;
  83.816 +                } else {
  83.817 +                    a[dest--] = tmp[cursor2--];
  83.818 +                    count2++;
  83.819 +                    count1 = 0;
  83.820 +                    if (--len2 == 1)
  83.821 +                        break outer;
  83.822 +                }
  83.823 +            } while ((count1 | count2) < minGallop);
  83.824 +
  83.825 +            /*
  83.826 +             * One run is winning so consistently that galloping may be a
  83.827 +             * huge win. So try that, and continue galloping until (if ever)
  83.828 +             * neither run appears to be winning consistently anymore.
  83.829 +             */
  83.830 +            do {
  83.831 +                assert len1 > 0 && len2 > 1;
  83.832 +                count1 = len1 - gallopRight(tmp[cursor2], a, base1, len1, len1 - 1, c);
  83.833 +                if (count1 != 0) {
  83.834 +                    dest -= count1;
  83.835 +                    cursor1 -= count1;
  83.836 +                    len1 -= count1;
  83.837 +                    System.arraycopy(a, cursor1 + 1, a, dest + 1, count1);
  83.838 +                    if (len1 == 0)
  83.839 +                        break outer;
  83.840 +                }
  83.841 +                a[dest--] = tmp[cursor2--];
  83.842 +                if (--len2 == 1)
  83.843 +                    break outer;
  83.844 +
  83.845 +                count2 = len2 - gallopLeft(a[cursor1], tmp, 0, len2, len2 - 1, c);
  83.846 +                if (count2 != 0) {
  83.847 +                    dest -= count2;
  83.848 +                    cursor2 -= count2;
  83.849 +                    len2 -= count2;
  83.850 +                    System.arraycopy(tmp, cursor2 + 1, a, dest + 1, count2);
  83.851 +                    if (len2 <= 1)  // len2 == 1 || len2 == 0
  83.852 +                        break outer;
  83.853 +                }
  83.854 +                a[dest--] = a[cursor1--];
  83.855 +                if (--len1 == 0)
  83.856 +                    break outer;
  83.857 +                minGallop--;
  83.858 +            } while (count1 >= MIN_GALLOP | count2 >= MIN_GALLOP);
  83.859 +            if (minGallop < 0)
  83.860 +                minGallop = 0;
  83.861 +            minGallop += 2;  // Penalize for leaving gallop mode
  83.862 +        }  // End of "outer" loop
  83.863 +        this.minGallop = minGallop < 1 ? 1 : minGallop;  // Write back to field
  83.864 +
  83.865 +        if (len2 == 1) {
  83.866 +            assert len1 > 0;
  83.867 +            dest -= len1;
  83.868 +            cursor1 -= len1;
  83.869 +            System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
  83.870 +            a[dest] = tmp[cursor2];  // Move first elt of run2 to front of merge
  83.871 +        } else if (len2 == 0) {
  83.872 +            throw new IllegalArgumentException(
  83.873 +                "Comparison method violates its general contract!");
  83.874 +        } else {
  83.875 +            assert len1 == 0;
  83.876 +            assert len2 > 0;
  83.877 +            System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2);
  83.878 +        }
  83.879 +    }
  83.880 +
  83.881 +    /**
  83.882 +     * Ensures that the external array tmp has at least the specified
  83.883 +     * number of elements, increasing its size if necessary.  The size
  83.884 +     * increases exponentially to ensure amortized linear time complexity.
  83.885 +     *
  83.886 +     * @param minCapacity the minimum required capacity of the tmp array
  83.887 +     * @return tmp, whether or not it grew
  83.888 +     */
  83.889 +    private T[] ensureCapacity(int minCapacity) {
  83.890 +        if (tmp.length < minCapacity) {
  83.891 +            // Compute smallest power of 2 > minCapacity
  83.892 +            int newSize = minCapacity;
  83.893 +            newSize |= newSize >> 1;
  83.894 +            newSize |= newSize >> 2;
  83.895 +            newSize |= newSize >> 4;
  83.896 +            newSize |= newSize >> 8;
  83.897 +            newSize |= newSize >> 16;
  83.898 +            newSize++;
  83.899 +
  83.900 +            if (newSize < 0) // Not bloody likely!
  83.901 +                newSize = minCapacity;
  83.902 +            else
  83.903 +                newSize = Math.min(newSize, a.length >>> 1);
  83.904 +
  83.905 +            @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
  83.906 +            T[] newArray = (T[]) new Object[newSize];
  83.907 +            tmp = newArray;
  83.908 +        }
  83.909 +        return tmp;
  83.910 +    }
  83.911 +
  83.912 +    /**
  83.913 +     * Checks that fromIndex and toIndex are in range, and throws an
  83.914 +     * appropriate exception if they aren't.
  83.915 +     *
  83.916 +     * @param arrayLen the length of the array
  83.917 +     * @param fromIndex the index of the first element of the range
  83.918 +     * @param toIndex the index after the last element of the range
  83.919 +     * @throws IllegalArgumentException if fromIndex > toIndex
  83.920 +     * @throws ArrayIndexOutOfBoundsException if fromIndex < 0
  83.921 +     *         or toIndex > arrayLen
  83.922 +     */
  83.923 +    private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) {
  83.924 +        if (fromIndex > toIndex)
  83.925 +            throw new IllegalArgumentException("fromIndex(" + fromIndex +
  83.926 +                       ") > toIndex(" + toIndex+")");
  83.927 +        if (fromIndex < 0)
  83.928 +            throw new ArrayIndexOutOfBoundsException(fromIndex);
  83.929 +        if (toIndex > arrayLen)
  83.930 +            throw new ArrayIndexOutOfBoundsException(toIndex);
  83.931 +    }
  83.932 +}
    84.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    84.2 +++ b/emul/compact/src/main/java/java/util/Vector.java	Sun Feb 03 07:48:42 2013 +0100
    84.3 @@ -0,0 +1,1194 @@
    84.4 +/*
    84.5 + * Copyright (c) 1994, 2011, 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.util;
   84.30 +
   84.31 +
   84.32 +/**
   84.33 + * The {@code Vector} class implements a growable array of
   84.34 + * objects. Like an array, it contains components that can be
   84.35 + * accessed using an integer index. However, the size of a
   84.36 + * {@code Vector} can grow or shrink as needed to accommodate
   84.37 + * adding and removing items after the {@code Vector} has been created.
   84.38 + *
   84.39 + * <p>Each vector tries to optimize storage management by maintaining a
   84.40 + * {@code capacity} and a {@code capacityIncrement}. The
   84.41 + * {@code capacity} is always at least as large as the vector
   84.42 + * size; it is usually larger because as components are added to the
   84.43 + * vector, the vector's storage increases in chunks the size of
   84.44 + * {@code capacityIncrement}. An application can increase the
   84.45 + * capacity of a vector before inserting a large number of
   84.46 + * components; this reduces the amount of incremental reallocation.
   84.47 + *
   84.48 + * <p><a name="fail-fast"/>
   84.49 + * The iterators returned by this class's {@link #iterator() iterator} and
   84.50 + * {@link #listIterator(int) listIterator} methods are <em>fail-fast</em>:
   84.51 + * if the vector is structurally modified at any time after the iterator is
   84.52 + * created, in any way except through the iterator's own
   84.53 + * {@link ListIterator#remove() remove} or
   84.54 + * {@link ListIterator#add(Object) add} methods, the iterator will throw a
   84.55 + * {@link ConcurrentModificationException}.  Thus, in the face of
   84.56 + * concurrent modification, the iterator fails quickly and cleanly, rather
   84.57 + * than risking arbitrary, non-deterministic behavior at an undetermined
   84.58 + * time in the future.  The {@link Enumeration Enumerations} returned by
   84.59 + * the {@link #elements() elements} method are <em>not</em> fail-fast.
   84.60 + *
   84.61 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
   84.62 + * as it is, generally speaking, impossible to make any hard guarantees in the
   84.63 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
   84.64 + * throw {@code ConcurrentModificationException} on a best-effort basis.
   84.65 + * Therefore, it would be wrong to write a program that depended on this
   84.66 + * exception for its correctness:  <i>the fail-fast behavior of iterators
   84.67 + * should be used only to detect bugs.</i>
   84.68 + *
   84.69 + * <p>As of the Java 2 platform v1.2, this class was retrofitted to
   84.70 + * implement the {@link List} interface, making it a member of the
   84.71 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   84.72 + * Java Collections Framework</a>.  Unlike the new collection
   84.73 + * implementations, {@code Vector} is synchronized.  If a thread-safe
   84.74 + * implementation is not needed, it is recommended to use {@link
   84.75 + * ArrayList} in place of {@code Vector}.
   84.76 + *
   84.77 + * @author  Lee Boynton
   84.78 + * @author  Jonathan Payne
   84.79 + * @see Collection
   84.80 + * @see LinkedList
   84.81 + * @since   JDK1.0
   84.82 + */
   84.83 +public class Vector<E>
   84.84 +    extends AbstractList<E>
   84.85 +    implements List<E>, RandomAccess, Cloneable, java.io.Serializable
   84.86 +{
   84.87 +    /**
   84.88 +     * The array buffer into which the components of the vector are
   84.89 +     * stored. The capacity of the vector is the length of this array buffer,
   84.90 +     * and is at least large enough to contain all the vector's elements.
   84.91 +     *
   84.92 +     * <p>Any array elements following the last element in the Vector are null.
   84.93 +     *
   84.94 +     * @serial
   84.95 +     */
   84.96 +    protected Object[] elementData;
   84.97 +
   84.98 +    /**
   84.99 +     * The number of valid components in this {@code Vector} object.
  84.100 +     * Components {@code elementData[0]} through
  84.101 +     * {@code elementData[elementCount-1]} are the actual items.
  84.102 +     *
  84.103 +     * @serial
  84.104 +     */
  84.105 +    protected int elementCount;
  84.106 +
  84.107 +    /**
  84.108 +     * The amount by which the capacity of the vector is automatically
  84.109 +     * incremented when its size becomes greater than its capacity.  If
  84.110 +     * the capacity increment is less than or equal to zero, the capacity
  84.111 +     * of the vector is doubled each time it needs to grow.
  84.112 +     *
  84.113 +     * @serial
  84.114 +     */
  84.115 +    protected int capacityIncrement;
  84.116 +
  84.117 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
  84.118 +    private static final long serialVersionUID = -2767605614048989439L;
  84.119 +
  84.120 +    /**
  84.121 +     * Constructs an empty vector with the specified initial capacity and
  84.122 +     * capacity increment.
  84.123 +     *
  84.124 +     * @param   initialCapacity     the initial capacity of the vector
  84.125 +     * @param   capacityIncrement   the amount by which the capacity is
  84.126 +     *                              increased when the vector overflows
  84.127 +     * @throws IllegalArgumentException if the specified initial capacity
  84.128 +     *         is negative
  84.129 +     */
  84.130 +    public Vector(int initialCapacity, int capacityIncrement) {
  84.131 +        super();
  84.132 +        if (initialCapacity < 0)
  84.133 +            throw new IllegalArgumentException("Illegal Capacity: "+
  84.134 +                                               initialCapacity);
  84.135 +        this.elementData = new Object[initialCapacity];
  84.136 +        this.capacityIncrement = capacityIncrement;
  84.137 +    }
  84.138 +
  84.139 +    /**
  84.140 +     * Constructs an empty vector with the specified initial capacity and
  84.141 +     * with its capacity increment equal to zero.
  84.142 +     *
  84.143 +     * @param   initialCapacity   the initial capacity of the vector
  84.144 +     * @throws IllegalArgumentException if the specified initial capacity
  84.145 +     *         is negative
  84.146 +     */
  84.147 +    public Vector(int initialCapacity) {
  84.148 +        this(initialCapacity, 0);
  84.149 +    }
  84.150 +
  84.151 +    /**
  84.152 +     * Constructs an empty vector so that its internal data array
  84.153 +     * has size {@code 10} and its standard capacity increment is
  84.154 +     * zero.
  84.155 +     */
  84.156 +    public Vector() {
  84.157 +        this(10);
  84.158 +    }
  84.159 +
  84.160 +    /**
  84.161 +     * Constructs a vector containing the elements of the specified
  84.162 +     * collection, in the order they are returned by the collection's
  84.163 +     * iterator.
  84.164 +     *
  84.165 +     * @param c the collection whose elements are to be placed into this
  84.166 +     *       vector
  84.167 +     * @throws NullPointerException if the specified collection is null
  84.168 +     * @since   1.2
  84.169 +     */
  84.170 +    public Vector(Collection<? extends E> c) {
  84.171 +        elementData = c.toArray();
  84.172 +        elementCount = elementData.length;
  84.173 +        // c.toArray might (incorrectly) not return Object[] (see 6260652)
  84.174 +        if (elementData.getClass() != Object[].class)
  84.175 +            elementData = Arrays.copyOf(elementData, elementCount, Object[].class);
  84.176 +    }
  84.177 +
  84.178 +    /**
  84.179 +     * Copies the components of this vector into the specified array.
  84.180 +     * The item at index {@code k} in this vector is copied into
  84.181 +     * component {@code k} of {@code anArray}.
  84.182 +     *
  84.183 +     * @param  anArray the array into which the components get copied
  84.184 +     * @throws NullPointerException if the given array is null
  84.185 +     * @throws IndexOutOfBoundsException if the specified array is not
  84.186 +     *         large enough to hold all the components of this vector
  84.187 +     * @throws ArrayStoreException if a component of this vector is not of
  84.188 +     *         a runtime type that can be stored in the specified array
  84.189 +     * @see #toArray(Object[])
  84.190 +     */
  84.191 +    public synchronized void copyInto(Object[] anArray) {
  84.192 +        System.arraycopy(elementData, 0, anArray, 0, elementCount);
  84.193 +    }
  84.194 +
  84.195 +    /**
  84.196 +     * Trims the capacity of this vector to be the vector's current
  84.197 +     * size. If the capacity of this vector is larger than its current
  84.198 +     * size, then the capacity is changed to equal the size by replacing
  84.199 +     * its internal data array, kept in the field {@code elementData},
  84.200 +     * with a smaller one. An application can use this operation to
  84.201 +     * minimize the storage of a vector.
  84.202 +     */
  84.203 +    public synchronized void trimToSize() {
  84.204 +        modCount++;
  84.205 +        int oldCapacity = elementData.length;
  84.206 +        if (elementCount < oldCapacity) {
  84.207 +            elementData = Arrays.copyOf(elementData, elementCount);
  84.208 +        }
  84.209 +    }
  84.210 +
  84.211 +    /**
  84.212 +     * Increases the capacity of this vector, if necessary, to ensure
  84.213 +     * that it can hold at least the number of components specified by
  84.214 +     * the minimum capacity argument.
  84.215 +     *
  84.216 +     * <p>If the current capacity of this vector is less than
  84.217 +     * {@code minCapacity}, then its capacity is increased by replacing its
  84.218 +     * internal data array, kept in the field {@code elementData}, with a
  84.219 +     * larger one.  The size of the new data array will be the old size plus
  84.220 +     * {@code capacityIncrement}, unless the value of
  84.221 +     * {@code capacityIncrement} is less than or equal to zero, in which case
  84.222 +     * the new capacity will be twice the old capacity; but if this new size
  84.223 +     * is still smaller than {@code minCapacity}, then the new capacity will
  84.224 +     * be {@code minCapacity}.
  84.225 +     *
  84.226 +     * @param minCapacity the desired minimum capacity
  84.227 +     */
  84.228 +    public synchronized void ensureCapacity(int minCapacity) {
  84.229 +        if (minCapacity > 0) {
  84.230 +            modCount++;
  84.231 +            ensureCapacityHelper(minCapacity);
  84.232 +        }
  84.233 +    }
  84.234 +
  84.235 +    /**
  84.236 +     * This implements the unsynchronized semantics of ensureCapacity.
  84.237 +     * Synchronized methods in this class can internally call this
  84.238 +     * method for ensuring capacity without incurring the cost of an
  84.239 +     * extra synchronization.
  84.240 +     *
  84.241 +     * @see #ensureCapacity(int)
  84.242 +     */
  84.243 +    private void ensureCapacityHelper(int minCapacity) {
  84.244 +        // overflow-conscious code
  84.245 +        if (minCapacity - elementData.length > 0)
  84.246 +            grow(minCapacity);
  84.247 +    }
  84.248 +
  84.249 +    /**
  84.250 +     * The maximum size of array to allocate.
  84.251 +     * Some VMs reserve some header words in an array.
  84.252 +     * Attempts to allocate larger arrays may result in
  84.253 +     * OutOfMemoryError: Requested array size exceeds VM limit
  84.254 +     */
  84.255 +    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
  84.256 +
  84.257 +    private void grow(int minCapacity) {
  84.258 +        // overflow-conscious code
  84.259 +        int oldCapacity = elementData.length;
  84.260 +        int newCapacity = oldCapacity + ((capacityIncrement > 0) ?
  84.261 +                                         capacityIncrement : oldCapacity);
  84.262 +        if (newCapacity - minCapacity < 0)
  84.263 +            newCapacity = minCapacity;
  84.264 +        if (newCapacity - MAX_ARRAY_SIZE > 0)
  84.265 +            newCapacity = hugeCapacity(minCapacity);
  84.266 +        elementData = Arrays.copyOf(elementData, newCapacity);
  84.267 +    }
  84.268 +
  84.269 +    private static int hugeCapacity(int minCapacity) {
  84.270 +        if (minCapacity < 0) // overflow
  84.271 +            throw new OutOfMemoryError();
  84.272 +        return (minCapacity > MAX_ARRAY_SIZE) ?
  84.273 +            Integer.MAX_VALUE :
  84.274 +            MAX_ARRAY_SIZE;
  84.275 +    }
  84.276 +
  84.277 +    /**
  84.278 +     * Sets the size of this vector. If the new size is greater than the
  84.279 +     * current size, new {@code null} items are added to the end of
  84.280 +     * the vector. If the new size is less than the current size, all
  84.281 +     * components at index {@code newSize} and greater are discarded.
  84.282 +     *
  84.283 +     * @param  newSize   the new size of this vector
  84.284 +     * @throws ArrayIndexOutOfBoundsException if the new size is negative
  84.285 +     */
  84.286 +    public synchronized void setSize(int newSize) {
  84.287 +        modCount++;
  84.288 +        if (newSize > elementCount) {
  84.289 +            ensureCapacityHelper(newSize);
  84.290 +        } else {
  84.291 +            for (int i = newSize ; i < elementCount ; i++) {
  84.292 +                elementData[i] = null;
  84.293 +            }
  84.294 +        }
  84.295 +        elementCount = newSize;
  84.296 +    }
  84.297 +
  84.298 +    /**
  84.299 +     * Returns the current capacity of this vector.
  84.300 +     *
  84.301 +     * @return  the current capacity (the length of its internal
  84.302 +     *          data array, kept in the field {@code elementData}
  84.303 +     *          of this vector)
  84.304 +     */
  84.305 +    public synchronized int capacity() {
  84.306 +        return elementData.length;
  84.307 +    }
  84.308 +
  84.309 +    /**
  84.310 +     * Returns the number of components in this vector.
  84.311 +     *
  84.312 +     * @return  the number of components in this vector
  84.313 +     */
  84.314 +    public synchronized int size() {
  84.315 +        return elementCount;
  84.316 +    }
  84.317 +
  84.318 +    /**
  84.319 +     * Tests if this vector has no components.
  84.320 +     *
  84.321 +     * @return  {@code true} if and only if this vector has
  84.322 +     *          no components, that is, its size is zero;
  84.323 +     *          {@code false} otherwise.
  84.324 +     */
  84.325 +    public synchronized boolean isEmpty() {
  84.326 +        return elementCount == 0;
  84.327 +    }
  84.328 +
  84.329 +    /**
  84.330 +     * Returns an enumeration of the components of this vector. The
  84.331 +     * returned {@code Enumeration} object will generate all items in
  84.332 +     * this vector. The first item generated is the item at index {@code 0},
  84.333 +     * then the item at index {@code 1}, and so on.
  84.334 +     *
  84.335 +     * @return  an enumeration of the components of this vector
  84.336 +     * @see     Iterator
  84.337 +     */
  84.338 +    public Enumeration<E> elements() {
  84.339 +        return new Enumeration<E>() {
  84.340 +            int count = 0;
  84.341 +
  84.342 +            public boolean hasMoreElements() {
  84.343 +                return count < elementCount;
  84.344 +            }
  84.345 +
  84.346 +            public E nextElement() {
  84.347 +                synchronized (Vector.this) {
  84.348 +                    if (count < elementCount) {
  84.349 +                        return elementData(count++);
  84.350 +                    }
  84.351 +                }
  84.352 +                throw new NoSuchElementException("Vector Enumeration");
  84.353 +            }
  84.354 +        };
  84.355 +    }
  84.356 +
  84.357 +    /**
  84.358 +     * Returns {@code true} if this vector contains the specified element.
  84.359 +     * More formally, returns {@code true} if and only if this vector
  84.360 +     * contains at least one element {@code e} such that
  84.361 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  84.362 +     *
  84.363 +     * @param o element whose presence in this vector is to be tested
  84.364 +     * @return {@code true} if this vector contains the specified element
  84.365 +     */
  84.366 +    public boolean contains(Object o) {
  84.367 +        return indexOf(o, 0) >= 0;
  84.368 +    }
  84.369 +
  84.370 +    /**
  84.371 +     * Returns the index of the first occurrence of the specified element
  84.372 +     * in this vector, or -1 if this vector does not contain the element.
  84.373 +     * More formally, returns the lowest index {@code i} such that
  84.374 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  84.375 +     * or -1 if there is no such index.
  84.376 +     *
  84.377 +     * @param o element to search for
  84.378 +     * @return the index of the first occurrence of the specified element in
  84.379 +     *         this vector, or -1 if this vector does not contain the element
  84.380 +     */
  84.381 +    public int indexOf(Object o) {
  84.382 +        return indexOf(o, 0);
  84.383 +    }
  84.384 +
  84.385 +    /**
  84.386 +     * Returns the index of the first occurrence of the specified element in
  84.387 +     * this vector, searching forwards from {@code index}, or returns -1 if
  84.388 +     * the element is not found.
  84.389 +     * More formally, returns the lowest index {@code i} such that
  84.390 +     * <tt>(i&nbsp;&gt;=&nbsp;index&nbsp;&amp;&amp;&nbsp;(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i))))</tt>,
  84.391 +     * or -1 if there is no such index.
  84.392 +     *
  84.393 +     * @param o element to search for
  84.394 +     * @param index index to start searching from
  84.395 +     * @return the index of the first occurrence of the element in
  84.396 +     *         this vector at position {@code index} or later in the vector;
  84.397 +     *         {@code -1} if the element is not found.
  84.398 +     * @throws IndexOutOfBoundsException if the specified index is negative
  84.399 +     * @see     Object#equals(Object)
  84.400 +     */
  84.401 +    public synchronized int indexOf(Object o, int index) {
  84.402 +        if (o == null) {
  84.403 +            for (int i = index ; i < elementCount ; i++)
  84.404 +                if (elementData[i]==null)
  84.405 +                    return i;
  84.406 +        } else {
  84.407 +            for (int i = index ; i < elementCount ; i++)
  84.408 +                if (o.equals(elementData[i]))
  84.409 +                    return i;
  84.410 +        }
  84.411 +        return -1;
  84.412 +    }
  84.413 +
  84.414 +    /**
  84.415 +     * Returns the index of the last occurrence of the specified element
  84.416 +     * in this vector, or -1 if this vector does not contain the element.
  84.417 +     * More formally, returns the highest index {@code i} such that
  84.418 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  84.419 +     * or -1 if there is no such index.
  84.420 +     *
  84.421 +     * @param o element to search for
  84.422 +     * @return the index of the last occurrence of the specified element in
  84.423 +     *         this vector, or -1 if this vector does not contain the element
  84.424 +     */
  84.425 +    public synchronized int lastIndexOf(Object o) {
  84.426 +        return lastIndexOf(o, elementCount-1);
  84.427 +    }
  84.428 +
  84.429 +    /**
  84.430 +     * Returns the index of the last occurrence of the specified element in
  84.431 +     * this vector, searching backwards from {@code index}, or returns -1 if
  84.432 +     * the element is not found.
  84.433 +     * More formally, returns the highest index {@code i} such that
  84.434 +     * <tt>(i&nbsp;&lt;=&nbsp;index&nbsp;&amp;&amp;&nbsp;(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i))))</tt>,
  84.435 +     * or -1 if there is no such index.
  84.436 +     *
  84.437 +     * @param o element to search for
  84.438 +     * @param index index to start searching backwards from
  84.439 +     * @return the index of the last occurrence of the element at position
  84.440 +     *         less than or equal to {@code index} in this vector;
  84.441 +     *         -1 if the element is not found.
  84.442 +     * @throws IndexOutOfBoundsException if the specified index is greater
  84.443 +     *         than or equal to the current size of this vector
  84.444 +     */
  84.445 +    public synchronized int lastIndexOf(Object o, int index) {
  84.446 +        if (index >= elementCount)
  84.447 +            throw new IndexOutOfBoundsException(index + " >= "+ elementCount);
  84.448 +
  84.449 +        if (o == null) {
  84.450 +            for (int i = index; i >= 0; i--)
  84.451 +                if (elementData[i]==null)
  84.452 +                    return i;
  84.453 +        } else {
  84.454 +            for (int i = index; i >= 0; i--)
  84.455 +                if (o.equals(elementData[i]))
  84.456 +                    return i;
  84.457 +        }
  84.458 +        return -1;
  84.459 +    }
  84.460 +
  84.461 +    /**
  84.462 +     * Returns the component at the specified index.
  84.463 +     *
  84.464 +     * <p>This method is identical in functionality to the {@link #get(int)}
  84.465 +     * method (which is part of the {@link List} interface).
  84.466 +     *
  84.467 +     * @param      index   an index into this vector
  84.468 +     * @return     the component at the specified index
  84.469 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
  84.470 +     *         ({@code index < 0 || index >= size()})
  84.471 +     */
  84.472 +    public synchronized E elementAt(int index) {
  84.473 +        if (index >= elementCount) {
  84.474 +            throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
  84.475 +        }
  84.476 +
  84.477 +        return elementData(index);
  84.478 +    }
  84.479 +
  84.480 +    /**
  84.481 +     * Returns the first component (the item at index {@code 0}) of
  84.482 +     * this vector.
  84.483 +     *
  84.484 +     * @return     the first component of this vector
  84.485 +     * @throws NoSuchElementException if this vector has no components
  84.486 +     */
  84.487 +    public synchronized E firstElement() {
  84.488 +        if (elementCount == 0) {
  84.489 +            throw new NoSuchElementException();
  84.490 +        }
  84.491 +        return elementData(0);
  84.492 +    }
  84.493 +
  84.494 +    /**
  84.495 +     * Returns the last component of the vector.
  84.496 +     *
  84.497 +     * @return  the last component of the vector, i.e., the component at index
  84.498 +     *          <code>size()&nbsp;-&nbsp;1</code>.
  84.499 +     * @throws NoSuchElementException if this vector is empty
  84.500 +     */
  84.501 +    public synchronized E lastElement() {
  84.502 +        if (elementCount == 0) {
  84.503 +            throw new NoSuchElementException();
  84.504 +        }
  84.505 +        return elementData(elementCount - 1);
  84.506 +    }
  84.507 +
  84.508 +    /**
  84.509 +     * Sets the component at the specified {@code index} of this
  84.510 +     * vector to be the specified object. The previous component at that
  84.511 +     * position is discarded.
  84.512 +     *
  84.513 +     * <p>The index must be a value greater than or equal to {@code 0}
  84.514 +     * and less than the current size of the vector.
  84.515 +     *
  84.516 +     * <p>This method is identical in functionality to the
  84.517 +     * {@link #set(int, Object) set(int, E)}
  84.518 +     * method (which is part of the {@link List} interface). Note that the
  84.519 +     * {@code set} method reverses the order of the parameters, to more closely
  84.520 +     * match array usage.  Note also that the {@code set} method returns the
  84.521 +     * old value that was stored at the specified position.
  84.522 +     *
  84.523 +     * @param      obj     what the component is to be set to
  84.524 +     * @param      index   the specified index
  84.525 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
  84.526 +     *         ({@code index < 0 || index >= size()})
  84.527 +     */
  84.528 +    public synchronized void setElementAt(E obj, int index) {
  84.529 +        if (index >= elementCount) {
  84.530 +            throw new ArrayIndexOutOfBoundsException(index + " >= " +
  84.531 +                                                     elementCount);
  84.532 +        }
  84.533 +        elementData[index] = obj;
  84.534 +    }
  84.535 +
  84.536 +    /**
  84.537 +     * Deletes the component at the specified index. Each component in
  84.538 +     * this vector with an index greater or equal to the specified
  84.539 +     * {@code index} is shifted downward to have an index one
  84.540 +     * smaller than the value it had previously. The size of this vector
  84.541 +     * is decreased by {@code 1}.
  84.542 +     *
  84.543 +     * <p>The index must be a value greater than or equal to {@code 0}
  84.544 +     * and less than the current size of the vector.
  84.545 +     *
  84.546 +     * <p>This method is identical in functionality to the {@link #remove(int)}
  84.547 +     * method (which is part of the {@link List} interface).  Note that the
  84.548 +     * {@code remove} method returns the old value that was stored at the
  84.549 +     * specified position.
  84.550 +     *
  84.551 +     * @param      index   the index of the object to remove
  84.552 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
  84.553 +     *         ({@code index < 0 || index >= size()})
  84.554 +     */
  84.555 +    public synchronized void removeElementAt(int index) {
  84.556 +        modCount++;
  84.557 +        if (index >= elementCount) {
  84.558 +            throw new ArrayIndexOutOfBoundsException(index + " >= " +
  84.559 +                                                     elementCount);
  84.560 +        }
  84.561 +        else if (index < 0) {
  84.562 +            throw new ArrayIndexOutOfBoundsException(index);
  84.563 +        }
  84.564 +        int j = elementCount - index - 1;
  84.565 +        if (j > 0) {
  84.566 +            System.arraycopy(elementData, index + 1, elementData, index, j);
  84.567 +        }
  84.568 +        elementCount--;
  84.569 +        elementData[elementCount] = null; /* to let gc do its work */
  84.570 +    }
  84.571 +
  84.572 +    /**
  84.573 +     * Inserts the specified object as a component in this vector at the
  84.574 +     * specified {@code index}. Each component in this vector with
  84.575 +     * an index greater or equal to the specified {@code index} is
  84.576 +     * shifted upward to have an index one greater than the value it had
  84.577 +     * previously.
  84.578 +     *
  84.579 +     * <p>The index must be a value greater than or equal to {@code 0}
  84.580 +     * and less than or equal to the current size of the vector. (If the
  84.581 +     * index is equal to the current size of the vector, the new element
  84.582 +     * is appended to the Vector.)
  84.583 +     *
  84.584 +     * <p>This method is identical in functionality to the
  84.585 +     * {@link #add(int, Object) add(int, E)}
  84.586 +     * method (which is part of the {@link List} interface).  Note that the
  84.587 +     * {@code add} method reverses the order of the parameters, to more closely
  84.588 +     * match array usage.
  84.589 +     *
  84.590 +     * @param      obj     the component to insert
  84.591 +     * @param      index   where to insert the new component
  84.592 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
  84.593 +     *         ({@code index < 0 || index > size()})
  84.594 +     */
  84.595 +    public synchronized void insertElementAt(E obj, int index) {
  84.596 +        modCount++;
  84.597 +        if (index > elementCount) {
  84.598 +            throw new ArrayIndexOutOfBoundsException(index
  84.599 +                                                     + " > " + elementCount);
  84.600 +        }
  84.601 +        ensureCapacityHelper(elementCount + 1);
  84.602 +        System.arraycopy(elementData, index, elementData, index + 1, elementCount - index);
  84.603 +        elementData[index] = obj;
  84.604 +        elementCount++;
  84.605 +    }
  84.606 +
  84.607 +    /**
  84.608 +     * Adds the specified component to the end of this vector,
  84.609 +     * increasing its size by one. The capacity of this vector is
  84.610 +     * increased if its size becomes greater than its capacity.
  84.611 +     *
  84.612 +     * <p>This method is identical in functionality to the
  84.613 +     * {@link #add(Object) add(E)}
  84.614 +     * method (which is part of the {@link List} interface).
  84.615 +     *
  84.616 +     * @param   obj   the component to be added
  84.617 +     */
  84.618 +    public synchronized void addElement(E obj) {
  84.619 +        modCount++;
  84.620 +        ensureCapacityHelper(elementCount + 1);
  84.621 +        elementData[elementCount++] = obj;
  84.622 +    }
  84.623 +
  84.624 +    /**
  84.625 +     * Removes the first (lowest-indexed) occurrence of the argument
  84.626 +     * from this vector. If the object is found in this vector, each
  84.627 +     * component in the vector with an index greater or equal to the
  84.628 +     * object's index is shifted downward to have an index one smaller
  84.629 +     * than the value it had previously.
  84.630 +     *
  84.631 +     * <p>This method is identical in functionality to the
  84.632 +     * {@link #remove(Object)} method (which is part of the
  84.633 +     * {@link List} interface).
  84.634 +     *
  84.635 +     * @param   obj   the component to be removed
  84.636 +     * @return  {@code true} if the argument was a component of this
  84.637 +     *          vector; {@code false} otherwise.
  84.638 +     */
  84.639 +    public synchronized boolean removeElement(Object obj) {
  84.640 +        modCount++;
  84.641 +        int i = indexOf(obj);
  84.642 +        if (i >= 0) {
  84.643 +            removeElementAt(i);
  84.644 +            return true;
  84.645 +        }
  84.646 +        return false;
  84.647 +    }
  84.648 +
  84.649 +    /**
  84.650 +     * Removes all components from this vector and sets its size to zero.
  84.651 +     *
  84.652 +     * <p>This method is identical in functionality to the {@link #clear}
  84.653 +     * method (which is part of the {@link List} interface).
  84.654 +     */
  84.655 +    public synchronized void removeAllElements() {
  84.656 +        modCount++;
  84.657 +        // Let gc do its work
  84.658 +        for (int i = 0; i < elementCount; i++)
  84.659 +            elementData[i] = null;
  84.660 +
  84.661 +        elementCount = 0;
  84.662 +    }
  84.663 +
  84.664 +    /**
  84.665 +     * Returns a clone of this vector. The copy will contain a
  84.666 +     * reference to a clone of the internal data array, not a reference
  84.667 +     * to the original internal data array of this {@code Vector} object.
  84.668 +     *
  84.669 +     * @return  a clone of this vector
  84.670 +     */
  84.671 +    public synchronized Object clone() {
  84.672 +        try {
  84.673 +            @SuppressWarnings("unchecked")
  84.674 +                Vector<E> v = (Vector<E>) super.clone();
  84.675 +            v.elementData = Arrays.copyOf(elementData, elementCount);
  84.676 +            v.modCount = 0;
  84.677 +            return v;
  84.678 +        } catch (CloneNotSupportedException e) {
  84.679 +            // this shouldn't happen, since we are Cloneable
  84.680 +            throw new InternalError();
  84.681 +        }
  84.682 +    }
  84.683 +
  84.684 +    /**
  84.685 +     * Returns an array containing all of the elements in this Vector
  84.686 +     * in the correct order.
  84.687 +     *
  84.688 +     * @since 1.2
  84.689 +     */
  84.690 +    public synchronized Object[] toArray() {
  84.691 +        return Arrays.copyOf(elementData, elementCount);
  84.692 +    }
  84.693 +
  84.694 +    /**
  84.695 +     * Returns an array containing all of the elements in this Vector in the
  84.696 +     * correct order; the runtime type of the returned array is that of the
  84.697 +     * specified array.  If the Vector fits in the specified array, it is
  84.698 +     * returned therein.  Otherwise, a new array is allocated with the runtime
  84.699 +     * type of the specified array and the size of this Vector.
  84.700 +     *
  84.701 +     * <p>If the Vector fits in the specified array with room to spare
  84.702 +     * (i.e., the array has more elements than the Vector),
  84.703 +     * the element in the array immediately following the end of the
  84.704 +     * Vector is set to null.  (This is useful in determining the length
  84.705 +     * of the Vector <em>only</em> if the caller knows that the Vector
  84.706 +     * does not contain any null elements.)
  84.707 +     *
  84.708 +     * @param a the array into which the elements of the Vector are to
  84.709 +     *          be stored, if it is big enough; otherwise, a new array of the
  84.710 +     *          same runtime type is allocated for this purpose.
  84.711 +     * @return an array containing the elements of the Vector
  84.712 +     * @throws ArrayStoreException if the runtime type of a is not a supertype
  84.713 +     * of the runtime type of every element in this Vector
  84.714 +     * @throws NullPointerException if the given array is null
  84.715 +     * @since 1.2
  84.716 +     */
  84.717 +    @SuppressWarnings("unchecked")
  84.718 +    public synchronized <T> T[] toArray(T[] a) {
  84.719 +        if (a.length < elementCount)
  84.720 +            return (T[]) Arrays.copyOf(elementData, elementCount, a.getClass());
  84.721 +
  84.722 +        System.arraycopy(elementData, 0, a, 0, elementCount);
  84.723 +
  84.724 +        if (a.length > elementCount)
  84.725 +            a[elementCount] = null;
  84.726 +
  84.727 +        return a;
  84.728 +    }
  84.729 +
  84.730 +    // Positional Access Operations
  84.731 +
  84.732 +    @SuppressWarnings("unchecked")
  84.733 +    E elementData(int index) {
  84.734 +        return (E) elementData[index];
  84.735 +    }
  84.736 +
  84.737 +    /**
  84.738 +     * Returns the element at the specified position in this Vector.
  84.739 +     *
  84.740 +     * @param index index of the element to return
  84.741 +     * @return object at the specified index
  84.742 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
  84.743 +     *            ({@code index < 0 || index >= size()})
  84.744 +     * @since 1.2
  84.745 +     */
  84.746 +    public synchronized E get(int index) {
  84.747 +        if (index >= elementCount)
  84.748 +            throw new ArrayIndexOutOfBoundsException(index);
  84.749 +
  84.750 +        return elementData(index);
  84.751 +    }
  84.752 +
  84.753 +    /**
  84.754 +     * Replaces the element at the specified position in this Vector with the
  84.755 +     * specified element.
  84.756 +     *
  84.757 +     * @param index index of the element to replace
  84.758 +     * @param element element to be stored at the specified position
  84.759 +     * @return the element previously at the specified position
  84.760 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
  84.761 +     *         ({@code index < 0 || index >= size()})
  84.762 +     * @since 1.2
  84.763 +     */
  84.764 +    public synchronized E set(int index, E element) {
  84.765 +        if (index >= elementCount)
  84.766 +            throw new ArrayIndexOutOfBoundsException(index);
  84.767 +
  84.768 +        E oldValue = elementData(index);
  84.769 +        elementData[index] = element;
  84.770 +        return oldValue;
  84.771 +    }
  84.772 +
  84.773 +    /**
  84.774 +     * Appends the specified element to the end of this Vector.
  84.775 +     *
  84.776 +     * @param e element to be appended to this Vector
  84.777 +     * @return {@code true} (as specified by {@link Collection#add})
  84.778 +     * @since 1.2
  84.779 +     */
  84.780 +    public synchronized boolean add(E e) {
  84.781 +        modCount++;
  84.782 +        ensureCapacityHelper(elementCount + 1);
  84.783 +        elementData[elementCount++] = e;
  84.784 +        return true;
  84.785 +    }
  84.786 +
  84.787 +    /**
  84.788 +     * Removes the first occurrence of the specified element in this Vector
  84.789 +     * If the Vector does not contain the element, it is unchanged.  More
  84.790 +     * formally, removes the element with the lowest index i such that
  84.791 +     * {@code (o==null ? get(i)==null : o.equals(get(i)))} (if such
  84.792 +     * an element exists).
  84.793 +     *
  84.794 +     * @param o element to be removed from this Vector, if present
  84.795 +     * @return true if the Vector contained the specified element
  84.796 +     * @since 1.2
  84.797 +     */
  84.798 +    public boolean remove(Object o) {
  84.799 +        return removeElement(o);
  84.800 +    }
  84.801 +
  84.802 +    /**
  84.803 +     * Inserts the specified element at the specified position in this Vector.
  84.804 +     * Shifts the element currently at that position (if any) and any
  84.805 +     * subsequent elements to the right (adds one to their indices).
  84.806 +     *
  84.807 +     * @param index index at which the specified element is to be inserted
  84.808 +     * @param element element to be inserted
  84.809 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
  84.810 +     *         ({@code index < 0 || index > size()})
  84.811 +     * @since 1.2
  84.812 +     */
  84.813 +    public void add(int index, E element) {
  84.814 +        insertElementAt(element, index);
  84.815 +    }
  84.816 +
  84.817 +    /**
  84.818 +     * Removes the element at the specified position in this Vector.
  84.819 +     * Shifts any subsequent elements to the left (subtracts one from their
  84.820 +     * indices).  Returns the element that was removed from the Vector.
  84.821 +     *
  84.822 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
  84.823 +     *         ({@code index < 0 || index >= size()})
  84.824 +     * @param index the index of the element to be removed
  84.825 +     * @return element that was removed
  84.826 +     * @since 1.2
  84.827 +     */
  84.828 +    public synchronized E remove(int index) {
  84.829 +        modCount++;
  84.830 +        if (index >= elementCount)
  84.831 +            throw new ArrayIndexOutOfBoundsException(index);
  84.832 +        E oldValue = elementData(index);
  84.833 +
  84.834 +        int numMoved = elementCount - index - 1;
  84.835 +        if (numMoved > 0)
  84.836 +            System.arraycopy(elementData, index+1, elementData, index,
  84.837 +                             numMoved);
  84.838 +        elementData[--elementCount] = null; // Let gc do its work
  84.839 +
  84.840 +        return oldValue;
  84.841 +    }
  84.842 +
  84.843 +    /**
  84.844 +     * Removes all of the elements from this Vector.  The Vector will
  84.845 +     * be empty after this call returns (unless it throws an exception).
  84.846 +     *
  84.847 +     * @since 1.2
  84.848 +     */
  84.849 +    public void clear() {
  84.850 +        removeAllElements();
  84.851 +    }
  84.852 +
  84.853 +    // Bulk Operations
  84.854 +
  84.855 +    /**
  84.856 +     * Returns true if this Vector contains all of the elements in the
  84.857 +     * specified Collection.
  84.858 +     *
  84.859 +     * @param   c a collection whose elements will be tested for containment
  84.860 +     *          in this Vector
  84.861 +     * @return true if this Vector contains all of the elements in the
  84.862 +     *         specified collection
  84.863 +     * @throws NullPointerException if the specified collection is null
  84.864 +     */
  84.865 +    public synchronized boolean containsAll(Collection<?> c) {
  84.866 +        return super.containsAll(c);
  84.867 +    }
  84.868 +
  84.869 +    /**
  84.870 +     * Appends all of the elements in the specified Collection to the end of
  84.871 +     * this Vector, in the order that they are returned by the specified
  84.872 +     * Collection's Iterator.  The behavior of this operation is undefined if
  84.873 +     * the specified Collection is modified while the operation is in progress.
  84.874 +     * (This implies that the behavior of this call is undefined if the
  84.875 +     * specified Collection is this Vector, and this Vector is nonempty.)
  84.876 +     *
  84.877 +     * @param c elements to be inserted into this Vector
  84.878 +     * @return {@code true} if this Vector changed as a result of the call
  84.879 +     * @throws NullPointerException if the specified collection is null
  84.880 +     * @since 1.2
  84.881 +     */
  84.882 +    public synchronized boolean addAll(Collection<? extends E> c) {
  84.883 +        modCount++;
  84.884 +        Object[] a = c.toArray();
  84.885 +        int numNew = a.length;
  84.886 +        ensureCapacityHelper(elementCount + numNew);
  84.887 +        System.arraycopy(a, 0, elementData, elementCount, numNew);
  84.888 +        elementCount += numNew;
  84.889 +        return numNew != 0;
  84.890 +    }
  84.891 +
  84.892 +    /**
  84.893 +     * Removes from this Vector all of its elements that are contained in the
  84.894 +     * specified Collection.
  84.895 +     *
  84.896 +     * @param c a collection of elements to be removed from the Vector
  84.897 +     * @return true if this Vector changed as a result of the call
  84.898 +     * @throws ClassCastException if the types of one or more elements
  84.899 +     *         in this vector are incompatible with the specified
  84.900 +     *         collection
  84.901 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  84.902 +     * @throws NullPointerException if this vector contains one or more null
  84.903 +     *         elements and the specified collection does not support null
  84.904 +     *         elements
  84.905 +     * (<a href="Collection.html#optional-restrictions">optional</a>),
  84.906 +     *         or if the specified collection is null
  84.907 +     * @since 1.2
  84.908 +     */
  84.909 +    public synchronized boolean removeAll(Collection<?> c) {
  84.910 +        return super.removeAll(c);
  84.911 +    }
  84.912 +
  84.913 +    /**
  84.914 +     * Retains only the elements in this Vector that are contained in the
  84.915 +     * specified Collection.  In other words, removes from this Vector all
  84.916 +     * of its elements that are not contained in the specified Collection.
  84.917 +     *
  84.918 +     * @param c a collection of elements to be retained in this Vector
  84.919 +     *          (all other elements are removed)
  84.920 +     * @return true if this Vector changed as a result of the call
  84.921 +     * @throws ClassCastException if the types of one or more elements
  84.922 +     *         in this vector are incompatible with the specified
  84.923 +     *         collection
  84.924 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
  84.925 +     * @throws NullPointerException if this vector contains one or more null
  84.926 +     *         elements and the specified collection does not support null
  84.927 +     *         elements
  84.928 +     *         (<a href="Collection.html#optional-restrictions">optional</a>),
  84.929 +     *         or if the specified collection is null
  84.930 +     * @since 1.2
  84.931 +     */
  84.932 +    public synchronized boolean retainAll(Collection<?> c) {
  84.933 +        return super.retainAll(c);
  84.934 +    }
  84.935 +
  84.936 +    /**
  84.937 +     * Inserts all of the elements in the specified Collection into this
  84.938 +     * Vector at the specified position.  Shifts the element currently at
  84.939 +     * that position (if any) and any subsequent elements to the right
  84.940 +     * (increases their indices).  The new elements will appear in the Vector
  84.941 +     * in the order that they are returned by the specified Collection's
  84.942 +     * iterator.
  84.943 +     *
  84.944 +     * @param index index at which to insert the first element from the
  84.945 +     *              specified collection
  84.946 +     * @param c elements to be inserted into this Vector
  84.947 +     * @return {@code true} if this Vector changed as a result of the call
  84.948 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
  84.949 +     *         ({@code index < 0 || index > size()})
  84.950 +     * @throws NullPointerException if the specified collection is null
  84.951 +     * @since 1.2
  84.952 +     */
  84.953 +    public synchronized boolean addAll(int index, Collection<? extends E> c) {
  84.954 +        modCount++;
  84.955 +        if (index < 0 || index > elementCount)
  84.956 +            throw new ArrayIndexOutOfBoundsException(index);
  84.957 +
  84.958 +        Object[] a = c.toArray();
  84.959 +        int numNew = a.length;
  84.960 +        ensureCapacityHelper(elementCount + numNew);
  84.961 +
  84.962 +        int numMoved = elementCount - index;
  84.963 +        if (numMoved > 0)
  84.964 +            System.arraycopy(elementData, index, elementData, index + numNew,
  84.965 +                             numMoved);
  84.966 +
  84.967 +        System.arraycopy(a, 0, elementData, index, numNew);
  84.968 +        elementCount += numNew;
  84.969 +        return numNew != 0;
  84.970 +    }
  84.971 +
  84.972 +    /**
  84.973 +     * Compares the specified Object with this Vector for equality.  Returns
  84.974 +     * true if and only if the specified Object is also a List, both Lists
  84.975 +     * have the same size, and all corresponding pairs of elements in the two
  84.976 +     * Lists are <em>equal</em>.  (Two elements {@code e1} and
  84.977 +     * {@code e2} are <em>equal</em> if {@code (e1==null ? e2==null :
  84.978 +     * e1.equals(e2))}.)  In other words, two Lists are defined to be
  84.979 +     * equal if they contain the same elements in the same order.
  84.980 +     *
  84.981 +     * @param o the Object to be compared for equality with this Vector
  84.982 +     * @return true if the specified Object is equal to this Vector
  84.983 +     */
  84.984 +    public synchronized boolean equals(Object o) {
  84.985 +        return super.equals(o);
  84.986 +    }
  84.987 +
  84.988 +    /**
  84.989 +     * Returns the hash code value for this Vector.
  84.990 +     */
  84.991 +    public synchronized int hashCode() {
  84.992 +        return super.hashCode();
  84.993 +    }
  84.994 +
  84.995 +    /**
  84.996 +     * Returns a string representation of this Vector, containing
  84.997 +     * the String representation of each element.
  84.998 +     */
  84.999 +    public synchronized String toString() {
 84.1000 +        return super.toString();
 84.1001 +    }
 84.1002 +
 84.1003 +    /**
 84.1004 +     * Returns a view of the portion of this List between fromIndex,
 84.1005 +     * inclusive, and toIndex, exclusive.  (If fromIndex and toIndex are
 84.1006 +     * equal, the returned List is empty.)  The returned List is backed by this
 84.1007 +     * List, so changes in the returned List are reflected in this List, and
 84.1008 +     * vice-versa.  The returned List supports all of the optional List
 84.1009 +     * operations supported by this List.
 84.1010 +     *
 84.1011 +     * <p>This method eliminates the need for explicit range operations (of
 84.1012 +     * the sort that commonly exist for arrays).  Any operation that expects
 84.1013 +     * a List can be used as a range operation by operating on a subList view
 84.1014 +     * instead of a whole List.  For example, the following idiom
 84.1015 +     * removes a range of elements from a List:
 84.1016 +     * <pre>
 84.1017 +     *      list.subList(from, to).clear();
 84.1018 +     * </pre>
 84.1019 +     * Similar idioms may be constructed for indexOf and lastIndexOf,
 84.1020 +     * and all of the algorithms in the Collections class can be applied to
 84.1021 +     * a subList.
 84.1022 +     *
 84.1023 +     * <p>The semantics of the List returned by this method become undefined if
 84.1024 +     * the backing list (i.e., this List) is <i>structurally modified</i> in
 84.1025 +     * any way other than via the returned List.  (Structural modifications are
 84.1026 +     * those that change the size of the List, or otherwise perturb it in such
 84.1027 +     * a fashion that iterations in progress may yield incorrect results.)
 84.1028 +     *
 84.1029 +     * @param fromIndex low endpoint (inclusive) of the subList
 84.1030 +     * @param toIndex high endpoint (exclusive) of the subList
 84.1031 +     * @return a view of the specified range within this List
 84.1032 +     * @throws IndexOutOfBoundsException if an endpoint index value is out of range
 84.1033 +     *         {@code (fromIndex < 0 || toIndex > size)}
 84.1034 +     * @throws IllegalArgumentException if the endpoint indices are out of order
 84.1035 +     *         {@code (fromIndex > toIndex)}
 84.1036 +     */
 84.1037 +    public synchronized List<E> subList(int fromIndex, int toIndex) {
 84.1038 +        return Collections.synchronizedList(super.subList(fromIndex, toIndex),
 84.1039 +                                            this);
 84.1040 +    }
 84.1041 +
 84.1042 +    /**
 84.1043 +     * Removes from this list all of the elements whose index is between
 84.1044 +     * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
 84.1045 +     * Shifts any succeeding elements to the left (reduces their index).
 84.1046 +     * This call shortens the list by {@code (toIndex - fromIndex)} elements.
 84.1047 +     * (If {@code toIndex==fromIndex}, this operation has no effect.)
 84.1048 +     */
 84.1049 +    protected synchronized void removeRange(int fromIndex, int toIndex) {
 84.1050 +        modCount++;
 84.1051 +        int numMoved = elementCount - toIndex;
 84.1052 +        System.arraycopy(elementData, toIndex, elementData, fromIndex,
 84.1053 +                         numMoved);
 84.1054 +
 84.1055 +        // Let gc do its work
 84.1056 +        int newElementCount = elementCount - (toIndex-fromIndex);
 84.1057 +        while (elementCount != newElementCount)
 84.1058 +            elementData[--elementCount] = null;
 84.1059 +    }
 84.1060 +
 84.1061 +    /**
 84.1062 +     * Returns a list iterator over the elements in this list (in proper
 84.1063 +     * sequence), starting at the specified position in the list.
 84.1064 +     * The specified index indicates the first element that would be
 84.1065 +     * returned by an initial call to {@link ListIterator#next next}.
 84.1066 +     * An initial call to {@link ListIterator#previous previous} would
 84.1067 +     * return the element with the specified index minus one.
 84.1068 +     *
 84.1069 +     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
 84.1070 +     *
 84.1071 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 84.1072 +     */
 84.1073 +    public synchronized ListIterator<E> listIterator(int index) {
 84.1074 +        if (index < 0 || index > elementCount)
 84.1075 +            throw new IndexOutOfBoundsException("Index: "+index);
 84.1076 +        return new ListItr(index);
 84.1077 +    }
 84.1078 +
 84.1079 +    /**
 84.1080 +     * Returns a list iterator over the elements in this list (in proper
 84.1081 +     * sequence).
 84.1082 +     *
 84.1083 +     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
 84.1084 +     *
 84.1085 +     * @see #listIterator(int)
 84.1086 +     */
 84.1087 +    public synchronized ListIterator<E> listIterator() {
 84.1088 +        return new ListItr(0);
 84.1089 +    }
 84.1090 +
 84.1091 +    /**
 84.1092 +     * Returns an iterator over the elements in this list in proper sequence.
 84.1093 +     *
 84.1094 +     * <p>The returned iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
 84.1095 +     *
 84.1096 +     * @return an iterator over the elements in this list in proper sequence
 84.1097 +     */
 84.1098 +    public synchronized Iterator<E> iterator() {
 84.1099 +        return new Itr();
 84.1100 +    }
 84.1101 +
 84.1102 +    /**
 84.1103 +     * An optimized version of AbstractList.Itr
 84.1104 +     */
 84.1105 +    private class Itr implements Iterator<E> {
 84.1106 +        int cursor;       // index of next element to return
 84.1107 +        int lastRet = -1; // index of last element returned; -1 if no such
 84.1108 +        int expectedModCount = modCount;
 84.1109 +
 84.1110 +        public boolean hasNext() {
 84.1111 +            // Racy but within spec, since modifications are checked
 84.1112 +            // within or after synchronization in next/previous
 84.1113 +            return cursor != elementCount;
 84.1114 +        }
 84.1115 +
 84.1116 +        public E next() {
 84.1117 +            synchronized (Vector.this) {
 84.1118 +                checkForComodification();
 84.1119 +                int i = cursor;
 84.1120 +                if (i >= elementCount)
 84.1121 +                    throw new NoSuchElementException();
 84.1122 +                cursor = i + 1;
 84.1123 +                return elementData(lastRet = i);
 84.1124 +            }
 84.1125 +        }
 84.1126 +
 84.1127 +        public void remove() {
 84.1128 +            if (lastRet == -1)
 84.1129 +                throw new IllegalStateException();
 84.1130 +            synchronized (Vector.this) {
 84.1131 +                checkForComodification();
 84.1132 +                Vector.this.remove(lastRet);
 84.1133 +                expectedModCount = modCount;
 84.1134 +            }
 84.1135 +            cursor = lastRet;
 84.1136 +            lastRet = -1;
 84.1137 +        }
 84.1138 +
 84.1139 +        final void checkForComodification() {
 84.1140 +            if (modCount != expectedModCount)
 84.1141 +                throw new ConcurrentModificationException();
 84.1142 +        }
 84.1143 +    }
 84.1144 +
 84.1145 +    /**
 84.1146 +     * An optimized version of AbstractList.ListItr
 84.1147 +     */
 84.1148 +    final class ListItr extends Itr implements ListIterator<E> {
 84.1149 +        ListItr(int index) {
 84.1150 +            super();
 84.1151 +            cursor = index;
 84.1152 +        }
 84.1153 +
 84.1154 +        public boolean hasPrevious() {
 84.1155 +            return cursor != 0;
 84.1156 +        }
 84.1157 +
 84.1158 +        public int nextIndex() {
 84.1159 +            return cursor;
 84.1160 +        }
 84.1161 +
 84.1162 +        public int previousIndex() {
 84.1163 +            return cursor - 1;
 84.1164 +        }
 84.1165 +
 84.1166 +        public E previous() {
 84.1167 +            synchronized (Vector.this) {
 84.1168 +                checkForComodification();
 84.1169 +                int i = cursor - 1;
 84.1170 +                if (i < 0)
 84.1171 +                    throw new NoSuchElementException();
 84.1172 +                cursor = i;
 84.1173 +                return elementData(lastRet = i);
 84.1174 +            }
 84.1175 +        }
 84.1176 +
 84.1177 +        public void set(E e) {
 84.1178 +            if (lastRet == -1)
 84.1179 +                throw new IllegalStateException();
 84.1180 +            synchronized (Vector.this) {
 84.1181 +                checkForComodification();
 84.1182 +                Vector.this.set(lastRet, e);
 84.1183 +            }
 84.1184 +        }
 84.1185 +
 84.1186 +        public void add(E e) {
 84.1187 +            int i = cursor;
 84.1188 +            synchronized (Vector.this) {
 84.1189 +                checkForComodification();
 84.1190 +                Vector.this.add(i, e);
 84.1191 +                expectedModCount = modCount;
 84.1192 +            }
 84.1193 +            cursor = i + 1;
 84.1194 +            lastRet = -1;
 84.1195 +        }
 84.1196 +    }
 84.1197 +}
    85.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    85.2 +++ b/emul/compact/src/main/java/java/util/concurrent/TimeUnit.java	Sun Feb 03 07:48:42 2013 +0100
    85.3 @@ -0,0 +1,367 @@
    85.4 +/*
    85.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    85.6 + *
    85.7 + * This code is free software; you can redistribute it and/or modify it
    85.8 + * under the terms of the GNU General Public License version 2 only, as
    85.9 + * published by the Free Software Foundation.  Oracle designates this
   85.10 + * particular file as subject to the "Classpath" exception as provided
   85.11 + * by Oracle in the LICENSE file that accompanied this code.
   85.12 + *
   85.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
   85.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   85.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   85.16 + * version 2 for more details (a copy is included in the LICENSE file that
   85.17 + * accompanied this code).
   85.18 + *
   85.19 + * You should have received a copy of the GNU General Public License version
   85.20 + * 2 along with this work; if not, write to the Free Software Foundation,
   85.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   85.22 + *
   85.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   85.24 + * or visit www.oracle.com if you need additional information or have any
   85.25 + * questions.
   85.26 + */
   85.27 +
   85.28 +/*
   85.29 + * This file is available under and governed by the GNU General Public
   85.30 + * License version 2 only, as published by the Free Software Foundation.
   85.31 + * However, the following notice accompanied the original version of this
   85.32 + * file:
   85.33 + *
   85.34 + * Written by Doug Lea with assistance from members of JCP JSR-166
   85.35 + * Expert Group and released to the public domain, as explained at
   85.36 + * http://creativecommons.org/publicdomain/zero/1.0/
   85.37 + */
   85.38 +
   85.39 +package java.util.concurrent;
   85.40 +
   85.41 +/**
   85.42 + * A <tt>TimeUnit</tt> represents time durations at a given unit of
   85.43 + * granularity and provides utility methods to convert across units,
   85.44 + * and to perform timing and delay operations in these units.  A
   85.45 + * <tt>TimeUnit</tt> does not maintain time information, but only
   85.46 + * helps organize and use time representations that may be maintained
   85.47 + * separately across various contexts.  A nanosecond is defined as one
   85.48 + * thousandth of a microsecond, a microsecond as one thousandth of a
   85.49 + * millisecond, a millisecond as one thousandth of a second, a minute
   85.50 + * as sixty seconds, an hour as sixty minutes, and a day as twenty four
   85.51 + * hours.
   85.52 + *
   85.53 + * <p>A <tt>TimeUnit</tt> is mainly used to inform time-based methods
   85.54 + * how a given timing parameter should be interpreted. For example,
   85.55 + * the following code will timeout in 50 milliseconds if the {@link
   85.56 + * java.util.concurrent.locks.Lock lock} is not available:
   85.57 + *
   85.58 + * <pre>  Lock lock = ...;
   85.59 + *  if (lock.tryLock(50L, TimeUnit.MILLISECONDS)) ...
   85.60 + * </pre>
   85.61 + * while this code will timeout in 50 seconds:
   85.62 + * <pre>
   85.63 + *  Lock lock = ...;
   85.64 + *  if (lock.tryLock(50L, TimeUnit.SECONDS)) ...
   85.65 + * </pre>
   85.66 + *
   85.67 + * Note however, that there is no guarantee that a particular timeout
   85.68 + * implementation will be able to notice the passage of time at the
   85.69 + * same granularity as the given <tt>TimeUnit</tt>.
   85.70 + *
   85.71 + * @since 1.5
   85.72 + * @author Doug Lea
   85.73 + */
   85.74 +public enum TimeUnit {
   85.75 +    NANOSECONDS {
   85.76 +        public long toNanos(long d)   { return d; }
   85.77 +        public long toMicros(long d)  { return d/(C1/C0); }
   85.78 +        public long toMillis(long d)  { return d/(C2/C0); }
   85.79 +        public long toSeconds(long d) { return d/(C3/C0); }
   85.80 +        public long toMinutes(long d) { return d/(C4/C0); }
   85.81 +        public long toHours(long d)   { return d/(C5/C0); }
   85.82 +        public long toDays(long d)    { return d/(C6/C0); }
   85.83 +        public long convert(long d, TimeUnit u) { return u.toNanos(d); }
   85.84 +        int excessNanos(long d, long m) { return (int)(d - (m*C2)); }
   85.85 +    },
   85.86 +    MICROSECONDS {
   85.87 +        public long toNanos(long d)   { return x(d, C1/C0, MAX/(C1/C0)); }
   85.88 +        public long toMicros(long d)  { return d; }
   85.89 +        public long toMillis(long d)  { return d/(C2/C1); }
   85.90 +        public long toSeconds(long d) { return d/(C3/C1); }
   85.91 +        public long toMinutes(long d) { return d/(C4/C1); }
   85.92 +        public long toHours(long d)   { return d/(C5/C1); }
   85.93 +        public long toDays(long d)    { return d/(C6/C1); }
   85.94 +        public long convert(long d, TimeUnit u) { return u.toMicros(d); }
   85.95 +        int excessNanos(long d, long m) { return (int)((d*C1) - (m*C2)); }
   85.96 +    },
   85.97 +    MILLISECONDS {
   85.98 +        public long toNanos(long d)   { return x(d, C2/C0, MAX/(C2/C0)); }
   85.99 +        public long toMicros(long d)  { return x(d, C2/C1, MAX/(C2/C1)); }
  85.100 +        public long toMillis(long d)  { return d; }
  85.101 +        public long toSeconds(long d) { return d/(C3/C2); }
  85.102 +        public long toMinutes(long d) { return d/(C4/C2); }
  85.103 +        public long toHours(long d)   { return d/(C5/C2); }
  85.104 +        public long toDays(long d)    { return d/(C6/C2); }
  85.105 +        public long convert(long d, TimeUnit u) { return u.toMillis(d); }
  85.106 +        int excessNanos(long d, long m) { return 0; }
  85.107 +    },
  85.108 +    SECONDS {
  85.109 +        public long toNanos(long d)   { return x(d, C3/C0, MAX/(C3/C0)); }
  85.110 +        public long toMicros(long d)  { return x(d, C3/C1, MAX/(C3/C1)); }
  85.111 +        public long toMillis(long d)  { return x(d, C3/C2, MAX/(C3/C2)); }
  85.112 +        public long toSeconds(long d) { return d; }
  85.113 +        public long toMinutes(long d) { return d/(C4/C3); }
  85.114 +        public long toHours(long d)   { return d/(C5/C3); }
  85.115 +        public long toDays(long d)    { return d/(C6/C3); }
  85.116 +        public long convert(long d, TimeUnit u) { return u.toSeconds(d); }
  85.117 +        int excessNanos(long d, long m) { return 0; }
  85.118 +    },
  85.119 +    MINUTES {
  85.120 +        public long toNanos(long d)   { return x(d, C4/C0, MAX/(C4/C0)); }
  85.121 +        public long toMicros(long d)  { return x(d, C4/C1, MAX/(C4/C1)); }
  85.122 +        public long toMillis(long d)  { return x(d, C4/C2, MAX/(C4/C2)); }
  85.123 +        public long toSeconds(long d) { return x(d, C4/C3, MAX/(C4/C3)); }
  85.124 +        public long toMinutes(long d) { return d; }
  85.125 +        public long toHours(long d)   { return d/(C5/C4); }
  85.126 +        public long toDays(long d)    { return d/(C6/C4); }
  85.127 +        public long convert(long d, TimeUnit u) { return u.toMinutes(d); }
  85.128 +        int excessNanos(long d, long m) { return 0; }
  85.129 +    },
  85.130 +    HOURS {
  85.131 +        public long toNanos(long d)   { return x(d, C5/C0, MAX/(C5/C0)); }
  85.132 +        public long toMicros(long d)  { return x(d, C5/C1, MAX/(C5/C1)); }
  85.133 +        public long toMillis(long d)  { return x(d, C5/C2, MAX/(C5/C2)); }
  85.134 +        public long toSeconds(long d) { return x(d, C5/C3, MAX/(C5/C3)); }
  85.135 +        public long toMinutes(long d) { return x(d, C5/C4, MAX/(C5/C4)); }
  85.136 +        public long toHours(long d)   { return d; }
  85.137 +        public long toDays(long d)    { return d/(C6/C5); }
  85.138 +        public long convert(long d, TimeUnit u) { return u.toHours(d); }
  85.139 +        int excessNanos(long d, long m) { return 0; }
  85.140 +    },
  85.141 +    DAYS {
  85.142 +        public long toNanos(long d)   { return x(d, C6/C0, MAX/(C6/C0)); }
  85.143 +        public long toMicros(long d)  { return x(d, C6/C1, MAX/(C6/C1)); }
  85.144 +        public long toMillis(long d)  { return x(d, C6/C2, MAX/(C6/C2)); }
  85.145 +        public long toSeconds(long d) { return x(d, C6/C3, MAX/(C6/C3)); }
  85.146 +        public long toMinutes(long d) { return x(d, C6/C4, MAX/(C6/C4)); }
  85.147 +        public long toHours(long d)   { return x(d, C6/C5, MAX/(C6/C5)); }
  85.148 +        public long toDays(long d)    { return d; }
  85.149 +        public long convert(long d, TimeUnit u) { return u.toDays(d); }
  85.150 +        int excessNanos(long d, long m) { return 0; }
  85.151 +    };
  85.152 +
  85.153 +    // Handy constants for conversion methods
  85.154 +    static final long C0 = 1L;
  85.155 +    static final long C1 = C0 * 1000L;
  85.156 +    static final long C2 = C1 * 1000L;
  85.157 +    static final long C3 = C2 * 1000L;
  85.158 +    static final long C4 = C3 * 60L;
  85.159 +    static final long C5 = C4 * 60L;
  85.160 +    static final long C6 = C5 * 24L;
  85.161 +
  85.162 +    static final long MAX = Long.MAX_VALUE;
  85.163 +
  85.164 +    /**
  85.165 +     * Scale d by m, checking for overflow.
  85.166 +     * This has a short name to make above code more readable.
  85.167 +     */
  85.168 +    static long x(long d, long m, long over) {
  85.169 +        if (d >  over) return Long.MAX_VALUE;
  85.170 +        if (d < -over) return Long.MIN_VALUE;
  85.171 +        return d * m;
  85.172 +    }
  85.173 +
  85.174 +    // To maintain full signature compatibility with 1.5, and to improve the
  85.175 +    // clarity of the generated javadoc (see 6287639: Abstract methods in
  85.176 +    // enum classes should not be listed as abstract), method convert
  85.177 +    // etc. are not declared abstract but otherwise act as abstract methods.
  85.178 +
  85.179 +    /**
  85.180 +     * Convert the given time duration in the given unit to this
  85.181 +     * unit.  Conversions from finer to coarser granularities
  85.182 +     * truncate, so lose precision. For example converting
  85.183 +     * <tt>999</tt> milliseconds to seconds results in
  85.184 +     * <tt>0</tt>. Conversions from coarser to finer granularities
  85.185 +     * with arguments that would numerically overflow saturate to
  85.186 +     * <tt>Long.MIN_VALUE</tt> if negative or <tt>Long.MAX_VALUE</tt>
  85.187 +     * if positive.
  85.188 +     *
  85.189 +     * <p>For example, to convert 10 minutes to milliseconds, use:
  85.190 +     * <tt>TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES)</tt>
  85.191 +     *
  85.192 +     * @param sourceDuration the time duration in the given <tt>sourceUnit</tt>
  85.193 +     * @param sourceUnit the unit of the <tt>sourceDuration</tt> argument
  85.194 +     * @return the converted duration in this unit,
  85.195 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
  85.196 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
  85.197 +     */
  85.198 +    public long convert(long sourceDuration, TimeUnit sourceUnit) {
  85.199 +        throw new AbstractMethodError();
  85.200 +    }
  85.201 +
  85.202 +    /**
  85.203 +     * Equivalent to <tt>NANOSECONDS.convert(duration, this)</tt>.
  85.204 +     * @param duration the duration
  85.205 +     * @return the converted duration,
  85.206 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
  85.207 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
  85.208 +     * @see #convert
  85.209 +     */
  85.210 +    public long toNanos(long duration) {
  85.211 +        throw new AbstractMethodError();
  85.212 +    }
  85.213 +
  85.214 +    /**
  85.215 +     * Equivalent to <tt>MICROSECONDS.convert(duration, this)</tt>.
  85.216 +     * @param duration the duration
  85.217 +     * @return the converted duration,
  85.218 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
  85.219 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
  85.220 +     * @see #convert
  85.221 +     */
  85.222 +    public long toMicros(long duration) {
  85.223 +        throw new AbstractMethodError();
  85.224 +    }
  85.225 +
  85.226 +    /**
  85.227 +     * Equivalent to <tt>MILLISECONDS.convert(duration, this)</tt>.
  85.228 +     * @param duration the duration
  85.229 +     * @return the converted duration,
  85.230 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
  85.231 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
  85.232 +     * @see #convert
  85.233 +     */
  85.234 +    public long toMillis(long duration) {
  85.235 +        throw new AbstractMethodError();
  85.236 +    }
  85.237 +
  85.238 +    /**
  85.239 +     * Equivalent to <tt>SECONDS.convert(duration, this)</tt>.
  85.240 +     * @param duration the duration
  85.241 +     * @return the converted duration,
  85.242 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
  85.243 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
  85.244 +     * @see #convert
  85.245 +     */
  85.246 +    public long toSeconds(long duration) {
  85.247 +        throw new AbstractMethodError();
  85.248 +    }
  85.249 +
  85.250 +    /**
  85.251 +     * Equivalent to <tt>MINUTES.convert(duration, this)</tt>.
  85.252 +     * @param duration the duration
  85.253 +     * @return the converted duration,
  85.254 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
  85.255 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
  85.256 +     * @see #convert
  85.257 +     * @since 1.6
  85.258 +     */
  85.259 +    public long toMinutes(long duration) {
  85.260 +        throw new AbstractMethodError();
  85.261 +    }
  85.262 +
  85.263 +    /**
  85.264 +     * Equivalent to <tt>HOURS.convert(duration, this)</tt>.
  85.265 +     * @param duration the duration
  85.266 +     * @return the converted duration,
  85.267 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
  85.268 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
  85.269 +     * @see #convert
  85.270 +     * @since 1.6
  85.271 +     */
  85.272 +    public long toHours(long duration) {
  85.273 +        throw new AbstractMethodError();
  85.274 +    }
  85.275 +
  85.276 +    /**
  85.277 +     * Equivalent to <tt>DAYS.convert(duration, this)</tt>.
  85.278 +     * @param duration the duration
  85.279 +     * @return the converted duration
  85.280 +     * @see #convert
  85.281 +     * @since 1.6
  85.282 +     */
  85.283 +    public long toDays(long duration) {
  85.284 +        throw new AbstractMethodError();
  85.285 +    }
  85.286 +
  85.287 +    /**
  85.288 +     * Utility to compute the excess-nanosecond argument to wait,
  85.289 +     * sleep, join.
  85.290 +     * @param d the duration
  85.291 +     * @param m the number of milliseconds
  85.292 +     * @return the number of nanoseconds
  85.293 +     */
  85.294 +    abstract int excessNanos(long d, long m);
  85.295 +
  85.296 +    /**
  85.297 +     * Performs a timed {@link Object#wait(long, int) Object.wait}
  85.298 +     * using this time unit.
  85.299 +     * This is a convenience method that converts timeout arguments
  85.300 +     * into the form required by the <tt>Object.wait</tt> method.
  85.301 +     *
  85.302 +     * <p>For example, you could implement a blocking <tt>poll</tt>
  85.303 +     * method (see {@link BlockingQueue#poll BlockingQueue.poll})
  85.304 +     * using:
  85.305 +     *
  85.306 +     *  <pre> {@code
  85.307 +     * public synchronized Object poll(long timeout, TimeUnit unit)
  85.308 +     *     throws InterruptedException {
  85.309 +     *   while (empty) {
  85.310 +     *     unit.timedWait(this, timeout);
  85.311 +     *     ...
  85.312 +     *   }
  85.313 +     * }}</pre>
  85.314 +     *
  85.315 +     * @param obj the object to wait on
  85.316 +     * @param timeout the maximum time to wait. If less than
  85.317 +     * or equal to zero, do not wait at all.
  85.318 +     * @throws InterruptedException if interrupted while waiting
  85.319 +     */
  85.320 +    public void timedWait(Object obj, long timeout)
  85.321 +            throws InterruptedException {
  85.322 +        if (timeout > 0) {
  85.323 +            long ms = toMillis(timeout);
  85.324 +            int ns = excessNanos(timeout, ms);
  85.325 +            obj.wait(ms, ns);
  85.326 +        }
  85.327 +    }
  85.328 +
  85.329 +    /**
  85.330 +     * Performs a timed {@link Thread#join(long, int) Thread.join}
  85.331 +     * using this time unit.
  85.332 +     * This is a convenience method that converts time arguments into the
  85.333 +     * form required by the <tt>Thread.join</tt> method.
  85.334 +     *
  85.335 +     * @param thread the thread to wait for
  85.336 +     * @param timeout the maximum time to wait. If less than
  85.337 +     * or equal to zero, do not wait at all.
  85.338 +     * @throws InterruptedException if interrupted while waiting
  85.339 +     */
  85.340 +//    public void timedJoin(Thread thread, long timeout)
  85.341 +//            throws InterruptedException {
  85.342 +//        if (timeout > 0) {
  85.343 +//            long ms = toMillis(timeout);
  85.344 +//            int ns = excessNanos(timeout, ms);
  85.345 +//            thread.join(ms, ns);
  85.346 +//        }
  85.347 +//    }
  85.348 +
  85.349 +    /**
  85.350 +     * Performs a {@link Thread#sleep(long, int) Thread.sleep} using
  85.351 +     * this time unit.
  85.352 +     * This is a convenience method that converts time arguments into the
  85.353 +     * form required by the <tt>Thread.sleep</tt> method.
  85.354 +     *
  85.355 +     * @param timeout the minimum time to sleep. If less than
  85.356 +     * or equal to zero, do not sleep at all.
  85.357 +     * @throws InterruptedException if interrupted while sleeping
  85.358 +     */
  85.359 +    public void sleep(long timeout) throws InterruptedException {
  85.360 +        if (timeout > 0) {
  85.361 +            long ms = toMillis(timeout);
  85.362 +            int ns = excessNanos(timeout, ms);
  85.363 +            Object o = new Object();
  85.364 +            synchronized (o) {
  85.365 +                o.wait(ms, ns);
  85.366 +            }
  85.367 +        }
  85.368 +    }
  85.369 +
  85.370 +}
    86.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    86.2 +++ b/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/CollectionsTest.java	Sun Feb 03 07:48:42 2013 +0100
    86.3 @@ -0,0 +1,107 @@
    86.4 +/**
    86.5 + * Back 2 Browser Bytecode Translator
    86.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    86.7 + *
    86.8 + * This program is free software: you can redistribute it and/or modify
    86.9 + * it under the terms of the GNU General Public License as published by
   86.10 + * the Free Software Foundation, version 2 of the License.
   86.11 + *
   86.12 + * This program is distributed in the hope that it will be useful,
   86.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   86.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   86.15 + * GNU General Public License for more details.
   86.16 + *
   86.17 + * You should have received a copy of the GNU General Public License
   86.18 + * along with this program. Look for COPYING file in the top folder.
   86.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   86.20 + */
   86.21 +package org.apidesign.bck2brwsr.compact.tck;
   86.22 +
   86.23 +import java.util.ArrayList;
   86.24 +import java.util.Arrays;
   86.25 +import java.util.Collection;
   86.26 +import java.util.Comparator;
   86.27 +import java.util.HashMap;
   86.28 +import java.util.HashSet;
   86.29 +import java.util.List;
   86.30 +import java.util.Map;
   86.31 +import java.util.Map.Entry;
   86.32 +import java.util.Vector;
   86.33 +import org.apidesign.bck2brwsr.vmtest.Compare;
   86.34 +import org.apidesign.bck2brwsr.vmtest.VMTest;
   86.35 +import org.testng.annotations.Factory;
   86.36 +
   86.37 +/**
   86.38 + *
   86.39 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   86.40 + */
   86.41 +public class CollectionsTest {
   86.42 +    @Compare public String sortStringsInArray() {
   86.43 +        List<String> list = new ArrayList<>();
   86.44 +        list.add("one");
   86.45 +        list.add("two");
   86.46 +        list.add("three");
   86.47 +        list.add("four");
   86.48 +        list.add("five");
   86.49 +        list.add("six");
   86.50 +        list.add("seven");
   86.51 +        list.add("eight");
   86.52 +        list.add("nine");
   86.53 +        list.add("ten");
   86.54 +        
   86.55 +        String[] arr = list.toArray(new String[list.size()]);
   86.56 +        Arrays.sort(arr);
   86.57 +        
   86.58 +        return Arrays.asList(arr).toString();
   86.59 +    }
   86.60 +    
   86.61 +    @Compare public String sortStringsInHashSet() {
   86.62 +        Collection<String> list = new HashSet<>();
   86.63 +        list.add("one");
   86.64 +        list.add("two");
   86.65 +        list.add("three");
   86.66 +        list.add("four");
   86.67 +        list.add("five");
   86.68 +        list.add("six");
   86.69 +        list.add("seven");
   86.70 +        list.add("eight");
   86.71 +        list.add("nine");
   86.72 +        list.add("ten");
   86.73 +        
   86.74 +        String[] arr = list.toArray(new String[0]);
   86.75 +        Arrays.sort(arr);
   86.76 +        
   86.77 +        return Arrays.asList(arr).toString();
   86.78 +    }
   86.79 +
   86.80 +    @SuppressWarnings("unchecked")
   86.81 +    @Compare public String sortStringsInHashMapWithComparator() {
   86.82 +        class C implements Comparator<Map.Entry<String,Integer>> {
   86.83 +            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
   86.84 +                return o1.getKey().compareTo(o2.getKey());
   86.85 +            }
   86.86 +        }
   86.87 +        
   86.88 +        Map<String,Integer> map = new HashMap<>();
   86.89 +        map.put("one", 1);
   86.90 +        map.put("two", 2);
   86.91 +        map.put("three", 3);
   86.92 +        map.put("four", 4);
   86.93 +        map.put("five", 5);
   86.94 +        map.put("six", 6);
   86.95 +        map.put("seven", 7);
   86.96 +        map.put("eight", 8);
   86.97 +        map.put("nine", 9);
   86.98 +        map.put("ten", 10);
   86.99 +        
  86.100 +        List<Entry<String,Integer>> arr = new Vector<>();
  86.101 +        arr.addAll(map.entrySet());
  86.102 +        return arr.toString();
  86.103 +    }
  86.104 +    
  86.105 +    @Factory
  86.106 +    public static Object[] create() {
  86.107 +        return VMTest.create(CollectionsTest.class);
  86.108 +    }
  86.109 +    
  86.110 +}
    87.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    87.2 +++ b/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/RandomTest.java	Sun Feb 03 07:48:42 2013 +0100
    87.3 @@ -0,0 +1,40 @@
    87.4 +/**
    87.5 + * Back 2 Browser Bytecode Translator
    87.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    87.7 + *
    87.8 + * This program is free software: you can redistribute it and/or modify
    87.9 + * it under the terms of the GNU General Public License as published by
   87.10 + * the Free Software Foundation, version 2 of the License.
   87.11 + *
   87.12 + * This program is distributed in the hope that it will be useful,
   87.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   87.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   87.15 + * GNU General Public License for more details.
   87.16 + *
   87.17 + * You should have received a copy of the GNU General Public License
   87.18 + * along with this program. Look for COPYING file in the top folder.
   87.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   87.20 + */
   87.21 +package org.apidesign.bck2brwsr.compact.tck;
   87.22 +
   87.23 +import java.util.Random;
   87.24 +import org.apidesign.bck2brwsr.vmtest.Compare;
   87.25 +import org.apidesign.bck2brwsr.vmtest.VMTest;
   87.26 +import org.testng.annotations.Factory;
   87.27 +
   87.28 +/**
   87.29 + *
   87.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   87.31 + */
   87.32 +public class RandomTest {
   87.33 +    @Compare public boolean canInstantiateRandom() {
   87.34 +        Random r = new Random();
   87.35 +        r.nextInt();
   87.36 +        return r != null;
   87.37 +    }
   87.38 +
   87.39 +    
   87.40 +    @Factory public static Object[] create() {
   87.41 +        return VMTest.create(RandomTest.class);
   87.42 +    }
   87.43 +}
    88.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    88.2 +++ b/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java	Sun Feb 03 07:48:42 2013 +0100
    88.3 @@ -0,0 +1,60 @@
    88.4 +/**
    88.5 + * Back 2 Browser Bytecode Translator
    88.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    88.7 + *
    88.8 + * This program is free software: you can redistribute it and/or modify
    88.9 + * it under the terms of the GNU General Public License as published by
   88.10 + * the Free Software Foundation, version 2 of the License.
   88.11 + *
   88.12 + * This program is distributed in the hope that it will be useful,
   88.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   88.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   88.15 + * GNU General Public License for more details.
   88.16 + *
   88.17 + * You should have received a copy of the GNU General Public License
   88.18 + * along with this program. Look for COPYING file in the top folder.
   88.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   88.20 + */
   88.21 +package org.apidesign.bck2brwsr.compact.tck;
   88.22 +
   88.23 +import java.io.ByteArrayInputStream;
   88.24 +import java.io.IOException;
   88.25 +import java.io.InputStreamReader;
   88.26 +import java.util.Arrays;
   88.27 +import org.apidesign.bck2brwsr.vmtest.Compare;
   88.28 +import org.apidesign.bck2brwsr.vmtest.VMTest;
   88.29 +import org.testng.annotations.Factory;
   88.30 +
   88.31 +/**
   88.32 + *
   88.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   88.34 + */
   88.35 +public class ReaderTest {
   88.36 +    @Compare public String readUTFString() throws IOException {
   88.37 +        byte[] arr = { 
   88.38 +            (byte)-59, (byte)-67, (byte)108, (byte)117, (byte)-59, (byte)-91, 
   88.39 +            (byte)111, (byte)117, (byte)-60, (byte)-115, (byte)107, (byte)-61, 
   88.40 +            (byte)-67, (byte)32, (byte)107, (byte)-59, (byte)-81, (byte)-59, 
   88.41 +            (byte)-120 
   88.42 +        };
   88.43 +        ByteArrayInputStream is = new ByteArrayInputStream(arr);
   88.44 +        InputStreamReader r = new InputStreamReader(is);
   88.45 +        
   88.46 +        StringBuilder sb = new StringBuilder();
   88.47 +        for (;;) {
   88.48 +            int ch = r.read();
   88.49 +            if (ch == -1) {
   88.50 +                break;
   88.51 +            }
   88.52 +            sb.append((char)ch);
   88.53 +        }
   88.54 +        return sb.toString().toString();
   88.55 +    }
   88.56 +    @Compare public String stringToBytes() {
   88.57 +        return Arrays.toString("Žluťoučký kůň".getBytes());
   88.58 +    }
   88.59 +    
   88.60 +    @Factory public static Object[] create() {
   88.61 +        return VMTest.create(ReaderTest.class);
   88.62 +    }
   88.63 +}
    89.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    89.2 +++ b/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ServiceLoaderTest.java	Sun Feb 03 07:48:42 2013 +0100
    89.3 @@ -0,0 +1,61 @@
    89.4 +/**
    89.5 + * Back 2 Browser Bytecode Translator
    89.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    89.7 + *
    89.8 + * This program is free software: you can redistribute it and/or modify
    89.9 + * it under the terms of the GNU General Public License as published by
   89.10 + * the Free Software Foundation, version 2 of the License.
   89.11 + *
   89.12 + * This program is distributed in the hope that it will be useful,
   89.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   89.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   89.15 + * GNU General Public License for more details.
   89.16 + *
   89.17 + * You should have received a copy of the GNU General Public License
   89.18 + * along with this program. Look for COPYING file in the top folder.
   89.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   89.20 + */
   89.21 +package org.apidesign.bck2brwsr.compact.tck;
   89.22 +
   89.23 +import java.io.IOException;
   89.24 +import java.util.ServiceLoader;
   89.25 +import org.apidesign.bck2brwsr.vmtest.Compare;
   89.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
   89.27 +import org.openide.util.lookup.ServiceProvider;
   89.28 +import org.testng.annotations.Factory;
   89.29 +
   89.30 +/**
   89.31 + *
   89.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   89.33 + */
   89.34 +public class ServiceLoaderTest {
   89.35 +    @Compare//(scripting = false) 
   89.36 +    public Object findsIOException() {
   89.37 +//      delayStart();
   89.38 +        for (IOException e : ServiceLoader.load(IOException.class)) {
   89.39 +            return "Found service: " + e.getClass().getName();
   89.40 +        }
   89.41 +        return null;
   89.42 +    }
   89.43 +/*    
   89.44 +    @org.apidesign.bck2brwsr.core.JavaScriptBody(args = { "a" }, body = "alert(a);")
   89.45 +    private static void alert(String a) {
   89.46 +    }
   89.47 +    private void delayStart() {
   89.48 +        for (int i = 0; i < 10; i++) {
   89.49 +            alert("State: " + i);
   89.50 +            for (int j = 0; j < 493208409; j++) ;
   89.51 +        }
   89.52 +    }
   89.53 +*/
   89.54 +    
   89.55 +    @Factory
   89.56 +    public static Object[] create() {
   89.57 +        return VMTest.create(ServiceLoaderTest.class);
   89.58 +    }
   89.59 +
   89.60 +    
   89.61 +    @ServiceProvider(service = IOException.class)
   89.62 +    public static class MyException extends IOException {
   89.63 +    }
   89.64 +}
    90.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    90.2 +++ b/emul/mini/pom.xml	Sun Feb 03 07:48:42 2013 +0100
    90.3 @@ -0,0 +1,42 @@
    90.4 +<?xml version="1.0"?>
    90.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"
    90.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    90.7 +  <modelVersion>4.0.0</modelVersion>
    90.8 +  <parent>
    90.9 +    <groupId>org.apidesign.bck2brwsr</groupId>
   90.10 +    <artifactId>emul.pom</artifactId>
   90.11 +    <version>0.3-SNAPSHOT</version>
   90.12 +  </parent>
   90.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
   90.14 +  <artifactId>emul.mini</artifactId>
   90.15 +  <version>0.3-SNAPSHOT</version>
   90.16 +  <name>Minimal API Profile</name>
   90.17 +  <url>http://maven.apache.org</url>
   90.18 +  <properties>
   90.19 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   90.20 +  </properties>
   90.21 +  <dependencies>
   90.22 +    <dependency>
   90.23 +      <groupId>org.apidesign.bck2brwsr</groupId>
   90.24 +      <artifactId>core</artifactId>
   90.25 +      <version>0.3-SNAPSHOT</version>
   90.26 +      <type>jar</type>
   90.27 +    </dependency>
   90.28 +  </dependencies>
   90.29 +  <build>
   90.30 +      <plugins>
   90.31 +          <plugin>
   90.32 +              <groupId>org.apache.maven.plugins</groupId>
   90.33 +              <artifactId>maven-compiler-plugin</artifactId>
   90.34 +              <version>2.5.1</version>
   90.35 +              <configuration>
   90.36 +                  <compilerArguments>
   90.37 +                      <bootclasspath>netbeans.ignore.jdk.bootsclasspath</bootclasspath>
   90.38 +                  </compilerArguments>
   90.39 +                 <source>1.7</source>
   90.40 +                 <target>1.7</target>
   90.41 +              </configuration>
   90.42 +          </plugin>
   90.43 +      </plugins>
   90.44 +  </build>
   90.45 +</project>
    91.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    91.2 +++ b/emul/mini/src/main/java/java/io/ByteArrayInputStream.java	Sun Feb 03 07:48:42 2013 +0100
    91.3 @@ -0,0 +1,285 @@
    91.4 +/*
    91.5 + * Copyright (c) 1994, 2010, 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.io;
   91.30 +
   91.31 +import org.apidesign.bck2brwsr.emul.lang.System;
   91.32 +
   91.33 +/**
   91.34 + * A <code>ByteArrayInputStream</code> contains
   91.35 + * an internal buffer that contains bytes that
   91.36 + * may be read from the stream. An internal
   91.37 + * counter keeps track of the next byte to
   91.38 + * be supplied by the <code>read</code> method.
   91.39 + * <p>
   91.40 + * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
   91.41 + * this class can be called after the stream has been closed without
   91.42 + * generating an <tt>IOException</tt>.
   91.43 + *
   91.44 + * @author  Arthur van Hoff
   91.45 + * @see     java.io.StringBufferInputStream
   91.46 + * @since   JDK1.0
   91.47 + */
   91.48 +public
   91.49 +class ByteArrayInputStream extends InputStream {
   91.50 +
   91.51 +    /**
   91.52 +     * An array of bytes that was provided
   91.53 +     * by the creator of the stream. Elements <code>buf[0]</code>
   91.54 +     * through <code>buf[count-1]</code> are the
   91.55 +     * only bytes that can ever be read from the
   91.56 +     * stream;  element <code>buf[pos]</code> is
   91.57 +     * the next byte to be read.
   91.58 +     */
   91.59 +    protected byte buf[];
   91.60 +
   91.61 +    /**
   91.62 +     * The index of the next character to read from the input stream buffer.
   91.63 +     * This value should always be nonnegative
   91.64 +     * and not larger than the value of <code>count</code>.
   91.65 +     * The next byte to be read from the input stream buffer
   91.66 +     * will be <code>buf[pos]</code>.
   91.67 +     */
   91.68 +    protected int pos;
   91.69 +
   91.70 +    /**
   91.71 +     * The currently marked position in the stream.
   91.72 +     * ByteArrayInputStream objects are marked at position zero by
   91.73 +     * default when constructed.  They may be marked at another
   91.74 +     * position within the buffer by the <code>mark()</code> method.
   91.75 +     * The current buffer position is set to this point by the
   91.76 +     * <code>reset()</code> method.
   91.77 +     * <p>
   91.78 +     * If no mark has been set, then the value of mark is the offset
   91.79 +     * passed to the constructor (or 0 if the offset was not supplied).
   91.80 +     *
   91.81 +     * @since   JDK1.1
   91.82 +     */
   91.83 +    protected int mark = 0;
   91.84 +
   91.85 +    /**
   91.86 +     * The index one greater than the last valid character in the input
   91.87 +     * stream buffer.
   91.88 +     * This value should always be nonnegative
   91.89 +     * and not larger than the length of <code>buf</code>.
   91.90 +     * It  is one greater than the position of
   91.91 +     * the last byte within <code>buf</code> that
   91.92 +     * can ever be read  from the input stream buffer.
   91.93 +     */
   91.94 +    protected int count;
   91.95 +
   91.96 +    /**
   91.97 +     * Creates a <code>ByteArrayInputStream</code>
   91.98 +     * so that it  uses <code>buf</code> as its
   91.99 +     * buffer array.
  91.100 +     * The buffer array is not copied.
  91.101 +     * The initial value of <code>pos</code>
  91.102 +     * is <code>0</code> and the initial value
  91.103 +     * of  <code>count</code> is the length of
  91.104 +     * <code>buf</code>.
  91.105 +     *
  91.106 +     * @param   buf   the input buffer.
  91.107 +     */
  91.108 +    public ByteArrayInputStream(byte buf[]) {
  91.109 +        this.buf = buf;
  91.110 +        this.pos = 0;
  91.111 +        this.count = buf.length;
  91.112 +    }
  91.113 +
  91.114 +    /**
  91.115 +     * Creates <code>ByteArrayInputStream</code>
  91.116 +     * that uses <code>buf</code> as its
  91.117 +     * buffer array. The initial value of <code>pos</code>
  91.118 +     * is <code>offset</code> and the initial value
  91.119 +     * of <code>count</code> is the minimum of <code>offset+length</code>
  91.120 +     * and <code>buf.length</code>.
  91.121 +     * The buffer array is not copied. The buffer's mark is
  91.122 +     * set to the specified offset.
  91.123 +     *
  91.124 +     * @param   buf      the input buffer.
  91.125 +     * @param   offset   the offset in the buffer of the first byte to read.
  91.126 +     * @param   length   the maximum number of bytes to read from the buffer.
  91.127 +     */
  91.128 +    public ByteArrayInputStream(byte buf[], int offset, int length) {
  91.129 +        this.buf = buf;
  91.130 +        this.pos = offset;
  91.131 +        this.count = Math.min(offset + length, buf.length);
  91.132 +        this.mark = offset;
  91.133 +    }
  91.134 +
  91.135 +    /**
  91.136 +     * Reads the next byte of data from this input stream. The value
  91.137 +     * byte is returned as an <code>int</code> in the range
  91.138 +     * <code>0</code> to <code>255</code>. If no byte is available
  91.139 +     * because the end of the stream has been reached, the value
  91.140 +     * <code>-1</code> is returned.
  91.141 +     * <p>
  91.142 +     * This <code>read</code> method
  91.143 +     * cannot block.
  91.144 +     *
  91.145 +     * @return  the next byte of data, or <code>-1</code> if the end of the
  91.146 +     *          stream has been reached.
  91.147 +     */
  91.148 +    public synchronized int read() {
  91.149 +        return (pos < count) ? (buf[pos++] & 0xff) : -1;
  91.150 +    }
  91.151 +
  91.152 +    /**
  91.153 +     * Reads up to <code>len</code> bytes of data into an array of bytes
  91.154 +     * from this input stream.
  91.155 +     * If <code>pos</code> equals <code>count</code>,
  91.156 +     * then <code>-1</code> is returned to indicate
  91.157 +     * end of file. Otherwise, the  number <code>k</code>
  91.158 +     * of bytes read is equal to the smaller of
  91.159 +     * <code>len</code> and <code>count-pos</code>.
  91.160 +     * If <code>k</code> is positive, then bytes
  91.161 +     * <code>buf[pos]</code> through <code>buf[pos+k-1]</code>
  91.162 +     * are copied into <code>b[off]</code>  through
  91.163 +     * <code>b[off+k-1]</code> in the manner performed
  91.164 +     * by <code>System.arraycopy</code>. The
  91.165 +     * value <code>k</code> is added into <code>pos</code>
  91.166 +     * and <code>k</code> is returned.
  91.167 +     * <p>
  91.168 +     * This <code>read</code> method cannot block.
  91.169 +     *
  91.170 +     * @param   b     the buffer into which the data is read.
  91.171 +     * @param   off   the start offset in the destination array <code>b</code>
  91.172 +     * @param   len   the maximum number of bytes read.
  91.173 +     * @return  the total number of bytes read into the buffer, or
  91.174 +     *          <code>-1</code> if there is no more data because the end of
  91.175 +     *          the stream has been reached.
  91.176 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
  91.177 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
  91.178 +     * <code>len</code> is negative, or <code>len</code> is greater than
  91.179 +     * <code>b.length - off</code>
  91.180 +     */
  91.181 +    public synchronized int read(byte b[], int off, int len) {
  91.182 +        if (b == null) {
  91.183 +            throw new NullPointerException();
  91.184 +        } else if (off < 0 || len < 0 || len > b.length - off) {
  91.185 +            throw new IndexOutOfBoundsException();
  91.186 +        }
  91.187 +
  91.188 +        if (pos >= count) {
  91.189 +            return -1;
  91.190 +        }
  91.191 +
  91.192 +        int avail = count - pos;
  91.193 +        if (len > avail) {
  91.194 +            len = avail;
  91.195 +        }
  91.196 +        if (len <= 0) {
  91.197 +            return 0;
  91.198 +        }
  91.199 +        System.arraycopy(buf, pos, b, off, len);
  91.200 +        pos += len;
  91.201 +        return len;
  91.202 +    }
  91.203 +
  91.204 +    /**
  91.205 +     * Skips <code>n</code> bytes of input from this input stream. Fewer
  91.206 +     * bytes might be skipped if the end of the input stream is reached.
  91.207 +     * The actual number <code>k</code>
  91.208 +     * of bytes to be skipped is equal to the smaller
  91.209 +     * of <code>n</code> and  <code>count-pos</code>.
  91.210 +     * The value <code>k</code> is added into <code>pos</code>
  91.211 +     * and <code>k</code> is returned.
  91.212 +     *
  91.213 +     * @param   n   the number of bytes to be skipped.
  91.214 +     * @return  the actual number of bytes skipped.
  91.215 +     */
  91.216 +    public synchronized long skip(long n) {
  91.217 +        long k = count - pos;
  91.218 +        if (n < k) {
  91.219 +            k = n < 0 ? 0 : n;
  91.220 +        }
  91.221 +
  91.222 +        pos += k;
  91.223 +        return k;
  91.224 +    }
  91.225 +
  91.226 +    /**
  91.227 +     * Returns the number of remaining bytes that can be read (or skipped over)
  91.228 +     * from this input stream.
  91.229 +     * <p>
  91.230 +     * The value returned is <code>count&nbsp;- pos</code>,
  91.231 +     * which is the number of bytes remaining to be read from the input buffer.
  91.232 +     *
  91.233 +     * @return  the number of remaining bytes that can be read (or skipped
  91.234 +     *          over) from this input stream without blocking.
  91.235 +     */
  91.236 +    public synchronized int available() {
  91.237 +        return count - pos;
  91.238 +    }
  91.239 +
  91.240 +    /**
  91.241 +     * Tests if this <code>InputStream</code> supports mark/reset. The
  91.242 +     * <code>markSupported</code> method of <code>ByteArrayInputStream</code>
  91.243 +     * always returns <code>true</code>.
  91.244 +     *
  91.245 +     * @since   JDK1.1
  91.246 +     */
  91.247 +    public boolean markSupported() {
  91.248 +        return true;
  91.249 +    }
  91.250 +
  91.251 +    /**
  91.252 +     * Set the current marked position in the stream.
  91.253 +     * ByteArrayInputStream objects are marked at position zero by
  91.254 +     * default when constructed.  They may be marked at another
  91.255 +     * position within the buffer by this method.
  91.256 +     * <p>
  91.257 +     * If no mark has been set, then the value of the mark is the
  91.258 +     * offset passed to the constructor (or 0 if the offset was not
  91.259 +     * supplied).
  91.260 +     *
  91.261 +     * <p> Note: The <code>readAheadLimit</code> for this class
  91.262 +     *  has no meaning.
  91.263 +     *
  91.264 +     * @since   JDK1.1
  91.265 +     */
  91.266 +    public void mark(int readAheadLimit) {
  91.267 +        mark = pos;
  91.268 +    }
  91.269 +
  91.270 +    /**
  91.271 +     * Resets the buffer to the marked position.  The marked position
  91.272 +     * is 0 unless another position was marked or an offset was specified
  91.273 +     * in the constructor.
  91.274 +     */
  91.275 +    public synchronized void reset() {
  91.276 +        pos = mark;
  91.277 +    }
  91.278 +
  91.279 +    /**
  91.280 +     * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
  91.281 +     * this class can be called after the stream has been closed without
  91.282 +     * generating an <tt>IOException</tt>.
  91.283 +     * <p>
  91.284 +     */
  91.285 +    public void close() throws IOException {
  91.286 +    }
  91.287 +
  91.288 +}
    92.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    92.2 +++ b/emul/mini/src/main/java/java/io/Closeable.java	Sun Feb 03 07:48:42 2013 +0100
    92.3 @@ -0,0 +1,48 @@
    92.4 +/*
    92.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
    92.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    92.7 + *
    92.8 + * This code is free software; you can redistribute it and/or modify it
    92.9 + * under the terms of the GNU General Public License version 2 only, as
   92.10 + * published by the Free Software Foundation.  Oracle designates this
   92.11 + * particular file as subject to the "Classpath" exception as provided
   92.12 + * by Oracle in the LICENSE file that accompanied this code.
   92.13 + *
   92.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   92.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   92.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   92.17 + * version 2 for more details (a copy is included in the LICENSE file that
   92.18 + * accompanied this code).
   92.19 + *
   92.20 + * You should have received a copy of the GNU General Public License version
   92.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   92.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   92.23 + *
   92.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   92.25 + * or visit www.oracle.com if you need additional information or have any
   92.26 + * questions.
   92.27 + */
   92.28 +
   92.29 +package java.io;
   92.30 +
   92.31 +import java.io.IOException;
   92.32 +
   92.33 +/**
   92.34 + * A {@code Closeable} is a source or destination of data that can be closed.
   92.35 + * The close method is invoked to release resources that the object is
   92.36 + * holding (such as open files).
   92.37 + *
   92.38 + * @since 1.5
   92.39 + */
   92.40 +
   92.41 +public interface Closeable extends AutoCloseable {
   92.42 +
   92.43 +    /**
   92.44 +     * Closes this stream and releases any system resources associated
   92.45 +     * with it. If the stream is already closed then invoking this
   92.46 +     * method has no effect.
   92.47 +     *
   92.48 +     * @throws IOException if an I/O error occurs
   92.49 +     */
   92.50 +    public void close() throws IOException;
   92.51 +}
    93.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    93.2 +++ b/emul/mini/src/main/java/java/io/DataInput.java	Sun Feb 03 07:48:42 2013 +0100
    93.3 @@ -0,0 +1,635 @@
    93.4 +/*
    93.5 + * Copyright (c) 1995, 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 +
   93.29 +package java.io;
   93.30 +
   93.31 +/**
   93.32 + * The <code>DataInput</code> interface provides
   93.33 + * for reading bytes from a binary stream and
   93.34 + * reconstructing from them data in any of
   93.35 + * the Java primitive types. There is also
   93.36 + * a
   93.37 + * facility for reconstructing a <code>String</code>
   93.38 + * from data in
   93.39 + * <a href="#modified-utf-8">modified UTF-8</a>
   93.40 + * format.
   93.41 + * <p>
   93.42 + * It is generally true of all the reading
   93.43 + * routines in this interface that if end of
   93.44 + * file is reached before the desired number
   93.45 + * of bytes has been read, an <code>EOFException</code>
   93.46 + * (which is a kind of <code>IOException</code>)
   93.47 + * is thrown. If any byte cannot be read for
   93.48 + * any reason other than end of file, an <code>IOException</code>
   93.49 + * other than <code>EOFException</code> is
   93.50 + * thrown. In particular, an <code>IOException</code>
   93.51 + * may be thrown if the input stream has been
   93.52 + * closed.
   93.53 + *
   93.54 + * <h4><a name="modified-utf-8">Modified UTF-8</a></h4>
   93.55 + * <p>
   93.56 + * Implementations of the DataInput and DataOutput interfaces represent
   93.57 + * Unicode strings in a format that is a slight modification of UTF-8.
   93.58 + * (For information regarding the standard UTF-8 format, see section
   93.59 + * <i>3.9 Unicode Encoding Forms</i> of <i>The Unicode Standard, Version
   93.60 + * 4.0</i>).
   93.61 + * Note that in the following tables, the most significant bit appears in the
   93.62 + * far left-hand column.
   93.63 + * <p>
   93.64 + * All characters in the range <code>'&#92;u0001'</code> to
   93.65 + * <code>'&#92;u007F'</code> are represented by a single byte:
   93.66 + *
   93.67 + * <blockquote>
   93.68 + *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
   93.69 + *          summary="Bit values and bytes">
   93.70 + *     <tr>
   93.71 + *       <td></td>
   93.72 + *       <th id="bit">Bit Values</th>
   93.73 + *     </tr>
   93.74 + *     <tr>
   93.75 + *       <th id="byte1">Byte 1</th>
   93.76 + *       <td>
   93.77 + *         <table border="1" cellspacing="0" width="100%">
   93.78 + *           <tr>
   93.79 + *             <td width="12%"><center>0</center>
   93.80 + *             <td colspan="7"><center>bits 6-0</center>
   93.81 + *           </tr>
   93.82 + *         </table>
   93.83 + *       </td>
   93.84 + *     </tr>
   93.85 + *   </table>
   93.86 + * </blockquote>
   93.87 + *
   93.88 + * <p>
   93.89 + * The null character <code>'&#92;u0000'</code> and characters in the
   93.90 + * range <code>'&#92;u0080'</code> to <code>'&#92;u07FF'</code> are
   93.91 + * represented by a pair of bytes:
   93.92 + *
   93.93 + * <blockquote>
   93.94 + *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
   93.95 + *          summary="Bit values and bytes">
   93.96 + *     <tr>
   93.97 + *       <td></td>
   93.98 + *       <th id="bit">Bit Values</th>
   93.99 + *     </tr>
  93.100 + *     <tr>
  93.101 + *       <th id="byte1">Byte 1</th>
  93.102 + *       <td>
  93.103 + *         <table border="1" cellspacing="0" width="100%">
  93.104 + *           <tr>
  93.105 + *             <td width="12%"><center>1</center>
  93.106 + *             <td width="13%"><center>1</center>
  93.107 + *             <td width="12%"><center>0</center>
  93.108 + *             <td colspan="5"><center>bits 10-6</center>
  93.109 + *           </tr>
  93.110 + *         </table>
  93.111 + *       </td>
  93.112 + *     </tr>
  93.113 + *     <tr>
  93.114 + *       <th id="byte2">Byte 2</th>
  93.115 + *       <td>
  93.116 + *         <table border="1" cellspacing="0" width="100%">
  93.117 + *           <tr>
  93.118 + *             <td width="12%"><center>1</center>
  93.119 + *             <td width="13%"><center>0</center>
  93.120 + *             <td colspan="6"><center>bits 5-0</center>
  93.121 + *           </tr>
  93.122 + *         </table>
  93.123 + *       </td>
  93.124 + *     </tr>
  93.125 + *   </table>
  93.126 + *  </blockquote>
  93.127 + *
  93.128 + * <br>
  93.129 + * <code>char</code> values in the range <code>'&#92;u0800'</code> to
  93.130 + * <code>'&#92;uFFFF'</code> are represented by three bytes:
  93.131 + *
  93.132 + * <blockquote>
  93.133 + *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
  93.134 + *          summary="Bit values and bytes">
  93.135 + *     <tr>
  93.136 + *       <td></td>
  93.137 + *       <th id="bit">Bit Values</th>
  93.138 + *     </tr>
  93.139 + *     <tr>
  93.140 + *       <th id="byte1">Byte 1</th>
  93.141 + *       <td>
  93.142 + *         <table border="1" cellspacing="0" width="100%">
  93.143 + *           <tr>
  93.144 + *             <td width="12%"><center>1</center>
  93.145 + *             <td width="13%"><center>1</center>
  93.146 + *             <td width="12%"><center>1</center>
  93.147 + *             <td width="13%"><center>0</center>
  93.148 + *             <td colspan="4"><center>bits 15-12</center>
  93.149 + *           </tr>
  93.150 + *         </table>
  93.151 + *       </td>
  93.152 + *     </tr>
  93.153 + *     <tr>
  93.154 + *       <th id="byte2">Byte 2</th>
  93.155 + *       <td>
  93.156 + *         <table border="1" cellspacing="0" width="100%">
  93.157 + *           <tr>
  93.158 + *             <td width="12%"><center>1</center>
  93.159 + *             <td width="13%"><center>0</center>
  93.160 + *             <td colspan="6"><center>bits 11-6</center>
  93.161 + *           </tr>
  93.162 + *         </table>
  93.163 + *       </td>
  93.164 + *     </tr>
  93.165 + *     <tr>
  93.166 + *       <th id="byte3">Byte 3</th>
  93.167 + *       <td>
  93.168 + *         <table border="1" cellspacing="0" width="100%">
  93.169 + *           <tr>
  93.170 + *             <td width="12%"><center>1</center>
  93.171 + *             <td width="13%"><center>0</center>
  93.172 + *             <td colspan="6"><center>bits 5-0</center>
  93.173 + *           </tr>
  93.174 + *         </table>
  93.175 + *       </td>
  93.176 + *     </tr>
  93.177 + *   </table>
  93.178 + *  </blockquote>
  93.179 + *
  93.180 + * <p>
  93.181 + * The differences between this format and the
  93.182 + * standard UTF-8 format are the following:
  93.183 + * <ul>
  93.184 + * <li>The null byte <code>'&#92;u0000'</code> is encoded in 2-byte format
  93.185 + *     rather than 1-byte, so that the encoded strings never have
  93.186 + *     embedded nulls.
  93.187 + * <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
  93.188 + * <li><a href="../lang/Character.html#unicode">Supplementary characters</a>
  93.189 + *     are represented in the form of surrogate pairs.
  93.190 + * </ul>
  93.191 + * @author  Frank Yellin
  93.192 + * @see     java.io.DataInputStream
  93.193 + * @see     java.io.DataOutput
  93.194 + * @since   JDK1.0
  93.195 + */
  93.196 +public
  93.197 +interface DataInput {
  93.198 +    /**
  93.199 +     * Reads some bytes from an input
  93.200 +     * stream and stores them into the buffer
  93.201 +     * array <code>b</code>. The number of bytes
  93.202 +     * read is equal
  93.203 +     * to the length of <code>b</code>.
  93.204 +     * <p>
  93.205 +     * This method blocks until one of the
  93.206 +     * following conditions occurs:<p>
  93.207 +     * <ul>
  93.208 +     * <li><code>b.length</code>
  93.209 +     * bytes of input data are available, in which
  93.210 +     * case a normal return is made.
  93.211 +     *
  93.212 +     * <li>End of
  93.213 +     * file is detected, in which case an <code>EOFException</code>
  93.214 +     * is thrown.
  93.215 +     *
  93.216 +     * <li>An I/O error occurs, in
  93.217 +     * which case an <code>IOException</code> other
  93.218 +     * than <code>EOFException</code> is thrown.
  93.219 +     * </ul>
  93.220 +     * <p>
  93.221 +     * If <code>b</code> is <code>null</code>,
  93.222 +     * a <code>NullPointerException</code> is thrown.
  93.223 +     * If <code>b.length</code> is zero, then
  93.224 +     * no bytes are read. Otherwise, the first
  93.225 +     * byte read is stored into element <code>b[0]</code>,
  93.226 +     * the next one into <code>b[1]</code>, and
  93.227 +     * so on.
  93.228 +     * If an exception is thrown from
  93.229 +     * this method, then it may be that some but
  93.230 +     * not all bytes of <code>b</code> have been
  93.231 +     * updated with data from the input stream.
  93.232 +     *
  93.233 +     * @param     b   the buffer into which the data is read.
  93.234 +     * @exception  EOFException  if this stream reaches the end before reading
  93.235 +     *               all the bytes.
  93.236 +     * @exception  IOException   if an I/O error occurs.
  93.237 +     */
  93.238 +    void readFully(byte b[]) throws IOException;
  93.239 +
  93.240 +    /**
  93.241 +     *
  93.242 +     * Reads <code>len</code>
  93.243 +     * bytes from
  93.244 +     * an input stream.
  93.245 +     * <p>
  93.246 +     * This method
  93.247 +     * blocks until one of the following conditions
  93.248 +     * occurs:<p>
  93.249 +     * <ul>
  93.250 +     * <li><code>len</code> bytes
  93.251 +     * of input data are available, in which case
  93.252 +     * a normal return is made.
  93.253 +     *
  93.254 +     * <li>End of file
  93.255 +     * is detected, in which case an <code>EOFException</code>
  93.256 +     * is thrown.
  93.257 +     *
  93.258 +     * <li>An I/O error occurs, in
  93.259 +     * which case an <code>IOException</code> other
  93.260 +     * than <code>EOFException</code> is thrown.
  93.261 +     * </ul>
  93.262 +     * <p>
  93.263 +     * If <code>b</code> is <code>null</code>,
  93.264 +     * a <code>NullPointerException</code> is thrown.
  93.265 +     * If <code>off</code> is negative, or <code>len</code>
  93.266 +     * is negative, or <code>off+len</code> is
  93.267 +     * greater than the length of the array <code>b</code>,
  93.268 +     * then an <code>IndexOutOfBoundsException</code>
  93.269 +     * is thrown.
  93.270 +     * If <code>len</code> is zero,
  93.271 +     * then no bytes are read. Otherwise, the first
  93.272 +     * byte read is stored into element <code>b[off]</code>,
  93.273 +     * the next one into <code>b[off+1]</code>,
  93.274 +     * and so on. The number of bytes read is,
  93.275 +     * at most, equal to <code>len</code>.
  93.276 +     *
  93.277 +     * @param     b   the buffer into which the data is read.
  93.278 +     * @param off  an int specifying the offset into the data.
  93.279 +     * @param len  an int specifying the number of bytes to read.
  93.280 +     * @exception  EOFException  if this stream reaches the end before reading
  93.281 +     *               all the bytes.
  93.282 +     * @exception  IOException   if an I/O error occurs.
  93.283 +     */
  93.284 +    void readFully(byte b[], int off, int len) throws IOException;
  93.285 +
  93.286 +    /**
  93.287 +     * Makes an attempt to skip over
  93.288 +     * <code>n</code> bytes
  93.289 +     * of data from the input
  93.290 +     * stream, discarding the skipped bytes. However,
  93.291 +     * it may skip
  93.292 +     * over some smaller number of
  93.293 +     * bytes, possibly zero. This may result from
  93.294 +     * any of a
  93.295 +     * number of conditions; reaching
  93.296 +     * end of file before <code>n</code> bytes
  93.297 +     * have been skipped is
  93.298 +     * only one possibility.
  93.299 +     * This method never throws an <code>EOFException</code>.
  93.300 +     * The actual
  93.301 +     * number of bytes skipped is returned.
  93.302 +     *
  93.303 +     * @param      n   the number of bytes to be skipped.
  93.304 +     * @return     the number of bytes actually skipped.
  93.305 +     * @exception  IOException   if an I/O error occurs.
  93.306 +     */
  93.307 +    int skipBytes(int n) throws IOException;
  93.308 +
  93.309 +    /**
  93.310 +     * Reads one input byte and returns
  93.311 +     * <code>true</code> if that byte is nonzero,
  93.312 +     * <code>false</code> if that byte is zero.
  93.313 +     * This method is suitable for reading
  93.314 +     * the byte written by the <code>writeBoolean</code>
  93.315 +     * method of interface <code>DataOutput</code>.
  93.316 +     *
  93.317 +     * @return     the <code>boolean</code> value read.
  93.318 +     * @exception  EOFException  if this stream reaches the end before reading
  93.319 +     *               all the bytes.
  93.320 +     * @exception  IOException   if an I/O error occurs.
  93.321 +     */
  93.322 +    boolean readBoolean() throws IOException;
  93.323 +
  93.324 +    /**
  93.325 +     * Reads and returns one input byte.
  93.326 +     * The byte is treated as a signed value in
  93.327 +     * the range <code>-128</code> through <code>127</code>,
  93.328 +     * inclusive.
  93.329 +     * This method is suitable for
  93.330 +     * reading the byte written by the <code>writeByte</code>
  93.331 +     * method of interface <code>DataOutput</code>.
  93.332 +     *
  93.333 +     * @return     the 8-bit value read.
  93.334 +     * @exception  EOFException  if this stream reaches the end before reading
  93.335 +     *               all the bytes.
  93.336 +     * @exception  IOException   if an I/O error occurs.
  93.337 +     */
  93.338 +    byte readByte() throws IOException;
  93.339 +
  93.340 +    /**
  93.341 +     * Reads one input byte, zero-extends
  93.342 +     * it to type <code>int</code>, and returns
  93.343 +     * the result, which is therefore in the range
  93.344 +     * <code>0</code>
  93.345 +     * through <code>255</code>.
  93.346 +     * This method is suitable for reading
  93.347 +     * the byte written by the <code>writeByte</code>
  93.348 +     * method of interface <code>DataOutput</code>
  93.349 +     * if the argument to <code>writeByte</code>
  93.350 +     * was intended to be a value in the range
  93.351 +     * <code>0</code> through <code>255</code>.
  93.352 +     *
  93.353 +     * @return     the unsigned 8-bit value read.
  93.354 +     * @exception  EOFException  if this stream reaches the end before reading
  93.355 +     *               all the bytes.
  93.356 +     * @exception  IOException   if an I/O error occurs.
  93.357 +     */
  93.358 +    int readUnsignedByte() throws IOException;
  93.359 +
  93.360 +    /**
  93.361 +     * Reads two input bytes and returns
  93.362 +     * a <code>short</code> value. Let <code>a</code>
  93.363 +     * be the first byte read and <code>b</code>
  93.364 +     * be the second byte. The value
  93.365 +     * returned
  93.366 +     * is:
  93.367 +     * <p><pre><code>(short)((a &lt;&lt; 8) | (b &amp; 0xff))
  93.368 +     * </code></pre>
  93.369 +     * This method
  93.370 +     * is suitable for reading the bytes written
  93.371 +     * by the <code>writeShort</code> method of
  93.372 +     * interface <code>DataOutput</code>.
  93.373 +     *
  93.374 +     * @return     the 16-bit value read.
  93.375 +     * @exception  EOFException  if this stream reaches the end before reading
  93.376 +     *               all the bytes.
  93.377 +     * @exception  IOException   if an I/O error occurs.
  93.378 +     */
  93.379 +    short readShort() throws IOException;
  93.380 +
  93.381 +    /**
  93.382 +     * Reads two input bytes and returns
  93.383 +     * an <code>int</code> value in the range <code>0</code>
  93.384 +     * through <code>65535</code>. Let <code>a</code>
  93.385 +     * be the first byte read and
  93.386 +     * <code>b</code>
  93.387 +     * be the second byte. The value returned is:
  93.388 +     * <p><pre><code>(((a &amp; 0xff) &lt;&lt; 8) | (b &amp; 0xff))
  93.389 +     * </code></pre>
  93.390 +     * This method is suitable for reading the bytes
  93.391 +     * written by the <code>writeShort</code> method
  93.392 +     * of interface <code>DataOutput</code>  if
  93.393 +     * the argument to <code>writeShort</code>
  93.394 +     * was intended to be a value in the range
  93.395 +     * <code>0</code> through <code>65535</code>.
  93.396 +     *
  93.397 +     * @return     the unsigned 16-bit value read.
  93.398 +     * @exception  EOFException  if this stream reaches the end before reading
  93.399 +     *               all the bytes.
  93.400 +     * @exception  IOException   if an I/O error occurs.
  93.401 +     */
  93.402 +    int readUnsignedShort() throws IOException;
  93.403 +
  93.404 +    /**
  93.405 +     * Reads two input bytes and returns a <code>char</code> value.
  93.406 +     * Let <code>a</code>
  93.407 +     * be the first byte read and <code>b</code>
  93.408 +     * be the second byte. The value
  93.409 +     * returned is:
  93.410 +     * <p><pre><code>(char)((a &lt;&lt; 8) | (b &amp; 0xff))
  93.411 +     * </code></pre>
  93.412 +     * This method
  93.413 +     * is suitable for reading bytes written by
  93.414 +     * the <code>writeChar</code> method of interface
  93.415 +     * <code>DataOutput</code>.
  93.416 +     *
  93.417 +     * @return     the <code>char</code> value read.
  93.418 +     * @exception  EOFException  if this stream reaches the end before reading
  93.419 +     *               all the bytes.
  93.420 +     * @exception  IOException   if an I/O error occurs.
  93.421 +     */
  93.422 +    char readChar() throws IOException;
  93.423 +
  93.424 +    /**
  93.425 +     * Reads four input bytes and returns an
  93.426 +     * <code>int</code> value. Let <code>a-d</code>
  93.427 +     * be the first through fourth bytes read. The value returned is:
  93.428 +     * <p><pre>
  93.429 +     * <code>
  93.430 +     * (((a &amp; 0xff) &lt;&lt; 24) | ((b &amp; 0xff) &lt;&lt; 16) |
  93.431 +     * &#32;((c &amp; 0xff) &lt;&lt; 8) | (d &amp; 0xff))
  93.432 +     * </code></pre>
  93.433 +     * This method is suitable
  93.434 +     * for reading bytes written by the <code>writeInt</code>
  93.435 +     * method of interface <code>DataOutput</code>.
  93.436 +     *
  93.437 +     * @return     the <code>int</code> value read.
  93.438 +     * @exception  EOFException  if this stream reaches the end before reading
  93.439 +     *               all the bytes.
  93.440 +     * @exception  IOException   if an I/O error occurs.
  93.441 +     */
  93.442 +    int readInt() throws IOException;
  93.443 +
  93.444 +    /**
  93.445 +     * Reads eight input bytes and returns
  93.446 +     * a <code>long</code> value. Let <code>a-h</code>
  93.447 +     * be the first through eighth bytes read.
  93.448 +     * The value returned is:
  93.449 +     * <p><pre> <code>
  93.450 +     * (((long)(a &amp; 0xff) &lt;&lt; 56) |
  93.451 +     *  ((long)(b &amp; 0xff) &lt;&lt; 48) |
  93.452 +     *  ((long)(c &amp; 0xff) &lt;&lt; 40) |
  93.453 +     *  ((long)(d &amp; 0xff) &lt;&lt; 32) |
  93.454 +     *  ((long)(e &amp; 0xff) &lt;&lt; 24) |
  93.455 +     *  ((long)(f &amp; 0xff) &lt;&lt; 16) |
  93.456 +     *  ((long)(g &amp; 0xff) &lt;&lt;  8) |
  93.457 +     *  ((long)(h &amp; 0xff)))
  93.458 +     * </code></pre>
  93.459 +     * <p>
  93.460 +     * This method is suitable
  93.461 +     * for reading bytes written by the <code>writeLong</code>
  93.462 +     * method of interface <code>DataOutput</code>.
  93.463 +     *
  93.464 +     * @return     the <code>long</code> value read.
  93.465 +     * @exception  EOFException  if this stream reaches the end before reading
  93.466 +     *               all the bytes.
  93.467 +     * @exception  IOException   if an I/O error occurs.
  93.468 +     */
  93.469 +    long readLong() throws IOException;
  93.470 +
  93.471 +    /**
  93.472 +     * Reads four input bytes and returns
  93.473 +     * a <code>float</code> value. It does this
  93.474 +     * by first constructing an <code>int</code>
  93.475 +     * value in exactly the manner
  93.476 +     * of the <code>readInt</code>
  93.477 +     * method, then converting this <code>int</code>
  93.478 +     * value to a <code>float</code> in
  93.479 +     * exactly the manner of the method <code>Float.intBitsToFloat</code>.
  93.480 +     * This method is suitable for reading
  93.481 +     * bytes written by the <code>writeFloat</code>
  93.482 +     * method of interface <code>DataOutput</code>.
  93.483 +     *
  93.484 +     * @return     the <code>float</code> value read.
  93.485 +     * @exception  EOFException  if this stream reaches the end before reading
  93.486 +     *               all the bytes.
  93.487 +     * @exception  IOException   if an I/O error occurs.
  93.488 +     */
  93.489 +    float readFloat() throws IOException;
  93.490 +
  93.491 +    /**
  93.492 +     * Reads eight input bytes and returns
  93.493 +     * a <code>double</code> value. It does this
  93.494 +     * by first constructing a <code>long</code>
  93.495 +     * value in exactly the manner
  93.496 +     * of the <code>readlong</code>
  93.497 +     * method, then converting this <code>long</code>
  93.498 +     * value to a <code>double</code> in exactly
  93.499 +     * the manner of the method <code>Double.longBitsToDouble</code>.
  93.500 +     * This method is suitable for reading
  93.501 +     * bytes written by the <code>writeDouble</code>
  93.502 +     * method of interface <code>DataOutput</code>.
  93.503 +     *
  93.504 +     * @return     the <code>double</code> value read.
  93.505 +     * @exception  EOFException  if this stream reaches the end before reading
  93.506 +     *               all the bytes.
  93.507 +     * @exception  IOException   if an I/O error occurs.
  93.508 +     */
  93.509 +    double readDouble() throws IOException;
  93.510 +
  93.511 +    /**
  93.512 +     * Reads the next line of text from the input stream.
  93.513 +     * It reads successive bytes, converting
  93.514 +     * each byte separately into a character,
  93.515 +     * until it encounters a line terminator or
  93.516 +     * end of
  93.517 +     * file; the characters read are then
  93.518 +     * returned as a <code>String</code>. Note
  93.519 +     * that because this
  93.520 +     * method processes bytes,
  93.521 +     * it does not support input of the full Unicode
  93.522 +     * character set.
  93.523 +     * <p>
  93.524 +     * If end of file is encountered
  93.525 +     * before even one byte can be read, then <code>null</code>
  93.526 +     * is returned. Otherwise, each byte that is
  93.527 +     * read is converted to type <code>char</code>
  93.528 +     * by zero-extension. If the character <code>'\n'</code>
  93.529 +     * is encountered, it is discarded and reading
  93.530 +     * ceases. If the character <code>'\r'</code>
  93.531 +     * is encountered, it is discarded and, if
  93.532 +     * the following byte converts &#32;to the
  93.533 +     * character <code>'\n'</code>, then that is
  93.534 +     * discarded also; reading then ceases. If
  93.535 +     * end of file is encountered before either
  93.536 +     * of the characters <code>'\n'</code> and
  93.537 +     * <code>'\r'</code> is encountered, reading
  93.538 +     * ceases. Once reading has ceased, a <code>String</code>
  93.539 +     * is returned that contains all the characters
  93.540 +     * read and not discarded, taken in order.
  93.541 +     * Note that every character in this string
  93.542 +     * will have a value less than <code>&#92;u0100</code>,
  93.543 +     * that is, <code>(char)256</code>.
  93.544 +     *
  93.545 +     * @return the next line of text from the input stream,
  93.546 +     *         or <CODE>null</CODE> if the end of file is
  93.547 +     *         encountered before a byte can be read.
  93.548 +     * @exception  IOException  if an I/O error occurs.
  93.549 +     */
  93.550 +    String readLine() throws IOException;
  93.551 +
  93.552 +    /**
  93.553 +     * Reads in a string that has been encoded using a
  93.554 +     * <a href="#modified-utf-8">modified UTF-8</a>
  93.555 +     * format.
  93.556 +     * The general contract of <code>readUTF</code>
  93.557 +     * is that it reads a representation of a Unicode
  93.558 +     * character string encoded in modified
  93.559 +     * UTF-8 format; this string of characters
  93.560 +     * is then returned as a <code>String</code>.
  93.561 +     * <p>
  93.562 +     * First, two bytes are read and used to
  93.563 +     * construct an unsigned 16-bit integer in
  93.564 +     * exactly the manner of the <code>readUnsignedShort</code>
  93.565 +     * method . This integer value is called the
  93.566 +     * <i>UTF length</i> and specifies the number
  93.567 +     * of additional bytes to be read. These bytes
  93.568 +     * are then converted to characters by considering
  93.569 +     * them in groups. The length of each group
  93.570 +     * is computed from the value of the first
  93.571 +     * byte of the group. The byte following a
  93.572 +     * group, if any, is the first byte of the
  93.573 +     * next group.
  93.574 +     * <p>
  93.575 +     * If the first byte of a group
  93.576 +     * matches the bit pattern <code>0xxxxxxx</code>
  93.577 +     * (where <code>x</code> means "may be <code>0</code>
  93.578 +     * or <code>1</code>"), then the group consists
  93.579 +     * of just that byte. The byte is zero-extended
  93.580 +     * to form a character.
  93.581 +     * <p>
  93.582 +     * If the first byte
  93.583 +     * of a group matches the bit pattern <code>110xxxxx</code>,
  93.584 +     * then the group consists of that byte <code>a</code>
  93.585 +     * and a second byte <code>b</code>. If there
  93.586 +     * is no byte <code>b</code> (because byte
  93.587 +     * <code>a</code> was the last of the bytes
  93.588 +     * to be read), or if byte <code>b</code> does
  93.589 +     * not match the bit pattern <code>10xxxxxx</code>,
  93.590 +     * then a <code>UTFDataFormatException</code>
  93.591 +     * is thrown. Otherwise, the group is converted
  93.592 +     * to the character:<p>
  93.593 +     * <pre><code>(char)(((a&amp; 0x1F) &lt;&lt; 6) | (b &amp; 0x3F))
  93.594 +     * </code></pre>
  93.595 +     * If the first byte of a group
  93.596 +     * matches the bit pattern <code>1110xxxx</code>,
  93.597 +     * then the group consists of that byte <code>a</code>
  93.598 +     * and two more bytes <code>b</code> and <code>c</code>.
  93.599 +     * If there is no byte <code>c</code> (because
  93.600 +     * byte <code>a</code> was one of the last
  93.601 +     * two of the bytes to be read), or either
  93.602 +     * byte <code>b</code> or byte <code>c</code>
  93.603 +     * does not match the bit pattern <code>10xxxxxx</code>,
  93.604 +     * then a <code>UTFDataFormatException</code>
  93.605 +     * is thrown. Otherwise, the group is converted
  93.606 +     * to the character:<p>
  93.607 +     * <pre><code>
  93.608 +     * (char)(((a &amp; 0x0F) &lt;&lt; 12) | ((b &amp; 0x3F) &lt;&lt; 6) | (c &amp; 0x3F))
  93.609 +     * </code></pre>
  93.610 +     * If the first byte of a group matches the
  93.611 +     * pattern <code>1111xxxx</code> or the pattern
  93.612 +     * <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code>
  93.613 +     * is thrown.
  93.614 +     * <p>
  93.615 +     * If end of file is encountered
  93.616 +     * at any time during this entire process,
  93.617 +     * then an <code>EOFException</code> is thrown.
  93.618 +     * <p>
  93.619 +     * After every group has been converted to
  93.620 +     * a character by this process, the characters
  93.621 +     * are gathered, in the same order in which
  93.622 +     * their corresponding groups were read from
  93.623 +     * the input stream, to form a <code>String</code>,
  93.624 +     * which is returned.
  93.625 +     * <p>
  93.626 +     * The <code>writeUTF</code>
  93.627 +     * method of interface <code>DataOutput</code>
  93.628 +     * may be used to write data that is suitable
  93.629 +     * for reading by this method.
  93.630 +     * @return     a Unicode string.
  93.631 +     * @exception  EOFException            if this stream reaches the end
  93.632 +     *               before reading all the bytes.
  93.633 +     * @exception  IOException             if an I/O error occurs.
  93.634 +     * @exception  UTFDataFormatException  if the bytes do not represent a
  93.635 +     *               valid modified UTF-8 encoding of a string.
  93.636 +     */
  93.637 +    String readUTF() throws IOException;
  93.638 +}
    94.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    94.2 +++ b/emul/mini/src/main/java/java/io/DataInputStream.java	Sun Feb 03 07:48:42 2013 +0100
    94.3 @@ -0,0 +1,700 @@
    94.4 +/*
    94.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
    94.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    94.7 + *
    94.8 + * This code is free software; you can redistribute it and/or modify it
    94.9 + * under the terms of the GNU General Public License version 2 only, as
   94.10 + * published by the Free Software Foundation.  Oracle designates this
   94.11 + * particular file as subject to the "Classpath" exception as provided
   94.12 + * by Oracle in the LICENSE file that accompanied this code.
   94.13 + *
   94.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   94.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   94.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   94.17 + * version 2 for more details (a copy is included in the LICENSE file that
   94.18 + * accompanied this code).
   94.19 + *
   94.20 + * You should have received a copy of the GNU General Public License version
   94.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   94.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   94.23 + *
   94.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   94.25 + * or visit www.oracle.com if you need additional information or have any
   94.26 + * questions.
   94.27 + */
   94.28 +
   94.29 +package java.io;
   94.30 +
   94.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
   94.32 +import org.apidesign.bck2brwsr.emul.lang.System;
   94.33 +
   94.34 +/**
   94.35 + * A data input stream lets an application read primitive Java data
   94.36 + * types from an underlying input stream in a machine-independent
   94.37 + * way. An application uses a data output stream to write data that
   94.38 + * can later be read by a data input stream.
   94.39 + * <p>
   94.40 + * DataInputStream is not necessarily safe for multithreaded access.
   94.41 + * Thread safety is optional and is the responsibility of users of
   94.42 + * methods in this class.
   94.43 + *
   94.44 + * @author  Arthur van Hoff
   94.45 + * @see     java.io.DataOutputStream
   94.46 + * @since   JDK1.0
   94.47 + */
   94.48 +public
   94.49 +class DataInputStream extends FilterInputStream implements DataInput {
   94.50 +
   94.51 +    /**
   94.52 +     * Creates a DataInputStream that uses the specified
   94.53 +     * underlying InputStream.
   94.54 +     *
   94.55 +     * @param  in   the specified input stream
   94.56 +     */
   94.57 +    public DataInputStream(InputStream in) {
   94.58 +        super(in);
   94.59 +    }
   94.60 +
   94.61 +    /**
   94.62 +     * working arrays initialized on demand by readUTF
   94.63 +     */
   94.64 +    private byte bytearr[] = new byte[80];
   94.65 +    private char chararr[] = new char[80];
   94.66 +
   94.67 +    /**
   94.68 +     * Reads some number of bytes from the contained input stream and
   94.69 +     * stores them into the buffer array <code>b</code>. The number of
   94.70 +     * bytes actually read is returned as an integer. This method blocks
   94.71 +     * until input data is available, end of file is detected, or an
   94.72 +     * exception is thrown.
   94.73 +     *
   94.74 +     * <p>If <code>b</code> is null, a <code>NullPointerException</code> is
   94.75 +     * thrown. If the length of <code>b</code> is zero, then no bytes are
   94.76 +     * read and <code>0</code> is returned; otherwise, there is an attempt
   94.77 +     * to read at least one byte. If no byte is available because the
   94.78 +     * stream is at end of file, the value <code>-1</code> is returned;
   94.79 +     * otherwise, at least one byte is read and stored into <code>b</code>.
   94.80 +     *
   94.81 +     * <p>The first byte read is stored into element <code>b[0]</code>, the
   94.82 +     * next one into <code>b[1]</code>, and so on. The number of bytes read
   94.83 +     * is, at most, equal to the length of <code>b</code>. Let <code>k</code>
   94.84 +     * be the number of bytes actually read; these bytes will be stored in
   94.85 +     * elements <code>b[0]</code> through <code>b[k-1]</code>, leaving
   94.86 +     * elements <code>b[k]</code> through <code>b[b.length-1]</code>
   94.87 +     * unaffected.
   94.88 +     *
   94.89 +     * <p>The <code>read(b)</code> method has the same effect as:
   94.90 +     * <blockquote><pre>
   94.91 +     * read(b, 0, b.length)
   94.92 +     * </pre></blockquote>
   94.93 +     *
   94.94 +     * @param      b   the buffer into which the data is read.
   94.95 +     * @return     the total number of bytes read into the buffer, or
   94.96 +     *             <code>-1</code> if there is no more data because the end
   94.97 +     *             of the stream has been reached.
   94.98 +     * @exception  IOException if the first byte cannot be read for any reason
   94.99 +     * other than end of file, the stream has been closed and the underlying
  94.100 +     * input stream does not support reading after close, or another I/O
  94.101 +     * error occurs.
  94.102 +     * @see        java.io.FilterInputStream#in
  94.103 +     * @see        java.io.InputStream#read(byte[], int, int)
  94.104 +     */
  94.105 +    public final int read(byte b[]) throws IOException {
  94.106 +        return in.read(b, 0, b.length);
  94.107 +    }
  94.108 +
  94.109 +    /**
  94.110 +     * Reads up to <code>len</code> bytes of data from the contained
  94.111 +     * input stream into an array of bytes.  An attempt is made to read
  94.112 +     * as many as <code>len</code> bytes, but a smaller number may be read,
  94.113 +     * possibly zero. The number of bytes actually read is returned as an
  94.114 +     * integer.
  94.115 +     *
  94.116 +     * <p> This method blocks until input data is available, end of file is
  94.117 +     * detected, or an exception is thrown.
  94.118 +     *
  94.119 +     * <p> If <code>len</code> is zero, then no bytes are read and
  94.120 +     * <code>0</code> is returned; otherwise, there is an attempt to read at
  94.121 +     * least one byte. If no byte is available because the stream is at end of
  94.122 +     * file, the value <code>-1</code> is returned; otherwise, at least one
  94.123 +     * byte is read and stored into <code>b</code>.
  94.124 +     *
  94.125 +     * <p> The first byte read is stored into element <code>b[off]</code>, the
  94.126 +     * next one into <code>b[off+1]</code>, and so on. The number of bytes read
  94.127 +     * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
  94.128 +     * bytes actually read; these bytes will be stored in elements
  94.129 +     * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
  94.130 +     * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
  94.131 +     * <code>b[off+len-1]</code> unaffected.
  94.132 +     *
  94.133 +     * <p> In every case, elements <code>b[0]</code> through
  94.134 +     * <code>b[off]</code> and elements <code>b[off+len]</code> through
  94.135 +     * <code>b[b.length-1]</code> are unaffected.
  94.136 +     *
  94.137 +     * @param      b     the buffer into which the data is read.
  94.138 +     * @param off the start offset in the destination array <code>b</code>
  94.139 +     * @param      len   the maximum number of bytes read.
  94.140 +     * @return     the total number of bytes read into the buffer, or
  94.141 +     *             <code>-1</code> if there is no more data because the end
  94.142 +     *             of the stream has been reached.
  94.143 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
  94.144 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
  94.145 +     * <code>len</code> is negative, or <code>len</code> is greater than
  94.146 +     * <code>b.length - off</code>
  94.147 +     * @exception  IOException if the first byte cannot be read for any reason
  94.148 +     * other than end of file, the stream has been closed and the underlying
  94.149 +     * input stream does not support reading after close, or another I/O
  94.150 +     * error occurs.
  94.151 +     * @see        java.io.FilterInputStream#in
  94.152 +     * @see        java.io.InputStream#read(byte[], int, int)
  94.153 +     */
  94.154 +    public final int read(byte b[], int off, int len) throws IOException {
  94.155 +        return in.read(b, off, len);
  94.156 +    }
  94.157 +
  94.158 +    /**
  94.159 +     * See the general contract of the <code>readFully</code>
  94.160 +     * method of <code>DataInput</code>.
  94.161 +     * <p>
  94.162 +     * Bytes
  94.163 +     * for this operation are read from the contained
  94.164 +     * input stream.
  94.165 +     *
  94.166 +     * @param      b   the buffer into which the data is read.
  94.167 +     * @exception  EOFException  if this input stream reaches the end before
  94.168 +     *             reading all the bytes.
  94.169 +     * @exception  IOException   the stream has been closed and the contained
  94.170 +     *             input stream does not support reading after close, or
  94.171 +     *             another I/O error occurs.
  94.172 +     * @see        java.io.FilterInputStream#in
  94.173 +     */
  94.174 +    public final void readFully(byte b[]) throws IOException {
  94.175 +        readFully(b, 0, b.length);
  94.176 +    }
  94.177 +
  94.178 +    /**
  94.179 +     * See the general contract of the <code>readFully</code>
  94.180 +     * method of <code>DataInput</code>.
  94.181 +     * <p>
  94.182 +     * Bytes
  94.183 +     * for this operation are read from the contained
  94.184 +     * input stream.
  94.185 +     *
  94.186 +     * @param      b     the buffer into which the data is read.
  94.187 +     * @param      off   the start offset of the data.
  94.188 +     * @param      len   the number of bytes to read.
  94.189 +     * @exception  EOFException  if this input stream reaches the end before
  94.190 +     *               reading all the bytes.
  94.191 +     * @exception  IOException   the stream has been closed and the contained
  94.192 +     *             input stream does not support reading after close, or
  94.193 +     *             another I/O error occurs.
  94.194 +     * @see        java.io.FilterInputStream#in
  94.195 +     */
  94.196 +    public final void readFully(byte b[], int off, int len) throws IOException {
  94.197 +        if (len < 0)
  94.198 +            throw new IndexOutOfBoundsException();
  94.199 +        int n = 0;
  94.200 +        while (n < len) {
  94.201 +            int count = in.read(b, off + n, len - n);
  94.202 +            if (count < 0)
  94.203 +                throw new EOFException();
  94.204 +            n += count;
  94.205 +        }
  94.206 +    }
  94.207 +
  94.208 +    /**
  94.209 +     * See the general contract of the <code>skipBytes</code>
  94.210 +     * method of <code>DataInput</code>.
  94.211 +     * <p>
  94.212 +     * Bytes for this operation are read from the contained
  94.213 +     * input stream.
  94.214 +     *
  94.215 +     * @param      n   the number of bytes to be skipped.
  94.216 +     * @return     the actual number of bytes skipped.
  94.217 +     * @exception  IOException  if the contained input stream does not support
  94.218 +     *             seek, or the stream has been closed and
  94.219 +     *             the contained input stream does not support
  94.220 +     *             reading after close, or another I/O error occurs.
  94.221 +     */
  94.222 +    public final int skipBytes(int n) throws IOException {
  94.223 +        int total = 0;
  94.224 +        int cur = 0;
  94.225 +
  94.226 +        while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
  94.227 +            total += cur;
  94.228 +        }
  94.229 +
  94.230 +        return total;
  94.231 +    }
  94.232 +
  94.233 +    /**
  94.234 +     * See the general contract of the <code>readBoolean</code>
  94.235 +     * method of <code>DataInput</code>.
  94.236 +     * <p>
  94.237 +     * Bytes for this operation are read from the contained
  94.238 +     * input stream.
  94.239 +     *
  94.240 +     * @return     the <code>boolean</code> value read.
  94.241 +     * @exception  EOFException  if this input stream has reached the end.
  94.242 +     * @exception  IOException   the stream has been closed and the contained
  94.243 +     *             input stream does not support reading after close, or
  94.244 +     *             another I/O error occurs.
  94.245 +     * @see        java.io.FilterInputStream#in
  94.246 +     */
  94.247 +    public final boolean readBoolean() throws IOException {
  94.248 +        int ch = in.read();
  94.249 +        if (ch < 0)
  94.250 +            throw new EOFException();
  94.251 +        return (ch != 0);
  94.252 +    }
  94.253 +
  94.254 +    /**
  94.255 +     * See the general contract of the <code>readByte</code>
  94.256 +     * method of <code>DataInput</code>.
  94.257 +     * <p>
  94.258 +     * Bytes
  94.259 +     * for this operation are read from the contained
  94.260 +     * input stream.
  94.261 +     *
  94.262 +     * @return     the next byte of this input stream as a signed 8-bit
  94.263 +     *             <code>byte</code>.
  94.264 +     * @exception  EOFException  if this input stream has reached the end.
  94.265 +     * @exception  IOException   the stream has been closed and the contained
  94.266 +     *             input stream does not support reading after close, or
  94.267 +     *             another I/O error occurs.
  94.268 +     * @see        java.io.FilterInputStream#in
  94.269 +     */
  94.270 +    public final byte readByte() throws IOException {
  94.271 +        int ch = in.read();
  94.272 +        if (ch < 0)
  94.273 +            throw new EOFException();
  94.274 +        return (byte)(ch);
  94.275 +    }
  94.276 +
  94.277 +    /**
  94.278 +     * See the general contract of the <code>readUnsignedByte</code>
  94.279 +     * method of <code>DataInput</code>.
  94.280 +     * <p>
  94.281 +     * Bytes
  94.282 +     * for this operation are read from the contained
  94.283 +     * input stream.
  94.284 +     *
  94.285 +     * @return     the next byte of this input stream, interpreted as an
  94.286 +     *             unsigned 8-bit number.
  94.287 +     * @exception  EOFException  if this input stream has reached the end.
  94.288 +     * @exception  IOException   the stream has been closed and the contained
  94.289 +     *             input stream does not support reading after close, or
  94.290 +     *             another I/O error occurs.
  94.291 +     * @see         java.io.FilterInputStream#in
  94.292 +     */
  94.293 +    public final int readUnsignedByte() throws IOException {
  94.294 +        int ch = in.read();
  94.295 +        if (ch < 0)
  94.296 +            throw new EOFException();
  94.297 +        return ch;
  94.298 +    }
  94.299 +
  94.300 +    /**
  94.301 +     * See the general contract of the <code>readShort</code>
  94.302 +     * method of <code>DataInput</code>.
  94.303 +     * <p>
  94.304 +     * Bytes
  94.305 +     * for this operation are read from the contained
  94.306 +     * input stream.
  94.307 +     *
  94.308 +     * @return     the next two bytes of this input stream, interpreted as a
  94.309 +     *             signed 16-bit number.
  94.310 +     * @exception  EOFException  if this input stream reaches the end before
  94.311 +     *               reading two bytes.
  94.312 +     * @exception  IOException   the stream has been closed and the contained
  94.313 +     *             input stream does not support reading after close, or
  94.314 +     *             another I/O error occurs.
  94.315 +     * @see        java.io.FilterInputStream#in
  94.316 +     */
  94.317 +    public final short readShort() throws IOException {
  94.318 +        int ch1 = in.read();
  94.319 +        int ch2 = in.read();
  94.320 +        if ((ch1 | ch2) < 0)
  94.321 +            throw new EOFException();
  94.322 +        return (short)((ch1 << 8) + (ch2 << 0));
  94.323 +    }
  94.324 +
  94.325 +    /**
  94.326 +     * See the general contract of the <code>readUnsignedShort</code>
  94.327 +     * method of <code>DataInput</code>.
  94.328 +     * <p>
  94.329 +     * Bytes
  94.330 +     * for this operation are read from the contained
  94.331 +     * input stream.
  94.332 +     *
  94.333 +     * @return     the next two bytes of this input stream, interpreted as an
  94.334 +     *             unsigned 16-bit integer.
  94.335 +     * @exception  EOFException  if this input stream reaches the end before
  94.336 +     *             reading two bytes.
  94.337 +     * @exception  IOException   the stream has been closed and the contained
  94.338 +     *             input stream does not support reading after close, or
  94.339 +     *             another I/O error occurs.
  94.340 +     * @see        java.io.FilterInputStream#in
  94.341 +     */
  94.342 +    public final int readUnsignedShort() throws IOException {
  94.343 +        int ch1 = in.read();
  94.344 +        int ch2 = in.read();
  94.345 +        if ((ch1 | ch2) < 0)
  94.346 +            throw new EOFException();
  94.347 +        return (ch1 << 8) + (ch2 << 0);
  94.348 +    }
  94.349 +
  94.350 +    /**
  94.351 +     * See the general contract of the <code>readChar</code>
  94.352 +     * method of <code>DataInput</code>.
  94.353 +     * <p>
  94.354 +     * Bytes
  94.355 +     * for this operation are read from the contained
  94.356 +     * input stream.
  94.357 +     *
  94.358 +     * @return     the next two bytes of this input stream, interpreted as a
  94.359 +     *             <code>char</code>.
  94.360 +     * @exception  EOFException  if this input stream reaches the end before
  94.361 +     *               reading two bytes.
  94.362 +     * @exception  IOException   the stream has been closed and the contained
  94.363 +     *             input stream does not support reading after close, or
  94.364 +     *             another I/O error occurs.
  94.365 +     * @see        java.io.FilterInputStream#in
  94.366 +     */
  94.367 +    public final char readChar() throws IOException {
  94.368 +        int ch1 = in.read();
  94.369 +        int ch2 = in.read();
  94.370 +        if ((ch1 | ch2) < 0)
  94.371 +            throw new EOFException();
  94.372 +        return (char)((ch1 << 8) + (ch2 << 0));
  94.373 +    }
  94.374 +
  94.375 +    /**
  94.376 +     * See the general contract of the <code>readInt</code>
  94.377 +     * method of <code>DataInput</code>.
  94.378 +     * <p>
  94.379 +     * Bytes
  94.380 +     * for this operation are read from the contained
  94.381 +     * input stream.
  94.382 +     *
  94.383 +     * @return     the next four bytes of this input stream, interpreted as an
  94.384 +     *             <code>int</code>.
  94.385 +     * @exception  EOFException  if this input stream reaches the end before
  94.386 +     *               reading four bytes.
  94.387 +     * @exception  IOException   the stream has been closed and the contained
  94.388 +     *             input stream does not support reading after close, or
  94.389 +     *             another I/O error occurs.
  94.390 +     * @see        java.io.FilterInputStream#in
  94.391 +     */
  94.392 +    public final int readInt() throws IOException {
  94.393 +        int ch1 = in.read();
  94.394 +        int ch2 = in.read();
  94.395 +        int ch3 = in.read();
  94.396 +        int ch4 = in.read();
  94.397 +        if ((ch1 | ch2 | ch3 | ch4) < 0)
  94.398 +            throw new EOFException();
  94.399 +        return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
  94.400 +    }
  94.401 +
  94.402 +    private byte readBuffer[] = new byte[8];
  94.403 +
  94.404 +    /**
  94.405 +     * See the general contract of the <code>readLong</code>
  94.406 +     * method of <code>DataInput</code>.
  94.407 +     * <p>
  94.408 +     * Bytes
  94.409 +     * for this operation are read from the contained
  94.410 +     * input stream.
  94.411 +     *
  94.412 +     * @return     the next eight bytes of this input stream, interpreted as a
  94.413 +     *             <code>long</code>.
  94.414 +     * @exception  EOFException  if this input stream reaches the end before
  94.415 +     *               reading eight bytes.
  94.416 +     * @exception  IOException   the stream has been closed and the contained
  94.417 +     *             input stream does not support reading after close, or
  94.418 +     *             another I/O error occurs.
  94.419 +     * @see        java.io.FilterInputStream#in
  94.420 +     */
  94.421 +    public final long readLong() throws IOException {
  94.422 +        readFully(readBuffer, 0, 8);
  94.423 +        return (((long)readBuffer[0] << 56) +
  94.424 +                ((long)(readBuffer[1] & 255) << 48) +
  94.425 +                ((long)(readBuffer[2] & 255) << 40) +
  94.426 +                ((long)(readBuffer[3] & 255) << 32) +
  94.427 +                ((long)(readBuffer[4] & 255) << 24) +
  94.428 +                ((readBuffer[5] & 255) << 16) +
  94.429 +                ((readBuffer[6] & 255) <<  8) +
  94.430 +                ((readBuffer[7] & 255) <<  0));
  94.431 +    }
  94.432 +
  94.433 +    /**
  94.434 +     * See the general contract of the <code>readFloat</code>
  94.435 +     * method of <code>DataInput</code>.
  94.436 +     * <p>
  94.437 +     * Bytes
  94.438 +     * for this operation are read from the contained
  94.439 +     * input stream.
  94.440 +     *
  94.441 +     * @return     the next four bytes of this input stream, interpreted as a
  94.442 +     *             <code>float</code>.
  94.443 +     * @exception  EOFException  if this input stream reaches the end before
  94.444 +     *               reading four bytes.
  94.445 +     * @exception  IOException   the stream has been closed and the contained
  94.446 +     *             input stream does not support reading after close, or
  94.447 +     *             another I/O error occurs.
  94.448 +     * @see        java.io.DataInputStream#readInt()
  94.449 +     * @see        java.lang.Float#intBitsToFloat(int)
  94.450 +     */
  94.451 +    public final float readFloat() throws IOException {
  94.452 +        return Float.intBitsToFloat(readInt());
  94.453 +    }
  94.454 +
  94.455 +    /**
  94.456 +     * See the general contract of the <code>readDouble</code>
  94.457 +     * method of <code>DataInput</code>.
  94.458 +     * <p>
  94.459 +     * Bytes
  94.460 +     * for this operation are read from the contained
  94.461 +     * input stream.
  94.462 +     *
  94.463 +     * @return     the next eight bytes of this input stream, interpreted as a
  94.464 +     *             <code>double</code>.
  94.465 +     * @exception  EOFException  if this input stream reaches the end before
  94.466 +     *               reading eight bytes.
  94.467 +     * @exception  IOException   the stream has been closed and the contained
  94.468 +     *             input stream does not support reading after close, or
  94.469 +     *             another I/O error occurs.
  94.470 +     * @see        java.io.DataInputStream#readLong()
  94.471 +     * @see        java.lang.Double#longBitsToDouble(long)
  94.472 +     */
  94.473 +    public final double readDouble() throws IOException {
  94.474 +        int hi = readInt();
  94.475 +        int low = readInt();
  94.476 +        return toDouble(hi, low);
  94.477 +    }
  94.478 +    
  94.479 +    @JavaScriptBody(args={ "hi", "low" },
  94.480 +        body=
  94.481 +          "if (low == 0) {\n"
  94.482 +        + "  if (hi === 0x7ff00000) return Number.POSITIVE_INFINITY;\n"
  94.483 +        + "  if (hi === 0xfff00000) return Number.NEGATIVE_INFINITY;\n"
  94.484 +        + "}\n"
  94.485 +        + "if (hi >= 0x7ff00000 && hi <= 0x7fffffff) return Number.NaN;\n"
  94.486 +        + "if (hi >= 0xfff00000 && hi <= 0xffffffff) return Number.NaN;\n"
  94.487 +        + "var s = (hi & 0x80000000) === 0 ? 1 : -1;\n"
  94.488 +        + "var e = (hi >> 20) & 0x7ff;\n"
  94.489 +        + "var to32 = low >> 0;\n"
  94.490 +        + "if (e === 0) {\n"
  94.491 +        + "  if (to32 & 0x80000000) {\n"
  94.492 +        + "    hi = hi << 1 + 1; low = low << 1;\n"
  94.493 +        + "  } else {\n"
  94.494 +        + "    hi = hi << 1; low = low << 1;\n"
  94.495 +        + "  }\n" 
  94.496 +        + "} else {\n"
  94.497 +        + "    hi = (hi & 0xfffff) | 0x100000;\n"
  94.498 +        + "}\n"
  94.499 +        + "to32 = low >> 0;\n"
  94.500 +        + "var m = Math.pow(2.0, 32) * hi + to32;\n"
  94.501 +        + "var r = s * m * Math.pow(2.0, e - 1075);\n"
  94.502 +        + "//throw 'exp: ' + e + ' sign: ' + s + ' hi:' + hi + ' low: ' + low + ' m: ' + m + ' r: ' + r;\n"
  94.503 +        + "return r;\n"
  94.504 +    )
  94.505 +    private static double toDouble(int hi, int low) {
  94.506 +        long both = hi;
  94.507 +        both = (both << 32) & low;
  94.508 +        return Double.doubleToLongBits(both);
  94.509 +    }
  94.510 +
  94.511 +    private char lineBuffer[];
  94.512 +
  94.513 +    /**
  94.514 +     * See the general contract of the <code>readLine</code>
  94.515 +     * method of <code>DataInput</code>.
  94.516 +     * <p>
  94.517 +     * Bytes
  94.518 +     * for this operation are read from the contained
  94.519 +     * input stream.
  94.520 +     *
  94.521 +     * @deprecated This method does not properly convert bytes to characters.
  94.522 +     * As of JDK&nbsp;1.1, the preferred way to read lines of text is via the
  94.523 +     * <code>BufferedReader.readLine()</code> method.  Programs that use the
  94.524 +     * <code>DataInputStream</code> class to read lines can be converted to use
  94.525 +     * the <code>BufferedReader</code> class by replacing code of the form:
  94.526 +     * <blockquote><pre>
  94.527 +     *     DataInputStream d =&nbsp;new&nbsp;DataInputStream(in);
  94.528 +     * </pre></blockquote>
  94.529 +     * with:
  94.530 +     * <blockquote><pre>
  94.531 +     *     BufferedReader d
  94.532 +     *          =&nbsp;new&nbsp;BufferedReader(new&nbsp;InputStreamReader(in));
  94.533 +     * </pre></blockquote>
  94.534 +     *
  94.535 +     * @return     the next line of text from this input stream.
  94.536 +     * @exception  IOException  if an I/O error occurs.
  94.537 +     * @see        java.io.BufferedReader#readLine()
  94.538 +     * @see        java.io.FilterInputStream#in
  94.539 +     */
  94.540 +    @Deprecated
  94.541 +    public final String readLine() throws IOException {
  94.542 +        char buf[] = lineBuffer;
  94.543 +
  94.544 +        if (buf == null) {
  94.545 +            buf = lineBuffer = new char[128];
  94.546 +        }
  94.547 +
  94.548 +        int room = buf.length;
  94.549 +        int offset = 0;
  94.550 +        int c;
  94.551 +
  94.552 +loop:   while (true) {
  94.553 +            switch (c = in.read()) {
  94.554 +              case -1:
  94.555 +              case '\n':
  94.556 +                break loop;
  94.557 +
  94.558 +              case '\r':
  94.559 +                int c2 = in.read();
  94.560 +                if ((c2 != '\n') && (c2 != -1)) {
  94.561 +                    if (!(in instanceof PushbackInputStream)) {
  94.562 +                        this.in = new PushbackInputStream(in);
  94.563 +                    }
  94.564 +                    ((PushbackInputStream)in).unread(c2);
  94.565 +                }
  94.566 +                break loop;
  94.567 +
  94.568 +              default:
  94.569 +                if (--room < 0) {
  94.570 +                    buf = new char[offset + 128];
  94.571 +                    room = buf.length - offset - 1;
  94.572 +                    System.arraycopy(lineBuffer, 0, buf, 0, offset);
  94.573 +                    lineBuffer = buf;
  94.574 +                }
  94.575 +                buf[offset++] = (char) c;
  94.576 +                break;
  94.577 +            }
  94.578 +        }
  94.579 +        if ((c == -1) && (offset == 0)) {
  94.580 +            return null;
  94.581 +        }
  94.582 +        return String.copyValueOf(buf, 0, offset);
  94.583 +    }
  94.584 +
  94.585 +    /**
  94.586 +     * See the general contract of the <code>readUTF</code>
  94.587 +     * method of <code>DataInput</code>.
  94.588 +     * <p>
  94.589 +     * Bytes
  94.590 +     * for this operation are read from the contained
  94.591 +     * input stream.
  94.592 +     *
  94.593 +     * @return     a Unicode string.
  94.594 +     * @exception  EOFException  if this input stream reaches the end before
  94.595 +     *               reading all the bytes.
  94.596 +     * @exception  IOException   the stream has been closed and the contained
  94.597 +     *             input stream does not support reading after close, or
  94.598 +     *             another I/O error occurs.
  94.599 +     * @exception  UTFDataFormatException if the bytes do not represent a valid
  94.600 +     *             modified UTF-8 encoding of a string.
  94.601 +     * @see        java.io.DataInputStream#readUTF(java.io.DataInput)
  94.602 +     */
  94.603 +    public final String readUTF() throws IOException {
  94.604 +        return readUTF(this);
  94.605 +    }
  94.606 +
  94.607 +    /**
  94.608 +     * Reads from the
  94.609 +     * stream <code>in</code> a representation
  94.610 +     * of a Unicode  character string encoded in
  94.611 +     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
  94.612 +     * this string of characters is then returned as a <code>String</code>.
  94.613 +     * The details of the modified UTF-8 representation
  94.614 +     * are  exactly the same as for the <code>readUTF</code>
  94.615 +     * method of <code>DataInput</code>.
  94.616 +     *
  94.617 +     * @param      in   a data input stream.
  94.618 +     * @return     a Unicode string.
  94.619 +     * @exception  EOFException            if the input stream reaches the end
  94.620 +     *               before all the bytes.
  94.621 +     * @exception  IOException   the stream has been closed and the contained
  94.622 +     *             input stream does not support reading after close, or
  94.623 +     *             another I/O error occurs.
  94.624 +     * @exception  UTFDataFormatException  if the bytes do not represent a
  94.625 +     *               valid modified UTF-8 encoding of a Unicode string.
  94.626 +     * @see        java.io.DataInputStream#readUnsignedShort()
  94.627 +     */
  94.628 +    public final static String readUTF(DataInput in) throws IOException {
  94.629 +        int utflen = in.readUnsignedShort();
  94.630 +        byte[] bytearr = null;
  94.631 +        char[] chararr = null;
  94.632 +        if (in instanceof DataInputStream) {
  94.633 +            DataInputStream dis = (DataInputStream)in;
  94.634 +            if (dis.bytearr.length < utflen){
  94.635 +                dis.bytearr = new byte[utflen*2];
  94.636 +                dis.chararr = new char[utflen*2];
  94.637 +            }
  94.638 +            chararr = dis.chararr;
  94.639 +            bytearr = dis.bytearr;
  94.640 +        } else {
  94.641 +            bytearr = new byte[utflen];
  94.642 +            chararr = new char[utflen];
  94.643 +        }
  94.644 +
  94.645 +        int c, char2, char3;
  94.646 +        int count = 0;
  94.647 +        int chararr_count=0;
  94.648 +
  94.649 +        in.readFully(bytearr, 0, utflen);
  94.650 +
  94.651 +        while (count < utflen) {
  94.652 +            c = (int) bytearr[count] & 0xff;
  94.653 +            if (c > 127) break;
  94.654 +            count++;
  94.655 +            chararr[chararr_count++]=(char)c;
  94.656 +        }
  94.657 +
  94.658 +        while (count < utflen) {
  94.659 +            c = (int) bytearr[count] & 0xff;
  94.660 +            switch (c >> 4) {
  94.661 +                case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
  94.662 +                    /* 0xxxxxxx*/
  94.663 +                    count++;
  94.664 +                    chararr[chararr_count++]=(char)c;
  94.665 +                    break;
  94.666 +                case 12: case 13:
  94.667 +                    /* 110x xxxx   10xx xxxx*/
  94.668 +                    count += 2;
  94.669 +                    if (count > utflen)
  94.670 +                        throw new UTFDataFormatException(
  94.671 +                            "malformed input: partial character at end");
  94.672 +                    char2 = (int) bytearr[count-1];
  94.673 +                    if ((char2 & 0xC0) != 0x80)
  94.674 +                        throw new UTFDataFormatException(
  94.675 +                            "malformed input around byte " + count);
  94.676 +                    chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
  94.677 +                                                    (char2 & 0x3F));
  94.678 +                    break;
  94.679 +                case 14:
  94.680 +                    /* 1110 xxxx  10xx xxxx  10xx xxxx */
  94.681 +                    count += 3;
  94.682 +                    if (count > utflen)
  94.683 +                        throw new UTFDataFormatException(
  94.684 +                            "malformed input: partial character at end");
  94.685 +                    char2 = (int) bytearr[count-2];
  94.686 +                    char3 = (int) bytearr[count-1];
  94.687 +                    if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
  94.688 +                        throw new UTFDataFormatException(
  94.689 +                            "malformed input around byte " + (count-1));
  94.690 +                    chararr[chararr_count++]=(char)(((c     & 0x0F) << 12) |
  94.691 +                                                    ((char2 & 0x3F) << 6)  |
  94.692 +                                                    ((char3 & 0x3F) << 0));
  94.693 +                    break;
  94.694 +                default:
  94.695 +                    /* 10xx xxxx,  1111 xxxx */
  94.696 +                    throw new UTFDataFormatException(
  94.697 +                        "malformed input around byte " + count);
  94.698 +            }
  94.699 +        }
  94.700 +        // The number of chars produced may be less than utflen
  94.701 +        return new String(chararr, 0, chararr_count);
  94.702 +    }
  94.703 +}
    95.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    95.2 +++ b/emul/mini/src/main/java/java/io/EOFException.java	Sun Feb 03 07:48:42 2013 +0100
    95.3 @@ -0,0 +1,65 @@
    95.4 +/*
    95.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
    95.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    95.7 + *
    95.8 + * This code is free software; you can redistribute it and/or modify it
    95.9 + * under the terms of the GNU General Public License version 2 only, as
   95.10 + * published by the Free Software Foundation.  Oracle designates this
   95.11 + * particular file as subject to the "Classpath" exception as provided
   95.12 + * by Oracle in the LICENSE file that accompanied this code.
   95.13 + *
   95.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   95.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   95.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   95.17 + * version 2 for more details (a copy is included in the LICENSE file that
   95.18 + * accompanied this code).
   95.19 + *
   95.20 + * You should have received a copy of the GNU General Public License version
   95.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   95.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   95.23 + *
   95.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   95.25 + * or visit www.oracle.com if you need additional information or have any
   95.26 + * questions.
   95.27 + */
   95.28 +
   95.29 +package java.io;
   95.30 +
   95.31 +/**
   95.32 + * Signals that an end of file or end of stream has been reached
   95.33 + * unexpectedly during input.
   95.34 + * <p>
   95.35 + * This exception is mainly used by data input streams to signal end of
   95.36 + * stream. Note that many other input operations return a special value on
   95.37 + * end of stream rather than throwing an exception.
   95.38 + * <p>
   95.39 + *
   95.40 + * @author  Frank Yellin
   95.41 + * @see     java.io.DataInputStream
   95.42 + * @see     java.io.IOException
   95.43 + * @since   JDK1.0
   95.44 + */
   95.45 +public
   95.46 +class EOFException extends IOException {
   95.47 +    private static final long serialVersionUID = 6433858223774886977L;
   95.48 +
   95.49 +    /**
   95.50 +     * Constructs an <code>EOFException</code> with <code>null</code>
   95.51 +     * as its error detail message.
   95.52 +     */
   95.53 +    public EOFException() {
   95.54 +        super();
   95.55 +    }
   95.56 +
   95.57 +    /**
   95.58 +     * Constructs an <code>EOFException</code> with the specified detail
   95.59 +     * message. The string <code>s</code> may later be retrieved by the
   95.60 +     * <code>{@link java.lang.Throwable#getMessage}</code> method of class
   95.61 +     * <code>java.lang.Throwable</code>.
   95.62 +     *
   95.63 +     * @param   s   the detail message.
   95.64 +     */
   95.65 +    public EOFException(String s) {
   95.66 +        super(s);
   95.67 +    }
   95.68 +}
    96.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    96.2 +++ b/emul/mini/src/main/java/java/io/FilterInputStream.java	Sun Feb 03 07:48:42 2013 +0100
    96.3 @@ -0,0 +1,245 @@
    96.4 +/*
    96.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
    96.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    96.7 + *
    96.8 + * This code is free software; you can redistribute it and/or modify it
    96.9 + * under the terms of the GNU General Public License version 2 only, as
   96.10 + * published by the Free Software Foundation.  Oracle designates this
   96.11 + * particular file as subject to the "Classpath" exception as provided
   96.12 + * by Oracle in the LICENSE file that accompanied this code.
   96.13 + *
   96.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   96.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   96.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   96.17 + * version 2 for more details (a copy is included in the LICENSE file that
   96.18 + * accompanied this code).
   96.19 + *
   96.20 + * You should have received a copy of the GNU General Public License version
   96.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   96.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   96.23 + *
   96.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   96.25 + * or visit www.oracle.com if you need additional information or have any
   96.26 + * questions.
   96.27 + */
   96.28 +
   96.29 +package java.io;
   96.30 +
   96.31 +/**
   96.32 + * A <code>FilterInputStream</code> contains
   96.33 + * some other input stream, which it uses as
   96.34 + * its  basic source of data, possibly transforming
   96.35 + * the data along the way or providing  additional
   96.36 + * functionality. The class <code>FilterInputStream</code>
   96.37 + * itself simply overrides all  methods of
   96.38 + * <code>InputStream</code> with versions that
   96.39 + * pass all requests to the contained  input
   96.40 + * stream. Subclasses of <code>FilterInputStream</code>
   96.41 + * may further override some of  these methods
   96.42 + * and may also provide additional methods
   96.43 + * and fields.
   96.44 + *
   96.45 + * @author  Jonathan Payne
   96.46 + * @since   JDK1.0
   96.47 + */
   96.48 +public
   96.49 +class FilterInputStream extends InputStream {
   96.50 +    /**
   96.51 +     * The input stream to be filtered.
   96.52 +     */
   96.53 +    protected volatile InputStream in;
   96.54 +
   96.55 +    /**
   96.56 +     * Creates a <code>FilterInputStream</code>
   96.57 +     * by assigning the  argument <code>in</code>
   96.58 +     * to the field <code>this.in</code> so as
   96.59 +     * to remember it for later use.
   96.60 +     *
   96.61 +     * @param   in   the underlying input stream, or <code>null</code> if
   96.62 +     *          this instance is to be created without an underlying stream.
   96.63 +     */
   96.64 +    protected FilterInputStream(InputStream in) {
   96.65 +        this.in = in;
   96.66 +    }
   96.67 +
   96.68 +    /**
   96.69 +     * Reads the next byte of data from this input stream. The value
   96.70 +     * byte is returned as an <code>int</code> in the range
   96.71 +     * <code>0</code> to <code>255</code>. If no byte is available
   96.72 +     * because the end of the stream has been reached, the value
   96.73 +     * <code>-1</code> is returned. This method blocks until input data
   96.74 +     * is available, the end of the stream is detected, or an exception
   96.75 +     * is thrown.
   96.76 +     * <p>
   96.77 +     * This method
   96.78 +     * simply performs <code>in.read()</code> and returns the result.
   96.79 +     *
   96.80 +     * @return     the next byte of data, or <code>-1</code> if the end of the
   96.81 +     *             stream is reached.
   96.82 +     * @exception  IOException  if an I/O error occurs.
   96.83 +     * @see        java.io.FilterInputStream#in
   96.84 +     */
   96.85 +    public int read() throws IOException {
   96.86 +        return in.read();
   96.87 +    }
   96.88 +
   96.89 +    /**
   96.90 +     * Reads up to <code>byte.length</code> bytes of data from this
   96.91 +     * input stream into an array of bytes. This method blocks until some
   96.92 +     * input is available.
   96.93 +     * <p>
   96.94 +     * This method simply performs the call
   96.95 +     * <code>read(b, 0, b.length)</code> and returns
   96.96 +     * the  result. It is important that it does
   96.97 +     * <i>not</i> do <code>in.read(b)</code> instead;
   96.98 +     * certain subclasses of  <code>FilterInputStream</code>
   96.99 +     * depend on the implementation strategy actually
  96.100 +     * used.
  96.101 +     *
  96.102 +     * @param      b   the buffer into which the data is read.
  96.103 +     * @return     the total number of bytes read into the buffer, or
  96.104 +     *             <code>-1</code> if there is no more data because the end of
  96.105 +     *             the stream has been reached.
  96.106 +     * @exception  IOException  if an I/O error occurs.
  96.107 +     * @see        java.io.FilterInputStream#read(byte[], int, int)
  96.108 +     */
  96.109 +    public int read(byte b[]) throws IOException {
  96.110 +        return read(b, 0, b.length);
  96.111 +    }
  96.112 +
  96.113 +    /**
  96.114 +     * Reads up to <code>len</code> bytes of data from this input stream
  96.115 +     * into an array of bytes. If <code>len</code> is not zero, the method
  96.116 +     * blocks until some input is available; otherwise, no
  96.117 +     * bytes are read and <code>0</code> is returned.
  96.118 +     * <p>
  96.119 +     * This method simply performs <code>in.read(b, off, len)</code>
  96.120 +     * and returns the result.
  96.121 +     *
  96.122 +     * @param      b     the buffer into which the data is read.
  96.123 +     * @param      off   the start offset in the destination array <code>b</code>
  96.124 +     * @param      len   the maximum number of bytes read.
  96.125 +     * @return     the total number of bytes read into the buffer, or
  96.126 +     *             <code>-1</code> if there is no more data because the end of
  96.127 +     *             the stream has been reached.
  96.128 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
  96.129 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
  96.130 +     * <code>len</code> is negative, or <code>len</code> is greater than
  96.131 +     * <code>b.length - off</code>
  96.132 +     * @exception  IOException  if an I/O error occurs.
  96.133 +     * @see        java.io.FilterInputStream#in
  96.134 +     */
  96.135 +    public int read(byte b[], int off, int len) throws IOException {
  96.136 +        return in.read(b, off, len);
  96.137 +    }
  96.138 +
  96.139 +    /**
  96.140 +     * Skips over and discards <code>n</code> bytes of data from the
  96.141 +     * input stream. The <code>skip</code> method may, for a variety of
  96.142 +     * reasons, end up skipping over some smaller number of bytes,
  96.143 +     * possibly <code>0</code>. The actual number of bytes skipped is
  96.144 +     * returned.
  96.145 +     * <p>
  96.146 +     * This method simply performs <code>in.skip(n)</code>.
  96.147 +     *
  96.148 +     * @param      n   the number of bytes to be skipped.
  96.149 +     * @return     the actual number of bytes skipped.
  96.150 +     * @exception  IOException  if the stream does not support seek,
  96.151 +     *                          or if some other I/O error occurs.
  96.152 +     */
  96.153 +    public long skip(long n) throws IOException {
  96.154 +        return in.skip(n);
  96.155 +    }
  96.156 +
  96.157 +    /**
  96.158 +     * Returns an estimate of the number of bytes that can be read (or
  96.159 +     * skipped over) from this input stream without blocking by the next
  96.160 +     * caller of a method for this input stream. The next caller might be
  96.161 +     * the same thread or another thread.  A single read or skip of this
  96.162 +     * many bytes will not block, but may read or skip fewer bytes.
  96.163 +     * <p>
  96.164 +     * This method returns the result of {@link #in in}.available().
  96.165 +     *
  96.166 +     * @return     an estimate of the number of bytes that can be read (or skipped
  96.167 +     *             over) from this input stream without blocking.
  96.168 +     * @exception  IOException  if an I/O error occurs.
  96.169 +     */
  96.170 +    public int available() throws IOException {
  96.171 +        return in.available();
  96.172 +    }
  96.173 +
  96.174 +    /**
  96.175 +     * Closes this input stream and releases any system resources
  96.176 +     * associated with the stream.
  96.177 +     * This
  96.178 +     * method simply performs <code>in.close()</code>.
  96.179 +     *
  96.180 +     * @exception  IOException  if an I/O error occurs.
  96.181 +     * @see        java.io.FilterInputStream#in
  96.182 +     */
  96.183 +    public void close() throws IOException {
  96.184 +        in.close();
  96.185 +    }
  96.186 +
  96.187 +    /**
  96.188 +     * Marks the current position in this input stream. A subsequent
  96.189 +     * call to the <code>reset</code> method repositions this stream at
  96.190 +     * the last marked position so that subsequent reads re-read the same bytes.
  96.191 +     * <p>
  96.192 +     * The <code>readlimit</code> argument tells this input stream to
  96.193 +     * allow that many bytes to be read before the mark position gets
  96.194 +     * invalidated.
  96.195 +     * <p>
  96.196 +     * This method simply performs <code>in.mark(readlimit)</code>.
  96.197 +     *
  96.198 +     * @param   readlimit   the maximum limit of bytes that can be read before
  96.199 +     *                      the mark position becomes invalid.
  96.200 +     * @see     java.io.FilterInputStream#in
  96.201 +     * @see     java.io.FilterInputStream#reset()
  96.202 +     */
  96.203 +    public synchronized void mark(int readlimit) {
  96.204 +        in.mark(readlimit);
  96.205 +    }
  96.206 +
  96.207 +    /**
  96.208 +     * Repositions this stream to the position at the time the
  96.209 +     * <code>mark</code> method was last called on this input stream.
  96.210 +     * <p>
  96.211 +     * This method
  96.212 +     * simply performs <code>in.reset()</code>.
  96.213 +     * <p>
  96.214 +     * Stream marks are intended to be used in
  96.215 +     * situations where you need to read ahead a little to see what's in
  96.216 +     * the stream. Often this is most easily done by invoking some
  96.217 +     * general parser. If the stream is of the type handled by the
  96.218 +     * parse, it just chugs along happily. If the stream is not of
  96.219 +     * that type, the parser should toss an exception when it fails.
  96.220 +     * If this happens within readlimit bytes, it allows the outer
  96.221 +     * code to reset the stream and try another parser.
  96.222 +     *
  96.223 +     * @exception  IOException  if the stream has not been marked or if the
  96.224 +     *               mark has been invalidated.
  96.225 +     * @see        java.io.FilterInputStream#in
  96.226 +     * @see        java.io.FilterInputStream#mark(int)
  96.227 +     */
  96.228 +    public synchronized void reset() throws IOException {
  96.229 +        in.reset();
  96.230 +    }
  96.231 +
  96.232 +    /**
  96.233 +     * Tests if this input stream supports the <code>mark</code>
  96.234 +     * and <code>reset</code> methods.
  96.235 +     * This method
  96.236 +     * simply performs <code>in.markSupported()</code>.
  96.237 +     *
  96.238 +     * @return  <code>true</code> if this stream type supports the
  96.239 +     *          <code>mark</code> and <code>reset</code> method;
  96.240 +     *          <code>false</code> otherwise.
  96.241 +     * @see     java.io.FilterInputStream#in
  96.242 +     * @see     java.io.InputStream#mark(int)
  96.243 +     * @see     java.io.InputStream#reset()
  96.244 +     */
  96.245 +    public boolean markSupported() {
  96.246 +        return in.markSupported();
  96.247 +    }
  96.248 +}
    97.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    97.2 +++ b/emul/mini/src/main/java/java/io/IOException.java	Sun Feb 03 07:48:42 2013 +0100
    97.3 @@ -0,0 +1,101 @@
    97.4 +/*
    97.5 + * Copyright (c) 1994, 2006, 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 + * Signals that an I/O exception of some sort has occurred. This
   97.33 + * class is the general class of exceptions produced by failed or
   97.34 + * interrupted I/O operations.
   97.35 + *
   97.36 + * @author  unascribed
   97.37 + * @see     java.io.InputStream
   97.38 + * @see     java.io.OutputStream
   97.39 + * @since   JDK1.0
   97.40 + */
   97.41 +public
   97.42 +class IOException extends Exception {
   97.43 +    static final long serialVersionUID = 7818375828146090155L;
   97.44 +
   97.45 +    /**
   97.46 +     * Constructs an {@code IOException} with {@code null}
   97.47 +     * as its error detail message.
   97.48 +     */
   97.49 +    public IOException() {
   97.50 +        super();
   97.51 +    }
   97.52 +
   97.53 +    /**
   97.54 +     * Constructs an {@code IOException} with the specified detail message.
   97.55 +     *
   97.56 +     * @param message
   97.57 +     *        The detail message (which is saved for later retrieval
   97.58 +     *        by the {@link #getMessage()} method)
   97.59 +     */
   97.60 +    public IOException(String message) {
   97.61 +        super(message);
   97.62 +    }
   97.63 +
   97.64 +    /**
   97.65 +     * Constructs an {@code IOException} with the specified detail message
   97.66 +     * and cause.
   97.67 +     *
   97.68 +     * <p> Note that the detail message associated with {@code cause} is
   97.69 +     * <i>not</i> automatically incorporated into this exception's detail
   97.70 +     * message.
   97.71 +     *
   97.72 +     * @param message
   97.73 +     *        The detail message (which is saved for later retrieval
   97.74 +     *        by the {@link #getMessage()} method)
   97.75 +     *
   97.76 +     * @param cause
   97.77 +     *        The cause (which is saved for later retrieval by the
   97.78 +     *        {@link #getCause()} method).  (A null value is permitted,
   97.79 +     *        and indicates that the cause is nonexistent or unknown.)
   97.80 +     *
   97.81 +     * @since 1.6
   97.82 +     */
   97.83 +    public IOException(String message, Throwable cause) {
   97.84 +        super(message, cause);
   97.85 +    }
   97.86 +
   97.87 +    /**
   97.88 +     * Constructs an {@code IOException} with the specified cause and a
   97.89 +     * detail message of {@code (cause==null ? null : cause.toString())}
   97.90 +     * (which typically contains the class and detail message of {@code cause}).
   97.91 +     * This constructor is useful for IO exceptions that are little more
   97.92 +     * than wrappers for other throwables.
   97.93 +     *
   97.94 +     * @param cause
   97.95 +     *        The cause (which is saved for later retrieval by the
   97.96 +     *        {@link #getCause()} method).  (A null value is permitted,
   97.97 +     *        and indicates that the cause is nonexistent or unknown.)
   97.98 +     *
   97.99 +     * @since 1.6
  97.100 +     */
  97.101 +    public IOException(Throwable cause) {
  97.102 +        super(cause);
  97.103 +    }
  97.104 +}
    98.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    98.2 +++ b/emul/mini/src/main/java/java/io/InputStream.java	Sun Feb 03 07:48:42 2013 +0100
    98.3 @@ -0,0 +1,370 @@
    98.4 +/*
    98.5 + * Copyright (c) 1994, 2006, 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 +/**
   98.32 + * This abstract class is the superclass of all classes representing
   98.33 + * an input stream of bytes.
   98.34 + *
   98.35 + * <p> Applications that need to define a subclass of <code>InputStream</code>
   98.36 + * must always provide a method that returns the next byte of input.
   98.37 + *
   98.38 + * @author  Arthur van Hoff
   98.39 + * @see     java.io.BufferedInputStream
   98.40 + * @see     java.io.ByteArrayInputStream
   98.41 + * @see     java.io.DataInputStream
   98.42 + * @see     java.io.FilterInputStream
   98.43 + * @see     java.io.InputStream#read()
   98.44 + * @see     java.io.OutputStream
   98.45 + * @see     java.io.PushbackInputStream
   98.46 + * @since   JDK1.0
   98.47 + */
   98.48 +public abstract class InputStream implements Closeable {
   98.49 +
   98.50 +    // SKIP_BUFFER_SIZE is used to determine the size of skipBuffer
   98.51 +    private static final int SKIP_BUFFER_SIZE = 2048;
   98.52 +    // skipBuffer is initialized in skip(long), if needed.
   98.53 +    private static byte[] skipBuffer;
   98.54 +
   98.55 +    /**
   98.56 +     * Reads the next byte of data from the input stream. The value byte is
   98.57 +     * returned as an <code>int</code> in the range <code>0</code> to
   98.58 +     * <code>255</code>. If no byte is available because the end of the stream
   98.59 +     * has been reached, the value <code>-1</code> is returned. This method
   98.60 +     * blocks until input data is available, the end of the stream is detected,
   98.61 +     * or an exception is thrown.
   98.62 +     *
   98.63 +     * <p> A subclass must provide an implementation of this method.
   98.64 +     *
   98.65 +     * @return     the next byte of data, or <code>-1</code> if the end of the
   98.66 +     *             stream is reached.
   98.67 +     * @exception  IOException  if an I/O error occurs.
   98.68 +     */
   98.69 +    public abstract int read() throws IOException;
   98.70 +
   98.71 +    /**
   98.72 +     * Reads some number of bytes from the input stream and stores them into
   98.73 +     * the buffer array <code>b</code>. The number of bytes actually read is
   98.74 +     * returned as an integer.  This method blocks until input data is
   98.75 +     * available, end of file is detected, or an exception is thrown.
   98.76 +     *
   98.77 +     * <p> If the length of <code>b</code> is zero, then no bytes are read and
   98.78 +     * <code>0</code> is returned; otherwise, there is an attempt to read at
   98.79 +     * least one byte. If no byte is available because the stream is at the
   98.80 +     * end of the file, the value <code>-1</code> is returned; otherwise, at
   98.81 +     * least one byte is read and stored into <code>b</code>.
   98.82 +     *
   98.83 +     * <p> The first byte read is stored into element <code>b[0]</code>, the
   98.84 +     * next one into <code>b[1]</code>, and so on. The number of bytes read is,
   98.85 +     * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
   98.86 +     * number of bytes actually read; these bytes will be stored in elements
   98.87 +     * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
   98.88 +     * leaving elements <code>b[</code><i>k</i><code>]</code> through
   98.89 +     * <code>b[b.length-1]</code> unaffected.
   98.90 +     *
   98.91 +     * <p> The <code>read(b)</code> method for class <code>InputStream</code>
   98.92 +     * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
   98.93 +     *
   98.94 +     * @param      b   the buffer into which the data is read.
   98.95 +     * @return     the total number of bytes read into the buffer, or
   98.96 +     *             <code>-1</code> if there is no more data because the end of
   98.97 +     *             the stream has been reached.
   98.98 +     * @exception  IOException  If the first byte cannot be read for any reason
   98.99 +     * other than the end of the file, if the input stream has been closed, or
  98.100 +     * if some other I/O error occurs.
  98.101 +     * @exception  NullPointerException  if <code>b</code> is <code>null</code>.
  98.102 +     * @see        java.io.InputStream#read(byte[], int, int)
  98.103 +     */
  98.104 +    public int read(byte b[]) throws IOException {
  98.105 +        return read(b, 0, b.length);
  98.106 +    }
  98.107 +
  98.108 +    /**
  98.109 +     * Reads up to <code>len</code> bytes of data from the input stream into
  98.110 +     * an array of bytes.  An attempt is made to read as many as
  98.111 +     * <code>len</code> bytes, but a smaller number may be read.
  98.112 +     * The number of bytes actually read is returned as an integer.
  98.113 +     *
  98.114 +     * <p> This method blocks until input data is available, end of file is
  98.115 +     * detected, or an exception is thrown.
  98.116 +     *
  98.117 +     * <p> If <code>len</code> is zero, then no bytes are read and
  98.118 +     * <code>0</code> is returned; otherwise, there is an attempt to read at
  98.119 +     * least one byte. If no byte is available because the stream is at end of
  98.120 +     * file, the value <code>-1</code> is returned; otherwise, at least one
  98.121 +     * byte is read and stored into <code>b</code>.
  98.122 +     *
  98.123 +     * <p> The first byte read is stored into element <code>b[off]</code>, the
  98.124 +     * next one into <code>b[off+1]</code>, and so on. The number of bytes read
  98.125 +     * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
  98.126 +     * bytes actually read; these bytes will be stored in elements
  98.127 +     * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
  98.128 +     * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
  98.129 +     * <code>b[off+len-1]</code> unaffected.
  98.130 +     *
  98.131 +     * <p> In every case, elements <code>b[0]</code> through
  98.132 +     * <code>b[off]</code> and elements <code>b[off+len]</code> through
  98.133 +     * <code>b[b.length-1]</code> are unaffected.
  98.134 +     *
  98.135 +     * <p> The <code>read(b,</code> <code>off,</code> <code>len)</code> method
  98.136 +     * for class <code>InputStream</code> simply calls the method
  98.137 +     * <code>read()</code> repeatedly. If the first such call results in an
  98.138 +     * <code>IOException</code>, that exception is returned from the call to
  98.139 +     * the <code>read(b,</code> <code>off,</code> <code>len)</code> method.  If
  98.140 +     * any subsequent call to <code>read()</code> results in a
  98.141 +     * <code>IOException</code>, the exception is caught and treated as if it
  98.142 +     * were end of file; the bytes read up to that point are stored into
  98.143 +     * <code>b</code> and the number of bytes read before the exception
  98.144 +     * occurred is returned. The default implementation of this method blocks
  98.145 +     * until the requested amount of input data <code>len</code> has been read,
  98.146 +     * end of file is detected, or an exception is thrown. Subclasses are encouraged
  98.147 +     * to provide a more efficient implementation of this method.
  98.148 +     *
  98.149 +     * @param      b     the buffer into which the data is read.
  98.150 +     * @param      off   the start offset in array <code>b</code>
  98.151 +     *                   at which the data is written.
  98.152 +     * @param      len   the maximum number of bytes to read.
  98.153 +     * @return     the total number of bytes read into the buffer, or
  98.154 +     *             <code>-1</code> if there is no more data because the end of
  98.155 +     *             the stream has been reached.
  98.156 +     * @exception  IOException If the first byte cannot be read for any reason
  98.157 +     * other than end of file, or if the input stream has been closed, or if
  98.158 +     * some other I/O error occurs.
  98.159 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
  98.160 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
  98.161 +     * <code>len</code> is negative, or <code>len</code> is greater than
  98.162 +     * <code>b.length - off</code>
  98.163 +     * @see        java.io.InputStream#read()
  98.164 +     */
  98.165 +    public int read(byte b[], int off, int len) throws IOException {
  98.166 +        if (b == null) {
  98.167 +            throw new NullPointerException();
  98.168 +        } else if (off < 0 || len < 0 || len > b.length - off) {
  98.169 +            throw new IndexOutOfBoundsException();
  98.170 +        } else if (len == 0) {
  98.171 +            return 0;
  98.172 +        }
  98.173 +
  98.174 +        int c = read();
  98.175 +        if (c == -1) {
  98.176 +            return -1;
  98.177 +        }
  98.178 +        b[off] = (byte)c;
  98.179 +
  98.180 +        int i = 1;
  98.181 +        try {
  98.182 +            for (; i < len ; i++) {
  98.183 +                c = read();
  98.184 +                if (c == -1) {
  98.185 +                    break;
  98.186 +                }
  98.187 +                b[off + i] = (byte)c;
  98.188 +            }
  98.189 +        } catch (IOException ee) {
  98.190 +        }
  98.191 +        return i;
  98.192 +    }
  98.193 +
  98.194 +    /**
  98.195 +     * Skips over and discards <code>n</code> bytes of data from this input
  98.196 +     * stream. The <code>skip</code> method may, for a variety of reasons, end
  98.197 +     * up skipping over some smaller number of bytes, possibly <code>0</code>.
  98.198 +     * This may result from any of a number of conditions; reaching end of file
  98.199 +     * before <code>n</code> bytes have been skipped is only one possibility.
  98.200 +     * The actual number of bytes skipped is returned.  If <code>n</code> is
  98.201 +     * negative, no bytes are skipped.
  98.202 +     *
  98.203 +     * <p> The <code>skip</code> method of this class creates a
  98.204 +     * byte array and then repeatedly reads into it until <code>n</code> bytes
  98.205 +     * have been read or the end of the stream has been reached. Subclasses are
  98.206 +     * encouraged to provide a more efficient implementation of this method.
  98.207 +     * For instance, the implementation may depend on the ability to seek.
  98.208 +     *
  98.209 +     * @param      n   the number of bytes to be skipped.
  98.210 +     * @return     the actual number of bytes skipped.
  98.211 +     * @exception  IOException  if the stream does not support seek,
  98.212 +     *                          or if some other I/O error occurs.
  98.213 +     */
  98.214 +    public long skip(long n) throws IOException {
  98.215 +
  98.216 +        long remaining = n;
  98.217 +        int nr;
  98.218 +        if (skipBuffer == null)
  98.219 +            skipBuffer = new byte[SKIP_BUFFER_SIZE];
  98.220 +
  98.221 +        byte[] localSkipBuffer = skipBuffer;
  98.222 +
  98.223 +        if (n <= 0) {
  98.224 +            return 0;
  98.225 +        }
  98.226 +
  98.227 +        while (remaining > 0) {
  98.228 +            nr = read(localSkipBuffer, 0,
  98.229 +                      (int) Math.min(SKIP_BUFFER_SIZE, remaining));
  98.230 +            if (nr < 0) {
  98.231 +                break;
  98.232 +            }
  98.233 +            remaining -= nr;
  98.234 +        }
  98.235 +
  98.236 +        return n - remaining;
  98.237 +    }
  98.238 +
  98.239 +    /**
  98.240 +     * Returns an estimate of the number of bytes that can be read (or
  98.241 +     * skipped over) from this input stream without blocking by the next
  98.242 +     * invocation of a method for this input stream. The next invocation
  98.243 +     * might be the same thread or another thread.  A single read or skip of this
  98.244 +     * many bytes will not block, but may read or skip fewer bytes.
  98.245 +     *
  98.246 +     * <p> Note that while some implementations of {@code InputStream} will return
  98.247 +     * the total number of bytes in the stream, many will not.  It is
  98.248 +     * never correct to use the return value of this method to allocate
  98.249 +     * a buffer intended to hold all data in this stream.
  98.250 +     *
  98.251 +     * <p> A subclass' implementation of this method may choose to throw an
  98.252 +     * {@link IOException} if this input stream has been closed by
  98.253 +     * invoking the {@link #close()} method.
  98.254 +     *
  98.255 +     * <p> The {@code available} method for class {@code InputStream} always
  98.256 +     * returns {@code 0}.
  98.257 +     *
  98.258 +     * <p> This method should be overridden by subclasses.
  98.259 +     *
  98.260 +     * @return     an estimate of the number of bytes that can be read (or skipped
  98.261 +     *             over) from this input stream without blocking or {@code 0} when
  98.262 +     *             it reaches the end of the input stream.
  98.263 +     * @exception  IOException if an I/O error occurs.
  98.264 +     */
  98.265 +    public int available() throws IOException {
  98.266 +        return 0;
  98.267 +    }
  98.268 +
  98.269 +    /**
  98.270 +     * Closes this input stream and releases any system resources associated
  98.271 +     * with the stream.
  98.272 +     *
  98.273 +     * <p> The <code>close</code> method of <code>InputStream</code> does
  98.274 +     * nothing.
  98.275 +     *
  98.276 +     * @exception  IOException  if an I/O error occurs.
  98.277 +     */
  98.278 +    public void close() throws IOException {}
  98.279 +
  98.280 +    /**
  98.281 +     * Marks the current position in this input stream. A subsequent call to
  98.282 +     * the <code>reset</code> method repositions this stream at the last marked
  98.283 +     * position so that subsequent reads re-read the same bytes.
  98.284 +     *
  98.285 +     * <p> The <code>readlimit</code> arguments tells this input stream to
  98.286 +     * allow that many bytes to be read before the mark position gets
  98.287 +     * invalidated.
  98.288 +     *
  98.289 +     * <p> The general contract of <code>mark</code> is that, if the method
  98.290 +     * <code>markSupported</code> returns <code>true</code>, the stream somehow
  98.291 +     * remembers all the bytes read after the call to <code>mark</code> and
  98.292 +     * stands ready to supply those same bytes again if and whenever the method
  98.293 +     * <code>reset</code> is called.  However, the stream is not required to
  98.294 +     * remember any data at all if more than <code>readlimit</code> bytes are
  98.295 +     * read from the stream before <code>reset</code> is called.
  98.296 +     *
  98.297 +     * <p> Marking a closed stream should not have any effect on the stream.
  98.298 +     *
  98.299 +     * <p> The <code>mark</code> method of <code>InputStream</code> does
  98.300 +     * nothing.
  98.301 +     *
  98.302 +     * @param   readlimit   the maximum limit of bytes that can be read before
  98.303 +     *                      the mark position becomes invalid.
  98.304 +     * @see     java.io.InputStream#reset()
  98.305 +     */
  98.306 +    public synchronized void mark(int readlimit) {}
  98.307 +
  98.308 +    /**
  98.309 +     * Repositions this stream to the position at the time the
  98.310 +     * <code>mark</code> method was last called on this input stream.
  98.311 +     *
  98.312 +     * <p> The general contract of <code>reset</code> is:
  98.313 +     *
  98.314 +     * <p><ul>
  98.315 +     *
  98.316 +     * <li> If the method <code>markSupported</code> returns
  98.317 +     * <code>true</code>, then:
  98.318 +     *
  98.319 +     *     <ul><li> If the method <code>mark</code> has not been called since
  98.320 +     *     the stream was created, or the number of bytes read from the stream
  98.321 +     *     since <code>mark</code> was last called is larger than the argument
  98.322 +     *     to <code>mark</code> at that last call, then an
  98.323 +     *     <code>IOException</code> might be thrown.
  98.324 +     *
  98.325 +     *     <li> If such an <code>IOException</code> is not thrown, then the
  98.326 +     *     stream is reset to a state such that all the bytes read since the
  98.327 +     *     most recent call to <code>mark</code> (or since the start of the
  98.328 +     *     file, if <code>mark</code> has not been called) will be resupplied
  98.329 +     *     to subsequent callers of the <code>read</code> method, followed by
  98.330 +     *     any bytes that otherwise would have been the next input data as of
  98.331 +     *     the time of the call to <code>reset</code>. </ul>
  98.332 +     *
  98.333 +     * <li> If the method <code>markSupported</code> returns
  98.334 +     * <code>false</code>, then:
  98.335 +     *
  98.336 +     *     <ul><li> The call to <code>reset</code> may throw an
  98.337 +     *     <code>IOException</code>.
  98.338 +     *
  98.339 +     *     <li> If an <code>IOException</code> is not thrown, then the stream
  98.340 +     *     is reset to a fixed state that depends on the particular type of the
  98.341 +     *     input stream and how it was created. The bytes that will be supplied
  98.342 +     *     to subsequent callers of the <code>read</code> method depend on the
  98.343 +     *     particular type of the input stream. </ul></ul>
  98.344 +     *
  98.345 +     * <p>The method <code>reset</code> for class <code>InputStream</code>
  98.346 +     * does nothing except throw an <code>IOException</code>.
  98.347 +     *
  98.348 +     * @exception  IOException  if this stream has not been marked or if the
  98.349 +     *               mark has been invalidated.
  98.350 +     * @see     java.io.InputStream#mark(int)
  98.351 +     * @see     java.io.IOException
  98.352 +     */
  98.353 +    public synchronized void reset() throws IOException {
  98.354 +        throw new IOException("mark/reset not supported");
  98.355 +    }
  98.356 +
  98.357 +    /**
  98.358 +     * Tests if this input stream supports the <code>mark</code> and
  98.359 +     * <code>reset</code> methods. Whether or not <code>mark</code> and
  98.360 +     * <code>reset</code> are supported is an invariant property of a
  98.361 +     * particular input stream instance. The <code>markSupported</code> method
  98.362 +     * of <code>InputStream</code> returns <code>false</code>.
  98.363 +     *
  98.364 +     * @return  <code>true</code> if this stream instance supports the mark
  98.365 +     *          and reset methods; <code>false</code> otherwise.
  98.366 +     * @see     java.io.InputStream#mark(int)
  98.367 +     * @see     java.io.InputStream#reset()
  98.368 +     */
  98.369 +    public boolean markSupported() {
  98.370 +        return false;
  98.371 +    }
  98.372 +
  98.373 +}
    99.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    99.2 +++ b/emul/mini/src/main/java/java/io/PushbackInputStream.java	Sun Feb 03 07:48:42 2013 +0100
    99.3 @@ -0,0 +1,385 @@
    99.4 +/*
    99.5 + * Copyright (c) 1994, 2011, 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 +import org.apidesign.bck2brwsr.emul.lang.System;
   99.32 +
   99.33 +/**
   99.34 + * A <code>PushbackInputStream</code> adds
   99.35 + * functionality to another input stream, namely
   99.36 + * the  ability to "push back" or "unread"
   99.37 + * one byte. This is useful in situations where
   99.38 + * it is  convenient for a fragment of code
   99.39 + * to read an indefinite number of data bytes
   99.40 + * that  are delimited by a particular byte
   99.41 + * value; after reading the terminating byte,
   99.42 + * the  code fragment can "unread" it, so that
   99.43 + * the next read operation on the input stream
   99.44 + * will reread the byte that was pushed back.
   99.45 + * For example, bytes representing the  characters
   99.46 + * constituting an identifier might be terminated
   99.47 + * by a byte representing an  operator character;
   99.48 + * a method whose job is to read just an identifier
   99.49 + * can read until it  sees the operator and
   99.50 + * then push the operator back to be re-read.
   99.51 + *
   99.52 + * @author  David Connelly
   99.53 + * @author  Jonathan Payne
   99.54 + * @since   JDK1.0
   99.55 + */
   99.56 +public
   99.57 +class PushbackInputStream extends FilterInputStream {
   99.58 +    /**
   99.59 +     * The pushback buffer.
   99.60 +     * @since   JDK1.1
   99.61 +     */
   99.62 +    protected byte[] buf;
   99.63 +
   99.64 +    /**
   99.65 +     * The position within the pushback buffer from which the next byte will
   99.66 +     * be read.  When the buffer is empty, <code>pos</code> is equal to
   99.67 +     * <code>buf.length</code>; when the buffer is full, <code>pos</code> is
   99.68 +     * equal to zero.
   99.69 +     *
   99.70 +     * @since   JDK1.1
   99.71 +     */
   99.72 +    protected int pos;
   99.73 +
   99.74 +    /**
   99.75 +     * Check to make sure that this stream has not been closed
   99.76 +     */
   99.77 +    private void ensureOpen() throws IOException {
   99.78 +        if (in == null)
   99.79 +            throw new IOException("Stream closed");
   99.80 +    }
   99.81 +
   99.82 +    /**
   99.83 +     * Creates a <code>PushbackInputStream</code>
   99.84 +     * with a pushback buffer of the specified <code>size</code>,
   99.85 +     * and saves its  argument, the input stream
   99.86 +     * <code>in</code>, for later use. Initially,
   99.87 +     * there is no pushed-back byte  (the field
   99.88 +     * <code>pushBack</code> is initialized to
   99.89 +     * <code>-1</code>).
   99.90 +     *
   99.91 +     * @param  in    the input stream from which bytes will be read.
   99.92 +     * @param  size  the size of the pushback buffer.
   99.93 +     * @exception IllegalArgumentException if size is <= 0
   99.94 +     * @since  JDK1.1
   99.95 +     */
   99.96 +    public PushbackInputStream(InputStream in, int size) {
   99.97 +        super(in);
   99.98 +        if (size <= 0) {
   99.99 +            throw new IllegalArgumentException("size <= 0");
  99.100 +        }
  99.101 +        this.buf = new byte[size];
  99.102 +        this.pos = size;
  99.103 +    }
  99.104 +
  99.105 +    /**
  99.106 +     * Creates a <code>PushbackInputStream</code>
  99.107 +     * and saves its  argument, the input stream
  99.108 +     * <code>in</code>, for later use. Initially,
  99.109 +     * there is no pushed-back byte  (the field
  99.110 +     * <code>pushBack</code> is initialized to
  99.111 +     * <code>-1</code>).
  99.112 +     *
  99.113 +     * @param   in   the input stream from which bytes will be read.
  99.114 +     */
  99.115 +    public PushbackInputStream(InputStream in) {
  99.116 +        this(in, 1);
  99.117 +    }
  99.118 +
  99.119 +    /**
  99.120 +     * Reads the next byte of data from this input stream. The value
  99.121 +     * byte is returned as an <code>int</code> in the range
  99.122 +     * <code>0</code> to <code>255</code>. If no byte is available
  99.123 +     * because the end of the stream has been reached, the value
  99.124 +     * <code>-1</code> is returned. This method blocks until input data
  99.125 +     * is available, the end of the stream is detected, or an exception
  99.126 +     * is thrown.
  99.127 +     *
  99.128 +     * <p> This method returns the most recently pushed-back byte, if there is
  99.129 +     * one, and otherwise calls the <code>read</code> method of its underlying
  99.130 +     * input stream and returns whatever value that method returns.
  99.131 +     *
  99.132 +     * @return     the next byte of data, or <code>-1</code> if the end of the
  99.133 +     *             stream has been reached.
  99.134 +     * @exception  IOException  if this input stream has been closed by
  99.135 +     *             invoking its {@link #close()} method,
  99.136 +     *             or an I/O error occurs.
  99.137 +     * @see        java.io.InputStream#read()
  99.138 +     */
  99.139 +    public int read() throws IOException {
  99.140 +        ensureOpen();
  99.141 +        if (pos < buf.length) {
  99.142 +            return buf[pos++] & 0xff;
  99.143 +        }
  99.144 +        return super.read();
  99.145 +    }
  99.146 +
  99.147 +    /**
  99.148 +     * Reads up to <code>len</code> bytes of data from this input stream into
  99.149 +     * an array of bytes.  This method first reads any pushed-back bytes; after
  99.150 +     * that, if fewer than <code>len</code> bytes have been read then it
  99.151 +     * reads from the underlying input stream. If <code>len</code> is not zero, the method
  99.152 +     * blocks until at least 1 byte of input is available; otherwise, no
  99.153 +     * bytes are read and <code>0</code> is returned.
  99.154 +     *
  99.155 +     * @param      b     the buffer into which the data is read.
  99.156 +     * @param      off   the start offset in the destination array <code>b</code>
  99.157 +     * @param      len   the maximum number of bytes read.
  99.158 +     * @return     the total number of bytes read into the buffer, or
  99.159 +     *             <code>-1</code> if there is no more data because the end of
  99.160 +     *             the stream has been reached.
  99.161 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
  99.162 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
  99.163 +     * <code>len</code> is negative, or <code>len</code> is greater than
  99.164 +     * <code>b.length - off</code>
  99.165 +     * @exception  IOException  if this input stream has been closed by
  99.166 +     *             invoking its {@link #close()} method,
  99.167 +     *             or an I/O error occurs.
  99.168 +     * @see        java.io.InputStream#read(byte[], int, int)
  99.169 +     */
  99.170 +    public int read(byte[] b, int off, int len) throws IOException {
  99.171 +        ensureOpen();
  99.172 +        if (b == null) {
  99.173 +            throw new NullPointerException();
  99.174 +        } else if (off < 0 || len < 0 || len > b.length - off) {
  99.175 +            throw new IndexOutOfBoundsException();
  99.176 +        } else if (len == 0) {
  99.177 +            return 0;
  99.178 +        }
  99.179 +
  99.180 +        int avail = buf.length - pos;
  99.181 +        if (avail > 0) {
  99.182 +            if (len < avail) {
  99.183 +                avail = len;
  99.184 +            }
  99.185 +            System.arraycopy(buf, pos, b, off, avail);
  99.186 +            pos += avail;
  99.187 +            off += avail;
  99.188 +            len -= avail;
  99.189 +        }
  99.190 +        if (len > 0) {
  99.191 +            len = super.read(b, off, len);
  99.192 +            if (len == -1) {
  99.193 +                return avail == 0 ? -1 : avail;
  99.194 +            }
  99.195 +            return avail + len;
  99.196 +        }
  99.197 +        return avail;
  99.198 +    }
  99.199 +
  99.200 +    /**
  99.201 +     * Pushes back a byte by copying it to the front of the pushback buffer.
  99.202 +     * After this method returns, the next byte to be read will have the value
  99.203 +     * <code>(byte)b</code>.
  99.204 +     *
  99.205 +     * @param      b   the <code>int</code> value whose low-order
  99.206 +     *                  byte is to be pushed back.
  99.207 +     * @exception IOException If there is not enough room in the pushback
  99.208 +     *            buffer for the byte, or this input stream has been closed by
  99.209 +     *            invoking its {@link #close()} method.
  99.210 +     */
  99.211 +    public void unread(int b) throws IOException {
  99.212 +        ensureOpen();
  99.213 +        if (pos == 0) {
  99.214 +            throw new IOException("Push back buffer is full");
  99.215 +        }
  99.216 +        buf[--pos] = (byte)b;
  99.217 +    }
  99.218 +
  99.219 +    /**
  99.220 +     * Pushes back a portion of an array of bytes by copying it to the front
  99.221 +     * of the pushback buffer.  After this method returns, the next byte to be
  99.222 +     * read will have the value <code>b[off]</code>, the byte after that will
  99.223 +     * have the value <code>b[off+1]</code>, and so forth.
  99.224 +     *
  99.225 +     * @param b the byte array to push back.
  99.226 +     * @param off the start offset of the data.
  99.227 +     * @param len the number of bytes to push back.
  99.228 +     * @exception IOException If there is not enough room in the pushback
  99.229 +     *            buffer for the specified number of bytes,
  99.230 +     *            or this input stream has been closed by
  99.231 +     *            invoking its {@link #close()} method.
  99.232 +     * @since     JDK1.1
  99.233 +     */
  99.234 +    public void unread(byte[] b, int off, int len) throws IOException {
  99.235 +        ensureOpen();
  99.236 +        if (len > pos) {
  99.237 +            throw new IOException("Push back buffer is full");
  99.238 +        }
  99.239 +        pos -= len;
  99.240 +        System.arraycopy(b, off, buf, pos, len);
  99.241 +    }
  99.242 +
  99.243 +    /**
  99.244 +     * Pushes back an array of bytes by copying it to the front of the
  99.245 +     * pushback buffer.  After this method returns, the next byte to be read
  99.246 +     * will have the value <code>b[0]</code>, the byte after that will have the
  99.247 +     * value <code>b[1]</code>, and so forth.
  99.248 +     *
  99.249 +     * @param b the byte array to push back
  99.250 +     * @exception IOException If there is not enough room in the pushback
  99.251 +     *            buffer for the specified number of bytes,
  99.252 +     *            or this input stream has been closed by
  99.253 +     *            invoking its {@link #close()} method.
  99.254 +     * @since     JDK1.1
  99.255 +     */
  99.256 +    public void unread(byte[] b) throws IOException {
  99.257 +        unread(b, 0, b.length);
  99.258 +    }
  99.259 +
  99.260 +    /**
  99.261 +     * Returns an estimate of the number of bytes that can be read (or
  99.262 +     * skipped over) from this input stream without blocking by the next
  99.263 +     * invocation of a method for this input stream. The next invocation might be
  99.264 +     * the same thread or another thread.  A single read or skip of this
  99.265 +     * many bytes will not block, but may read or skip fewer bytes.
  99.266 +     *
  99.267 +     * <p> The method returns the sum of the number of bytes that have been
  99.268 +     * pushed back and the value returned by {@link
  99.269 +     * java.io.FilterInputStream#available available}.
  99.270 +     *
  99.271 +     * @return     the number of bytes that can be read (or skipped over) from
  99.272 +     *             the input stream without blocking.
  99.273 +     * @exception  IOException  if this input stream has been closed by
  99.274 +     *             invoking its {@link #close()} method,
  99.275 +     *             or an I/O error occurs.
  99.276 +     * @see        java.io.FilterInputStream#in
  99.277 +     * @see        java.io.InputStream#available()
  99.278 +     */
  99.279 +    public int available() throws IOException {
  99.280 +        ensureOpen();
  99.281 +        int n = buf.length - pos;
  99.282 +        int avail = super.available();
  99.283 +        return n > (Integer.MAX_VALUE - avail)
  99.284 +                    ? Integer.MAX_VALUE
  99.285 +                    : n + avail;
  99.286 +    }
  99.287 +
  99.288 +    /**
  99.289 +     * Skips over and discards <code>n</code> bytes of data from this
  99.290 +     * input stream. The <code>skip</code> method may, for a variety of
  99.291 +     * reasons, end up skipping over some smaller number of bytes,
  99.292 +     * possibly zero.  If <code>n</code> is negative, no bytes are skipped.
  99.293 +     *
  99.294 +     * <p> The <code>skip</code> method of <code>PushbackInputStream</code>
  99.295 +     * first skips over the bytes in the pushback buffer, if any.  It then
  99.296 +     * calls the <code>skip</code> method of the underlying input stream if
  99.297 +     * more bytes need to be skipped.  The actual number of bytes skipped
  99.298 +     * is returned.
  99.299 +     *
  99.300 +     * @param      n  {@inheritDoc}
  99.301 +     * @return     {@inheritDoc}
  99.302 +     * @exception  IOException  if the stream does not support seek,
  99.303 +     *            or the stream has been closed by
  99.304 +     *            invoking its {@link #close()} method,
  99.305 +     *            or an I/O error occurs.
  99.306 +     * @see        java.io.FilterInputStream#in
  99.307 +     * @see        java.io.InputStream#skip(long n)
  99.308 +     * @since      1.2
  99.309 +     */
  99.310 +    public long skip(long n) throws IOException {
  99.311 +        ensureOpen();
  99.312 +        if (n <= 0) {
  99.313 +            return 0;
  99.314 +        }
  99.315 +
  99.316 +        long pskip = buf.length - pos;
  99.317 +        if (pskip > 0) {
  99.318 +            if (n < pskip) {
  99.319 +                pskip = n;
  99.320 +            }
  99.321 +            pos += pskip;
  99.322 +            n -= pskip;
  99.323 +        }
  99.324 +        if (n > 0) {
  99.325 +            pskip += super.skip(n);
  99.326 +        }
  99.327 +        return pskip;
  99.328 +    }
  99.329 +
  99.330 +    /**
  99.331 +     * Tests if this input stream supports the <code>mark</code> and
  99.332 +     * <code>reset</code> methods, which it does not.
  99.333 +     *
  99.334 +     * @return   <code>false</code>, since this class does not support the
  99.335 +     *           <code>mark</code> and <code>reset</code> methods.
  99.336 +     * @see     java.io.InputStream#mark(int)
  99.337 +     * @see     java.io.InputStream#reset()
  99.338 +     */
  99.339 +    public boolean markSupported() {
  99.340 +        return false;
  99.341 +    }
  99.342 +
  99.343 +    /**
  99.344 +     * Marks the current position in this input stream.
  99.345 +     *
  99.346 +     * <p> The <code>mark</code> method of <code>PushbackInputStream</code>
  99.347 +     * does nothing.
  99.348 +     *
  99.349 +     * @param   readlimit   the maximum limit of bytes that can be read before
  99.350 +     *                      the mark position becomes invalid.
  99.351 +     * @see     java.io.InputStream#reset()
  99.352 +     */
  99.353 +    public synchronized void mark(int readlimit) {
  99.354 +    }
  99.355 +
  99.356 +    /**
  99.357 +     * Repositions this stream to the position at the time the
  99.358 +     * <code>mark</code> method was last called on this input stream.
  99.359 +     *
  99.360 +     * <p> The method <code>reset</code> for class
  99.361 +     * <code>PushbackInputStream</code> does nothing except throw an
  99.362 +     * <code>IOException</code>.
  99.363 +     *
  99.364 +     * @exception  IOException  if this method is invoked.
  99.365 +     * @see     java.io.InputStream#mark(int)
  99.366 +     * @see     java.io.IOException
  99.367 +     */
  99.368 +    public synchronized void reset() throws IOException {
  99.369 +        throw new IOException("mark/reset not supported");
  99.370 +    }
  99.371 +
  99.372 +    /**
  99.373 +     * Closes this input stream and releases any system resources
  99.374 +     * associated with the stream.
  99.375 +     * Once the stream has been closed, further read(), unread(),
  99.376 +     * available(), reset(), or skip() invocations will throw an IOException.
  99.377 +     * Closing a previously closed stream has no effect.
  99.378 +     *
  99.379 +     * @exception  IOException  if an I/O error occurs.
  99.380 +     */
  99.381 +    public synchronized void close() throws IOException {
  99.382 +        if (in == null)
  99.383 +            return;
  99.384 +        in.close();
  99.385 +        in = null;
  99.386 +        buf = null;
  99.387 +    }
  99.388 +}
   100.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   100.2 +++ b/emul/mini/src/main/java/java/io/Serializable.java	Sun Feb 03 07:48:42 2013 +0100
   100.3 @@ -0,0 +1,170 @@
   100.4 +/*
   100.5 + * Copyright (c) 1996, 2005, 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 +/**
  100.32 + * Serializability of a class is enabled by the class implementing the
  100.33 + * java.io.Serializable interface. Classes that do not implement this
  100.34 + * interface will not have any of their state serialized or
  100.35 + * deserialized.  All subtypes of a serializable class are themselves
  100.36 + * serializable.  The serialization interface has no methods or fields
  100.37 + * and serves only to identify the semantics of being serializable. <p>
  100.38 + *
  100.39 + * To allow subtypes of non-serializable classes to be serialized, the
  100.40 + * subtype may assume responsibility for saving and restoring the
  100.41 + * state of the supertype's public, protected, and (if accessible)
  100.42 + * package fields.  The subtype may assume this responsibility only if
  100.43 + * the class it extends has an accessible no-arg constructor to
  100.44 + * initialize the class's state.  It is an error to declare a class
  100.45 + * Serializable if this is not the case.  The error will be detected at
  100.46 + * runtime. <p>
  100.47 + *
  100.48 + * During deserialization, the fields of non-serializable classes will
  100.49 + * be initialized using the public or protected no-arg constructor of
  100.50 + * the class.  A no-arg constructor must be accessible to the subclass
  100.51 + * that is serializable.  The fields of serializable subclasses will
  100.52 + * be restored from the stream. <p>
  100.53 + *
  100.54 + * When traversing a graph, an object may be encountered that does not
  100.55 + * support the Serializable interface. In this case the
  100.56 + * NotSerializableException will be thrown and will identify the class
  100.57 + * of the non-serializable object. <p>
  100.58 + *
  100.59 + * Classes that require special handling during the serialization and
  100.60 + * deserialization process must implement special methods with these exact
  100.61 + * signatures: <p>
  100.62 + *
  100.63 + * <PRE>
  100.64 + * private void writeObject(java.io.ObjectOutputStream out)
  100.65 + *     throws IOException
  100.66 + * private void readObject(java.io.ObjectInputStream in)
  100.67 + *     throws IOException, ClassNotFoundException;
  100.68 + * private void readObjectNoData()
  100.69 + *     throws ObjectStreamException;
  100.70 + * </PRE>
  100.71 + *
  100.72 + * <p>The writeObject method is responsible for writing the state of the
  100.73 + * object for its particular class so that the corresponding
  100.74 + * readObject method can restore it.  The default mechanism for saving
  100.75 + * the Object's fields can be invoked by calling
  100.76 + * out.defaultWriteObject. The method does not need to concern
  100.77 + * itself with the state belonging to its superclasses or subclasses.
  100.78 + * State is saved by writing the individual fields to the
  100.79 + * ObjectOutputStream using the writeObject method or by using the
  100.80 + * methods for primitive data types supported by DataOutput.
  100.81 + *
  100.82 + * <p>The readObject method is responsible for reading from the stream and
  100.83 + * restoring the classes fields. It may call in.defaultReadObject to invoke
  100.84 + * the default mechanism for restoring the object's non-static and
  100.85 + * non-transient fields.  The defaultReadObject method uses information in
  100.86 + * the stream to assign the fields of the object saved in the stream with the
  100.87 + * correspondingly named fields in the current object.  This handles the case
  100.88 + * when the class has evolved to add new fields. The method does not need to
  100.89 + * concern itself with the state belonging to its superclasses or subclasses.
  100.90 + * State is saved by writing the individual fields to the
  100.91 + * ObjectOutputStream using the writeObject method or by using the
  100.92 + * methods for primitive data types supported by DataOutput.
  100.93 + *
  100.94 + * <p>The readObjectNoData method is responsible for initializing the state of
  100.95 + * the object for its particular class in the event that the serialization
  100.96 + * stream does not list the given class as a superclass of the object being
  100.97 + * deserialized.  This may occur in cases where the receiving party uses a
  100.98 + * different version of the deserialized instance's class than the sending
  100.99 + * party, and the receiver's version extends classes that are not extended by
 100.100 + * the sender's version.  This may also occur if the serialization stream has
 100.101 + * been tampered; hence, readObjectNoData is useful for initializing
 100.102 + * deserialized objects properly despite a "hostile" or incomplete source
 100.103 + * stream.
 100.104 + *
 100.105 + * <p>Serializable classes that need to designate an alternative object to be
 100.106 + * used when writing an object to the stream should implement this
 100.107 + * special method with the exact signature: <p>
 100.108 + *
 100.109 + * <PRE>
 100.110 + * ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
 100.111 + * </PRE><p>
 100.112 + *
 100.113 + * This writeReplace method is invoked by serialization if the method
 100.114 + * exists and it would be accessible from a method defined within the
 100.115 + * class of the object being serialized. Thus, the method can have private,
 100.116 + * protected and package-private access. Subclass access to this method
 100.117 + * follows java accessibility rules. <p>
 100.118 + *
 100.119 + * Classes that need to designate a replacement when an instance of it
 100.120 + * is read from the stream should implement this special method with the
 100.121 + * exact signature.<p>
 100.122 + *
 100.123 + * <PRE>
 100.124 + * ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
 100.125 + * </PRE><p>
 100.126 + *
 100.127 + * This readResolve method follows the same invocation rules and
 100.128 + * accessibility rules as writeReplace.<p>
 100.129 + *
 100.130 + * The serialization runtime associates with each serializable class a version
 100.131 + * number, called a serialVersionUID, which is used during deserialization to
 100.132 + * verify that the sender and receiver of a serialized object have loaded
 100.133 + * classes for that object that are compatible with respect to serialization.
 100.134 + * If the receiver has loaded a class for the object that has a different
 100.135 + * serialVersionUID than that of the corresponding sender's class, then
 100.136 + * deserialization will result in an {@link InvalidClassException}.  A
 100.137 + * serializable class can declare its own serialVersionUID explicitly by
 100.138 + * declaring a field named <code>"serialVersionUID"</code> that must be static,
 100.139 + * final, and of type <code>long</code>:<p>
 100.140 + *
 100.141 + * <PRE>
 100.142 + * ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
 100.143 + * </PRE>
 100.144 + *
 100.145 + * If a serializable class does not explicitly declare a serialVersionUID, then
 100.146 + * the serialization runtime will calculate a default serialVersionUID value
 100.147 + * for that class based on various aspects of the class, as described in the
 100.148 + * Java(TM) Object Serialization Specification.  However, it is <em>strongly
 100.149 + * recommended</em> that all serializable classes explicitly declare
 100.150 + * serialVersionUID values, since the default serialVersionUID computation is
 100.151 + * highly sensitive to class details that may vary depending on compiler
 100.152 + * implementations, and can thus result in unexpected
 100.153 + * <code>InvalidClassException</code>s during deserialization.  Therefore, to
 100.154 + * guarantee a consistent serialVersionUID value across different java compiler
 100.155 + * implementations, a serializable class must declare an explicit
 100.156 + * serialVersionUID value.  It is also strongly advised that explicit
 100.157 + * serialVersionUID declarations use the <code>private</code> modifier where
 100.158 + * possible, since such declarations apply only to the immediately declaring
 100.159 + * class--serialVersionUID fields are not useful as inherited members. Array
 100.160 + * classes cannot declare an explicit serialVersionUID, so they always have
 100.161 + * the default computed value, but the requirement for matching
 100.162 + * serialVersionUID values is waived for array classes.
 100.163 + *
 100.164 + * @author  unascribed
 100.165 + * @see java.io.ObjectOutputStream
 100.166 + * @see java.io.ObjectInputStream
 100.167 + * @see java.io.ObjectOutput
 100.168 + * @see java.io.ObjectInput
 100.169 + * @see java.io.Externalizable
 100.170 + * @since   JDK1.1
 100.171 + */
 100.172 +public interface Serializable {
 100.173 +}
   101.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   101.2 +++ b/emul/mini/src/main/java/java/io/UTFDataFormatException.java	Sun Feb 03 07:48:42 2013 +0100
   101.3 @@ -0,0 +1,69 @@
   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 a malformed string in
  101.33 + * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
  101.34 + * format has been read in a data
  101.35 + * input stream or by any class that implements the data input
  101.36 + * interface.
  101.37 + * See the
  101.38 + * <a href="DataInput.html#modified-utf-8"><code>DataInput</code></a>
  101.39 + * class description for the format in
  101.40 + * which modified UTF-8 strings are read and written.
  101.41 + *
  101.42 + * @author  Frank Yellin
  101.43 + * @see     java.io.DataInput
  101.44 + * @see     java.io.DataInputStream#readUTF(java.io.DataInput)
  101.45 + * @see     java.io.IOException
  101.46 + * @since   JDK1.0
  101.47 + */
  101.48 +public
  101.49 +class UTFDataFormatException extends IOException {
  101.50 +    private static final long serialVersionUID = 420743449228280612L;
  101.51 +
  101.52 +    /**
  101.53 +     * Constructs a <code>UTFDataFormatException</code> with
  101.54 +     * <code>null</code> as its error detail message.
  101.55 +     */
  101.56 +    public UTFDataFormatException() {
  101.57 +        super();
  101.58 +    }
  101.59 +
  101.60 +    /**
  101.61 +     * Constructs a <code>UTFDataFormatException</code> with the
  101.62 +     * specified detail message. The string <code>s</code> can be
  101.63 +     * retrieved later by the
  101.64 +     * <code>{@link java.lang.Throwable#getMessage}</code>
  101.65 +     * method of class <code>java.lang.Throwable</code>.
  101.66 +     *
  101.67 +     * @param   s   the detail message.
  101.68 +     */
  101.69 +    public UTFDataFormatException(String s) {
  101.70 +        super(s);
  101.71 +    }
  101.72 +}
   102.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   102.2 +++ b/emul/mini/src/main/java/java/io/UnsupportedEncodingException.java	Sun Feb 03 07:48:42 2013 +0100
   102.3 @@ -0,0 +1,52 @@
   102.4 +/*
   102.5 + * Copyright (c) 1996, 2008, 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 +package java.io;
  102.29 +
  102.30 +/**
  102.31 + * The Character Encoding is not supported.
  102.32 + *
  102.33 + * @author  Asmus Freytag
  102.34 + * @since   JDK1.1
  102.35 + */
  102.36 +public class UnsupportedEncodingException
  102.37 +    extends IOException
  102.38 +{
  102.39 +    private static final long serialVersionUID = -4274276298326136670L;
  102.40 +
  102.41 +    /**
  102.42 +     * Constructs an UnsupportedEncodingException without a detail message.
  102.43 +     */
  102.44 +    public UnsupportedEncodingException() {
  102.45 +        super();
  102.46 +    }
  102.47 +
  102.48 +    /**
  102.49 +     * Constructs an UnsupportedEncodingException with a detail message.
  102.50 +     * @param s Describes the reason for the exception.
  102.51 +     */
  102.52 +    public UnsupportedEncodingException(String s) {
  102.53 +        super(s);
  102.54 +    }
  102.55 +}
   103.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   103.2 +++ b/emul/mini/src/main/java/java/lang/AbstractStringBuilder.java	Sun Feb 03 07:48:42 2013 +0100
   103.3 @@ -0,0 +1,1414 @@
   103.4 +/*
   103.5 + * Copyright (c) 2003, 2010, 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.lang;
  103.30 +
  103.31 +import org.apidesign.bck2brwsr.emul.lang.System;
  103.32 +
  103.33 +/**
  103.34 + * A mutable sequence of characters.
  103.35 + * <p>
  103.36 + * Implements a modifiable string. At any point in time it contains some
  103.37 + * particular sequence of characters, but the length and content of the
  103.38 + * sequence can be changed through certain method calls.
  103.39 + *
  103.40 + * @author      Michael McCloskey
  103.41 + * @author      Martin Buchholz
  103.42 + * @author      Ulf Zibis
  103.43 + * @since       1.5
  103.44 + */
  103.45 +abstract class AbstractStringBuilder implements Appendable, CharSequence {
  103.46 +    /**
  103.47 +     * The value is used for character storage.
  103.48 +     */
  103.49 +    char[] value;
  103.50 +
  103.51 +    /**
  103.52 +     * The count is the number of characters used.
  103.53 +     */
  103.54 +    int count;
  103.55 +
  103.56 +    /**
  103.57 +     * This no-arg constructor is necessary for serialization of subclasses.
  103.58 +     */
  103.59 +    AbstractStringBuilder() {
  103.60 +    }
  103.61 +
  103.62 +    /**
  103.63 +     * Creates an AbstractStringBuilder of the specified capacity.
  103.64 +     */
  103.65 +    AbstractStringBuilder(int capacity) {
  103.66 +        value = new char[capacity];
  103.67 +    }
  103.68 +
  103.69 +    /**
  103.70 +     * Returns the length (character count).
  103.71 +     *
  103.72 +     * @return  the length of the sequence of characters currently
  103.73 +     *          represented by this object
  103.74 +     */
  103.75 +    public int length() {
  103.76 +        return count;
  103.77 +    }
  103.78 +
  103.79 +    /**
  103.80 +     * Returns the current capacity. The capacity is the amount of storage
  103.81 +     * available for newly inserted characters, beyond which an allocation
  103.82 +     * will occur.
  103.83 +     *
  103.84 +     * @return  the current capacity
  103.85 +     */
  103.86 +    public int capacity() {
  103.87 +        return value.length;
  103.88 +    }
  103.89 +
  103.90 +    /**
  103.91 +     * Ensures that the capacity is at least equal to the specified minimum.
  103.92 +     * If the current capacity is less than the argument, then a new internal
  103.93 +     * array is allocated with greater capacity. The new capacity is the
  103.94 +     * larger of:
  103.95 +     * <ul>
  103.96 +     * <li>The <code>minimumCapacity</code> argument.
  103.97 +     * <li>Twice the old capacity, plus <code>2</code>.
  103.98 +     * </ul>
  103.99 +     * If the <code>minimumCapacity</code> argument is nonpositive, this
 103.100 +     * method takes no action and simply returns.
 103.101 +     *
 103.102 +     * @param   minimumCapacity   the minimum desired capacity.
 103.103 +     */
 103.104 +    public void ensureCapacity(int minimumCapacity) {
 103.105 +        if (minimumCapacity > 0)
 103.106 +            ensureCapacityInternal(minimumCapacity);
 103.107 +    }
 103.108 +
 103.109 +    /**
 103.110 +     * This method has the same contract as ensureCapacity, but is
 103.111 +     * never synchronized.
 103.112 +     */
 103.113 +    private void ensureCapacityInternal(int minimumCapacity) {
 103.114 +        // overflow-conscious code
 103.115 +        if (minimumCapacity - value.length > 0)
 103.116 +            expandCapacity(minimumCapacity);
 103.117 +    }
 103.118 +
 103.119 +    /**
 103.120 +     * This implements the expansion semantics of ensureCapacity with no
 103.121 +     * size check or synchronization.
 103.122 +     */
 103.123 +    void expandCapacity(int minimumCapacity) {
 103.124 +        int newCapacity = value.length * 2 + 2;
 103.125 +        if (newCapacity - minimumCapacity < 0)
 103.126 +            newCapacity = minimumCapacity;
 103.127 +        if (newCapacity < 0) {
 103.128 +            if (minimumCapacity < 0) // overflow
 103.129 +                throw new OutOfMemoryError();
 103.130 +            newCapacity = Integer.MAX_VALUE;
 103.131 +        }
 103.132 +        value = copyOf(value, newCapacity);
 103.133 +    }
 103.134 +
 103.135 +    /**
 103.136 +     * Attempts to reduce storage used for the character sequence.
 103.137 +     * If the buffer is larger than necessary to hold its current sequence of
 103.138 +     * characters, then it may be resized to become more space efficient.
 103.139 +     * Calling this method may, but is not required to, affect the value
 103.140 +     * returned by a subsequent call to the {@link #capacity()} method.
 103.141 +     */
 103.142 +    public void trimToSize() {
 103.143 +        if (count < value.length) {
 103.144 +            value = copyOf(value, count);
 103.145 +        }
 103.146 +    }
 103.147 +
 103.148 +    /**
 103.149 +     * Sets the length of the character sequence.
 103.150 +     * The sequence is changed to a new character sequence
 103.151 +     * whose length is specified by the argument. For every nonnegative
 103.152 +     * index <i>k</i> less than <code>newLength</code>, the character at
 103.153 +     * index <i>k</i> in the new character sequence is the same as the
 103.154 +     * character at index <i>k</i> in the old sequence if <i>k</i> is less
 103.155 +     * than the length of the old character sequence; otherwise, it is the
 103.156 +     * null character <code>'&#92;u0000'</code>.
 103.157 +     *
 103.158 +     * In other words, if the <code>newLength</code> argument is less than
 103.159 +     * the current length, the length is changed to the specified length.
 103.160 +     * <p>
 103.161 +     * If the <code>newLength</code> argument is greater than or equal
 103.162 +     * to the current length, sufficient null characters
 103.163 +     * (<code>'&#92;u0000'</code>) are appended so that
 103.164 +     * length becomes the <code>newLength</code> argument.
 103.165 +     * <p>
 103.166 +     * The <code>newLength</code> argument must be greater than or equal
 103.167 +     * to <code>0</code>.
 103.168 +     *
 103.169 +     * @param      newLength   the new length
 103.170 +     * @throws     IndexOutOfBoundsException  if the
 103.171 +     *               <code>newLength</code> argument is negative.
 103.172 +     */
 103.173 +    public void setLength(int newLength) {
 103.174 +        if (newLength < 0)
 103.175 +            throw new StringIndexOutOfBoundsException(newLength);
 103.176 +        ensureCapacityInternal(newLength);
 103.177 +
 103.178 +        if (count < newLength) {
 103.179 +            for (; count < newLength; count++)
 103.180 +                value[count] = '\0';
 103.181 +        } else {
 103.182 +            count = newLength;
 103.183 +        }
 103.184 +    }
 103.185 +
 103.186 +    /**
 103.187 +     * Returns the <code>char</code> value in this sequence at the specified index.
 103.188 +     * The first <code>char</code> value is at index <code>0</code>, the next at index
 103.189 +     * <code>1</code>, and so on, as in array indexing.
 103.190 +     * <p>
 103.191 +     * The index argument must be greater than or equal to
 103.192 +     * <code>0</code>, and less than the length of this sequence.
 103.193 +     *
 103.194 +     * <p>If the <code>char</code> value specified by the index is a
 103.195 +     * <a href="Character.html#unicode">surrogate</a>, the surrogate
 103.196 +     * value is returned.
 103.197 +     *
 103.198 +     * @param      index   the index of the desired <code>char</code> value.
 103.199 +     * @return     the <code>char</code> value at the specified index.
 103.200 +     * @throws     IndexOutOfBoundsException  if <code>index</code> is
 103.201 +     *             negative or greater than or equal to <code>length()</code>.
 103.202 +     */
 103.203 +    public char charAt(int index) {
 103.204 +        if ((index < 0) || (index >= count))
 103.205 +            throw new StringIndexOutOfBoundsException(index);
 103.206 +        return value[index];
 103.207 +    }
 103.208 +
 103.209 +    /**
 103.210 +     * Returns the character (Unicode code point) at the specified
 103.211 +     * index. The index refers to <code>char</code> values
 103.212 +     * (Unicode code units) and ranges from <code>0</code> to
 103.213 +     * {@link #length()}<code> - 1</code>.
 103.214 +     *
 103.215 +     * <p> If the <code>char</code> value specified at the given index
 103.216 +     * is in the high-surrogate range, the following index is less
 103.217 +     * than the length of this sequence, and the
 103.218 +     * <code>char</code> value at the following index is in the
 103.219 +     * low-surrogate range, then the supplementary code point
 103.220 +     * corresponding to this surrogate pair is returned. Otherwise,
 103.221 +     * the <code>char</code> value at the given index is returned.
 103.222 +     *
 103.223 +     * @param      index the index to the <code>char</code> values
 103.224 +     * @return     the code point value of the character at the
 103.225 +     *             <code>index</code>
 103.226 +     * @exception  IndexOutOfBoundsException  if the <code>index</code>
 103.227 +     *             argument is negative or not less than the length of this
 103.228 +     *             sequence.
 103.229 +     */
 103.230 +    public int codePointAt(int index) {
 103.231 +        if ((index < 0) || (index >= count)) {
 103.232 +            throw new StringIndexOutOfBoundsException(index);
 103.233 +        }
 103.234 +        return Character.codePointAt(value, index);
 103.235 +    }
 103.236 +
 103.237 +    /**
 103.238 +     * Returns the character (Unicode code point) before the specified
 103.239 +     * index. The index refers to <code>char</code> values
 103.240 +     * (Unicode code units) and ranges from <code>1</code> to {@link
 103.241 +     * #length()}.
 103.242 +     *
 103.243 +     * <p> If the <code>char</code> value at <code>(index - 1)</code>
 103.244 +     * is in the low-surrogate range, <code>(index - 2)</code> is not
 103.245 +     * negative, and the <code>char</code> value at <code>(index -
 103.246 +     * 2)</code> is in the high-surrogate range, then the
 103.247 +     * supplementary code point value of the surrogate pair is
 103.248 +     * returned. If the <code>char</code> value at <code>index -
 103.249 +     * 1</code> is an unpaired low-surrogate or a high-surrogate, the
 103.250 +     * surrogate value is returned.
 103.251 +     *
 103.252 +     * @param     index the index following the code point that should be returned
 103.253 +     * @return    the Unicode code point value before the given index.
 103.254 +     * @exception IndexOutOfBoundsException if the <code>index</code>
 103.255 +     *            argument is less than 1 or greater than the length
 103.256 +     *            of this sequence.
 103.257 +     */
 103.258 +    public int codePointBefore(int index) {
 103.259 +        int i = index - 1;
 103.260 +        if ((i < 0) || (i >= count)) {
 103.261 +            throw new StringIndexOutOfBoundsException(index);
 103.262 +        }
 103.263 +        return Character.codePointBefore(value, index);
 103.264 +    }
 103.265 +
 103.266 +    /**
 103.267 +     * Returns the number of Unicode code points in the specified text
 103.268 +     * range of this sequence. The text range begins at the specified
 103.269 +     * <code>beginIndex</code> and extends to the <code>char</code> at
 103.270 +     * index <code>endIndex - 1</code>. Thus the length (in
 103.271 +     * <code>char</code>s) of the text range is
 103.272 +     * <code>endIndex-beginIndex</code>. Unpaired surrogates within
 103.273 +     * this sequence count as one code point each.
 103.274 +     *
 103.275 +     * @param beginIndex the index to the first <code>char</code> of
 103.276 +     * the text range.
 103.277 +     * @param endIndex the index after the last <code>char</code> of
 103.278 +     * the text range.
 103.279 +     * @return the number of Unicode code points in the specified text
 103.280 +     * range
 103.281 +     * @exception IndexOutOfBoundsException if the
 103.282 +     * <code>beginIndex</code> is negative, or <code>endIndex</code>
 103.283 +     * is larger than the length of this sequence, or
 103.284 +     * <code>beginIndex</code> is larger than <code>endIndex</code>.
 103.285 +     */
 103.286 +    public int codePointCount(int beginIndex, int endIndex) {
 103.287 +        if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
 103.288 +            throw new IndexOutOfBoundsException();
 103.289 +        }
 103.290 +        return Character.codePointCountImpl(value, beginIndex, endIndex-beginIndex);
 103.291 +    }
 103.292 +
 103.293 +    /**
 103.294 +     * Returns the index within this sequence that is offset from the
 103.295 +     * given <code>index</code> by <code>codePointOffset</code> code
 103.296 +     * points. Unpaired surrogates within the text range given by
 103.297 +     * <code>index</code> and <code>codePointOffset</code> count as
 103.298 +     * one code point each.
 103.299 +     *
 103.300 +     * @param index the index to be offset
 103.301 +     * @param codePointOffset the offset in code points
 103.302 +     * @return the index within this sequence
 103.303 +     * @exception IndexOutOfBoundsException if <code>index</code>
 103.304 +     *   is negative or larger then the length of this sequence,
 103.305 +     *   or if <code>codePointOffset</code> is positive and the subsequence
 103.306 +     *   starting with <code>index</code> has fewer than
 103.307 +     *   <code>codePointOffset</code> code points,
 103.308 +     *   or if <code>codePointOffset</code> is negative and the subsequence
 103.309 +     *   before <code>index</code> has fewer than the absolute value of
 103.310 +     *   <code>codePointOffset</code> code points.
 103.311 +     */
 103.312 +    public int offsetByCodePoints(int index, int codePointOffset) {
 103.313 +        if (index < 0 || index > count) {
 103.314 +            throw new IndexOutOfBoundsException();
 103.315 +        }
 103.316 +        return Character.offsetByCodePointsImpl(value, 0, count,
 103.317 +                                                index, codePointOffset);
 103.318 +    }
 103.319 +
 103.320 +    /**
 103.321 +     * Characters are copied from this sequence into the
 103.322 +     * destination character array <code>dst</code>. The first character to
 103.323 +     * be copied is at index <code>srcBegin</code>; the last character to
 103.324 +     * be copied is at index <code>srcEnd-1</code>. The total number of
 103.325 +     * characters to be copied is <code>srcEnd-srcBegin</code>. The
 103.326 +     * characters are copied into the subarray of <code>dst</code> starting
 103.327 +     * at index <code>dstBegin</code> and ending at index:
 103.328 +     * <p><blockquote><pre>
 103.329 +     * dstbegin + (srcEnd-srcBegin) - 1
 103.330 +     * </pre></blockquote>
 103.331 +     *
 103.332 +     * @param      srcBegin   start copying at this offset.
 103.333 +     * @param      srcEnd     stop copying at this offset.
 103.334 +     * @param      dst        the array to copy the data into.
 103.335 +     * @param      dstBegin   offset into <code>dst</code>.
 103.336 +     * @throws     NullPointerException if <code>dst</code> is
 103.337 +     *             <code>null</code>.
 103.338 +     * @throws     IndexOutOfBoundsException  if any of the following is true:
 103.339 +     *             <ul>
 103.340 +     *             <li><code>srcBegin</code> is negative
 103.341 +     *             <li><code>dstBegin</code> is negative
 103.342 +     *             <li>the <code>srcBegin</code> argument is greater than
 103.343 +     *             the <code>srcEnd</code> argument.
 103.344 +     *             <li><code>srcEnd</code> is greater than
 103.345 +     *             <code>this.length()</code>.
 103.346 +     *             <li><code>dstBegin+srcEnd-srcBegin</code> is greater than
 103.347 +     *             <code>dst.length</code>
 103.348 +     *             </ul>
 103.349 +     */
 103.350 +    public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
 103.351 +    {
 103.352 +        if (srcBegin < 0)
 103.353 +            throw new StringIndexOutOfBoundsException(srcBegin);
 103.354 +        if ((srcEnd < 0) || (srcEnd > count))
 103.355 +            throw new StringIndexOutOfBoundsException(srcEnd);
 103.356 +        if (srcBegin > srcEnd)
 103.357 +            throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
 103.358 +        System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
 103.359 +    }
 103.360 +
 103.361 +    /**
 103.362 +     * The character at the specified index is set to <code>ch</code>. This
 103.363 +     * sequence is altered to represent a new character sequence that is
 103.364 +     * identical to the old character sequence, except that it contains the
 103.365 +     * character <code>ch</code> at position <code>index</code>.
 103.366 +     * <p>
 103.367 +     * The index argument must be greater than or equal to
 103.368 +     * <code>0</code>, and less than the length of this sequence.
 103.369 +     *
 103.370 +     * @param      index   the index of the character to modify.
 103.371 +     * @param      ch      the new character.
 103.372 +     * @throws     IndexOutOfBoundsException  if <code>index</code> is
 103.373 +     *             negative or greater than or equal to <code>length()</code>.
 103.374 +     */
 103.375 +    public void setCharAt(int index, char ch) {
 103.376 +        if ((index < 0) || (index >= count))
 103.377 +            throw new StringIndexOutOfBoundsException(index);
 103.378 +        value[index] = ch;
 103.379 +    }
 103.380 +
 103.381 +    /**
 103.382 +     * Appends the string representation of the {@code Object} argument.
 103.383 +     * <p>
 103.384 +     * The overall effect is exactly as if the argument were converted
 103.385 +     * to a string by the method {@link String#valueOf(Object)},
 103.386 +     * and the characters of that string were then
 103.387 +     * {@link #append(String) appended} to this character sequence.
 103.388 +     *
 103.389 +     * @param   obj   an {@code Object}.
 103.390 +     * @return  a reference to this object.
 103.391 +     */
 103.392 +    public AbstractStringBuilder append(Object obj) {
 103.393 +        return append(String.valueOf(obj));
 103.394 +    }
 103.395 +
 103.396 +    /**
 103.397 +     * Appends the specified string to this character sequence.
 103.398 +     * <p>
 103.399 +     * The characters of the {@code String} argument are appended, in
 103.400 +     * order, increasing the length of this sequence by the length of the
 103.401 +     * argument. If {@code str} is {@code null}, then the four
 103.402 +     * characters {@code "null"} are appended.
 103.403 +     * <p>
 103.404 +     * Let <i>n</i> be the length of this character sequence just prior to
 103.405 +     * execution of the {@code append} method. Then the character at
 103.406 +     * index <i>k</i> in the new character sequence is equal to the character
 103.407 +     * at index <i>k</i> in the old character sequence, if <i>k</i> is less
 103.408 +     * than <i>n</i>; otherwise, it is equal to the character at index
 103.409 +     * <i>k-n</i> in the argument {@code str}.
 103.410 +     *
 103.411 +     * @param   str   a string.
 103.412 +     * @return  a reference to this object.
 103.413 +     */
 103.414 +    public AbstractStringBuilder append(String str) {
 103.415 +        if (str == null) str = "null";
 103.416 +        int len = str.length();
 103.417 +        ensureCapacityInternal(count + len);
 103.418 +        str.getChars(0, len, value, count);
 103.419 +        count += len;
 103.420 +        return this;
 103.421 +    }
 103.422 +
 103.423 +    // Documentation in subclasses because of synchro difference
 103.424 +    public AbstractStringBuilder append(StringBuffer sb) {
 103.425 +        if (sb == null)
 103.426 +            return append("null");
 103.427 +        int len = sb.length();
 103.428 +        ensureCapacityInternal(count + len);
 103.429 +        sb.getChars(0, len, value, count);
 103.430 +        count += len;
 103.431 +        return this;
 103.432 +    }
 103.433 +
 103.434 +    // Documentation in subclasses because of synchro difference
 103.435 +    public AbstractStringBuilder append(CharSequence s) {
 103.436 +        if (s == null)
 103.437 +            s = "null";
 103.438 +        if (s instanceof String)
 103.439 +            return this.append((String)s);
 103.440 +        if (s instanceof StringBuffer)
 103.441 +            return this.append((StringBuffer)s);
 103.442 +        return this.append(s, 0, s.length());
 103.443 +    }
 103.444 +
 103.445 +    /**
 103.446 +     * Appends a subsequence of the specified {@code CharSequence} to this
 103.447 +     * sequence.
 103.448 +     * <p>
 103.449 +     * Characters of the argument {@code s}, starting at
 103.450 +     * index {@code start}, are appended, in order, to the contents of
 103.451 +     * this sequence up to the (exclusive) index {@code end}. The length
 103.452 +     * of this sequence is increased by the value of {@code end - start}.
 103.453 +     * <p>
 103.454 +     * Let <i>n</i> be the length of this character sequence just prior to
 103.455 +     * execution of the {@code append} method. Then the character at
 103.456 +     * index <i>k</i> in this character sequence becomes equal to the
 103.457 +     * character at index <i>k</i> in this sequence, if <i>k</i> is less than
 103.458 +     * <i>n</i>; otherwise, it is equal to the character at index
 103.459 +     * <i>k+start-n</i> in the argument {@code s}.
 103.460 +     * <p>
 103.461 +     * If {@code s} is {@code null}, then this method appends
 103.462 +     * characters as if the s parameter was a sequence containing the four
 103.463 +     * characters {@code "null"}.
 103.464 +     *
 103.465 +     * @param   s the sequence to append.
 103.466 +     * @param   start   the starting index of the subsequence to be appended.
 103.467 +     * @param   end     the end index of the subsequence to be appended.
 103.468 +     * @return  a reference to this object.
 103.469 +     * @throws     IndexOutOfBoundsException if
 103.470 +     *             {@code start} is negative, or
 103.471 +     *             {@code start} is greater than {@code end} or
 103.472 +     *             {@code end} is greater than {@code s.length()}
 103.473 +     */
 103.474 +    public AbstractStringBuilder append(CharSequence s, int start, int end) {
 103.475 +        if (s == null)
 103.476 +            s = "null";
 103.477 +        if ((start < 0) || (start > end) || (end > s.length()))
 103.478 +            throw new IndexOutOfBoundsException(
 103.479 +                "start " + start + ", end " + end + ", s.length() "
 103.480 +                + s.length());
 103.481 +        int len = end - start;
 103.482 +        ensureCapacityInternal(count + len);
 103.483 +        for (int i = start, j = count; i < end; i++, j++)
 103.484 +            value[j] = s.charAt(i);
 103.485 +        count += len;
 103.486 +        return this;
 103.487 +    }
 103.488 +
 103.489 +    /**
 103.490 +     * Appends the string representation of the {@code char} array
 103.491 +     * argument to this sequence.
 103.492 +     * <p>
 103.493 +     * The characters of the array argument are appended, in order, to
 103.494 +     * the contents of this sequence. The length of this sequence
 103.495 +     * increases by the length of the argument.
 103.496 +     * <p>
 103.497 +     * The overall effect is exactly as if the argument were converted
 103.498 +     * to a string by the method {@link String#valueOf(char[])},
 103.499 +     * and the characters of that string were then
 103.500 +     * {@link #append(String) appended} to this character sequence.
 103.501 +     *
 103.502 +     * @param   str   the characters to be appended.
 103.503 +     * @return  a reference to this object.
 103.504 +     */
 103.505 +    public AbstractStringBuilder append(char[] str) {
 103.506 +        int len = str.length;
 103.507 +        ensureCapacityInternal(count + len);
 103.508 +        System.arraycopy(str, 0, value, count, len);
 103.509 +        count += len;
 103.510 +        return this;
 103.511 +    }
 103.512 +
 103.513 +    /**
 103.514 +     * Appends the string representation of a subarray of the
 103.515 +     * {@code char} array argument to this sequence.
 103.516 +     * <p>
 103.517 +     * Characters of the {@code char} array {@code str}, starting at
 103.518 +     * index {@code offset}, are appended, in order, to the contents
 103.519 +     * of this sequence. The length of this sequence increases
 103.520 +     * by the value of {@code len}.
 103.521 +     * <p>
 103.522 +     * The overall effect is exactly as if the arguments were converted
 103.523 +     * to a string by the method {@link String#valueOf(char[],int,int)},
 103.524 +     * and the characters of that string were then
 103.525 +     * {@link #append(String) appended} to this character sequence.
 103.526 +     *
 103.527 +     * @param   str      the characters to be appended.
 103.528 +     * @param   offset   the index of the first {@code char} to append.
 103.529 +     * @param   len      the number of {@code char}s to append.
 103.530 +     * @return  a reference to this object.
 103.531 +     * @throws IndexOutOfBoundsException
 103.532 +     *         if {@code offset < 0} or {@code len < 0}
 103.533 +     *         or {@code offset+len > str.length}
 103.534 +     */
 103.535 +    public AbstractStringBuilder append(char str[], int offset, int len) {
 103.536 +        if (len > 0)                // let arraycopy report AIOOBE for len < 0
 103.537 +            ensureCapacityInternal(count + len);
 103.538 +        System.arraycopy(str, offset, value, count, len);
 103.539 +        count += len;
 103.540 +        return this;
 103.541 +    }
 103.542 +
 103.543 +    /**
 103.544 +     * Appends the string representation of the {@code boolean}
 103.545 +     * argument to the sequence.
 103.546 +     * <p>
 103.547 +     * The overall effect is exactly as if the argument were converted
 103.548 +     * to a string by the method {@link String#valueOf(boolean)},
 103.549 +     * and the characters of that string were then
 103.550 +     * {@link #append(String) appended} to this character sequence.
 103.551 +     *
 103.552 +     * @param   b   a {@code boolean}.
 103.553 +     * @return  a reference to this object.
 103.554 +     */
 103.555 +    public AbstractStringBuilder append(boolean b) {
 103.556 +        if (b) {
 103.557 +            ensureCapacityInternal(count + 4);
 103.558 +            value[count++] = 't';
 103.559 +            value[count++] = 'r';
 103.560 +            value[count++] = 'u';
 103.561 +            value[count++] = 'e';
 103.562 +        } else {
 103.563 +            ensureCapacityInternal(count + 5);
 103.564 +            value[count++] = 'f';
 103.565 +            value[count++] = 'a';
 103.566 +            value[count++] = 'l';
 103.567 +            value[count++] = 's';
 103.568 +            value[count++] = 'e';
 103.569 +        }
 103.570 +        return this;
 103.571 +    }
 103.572 +
 103.573 +    /**
 103.574 +     * Appends the string representation of the {@code char}
 103.575 +     * argument to this sequence.
 103.576 +     * <p>
 103.577 +     * The argument is appended to the contents of this sequence.
 103.578 +     * The length of this sequence increases by {@code 1}.
 103.579 +     * <p>
 103.580 +     * The overall effect is exactly as if the argument were converted
 103.581 +     * to a string by the method {@link String#valueOf(char)},
 103.582 +     * and the character in that string were then
 103.583 +     * {@link #append(String) appended} to this character sequence.
 103.584 +     *
 103.585 +     * @param   c   a {@code char}.
 103.586 +     * @return  a reference to this object.
 103.587 +     */
 103.588 +    public AbstractStringBuilder append(char c) {
 103.589 +        ensureCapacityInternal(count + 1);
 103.590 +        value[count++] = c;
 103.591 +        return this;
 103.592 +    }
 103.593 +
 103.594 +    /**
 103.595 +     * Appends the string representation of the {@code int}
 103.596 +     * argument to this sequence.
 103.597 +     * <p>
 103.598 +     * The overall effect is exactly as if the argument were converted
 103.599 +     * to a string by the method {@link String#valueOf(int)},
 103.600 +     * and the characters of that string were then
 103.601 +     * {@link #append(String) appended} to this character sequence.
 103.602 +     *
 103.603 +     * @param   i   an {@code int}.
 103.604 +     * @return  a reference to this object.
 103.605 +     */
 103.606 +    public AbstractStringBuilder append(int i) {
 103.607 +        return append(Integer.toString(i));
 103.608 +    }
 103.609 +
 103.610 +    /**
 103.611 +     * Appends the string representation of the {@code long}
 103.612 +     * argument to this sequence.
 103.613 +     * <p>
 103.614 +     * The overall effect is exactly as if the argument were converted
 103.615 +     * to a string by the method {@link String#valueOf(long)},
 103.616 +     * and the characters of that string were then
 103.617 +     * {@link #append(String) appended} to this character sequence.
 103.618 +     *
 103.619 +     * @param   l   a {@code long}.
 103.620 +     * @return  a reference to this object.
 103.621 +     */
 103.622 +    public AbstractStringBuilder append(long l) {
 103.623 +        if (l == Long.MIN_VALUE) {
 103.624 +            append("-9223372036854775808");
 103.625 +            return this;
 103.626 +        }
 103.627 +        int appendedLength = (l < 0) ? Long.stringSize(-l) + 1
 103.628 +                                     : Long.stringSize(l);
 103.629 +        int spaceNeeded = count + appendedLength;
 103.630 +        ensureCapacityInternal(spaceNeeded);
 103.631 +        Long.getChars(l, spaceNeeded, value);
 103.632 +        count = spaceNeeded;
 103.633 +        return this;
 103.634 +    }
 103.635 +
 103.636 +    /**
 103.637 +     * Appends the string representation of the {@code float}
 103.638 +     * argument to this sequence.
 103.639 +     * <p>
 103.640 +     * The overall effect is exactly as if the argument were converted
 103.641 +     * to a string by the method {@link String#valueOf(float)},
 103.642 +     * and the characters of that string were then
 103.643 +     * {@link #append(String) appended} to this character sequence.
 103.644 +     *
 103.645 +     * @param   f   a {@code float}.
 103.646 +     * @return  a reference to this object.
 103.647 +     */
 103.648 +    public AbstractStringBuilder append(float f) {
 103.649 +        return append(Float.toString(f));
 103.650 +    }
 103.651 +
 103.652 +    /**
 103.653 +     * Appends the string representation of the {@code double}
 103.654 +     * argument to this sequence.
 103.655 +     * <p>
 103.656 +     * The overall effect is exactly as if the argument were converted
 103.657 +     * to a string by the method {@link String#valueOf(double)},
 103.658 +     * and the characters of that string were then
 103.659 +     * {@link #append(String) appended} to this character sequence.
 103.660 +     *
 103.661 +     * @param   d   a {@code double}.
 103.662 +     * @return  a reference to this object.
 103.663 +     */
 103.664 +    public AbstractStringBuilder append(double d) {
 103.665 +        return append(Double.toString(d));
 103.666 +    }
 103.667 +
 103.668 +    /**
 103.669 +     * Removes the characters in a substring of this sequence.
 103.670 +     * The substring begins at the specified {@code start} and extends to
 103.671 +     * the character at index {@code end - 1} or to the end of the
 103.672 +     * sequence if no such character exists. If
 103.673 +     * {@code start} is equal to {@code end}, no changes are made.
 103.674 +     *
 103.675 +     * @param      start  The beginning index, inclusive.
 103.676 +     * @param      end    The ending index, exclusive.
 103.677 +     * @return     This object.
 103.678 +     * @throws     StringIndexOutOfBoundsException  if {@code start}
 103.679 +     *             is negative, greater than {@code length()}, or
 103.680 +     *             greater than {@code end}.
 103.681 +     */
 103.682 +    public AbstractStringBuilder delete(int start, int end) {
 103.683 +        if (start < 0)
 103.684 +            throw new StringIndexOutOfBoundsException(start);
 103.685 +        if (end > count)
 103.686 +            end = count;
 103.687 +        if (start > end)
 103.688 +            throw new StringIndexOutOfBoundsException();
 103.689 +        int len = end - start;
 103.690 +        if (len > 0) {
 103.691 +            System.arraycopy(value, start+len, value, start, count-end);
 103.692 +            count -= len;
 103.693 +        }
 103.694 +        return this;
 103.695 +    }
 103.696 +
 103.697 +    /**
 103.698 +     * Appends the string representation of the {@code codePoint}
 103.699 +     * argument to this sequence.
 103.700 +     *
 103.701 +     * <p> The argument is appended to the contents of this sequence.
 103.702 +     * The length of this sequence increases by
 103.703 +     * {@link Character#charCount(int) Character.charCount(codePoint)}.
 103.704 +     *
 103.705 +     * <p> The overall effect is exactly as if the argument were
 103.706 +     * converted to a {@code char} array by the method
 103.707 +     * {@link Character#toChars(int)} and the character in that array
 103.708 +     * were then {@link #append(char[]) appended} to this character
 103.709 +     * sequence.
 103.710 +     *
 103.711 +     * @param   codePoint   a Unicode code point
 103.712 +     * @return  a reference to this object.
 103.713 +     * @exception IllegalArgumentException if the specified
 103.714 +     * {@code codePoint} isn't a valid Unicode code point
 103.715 +     */
 103.716 +    public AbstractStringBuilder appendCodePoint(int codePoint) {
 103.717 +        final int count = this.count;
 103.718 +
 103.719 +        if (Character.isBmpCodePoint(codePoint)) {
 103.720 +            ensureCapacityInternal(count + 1);
 103.721 +            value[count] = (char) codePoint;
 103.722 +            this.count = count + 1;
 103.723 +        } else if (Character.isValidCodePoint(codePoint)) {
 103.724 +            ensureCapacityInternal(count + 2);
 103.725 +            Character.toSurrogates(codePoint, value, count);
 103.726 +            this.count = count + 2;
 103.727 +        } else {
 103.728 +            throw new IllegalArgumentException();
 103.729 +        }
 103.730 +        return this;
 103.731 +    }
 103.732 +
 103.733 +    /**
 103.734 +     * Removes the <code>char</code> at the specified position in this
 103.735 +     * sequence. This sequence is shortened by one <code>char</code>.
 103.736 +     *
 103.737 +     * <p>Note: If the character at the given index is a supplementary
 103.738 +     * character, this method does not remove the entire character. If
 103.739 +     * correct handling of supplementary characters is required,
 103.740 +     * determine the number of <code>char</code>s to remove by calling
 103.741 +     * <code>Character.charCount(thisSequence.codePointAt(index))</code>,
 103.742 +     * where <code>thisSequence</code> is this sequence.
 103.743 +     *
 103.744 +     * @param       index  Index of <code>char</code> to remove
 103.745 +     * @return      This object.
 103.746 +     * @throws      StringIndexOutOfBoundsException  if the <code>index</code>
 103.747 +     *              is negative or greater than or equal to
 103.748 +     *              <code>length()</code>.
 103.749 +     */
 103.750 +    public AbstractStringBuilder deleteCharAt(int index) {
 103.751 +        if ((index < 0) || (index >= count))
 103.752 +            throw new StringIndexOutOfBoundsException(index);
 103.753 +        System.arraycopy(value, index+1, value, index, count-index-1);
 103.754 +        count--;
 103.755 +        return this;
 103.756 +    }
 103.757 +
 103.758 +    /**
 103.759 +     * Replaces the characters in a substring of this sequence
 103.760 +     * with characters in the specified <code>String</code>. The substring
 103.761 +     * begins at the specified <code>start</code> and extends to the character
 103.762 +     * at index <code>end - 1</code> or to the end of the
 103.763 +     * sequence if no such character exists. First the
 103.764 +     * characters in the substring are removed and then the specified
 103.765 +     * <code>String</code> is inserted at <code>start</code>. (This
 103.766 +     * sequence will be lengthened to accommodate the
 103.767 +     * specified String if necessary.)
 103.768 +     *
 103.769 +     * @param      start    The beginning index, inclusive.
 103.770 +     * @param      end      The ending index, exclusive.
 103.771 +     * @param      str   String that will replace previous contents.
 103.772 +     * @return     This object.
 103.773 +     * @throws     StringIndexOutOfBoundsException  if <code>start</code>
 103.774 +     *             is negative, greater than <code>length()</code>, or
 103.775 +     *             greater than <code>end</code>.
 103.776 +     */
 103.777 +    public AbstractStringBuilder replace(int start, int end, String str) {
 103.778 +        if (start < 0)
 103.779 +            throw new StringIndexOutOfBoundsException(start);
 103.780 +        if (start > count)
 103.781 +            throw new StringIndexOutOfBoundsException("start > length()");
 103.782 +        if (start > end)
 103.783 +            throw new StringIndexOutOfBoundsException("start > end");
 103.784 +
 103.785 +        if (end > count)
 103.786 +            end = count;
 103.787 +        int len = str.length();
 103.788 +        int newCount = count + len - (end - start);
 103.789 +        ensureCapacityInternal(newCount);
 103.790 +
 103.791 +        System.arraycopy(value, end, value, start + len, count - end);
 103.792 +        str.getChars(value, start);
 103.793 +        count = newCount;
 103.794 +        return this;
 103.795 +    }
 103.796 +
 103.797 +    /**
 103.798 +     * Returns a new <code>String</code> that contains a subsequence of
 103.799 +     * characters currently contained in this character sequence. The
 103.800 +     * substring begins at the specified index and extends to the end of
 103.801 +     * this sequence.
 103.802 +     *
 103.803 +     * @param      start    The beginning index, inclusive.
 103.804 +     * @return     The new string.
 103.805 +     * @throws     StringIndexOutOfBoundsException  if <code>start</code> is
 103.806 +     *             less than zero, or greater than the length of this object.
 103.807 +     */
 103.808 +    public String substring(int start) {
 103.809 +        return substring(start, count);
 103.810 +    }
 103.811 +
 103.812 +    /**
 103.813 +     * Returns a new character sequence that is a subsequence of this sequence.
 103.814 +     *
 103.815 +     * <p> An invocation of this method of the form
 103.816 +     *
 103.817 +     * <blockquote><pre>
 103.818 +     * sb.subSequence(begin,&nbsp;end)</pre></blockquote>
 103.819 +     *
 103.820 +     * behaves in exactly the same way as the invocation
 103.821 +     *
 103.822 +     * <blockquote><pre>
 103.823 +     * sb.substring(begin,&nbsp;end)</pre></blockquote>
 103.824 +     *
 103.825 +     * This method is provided so that this class can
 103.826 +     * implement the {@link CharSequence} interface. </p>
 103.827 +     *
 103.828 +     * @param      start   the start index, inclusive.
 103.829 +     * @param      end     the end index, exclusive.
 103.830 +     * @return     the specified subsequence.
 103.831 +     *
 103.832 +     * @throws  IndexOutOfBoundsException
 103.833 +     *          if <tt>start</tt> or <tt>end</tt> are negative,
 103.834 +     *          if <tt>end</tt> is greater than <tt>length()</tt>,
 103.835 +     *          or if <tt>start</tt> is greater than <tt>end</tt>
 103.836 +     * @spec JSR-51
 103.837 +     */
 103.838 +    public CharSequence subSequence(int start, int end) {
 103.839 +        return substring(start, end);
 103.840 +    }
 103.841 +
 103.842 +    /**
 103.843 +     * Returns a new <code>String</code> that contains a subsequence of
 103.844 +     * characters currently contained in this sequence. The
 103.845 +     * substring begins at the specified <code>start</code> and
 103.846 +     * extends to the character at index <code>end - 1</code>.
 103.847 +     *
 103.848 +     * @param      start    The beginning index, inclusive.
 103.849 +     * @param      end      The ending index, exclusive.
 103.850 +     * @return     The new string.
 103.851 +     * @throws     StringIndexOutOfBoundsException  if <code>start</code>
 103.852 +     *             or <code>end</code> are negative or greater than
 103.853 +     *             <code>length()</code>, or <code>start</code> is
 103.854 +     *             greater than <code>end</code>.
 103.855 +     */
 103.856 +    public String substring(int start, int end) {
 103.857 +        if (start < 0)
 103.858 +            throw new StringIndexOutOfBoundsException(start);
 103.859 +        if (end > count)
 103.860 +            throw new StringIndexOutOfBoundsException(end);
 103.861 +        if (start > end)
 103.862 +            throw new StringIndexOutOfBoundsException(end - start);
 103.863 +        return new String(value, start, end - start);
 103.864 +    }
 103.865 +
 103.866 +    /**
 103.867 +     * Inserts the string representation of a subarray of the {@code str}
 103.868 +     * array argument into this sequence. The subarray begins at the
 103.869 +     * specified {@code offset} and extends {@code len} {@code char}s.
 103.870 +     * The characters of the subarray are inserted into this sequence at
 103.871 +     * the position indicated by {@code index}. The length of this
 103.872 +     * sequence increases by {@code len} {@code char}s.
 103.873 +     *
 103.874 +     * @param      index    position at which to insert subarray.
 103.875 +     * @param      str       A {@code char} array.
 103.876 +     * @param      offset   the index of the first {@code char} in subarray to
 103.877 +     *             be inserted.
 103.878 +     * @param      len      the number of {@code char}s in the subarray to
 103.879 +     *             be inserted.
 103.880 +     * @return     This object
 103.881 +     * @throws     StringIndexOutOfBoundsException  if {@code index}
 103.882 +     *             is negative or greater than {@code length()}, or
 103.883 +     *             {@code offset} or {@code len} are negative, or
 103.884 +     *             {@code (offset+len)} is greater than
 103.885 +     *             {@code str.length}.
 103.886 +     */
 103.887 +    public AbstractStringBuilder insert(int index, char[] str, int offset,
 103.888 +                                        int len)
 103.889 +    {
 103.890 +        if ((index < 0) || (index > length()))
 103.891 +            throw new StringIndexOutOfBoundsException(index);
 103.892 +        if ((offset < 0) || (len < 0) || (offset > str.length - len))
 103.893 +            throw new StringIndexOutOfBoundsException(
 103.894 +                "offset " + offset + ", len " + len + ", str.length "
 103.895 +                + str.length);
 103.896 +        ensureCapacityInternal(count + len);
 103.897 +        System.arraycopy(value, index, value, index + len, count - index);
 103.898 +        System.arraycopy(str, offset, value, index, len);
 103.899 +        count += len;
 103.900 +        return this;
 103.901 +    }
 103.902 +
 103.903 +    /**
 103.904 +     * Inserts the string representation of the {@code Object}
 103.905 +     * argument into this character sequence.
 103.906 +     * <p>
 103.907 +     * The overall effect is exactly as if the second argument were
 103.908 +     * converted to a string by the method {@link String#valueOf(Object)},
 103.909 +     * and the characters of that string were then
 103.910 +     * {@link #insert(int,String) inserted} into this character
 103.911 +     * sequence at the indicated offset.
 103.912 +     * <p>
 103.913 +     * The {@code offset} argument must be greater than or equal to
 103.914 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
 103.915 +     * of this sequence.
 103.916 +     *
 103.917 +     * @param      offset   the offset.
 103.918 +     * @param      obj      an {@code Object}.
 103.919 +     * @return     a reference to this object.
 103.920 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
 103.921 +     */
 103.922 +    public AbstractStringBuilder insert(int offset, Object obj) {
 103.923 +        return insert(offset, String.valueOf(obj));
 103.924 +    }
 103.925 +
 103.926 +    /**
 103.927 +     * Inserts the string into this character sequence.
 103.928 +     * <p>
 103.929 +     * The characters of the {@code String} argument are inserted, in
 103.930 +     * order, into this sequence at the indicated offset, moving up any
 103.931 +     * characters originally above that position and increasing the length
 103.932 +     * of this sequence by the length of the argument. If
 103.933 +     * {@code str} is {@code null}, then the four characters
 103.934 +     * {@code "null"} are inserted into this sequence.
 103.935 +     * <p>
 103.936 +     * The character at index <i>k</i> in the new character sequence is
 103.937 +     * equal to:
 103.938 +     * <ul>
 103.939 +     * <li>the character at index <i>k</i> in the old character sequence, if
 103.940 +     * <i>k</i> is less than {@code offset}
 103.941 +     * <li>the character at index <i>k</i>{@code -offset} in the
 103.942 +     * argument {@code str}, if <i>k</i> is not less than
 103.943 +     * {@code offset} but is less than {@code offset+str.length()}
 103.944 +     * <li>the character at index <i>k</i>{@code -str.length()} in the
 103.945 +     * old character sequence, if <i>k</i> is not less than
 103.946 +     * {@code offset+str.length()}
 103.947 +     * </ul><p>
 103.948 +     * The {@code offset} argument must be greater than or equal to
 103.949 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
 103.950 +     * of this sequence.
 103.951 +     *
 103.952 +     * @param      offset   the offset.
 103.953 +     * @param      str      a string.
 103.954 +     * @return     a reference to this object.
 103.955 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
 103.956 +     */
 103.957 +    public AbstractStringBuilder insert(int offset, String str) {
 103.958 +        if ((offset < 0) || (offset > length()))
 103.959 +            throw new StringIndexOutOfBoundsException(offset);
 103.960 +        if (str == null)
 103.961 +            str = "null";
 103.962 +        int len = str.length();
 103.963 +        ensureCapacityInternal(count + len);
 103.964 +        System.arraycopy(value, offset, value, offset + len, count - offset);
 103.965 +        str.getChars(value, offset);
 103.966 +        count += len;
 103.967 +        return this;
 103.968 +    }
 103.969 +
 103.970 +    /**
 103.971 +     * Inserts the string representation of the {@code char} array
 103.972 +     * argument into this sequence.
 103.973 +     * <p>
 103.974 +     * The characters of the array argument are inserted into the
 103.975 +     * contents of this sequence at the position indicated by
 103.976 +     * {@code offset}. The length of this sequence increases by
 103.977 +     * the length of the argument.
 103.978 +     * <p>
 103.979 +     * The overall effect is exactly as if the second argument were
 103.980 +     * converted to a string by the method {@link String#valueOf(char[])},
 103.981 +     * and the characters of that string were then
 103.982 +     * {@link #insert(int,String) inserted} into this character
 103.983 +     * sequence at the indicated offset.
 103.984 +     * <p>
 103.985 +     * The {@code offset} argument must be greater than or equal to
 103.986 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
 103.987 +     * of this sequence.
 103.988 +     *
 103.989 +     * @param      offset   the offset.
 103.990 +     * @param      str      a character array.
 103.991 +     * @return     a reference to this object.
 103.992 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
 103.993 +     */
 103.994 +    public AbstractStringBuilder insert(int offset, char[] str) {
 103.995 +        if ((offset < 0) || (offset > length()))
 103.996 +            throw new StringIndexOutOfBoundsException(offset);
 103.997 +        int len = str.length;
 103.998 +        ensureCapacityInternal(count + len);
 103.999 +        System.arraycopy(value, offset, value, offset + len, count - offset);
103.1000 +        System.arraycopy(str, 0, value, offset, len);
103.1001 +        count += len;
103.1002 +        return this;
103.1003 +    }
103.1004 +
103.1005 +    /**
103.1006 +     * Inserts the specified {@code CharSequence} into this sequence.
103.1007 +     * <p>
103.1008 +     * The characters of the {@code CharSequence} argument are inserted,
103.1009 +     * in order, into this sequence at the indicated offset, moving up
103.1010 +     * any characters originally above that position and increasing the length
103.1011 +     * of this sequence by the length of the argument s.
103.1012 +     * <p>
103.1013 +     * The result of this method is exactly the same as if it were an
103.1014 +     * invocation of this object's
103.1015 +     * {@link #insert(int,CharSequence,int,int) insert}(dstOffset, s, 0, s.length())
103.1016 +     * method.
103.1017 +     *
103.1018 +     * <p>If {@code s} is {@code null}, then the four characters
103.1019 +     * {@code "null"} are inserted into this sequence.
103.1020 +     *
103.1021 +     * @param      dstOffset   the offset.
103.1022 +     * @param      s the sequence to be inserted
103.1023 +     * @return     a reference to this object.
103.1024 +     * @throws     IndexOutOfBoundsException  if the offset is invalid.
103.1025 +     */
103.1026 +    public AbstractStringBuilder insert(int dstOffset, CharSequence s) {
103.1027 +        if (s == null)
103.1028 +            s = "null";
103.1029 +        if (s instanceof String)
103.1030 +            return this.insert(dstOffset, (String)s);
103.1031 +        return this.insert(dstOffset, s, 0, s.length());
103.1032 +    }
103.1033 +
103.1034 +    /**
103.1035 +     * Inserts a subsequence of the specified {@code CharSequence} into
103.1036 +     * this sequence.
103.1037 +     * <p>
103.1038 +     * The subsequence of the argument {@code s} specified by
103.1039 +     * {@code start} and {@code end} are inserted,
103.1040 +     * in order, into this sequence at the specified destination offset, moving
103.1041 +     * up any characters originally above that position. The length of this
103.1042 +     * sequence is increased by {@code end - start}.
103.1043 +     * <p>
103.1044 +     * The character at index <i>k</i> in this sequence becomes equal to:
103.1045 +     * <ul>
103.1046 +     * <li>the character at index <i>k</i> in this sequence, if
103.1047 +     * <i>k</i> is less than {@code dstOffset}
103.1048 +     * <li>the character at index <i>k</i>{@code +start-dstOffset} in
103.1049 +     * the argument {@code s}, if <i>k</i> is greater than or equal to
103.1050 +     * {@code dstOffset} but is less than {@code dstOffset+end-start}
103.1051 +     * <li>the character at index <i>k</i>{@code -(end-start)} in this
103.1052 +     * sequence, if <i>k</i> is greater than or equal to
103.1053 +     * {@code dstOffset+end-start}
103.1054 +     * </ul><p>
103.1055 +     * The {@code dstOffset} argument must be greater than or equal to
103.1056 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
103.1057 +     * of this sequence.
103.1058 +     * <p>The start argument must be nonnegative, and not greater than
103.1059 +     * {@code end}.
103.1060 +     * <p>The end argument must be greater than or equal to
103.1061 +     * {@code start}, and less than or equal to the length of s.
103.1062 +     *
103.1063 +     * <p>If {@code s} is {@code null}, then this method inserts
103.1064 +     * characters as if the s parameter was a sequence containing the four
103.1065 +     * characters {@code "null"}.
103.1066 +     *
103.1067 +     * @param      dstOffset   the offset in this sequence.
103.1068 +     * @param      s       the sequence to be inserted.
103.1069 +     * @param      start   the starting index of the subsequence to be inserted.
103.1070 +     * @param      end     the end index of the subsequence to be inserted.
103.1071 +     * @return     a reference to this object.
103.1072 +     * @throws     IndexOutOfBoundsException  if {@code dstOffset}
103.1073 +     *             is negative or greater than {@code this.length()}, or
103.1074 +     *              {@code start} or {@code end} are negative, or
103.1075 +     *              {@code start} is greater than {@code end} or
103.1076 +     *              {@code end} is greater than {@code s.length()}
103.1077 +     */
103.1078 +     public AbstractStringBuilder insert(int dstOffset, CharSequence s,
103.1079 +                                         int start, int end) {
103.1080 +        if (s == null)
103.1081 +            s = "null";
103.1082 +        if ((dstOffset < 0) || (dstOffset > this.length()))
103.1083 +            throw new IndexOutOfBoundsException("dstOffset "+dstOffset);
103.1084 +        if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
103.1085 +            throw new IndexOutOfBoundsException(
103.1086 +                "start " + start + ", end " + end + ", s.length() "
103.1087 +                + s.length());
103.1088 +        int len = end - start;
103.1089 +        ensureCapacityInternal(count + len);
103.1090 +        System.arraycopy(value, dstOffset, value, dstOffset + len,
103.1091 +                         count - dstOffset);
103.1092 +        for (int i=start; i<end; i++)
103.1093 +            value[dstOffset++] = s.charAt(i);
103.1094 +        count += len;
103.1095 +        return this;
103.1096 +    }
103.1097 +
103.1098 +    /**
103.1099 +     * Inserts the string representation of the {@code boolean}
103.1100 +     * argument into this sequence.
103.1101 +     * <p>
103.1102 +     * The overall effect is exactly as if the second argument were
103.1103 +     * converted to a string by the method {@link String#valueOf(boolean)},
103.1104 +     * and the characters of that string were then
103.1105 +     * {@link #insert(int,String) inserted} into this character
103.1106 +     * sequence at the indicated offset.
103.1107 +     * <p>
103.1108 +     * The {@code offset} argument must be greater than or equal to
103.1109 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
103.1110 +     * of this sequence.
103.1111 +     *
103.1112 +     * @param      offset   the offset.
103.1113 +     * @param      b        a {@code boolean}.
103.1114 +     * @return     a reference to this object.
103.1115 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
103.1116 +     */
103.1117 +    public AbstractStringBuilder insert(int offset, boolean b) {
103.1118 +        return insert(offset, String.valueOf(b));
103.1119 +    }
103.1120 +
103.1121 +    /**
103.1122 +     * Inserts the string representation of the {@code char}
103.1123 +     * argument into this sequence.
103.1124 +     * <p>
103.1125 +     * The overall effect is exactly as if the second argument were
103.1126 +     * converted to a string by the method {@link String#valueOf(char)},
103.1127 +     * and the character in that string were then
103.1128 +     * {@link #insert(int,String) inserted} into this character
103.1129 +     * sequence at the indicated offset.
103.1130 +     * <p>
103.1131 +     * The {@code offset} argument must be greater than or equal to
103.1132 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
103.1133 +     * of this sequence.
103.1134 +     *
103.1135 +     * @param      offset   the offset.
103.1136 +     * @param      c        a {@code char}.
103.1137 +     * @return     a reference to this object.
103.1138 +     * @throws     IndexOutOfBoundsException  if the offset is invalid.
103.1139 +     */
103.1140 +    public AbstractStringBuilder insert(int offset, char c) {
103.1141 +        ensureCapacityInternal(count + 1);
103.1142 +        System.arraycopy(value, offset, value, offset + 1, count - offset);
103.1143 +        value[offset] = c;
103.1144 +        count += 1;
103.1145 +        return this;
103.1146 +    }
103.1147 +
103.1148 +    /**
103.1149 +     * Inserts the string representation of the second {@code int}
103.1150 +     * argument into this sequence.
103.1151 +     * <p>
103.1152 +     * The overall effect is exactly as if the second argument were
103.1153 +     * converted to a string by the method {@link String#valueOf(int)},
103.1154 +     * and the characters of that string were then
103.1155 +     * {@link #insert(int,String) inserted} into this character
103.1156 +     * sequence at the indicated offset.
103.1157 +     * <p>
103.1158 +     * The {@code offset} argument must be greater than or equal to
103.1159 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
103.1160 +     * of this sequence.
103.1161 +     *
103.1162 +     * @param      offset   the offset.
103.1163 +     * @param      i        an {@code int}.
103.1164 +     * @return     a reference to this object.
103.1165 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
103.1166 +     */
103.1167 +    public AbstractStringBuilder insert(int offset, int i) {
103.1168 +        return insert(offset, String.valueOf(i));
103.1169 +    }
103.1170 +
103.1171 +    /**
103.1172 +     * Inserts the string representation of the {@code long}
103.1173 +     * argument into this sequence.
103.1174 +     * <p>
103.1175 +     * The overall effect is exactly as if the second argument were
103.1176 +     * converted to a string by the method {@link String#valueOf(long)},
103.1177 +     * and the characters of that string were then
103.1178 +     * {@link #insert(int,String) inserted} into this character
103.1179 +     * sequence at the indicated offset.
103.1180 +     * <p>
103.1181 +     * The {@code offset} argument must be greater than or equal to
103.1182 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
103.1183 +     * of this sequence.
103.1184 +     *
103.1185 +     * @param      offset   the offset.
103.1186 +     * @param      l        a {@code long}.
103.1187 +     * @return     a reference to this object.
103.1188 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
103.1189 +     */
103.1190 +    public AbstractStringBuilder insert(int offset, long l) {
103.1191 +        return insert(offset, String.valueOf(l));
103.1192 +    }
103.1193 +
103.1194 +    /**
103.1195 +     * Inserts the string representation of the {@code float}
103.1196 +     * argument into this sequence.
103.1197 +     * <p>
103.1198 +     * The overall effect is exactly as if the second argument were
103.1199 +     * converted to a string by the method {@link String#valueOf(float)},
103.1200 +     * and the characters of that string were then
103.1201 +     * {@link #insert(int,String) inserted} into this character
103.1202 +     * sequence at the indicated offset.
103.1203 +     * <p>
103.1204 +     * The {@code offset} argument must be greater than or equal to
103.1205 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
103.1206 +     * of this sequence.
103.1207 +     *
103.1208 +     * @param      offset   the offset.
103.1209 +     * @param      f        a {@code float}.
103.1210 +     * @return     a reference to this object.
103.1211 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
103.1212 +     */
103.1213 +    public AbstractStringBuilder insert(int offset, float f) {
103.1214 +        return insert(offset, String.valueOf(f));
103.1215 +    }
103.1216 +
103.1217 +    /**
103.1218 +     * Inserts the string representation of the {@code double}
103.1219 +     * argument into this sequence.
103.1220 +     * <p>
103.1221 +     * The overall effect is exactly as if the second argument were
103.1222 +     * converted to a string by the method {@link String#valueOf(double)},
103.1223 +     * and the characters of that string were then
103.1224 +     * {@link #insert(int,String) inserted} into this character
103.1225 +     * sequence at the indicated offset.
103.1226 +     * <p>
103.1227 +     * The {@code offset} argument must be greater than or equal to
103.1228 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
103.1229 +     * of this sequence.
103.1230 +     *
103.1231 +     * @param      offset   the offset.
103.1232 +     * @param      d        a {@code double}.
103.1233 +     * @return     a reference to this object.
103.1234 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
103.1235 +     */
103.1236 +    public AbstractStringBuilder insert(int offset, double d) {
103.1237 +        return insert(offset, String.valueOf(d));
103.1238 +    }
103.1239 +
103.1240 +    /**
103.1241 +     * Returns the index within this string of the first occurrence of the
103.1242 +     * specified substring. The integer returned is the smallest value
103.1243 +     * <i>k</i> such that:
103.1244 +     * <blockquote><pre>
103.1245 +     * this.toString().startsWith(str, <i>k</i>)
103.1246 +     * </pre></blockquote>
103.1247 +     * is <code>true</code>.
103.1248 +     *
103.1249 +     * @param   str   any string.
103.1250 +     * @return  if the string argument occurs as a substring within this
103.1251 +     *          object, then the index of the first character of the first
103.1252 +     *          such substring is returned; if it does not occur as a
103.1253 +     *          substring, <code>-1</code> is returned.
103.1254 +     * @throws  java.lang.NullPointerException if <code>str</code> is
103.1255 +     *          <code>null</code>.
103.1256 +     */
103.1257 +    public int indexOf(String str) {
103.1258 +        return indexOf(str, 0);
103.1259 +    }
103.1260 +
103.1261 +    /**
103.1262 +     * Returns the index within this string of the first occurrence of the
103.1263 +     * specified substring, starting at the specified index.  The integer
103.1264 +     * returned is the smallest value <tt>k</tt> for which:
103.1265 +     * <blockquote><pre>
103.1266 +     *     k >= Math.min(fromIndex, str.length()) &&
103.1267 +     *                   this.toString().startsWith(str, k)
103.1268 +     * </pre></blockquote>
103.1269 +     * If no such value of <i>k</i> exists, then -1 is returned.
103.1270 +     *
103.1271 +     * @param   str         the substring for which to search.
103.1272 +     * @param   fromIndex   the index from which to start the search.
103.1273 +     * @return  the index within this string of the first occurrence of the
103.1274 +     *          specified substring, starting at the specified index.
103.1275 +     * @throws  java.lang.NullPointerException if <code>str</code> is
103.1276 +     *            <code>null</code>.
103.1277 +     */
103.1278 +    public int indexOf(String str, int fromIndex) {
103.1279 +        return toString().indexOf(str, fromIndex);
103.1280 +    }
103.1281 +
103.1282 +    /**
103.1283 +     * Returns the index within this string of the rightmost occurrence
103.1284 +     * of the specified substring.  The rightmost empty string "" is
103.1285 +     * considered to occur at the index value <code>this.length()</code>.
103.1286 +     * The returned index is the largest value <i>k</i> such that
103.1287 +     * <blockquote><pre>
103.1288 +     * this.toString().startsWith(str, k)
103.1289 +     * </pre></blockquote>
103.1290 +     * is true.
103.1291 +     *
103.1292 +     * @param   str   the substring to search for.
103.1293 +     * @return  if the string argument occurs one or more times as a substring
103.1294 +     *          within this object, then the index of the first character of
103.1295 +     *          the last such substring is returned. If it does not occur as
103.1296 +     *          a substring, <code>-1</code> is returned.
103.1297 +     * @throws  java.lang.NullPointerException  if <code>str</code> is
103.1298 +     *          <code>null</code>.
103.1299 +     */
103.1300 +    public int lastIndexOf(String str) {
103.1301 +        return lastIndexOf(str, count);
103.1302 +    }
103.1303 +
103.1304 +    /**
103.1305 +     * Returns the index within this string of the last occurrence of the
103.1306 +     * specified substring. The integer returned is the largest value <i>k</i>
103.1307 +     * such that:
103.1308 +     * <blockquote><pre>
103.1309 +     *     k <= Math.min(fromIndex, str.length()) &&
103.1310 +     *                   this.toString().startsWith(str, k)
103.1311 +     * </pre></blockquote>
103.1312 +     * If no such value of <i>k</i> exists, then -1 is returned.
103.1313 +     *
103.1314 +     * @param   str         the substring to search for.
103.1315 +     * @param   fromIndex   the index to start the search from.
103.1316 +     * @return  the index within this sequence of the last occurrence of the
103.1317 +     *          specified substring.
103.1318 +     * @throws  java.lang.NullPointerException if <code>str</code> is
103.1319 +     *          <code>null</code>.
103.1320 +     */
103.1321 +    public int lastIndexOf(String str, int fromIndex) {
103.1322 +        return String.lastIndexOf(value, 0, count,
103.1323 +                              str.toCharArray(), 0, str.length(), fromIndex);
103.1324 +    }
103.1325 +
103.1326 +    /**
103.1327 +     * Causes this character sequence to be replaced by the reverse of
103.1328 +     * the sequence. If there are any surrogate pairs included in the
103.1329 +     * sequence, these are treated as single characters for the
103.1330 +     * reverse operation. Thus, the order of the high-low surrogates
103.1331 +     * is never reversed.
103.1332 +     *
103.1333 +     * Let <i>n</i> be the character length of this character sequence
103.1334 +     * (not the length in <code>char</code> values) just prior to
103.1335 +     * execution of the <code>reverse</code> method. Then the
103.1336 +     * character at index <i>k</i> in the new character sequence is
103.1337 +     * equal to the character at index <i>n-k-1</i> in the old
103.1338 +     * character sequence.
103.1339 +     *
103.1340 +     * <p>Note that the reverse operation may result in producing
103.1341 +     * surrogate pairs that were unpaired low-surrogates and
103.1342 +     * high-surrogates before the operation. For example, reversing
103.1343 +     * "&#92;uDC00&#92;uD800" produces "&#92;uD800&#92;uDC00" which is
103.1344 +     * a valid surrogate pair.
103.1345 +     *
103.1346 +     * @return  a reference to this object.
103.1347 +     */
103.1348 +    public AbstractStringBuilder reverse() {
103.1349 +        boolean hasSurrogate = false;
103.1350 +        int n = count - 1;
103.1351 +        for (int j = (n-1) >> 1; j >= 0; --j) {
103.1352 +            char temp = value[j];
103.1353 +            char temp2 = value[n - j];
103.1354 +            if (!hasSurrogate) {
103.1355 +                hasSurrogate = (temp >= Character.MIN_SURROGATE && temp <= Character.MAX_SURROGATE)
103.1356 +                    || (temp2 >= Character.MIN_SURROGATE && temp2 <= Character.MAX_SURROGATE);
103.1357 +            }
103.1358 +            value[j] = temp2;
103.1359 +            value[n - j] = temp;
103.1360 +        }
103.1361 +        if (hasSurrogate) {
103.1362 +            // Reverse back all valid surrogate pairs
103.1363 +            for (int i = 0; i < count - 1; i++) {
103.1364 +                char c2 = value[i];
103.1365 +                if (Character.isLowSurrogate(c2)) {
103.1366 +                    char c1 = value[i + 1];
103.1367 +                    if (Character.isHighSurrogate(c1)) {
103.1368 +                        value[i++] = c1;
103.1369 +                        value[i] = c2;
103.1370 +                    }
103.1371 +                }
103.1372 +            }
103.1373 +        }
103.1374 +        return this;
103.1375 +    }
103.1376 +
103.1377 +    /**
103.1378 +     * Returns a string representing the data in this sequence.
103.1379 +     * A new <code>String</code> object is allocated and initialized to
103.1380 +     * contain the character sequence currently represented by this
103.1381 +     * object. This <code>String</code> is then returned. Subsequent
103.1382 +     * changes to this sequence do not affect the contents of the
103.1383 +     * <code>String</code>.
103.1384 +     *
103.1385 +     * @return  a string representation of this sequence of characters.
103.1386 +     */
103.1387 +    public abstract String toString();
103.1388 +
103.1389 +    /**
103.1390 +     * Needed by <tt>String</tt> for the contentEquals method.
103.1391 +     */
103.1392 +    final char[] getValue() {
103.1393 +        return value;
103.1394 +    }
103.1395 +
103.1396 +    static char[] copyOfRange(char[] original, int from, int to) {
103.1397 +        int newLength = to - from;
103.1398 +        if (newLength < 0) {
103.1399 +            throw new IllegalArgumentException(from + " > " + to);
103.1400 +        }
103.1401 +        char[] copy = new char[newLength];
103.1402 +        System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
103.1403 +        return copy;
103.1404 +    }
103.1405 +
103.1406 +    // access system property
103.1407 +    static String getProperty(String nm) {
103.1408 +        return null;
103.1409 +    }
103.1410 +
103.1411 +    static char[] copyOf(char[] original, int newLength) {
103.1412 +        char[] copy = new char[newLength];
103.1413 +        System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
103.1414 +        return copy;
103.1415 +    }
103.1416 +    
103.1417 +}
   104.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   104.2 +++ b/emul/mini/src/main/java/java/lang/Appendable.java	Sun Feb 03 07:48:42 2013 +0100
   104.3 @@ -0,0 +1,121 @@
   104.4 +/*
   104.5 + * Copyright (c) 2003, 2004, 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.lang;
  104.30 +
  104.31 +import java.io.IOException;
  104.32 +
  104.33 +/**
  104.34 + * An object to which <tt>char</tt> sequences and values can be appended.  The
  104.35 + * <tt>Appendable</tt> interface must be implemented by any class whose
  104.36 + * instances are intended to receive formatted output from a {@link
  104.37 + * java.util.Formatter}.
  104.38 + *
  104.39 + * <p> The characters to be appended should be valid Unicode characters as
  104.40 + * described in <a href="Character.html#unicode">Unicode Character
  104.41 + * Representation</a>.  Note that supplementary characters may be composed of
  104.42 + * multiple 16-bit <tt>char</tt> values.
  104.43 + *
  104.44 + * <p> Appendables are not necessarily safe for multithreaded access.  Thread
  104.45 + * safety is the responsibility of classes that extend and implement this
  104.46 + * interface.
  104.47 + *
  104.48 + * <p> Since this interface may be implemented by existing classes
  104.49 + * with different styles of error handling there is no guarantee that
  104.50 + * errors will be propagated to the invoker.
  104.51 + *
  104.52 + * @since 1.5
  104.53 + */
  104.54 +public interface Appendable {
  104.55 +
  104.56 +    /**
  104.57 +     * Appends the specified character sequence to this <tt>Appendable</tt>.
  104.58 +     *
  104.59 +     * <p> Depending on which class implements the character sequence
  104.60 +     * <tt>csq</tt>, the entire sequence may not be appended.  For
  104.61 +     * instance, if <tt>csq</tt> is a {@link java.nio.CharBuffer} then
  104.62 +     * the subsequence to append is defined by the buffer's position and limit.
  104.63 +     *
  104.64 +     * @param  csq
  104.65 +     *         The character sequence to append.  If <tt>csq</tt> is
  104.66 +     *         <tt>null</tt>, then the four characters <tt>"null"</tt> are
  104.67 +     *         appended to this Appendable.
  104.68 +     *
  104.69 +     * @return  A reference to this <tt>Appendable</tt>
  104.70 +     *
  104.71 +     * @throws  IOException
  104.72 +     *          If an I/O error occurs
  104.73 +     */
  104.74 +    Appendable append(CharSequence csq) throws IOException;
  104.75 +
  104.76 +    /**
  104.77 +     * Appends a subsequence of the specified character sequence to this
  104.78 +     * <tt>Appendable</tt>.
  104.79 +     *
  104.80 +     * <p> An invocation of this method of the form <tt>out.append(csq, start,
  104.81 +     * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
  104.82 +     * exactly the same way as the invocation
  104.83 +     *
  104.84 +     * <pre>
  104.85 +     *     out.append(csq.subSequence(start, end)) </pre>
  104.86 +     *
  104.87 +     * @param  csq
  104.88 +     *         The character sequence from which a subsequence will be
  104.89 +     *         appended.  If <tt>csq</tt> is <tt>null</tt>, then characters
  104.90 +     *         will be appended as if <tt>csq</tt> contained the four
  104.91 +     *         characters <tt>"null"</tt>.
  104.92 +     *
  104.93 +     * @param  start
  104.94 +     *         The index of the first character in the subsequence
  104.95 +     *
  104.96 +     * @param  end
  104.97 +     *         The index of the character following the last character in the
  104.98 +     *         subsequence
  104.99 +     *
 104.100 +     * @return  A reference to this <tt>Appendable</tt>
 104.101 +     *
 104.102 +     * @throws  IndexOutOfBoundsException
 104.103 +     *          If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
 104.104 +     *          is greater than <tt>end</tt>, or <tt>end</tt> is greater than
 104.105 +     *          <tt>csq.length()</tt>
 104.106 +     *
 104.107 +     * @throws  IOException
 104.108 +     *          If an I/O error occurs
 104.109 +     */
 104.110 +    Appendable append(CharSequence csq, int start, int end) throws IOException;
 104.111 +
 104.112 +    /**
 104.113 +     * Appends the specified character to this <tt>Appendable</tt>.
 104.114 +     *
 104.115 +     * @param  c
 104.116 +     *         The character to append
 104.117 +     *
 104.118 +     * @return  A reference to this <tt>Appendable</tt>
 104.119 +     *
 104.120 +     * @throws  IOException
 104.121 +     *          If an I/O error occurs
 104.122 +     */
 104.123 +    Appendable append(char c) throws IOException;
 104.124 +}
   105.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   105.2 +++ b/emul/mini/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java	Sun Feb 03 07:48:42 2013 +0100
   105.3 @@ -0,0 +1,67 @@
   105.4 +/*
   105.5 + * Copyright (c) 1994, 2008, 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.lang;
  105.30 +
  105.31 +/**
  105.32 + * Thrown to indicate that an array has been accessed with an
  105.33 + * illegal index. The index is either negative or greater than or
  105.34 + * equal to the size of the array.
  105.35 + *
  105.36 + * @author  unascribed
  105.37 + * @since   JDK1.0
  105.38 + */
  105.39 +public
  105.40 +class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException {
  105.41 +    private static final long serialVersionUID = -5116101128118950844L;
  105.42 +
  105.43 +    /**
  105.44 +     * Constructs an <code>ArrayIndexOutOfBoundsException</code> with no
  105.45 +     * detail message.
  105.46 +     */
  105.47 +    public ArrayIndexOutOfBoundsException() {
  105.48 +        super();
  105.49 +    }
  105.50 +
  105.51 +    /**
  105.52 +     * Constructs a new <code>ArrayIndexOutOfBoundsException</code>
  105.53 +     * class with an argument indicating the illegal index.
  105.54 +     *
  105.55 +     * @param   index   the illegal index.
  105.56 +     */
  105.57 +    public ArrayIndexOutOfBoundsException(int index) {
  105.58 +        super("Array index out of range: " + index);
  105.59 +    }
  105.60 +
  105.61 +    /**
  105.62 +     * Constructs an <code>ArrayIndexOutOfBoundsException</code> class
  105.63 +     * with the specified detail message.
  105.64 +     *
  105.65 +     * @param   s   the detail message.
  105.66 +     */
  105.67 +    public ArrayIndexOutOfBoundsException(String s) {
  105.68 +        super(s);
  105.69 +    }
  105.70 +}
   106.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   106.2 +++ b/emul/mini/src/main/java/java/lang/ArrayStoreException.java	Sun Feb 03 07:48:42 2013 +0100
   106.3 @@ -0,0 +1,60 @@
   106.4 +/*
   106.5 + * Copyright (c) 1995, 2008, 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.lang;
  106.30 +
  106.31 +/**
  106.32 + * Thrown to indicate that an attempt has been made to store the
  106.33 + * wrong type of object into an array of objects. For example, the
  106.34 + * following code generates an <code>ArrayStoreException</code>:
  106.35 + * <p><blockquote><pre>
  106.36 + *     Object x[] = new String[3];
  106.37 + *     x[0] = new Integer(0);
  106.38 + * </pre></blockquote>
  106.39 + *
  106.40 + * @author  unascribed
  106.41 + * @since   JDK1.0
  106.42 + */
  106.43 +public
  106.44 +class ArrayStoreException extends RuntimeException {
  106.45 +    private static final long serialVersionUID = -4522193890499838241L;
  106.46 +
  106.47 +    /**
  106.48 +     * Constructs an <code>ArrayStoreException</code> with no detail message.
  106.49 +     */
  106.50 +    public ArrayStoreException() {
  106.51 +        super();
  106.52 +    }
  106.53 +
  106.54 +    /**
  106.55 +     * Constructs an <code>ArrayStoreException</code> with the specified
  106.56 +     * detail message.
  106.57 +     *
  106.58 +     * @param   s   the detail message.
  106.59 +     */
  106.60 +    public ArrayStoreException(String s) {
  106.61 +        super(s);
  106.62 +    }
  106.63 +}
   107.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   107.2 +++ b/emul/mini/src/main/java/java/lang/AssertionError.java	Sun Feb 03 07:48:42 2013 +0100
   107.3 @@ -0,0 +1,167 @@
   107.4 +/*
   107.5 + * Copyright (c) 2000, 2010, 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.lang;
  107.30 +
  107.31 +/**
  107.32 + * Thrown to indicate that an assertion has failed.
  107.33 + *
  107.34 + * <p>The seven one-argument public constructors provided by this
  107.35 + * class ensure that the assertion error returned by the invocation:
  107.36 + * <pre>
  107.37 + *     new AssertionError(<i>expression</i>)
  107.38 + * </pre>
  107.39 + * has as its detail message the <i>string conversion</i> of
  107.40 + * <i>expression</i> (as defined in section 15.18.1.1 of
  107.41 + * <cite>The Java&trade; Language Specification</cite>),
  107.42 + * regardless of the type of <i>expression</i>.
  107.43 + *
  107.44 + * @since   1.4
  107.45 + */
  107.46 +public class AssertionError extends Error {
  107.47 +    private static final long serialVersionUID = -5013299493970297370L;
  107.48 +
  107.49 +    /**
  107.50 +     * Constructs an AssertionError with no detail message.
  107.51 +     */
  107.52 +    public AssertionError() {
  107.53 +    }
  107.54 +
  107.55 +    /**
  107.56 +     * This internal constructor does no processing on its string argument,
  107.57 +     * even if it is a null reference.  The public constructors will
  107.58 +     * never call this constructor with a null argument.
  107.59 +     */
  107.60 +    private AssertionError(String detailMessage) {
  107.61 +        super(detailMessage);
  107.62 +    }
  107.63 +
  107.64 +    /**
  107.65 +     * Constructs an AssertionError with its detail message derived
  107.66 +     * from the specified object, which is converted to a string as
  107.67 +     * defined in section 15.18.1.1 of
  107.68 +     * <cite>The Java&trade; Language Specification</cite>.
  107.69 +     *<p>
  107.70 +     * If the specified object is an instance of {@code Throwable}, it
  107.71 +     * becomes the <i>cause</i> of the newly constructed assertion error.
  107.72 +     *
  107.73 +     * @param detailMessage value to be used in constructing detail message
  107.74 +     * @see   Throwable#getCause()
  107.75 +     */
  107.76 +    public AssertionError(Object detailMessage) {
  107.77 +        this("" +  detailMessage);
  107.78 +        if (detailMessage instanceof Throwable)
  107.79 +            initCause((Throwable) detailMessage);
  107.80 +    }
  107.81 +
  107.82 +    /**
  107.83 +     * Constructs an AssertionError with its detail message derived
  107.84 +     * from the specified <code>boolean</code>, which is converted to
  107.85 +     * a string as defined in section 15.18.1.1 of
  107.86 +     * <cite>The Java&trade; Language Specification</cite>.
  107.87 +     *
  107.88 +     * @param detailMessage value to be used in constructing detail message
  107.89 +     */
  107.90 +    public AssertionError(boolean detailMessage) {
  107.91 +        this("" +  detailMessage);
  107.92 +    }
  107.93 +
  107.94 +    /**
  107.95 +     * Constructs an AssertionError with its detail message derived
  107.96 +     * from the specified <code>char</code>, which is converted to a
  107.97 +     * string as defined in section 15.18.1.1 of
  107.98 +     * <cite>The Java&trade; Language Specification</cite>.
  107.99 +     *
 107.100 +     * @param detailMessage value to be used in constructing detail message
 107.101 +     */
 107.102 +    public AssertionError(char detailMessage) {
 107.103 +        this("" +  detailMessage);
 107.104 +    }
 107.105 +
 107.106 +    /**
 107.107 +     * Constructs an AssertionError with its detail message derived
 107.108 +     * from the specified <code>int</code>, which is converted to a
 107.109 +     * string as defined in section 15.18.1.1 of
 107.110 +     * <cite>The Java&trade; Language Specification</cite>.
 107.111 +     *
 107.112 +     * @param detailMessage value to be used in constructing detail message
 107.113 +     */
 107.114 +    public AssertionError(int detailMessage) {
 107.115 +        this("" +  detailMessage);
 107.116 +    }
 107.117 +
 107.118 +    /**
 107.119 +     * Constructs an AssertionError with its detail message derived
 107.120 +     * from the specified <code>long</code>, which is converted to a
 107.121 +     * string as defined in section 15.18.1.1 of
 107.122 +     * <cite>The Java&trade; Language Specification</cite>.
 107.123 +     *
 107.124 +     * @param detailMessage value to be used in constructing detail message
 107.125 +     */
 107.126 +    public AssertionError(long detailMessage) {
 107.127 +        this("" +  detailMessage);
 107.128 +    }
 107.129 +
 107.130 +    /**
 107.131 +     * Constructs an AssertionError with its detail message derived
 107.132 +     * from the specified <code>float</code>, which is converted to a
 107.133 +     * string as defined in section 15.18.1.1 of
 107.134 +     * <cite>The Java&trade; Language Specification</cite>.
 107.135 +     *
 107.136 +     * @param detailMessage value to be used in constructing detail message
 107.137 +     */
 107.138 +    public AssertionError(float detailMessage) {
 107.139 +        this("" +  detailMessage);
 107.140 +    }
 107.141 +
 107.142 +    /**
 107.143 +     * Constructs an AssertionError with its detail message derived
 107.144 +     * from the specified <code>double</code>, which is converted to a
 107.145 +     * string as defined in section 15.18.1.1 of
 107.146 +     * <cite>The Java&trade; Language Specification</cite>.
 107.147 +     *
 107.148 +     * @param detailMessage value to be used in constructing detail message
 107.149 +     */
 107.150 +    public AssertionError(double detailMessage) {
 107.151 +        this("" +  detailMessage);
 107.152 +    }
 107.153 +
 107.154 +    /**
 107.155 +     * Constructs a new {@code AssertionError} with the specified
 107.156 +     * detail message and cause.
 107.157 +     *
 107.158 +     * <p>Note that the detail message associated with
 107.159 +     * {@code cause} is <i>not</i> automatically incorporated in
 107.160 +     * this error's detail message.
 107.161 +     *
 107.162 +     * @param  message the detail message, may be {@code null}
 107.163 +     * @param  cause the cause, may be {@code null}
 107.164 +     *
 107.165 +     * @since 1.7
 107.166 +     */
 107.167 +    public AssertionError(String message, Throwable cause) {
 107.168 +        super(message, cause);
 107.169 +    }
 107.170 +}
   108.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   108.2 +++ b/emul/mini/src/main/java/java/lang/AutoCloseable.java	Sun Feb 03 07:48:42 2013 +0100
   108.3 @@ -0,0 +1,72 @@
   108.4 +/*
   108.5 + * Copyright (c) 2009, 2011, 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 +
  108.29 +package java.lang;
  108.30 +
  108.31 +/**
  108.32 + * A resource that must be closed when it is no longer needed.
  108.33 + *
  108.34 + * @author Josh Bloch
  108.35 + * @since 1.7
  108.36 + */
  108.37 +public interface AutoCloseable {
  108.38 +    /**
  108.39 +     * Closes this resource, relinquishing any underlying resources.
  108.40 +     * This method is invoked automatically on objects managed by the
  108.41 +     * {@code try}-with-resources statement.
  108.42 +     *
  108.43 +     * <p>While this interface method is declared to throw {@code
  108.44 +     * Exception}, implementers are <em>strongly</em> encouraged to
  108.45 +     * declare concrete implementations of the {@code close} method to
  108.46 +     * throw more specific exceptions, or to throw no exception at all
  108.47 +     * if the close operation cannot fail.
  108.48 +     *
  108.49 +     * <p><em>Implementers of this interface are also strongly advised
  108.50 +     * to not have the {@code close} method throw {@link
  108.51 +     * InterruptedException}.</em>
  108.52 +     *
  108.53 +     * This exception interacts with a thread's interrupted status,
  108.54 +     * and runtime misbehavior is likely to occur if an {@code
  108.55 +     * InterruptedException} is {@linkplain Throwable#addSuppressed
  108.56 +     * suppressed}.
  108.57 +     *
  108.58 +     * More generally, if it would cause problems for an
  108.59 +     * exception to be suppressed, the {@code AutoCloseable.close}
  108.60 +     * method should not throw it.
  108.61 +     *
  108.62 +     * <p>Note that unlike the {@link java.io.Closeable#close close}
  108.63 +     * method of {@link java.io.Closeable}, this {@code close} method
  108.64 +     * is <em>not</em> required to be idempotent.  In other words,
  108.65 +     * calling this {@code close} method more than once may have some
  108.66 +     * visible side effect, unlike {@code Closeable.close} which is
  108.67 +     * required to have no effect if called more than once.
  108.68 +     *
  108.69 +     * However, implementers of this interface are strongly encouraged
  108.70 +     * to make their {@code close} methods idempotent.
  108.71 +     *
  108.72 +     * @throws Exception if this resource cannot be closed
  108.73 +     */
  108.74 +    void close() throws Exception;
  108.75 +}
   109.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   109.2 +++ b/emul/mini/src/main/java/java/lang/Boolean.java	Sun Feb 03 07:48:42 2013 +0100
   109.3 @@ -0,0 +1,282 @@
   109.4 +/*
   109.5 + * Copyright (c) 1994, 2006, 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 + * The Boolean class wraps a value of the primitive type
  109.33 + * {@code boolean} in an object. An object of type
  109.34 + * {@code Boolean} contains a single field whose type is
  109.35 + * {@code boolean}.
  109.36 + * <p>
  109.37 + * In addition, this class provides many methods for
  109.38 + * converting a {@code boolean} to a {@code String} and a
  109.39 + * {@code String} to a {@code boolean}, as well as other
  109.40 + * constants and methods useful when dealing with a
  109.41 + * {@code boolean}.
  109.42 + *
  109.43 + * @author  Arthur van Hoff
  109.44 + * @since   JDK1.0
  109.45 + */
  109.46 +public final class Boolean implements java.io.Serializable,
  109.47 +                                      Comparable<Boolean>
  109.48 +{
  109.49 +    /**
  109.50 +     * The {@code Boolean} object corresponding to the primitive
  109.51 +     * value {@code true}.
  109.52 +     */
  109.53 +    public static final Boolean TRUE = new Boolean(true);
  109.54 +
  109.55 +    /**
  109.56 +     * The {@code Boolean} object corresponding to the primitive
  109.57 +     * value {@code false}.
  109.58 +     */
  109.59 +    public static final Boolean FALSE = new Boolean(false);
  109.60 +
  109.61 +    /**
  109.62 +     * The Class object representing the primitive type boolean.
  109.63 +     *
  109.64 +     * @since   JDK1.1
  109.65 +     */
  109.66 +    public static final Class<Boolean> TYPE = Class.getPrimitiveClass("boolean");
  109.67 +
  109.68 +    /**
  109.69 +     * The value of the Boolean.
  109.70 +     *
  109.71 +     * @serial
  109.72 +     */
  109.73 +    private final boolean value;
  109.74 +
  109.75 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
  109.76 +    private static final long serialVersionUID = -3665804199014368530L;
  109.77 +
  109.78 +    /**
  109.79 +     * Allocates a {@code Boolean} object representing the
  109.80 +     * {@code value} argument.
  109.81 +     *
  109.82 +     * <p><b>Note: It is rarely appropriate to use this constructor.
  109.83 +     * Unless a <i>new</i> instance is required, the static factory
  109.84 +     * {@link #valueOf(boolean)} is generally a better choice. It is
  109.85 +     * likely to yield significantly better space and time performance.</b>
  109.86 +     *
  109.87 +     * @param   value   the value of the {@code Boolean}.
  109.88 +     */
  109.89 +    public Boolean(boolean value) {
  109.90 +        this.value = value;
  109.91 +    }
  109.92 +
  109.93 +    /**
  109.94 +     * Allocates a {@code Boolean} object representing the value
  109.95 +     * {@code true} if the string argument is not {@code null}
  109.96 +     * and is equal, ignoring case, to the string {@code "true"}.
  109.97 +     * Otherwise, allocate a {@code Boolean} object representing the
  109.98 +     * value {@code false}. Examples:<p>
  109.99 +     * {@code new Boolean("True")} produces a {@code Boolean} object
 109.100 +     * that represents {@code true}.<br>
 109.101 +     * {@code new Boolean("yes")} produces a {@code Boolean} object
 109.102 +     * that represents {@code false}.
 109.103 +     *
 109.104 +     * @param   s   the string to be converted to a {@code Boolean}.
 109.105 +     */
 109.106 +    public Boolean(String s) {
 109.107 +        this(toBoolean(s));
 109.108 +    }
 109.109 +
 109.110 +    /**
 109.111 +     * Parses the string argument as a boolean.  The {@code boolean}
 109.112 +     * returned represents the value {@code true} if the string argument
 109.113 +     * is not {@code null} and is equal, ignoring case, to the string
 109.114 +     * {@code "true"}. <p>
 109.115 +     * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
 109.116 +     * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
 109.117 +     *
 109.118 +     * @param      s   the {@code String} containing the boolean
 109.119 +     *                 representation to be parsed
 109.120 +     * @return     the boolean represented by the string argument
 109.121 +     * @since 1.5
 109.122 +     */
 109.123 +    public static boolean parseBoolean(String s) {
 109.124 +        return toBoolean(s);
 109.125 +    }
 109.126 +
 109.127 +    /**
 109.128 +     * Returns the value of this {@code Boolean} object as a boolean
 109.129 +     * primitive.
 109.130 +     *
 109.131 +     * @return  the primitive {@code boolean} value of this object.
 109.132 +     */
 109.133 +    public boolean booleanValue() {
 109.134 +        return value;
 109.135 +    }
 109.136 +
 109.137 +    /**
 109.138 +     * Returns a {@code Boolean} instance representing the specified
 109.139 +     * {@code boolean} value.  If the specified {@code boolean} value
 109.140 +     * is {@code true}, this method returns {@code Boolean.TRUE};
 109.141 +     * if it is {@code false}, this method returns {@code Boolean.FALSE}.
 109.142 +     * If a new {@code Boolean} instance is not required, this method
 109.143 +     * should generally be used in preference to the constructor
 109.144 +     * {@link #Boolean(boolean)}, as this method is likely to yield
 109.145 +     * significantly better space and time performance.
 109.146 +     *
 109.147 +     * @param  b a boolean value.
 109.148 +     * @return a {@code Boolean} instance representing {@code b}.
 109.149 +     * @since  1.4
 109.150 +     */
 109.151 +    public static Boolean valueOf(boolean b) {
 109.152 +        return (b ? TRUE : FALSE);
 109.153 +    }
 109.154 +
 109.155 +    /**
 109.156 +     * Returns a {@code Boolean} with a value represented by the
 109.157 +     * specified string.  The {@code Boolean} returned represents a
 109.158 +     * true value if the string argument is not {@code null}
 109.159 +     * and is equal, ignoring case, to the string {@code "true"}.
 109.160 +     *
 109.161 +     * @param   s   a string.
 109.162 +     * @return  the {@code Boolean} value represented by the string.
 109.163 +     */
 109.164 +    public static Boolean valueOf(String s) {
 109.165 +        return toBoolean(s) ? TRUE : FALSE;
 109.166 +    }
 109.167 +
 109.168 +    /**
 109.169 +     * Returns a {@code String} object representing the specified
 109.170 +     * boolean.  If the specified boolean is {@code true}, then
 109.171 +     * the string {@code "true"} will be returned, otherwise the
 109.172 +     * string {@code "false"} will be returned.
 109.173 +     *
 109.174 +     * @param b the boolean to be converted
 109.175 +     * @return the string representation of the specified {@code boolean}
 109.176 +     * @since 1.4
 109.177 +     */
 109.178 +    public static String toString(boolean b) {
 109.179 +        return b ? "true" : "false";
 109.180 +    }
 109.181 +
 109.182 +    /**
 109.183 +     * Returns a {@code String} object representing this Boolean's
 109.184 +     * value.  If this object represents the value {@code true},
 109.185 +     * a string equal to {@code "true"} is returned. Otherwise, a
 109.186 +     * string equal to {@code "false"} is returned.
 109.187 +     *
 109.188 +     * @return  a string representation of this object.
 109.189 +     */
 109.190 +    public String toString() {
 109.191 +        return value ? "true" : "false";
 109.192 +    }
 109.193 +
 109.194 +    /**
 109.195 +     * Returns a hash code for this {@code Boolean} object.
 109.196 +     *
 109.197 +     * @return  the integer {@code 1231} if this object represents
 109.198 +     * {@code true}; returns the integer {@code 1237} if this
 109.199 +     * object represents {@code false}.
 109.200 +     */
 109.201 +    public int hashCode() {
 109.202 +        return value ? 1231 : 1237;
 109.203 +    }
 109.204 +
 109.205 +    /**
 109.206 +     * Returns {@code true} if and only if the argument is not
 109.207 +     * {@code null} and is a {@code Boolean} object that
 109.208 +     * represents the same {@code boolean} value as this object.
 109.209 +     *
 109.210 +     * @param   obj   the object to compare with.
 109.211 +     * @return  {@code true} if the Boolean objects represent the
 109.212 +     *          same value; {@code false} otherwise.
 109.213 +     */
 109.214 +    public boolean equals(Object obj) {
 109.215 +        if (obj instanceof Boolean) {
 109.216 +            return value == ((Boolean)obj).booleanValue();
 109.217 +        }
 109.218 +        return false;
 109.219 +    }
 109.220 +
 109.221 +    /**
 109.222 +     * Returns {@code true} if and only if the system property
 109.223 +     * named by the argument exists and is equal to the string
 109.224 +     * {@code "true"}. (Beginning with version 1.0.2 of the
 109.225 +     * Java<small><sup>TM</sup></small> platform, the test of
 109.226 +     * this string is case insensitive.) A system property is accessible
 109.227 +     * through {@code getProperty}, a method defined by the
 109.228 +     * {@code System} class.
 109.229 +     * <p>
 109.230 +     * If there is no property with the specified name, or if the specified
 109.231 +     * name is empty or null, then {@code false} is returned.
 109.232 +     *
 109.233 +     * @param   name   the system property name.
 109.234 +     * @return  the {@code boolean} value of the system property.
 109.235 +     * @see     java.lang.System#getProperty(java.lang.String)
 109.236 +     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 109.237 +     */
 109.238 +    public static boolean getBoolean(String name) {
 109.239 +        boolean result = false;
 109.240 +        try {
 109.241 +            result = toBoolean(AbstractStringBuilder.getProperty(name));
 109.242 +        } catch (IllegalArgumentException e) {
 109.243 +        } catch (NullPointerException e) {
 109.244 +        }
 109.245 +        return result;
 109.246 +    }
 109.247 +
 109.248 +    /**
 109.249 +     * Compares this {@code Boolean} instance with another.
 109.250 +     *
 109.251 +     * @param   b the {@code Boolean} instance to be compared
 109.252 +     * @return  zero if this object represents the same boolean value as the
 109.253 +     *          argument; a positive value if this object represents true
 109.254 +     *          and the argument represents false; and a negative value if
 109.255 +     *          this object represents false and the argument represents true
 109.256 +     * @throws  NullPointerException if the argument is {@code null}
 109.257 +     * @see     Comparable
 109.258 +     * @since  1.5
 109.259 +     */
 109.260 +    public int compareTo(Boolean b) {
 109.261 +        return compare(this.value, b.value);
 109.262 +    }
 109.263 +
 109.264 +    /**
 109.265 +     * Compares two {@code boolean} values.
 109.266 +     * The value returned is identical to what would be returned by:
 109.267 +     * <pre>
 109.268 +     *    Boolean.valueOf(x).compareTo(Boolean.valueOf(y))
 109.269 +     * </pre>
 109.270 +     *
 109.271 +     * @param  x the first {@code boolean} to compare
 109.272 +     * @param  y the second {@code boolean} to compare
 109.273 +     * @return the value {@code 0} if {@code x == y};
 109.274 +     *         a value less than {@code 0} if {@code !x && y}; and
 109.275 +     *         a value greater than {@code 0} if {@code x && !y}
 109.276 +     * @since 1.7
 109.277 +     */
 109.278 +    public static int compare(boolean x, boolean y) {
 109.279 +        return (x == y) ? 0 : (x ? 1 : -1);
 109.280 +    }
 109.281 +
 109.282 +    private static boolean toBoolean(String name) {
 109.283 +        return ((name != null) && name.equalsIgnoreCase("true"));
 109.284 +    }
 109.285 +}
   110.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   110.2 +++ b/emul/mini/src/main/java/java/lang/Byte.java	Sun Feb 03 07:48:42 2013 +0100
   110.3 @@ -0,0 +1,452 @@
   110.4 +/*
   110.5 + * Copyright (c) 1996, 2009, 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 +/**
  110.32 + *
  110.33 + * The {@code Byte} class wraps a value of primitive type {@code byte}
  110.34 + * in an object.  An object of type {@code Byte} contains a single
  110.35 + * field whose type is {@code byte}.
  110.36 + *
  110.37 + * <p>In addition, this class provides several methods for converting
  110.38 + * a {@code byte} to a {@code String} and a {@code String} to a {@code
  110.39 + * byte}, as well as other constants and methods useful when dealing
  110.40 + * with a {@code byte}.
  110.41 + *
  110.42 + * @author  Nakul Saraiya
  110.43 + * @author  Joseph D. Darcy
  110.44 + * @see     java.lang.Number
  110.45 + * @since   JDK1.1
  110.46 + */
  110.47 +public final class Byte extends Number implements Comparable<Byte> {
  110.48 +
  110.49 +    /**
  110.50 +     * A constant holding the minimum value a {@code byte} can
  110.51 +     * have, -2<sup>7</sup>.
  110.52 +     */
  110.53 +    public static final byte   MIN_VALUE = -128;
  110.54 +
  110.55 +    /**
  110.56 +     * A constant holding the maximum value a {@code byte} can
  110.57 +     * have, 2<sup>7</sup>-1.
  110.58 +     */
  110.59 +    public static final byte   MAX_VALUE = 127;
  110.60 +
  110.61 +    /**
  110.62 +     * The {@code Class} instance representing the primitive type
  110.63 +     * {@code byte}.
  110.64 +     */
  110.65 +    public static final Class<Byte>     TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");
  110.66 +
  110.67 +    /**
  110.68 +     * Returns a new {@code String} object representing the
  110.69 +     * specified {@code byte}. The radix is assumed to be 10.
  110.70 +     *
  110.71 +     * @param b the {@code byte} to be converted
  110.72 +     * @return the string representation of the specified {@code byte}
  110.73 +     * @see java.lang.Integer#toString(int)
  110.74 +     */
  110.75 +    public static String toString(byte b) {
  110.76 +        return Integer.toString((int)b, 10);
  110.77 +    }
  110.78 +
  110.79 +    private static class ByteCache {
  110.80 +        private ByteCache(){}
  110.81 +
  110.82 +        static final Byte cache[] = new Byte[-(-128) + 127 + 1];
  110.83 +
  110.84 +        static {
  110.85 +            for(int i = 0; i < cache.length; i++)
  110.86 +                cache[i] = new Byte((byte)(i - 128));
  110.87 +        }
  110.88 +    }
  110.89 +
  110.90 +    /**
  110.91 +     * Returns a {@code Byte} instance representing the specified
  110.92 +     * {@code byte} value.
  110.93 +     * If a new {@code Byte} instance is not required, this method
  110.94 +     * should generally be used in preference to the constructor
  110.95 +     * {@link #Byte(byte)}, as this method is likely to yield
  110.96 +     * significantly better space and time performance since
  110.97 +     * all byte values are cached.
  110.98 +     *
  110.99 +     * @param  b a byte value.
 110.100 +     * @return a {@code Byte} instance representing {@code b}.
 110.101 +     * @since  1.5
 110.102 +     */
 110.103 +    public static Byte valueOf(byte b) {
 110.104 +        final int offset = 128;
 110.105 +        return ByteCache.cache[(int)b + offset];
 110.106 +    }
 110.107 +
 110.108 +    /**
 110.109 +     * Parses the string argument as a signed {@code byte} in the
 110.110 +     * radix specified by the second argument. The characters in the
 110.111 +     * string must all be digits, of the specified radix (as
 110.112 +     * determined by whether {@link java.lang.Character#digit(char,
 110.113 +     * int)} returns a nonnegative value) except that the first
 110.114 +     * character may be an ASCII minus sign {@code '-'}
 110.115 +     * (<code>'&#92;u002D'</code>) to indicate a negative value or an
 110.116 +     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
 110.117 +     * indicate a positive value.  The resulting {@code byte} value is
 110.118 +     * returned.
 110.119 +     *
 110.120 +     * <p>An exception of type {@code NumberFormatException} is
 110.121 +     * thrown if any of the following situations occurs:
 110.122 +     * <ul>
 110.123 +     * <li> The first argument is {@code null} or is a string of
 110.124 +     * length zero.
 110.125 +     *
 110.126 +     * <li> The radix is either smaller than {@link
 110.127 +     * java.lang.Character#MIN_RADIX} or larger than {@link
 110.128 +     * java.lang.Character#MAX_RADIX}.
 110.129 +     *
 110.130 +     * <li> Any character of the string is not a digit of the
 110.131 +     * specified radix, except that the first character may be a minus
 110.132 +     * sign {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
 110.133 +     * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
 110.134 +     * string is longer than length 1.
 110.135 +     *
 110.136 +     * <li> The value represented by the string is not a value of type
 110.137 +     * {@code byte}.
 110.138 +     * </ul>
 110.139 +     *
 110.140 +     * @param s         the {@code String} containing the
 110.141 +     *                  {@code byte}
 110.142 +     *                  representation to be parsed
 110.143 +     * @param radix     the radix to be used while parsing {@code s}
 110.144 +     * @return          the {@code byte} value represented by the string
 110.145 +     *                   argument in the specified radix
 110.146 +     * @throws          NumberFormatException If the string does
 110.147 +     *                  not contain a parsable {@code byte}.
 110.148 +     */
 110.149 +    public static byte parseByte(String s, int radix)
 110.150 +        throws NumberFormatException {
 110.151 +        int i = Integer.parseInt(s, radix);
 110.152 +        if (i < MIN_VALUE || i > MAX_VALUE)
 110.153 +            throw new NumberFormatException(
 110.154 +                "Value out of range. Value:\"" + s + "\" Radix:" + radix);
 110.155 +        return (byte)i;
 110.156 +    }
 110.157 +
 110.158 +    /**
 110.159 +     * Parses the string argument as a signed decimal {@code
 110.160 +     * byte}. The characters in the string must all be decimal digits,
 110.161 +     * except that the first character may be an ASCII minus sign
 110.162 +     * {@code '-'} (<code>'&#92;u002D'</code>) to indicate a negative
 110.163 +     * value or an ASCII plus sign {@code '+'}
 110.164 +     * (<code>'&#92;u002B'</code>) to indicate a positive value. The
 110.165 +     * resulting {@code byte} value is returned, exactly as if the
 110.166 +     * argument and the radix 10 were given as arguments to the {@link
 110.167 +     * #parseByte(java.lang.String, int)} method.
 110.168 +     *
 110.169 +     * @param s         a {@code String} containing the
 110.170 +     *                  {@code byte} representation to be parsed
 110.171 +     * @return          the {@code byte} value represented by the
 110.172 +     *                  argument in decimal
 110.173 +     * @throws          NumberFormatException if the string does not
 110.174 +     *                  contain a parsable {@code byte}.
 110.175 +     */
 110.176 +    public static byte parseByte(String s) throws NumberFormatException {
 110.177 +        return parseByte(s, 10);
 110.178 +    }
 110.179 +
 110.180 +    /**
 110.181 +     * Returns a {@code Byte} object holding the value
 110.182 +     * extracted from the specified {@code String} when parsed
 110.183 +     * with the radix given by the second argument. The first argument
 110.184 +     * is interpreted as representing a signed {@code byte} in
 110.185 +     * the radix specified by the second argument, exactly as if the
 110.186 +     * argument were given to the {@link #parseByte(java.lang.String,
 110.187 +     * int)} method. The result is a {@code Byte} object that
 110.188 +     * represents the {@code byte} value specified by the string.
 110.189 +     *
 110.190 +     * <p> In other words, this method returns a {@code Byte} object
 110.191 +     * equal to the value of:
 110.192 +     *
 110.193 +     * <blockquote>
 110.194 +     * {@code new Byte(Byte.parseByte(s, radix))}
 110.195 +     * </blockquote>
 110.196 +     *
 110.197 +     * @param s         the string to be parsed
 110.198 +     * @param radix     the radix to be used in interpreting {@code s}
 110.199 +     * @return          a {@code Byte} object holding the value
 110.200 +     *                  represented by the string argument in the
 110.201 +     *                  specified radix.
 110.202 +     * @throws          NumberFormatException If the {@code String} does
 110.203 +     *                  not contain a parsable {@code byte}.
 110.204 +     */
 110.205 +    public static Byte valueOf(String s, int radix)
 110.206 +        throws NumberFormatException {
 110.207 +        return valueOf(parseByte(s, radix));
 110.208 +    }
 110.209 +
 110.210 +    /**
 110.211 +     * Returns a {@code Byte} object holding the value
 110.212 +     * given by the specified {@code String}. The argument is
 110.213 +     * interpreted as representing a signed decimal {@code byte},
 110.214 +     * exactly as if the argument were given to the {@link
 110.215 +     * #parseByte(java.lang.String)} method. The result is a
 110.216 +     * {@code Byte} object that represents the {@code byte}
 110.217 +     * value specified by the string.
 110.218 +     *
 110.219 +     * <p> In other words, this method returns a {@code Byte} object
 110.220 +     * equal to the value of:
 110.221 +     *
 110.222 +     * <blockquote>
 110.223 +     * {@code new Byte(Byte.parseByte(s))}
 110.224 +     * </blockquote>
 110.225 +     *
 110.226 +     * @param s         the string to be parsed
 110.227 +     * @return          a {@code Byte} object holding the value
 110.228 +     *                  represented by the string argument
 110.229 +     * @throws          NumberFormatException If the {@code String} does
 110.230 +     *                  not contain a parsable {@code byte}.
 110.231 +     */
 110.232 +    public static Byte valueOf(String s) throws NumberFormatException {
 110.233 +        return valueOf(s, 10);
 110.234 +    }
 110.235 +
 110.236 +    /**
 110.237 +     * Decodes a {@code String} into a {@code Byte}.
 110.238 +     * Accepts decimal, hexadecimal, and octal numbers given by
 110.239 +     * the following grammar:
 110.240 +     *
 110.241 +     * <blockquote>
 110.242 +     * <dl>
 110.243 +     * <dt><i>DecodableString:</i>
 110.244 +     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 110.245 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 110.246 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 110.247 +     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 110.248 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 110.249 +     * <p>
 110.250 +     * <dt><i>Sign:</i>
 110.251 +     * <dd>{@code -}
 110.252 +     * <dd>{@code +}
 110.253 +     * </dl>
 110.254 +     * </blockquote>
 110.255 +     *
 110.256 +     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 110.257 +     * are as defined in section 3.10.1 of
 110.258 +     * <cite>The Java&trade; Language Specification</cite>,
 110.259 +     * except that underscores are not accepted between digits.
 110.260 +     *
 110.261 +     * <p>The sequence of characters following an optional
 110.262 +     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 110.263 +     * "{@code #}", or leading zero) is parsed as by the {@code
 110.264 +     * Byte.parseByte} method with the indicated radix (10, 16, or 8).
 110.265 +     * This sequence of characters must represent a positive value or
 110.266 +     * a {@link NumberFormatException} will be thrown.  The result is
 110.267 +     * negated if first character of the specified {@code String} is
 110.268 +     * the minus sign.  No whitespace characters are permitted in the
 110.269 +     * {@code String}.
 110.270 +     *
 110.271 +     * @param     nm the {@code String} to decode.
 110.272 +     * @return   a {@code Byte} object holding the {@code byte}
 110.273 +     *          value represented by {@code nm}
 110.274 +     * @throws  NumberFormatException  if the {@code String} does not
 110.275 +     *            contain a parsable {@code byte}.
 110.276 +     * @see java.lang.Byte#parseByte(java.lang.String, int)
 110.277 +     */
 110.278 +    public static Byte decode(String nm) throws NumberFormatException {
 110.279 +        int i = Integer.decode(nm);
 110.280 +        if (i < MIN_VALUE || i > MAX_VALUE)
 110.281 +            throw new NumberFormatException(
 110.282 +                    "Value " + i + " out of range from input " + nm);
 110.283 +        return valueOf((byte)i);
 110.284 +    }
 110.285 +
 110.286 +    /**
 110.287 +     * The value of the {@code Byte}.
 110.288 +     *
 110.289 +     * @serial
 110.290 +     */
 110.291 +    private final byte value;
 110.292 +
 110.293 +    /**
 110.294 +     * Constructs a newly allocated {@code Byte} object that
 110.295 +     * represents the specified {@code byte} value.
 110.296 +     *
 110.297 +     * @param value     the value to be represented by the
 110.298 +     *                  {@code Byte}.
 110.299 +     */
 110.300 +    public Byte(byte value) {
 110.301 +        this.value = value;
 110.302 +    }
 110.303 +
 110.304 +    /**
 110.305 +     * Constructs a newly allocated {@code Byte} object that
 110.306 +     * represents the {@code byte} value indicated by the
 110.307 +     * {@code String} parameter. The string is converted to a
 110.308 +     * {@code byte} value in exactly the manner used by the
 110.309 +     * {@code parseByte} method for radix 10.
 110.310 +     *
 110.311 +     * @param s         the {@code String} to be converted to a
 110.312 +     *                  {@code Byte}
 110.313 +     * @throws           NumberFormatException If the {@code String}
 110.314 +     *                  does not contain a parsable {@code byte}.
 110.315 +     * @see        java.lang.Byte#parseByte(java.lang.String, int)
 110.316 +     */
 110.317 +    public Byte(String s) throws NumberFormatException {
 110.318 +        this.value = parseByte(s, 10);
 110.319 +    }
 110.320 +
 110.321 +    /**
 110.322 +     * Returns the value of this {@code Byte} as a
 110.323 +     * {@code byte}.
 110.324 +     */
 110.325 +    public byte byteValue() {
 110.326 +        return value;
 110.327 +    }
 110.328 +
 110.329 +    /**
 110.330 +     * Returns the value of this {@code Byte} as a
 110.331 +     * {@code short}.
 110.332 +     */
 110.333 +    public short shortValue() {
 110.334 +        return (short)value;
 110.335 +    }
 110.336 +
 110.337 +    /**
 110.338 +     * Returns the value of this {@code Byte} as an
 110.339 +     * {@code int}.
 110.340 +     */
 110.341 +    public int intValue() {
 110.342 +        return (int)value;
 110.343 +    }
 110.344 +
 110.345 +    /**
 110.346 +     * Returns the value of this {@code Byte} as a
 110.347 +     * {@code long}.
 110.348 +     */
 110.349 +    public long longValue() {
 110.350 +        return (long)value;
 110.351 +    }
 110.352 +
 110.353 +    /**
 110.354 +     * Returns the value of this {@code Byte} as a
 110.355 +     * {@code float}.
 110.356 +     */
 110.357 +    public float floatValue() {
 110.358 +        return (float)value;
 110.359 +    }
 110.360 +
 110.361 +    /**
 110.362 +     * Returns the value of this {@code Byte} as a
 110.363 +     * {@code double}.
 110.364 +     */
 110.365 +    public double doubleValue() {
 110.366 +        return (double)value;
 110.367 +    }
 110.368 +
 110.369 +    /**
 110.370 +     * Returns a {@code String} object representing this
 110.371 +     * {@code Byte}'s value.  The value is converted to signed
 110.372 +     * decimal representation and returned as a string, exactly as if
 110.373 +     * the {@code byte} value were given as an argument to the
 110.374 +     * {@link java.lang.Byte#toString(byte)} method.
 110.375 +     *
 110.376 +     * @return  a string representation of the value of this object in
 110.377 +     *          base&nbsp;10.
 110.378 +     */
 110.379 +    public String toString() {
 110.380 +        return Integer.toString((int)value);
 110.381 +    }
 110.382 +
 110.383 +    /**
 110.384 +     * Returns a hash code for this {@code Byte}; equal to the result
 110.385 +     * of invoking {@code intValue()}.
 110.386 +     *
 110.387 +     * @return a hash code value for this {@code Byte}
 110.388 +     */
 110.389 +    public int hashCode() {
 110.390 +        return (int)value;
 110.391 +    }
 110.392 +
 110.393 +    /**
 110.394 +     * Compares this object to the specified object.  The result is
 110.395 +     * {@code true} if and only if the argument is not
 110.396 +     * {@code null} and is a {@code Byte} object that
 110.397 +     * contains the same {@code byte} value as this object.
 110.398 +     *
 110.399 +     * @param obj       the object to compare with
 110.400 +     * @return          {@code true} if the objects are the same;
 110.401 +     *                  {@code false} otherwise.
 110.402 +     */
 110.403 +    public boolean equals(Object obj) {
 110.404 +        if (obj instanceof Byte) {
 110.405 +            return value == ((Byte)obj).byteValue();
 110.406 +        }
 110.407 +        return false;
 110.408 +    }
 110.409 +
 110.410 +    /**
 110.411 +     * Compares two {@code Byte} objects numerically.
 110.412 +     *
 110.413 +     * @param   anotherByte   the {@code Byte} to be compared.
 110.414 +     * @return  the value {@code 0} if this {@code Byte} is
 110.415 +     *          equal to the argument {@code Byte}; a value less than
 110.416 +     *          {@code 0} if this {@code Byte} is numerically less
 110.417 +     *          than the argument {@code Byte}; and a value greater than
 110.418 +     *           {@code 0} if this {@code Byte} is numerically
 110.419 +     *           greater than the argument {@code Byte} (signed
 110.420 +     *           comparison).
 110.421 +     * @since   1.2
 110.422 +     */
 110.423 +    public int compareTo(Byte anotherByte) {
 110.424 +        return compare(this.value, anotherByte.value);
 110.425 +    }
 110.426 +
 110.427 +    /**
 110.428 +     * Compares two {@code byte} values numerically.
 110.429 +     * The value returned is identical to what would be returned by:
 110.430 +     * <pre>
 110.431 +     *    Byte.valueOf(x).compareTo(Byte.valueOf(y))
 110.432 +     * </pre>
 110.433 +     *
 110.434 +     * @param  x the first {@code byte} to compare
 110.435 +     * @param  y the second {@code byte} to compare
 110.436 +     * @return the value {@code 0} if {@code x == y};
 110.437 +     *         a value less than {@code 0} if {@code x < y}; and
 110.438 +     *         a value greater than {@code 0} if {@code x > y}
 110.439 +     * @since 1.7
 110.440 +     */
 110.441 +    public static int compare(byte x, byte y) {
 110.442 +        return x - y;
 110.443 +    }
 110.444 +
 110.445 +    /**
 110.446 +     * The number of bits used to represent a {@code byte} value in two's
 110.447 +     * complement binary form.
 110.448 +     *
 110.449 +     * @since 1.5
 110.450 +     */
 110.451 +    public static final int SIZE = 8;
 110.452 +
 110.453 +    /** use serialVersionUID from JDK 1.1. for interoperability */
 110.454 +    private static final long serialVersionUID = -7183698231559129828L;
 110.455 +}
   111.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   111.2 +++ b/emul/mini/src/main/java/java/lang/CharSequence.java	Sun Feb 03 07:48:42 2013 +0100
   111.3 @@ -0,0 +1,111 @@
   111.4 +/*
   111.5 + * Copyright (c) 2000, 2003, 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 +/**
  111.33 + * A <tt>CharSequence</tt> is a readable sequence of <code>char</code> values. This
  111.34 + * interface provides uniform, read-only access to many different kinds of
  111.35 + * <code>char</code> sequences.
  111.36 + * A <code>char</code> value represents a character in the <i>Basic
  111.37 + * Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
  111.38 + * href="Character.html#unicode">Unicode Character Representation</a> for details.
  111.39 + *
  111.40 + * <p> This interface does not refine the general contracts of the {@link
  111.41 + * java.lang.Object#equals(java.lang.Object) equals} and {@link
  111.42 + * java.lang.Object#hashCode() hashCode} methods.  The result of comparing two
  111.43 + * objects that implement <tt>CharSequence</tt> is therefore, in general,
  111.44 + * undefined.  Each object may be implemented by a different class, and there
  111.45 + * is no guarantee that each class will be capable of testing its instances
  111.46 + * for equality with those of the other.  It is therefore inappropriate to use
  111.47 + * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in
  111.48 + * a map. </p>
  111.49 + *
  111.50 + * @author Mike McCloskey
  111.51 + * @since 1.4
  111.52 + * @spec JSR-51
  111.53 + */
  111.54 +
  111.55 +public interface CharSequence {
  111.56 +
  111.57 +    /**
  111.58 +     * Returns the length of this character sequence.  The length is the number
  111.59 +     * of 16-bit <code>char</code>s in the sequence.</p>
  111.60 +     *
  111.61 +     * @return  the number of <code>char</code>s in this sequence
  111.62 +     */
  111.63 +    int length();
  111.64 +
  111.65 +    /**
  111.66 +     * Returns the <code>char</code> value at the specified index.  An index ranges from zero
  111.67 +     * to <tt>length() - 1</tt>.  The first <code>char</code> value of the sequence is at
  111.68 +     * index zero, the next at index one, and so on, as for array
  111.69 +     * indexing. </p>
  111.70 +     *
  111.71 +     * <p>If the <code>char</code> value specified by the index is a
  111.72 +     * <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
  111.73 +     * value is returned.
  111.74 +     *
  111.75 +     * @param   index   the index of the <code>char</code> value to be returned
  111.76 +     *
  111.77 +     * @return  the specified <code>char</code> value
  111.78 +     *
  111.79 +     * @throws  IndexOutOfBoundsException
  111.80 +     *          if the <tt>index</tt> argument is negative or not less than
  111.81 +     *          <tt>length()</tt>
  111.82 +     */
  111.83 +    char charAt(int index);
  111.84 +
  111.85 +    /**
  111.86 +     * Returns a new <code>CharSequence</code> that is a subsequence of this sequence.
  111.87 +     * The subsequence starts with the <code>char</code> value at the specified index and
  111.88 +     * ends with the <code>char</code> value at index <tt>end - 1</tt>.  The length
  111.89 +     * (in <code>char</code>s) of the
  111.90 +     * returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
  111.91 +     * then an empty sequence is returned. </p>
  111.92 +     *
  111.93 +     * @param   start   the start index, inclusive
  111.94 +     * @param   end     the end index, exclusive
  111.95 +     *
  111.96 +     * @return  the specified subsequence
  111.97 +     *
  111.98 +     * @throws  IndexOutOfBoundsException
  111.99 +     *          if <tt>start</tt> or <tt>end</tt> are negative,
 111.100 +     *          if <tt>end</tt> is greater than <tt>length()</tt>,
 111.101 +     *          or if <tt>start</tt> is greater than <tt>end</tt>
 111.102 +     */
 111.103 +    CharSequence subSequence(int start, int end);
 111.104 +
 111.105 +    /**
 111.106 +     * Returns a string containing the characters in this sequence in the same
 111.107 +     * order as this sequence.  The length of the string will be the length of
 111.108 +     * this sequence. </p>
 111.109 +     *
 111.110 +     * @return  a string consisting of exactly this sequence of characters
 111.111 +     */
 111.112 +    public String toString();
 111.113 +
 111.114 +}
   112.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   112.2 +++ b/emul/mini/src/main/java/java/lang/Character.java	Sun Feb 03 07:48:42 2013 +0100
   112.3 @@ -0,0 +1,2515 @@
   112.4 +/*
   112.5 + * Copyright (c) 2002, 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 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  112.32 +
  112.33 +/**
  112.34 + * The {@code Character} class wraps a value of the primitive
  112.35 + * type {@code char} in an object. An object of type
  112.36 + * {@code Character} contains a single field whose type is
  112.37 + * {@code char}.
  112.38 + * <p>
  112.39 + * In addition, this class provides several methods for determining
  112.40 + * a character's category (lowercase letter, digit, etc.) and for converting
  112.41 + * characters from uppercase to lowercase and vice versa.
  112.42 + * <p>
  112.43 + * Character information is based on the Unicode Standard, version 6.0.0.
  112.44 + * <p>
  112.45 + * The methods and data of class {@code Character} are defined by
  112.46 + * the information in the <i>UnicodeData</i> file that is part of the
  112.47 + * Unicode Character Database maintained by the Unicode
  112.48 + * Consortium. This file specifies various properties including name
  112.49 + * and general category for every defined Unicode code point or
  112.50 + * character range.
  112.51 + * <p>
  112.52 + * The file and its description are available from the Unicode Consortium at:
  112.53 + * <ul>
  112.54 + * <li><a href="http://www.unicode.org">http://www.unicode.org</a>
  112.55 + * </ul>
  112.56 + *
  112.57 + * <h4><a name="unicode">Unicode Character Representations</a></h4>
  112.58 + *
  112.59 + * <p>The {@code char} data type (and therefore the value that a
  112.60 + * {@code Character} object encapsulates) are based on the
  112.61 + * original Unicode specification, which defined characters as
  112.62 + * fixed-width 16-bit entities. The Unicode Standard has since been
  112.63 + * changed to allow for characters whose representation requires more
  112.64 + * than 16 bits.  The range of legal <em>code point</em>s is now
  112.65 + * U+0000 to U+10FFFF, known as <em>Unicode scalar value</em>.
  112.66 + * (Refer to the <a
  112.67 + * href="http://www.unicode.org/reports/tr27/#notation"><i>
  112.68 + * definition</i></a> of the U+<i>n</i> notation in the Unicode
  112.69 + * Standard.)
  112.70 + *
  112.71 + * <p><a name="BMP">The set of characters from U+0000 to U+FFFF is
  112.72 + * sometimes referred to as the <em>Basic Multilingual Plane (BMP)</em>.
  112.73 + * <a name="supplementary">Characters</a> whose code points are greater
  112.74 + * than U+FFFF are called <em>supplementary character</em>s.  The Java
  112.75 + * platform uses the UTF-16 representation in {@code char} arrays and
  112.76 + * in the {@code String} and {@code StringBuffer} classes. In
  112.77 + * this representation, supplementary characters are represented as a pair
  112.78 + * of {@code char} values, the first from the <em>high-surrogates</em>
  112.79 + * range, (&#92;uD800-&#92;uDBFF), the second from the
  112.80 + * <em>low-surrogates</em> range (&#92;uDC00-&#92;uDFFF).
  112.81 + *
  112.82 + * <p>A {@code char} value, therefore, represents Basic
  112.83 + * Multilingual Plane (BMP) code points, including the surrogate
  112.84 + * code points, or code units of the UTF-16 encoding. An
  112.85 + * {@code int} value represents all Unicode code points,
  112.86 + * including supplementary code points. The lower (least significant)
  112.87 + * 21 bits of {@code int} are used to represent Unicode code
  112.88 + * points and the upper (most significant) 11 bits must be zero.
  112.89 + * Unless otherwise specified, the behavior with respect to
  112.90 + * supplementary characters and surrogate {@code char} values is
  112.91 + * as follows:
  112.92 + *
  112.93 + * <ul>
  112.94 + * <li>The methods that only accept a {@code char} value cannot support
  112.95 + * supplementary characters. They treat {@code char} values from the
  112.96 + * surrogate ranges as undefined characters. For example,
  112.97 + * {@code Character.isLetter('\u005CuD840')} returns {@code false}, even though
  112.98 + * this specific value if followed by any low-surrogate value in a string
  112.99 + * would represent a letter.
 112.100 + *
 112.101 + * <li>The methods that accept an {@code int} value support all
 112.102 + * Unicode characters, including supplementary characters. For
 112.103 + * example, {@code Character.isLetter(0x2F81A)} returns
 112.104 + * {@code true} because the code point value represents a letter
 112.105 + * (a CJK ideograph).
 112.106 + * </ul>
 112.107 + *
 112.108 + * <p>In the Java SE API documentation, <em>Unicode code point</em> is
 112.109 + * used for character values in the range between U+0000 and U+10FFFF,
 112.110 + * and <em>Unicode code unit</em> is used for 16-bit
 112.111 + * {@code char} values that are code units of the <em>UTF-16</em>
 112.112 + * encoding. For more information on Unicode terminology, refer to the
 112.113 + * <a href="http://www.unicode.org/glossary/">Unicode Glossary</a>.
 112.114 + *
 112.115 + * @author  Lee Boynton
 112.116 + * @author  Guy Steele
 112.117 + * @author  Akira Tanaka
 112.118 + * @author  Martin Buchholz
 112.119 + * @author  Ulf Zibis
 112.120 + * @since   1.0
 112.121 + */
 112.122 +public final
 112.123 +class Character implements java.io.Serializable, Comparable<Character> {
 112.124 +    /**
 112.125 +     * The minimum radix available for conversion to and from strings.
 112.126 +     * The constant value of this field is the smallest value permitted
 112.127 +     * for the radix argument in radix-conversion methods such as the
 112.128 +     * {@code digit} method, the {@code forDigit} method, and the
 112.129 +     * {@code toString} method of class {@code Integer}.
 112.130 +     *
 112.131 +     * @see     Character#digit(char, int)
 112.132 +     * @see     Character#forDigit(int, int)
 112.133 +     * @see     Integer#toString(int, int)
 112.134 +     * @see     Integer#valueOf(String)
 112.135 +     */
 112.136 +    public static final int MIN_RADIX = 2;
 112.137 +
 112.138 +    /**
 112.139 +     * The maximum radix available for conversion to and from strings.
 112.140 +     * The constant value of this field is the largest value permitted
 112.141 +     * for the radix argument in radix-conversion methods such as the
 112.142 +     * {@code digit} method, the {@code forDigit} method, and the
 112.143 +     * {@code toString} method of class {@code Integer}.
 112.144 +     *
 112.145 +     * @see     Character#digit(char, int)
 112.146 +     * @see     Character#forDigit(int, int)
 112.147 +     * @see     Integer#toString(int, int)
 112.148 +     * @see     Integer#valueOf(String)
 112.149 +     */
 112.150 +    public static final int MAX_RADIX = 36;
 112.151 +
 112.152 +    /**
 112.153 +     * The constant value of this field is the smallest value of type
 112.154 +     * {@code char}, {@code '\u005Cu0000'}.
 112.155 +     *
 112.156 +     * @since   1.0.2
 112.157 +     */
 112.158 +    public static final char MIN_VALUE = '\u0000';
 112.159 +
 112.160 +    /**
 112.161 +     * The constant value of this field is the largest value of type
 112.162 +     * {@code char}, {@code '\u005CuFFFF'}.
 112.163 +     *
 112.164 +     * @since   1.0.2
 112.165 +     */
 112.166 +    public static final char MAX_VALUE = '\uFFFF';
 112.167 +
 112.168 +    /**
 112.169 +     * The {@code Class} instance representing the primitive type
 112.170 +     * {@code char}.
 112.171 +     *
 112.172 +     * @since   1.1
 112.173 +     */
 112.174 +    public static final Class<Character> TYPE = Class.getPrimitiveClass("char");
 112.175 +
 112.176 +    /*
 112.177 +     * Normative general types
 112.178 +     */
 112.179 +
 112.180 +    /*
 112.181 +     * General character types
 112.182 +     */
 112.183 +
 112.184 +    /**
 112.185 +     * General category "Cn" in the Unicode specification.
 112.186 +     * @since   1.1
 112.187 +     */
 112.188 +    public static final byte UNASSIGNED = 0;
 112.189 +
 112.190 +    /**
 112.191 +     * General category "Lu" in the Unicode specification.
 112.192 +     * @since   1.1
 112.193 +     */
 112.194 +    public static final byte UPPERCASE_LETTER = 1;
 112.195 +
 112.196 +    /**
 112.197 +     * General category "Ll" in the Unicode specification.
 112.198 +     * @since   1.1
 112.199 +     */
 112.200 +    public static final byte LOWERCASE_LETTER = 2;
 112.201 +
 112.202 +    /**
 112.203 +     * General category "Lt" in the Unicode specification.
 112.204 +     * @since   1.1
 112.205 +     */
 112.206 +    public static final byte TITLECASE_LETTER = 3;
 112.207 +
 112.208 +    /**
 112.209 +     * General category "Lm" in the Unicode specification.
 112.210 +     * @since   1.1
 112.211 +     */
 112.212 +    public static final byte MODIFIER_LETTER = 4;
 112.213 +
 112.214 +    /**
 112.215 +     * General category "Lo" in the Unicode specification.
 112.216 +     * @since   1.1
 112.217 +     */
 112.218 +    public static final byte OTHER_LETTER = 5;
 112.219 +
 112.220 +    /**
 112.221 +     * General category "Mn" in the Unicode specification.
 112.222 +     * @since   1.1
 112.223 +     */
 112.224 +    public static final byte NON_SPACING_MARK = 6;
 112.225 +
 112.226 +    /**
 112.227 +     * General category "Me" in the Unicode specification.
 112.228 +     * @since   1.1
 112.229 +     */
 112.230 +    public static final byte ENCLOSING_MARK = 7;
 112.231 +
 112.232 +    /**
 112.233 +     * General category "Mc" in the Unicode specification.
 112.234 +     * @since   1.1
 112.235 +     */
 112.236 +    public static final byte COMBINING_SPACING_MARK = 8;
 112.237 +
 112.238 +    /**
 112.239 +     * General category "Nd" in the Unicode specification.
 112.240 +     * @since   1.1
 112.241 +     */
 112.242 +    public static final byte DECIMAL_DIGIT_NUMBER        = 9;
 112.243 +
 112.244 +    /**
 112.245 +     * General category "Nl" in the Unicode specification.
 112.246 +     * @since   1.1
 112.247 +     */
 112.248 +    public static final byte LETTER_NUMBER = 10;
 112.249 +
 112.250 +    /**
 112.251 +     * General category "No" in the Unicode specification.
 112.252 +     * @since   1.1
 112.253 +     */
 112.254 +    public static final byte OTHER_NUMBER = 11;
 112.255 +
 112.256 +    /**
 112.257 +     * General category "Zs" in the Unicode specification.
 112.258 +     * @since   1.1
 112.259 +     */
 112.260 +    public static final byte SPACE_SEPARATOR = 12;
 112.261 +
 112.262 +    /**
 112.263 +     * General category "Zl" in the Unicode specification.
 112.264 +     * @since   1.1
 112.265 +     */
 112.266 +    public static final byte LINE_SEPARATOR = 13;
 112.267 +
 112.268 +    /**
 112.269 +     * General category "Zp" in the Unicode specification.
 112.270 +     * @since   1.1
 112.271 +     */
 112.272 +    public static final byte PARAGRAPH_SEPARATOR = 14;
 112.273 +
 112.274 +    /**
 112.275 +     * General category "Cc" in the Unicode specification.
 112.276 +     * @since   1.1
 112.277 +     */
 112.278 +    public static final byte CONTROL = 15;
 112.279 +
 112.280 +    /**
 112.281 +     * General category "Cf" in the Unicode specification.
 112.282 +     * @since   1.1
 112.283 +     */
 112.284 +    public static final byte FORMAT = 16;
 112.285 +
 112.286 +    /**
 112.287 +     * General category "Co" in the Unicode specification.
 112.288 +     * @since   1.1
 112.289 +     */
 112.290 +    public static final byte PRIVATE_USE = 18;
 112.291 +
 112.292 +    /**
 112.293 +     * General category "Cs" in the Unicode specification.
 112.294 +     * @since   1.1
 112.295 +     */
 112.296 +    public static final byte SURROGATE = 19;
 112.297 +
 112.298 +    /**
 112.299 +     * General category "Pd" in the Unicode specification.
 112.300 +     * @since   1.1
 112.301 +     */
 112.302 +    public static final byte DASH_PUNCTUATION = 20;
 112.303 +
 112.304 +    /**
 112.305 +     * General category "Ps" in the Unicode specification.
 112.306 +     * @since   1.1
 112.307 +     */
 112.308 +    public static final byte START_PUNCTUATION = 21;
 112.309 +
 112.310 +    /**
 112.311 +     * General category "Pe" in the Unicode specification.
 112.312 +     * @since   1.1
 112.313 +     */
 112.314 +    public static final byte END_PUNCTUATION = 22;
 112.315 +
 112.316 +    /**
 112.317 +     * General category "Pc" in the Unicode specification.
 112.318 +     * @since   1.1
 112.319 +     */
 112.320 +    public static final byte CONNECTOR_PUNCTUATION = 23;
 112.321 +
 112.322 +    /**
 112.323 +     * General category "Po" in the Unicode specification.
 112.324 +     * @since   1.1
 112.325 +     */
 112.326 +    public static final byte OTHER_PUNCTUATION = 24;
 112.327 +
 112.328 +    /**
 112.329 +     * General category "Sm" in the Unicode specification.
 112.330 +     * @since   1.1
 112.331 +     */
 112.332 +    public static final byte MATH_SYMBOL = 25;
 112.333 +
 112.334 +    /**
 112.335 +     * General category "Sc" in the Unicode specification.
 112.336 +     * @since   1.1
 112.337 +     */
 112.338 +    public static final byte CURRENCY_SYMBOL = 26;
 112.339 +
 112.340 +    /**
 112.341 +     * General category "Sk" in the Unicode specification.
 112.342 +     * @since   1.1
 112.343 +     */
 112.344 +    public static final byte MODIFIER_SYMBOL = 27;
 112.345 +
 112.346 +    /**
 112.347 +     * General category "So" in the Unicode specification.
 112.348 +     * @since   1.1
 112.349 +     */
 112.350 +    public static final byte OTHER_SYMBOL = 28;
 112.351 +
 112.352 +    /**
 112.353 +     * General category "Pi" in the Unicode specification.
 112.354 +     * @since   1.4
 112.355 +     */
 112.356 +    public static final byte INITIAL_QUOTE_PUNCTUATION = 29;
 112.357 +
 112.358 +    /**
 112.359 +     * General category "Pf" in the Unicode specification.
 112.360 +     * @since   1.4
 112.361 +     */
 112.362 +    public static final byte FINAL_QUOTE_PUNCTUATION = 30;
 112.363 +
 112.364 +    /**
 112.365 +     * Error flag. Use int (code point) to avoid confusion with U+FFFF.
 112.366 +     */
 112.367 +    static final int ERROR = 0xFFFFFFFF;
 112.368 +
 112.369 +
 112.370 +    /**
 112.371 +     * Undefined bidirectional character type. Undefined {@code char}
 112.372 +     * values have undefined directionality in the Unicode specification.
 112.373 +     * @since 1.4
 112.374 +     */
 112.375 +    public static final byte DIRECTIONALITY_UNDEFINED = -1;
 112.376 +
 112.377 +    /**
 112.378 +     * Strong bidirectional character type "L" in the Unicode specification.
 112.379 +     * @since 1.4
 112.380 +     */
 112.381 +    public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = 0;
 112.382 +
 112.383 +    /**
 112.384 +     * Strong bidirectional character type "R" in the Unicode specification.
 112.385 +     * @since 1.4
 112.386 +     */
 112.387 +    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = 1;
 112.388 +
 112.389 +    /**
 112.390 +    * Strong bidirectional character type "AL" in the Unicode specification.
 112.391 +     * @since 1.4
 112.392 +     */
 112.393 +    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = 2;
 112.394 +
 112.395 +    /**
 112.396 +     * Weak bidirectional character type "EN" in the Unicode specification.
 112.397 +     * @since 1.4
 112.398 +     */
 112.399 +    public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = 3;
 112.400 +
 112.401 +    /**
 112.402 +     * Weak bidirectional character type "ES" in the Unicode specification.
 112.403 +     * @since 1.4
 112.404 +     */
 112.405 +    public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = 4;
 112.406 +
 112.407 +    /**
 112.408 +     * Weak bidirectional character type "ET" in the Unicode specification.
 112.409 +     * @since 1.4
 112.410 +     */
 112.411 +    public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = 5;
 112.412 +
 112.413 +    /**
 112.414 +     * Weak bidirectional character type "AN" in the Unicode specification.
 112.415 +     * @since 1.4
 112.416 +     */
 112.417 +    public static final byte DIRECTIONALITY_ARABIC_NUMBER = 6;
 112.418 +
 112.419 +    /**
 112.420 +     * Weak bidirectional character type "CS" in the Unicode specification.
 112.421 +     * @since 1.4
 112.422 +     */
 112.423 +    public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = 7;
 112.424 +
 112.425 +    /**
 112.426 +     * Weak bidirectional character type "NSM" in the Unicode specification.
 112.427 +     * @since 1.4
 112.428 +     */
 112.429 +    public static final byte DIRECTIONALITY_NONSPACING_MARK = 8;
 112.430 +
 112.431 +    /**
 112.432 +     * Weak bidirectional character type "BN" in the Unicode specification.
 112.433 +     * @since 1.4
 112.434 +     */
 112.435 +    public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = 9;
 112.436 +
 112.437 +    /**
 112.438 +     * Neutral bidirectional character type "B" in the Unicode specification.
 112.439 +     * @since 1.4
 112.440 +     */
 112.441 +    public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = 10;
 112.442 +
 112.443 +    /**
 112.444 +     * Neutral bidirectional character type "S" in the Unicode specification.
 112.445 +     * @since 1.4
 112.446 +     */
 112.447 +    public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = 11;
 112.448 +
 112.449 +    /**
 112.450 +     * Neutral bidirectional character type "WS" in the Unicode specification.
 112.451 +     * @since 1.4
 112.452 +     */
 112.453 +    public static final byte DIRECTIONALITY_WHITESPACE = 12;
 112.454 +
 112.455 +    /**
 112.456 +     * Neutral bidirectional character type "ON" in the Unicode specification.
 112.457 +     * @since 1.4
 112.458 +     */
 112.459 +    public static final byte DIRECTIONALITY_OTHER_NEUTRALS = 13;
 112.460 +
 112.461 +    /**
 112.462 +     * Strong bidirectional character type "LRE" in the Unicode specification.
 112.463 +     * @since 1.4
 112.464 +     */
 112.465 +    public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = 14;
 112.466 +
 112.467 +    /**
 112.468 +     * Strong bidirectional character type "LRO" in the Unicode specification.
 112.469 +     * @since 1.4
 112.470 +     */
 112.471 +    public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = 15;
 112.472 +
 112.473 +    /**
 112.474 +     * Strong bidirectional character type "RLE" in the Unicode specification.
 112.475 +     * @since 1.4
 112.476 +     */
 112.477 +    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = 16;
 112.478 +
 112.479 +    /**
 112.480 +     * Strong bidirectional character type "RLO" in the Unicode specification.
 112.481 +     * @since 1.4
 112.482 +     */
 112.483 +    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = 17;
 112.484 +
 112.485 +    /**
 112.486 +     * Weak bidirectional character type "PDF" in the Unicode specification.
 112.487 +     * @since 1.4
 112.488 +     */
 112.489 +    public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18;
 112.490 +
 112.491 +    /**
 112.492 +     * The minimum value of a
 112.493 +     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 112.494 +     * Unicode high-surrogate code unit</a>
 112.495 +     * in the UTF-16 encoding, constant {@code '\u005CuD800'}.
 112.496 +     * A high-surrogate is also known as a <i>leading-surrogate</i>.
 112.497 +     *
 112.498 +     * @since 1.5
 112.499 +     */
 112.500 +    public static final char MIN_HIGH_SURROGATE = '\uD800';
 112.501 +
 112.502 +    /**
 112.503 +     * The maximum value of a
 112.504 +     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 112.505 +     * Unicode high-surrogate code unit</a>
 112.506 +     * in the UTF-16 encoding, constant {@code '\u005CuDBFF'}.
 112.507 +     * A high-surrogate is also known as a <i>leading-surrogate</i>.
 112.508 +     *
 112.509 +     * @since 1.5
 112.510 +     */
 112.511 +    public static final char MAX_HIGH_SURROGATE = '\uDBFF';
 112.512 +
 112.513 +    /**
 112.514 +     * The minimum value of a
 112.515 +     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
 112.516 +     * Unicode low-surrogate code unit</a>
 112.517 +     * in the UTF-16 encoding, constant {@code '\u005CuDC00'}.
 112.518 +     * A low-surrogate is also known as a <i>trailing-surrogate</i>.
 112.519 +     *
 112.520 +     * @since 1.5
 112.521 +     */
 112.522 +    public static final char MIN_LOW_SURROGATE  = '\uDC00';
 112.523 +
 112.524 +    /**
 112.525 +     * The maximum value of a
 112.526 +     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
 112.527 +     * Unicode low-surrogate code unit</a>
 112.528 +     * in the UTF-16 encoding, constant {@code '\u005CuDFFF'}.
 112.529 +     * A low-surrogate is also known as a <i>trailing-surrogate</i>.
 112.530 +     *
 112.531 +     * @since 1.5
 112.532 +     */
 112.533 +    public static final char MAX_LOW_SURROGATE  = '\uDFFF';
 112.534 +
 112.535 +    /**
 112.536 +     * The minimum value of a Unicode surrogate code unit in the
 112.537 +     * UTF-16 encoding, constant {@code '\u005CuD800'}.
 112.538 +     *
 112.539 +     * @since 1.5
 112.540 +     */
 112.541 +    public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE;
 112.542 +
 112.543 +    /**
 112.544 +     * The maximum value of a Unicode surrogate code unit in the
 112.545 +     * UTF-16 encoding, constant {@code '\u005CuDFFF'}.
 112.546 +     *
 112.547 +     * @since 1.5
 112.548 +     */
 112.549 +    public static final char MAX_SURROGATE = MAX_LOW_SURROGATE;
 112.550 +
 112.551 +    /**
 112.552 +     * The minimum value of a
 112.553 +     * <a href="http://www.unicode.org/glossary/#supplementary_code_point">
 112.554 +     * Unicode supplementary code point</a>, constant {@code U+10000}.
 112.555 +     *
 112.556 +     * @since 1.5
 112.557 +     */
 112.558 +    public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000;
 112.559 +
 112.560 +    /**
 112.561 +     * The minimum value of a
 112.562 +     * <a href="http://www.unicode.org/glossary/#code_point">
 112.563 +     * Unicode code point</a>, constant {@code U+0000}.
 112.564 +     *
 112.565 +     * @since 1.5
 112.566 +     */
 112.567 +    public static final int MIN_CODE_POINT = 0x000000;
 112.568 +
 112.569 +    /**
 112.570 +     * The maximum value of a
 112.571 +     * <a href="http://www.unicode.org/glossary/#code_point">
 112.572 +     * Unicode code point</a>, constant {@code U+10FFFF}.
 112.573 +     *
 112.574 +     * @since 1.5
 112.575 +     */
 112.576 +    public static final int MAX_CODE_POINT = 0X10FFFF;
 112.577 +
 112.578 +
 112.579 +    /**
 112.580 +     * Instances of this class represent particular subsets of the Unicode
 112.581 +     * character set.  The only family of subsets defined in the
 112.582 +     * {@code Character} class is {@link Character.UnicodeBlock}.
 112.583 +     * Other portions of the Java API may define other subsets for their
 112.584 +     * own purposes.
 112.585 +     *
 112.586 +     * @since 1.2
 112.587 +     */
 112.588 +    public static class Subset  {
 112.589 +
 112.590 +        private String name;
 112.591 +
 112.592 +        /**
 112.593 +         * Constructs a new {@code Subset} instance.
 112.594 +         *
 112.595 +         * @param  name  The name of this subset
 112.596 +         * @exception NullPointerException if name is {@code null}
 112.597 +         */
 112.598 +        protected Subset(String name) {
 112.599 +            if (name == null) {
 112.600 +                throw new NullPointerException("name");
 112.601 +            }
 112.602 +            this.name = name;
 112.603 +        }
 112.604 +
 112.605 +        /**
 112.606 +         * Compares two {@code Subset} objects for equality.
 112.607 +         * This method returns {@code true} if and only if
 112.608 +         * {@code this} and the argument refer to the same
 112.609 +         * object; since this method is {@code final}, this
 112.610 +         * guarantee holds for all subclasses.
 112.611 +         */
 112.612 +        public final boolean equals(Object obj) {
 112.613 +            return (this == obj);
 112.614 +        }
 112.615 +
 112.616 +        /**
 112.617 +         * Returns the standard hash code as defined by the
 112.618 +         * {@link Object#hashCode} method.  This method
 112.619 +         * is {@code final} in order to ensure that the
 112.620 +         * {@code equals} and {@code hashCode} methods will
 112.621 +         * be consistent in all subclasses.
 112.622 +         */
 112.623 +        public final int hashCode() {
 112.624 +            return super.hashCode();
 112.625 +        }
 112.626 +
 112.627 +        /**
 112.628 +         * Returns the name of this subset.
 112.629 +         */
 112.630 +        public final String toString() {
 112.631 +            return name;
 112.632 +        }
 112.633 +    }
 112.634 +
 112.635 +    // See http://www.unicode.org/Public/UNIDATA/Blocks.txt
 112.636 +    // for the latest specification of Unicode Blocks.
 112.637 +
 112.638 +
 112.639 +    /**
 112.640 +     * The value of the {@code Character}.
 112.641 +     *
 112.642 +     * @serial
 112.643 +     */
 112.644 +    private final char value;
 112.645 +
 112.646 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 112.647 +    private static final long serialVersionUID = 3786198910865385080L;
 112.648 +
 112.649 +    /**
 112.650 +     * Constructs a newly allocated {@code Character} object that
 112.651 +     * represents the specified {@code char} value.
 112.652 +     *
 112.653 +     * @param  value   the value to be represented by the
 112.654 +     *                  {@code Character} object.
 112.655 +     */
 112.656 +    public Character(char value) {
 112.657 +        this.value = value;
 112.658 +    }
 112.659 +
 112.660 +    private static class CharacterCache {
 112.661 +        private CharacterCache(){}
 112.662 +
 112.663 +        static final Character cache[] = new Character[127 + 1];
 112.664 +
 112.665 +        static {
 112.666 +            for (int i = 0; i < cache.length; i++)
 112.667 +                cache[i] = new Character((char)i);
 112.668 +        }
 112.669 +    }
 112.670 +
 112.671 +    /**
 112.672 +     * Returns a <tt>Character</tt> instance representing the specified
 112.673 +     * <tt>char</tt> value.
 112.674 +     * If a new <tt>Character</tt> instance is not required, this method
 112.675 +     * should generally be used in preference to the constructor
 112.676 +     * {@link #Character(char)}, as this method is likely to yield
 112.677 +     * significantly better space and time performance by caching
 112.678 +     * frequently requested values.
 112.679 +     *
 112.680 +     * This method will always cache values in the range {@code
 112.681 +     * '\u005Cu0000'} to {@code '\u005Cu007F'}, inclusive, and may
 112.682 +     * cache other values outside of this range.
 112.683 +     *
 112.684 +     * @param  c a char value.
 112.685 +     * @return a <tt>Character</tt> instance representing <tt>c</tt>.
 112.686 +     * @since  1.5
 112.687 +     */
 112.688 +    public static Character valueOf(char c) {
 112.689 +        if (c <= 127) { // must cache
 112.690 +            return CharacterCache.cache[(int)c];
 112.691 +        }
 112.692 +        return new Character(c);
 112.693 +    }
 112.694 +
 112.695 +    /**
 112.696 +     * Returns the value of this {@code Character} object.
 112.697 +     * @return  the primitive {@code char} value represented by
 112.698 +     *          this object.
 112.699 +     */
 112.700 +    public char charValue() {
 112.701 +        return value;
 112.702 +    }
 112.703 +
 112.704 +    /**
 112.705 +     * Returns a hash code for this {@code Character}; equal to the result
 112.706 +     * of invoking {@code charValue()}.
 112.707 +     *
 112.708 +     * @return a hash code value for this {@code Character}
 112.709 +     */
 112.710 +    public int hashCode() {
 112.711 +        return (int)value;
 112.712 +    }
 112.713 +
 112.714 +    /**
 112.715 +     * Compares this object against the specified object.
 112.716 +     * The result is {@code true} if and only if the argument is not
 112.717 +     * {@code null} and is a {@code Character} object that
 112.718 +     * represents the same {@code char} value as this object.
 112.719 +     *
 112.720 +     * @param   obj   the object to compare with.
 112.721 +     * @return  {@code true} if the objects are the same;
 112.722 +     *          {@code false} otherwise.
 112.723 +     */
 112.724 +    public boolean equals(Object obj) {
 112.725 +        if (obj instanceof Character) {
 112.726 +            return value == ((Character)obj).charValue();
 112.727 +        }
 112.728 +        return false;
 112.729 +    }
 112.730 +
 112.731 +    /**
 112.732 +     * Returns a {@code String} object representing this
 112.733 +     * {@code Character}'s value.  The result is a string of
 112.734 +     * length 1 whose sole component is the primitive
 112.735 +     * {@code char} value represented by this
 112.736 +     * {@code Character} object.
 112.737 +     *
 112.738 +     * @return  a string representation of this object.
 112.739 +     */
 112.740 +    public String toString() {
 112.741 +        char buf[] = {value};
 112.742 +        return String.valueOf(buf);
 112.743 +    }
 112.744 +
 112.745 +    /**
 112.746 +     * Returns a {@code String} object representing the
 112.747 +     * specified {@code char}.  The result is a string of length
 112.748 +     * 1 consisting solely of the specified {@code char}.
 112.749 +     *
 112.750 +     * @param c the {@code char} to be converted
 112.751 +     * @return the string representation of the specified {@code char}
 112.752 +     * @since 1.4
 112.753 +     */
 112.754 +    public static String toString(char c) {
 112.755 +        return String.valueOf(c);
 112.756 +    }
 112.757 +
 112.758 +    /**
 112.759 +     * Determines whether the specified code point is a valid
 112.760 +     * <a href="http://www.unicode.org/glossary/#code_point">
 112.761 +     * Unicode code point value</a>.
 112.762 +     *
 112.763 +     * @param  codePoint the Unicode code point to be tested
 112.764 +     * @return {@code true} if the specified code point value is between
 112.765 +     *         {@link #MIN_CODE_POINT} and
 112.766 +     *         {@link #MAX_CODE_POINT} inclusive;
 112.767 +     *         {@code false} otherwise.
 112.768 +     * @since  1.5
 112.769 +     */
 112.770 +    public static boolean isValidCodePoint(int codePoint) {
 112.771 +        // Optimized form of:
 112.772 +        //     codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT
 112.773 +        int plane = codePoint >>> 16;
 112.774 +        return plane < ((MAX_CODE_POINT + 1) >>> 16);
 112.775 +    }
 112.776 +
 112.777 +    /**
 112.778 +     * Determines whether the specified character (Unicode code point)
 112.779 +     * is in the <a href="#BMP">Basic Multilingual Plane (BMP)</a>.
 112.780 +     * Such code points can be represented using a single {@code char}.
 112.781 +     *
 112.782 +     * @param  codePoint the character (Unicode code point) to be tested
 112.783 +     * @return {@code true} if the specified code point is between
 112.784 +     *         {@link #MIN_VALUE} and {@link #MAX_VALUE} inclusive;
 112.785 +     *         {@code false} otherwise.
 112.786 +     * @since  1.7
 112.787 +     */
 112.788 +    public static boolean isBmpCodePoint(int codePoint) {
 112.789 +        return codePoint >>> 16 == 0;
 112.790 +        // Optimized form of:
 112.791 +        //     codePoint >= MIN_VALUE && codePoint <= MAX_VALUE
 112.792 +        // We consistently use logical shift (>>>) to facilitate
 112.793 +        // additional runtime optimizations.
 112.794 +    }
 112.795 +
 112.796 +    /**
 112.797 +     * Determines whether the specified character (Unicode code point)
 112.798 +     * is in the <a href="#supplementary">supplementary character</a> range.
 112.799 +     *
 112.800 +     * @param  codePoint the character (Unicode code point) to be tested
 112.801 +     * @return {@code true} if the specified code point is between
 112.802 +     *         {@link #MIN_SUPPLEMENTARY_CODE_POINT} and
 112.803 +     *         {@link #MAX_CODE_POINT} inclusive;
 112.804 +     *         {@code false} otherwise.
 112.805 +     * @since  1.5
 112.806 +     */
 112.807 +    public static boolean isSupplementaryCodePoint(int codePoint) {
 112.808 +        return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT
 112.809 +            && codePoint <  MAX_CODE_POINT + 1;
 112.810 +    }
 112.811 +
 112.812 +    /**
 112.813 +     * Determines if the given {@code char} value is a
 112.814 +     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 112.815 +     * Unicode high-surrogate code unit</a>
 112.816 +     * (also known as <i>leading-surrogate code unit</i>).
 112.817 +     *
 112.818 +     * <p>Such values do not represent characters by themselves,
 112.819 +     * but are used in the representation of
 112.820 +     * <a href="#supplementary">supplementary characters</a>
 112.821 +     * in the UTF-16 encoding.
 112.822 +     *
 112.823 +     * @param  ch the {@code char} value to be tested.
 112.824 +     * @return {@code true} if the {@code char} value is between
 112.825 +     *         {@link #MIN_HIGH_SURROGATE} and
 112.826 +     *         {@link #MAX_HIGH_SURROGATE} inclusive;
 112.827 +     *         {@code false} otherwise.
 112.828 +     * @see    Character#isLowSurrogate(char)
 112.829 +     * @see    Character.UnicodeBlock#of(int)
 112.830 +     * @since  1.5
 112.831 +     */
 112.832 +    public static boolean isHighSurrogate(char ch) {
 112.833 +        // Help VM constant-fold; MAX_HIGH_SURROGATE + 1 == MIN_LOW_SURROGATE
 112.834 +        return ch >= MIN_HIGH_SURROGATE && ch < (MAX_HIGH_SURROGATE + 1);
 112.835 +    }
 112.836 +
 112.837 +    /**
 112.838 +     * Determines if the given {@code char} value is a
 112.839 +     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
 112.840 +     * Unicode low-surrogate code unit</a>
 112.841 +     * (also known as <i>trailing-surrogate code unit</i>).
 112.842 +     *
 112.843 +     * <p>Such values do not represent characters by themselves,
 112.844 +     * but are used in the representation of
 112.845 +     * <a href="#supplementary">supplementary characters</a>
 112.846 +     * in the UTF-16 encoding.
 112.847 +     *
 112.848 +     * @param  ch the {@code char} value to be tested.
 112.849 +     * @return {@code true} if the {@code char} value is between
 112.850 +     *         {@link #MIN_LOW_SURROGATE} and
 112.851 +     *         {@link #MAX_LOW_SURROGATE} inclusive;
 112.852 +     *         {@code false} otherwise.
 112.853 +     * @see    Character#isHighSurrogate(char)
 112.854 +     * @since  1.5
 112.855 +     */
 112.856 +    public static boolean isLowSurrogate(char ch) {
 112.857 +        return ch >= MIN_LOW_SURROGATE && ch < (MAX_LOW_SURROGATE + 1);
 112.858 +    }
 112.859 +
 112.860 +    /**
 112.861 +     * Determines if the given {@code char} value is a Unicode
 112.862 +     * <i>surrogate code unit</i>.
 112.863 +     *
 112.864 +     * <p>Such values do not represent characters by themselves,
 112.865 +     * but are used in the representation of
 112.866 +     * <a href="#supplementary">supplementary characters</a>
 112.867 +     * in the UTF-16 encoding.
 112.868 +     *
 112.869 +     * <p>A char value is a surrogate code unit if and only if it is either
 112.870 +     * a {@linkplain #isLowSurrogate(char) low-surrogate code unit} or
 112.871 +     * a {@linkplain #isHighSurrogate(char) high-surrogate code unit}.
 112.872 +     *
 112.873 +     * @param  ch the {@code char} value to be tested.
 112.874 +     * @return {@code true} if the {@code char} value is between
 112.875 +     *         {@link #MIN_SURROGATE} and
 112.876 +     *         {@link #MAX_SURROGATE} inclusive;
 112.877 +     *         {@code false} otherwise.
 112.878 +     * @since  1.7
 112.879 +     */
 112.880 +    public static boolean isSurrogate(char ch) {
 112.881 +        return ch >= MIN_SURROGATE && ch < (MAX_SURROGATE + 1);
 112.882 +    }
 112.883 +
 112.884 +    /**
 112.885 +     * Determines whether the specified pair of {@code char}
 112.886 +     * values is a valid
 112.887 +     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
 112.888 +     * Unicode surrogate pair</a>.
 112.889 +
 112.890 +     * <p>This method is equivalent to the expression:
 112.891 +     * <blockquote><pre>
 112.892 +     * isHighSurrogate(high) && isLowSurrogate(low)
 112.893 +     * </pre></blockquote>
 112.894 +     *
 112.895 +     * @param  high the high-surrogate code value to be tested
 112.896 +     * @param  low the low-surrogate code value to be tested
 112.897 +     * @return {@code true} if the specified high and
 112.898 +     * low-surrogate code values represent a valid surrogate pair;
 112.899 +     * {@code false} otherwise.
 112.900 +     * @since  1.5
 112.901 +     */
 112.902 +    public static boolean isSurrogatePair(char high, char low) {
 112.903 +        return isHighSurrogate(high) && isLowSurrogate(low);
 112.904 +    }
 112.905 +
 112.906 +    /**
 112.907 +     * Determines the number of {@code char} values needed to
 112.908 +     * represent the specified character (Unicode code point). If the
 112.909 +     * specified character is equal to or greater than 0x10000, then
 112.910 +     * the method returns 2. Otherwise, the method returns 1.
 112.911 +     *
 112.912 +     * <p>This method doesn't validate the specified character to be a
 112.913 +     * valid Unicode code point. The caller must validate the
 112.914 +     * character value using {@link #isValidCodePoint(int) isValidCodePoint}
 112.915 +     * if necessary.
 112.916 +     *
 112.917 +     * @param   codePoint the character (Unicode code point) to be tested.
 112.918 +     * @return  2 if the character is a valid supplementary character; 1 otherwise.
 112.919 +     * @see     Character#isSupplementaryCodePoint(int)
 112.920 +     * @since   1.5
 112.921 +     */
 112.922 +    public static int charCount(int codePoint) {
 112.923 +        return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT ? 2 : 1;
 112.924 +    }
 112.925 +
 112.926 +    /**
 112.927 +     * Converts the specified surrogate pair to its supplementary code
 112.928 +     * point value. This method does not validate the specified
 112.929 +     * surrogate pair. The caller must validate it using {@link
 112.930 +     * #isSurrogatePair(char, char) isSurrogatePair} if necessary.
 112.931 +     *
 112.932 +     * @param  high the high-surrogate code unit
 112.933 +     * @param  low the low-surrogate code unit
 112.934 +     * @return the supplementary code point composed from the
 112.935 +     *         specified surrogate pair.
 112.936 +     * @since  1.5
 112.937 +     */
 112.938 +    public static int toCodePoint(char high, char low) {
 112.939 +        // Optimized form of:
 112.940 +        // return ((high - MIN_HIGH_SURROGATE) << 10)
 112.941 +        //         + (low - MIN_LOW_SURROGATE)
 112.942 +        //         + MIN_SUPPLEMENTARY_CODE_POINT;
 112.943 +        return ((high << 10) + low) + (MIN_SUPPLEMENTARY_CODE_POINT
 112.944 +                                       - (MIN_HIGH_SURROGATE << 10)
 112.945 +                                       - MIN_LOW_SURROGATE);
 112.946 +    }
 112.947 +
 112.948 +    /**
 112.949 +     * Returns the code point at the given index of the
 112.950 +     * {@code CharSequence}. If the {@code char} value at
 112.951 +     * the given index in the {@code CharSequence} is in the
 112.952 +     * high-surrogate range, the following index is less than the
 112.953 +     * length of the {@code CharSequence}, and the
 112.954 +     * {@code char} value at the following index is in the
 112.955 +     * low-surrogate range, then the supplementary code point
 112.956 +     * corresponding to this surrogate pair is returned. Otherwise,
 112.957 +     * the {@code char} value at the given index is returned.
 112.958 +     *
 112.959 +     * @param seq a sequence of {@code char} values (Unicode code
 112.960 +     * units)
 112.961 +     * @param index the index to the {@code char} values (Unicode
 112.962 +     * code units) in {@code seq} to be converted
 112.963 +     * @return the Unicode code point at the given index
 112.964 +     * @exception NullPointerException if {@code seq} is null.
 112.965 +     * @exception IndexOutOfBoundsException if the value
 112.966 +     * {@code index} is negative or not less than
 112.967 +     * {@link CharSequence#length() seq.length()}.
 112.968 +     * @since  1.5
 112.969 +     */
 112.970 +    public static int codePointAt(CharSequence seq, int index) {
 112.971 +        char c1 = seq.charAt(index++);
 112.972 +        if (isHighSurrogate(c1)) {
 112.973 +            if (index < seq.length()) {
 112.974 +                char c2 = seq.charAt(index);
 112.975 +                if (isLowSurrogate(c2)) {
 112.976 +                    return toCodePoint(c1, c2);
 112.977 +                }
 112.978 +            }
 112.979 +        }
 112.980 +        return c1;
 112.981 +    }
 112.982 +
 112.983 +    /**
 112.984 +     * Returns the code point at the given index of the
 112.985 +     * {@code char} array. If the {@code char} value at
 112.986 +     * the given index in the {@code char} array is in the
 112.987 +     * high-surrogate range, the following index is less than the
 112.988 +     * length of the {@code char} array, and the
 112.989 +     * {@code char} value at the following index is in the
 112.990 +     * low-surrogate range, then the supplementary code point
 112.991 +     * corresponding to this surrogate pair is returned. Otherwise,
 112.992 +     * the {@code char} value at the given index is returned.
 112.993 +     *
 112.994 +     * @param a the {@code char} array
 112.995 +     * @param index the index to the {@code char} values (Unicode
 112.996 +     * code units) in the {@code char} array to be converted
 112.997 +     * @return the Unicode code point at the given index
 112.998 +     * @exception NullPointerException if {@code a} is null.
 112.999 +     * @exception IndexOutOfBoundsException if the value
112.1000 +     * {@code index} is negative or not less than
112.1001 +     * the length of the {@code char} array.
112.1002 +     * @since  1.5
112.1003 +     */
112.1004 +    public static int codePointAt(char[] a, int index) {
112.1005 +        return codePointAtImpl(a, index, a.length);
112.1006 +    }
112.1007 +
112.1008 +    /**
112.1009 +     * Returns the code point at the given index of the
112.1010 +     * {@code char} array, where only array elements with
112.1011 +     * {@code index} less than {@code limit} can be used. If
112.1012 +     * the {@code char} value at the given index in the
112.1013 +     * {@code char} array is in the high-surrogate range, the
112.1014 +     * following index is less than the {@code limit}, and the
112.1015 +     * {@code char} value at the following index is in the
112.1016 +     * low-surrogate range, then the supplementary code point
112.1017 +     * corresponding to this surrogate pair is returned. Otherwise,
112.1018 +     * the {@code char} value at the given index is returned.
112.1019 +     *
112.1020 +     * @param a the {@code char} array
112.1021 +     * @param index the index to the {@code char} values (Unicode
112.1022 +     * code units) in the {@code char} array to be converted
112.1023 +     * @param limit the index after the last array element that
112.1024 +     * can be used in the {@code char} array
112.1025 +     * @return the Unicode code point at the given index
112.1026 +     * @exception NullPointerException if {@code a} is null.
112.1027 +     * @exception IndexOutOfBoundsException if the {@code index}
112.1028 +     * argument is negative or not less than the {@code limit}
112.1029 +     * argument, or if the {@code limit} argument is negative or
112.1030 +     * greater than the length of the {@code char} array.
112.1031 +     * @since  1.5
112.1032 +     */
112.1033 +    public static int codePointAt(char[] a, int index, int limit) {
112.1034 +        if (index >= limit || limit < 0 || limit > a.length) {
112.1035 +            throw new IndexOutOfBoundsException();
112.1036 +        }
112.1037 +        return codePointAtImpl(a, index, limit);
112.1038 +    }
112.1039 +
112.1040 +    // throws ArrayIndexOutofBoundsException if index out of bounds
112.1041 +    static int codePointAtImpl(char[] a, int index, int limit) {
112.1042 +        char c1 = a[index++];
112.1043 +        if (isHighSurrogate(c1)) {
112.1044 +            if (index < limit) {
112.1045 +                char c2 = a[index];
112.1046 +                if (isLowSurrogate(c2)) {
112.1047 +                    return toCodePoint(c1, c2);
112.1048 +                }
112.1049 +            }
112.1050 +        }
112.1051 +        return c1;
112.1052 +    }
112.1053 +
112.1054 +    /**
112.1055 +     * Returns the code point preceding the given index of the
112.1056 +     * {@code CharSequence}. If the {@code char} value at
112.1057 +     * {@code (index - 1)} in the {@code CharSequence} is in
112.1058 +     * the low-surrogate range, {@code (index - 2)} is not
112.1059 +     * negative, and the {@code char} value at {@code (index - 2)}
112.1060 +     * in the {@code CharSequence} is in the
112.1061 +     * high-surrogate range, then the supplementary code point
112.1062 +     * corresponding to this surrogate pair is returned. Otherwise,
112.1063 +     * the {@code char} value at {@code (index - 1)} is
112.1064 +     * returned.
112.1065 +     *
112.1066 +     * @param seq the {@code CharSequence} instance
112.1067 +     * @param index the index following the code point that should be returned
112.1068 +     * @return the Unicode code point value before the given index.
112.1069 +     * @exception NullPointerException if {@code seq} is null.
112.1070 +     * @exception IndexOutOfBoundsException if the {@code index}
112.1071 +     * argument is less than 1 or greater than {@link
112.1072 +     * CharSequence#length() seq.length()}.
112.1073 +     * @since  1.5
112.1074 +     */
112.1075 +    public static int codePointBefore(CharSequence seq, int index) {
112.1076 +        char c2 = seq.charAt(--index);
112.1077 +        if (isLowSurrogate(c2)) {
112.1078 +            if (index > 0) {
112.1079 +                char c1 = seq.charAt(--index);
112.1080 +                if (isHighSurrogate(c1)) {
112.1081 +                    return toCodePoint(c1, c2);
112.1082 +                }
112.1083 +            }
112.1084 +        }
112.1085 +        return c2;
112.1086 +    }
112.1087 +
112.1088 +    /**
112.1089 +     * Returns the code point preceding the given index of the
112.1090 +     * {@code char} array. If the {@code char} value at
112.1091 +     * {@code (index - 1)} in the {@code char} array is in
112.1092 +     * the low-surrogate range, {@code (index - 2)} is not
112.1093 +     * negative, and the {@code char} value at {@code (index - 2)}
112.1094 +     * in the {@code char} array is in the
112.1095 +     * high-surrogate range, then the supplementary code point
112.1096 +     * corresponding to this surrogate pair is returned. Otherwise,
112.1097 +     * the {@code char} value at {@code (index - 1)} is
112.1098 +     * returned.
112.1099 +     *
112.1100 +     * @param a the {@code char} array
112.1101 +     * @param index the index following the code point that should be returned
112.1102 +     * @return the Unicode code point value before the given index.
112.1103 +     * @exception NullPointerException if {@code a} is null.
112.1104 +     * @exception IndexOutOfBoundsException if the {@code index}
112.1105 +     * argument is less than 1 or greater than the length of the
112.1106 +     * {@code char} array
112.1107 +     * @since  1.5
112.1108 +     */
112.1109 +    public static int codePointBefore(char[] a, int index) {
112.1110 +        return codePointBeforeImpl(a, index, 0);
112.1111 +    }
112.1112 +
112.1113 +    /**
112.1114 +     * Returns the code point preceding the given index of the
112.1115 +     * {@code char} array, where only array elements with
112.1116 +     * {@code index} greater than or equal to {@code start}
112.1117 +     * can be used. If the {@code char} value at {@code (index - 1)}
112.1118 +     * in the {@code char} array is in the
112.1119 +     * low-surrogate range, {@code (index - 2)} is not less than
112.1120 +     * {@code start}, and the {@code char} value at
112.1121 +     * {@code (index - 2)} in the {@code char} array is in
112.1122 +     * the high-surrogate range, then the supplementary code point
112.1123 +     * corresponding to this surrogate pair is returned. Otherwise,
112.1124 +     * the {@code char} value at {@code (index - 1)} is
112.1125 +     * returned.
112.1126 +     *
112.1127 +     * @param a the {@code char} array
112.1128 +     * @param index the index following the code point that should be returned
112.1129 +     * @param start the index of the first array element in the
112.1130 +     * {@code char} array
112.1131 +     * @return the Unicode code point value before the given index.
112.1132 +     * @exception NullPointerException if {@code a} is null.
112.1133 +     * @exception IndexOutOfBoundsException if the {@code index}
112.1134 +     * argument is not greater than the {@code start} argument or
112.1135 +     * is greater than the length of the {@code char} array, or
112.1136 +     * if the {@code start} argument is negative or not less than
112.1137 +     * the length of the {@code char} array.
112.1138 +     * @since  1.5
112.1139 +     */
112.1140 +    public static int codePointBefore(char[] a, int index, int start) {
112.1141 +        if (index <= start || start < 0 || start >= a.length) {
112.1142 +            throw new IndexOutOfBoundsException();
112.1143 +        }
112.1144 +        return codePointBeforeImpl(a, index, start);
112.1145 +    }
112.1146 +
112.1147 +    // throws ArrayIndexOutofBoundsException if index-1 out of bounds
112.1148 +    static int codePointBeforeImpl(char[] a, int index, int start) {
112.1149 +        char c2 = a[--index];
112.1150 +        if (isLowSurrogate(c2)) {
112.1151 +            if (index > start) {
112.1152 +                char c1 = a[--index];
112.1153 +                if (isHighSurrogate(c1)) {
112.1154 +                    return toCodePoint(c1, c2);
112.1155 +                }
112.1156 +            }
112.1157 +        }
112.1158 +        return c2;
112.1159 +    }
112.1160 +
112.1161 +    /**
112.1162 +     * Returns the leading surrogate (a
112.1163 +     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
112.1164 +     * high surrogate code unit</a>) of the
112.1165 +     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
112.1166 +     * surrogate pair</a>
112.1167 +     * representing the specified supplementary character (Unicode
112.1168 +     * code point) in the UTF-16 encoding.  If the specified character
112.1169 +     * is not a
112.1170 +     * <a href="Character.html#supplementary">supplementary character</a>,
112.1171 +     * an unspecified {@code char} is returned.
112.1172 +     *
112.1173 +     * <p>If
112.1174 +     * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
112.1175 +     * is {@code true}, then
112.1176 +     * {@link #isHighSurrogate isHighSurrogate}{@code (highSurrogate(x))} and
112.1177 +     * {@link #toCodePoint toCodePoint}{@code (highSurrogate(x), }{@link #lowSurrogate lowSurrogate}{@code (x)) == x}
112.1178 +     * are also always {@code true}.
112.1179 +     *
112.1180 +     * @param   codePoint a supplementary character (Unicode code point)
112.1181 +     * @return  the leading surrogate code unit used to represent the
112.1182 +     *          character in the UTF-16 encoding
112.1183 +     * @since   1.7
112.1184 +     */
112.1185 +    public static char highSurrogate(int codePoint) {
112.1186 +        return (char) ((codePoint >>> 10)
112.1187 +            + (MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT >>> 10)));
112.1188 +    }
112.1189 +
112.1190 +    /**
112.1191 +     * Returns the trailing surrogate (a
112.1192 +     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
112.1193 +     * low surrogate code unit</a>) of the
112.1194 +     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
112.1195 +     * surrogate pair</a>
112.1196 +     * representing the specified supplementary character (Unicode
112.1197 +     * code point) in the UTF-16 encoding.  If the specified character
112.1198 +     * is not a
112.1199 +     * <a href="Character.html#supplementary">supplementary character</a>,
112.1200 +     * an unspecified {@code char} is returned.
112.1201 +     *
112.1202 +     * <p>If
112.1203 +     * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
112.1204 +     * is {@code true}, then
112.1205 +     * {@link #isLowSurrogate isLowSurrogate}{@code (lowSurrogate(x))} and
112.1206 +     * {@link #toCodePoint toCodePoint}{@code (}{@link #highSurrogate highSurrogate}{@code (x), lowSurrogate(x)) == x}
112.1207 +     * are also always {@code true}.
112.1208 +     *
112.1209 +     * @param   codePoint a supplementary character (Unicode code point)
112.1210 +     * @return  the trailing surrogate code unit used to represent the
112.1211 +     *          character in the UTF-16 encoding
112.1212 +     * @since   1.7
112.1213 +     */
112.1214 +    public static char lowSurrogate(int codePoint) {
112.1215 +        return (char) ((codePoint & 0x3ff) + MIN_LOW_SURROGATE);
112.1216 +    }
112.1217 +
112.1218 +    /**
112.1219 +     * Converts the specified character (Unicode code point) to its
112.1220 +     * UTF-16 representation. If the specified code point is a BMP
112.1221 +     * (Basic Multilingual Plane or Plane 0) value, the same value is
112.1222 +     * stored in {@code dst[dstIndex]}, and 1 is returned. If the
112.1223 +     * specified code point is a supplementary character, its
112.1224 +     * surrogate values are stored in {@code dst[dstIndex]}
112.1225 +     * (high-surrogate) and {@code dst[dstIndex+1]}
112.1226 +     * (low-surrogate), and 2 is returned.
112.1227 +     *
112.1228 +     * @param  codePoint the character (Unicode code point) to be converted.
112.1229 +     * @param  dst an array of {@code char} in which the
112.1230 +     * {@code codePoint}'s UTF-16 value is stored.
112.1231 +     * @param dstIndex the start index into the {@code dst}
112.1232 +     * array where the converted value is stored.
112.1233 +     * @return 1 if the code point is a BMP code point, 2 if the
112.1234 +     * code point is a supplementary code point.
112.1235 +     * @exception IllegalArgumentException if the specified
112.1236 +     * {@code codePoint} is not a valid Unicode code point.
112.1237 +     * @exception NullPointerException if the specified {@code dst} is null.
112.1238 +     * @exception IndexOutOfBoundsException if {@code dstIndex}
112.1239 +     * is negative or not less than {@code dst.length}, or if
112.1240 +     * {@code dst} at {@code dstIndex} doesn't have enough
112.1241 +     * array element(s) to store the resulting {@code char}
112.1242 +     * value(s). (If {@code dstIndex} is equal to
112.1243 +     * {@code dst.length-1} and the specified
112.1244 +     * {@code codePoint} is a supplementary character, the
112.1245 +     * high-surrogate value is not stored in
112.1246 +     * {@code dst[dstIndex]}.)
112.1247 +     * @since  1.5
112.1248 +     */
112.1249 +    public static int toChars(int codePoint, char[] dst, int dstIndex) {
112.1250 +        if (isBmpCodePoint(codePoint)) {
112.1251 +            dst[dstIndex] = (char) codePoint;
112.1252 +            return 1;
112.1253 +        } else if (isValidCodePoint(codePoint)) {
112.1254 +            toSurrogates(codePoint, dst, dstIndex);
112.1255 +            return 2;
112.1256 +        } else {
112.1257 +            throw new IllegalArgumentException();
112.1258 +        }
112.1259 +    }
112.1260 +
112.1261 +    /**
112.1262 +     * Converts the specified character (Unicode code point) to its
112.1263 +     * UTF-16 representation stored in a {@code char} array. If
112.1264 +     * the specified code point is a BMP (Basic Multilingual Plane or
112.1265 +     * Plane 0) value, the resulting {@code char} array has
112.1266 +     * the same value as {@code codePoint}. If the specified code
112.1267 +     * point is a supplementary code point, the resulting
112.1268 +     * {@code char} array has the corresponding surrogate pair.
112.1269 +     *
112.1270 +     * @param  codePoint a Unicode code point
112.1271 +     * @return a {@code char} array having
112.1272 +     *         {@code codePoint}'s UTF-16 representation.
112.1273 +     * @exception IllegalArgumentException if the specified
112.1274 +     * {@code codePoint} is not a valid Unicode code point.
112.1275 +     * @since  1.5
112.1276 +     */
112.1277 +    public static char[] toChars(int codePoint) {
112.1278 +        if (isBmpCodePoint(codePoint)) {
112.1279 +            return new char[] { (char) codePoint };
112.1280 +        } else if (isValidCodePoint(codePoint)) {
112.1281 +            char[] result = new char[2];
112.1282 +            toSurrogates(codePoint, result, 0);
112.1283 +            return result;
112.1284 +        } else {
112.1285 +            throw new IllegalArgumentException();
112.1286 +        }
112.1287 +    }
112.1288 +
112.1289 +    static void toSurrogates(int codePoint, char[] dst, int index) {
112.1290 +        // We write elements "backwards" to guarantee all-or-nothing
112.1291 +        dst[index+1] = lowSurrogate(codePoint);
112.1292 +        dst[index] = highSurrogate(codePoint);
112.1293 +    }
112.1294 +
112.1295 +    /**
112.1296 +     * Returns the number of Unicode code points in the text range of
112.1297 +     * the specified char sequence. The text range begins at the
112.1298 +     * specified {@code beginIndex} and extends to the
112.1299 +     * {@code char} at index {@code endIndex - 1}. Thus the
112.1300 +     * length (in {@code char}s) of the text range is
112.1301 +     * {@code endIndex-beginIndex}. Unpaired surrogates within
112.1302 +     * the text range count as one code point each.
112.1303 +     *
112.1304 +     * @param seq the char sequence
112.1305 +     * @param beginIndex the index to the first {@code char} of
112.1306 +     * the text range.
112.1307 +     * @param endIndex the index after the last {@code char} of
112.1308 +     * the text range.
112.1309 +     * @return the number of Unicode code points in the specified text
112.1310 +     * range
112.1311 +     * @exception NullPointerException if {@code seq} is null.
112.1312 +     * @exception IndexOutOfBoundsException if the
112.1313 +     * {@code beginIndex} is negative, or {@code endIndex}
112.1314 +     * is larger than the length of the given sequence, or
112.1315 +     * {@code beginIndex} is larger than {@code endIndex}.
112.1316 +     * @since  1.5
112.1317 +     */
112.1318 +    public static int codePointCount(CharSequence seq, int beginIndex, int endIndex) {
112.1319 +        int length = seq.length();
112.1320 +        if (beginIndex < 0 || endIndex > length || beginIndex > endIndex) {
112.1321 +            throw new IndexOutOfBoundsException();
112.1322 +        }
112.1323 +        int n = endIndex - beginIndex;
112.1324 +        for (int i = beginIndex; i < endIndex; ) {
112.1325 +            if (isHighSurrogate(seq.charAt(i++)) && i < endIndex &&
112.1326 +                isLowSurrogate(seq.charAt(i))) {
112.1327 +                n--;
112.1328 +                i++;
112.1329 +            }
112.1330 +        }
112.1331 +        return n;
112.1332 +    }
112.1333 +
112.1334 +    /**
112.1335 +     * Returns the number of Unicode code points in a subarray of the
112.1336 +     * {@code char} array argument. The {@code offset}
112.1337 +     * argument is the index of the first {@code char} of the
112.1338 +     * subarray and the {@code count} argument specifies the
112.1339 +     * length of the subarray in {@code char}s. Unpaired
112.1340 +     * surrogates within the subarray count as one code point each.
112.1341 +     *
112.1342 +     * @param a the {@code char} array
112.1343 +     * @param offset the index of the first {@code char} in the
112.1344 +     * given {@code char} array
112.1345 +     * @param count the length of the subarray in {@code char}s
112.1346 +     * @return the number of Unicode code points in the specified subarray
112.1347 +     * @exception NullPointerException if {@code a} is null.
112.1348 +     * @exception IndexOutOfBoundsException if {@code offset} or
112.1349 +     * {@code count} is negative, or if {@code offset +
112.1350 +     * count} is larger than the length of the given array.
112.1351 +     * @since  1.5
112.1352 +     */
112.1353 +    public static int codePointCount(char[] a, int offset, int count) {
112.1354 +        if (count > a.length - offset || offset < 0 || count < 0) {
112.1355 +            throw new IndexOutOfBoundsException();
112.1356 +        }
112.1357 +        return codePointCountImpl(a, offset, count);
112.1358 +    }
112.1359 +
112.1360 +    static int codePointCountImpl(char[] a, int offset, int count) {
112.1361 +        int endIndex = offset + count;
112.1362 +        int n = count;
112.1363 +        for (int i = offset; i < endIndex; ) {
112.1364 +            if (isHighSurrogate(a[i++]) && i < endIndex &&
112.1365 +                isLowSurrogate(a[i])) {
112.1366 +                n--;
112.1367 +                i++;
112.1368 +            }
112.1369 +        }
112.1370 +        return n;
112.1371 +    }
112.1372 +
112.1373 +    /**
112.1374 +     * Returns the index within the given char sequence that is offset
112.1375 +     * from the given {@code index} by {@code codePointOffset}
112.1376 +     * code points. Unpaired surrogates within the text range given by
112.1377 +     * {@code index} and {@code codePointOffset} count as
112.1378 +     * one code point each.
112.1379 +     *
112.1380 +     * @param seq the char sequence
112.1381 +     * @param index the index to be offset
112.1382 +     * @param codePointOffset the offset in code points
112.1383 +     * @return the index within the char sequence
112.1384 +     * @exception NullPointerException if {@code seq} is null.
112.1385 +     * @exception IndexOutOfBoundsException if {@code index}
112.1386 +     *   is negative or larger then the length of the char sequence,
112.1387 +     *   or if {@code codePointOffset} is positive and the
112.1388 +     *   subsequence starting with {@code index} has fewer than
112.1389 +     *   {@code codePointOffset} code points, or if
112.1390 +     *   {@code codePointOffset} is negative and the subsequence
112.1391 +     *   before {@code index} has fewer than the absolute value
112.1392 +     *   of {@code codePointOffset} code points.
112.1393 +     * @since 1.5
112.1394 +     */
112.1395 +    public static int offsetByCodePoints(CharSequence seq, int index,
112.1396 +                                         int codePointOffset) {
112.1397 +        int length = seq.length();
112.1398 +        if (index < 0 || index > length) {
112.1399 +            throw new IndexOutOfBoundsException();
112.1400 +        }
112.1401 +
112.1402 +        int x = index;
112.1403 +        if (codePointOffset >= 0) {
112.1404 +            int i;
112.1405 +            for (i = 0; x < length && i < codePointOffset; i++) {
112.1406 +                if (isHighSurrogate(seq.charAt(x++)) && x < length &&
112.1407 +                    isLowSurrogate(seq.charAt(x))) {
112.1408 +                    x++;
112.1409 +                }
112.1410 +            }
112.1411 +            if (i < codePointOffset) {
112.1412 +                throw new IndexOutOfBoundsException();
112.1413 +            }
112.1414 +        } else {
112.1415 +            int i;
112.1416 +            for (i = codePointOffset; x > 0 && i < 0; i++) {
112.1417 +                if (isLowSurrogate(seq.charAt(--x)) && x > 0 &&
112.1418 +                    isHighSurrogate(seq.charAt(x-1))) {
112.1419 +                    x--;
112.1420 +                }
112.1421 +            }
112.1422 +            if (i < 0) {
112.1423 +                throw new IndexOutOfBoundsException();
112.1424 +            }
112.1425 +        }
112.1426 +        return x;
112.1427 +    }
112.1428 +
112.1429 +    /**
112.1430 +     * Returns the index within the given {@code char} subarray
112.1431 +     * that is offset from the given {@code index} by
112.1432 +     * {@code codePointOffset} code points. The
112.1433 +     * {@code start} and {@code count} arguments specify a
112.1434 +     * subarray of the {@code char} array. Unpaired surrogates
112.1435 +     * within the text range given by {@code index} and
112.1436 +     * {@code codePointOffset} count as one code point each.
112.1437 +     *
112.1438 +     * @param a the {@code char} array
112.1439 +     * @param start the index of the first {@code char} of the
112.1440 +     * subarray
112.1441 +     * @param count the length of the subarray in {@code char}s
112.1442 +     * @param index the index to be offset
112.1443 +     * @param codePointOffset the offset in code points
112.1444 +     * @return the index within the subarray
112.1445 +     * @exception NullPointerException if {@code a} is null.
112.1446 +     * @exception IndexOutOfBoundsException
112.1447 +     *   if {@code start} or {@code count} is negative,
112.1448 +     *   or if {@code start + count} is larger than the length of
112.1449 +     *   the given array,
112.1450 +     *   or if {@code index} is less than {@code start} or
112.1451 +     *   larger then {@code start + count},
112.1452 +     *   or if {@code codePointOffset} is positive and the text range
112.1453 +     *   starting with {@code index} and ending with {@code start + count - 1}
112.1454 +     *   has fewer than {@code codePointOffset} code
112.1455 +     *   points,
112.1456 +     *   or if {@code codePointOffset} is negative and the text range
112.1457 +     *   starting with {@code start} and ending with {@code index - 1}
112.1458 +     *   has fewer than the absolute value of
112.1459 +     *   {@code codePointOffset} code points.
112.1460 +     * @since 1.5
112.1461 +     */
112.1462 +    public static int offsetByCodePoints(char[] a, int start, int count,
112.1463 +                                         int index, int codePointOffset) {
112.1464 +        if (count > a.length-start || start < 0 || count < 0
112.1465 +            || index < start || index > start+count) {
112.1466 +            throw new IndexOutOfBoundsException();
112.1467 +        }
112.1468 +        return offsetByCodePointsImpl(a, start, count, index, codePointOffset);
112.1469 +    }
112.1470 +
112.1471 +    static int offsetByCodePointsImpl(char[]a, int start, int count,
112.1472 +                                      int index, int codePointOffset) {
112.1473 +        int x = index;
112.1474 +        if (codePointOffset >= 0) {
112.1475 +            int limit = start + count;
112.1476 +            int i;
112.1477 +            for (i = 0; x < limit && i < codePointOffset; i++) {
112.1478 +                if (isHighSurrogate(a[x++]) && x < limit &&
112.1479 +                    isLowSurrogate(a[x])) {
112.1480 +                    x++;
112.1481 +                }
112.1482 +            }
112.1483 +            if (i < codePointOffset) {
112.1484 +                throw new IndexOutOfBoundsException();
112.1485 +            }
112.1486 +        } else {
112.1487 +            int i;
112.1488 +            for (i = codePointOffset; x > start && i < 0; i++) {
112.1489 +                if (isLowSurrogate(a[--x]) && x > start &&
112.1490 +                    isHighSurrogate(a[x-1])) {
112.1491 +                    x--;
112.1492 +                }
112.1493 +            }
112.1494 +            if (i < 0) {
112.1495 +                throw new IndexOutOfBoundsException();
112.1496 +            }
112.1497 +        }
112.1498 +        return x;
112.1499 +    }
112.1500 +
112.1501 +    /**
112.1502 +     * Determines if the specified character is a lowercase character.
112.1503 +     * <p>
112.1504 +     * A character is lowercase if its general category type, provided
112.1505 +     * by {@code Character.getType(ch)}, is
112.1506 +     * {@code LOWERCASE_LETTER}, or it has contributory property
112.1507 +     * Other_Lowercase as defined by the Unicode Standard.
112.1508 +     * <p>
112.1509 +     * The following are examples of lowercase characters:
112.1510 +     * <p><blockquote><pre>
112.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
112.1512 +     * '&#92;u00DF' '&#92;u00E0' '&#92;u00E1' '&#92;u00E2' '&#92;u00E3' '&#92;u00E4' '&#92;u00E5' '&#92;u00E6'
112.1513 +     * '&#92;u00E7' '&#92;u00E8' '&#92;u00E9' '&#92;u00EA' '&#92;u00EB' '&#92;u00EC' '&#92;u00ED' '&#92;u00EE'
112.1514 +     * '&#92;u00EF' '&#92;u00F0' '&#92;u00F1' '&#92;u00F2' '&#92;u00F3' '&#92;u00F4' '&#92;u00F5' '&#92;u00F6'
112.1515 +     * '&#92;u00F8' '&#92;u00F9' '&#92;u00FA' '&#92;u00FB' '&#92;u00FC' '&#92;u00FD' '&#92;u00FE' '&#92;u00FF'
112.1516 +     * </pre></blockquote>
112.1517 +     * <p> Many other Unicode characters are lowercase too.
112.1518 +     *
112.1519 +     * <p><b>Note:</b> This method cannot handle <a
112.1520 +     * href="#supplementary"> supplementary characters</a>. To support
112.1521 +     * all Unicode characters, including supplementary characters, use
112.1522 +     * the {@link #isLowerCase(int)} method.
112.1523 +     *
112.1524 +     * @param   ch   the character to be tested.
112.1525 +     * @return  {@code true} if the character is lowercase;
112.1526 +     *          {@code false} otherwise.
112.1527 +     * @see     Character#isLowerCase(char)
112.1528 +     * @see     Character#isTitleCase(char)
112.1529 +     * @see     Character#toLowerCase(char)
112.1530 +     * @see     Character#getType(char)
112.1531 +     */
112.1532 +    public static boolean isLowerCase(char ch) {
112.1533 +        return ch == toLowerCase(ch);
112.1534 +    }
112.1535 +
112.1536 +    /**
112.1537 +     * Determines if the specified character is an uppercase character.
112.1538 +     * <p>
112.1539 +     * A character is uppercase if its general category type, provided by
112.1540 +     * {@code Character.getType(ch)}, is {@code UPPERCASE_LETTER}.
112.1541 +     * or it has contributory property Other_Uppercase as defined by the Unicode Standard.
112.1542 +     * <p>
112.1543 +     * The following are examples of uppercase characters:
112.1544 +     * <p><blockquote><pre>
112.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
112.1546 +     * '&#92;u00C0' '&#92;u00C1' '&#92;u00C2' '&#92;u00C3' '&#92;u00C4' '&#92;u00C5' '&#92;u00C6' '&#92;u00C7'
112.1547 +     * '&#92;u00C8' '&#92;u00C9' '&#92;u00CA' '&#92;u00CB' '&#92;u00CC' '&#92;u00CD' '&#92;u00CE' '&#92;u00CF'
112.1548 +     * '&#92;u00D0' '&#92;u00D1' '&#92;u00D2' '&#92;u00D3' '&#92;u00D4' '&#92;u00D5' '&#92;u00D6' '&#92;u00D8'
112.1549 +     * '&#92;u00D9' '&#92;u00DA' '&#92;u00DB' '&#92;u00DC' '&#92;u00DD' '&#92;u00DE'
112.1550 +     * </pre></blockquote>
112.1551 +     * <p> Many other Unicode characters are uppercase too.<p>
112.1552 +     *
112.1553 +     * <p><b>Note:</b> This method cannot handle <a
112.1554 +     * href="#supplementary"> supplementary characters</a>. To support
112.1555 +     * all Unicode characters, including supplementary characters, use
112.1556 +     * the {@link #isUpperCase(int)} method.
112.1557 +     *
112.1558 +     * @param   ch   the character to be tested.
112.1559 +     * @return  {@code true} if the character is uppercase;
112.1560 +     *          {@code false} otherwise.
112.1561 +     * @see     Character#isLowerCase(char)
112.1562 +     * @see     Character#isTitleCase(char)
112.1563 +     * @see     Character#toUpperCase(char)
112.1564 +     * @see     Character#getType(char)
112.1565 +     * @since   1.0
112.1566 +     */
112.1567 +    public static boolean isUpperCase(char ch) {
112.1568 +        return ch == toUpperCase(ch);
112.1569 +    }
112.1570 +
112.1571 +    /**
112.1572 +     * Determines if the specified character is a titlecase character.
112.1573 +     * <p>
112.1574 +     * A character is a titlecase character if its general
112.1575 +     * category type, provided by {@code Character.getType(ch)},
112.1576 +     * is {@code TITLECASE_LETTER}.
112.1577 +     * <p>
112.1578 +     * Some characters look like pairs of Latin letters. For example, there
112.1579 +     * is an uppercase letter that looks like "LJ" and has a corresponding
112.1580 +     * lowercase letter that looks like "lj". A third form, which looks like "Lj",
112.1581 +     * is the appropriate form to use when rendering a word in lowercase
112.1582 +     * with initial capitals, as for a book title.
112.1583 +     * <p>
112.1584 +     * These are some of the Unicode characters for which this method returns
112.1585 +     * {@code true}:
112.1586 +     * <ul>
112.1587 +     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON}
112.1588 +     * <li>{@code LATIN CAPITAL LETTER L WITH SMALL LETTER J}
112.1589 +     * <li>{@code LATIN CAPITAL LETTER N WITH SMALL LETTER J}
112.1590 +     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z}
112.1591 +     * </ul>
112.1592 +     * <p> Many other Unicode characters are titlecase too.<p>
112.1593 +     *
112.1594 +     * <p><b>Note:</b> This method cannot handle <a
112.1595 +     * href="#supplementary"> supplementary characters</a>. To support
112.1596 +     * all Unicode characters, including supplementary characters, use
112.1597 +     * the {@link #isTitleCase(int)} method.
112.1598 +     *
112.1599 +     * @param   ch   the character to be tested.
112.1600 +     * @return  {@code true} if the character is titlecase;
112.1601 +     *          {@code false} otherwise.
112.1602 +     * @see     Character#isLowerCase(char)
112.1603 +     * @see     Character#isUpperCase(char)
112.1604 +     * @see     Character#toTitleCase(char)
112.1605 +     * @see     Character#getType(char)
112.1606 +     * @since   1.0.2
112.1607 +     */
112.1608 +    public static boolean isTitleCase(char ch) {
112.1609 +        return isTitleCase((int)ch);
112.1610 +    }
112.1611 +
112.1612 +    /**
112.1613 +     * Determines if the specified character (Unicode code point) is a titlecase character.
112.1614 +     * <p>
112.1615 +     * A character is a titlecase character if its general
112.1616 +     * category type, provided by {@link Character#getType(int) getType(codePoint)},
112.1617 +     * is {@code TITLECASE_LETTER}.
112.1618 +     * <p>
112.1619 +     * Some characters look like pairs of Latin letters. For example, there
112.1620 +     * is an uppercase letter that looks like "LJ" and has a corresponding
112.1621 +     * lowercase letter that looks like "lj". A third form, which looks like "Lj",
112.1622 +     * is the appropriate form to use when rendering a word in lowercase
112.1623 +     * with initial capitals, as for a book title.
112.1624 +     * <p>
112.1625 +     * These are some of the Unicode characters for which this method returns
112.1626 +     * {@code true}:
112.1627 +     * <ul>
112.1628 +     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON}
112.1629 +     * <li>{@code LATIN CAPITAL LETTER L WITH SMALL LETTER J}
112.1630 +     * <li>{@code LATIN CAPITAL LETTER N WITH SMALL LETTER J}
112.1631 +     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z}
112.1632 +     * </ul>
112.1633 +     * <p> Many other Unicode characters are titlecase too.<p>
112.1634 +     *
112.1635 +     * @param   codePoint the character (Unicode code point) to be tested.
112.1636 +     * @return  {@code true} if the character is titlecase;
112.1637 +     *          {@code false} otherwise.
112.1638 +     * @see     Character#isLowerCase(int)
112.1639 +     * @see     Character#isUpperCase(int)
112.1640 +     * @see     Character#toTitleCase(int)
112.1641 +     * @see     Character#getType(int)
112.1642 +     * @since   1.5
112.1643 +     */
112.1644 +    public static boolean isTitleCase(int codePoint) {
112.1645 +        return getType(codePoint) == Character.TITLECASE_LETTER;
112.1646 +    }
112.1647 +
112.1648 +    /**
112.1649 +     * Determines if the specified character is a digit.
112.1650 +     * <p>
112.1651 +     * A character is a digit if its general category type, provided
112.1652 +     * by {@code Character.getType(ch)}, is
112.1653 +     * {@code DECIMAL_DIGIT_NUMBER}.
112.1654 +     * <p>
112.1655 +     * Some Unicode character ranges that contain digits:
112.1656 +     * <ul>
112.1657 +     * <li>{@code '\u005Cu0030'} through {@code '\u005Cu0039'},
112.1658 +     *     ISO-LATIN-1 digits ({@code '0'} through {@code '9'})
112.1659 +     * <li>{@code '\u005Cu0660'} through {@code '\u005Cu0669'},
112.1660 +     *     Arabic-Indic digits
112.1661 +     * <li>{@code '\u005Cu06F0'} through {@code '\u005Cu06F9'},
112.1662 +     *     Extended Arabic-Indic digits
112.1663 +     * <li>{@code '\u005Cu0966'} through {@code '\u005Cu096F'},
112.1664 +     *     Devanagari digits
112.1665 +     * <li>{@code '\u005CuFF10'} through {@code '\u005CuFF19'},
112.1666 +     *     Fullwidth digits
112.1667 +     * </ul>
112.1668 +     *
112.1669 +     * Many other character ranges contain digits as well.
112.1670 +     *
112.1671 +     * <p><b>Note:</b> This method cannot handle <a
112.1672 +     * href="#supplementary"> supplementary characters</a>. To support
112.1673 +     * all Unicode characters, including supplementary characters, use
112.1674 +     * the {@link #isDigit(int)} method.
112.1675 +     *
112.1676 +     * @param   ch   the character to be tested.
112.1677 +     * @return  {@code true} if the character is a digit;
112.1678 +     *          {@code false} otherwise.
112.1679 +     * @see     Character#digit(char, int)
112.1680 +     * @see     Character#forDigit(int, int)
112.1681 +     * @see     Character#getType(char)
112.1682 +     */
112.1683 +    public static boolean isDigit(char ch) {
112.1684 +        return String.valueOf(ch).matches("\\d");
112.1685 +    }
112.1686 +
112.1687 +    /**
112.1688 +     * Determines if the specified character (Unicode code point) is a digit.
112.1689 +     * <p>
112.1690 +     * A character is a digit if its general category type, provided
112.1691 +     * by {@link Character#getType(int) getType(codePoint)}, is
112.1692 +     * {@code DECIMAL_DIGIT_NUMBER}.
112.1693 +     * <p>
112.1694 +     * Some Unicode character ranges that contain digits:
112.1695 +     * <ul>
112.1696 +     * <li>{@code '\u005Cu0030'} through {@code '\u005Cu0039'},
112.1697 +     *     ISO-LATIN-1 digits ({@code '0'} through {@code '9'})
112.1698 +     * <li>{@code '\u005Cu0660'} through {@code '\u005Cu0669'},
112.1699 +     *     Arabic-Indic digits
112.1700 +     * <li>{@code '\u005Cu06F0'} through {@code '\u005Cu06F9'},
112.1701 +     *     Extended Arabic-Indic digits
112.1702 +     * <li>{@code '\u005Cu0966'} through {@code '\u005Cu096F'},
112.1703 +     *     Devanagari digits
112.1704 +     * <li>{@code '\u005CuFF10'} through {@code '\u005CuFF19'},
112.1705 +     *     Fullwidth digits
112.1706 +     * </ul>
112.1707 +     *
112.1708 +     * Many other character ranges contain digits as well.
112.1709 +     *
112.1710 +     * @param   codePoint the character (Unicode code point) to be tested.
112.1711 +     * @return  {@code true} if the character is a digit;
112.1712 +     *          {@code false} otherwise.
112.1713 +     * @see     Character#forDigit(int, int)
112.1714 +     * @see     Character#getType(int)
112.1715 +     * @since   1.5
112.1716 +     */
112.1717 +    public static boolean isDigit(int codePoint) {
112.1718 +        return fromCodeChars(codePoint).matches("\\d");
112.1719 +    }
112.1720 +    
112.1721 +    @JavaScriptBody(args = "c", body = "return String.fromCharCode(c);")
112.1722 +    private native static String fromCodeChars(int codePoint);
112.1723 +
112.1724 +    /**
112.1725 +     * Determines if a character is defined in Unicode.
112.1726 +     * <p>
112.1727 +     * A character is defined if at least one of the following is true:
112.1728 +     * <ul>
112.1729 +     * <li>It has an entry in the UnicodeData file.
112.1730 +     * <li>It has a value in a range defined by the UnicodeData file.
112.1731 +     * </ul>
112.1732 +     *
112.1733 +     * <p><b>Note:</b> This method cannot handle <a
112.1734 +     * href="#supplementary"> supplementary characters</a>. To support
112.1735 +     * all Unicode characters, including supplementary characters, use
112.1736 +     * the {@link #isDefined(int)} method.
112.1737 +     *
112.1738 +     * @param   ch   the character to be tested
112.1739 +     * @return  {@code true} if the character has a defined meaning
112.1740 +     *          in Unicode; {@code false} otherwise.
112.1741 +     * @see     Character#isDigit(char)
112.1742 +     * @see     Character#isLetter(char)
112.1743 +     * @see     Character#isLetterOrDigit(char)
112.1744 +     * @see     Character#isLowerCase(char)
112.1745 +     * @see     Character#isTitleCase(char)
112.1746 +     * @see     Character#isUpperCase(char)
112.1747 +     * @since   1.0.2
112.1748 +     */
112.1749 +    public static boolean isDefined(char ch) {
112.1750 +        return isDefined((int)ch);
112.1751 +    }
112.1752 +
112.1753 +    /**
112.1754 +     * Determines if a character (Unicode code point) is defined in Unicode.
112.1755 +     * <p>
112.1756 +     * A character is defined if at least one of the following is true:
112.1757 +     * <ul>
112.1758 +     * <li>It has an entry in the UnicodeData file.
112.1759 +     * <li>It has a value in a range defined by the UnicodeData file.
112.1760 +     * </ul>
112.1761 +     *
112.1762 +     * @param   codePoint the character (Unicode code point) to be tested.
112.1763 +     * @return  {@code true} if the character has a defined meaning
112.1764 +     *          in Unicode; {@code false} otherwise.
112.1765 +     * @see     Character#isDigit(int)
112.1766 +     * @see     Character#isLetter(int)
112.1767 +     * @see     Character#isLetterOrDigit(int)
112.1768 +     * @see     Character#isLowerCase(int)
112.1769 +     * @see     Character#isTitleCase(int)
112.1770 +     * @see     Character#isUpperCase(int)
112.1771 +     * @since   1.5
112.1772 +     */
112.1773 +    public static boolean isDefined(int codePoint) {
112.1774 +        return getType(codePoint) != Character.UNASSIGNED;
112.1775 +    }
112.1776 +
112.1777 +    /**
112.1778 +     * Determines if the specified character is a letter.
112.1779 +     * <p>
112.1780 +     * A character is considered to be a letter if its general
112.1781 +     * category type, provided by {@code Character.getType(ch)},
112.1782 +     * is any of the following:
112.1783 +     * <ul>
112.1784 +     * <li> {@code UPPERCASE_LETTER}
112.1785 +     * <li> {@code LOWERCASE_LETTER}
112.1786 +     * <li> {@code TITLECASE_LETTER}
112.1787 +     * <li> {@code MODIFIER_LETTER}
112.1788 +     * <li> {@code OTHER_LETTER}
112.1789 +     * </ul>
112.1790 +     *
112.1791 +     * Not all letters have case. Many characters are
112.1792 +     * letters but are neither uppercase nor lowercase nor titlecase.
112.1793 +     *
112.1794 +     * <p><b>Note:</b> This method cannot handle <a
112.1795 +     * href="#supplementary"> supplementary characters</a>. To support
112.1796 +     * all Unicode characters, including supplementary characters, use
112.1797 +     * the {@link #isLetter(int)} method.
112.1798 +     *
112.1799 +     * @param   ch   the character to be tested.
112.1800 +     * @return  {@code true} if the character is a letter;
112.1801 +     *          {@code false} otherwise.
112.1802 +     * @see     Character#isDigit(char)
112.1803 +     * @see     Character#isJavaIdentifierStart(char)
112.1804 +     * @see     Character#isJavaLetter(char)
112.1805 +     * @see     Character#isJavaLetterOrDigit(char)
112.1806 +     * @see     Character#isLetterOrDigit(char)
112.1807 +     * @see     Character#isLowerCase(char)
112.1808 +     * @see     Character#isTitleCase(char)
112.1809 +     * @see     Character#isUnicodeIdentifierStart(char)
112.1810 +     * @see     Character#isUpperCase(char)
112.1811 +     */
112.1812 +    public static boolean isLetter(char ch) {
112.1813 +        return String.valueOf(ch).matches("\\w") && !isDigit(ch);
112.1814 +    }
112.1815 +
112.1816 +    /**
112.1817 +     * Determines if the specified character (Unicode code point) is a letter.
112.1818 +     * <p>
112.1819 +     * A character is considered to be a letter if its general
112.1820 +     * category type, provided by {@link Character#getType(int) getType(codePoint)},
112.1821 +     * is any of the following:
112.1822 +     * <ul>
112.1823 +     * <li> {@code UPPERCASE_LETTER}
112.1824 +     * <li> {@code LOWERCASE_LETTER}
112.1825 +     * <li> {@code TITLECASE_LETTER}
112.1826 +     * <li> {@code MODIFIER_LETTER}
112.1827 +     * <li> {@code OTHER_LETTER}
112.1828 +     * </ul>
112.1829 +     *
112.1830 +     * Not all letters have case. Many characters are
112.1831 +     * letters but are neither uppercase nor lowercase nor titlecase.
112.1832 +     *
112.1833 +     * @param   codePoint the character (Unicode code point) to be tested.
112.1834 +     * @return  {@code true} if the character is a letter;
112.1835 +     *          {@code false} otherwise.
112.1836 +     * @see     Character#isDigit(int)
112.1837 +     * @see     Character#isJavaIdentifierStart(int)
112.1838 +     * @see     Character#isLetterOrDigit(int)
112.1839 +     * @see     Character#isLowerCase(int)
112.1840 +     * @see     Character#isTitleCase(int)
112.1841 +     * @see     Character#isUnicodeIdentifierStart(int)
112.1842 +     * @see     Character#isUpperCase(int)
112.1843 +     * @since   1.5
112.1844 +     */
112.1845 +    public static boolean isLetter(int codePoint) {
112.1846 +        return fromCodeChars(codePoint).matches("\\w") && !isDigit(codePoint);
112.1847 +    }
112.1848 +
112.1849 +    /**
112.1850 +     * Determines if the specified character is a letter or digit.
112.1851 +     * <p>
112.1852 +     * A character is considered to be a letter or digit if either
112.1853 +     * {@code Character.isLetter(char ch)} or
112.1854 +     * {@code Character.isDigit(char ch)} returns
112.1855 +     * {@code true} for the character.
112.1856 +     *
112.1857 +     * <p><b>Note:</b> This method cannot handle <a
112.1858 +     * href="#supplementary"> supplementary characters</a>. To support
112.1859 +     * all Unicode characters, including supplementary characters, use
112.1860 +     * the {@link #isLetterOrDigit(int)} method.
112.1861 +     *
112.1862 +     * @param   ch   the character to be tested.
112.1863 +     * @return  {@code true} if the character is a letter or digit;
112.1864 +     *          {@code false} otherwise.
112.1865 +     * @see     Character#isDigit(char)
112.1866 +     * @see     Character#isJavaIdentifierPart(char)
112.1867 +     * @see     Character#isJavaLetter(char)
112.1868 +     * @see     Character#isJavaLetterOrDigit(char)
112.1869 +     * @see     Character#isLetter(char)
112.1870 +     * @see     Character#isUnicodeIdentifierPart(char)
112.1871 +     * @since   1.0.2
112.1872 +     */
112.1873 +    public static boolean isLetterOrDigit(char ch) {
112.1874 +        return String.valueOf(ch).matches("\\w");
112.1875 +    }
112.1876 +
112.1877 +    /**
112.1878 +     * Determines if the specified character (Unicode code point) is a letter or digit.
112.1879 +     * <p>
112.1880 +     * A character is considered to be a letter or digit if either
112.1881 +     * {@link #isLetter(int) isLetter(codePoint)} or
112.1882 +     * {@link #isDigit(int) isDigit(codePoint)} returns
112.1883 +     * {@code true} for the character.
112.1884 +     *
112.1885 +     * @param   codePoint the character (Unicode code point) to be tested.
112.1886 +     * @return  {@code true} if the character is a letter or digit;
112.1887 +     *          {@code false} otherwise.
112.1888 +     * @see     Character#isDigit(int)
112.1889 +     * @see     Character#isJavaIdentifierPart(int)
112.1890 +     * @see     Character#isLetter(int)
112.1891 +     * @see     Character#isUnicodeIdentifierPart(int)
112.1892 +     * @since   1.5
112.1893 +     */
112.1894 +    public static boolean isLetterOrDigit(int codePoint) {
112.1895 +        return fromCodeChars(codePoint).matches("\\w");
112.1896 +    }
112.1897 +    
112.1898 +    static int getType(int x) {
112.1899 +        throw new UnsupportedOperationException();
112.1900 +    }
112.1901 + 
112.1902 +    /**
112.1903 +     * Determines if the specified character is
112.1904 +     * permissible as the first character in a Java identifier.
112.1905 +     * <p>
112.1906 +     * A character may start a Java identifier if and only if
112.1907 +     * one of the following conditions is true:
112.1908 +     * <ul>
112.1909 +     * <li> {@link #isLetter(char) isLetter(ch)} returns {@code true}
112.1910 +     * <li> {@link #getType(char) getType(ch)} returns {@code LETTER_NUMBER}
112.1911 +     * <li> {@code ch} is a currency symbol (such as {@code '$'})
112.1912 +     * <li> {@code ch} is a connecting punctuation character (such as {@code '_'}).
112.1913 +     * </ul>
112.1914 +     *
112.1915 +     * <p><b>Note:</b> This method cannot handle <a
112.1916 +     * href="#supplementary"> supplementary characters</a>. To support
112.1917 +     * all Unicode characters, including supplementary characters, use
112.1918 +     * the {@link #isJavaIdentifierStart(int)} method.
112.1919 +     *
112.1920 +     * @param   ch the character to be tested.
112.1921 +     * @return  {@code true} if the character may start a Java identifier;
112.1922 +     *          {@code false} otherwise.
112.1923 +     * @see     Character#isJavaIdentifierPart(char)
112.1924 +     * @see     Character#isLetter(char)
112.1925 +     * @see     Character#isUnicodeIdentifierStart(char)
112.1926 +     * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
112.1927 +     * @since   1.1
112.1928 +     */
112.1929 +    public static boolean isJavaIdentifierStart(char ch) {
112.1930 +        return isJavaIdentifierStart((int)ch);
112.1931 +    }
112.1932 +
112.1933 +    /**
112.1934 +     * Determines if the character (Unicode code point) is
112.1935 +     * permissible as the first character in a Java identifier.
112.1936 +     * <p>
112.1937 +     * A character may start a Java identifier if and only if
112.1938 +     * one of the following conditions is true:
112.1939 +     * <ul>
112.1940 +     * <li> {@link #isLetter(int) isLetter(codePoint)}
112.1941 +     *      returns {@code true}
112.1942 +     * <li> {@link #getType(int) getType(codePoint)}
112.1943 +     *      returns {@code LETTER_NUMBER}
112.1944 +     * <li> the referenced character is a currency symbol (such as {@code '$'})
112.1945 +     * <li> the referenced character is a connecting punctuation character
112.1946 +     *      (such as {@code '_'}).
112.1947 +     * </ul>
112.1948 +     *
112.1949 +     * @param   codePoint the character (Unicode code point) to be tested.
112.1950 +     * @return  {@code true} if the character may start a Java identifier;
112.1951 +     *          {@code false} otherwise.
112.1952 +     * @see     Character#isJavaIdentifierPart(int)
112.1953 +     * @see     Character#isLetter(int)
112.1954 +     * @see     Character#isUnicodeIdentifierStart(int)
112.1955 +     * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
112.1956 +     * @since   1.5
112.1957 +     */
112.1958 +    public static boolean isJavaIdentifierStart(int codePoint) {
112.1959 +        return 
112.1960 +            ('A' <= codePoint && codePoint <= 'Z') ||
112.1961 +            ('a' <= codePoint && codePoint <= 'z');
112.1962 +    }
112.1963 +
112.1964 +    /**
112.1965 +     * Determines if the specified character may be part of a Java
112.1966 +     * identifier as other than the first character.
112.1967 +     * <p>
112.1968 +     * A character may be part of a Java identifier if any of the following
112.1969 +     * are true:
112.1970 +     * <ul>
112.1971 +     * <li>  it is a letter
112.1972 +     * <li>  it is a currency symbol (such as {@code '$'})
112.1973 +     * <li>  it is a connecting punctuation character (such as {@code '_'})
112.1974 +     * <li>  it is a digit
112.1975 +     * <li>  it is a numeric letter (such as a Roman numeral character)
112.1976 +     * <li>  it is a combining mark
112.1977 +     * <li>  it is a non-spacing mark
112.1978 +     * <li> {@code isIdentifierIgnorable} returns
112.1979 +     * {@code true} for the character
112.1980 +     * </ul>
112.1981 +     *
112.1982 +     * <p><b>Note:</b> This method cannot handle <a
112.1983 +     * href="#supplementary"> supplementary characters</a>. To support
112.1984 +     * all Unicode characters, including supplementary characters, use
112.1985 +     * the {@link #isJavaIdentifierPart(int)} method.
112.1986 +     *
112.1987 +     * @param   ch      the character to be tested.
112.1988 +     * @return {@code true} if the character may be part of a
112.1989 +     *          Java identifier; {@code false} otherwise.
112.1990 +     * @see     Character#isIdentifierIgnorable(char)
112.1991 +     * @see     Character#isJavaIdentifierStart(char)
112.1992 +     * @see     Character#isLetterOrDigit(char)
112.1993 +     * @see     Character#isUnicodeIdentifierPart(char)
112.1994 +     * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
112.1995 +     * @since   1.1
112.1996 +     */
112.1997 +    public static boolean isJavaIdentifierPart(char ch) {
112.1998 +        return isJavaIdentifierPart((int)ch);
112.1999 +    }
112.2000 +
112.2001 +    /**
112.2002 +     * Determines if the character (Unicode code point) may be part of a Java
112.2003 +     * identifier as other than the first character.
112.2004 +     * <p>
112.2005 +     * A character may be part of a Java identifier if any of the following
112.2006 +     * are true:
112.2007 +     * <ul>
112.2008 +     * <li>  it is a letter
112.2009 +     * <li>  it is a currency symbol (such as {@code '$'})
112.2010 +     * <li>  it is a connecting punctuation character (such as {@code '_'})
112.2011 +     * <li>  it is a digit
112.2012 +     * <li>  it is a numeric letter (such as a Roman numeral character)
112.2013 +     * <li>  it is a combining mark
112.2014 +     * <li>  it is a non-spacing mark
112.2015 +     * <li> {@link #isIdentifierIgnorable(int)
112.2016 +     * isIdentifierIgnorable(codePoint)} returns {@code true} for
112.2017 +     * the character
112.2018 +     * </ul>
112.2019 +     *
112.2020 +     * @param   codePoint the character (Unicode code point) to be tested.
112.2021 +     * @return {@code true} if the character may be part of a
112.2022 +     *          Java identifier; {@code false} otherwise.
112.2023 +     * @see     Character#isIdentifierIgnorable(int)
112.2024 +     * @see     Character#isJavaIdentifierStart(int)
112.2025 +     * @see     Character#isLetterOrDigit(int)
112.2026 +     * @see     Character#isUnicodeIdentifierPart(int)
112.2027 +     * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
112.2028 +     * @since   1.5
112.2029 +     */
112.2030 +    public static boolean isJavaIdentifierPart(int codePoint) {
112.2031 +        return isJavaIdentifierStart(codePoint) ||
112.2032 +            ('0' <= codePoint && codePoint <= '9') || codePoint == '$';
112.2033 +    }
112.2034 +   
112.2035 +    /**
112.2036 +     * Converts the character argument to lowercase using case
112.2037 +     * mapping information from the UnicodeData file.
112.2038 +     * <p>
112.2039 +     * Note that
112.2040 +     * {@code Character.isLowerCase(Character.toLowerCase(ch))}
112.2041 +     * does not always return {@code true} for some ranges of
112.2042 +     * characters, particularly those that are symbols or ideographs.
112.2043 +     *
112.2044 +     * <p>In general, {@link String#toLowerCase()} should be used to map
112.2045 +     * characters to lowercase. {@code String} case mapping methods
112.2046 +     * have several benefits over {@code Character} case mapping methods.
112.2047 +     * {@code String} case mapping methods can perform locale-sensitive
112.2048 +     * mappings, context-sensitive mappings, and 1:M character mappings, whereas
112.2049 +     * the {@code Character} case mapping methods cannot.
112.2050 +     *
112.2051 +     * <p><b>Note:</b> This method cannot handle <a
112.2052 +     * href="#supplementary"> supplementary characters</a>. To support
112.2053 +     * all Unicode characters, including supplementary characters, use
112.2054 +     * the {@link #toLowerCase(int)} method.
112.2055 +     *
112.2056 +     * @param   ch   the character to be converted.
112.2057 +     * @return  the lowercase equivalent of the character, if any;
112.2058 +     *          otherwise, the character itself.
112.2059 +     * @see     Character#isLowerCase(char)
112.2060 +     * @see     String#toLowerCase()
112.2061 +     */
112.2062 +    public static char toLowerCase(char ch) {
112.2063 +        return String.valueOf(ch).toLowerCase().charAt(0);
112.2064 +    }
112.2065 +
112.2066 +    /**
112.2067 +     * Converts the character argument to uppercase using case mapping
112.2068 +     * information from the UnicodeData file.
112.2069 +     * <p>
112.2070 +     * Note that
112.2071 +     * {@code Character.isUpperCase(Character.toUpperCase(ch))}
112.2072 +     * does not always return {@code true} for some ranges of
112.2073 +     * characters, particularly those that are symbols or ideographs.
112.2074 +     *
112.2075 +     * <p>In general, {@link String#toUpperCase()} should be used to map
112.2076 +     * characters to uppercase. {@code String} case mapping methods
112.2077 +     * have several benefits over {@code Character} case mapping methods.
112.2078 +     * {@code String} case mapping methods can perform locale-sensitive
112.2079 +     * mappings, context-sensitive mappings, and 1:M character mappings, whereas
112.2080 +     * the {@code Character} case mapping methods cannot.
112.2081 +     *
112.2082 +     * <p><b>Note:</b> This method cannot handle <a
112.2083 +     * href="#supplementary"> supplementary characters</a>. To support
112.2084 +     * all Unicode characters, including supplementary characters, use
112.2085 +     * the {@link #toUpperCase(int)} method.
112.2086 +     *
112.2087 +     * @param   ch   the character to be converted.
112.2088 +     * @return  the uppercase equivalent of the character, if any;
112.2089 +     *          otherwise, the character itself.
112.2090 +     * @see     Character#isUpperCase(char)
112.2091 +     * @see     String#toUpperCase()
112.2092 +     */
112.2093 +    public static char toUpperCase(char ch) {
112.2094 +        return String.valueOf(ch).toUpperCase().charAt(0);
112.2095 +    }
112.2096 +
112.2097 +    /**
112.2098 +     * Returns the numeric value of the character {@code ch} in the
112.2099 +     * specified radix.
112.2100 +     * <p>
112.2101 +     * If the radix is not in the range {@code MIN_RADIX} &le;
112.2102 +     * {@code radix} &le; {@code MAX_RADIX} or if the
112.2103 +     * value of {@code ch} is not a valid digit in the specified
112.2104 +     * radix, {@code -1} is returned. A character is a valid digit
112.2105 +     * if at least one of the following is true:
112.2106 +     * <ul>
112.2107 +     * <li>The method {@code isDigit} is {@code true} of the character
112.2108 +     *     and the Unicode decimal digit value of the character (or its
112.2109 +     *     single-character decomposition) is less than the specified radix.
112.2110 +     *     In this case the decimal digit value is returned.
112.2111 +     * <li>The character is one of the uppercase Latin letters
112.2112 +     *     {@code 'A'} through {@code 'Z'} and its code is less than
112.2113 +     *     {@code radix + 'A' - 10}.
112.2114 +     *     In this case, {@code ch - 'A' + 10}
112.2115 +     *     is returned.
112.2116 +     * <li>The character is one of the lowercase Latin letters
112.2117 +     *     {@code 'a'} through {@code 'z'} and its code is less than
112.2118 +     *     {@code radix + 'a' - 10}.
112.2119 +     *     In this case, {@code ch - 'a' + 10}
112.2120 +     *     is returned.
112.2121 +     * <li>The character is one of the fullwidth uppercase Latin letters A
112.2122 +     *     ({@code '\u005CuFF21'}) through Z ({@code '\u005CuFF3A'})
112.2123 +     *     and its code is less than
112.2124 +     *     {@code radix + '\u005CuFF21' - 10}.
112.2125 +     *     In this case, {@code ch - '\u005CuFF21' + 10}
112.2126 +     *     is returned.
112.2127 +     * <li>The character is one of the fullwidth lowercase Latin letters a
112.2128 +     *     ({@code '\u005CuFF41'}) through z ({@code '\u005CuFF5A'})
112.2129 +     *     and its code is less than
112.2130 +     *     {@code radix + '\u005CuFF41' - 10}.
112.2131 +     *     In this case, {@code ch - '\u005CuFF41' + 10}
112.2132 +     *     is returned.
112.2133 +     * </ul>
112.2134 +     *
112.2135 +     * <p><b>Note:</b> This method cannot handle <a
112.2136 +     * href="#supplementary"> supplementary characters</a>. To support
112.2137 +     * all Unicode characters, including supplementary characters, use
112.2138 +     * the {@link #digit(int, int)} method.
112.2139 +     *
112.2140 +     * @param   ch      the character to be converted.
112.2141 +     * @param   radix   the radix.
112.2142 +     * @return  the numeric value represented by the character in the
112.2143 +     *          specified radix.
112.2144 +     * @see     Character#forDigit(int, int)
112.2145 +     * @see     Character#isDigit(char)
112.2146 +     */
112.2147 +    public static int digit(char ch, int radix) {
112.2148 +        return digit((int)ch, radix);
112.2149 +    }
112.2150 +
112.2151 +    /**
112.2152 +     * Returns the numeric value of the specified character (Unicode
112.2153 +     * code point) in the specified radix.
112.2154 +     *
112.2155 +     * <p>If the radix is not in the range {@code MIN_RADIX} &le;
112.2156 +     * {@code radix} &le; {@code MAX_RADIX} or if the
112.2157 +     * character is not a valid digit in the specified
112.2158 +     * radix, {@code -1} is returned. A character is a valid digit
112.2159 +     * if at least one of the following is true:
112.2160 +     * <ul>
112.2161 +     * <li>The method {@link #isDigit(int) isDigit(codePoint)} is {@code true} of the character
112.2162 +     *     and the Unicode decimal digit value of the character (or its
112.2163 +     *     single-character decomposition) is less than the specified radix.
112.2164 +     *     In this case the decimal digit value is returned.
112.2165 +     * <li>The character is one of the uppercase Latin letters
112.2166 +     *     {@code 'A'} through {@code 'Z'} and its code is less than
112.2167 +     *     {@code radix + 'A' - 10}.
112.2168 +     *     In this case, {@code codePoint - 'A' + 10}
112.2169 +     *     is returned.
112.2170 +     * <li>The character is one of the lowercase Latin letters
112.2171 +     *     {@code 'a'} through {@code 'z'} and its code is less than
112.2172 +     *     {@code radix + 'a' - 10}.
112.2173 +     *     In this case, {@code codePoint - 'a' + 10}
112.2174 +     *     is returned.
112.2175 +     * <li>The character is one of the fullwidth uppercase Latin letters A
112.2176 +     *     ({@code '\u005CuFF21'}) through Z ({@code '\u005CuFF3A'})
112.2177 +     *     and its code is less than
112.2178 +     *     {@code radix + '\u005CuFF21' - 10}.
112.2179 +     *     In this case,
112.2180 +     *     {@code codePoint - '\u005CuFF21' + 10}
112.2181 +     *     is returned.
112.2182 +     * <li>The character is one of the fullwidth lowercase Latin letters a
112.2183 +     *     ({@code '\u005CuFF41'}) through z ({@code '\u005CuFF5A'})
112.2184 +     *     and its code is less than
112.2185 +     *     {@code radix + '\u005CuFF41'- 10}.
112.2186 +     *     In this case,
112.2187 +     *     {@code codePoint - '\u005CuFF41' + 10}
112.2188 +     *     is returned.
112.2189 +     * </ul>
112.2190 +     *
112.2191 +     * @param   codePoint the character (Unicode code point) to be converted.
112.2192 +     * @param   radix   the radix.
112.2193 +     * @return  the numeric value represented by the character in the
112.2194 +     *          specified radix.
112.2195 +     * @see     Character#forDigit(int, int)
112.2196 +     * @see     Character#isDigit(int)
112.2197 +     * @since   1.5
112.2198 +     */
112.2199 +    public static int digit(int codePoint, int radix) {
112.2200 +        throw new UnsupportedOperationException();
112.2201 +    }
112.2202 +
112.2203 +    /**
112.2204 +     * Returns the {@code int} value that the specified Unicode
112.2205 +     * character represents. For example, the character
112.2206 +     * {@code '\u005Cu216C'} (the roman numeral fifty) will return
112.2207 +     * an int with a value of 50.
112.2208 +     * <p>
112.2209 +     * The letters A-Z in their uppercase ({@code '\u005Cu0041'} through
112.2210 +     * {@code '\u005Cu005A'}), lowercase
112.2211 +     * ({@code '\u005Cu0061'} through {@code '\u005Cu007A'}), and
112.2212 +     * full width variant ({@code '\u005CuFF21'} through
112.2213 +     * {@code '\u005CuFF3A'} and {@code '\u005CuFF41'} through
112.2214 +     * {@code '\u005CuFF5A'}) forms have numeric values from 10
112.2215 +     * through 35. This is independent of the Unicode specification,
112.2216 +     * which does not assign numeric values to these {@code char}
112.2217 +     * values.
112.2218 +     * <p>
112.2219 +     * If the character does not have a numeric value, then -1 is returned.
112.2220 +     * If the character has a numeric value that cannot be represented as a
112.2221 +     * nonnegative integer (for example, a fractional value), then -2
112.2222 +     * is returned.
112.2223 +     *
112.2224 +     * <p><b>Note:</b> This method cannot handle <a
112.2225 +     * href="#supplementary"> supplementary characters</a>. To support
112.2226 +     * all Unicode characters, including supplementary characters, use
112.2227 +     * the {@link #getNumericValue(int)} method.
112.2228 +     *
112.2229 +     * @param   ch      the character to be converted.
112.2230 +     * @return  the numeric value of the character, as a nonnegative {@code int}
112.2231 +     *           value; -2 if the character has a numeric value that is not a
112.2232 +     *          nonnegative integer; -1 if the character has no numeric value.
112.2233 +     * @see     Character#forDigit(int, int)
112.2234 +     * @see     Character#isDigit(char)
112.2235 +     * @since   1.1
112.2236 +     */
112.2237 +    public static int getNumericValue(char ch) {
112.2238 +        return getNumericValue((int)ch);
112.2239 +    }
112.2240 +
112.2241 +    /**
112.2242 +     * Returns the {@code int} value that the specified
112.2243 +     * character (Unicode code point) represents. For example, the character
112.2244 +     * {@code '\u005Cu216C'} (the Roman numeral fifty) will return
112.2245 +     * an {@code int} with a value of 50.
112.2246 +     * <p>
112.2247 +     * The letters A-Z in their uppercase ({@code '\u005Cu0041'} through
112.2248 +     * {@code '\u005Cu005A'}), lowercase
112.2249 +     * ({@code '\u005Cu0061'} through {@code '\u005Cu007A'}), and
112.2250 +     * full width variant ({@code '\u005CuFF21'} through
112.2251 +     * {@code '\u005CuFF3A'} and {@code '\u005CuFF41'} through
112.2252 +     * {@code '\u005CuFF5A'}) forms have numeric values from 10
112.2253 +     * through 35. This is independent of the Unicode specification,
112.2254 +     * which does not assign numeric values to these {@code char}
112.2255 +     * values.
112.2256 +     * <p>
112.2257 +     * If the character does not have a numeric value, then -1 is returned.
112.2258 +     * If the character has a numeric value that cannot be represented as a
112.2259 +     * nonnegative integer (for example, a fractional value), then -2
112.2260 +     * is returned.
112.2261 +     *
112.2262 +     * @param   codePoint the character (Unicode code point) to be converted.
112.2263 +     * @return  the numeric value of the character, as a nonnegative {@code int}
112.2264 +     *          value; -2 if the character has a numeric value that is not a
112.2265 +     *          nonnegative integer; -1 if the character has no numeric value.
112.2266 +     * @see     Character#forDigit(int, int)
112.2267 +     * @see     Character#isDigit(int)
112.2268 +     * @since   1.5
112.2269 +     */
112.2270 +    public static int getNumericValue(int codePoint) {
112.2271 +        throw new UnsupportedOperationException();
112.2272 +    }
112.2273 +
112.2274 +    /**
112.2275 +     * Determines if the specified character is ISO-LATIN-1 white space.
112.2276 +     * This method returns {@code true} for the following five
112.2277 +     * characters only:
112.2278 +     * <table>
112.2279 +     * <tr><td>{@code '\t'}</td>            <td>{@code U+0009}</td>
112.2280 +     *     <td>{@code HORIZONTAL TABULATION}</td></tr>
112.2281 +     * <tr><td>{@code '\n'}</td>            <td>{@code U+000A}</td>
112.2282 +     *     <td>{@code NEW LINE}</td></tr>
112.2283 +     * <tr><td>{@code '\f'}</td>            <td>{@code U+000C}</td>
112.2284 +     *     <td>{@code FORM FEED}</td></tr>
112.2285 +     * <tr><td>{@code '\r'}</td>            <td>{@code U+000D}</td>
112.2286 +     *     <td>{@code CARRIAGE RETURN}</td></tr>
112.2287 +     * <tr><td>{@code '&nbsp;'}</td>  <td>{@code U+0020}</td>
112.2288 +     *     <td>{@code SPACE}</td></tr>
112.2289 +     * </table>
112.2290 +     *
112.2291 +     * @param      ch   the character to be tested.
112.2292 +     * @return     {@code true} if the character is ISO-LATIN-1 white
112.2293 +     *             space; {@code false} otherwise.
112.2294 +     * @see        Character#isSpaceChar(char)
112.2295 +     * @see        Character#isWhitespace(char)
112.2296 +     * @deprecated Replaced by isWhitespace(char).
112.2297 +     */
112.2298 +    @Deprecated
112.2299 +    public static boolean isSpace(char ch) {
112.2300 +        return (ch <= 0x0020) &&
112.2301 +            (((((1L << 0x0009) |
112.2302 +            (1L << 0x000A) |
112.2303 +            (1L << 0x000C) |
112.2304 +            (1L << 0x000D) |
112.2305 +            (1L << 0x0020)) >> ch) & 1L) != 0);
112.2306 +    }
112.2307 +
112.2308 +
112.2309 +
112.2310 +    /**
112.2311 +     * Determines if the specified character is white space according to Java.
112.2312 +     * A character is a Java whitespace character if and only if it satisfies
112.2313 +     * one of the following criteria:
112.2314 +     * <ul>
112.2315 +     * <li> It is a Unicode space character ({@code SPACE_SEPARATOR},
112.2316 +     *      {@code LINE_SEPARATOR}, or {@code PARAGRAPH_SEPARATOR})
112.2317 +     *      but is not also a non-breaking space ({@code '\u005Cu00A0'},
112.2318 +     *      {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).
112.2319 +     * <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.
112.2320 +     * <li> It is {@code '\u005Cn'}, U+000A LINE FEED.
112.2321 +     * <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.
112.2322 +     * <li> It is {@code '\u005Cf'}, U+000C FORM FEED.
112.2323 +     * <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.
112.2324 +     * <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.
112.2325 +     * <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.
112.2326 +     * <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.
112.2327 +     * <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.
112.2328 +     * </ul>
112.2329 +     *
112.2330 +     * <p><b>Note:</b> This method cannot handle <a
112.2331 +     * href="#supplementary"> supplementary characters</a>. To support
112.2332 +     * all Unicode characters, including supplementary characters, use
112.2333 +     * the {@link #isWhitespace(int)} method.
112.2334 +     *
112.2335 +     * @param   ch the character to be tested.
112.2336 +     * @return  {@code true} if the character is a Java whitespace
112.2337 +     *          character; {@code false} otherwise.
112.2338 +     * @see     Character#isSpaceChar(char)
112.2339 +     * @since   1.1
112.2340 +     */
112.2341 +    public static boolean isWhitespace(char ch) {
112.2342 +        return isWhitespace((int)ch);
112.2343 +    }
112.2344 +
112.2345 +    /**
112.2346 +     * Determines if the specified character (Unicode code point) is
112.2347 +     * white space according to Java.  A character is a Java
112.2348 +     * whitespace character if and only if it satisfies one of the
112.2349 +     * following criteria:
112.2350 +     * <ul>
112.2351 +     * <li> It is a Unicode space character ({@link #SPACE_SEPARATOR},
112.2352 +     *      {@link #LINE_SEPARATOR}, or {@link #PARAGRAPH_SEPARATOR})
112.2353 +     *      but is not also a non-breaking space ({@code '\u005Cu00A0'},
112.2354 +     *      {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).
112.2355 +     * <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.
112.2356 +     * <li> It is {@code '\u005Cn'}, U+000A LINE FEED.
112.2357 +     * <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.
112.2358 +     * <li> It is {@code '\u005Cf'}, U+000C FORM FEED.
112.2359 +     * <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.
112.2360 +     * <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.
112.2361 +     * <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.
112.2362 +     * <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.
112.2363 +     * <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.
112.2364 +     * </ul>
112.2365 +     * <p>
112.2366 +     *
112.2367 +     * @param   codePoint the character (Unicode code point) to be tested.
112.2368 +     * @return  {@code true} if the character is a Java whitespace
112.2369 +     *          character; {@code false} otherwise.
112.2370 +     * @see     Character#isSpaceChar(int)
112.2371 +     * @since   1.5
112.2372 +     */
112.2373 +    public static boolean isWhitespace(int codePoint) {
112.2374 +        throw new UnsupportedOperationException();
112.2375 +    }
112.2376 +
112.2377 +    /**
112.2378 +     * Determines if the specified character is an ISO control
112.2379 +     * character.  A character is considered to be an ISO control
112.2380 +     * character if its code is in the range {@code '\u005Cu0000'}
112.2381 +     * through {@code '\u005Cu001F'} or in the range
112.2382 +     * {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.
112.2383 +     *
112.2384 +     * <p><b>Note:</b> This method cannot handle <a
112.2385 +     * href="#supplementary"> supplementary characters</a>. To support
112.2386 +     * all Unicode characters, including supplementary characters, use
112.2387 +     * the {@link #isISOControl(int)} method.
112.2388 +     *
112.2389 +     * @param   ch      the character to be tested.
112.2390 +     * @return  {@code true} if the character is an ISO control character;
112.2391 +     *          {@code false} otherwise.
112.2392 +     *
112.2393 +     * @see     Character#isSpaceChar(char)
112.2394 +     * @see     Character#isWhitespace(char)
112.2395 +     * @since   1.1
112.2396 +     */
112.2397 +    public static boolean isISOControl(char ch) {
112.2398 +        return isISOControl((int)ch);
112.2399 +    }
112.2400 +
112.2401 +    /**
112.2402 +     * Determines if the referenced character (Unicode code point) is an ISO control
112.2403 +     * character.  A character is considered to be an ISO control
112.2404 +     * character if its code is in the range {@code '\u005Cu0000'}
112.2405 +     * through {@code '\u005Cu001F'} or in the range
112.2406 +     * {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.
112.2407 +     *
112.2408 +     * @param   codePoint the character (Unicode code point) to be tested.
112.2409 +     * @return  {@code true} if the character is an ISO control character;
112.2410 +     *          {@code false} otherwise.
112.2411 +     * @see     Character#isSpaceChar(int)
112.2412 +     * @see     Character#isWhitespace(int)
112.2413 +     * @since   1.5
112.2414 +     */
112.2415 +    public static boolean isISOControl(int codePoint) {
112.2416 +        // Optimized form of:
112.2417 +        //     (codePoint >= 0x00 && codePoint <= 0x1F) ||
112.2418 +        //     (codePoint >= 0x7F && codePoint <= 0x9F);
112.2419 +        return codePoint <= 0x9F &&
112.2420 +            (codePoint >= 0x7F || (codePoint >>> 5 == 0));
112.2421 +    }
112.2422 +
112.2423 +    /**
112.2424 +     * Determines the character representation for a specific digit in
112.2425 +     * the specified radix. If the value of {@code radix} is not a
112.2426 +     * valid radix, or the value of {@code digit} is not a valid
112.2427 +     * digit in the specified radix, the null character
112.2428 +     * ({@code '\u005Cu0000'}) is returned.
112.2429 +     * <p>
112.2430 +     * The {@code radix} argument is valid if it is greater than or
112.2431 +     * equal to {@code MIN_RADIX} and less than or equal to
112.2432 +     * {@code MAX_RADIX}. The {@code digit} argument is valid if
112.2433 +     * {@code 0 <= digit < radix}.
112.2434 +     * <p>
112.2435 +     * If the digit is less than 10, then
112.2436 +     * {@code '0' + digit} is returned. Otherwise, the value
112.2437 +     * {@code 'a' + digit - 10} is returned.
112.2438 +     *
112.2439 +     * @param   digit   the number to convert to a character.
112.2440 +     * @param   radix   the radix.
112.2441 +     * @return  the {@code char} representation of the specified digit
112.2442 +     *          in the specified radix.
112.2443 +     * @see     Character#MIN_RADIX
112.2444 +     * @see     Character#MAX_RADIX
112.2445 +     * @see     Character#digit(char, int)
112.2446 +     */
112.2447 +    public static char forDigit(int digit, int radix) {
112.2448 +        if ((digit >= radix) || (digit < 0)) {
112.2449 +            return '\0';
112.2450 +        }
112.2451 +        if ((radix < Character.MIN_RADIX) || (radix > Character.MAX_RADIX)) {
112.2452 +            return '\0';
112.2453 +        }
112.2454 +        if (digit < 10) {
112.2455 +            return (char)('0' + digit);
112.2456 +        }
112.2457 +        return (char)('a' - 10 + digit);
112.2458 +    }
112.2459 +
112.2460 +    /**
112.2461 +     * Compares two {@code Character} objects numerically.
112.2462 +     *
112.2463 +     * @param   anotherCharacter   the {@code Character} to be compared.
112.2464 +
112.2465 +     * @return  the value {@code 0} if the argument {@code Character}
112.2466 +     *          is equal to this {@code Character}; a value less than
112.2467 +     *          {@code 0} if this {@code Character} is numerically less
112.2468 +     *          than the {@code Character} argument; and a value greater than
112.2469 +     *          {@code 0} if this {@code Character} is numerically greater
112.2470 +     *          than the {@code Character} argument (unsigned comparison).
112.2471 +     *          Note that this is strictly a numerical comparison; it is not
112.2472 +     *          locale-dependent.
112.2473 +     * @since   1.2
112.2474 +     */
112.2475 +    public int compareTo(Character anotherCharacter) {
112.2476 +        return compare(this.value, anotherCharacter.value);
112.2477 +    }
112.2478 +
112.2479 +    /**
112.2480 +     * Compares two {@code char} values numerically.
112.2481 +     * The value returned is identical to what would be returned by:
112.2482 +     * <pre>
112.2483 +     *    Character.valueOf(x).compareTo(Character.valueOf(y))
112.2484 +     * </pre>
112.2485 +     *
112.2486 +     * @param  x the first {@code char} to compare
112.2487 +     * @param  y the second {@code char} to compare
112.2488 +     * @return the value {@code 0} if {@code x == y};
112.2489 +     *         a value less than {@code 0} if {@code x < y}; and
112.2490 +     *         a value greater than {@code 0} if {@code x > y}
112.2491 +     * @since 1.7
112.2492 +     */
112.2493 +    public static int compare(char x, char y) {
112.2494 +        return x - y;
112.2495 +    }
112.2496 +
112.2497 +
112.2498 +    /**
112.2499 +     * The number of bits used to represent a <tt>char</tt> value in unsigned
112.2500 +     * binary form, constant {@code 16}.
112.2501 +     *
112.2502 +     * @since 1.5
112.2503 +     */
112.2504 +    public static final int SIZE = 16;
112.2505 +
112.2506 +    /**
112.2507 +     * Returns the value obtained by reversing the order of the bytes in the
112.2508 +     * specified <tt>char</tt> value.
112.2509 +     *
112.2510 +     * @return the value obtained by reversing (or, equivalently, swapping)
112.2511 +     *     the bytes in the specified <tt>char</tt> value.
112.2512 +     * @since 1.5
112.2513 +     */
112.2514 +    public static char reverseBytes(char ch) {
112.2515 +        return (char) (((ch & 0xFF00) >> 8) | (ch << 8));
112.2516 +    }
112.2517 +
112.2518 +}
   113.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   113.2 +++ b/emul/mini/src/main/java/java/lang/Class.java	Sun Feb 03 07:48:42 2013 +0100
   113.3 @@ -0,0 +1,1295 @@
   113.4 +/*
   113.5 + * Copyright (c) 1994, 2010, 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 +import java.io.ByteArrayInputStream;
  113.32 +import org.apidesign.bck2brwsr.emul.reflect.AnnotationImpl;
  113.33 +import java.io.InputStream;
  113.34 +import java.lang.annotation.Annotation;
  113.35 +import java.lang.reflect.Field;
  113.36 +import java.lang.reflect.Method;
  113.37 +import java.lang.reflect.TypeVariable;
  113.38 +import java.net.URL;
  113.39 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  113.40 +import org.apidesign.bck2brwsr.emul.reflect.MethodImpl;
  113.41 +
  113.42 +/**
  113.43 + * Instances of the class {@code Class} represent classes and
  113.44 + * interfaces in a running Java application.  An enum is a kind of
  113.45 + * class and an annotation is a kind of interface.  Every array also
  113.46 + * belongs to a class that is reflected as a {@code Class} object
  113.47 + * that is shared by all arrays with the same element type and number
  113.48 + * of dimensions.  The primitive Java types ({@code boolean},
  113.49 + * {@code byte}, {@code char}, {@code short},
  113.50 + * {@code int}, {@code long}, {@code float}, and
  113.51 + * {@code double}), and the keyword {@code void} are also
  113.52 + * represented as {@code Class} objects.
  113.53 + *
  113.54 + * <p> {@code Class} has no public constructor. Instead {@code Class}
  113.55 + * objects are constructed automatically by the Java Virtual Machine as classes
  113.56 + * are loaded and by calls to the {@code defineClass} method in the class
  113.57 + * loader.
  113.58 + *
  113.59 + * <p> The following example uses a {@code Class} object to print the
  113.60 + * class name of an object:
  113.61 + *
  113.62 + * <p> <blockquote><pre>
  113.63 + *     void printClassName(Object obj) {
  113.64 + *         System.out.println("The class of " + obj +
  113.65 + *                            " is " + obj.getClass().getName());
  113.66 + *     }
  113.67 + * </pre></blockquote>
  113.68 + *
  113.69 + * <p> It is also possible to get the {@code Class} object for a named
  113.70 + * type (or for void) using a class literal.  See Section 15.8.2 of
  113.71 + * <cite>The Java&trade; Language Specification</cite>.
  113.72 + * For example:
  113.73 + *
  113.74 + * <p> <blockquote>
  113.75 + *     {@code System.out.println("The name of class Foo is: "+Foo.class.getName());}
  113.76 + * </blockquote>
  113.77 + *
  113.78 + * @param <T> the type of the class modeled by this {@code Class}
  113.79 + * object.  For example, the type of {@code String.class} is {@code
  113.80 + * Class<String>}.  Use {@code Class<?>} if the class being modeled is
  113.81 + * unknown.
  113.82 + *
  113.83 + * @author  unascribed
  113.84 + * @see     java.lang.ClassLoader#defineClass(byte[], int, int)
  113.85 + * @since   JDK1.0
  113.86 + */
  113.87 +public final
  113.88 +    class Class<T> implements java.io.Serializable,
  113.89 +                              java.lang.reflect.GenericDeclaration,
  113.90 +                              java.lang.reflect.Type,
  113.91 +                              java.lang.reflect.AnnotatedElement {
  113.92 +    private static final int ANNOTATION= 0x00002000;
  113.93 +    private static final int ENUM      = 0x00004000;
  113.94 +    private static final int SYNTHETIC = 0x00001000;
  113.95 +
  113.96 +    /*
  113.97 +     * Constructor. Only the Java Virtual Machine creates Class
  113.98 +     * objects.
  113.99 +     */
 113.100 +    private Class() {}
 113.101 +
 113.102 +
 113.103 +    /**
 113.104 +     * Converts the object to a string. The string representation is the
 113.105 +     * string "class" or "interface", followed by a space, and then by the
 113.106 +     * fully qualified name of the class in the format returned by
 113.107 +     * {@code getName}.  If this {@code Class} object represents a
 113.108 +     * primitive type, this method returns the name of the primitive type.  If
 113.109 +     * this {@code Class} object represents void this method returns
 113.110 +     * "void".
 113.111 +     *
 113.112 +     * @return a string representation of this class object.
 113.113 +     */
 113.114 +    public String toString() {
 113.115 +        return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
 113.116 +            + getName();
 113.117 +    }
 113.118 +
 113.119 +
 113.120 +    /**
 113.121 +     * Returns the {@code Class} object associated with the class or
 113.122 +     * interface with the given string name.  Invoking this method is
 113.123 +     * equivalent to:
 113.124 +     *
 113.125 +     * <blockquote>
 113.126 +     *  {@code Class.forName(className, true, currentLoader)}
 113.127 +     * </blockquote>
 113.128 +     *
 113.129 +     * where {@code currentLoader} denotes the defining class loader of
 113.130 +     * the current class.
 113.131 +     *
 113.132 +     * <p> For example, the following code fragment returns the
 113.133 +     * runtime {@code Class} descriptor for the class named
 113.134 +     * {@code java.lang.Thread}:
 113.135 +     *
 113.136 +     * <blockquote>
 113.137 +     *   {@code Class t = Class.forName("java.lang.Thread")}
 113.138 +     * </blockquote>
 113.139 +     * <p>
 113.140 +     * A call to {@code forName("X")} causes the class named
 113.141 +     * {@code X} to be initialized.
 113.142 +     *
 113.143 +     * @param      className   the fully qualified name of the desired class.
 113.144 +     * @return     the {@code Class} object for the class with the
 113.145 +     *             specified name.
 113.146 +     * @exception LinkageError if the linkage fails
 113.147 +     * @exception ExceptionInInitializerError if the initialization provoked
 113.148 +     *            by this method fails
 113.149 +     * @exception ClassNotFoundException if the class cannot be located
 113.150 +     */
 113.151 +    public static Class<?> forName(String className)
 113.152 +    throws ClassNotFoundException {
 113.153 +        if (className.startsWith("[")) {
 113.154 +            Class<?> arrType = defineArray(className);
 113.155 +            Class<?> c = arrType;
 113.156 +            while (c != null && c.isArray()) {
 113.157 +                c = c.getComponentType0(); // verify component type is sane
 113.158 +            }
 113.159 +            return arrType;
 113.160 +        }
 113.161 +        Class<?> c = loadCls(className, className.replace('.', '_'));
 113.162 +        if (c == null) {
 113.163 +            throw new ClassNotFoundException(className);
 113.164 +        }
 113.165 +        return c;
 113.166 +    }
 113.167 +
 113.168 +
 113.169 +    /**
 113.170 +     * Returns the {@code Class} object associated with the class or
 113.171 +     * interface with the given string name, using the given class loader.
 113.172 +     * Given the fully qualified name for a class or interface (in the same
 113.173 +     * format returned by {@code getName}) this method attempts to
 113.174 +     * locate, load, and link the class or interface.  The specified class
 113.175 +     * loader is used to load the class or interface.  If the parameter
 113.176 +     * {@code loader} is null, the class is loaded through the bootstrap
 113.177 +     * class loader.  The class is initialized only if the
 113.178 +     * {@code initialize} parameter is {@code true} and if it has
 113.179 +     * not been initialized earlier.
 113.180 +     *
 113.181 +     * <p> If {@code name} denotes a primitive type or void, an attempt
 113.182 +     * will be made to locate a user-defined class in the unnamed package whose
 113.183 +     * name is {@code name}. Therefore, this method cannot be used to
 113.184 +     * obtain any of the {@code Class} objects representing primitive
 113.185 +     * types or void.
 113.186 +     *
 113.187 +     * <p> If {@code name} denotes an array class, the component type of
 113.188 +     * the array class is loaded but not initialized.
 113.189 +     *
 113.190 +     * <p> For example, in an instance method the expression:
 113.191 +     *
 113.192 +     * <blockquote>
 113.193 +     *  {@code Class.forName("Foo")}
 113.194 +     * </blockquote>
 113.195 +     *
 113.196 +     * is equivalent to:
 113.197 +     *
 113.198 +     * <blockquote>
 113.199 +     *  {@code Class.forName("Foo", true, this.getClass().getClassLoader())}
 113.200 +     * </blockquote>
 113.201 +     *
 113.202 +     * Note that this method throws errors related to loading, linking or
 113.203 +     * initializing as specified in Sections 12.2, 12.3 and 12.4 of <em>The
 113.204 +     * Java Language Specification</em>.
 113.205 +     * Note that this method does not check whether the requested class
 113.206 +     * is accessible to its caller.
 113.207 +     *
 113.208 +     * <p> If the {@code loader} is {@code null}, and a security
 113.209 +     * manager is present, and the caller's class loader is not null, then this
 113.210 +     * method calls the security manager's {@code checkPermission} method
 113.211 +     * with a {@code RuntimePermission("getClassLoader")} permission to
 113.212 +     * ensure it's ok to access the bootstrap class loader.
 113.213 +     *
 113.214 +     * @param name       fully qualified name of the desired class
 113.215 +     * @param initialize whether the class must be initialized
 113.216 +     * @param loader     class loader from which the class must be loaded
 113.217 +     * @return           class object representing the desired class
 113.218 +     *
 113.219 +     * @exception LinkageError if the linkage fails
 113.220 +     * @exception ExceptionInInitializerError if the initialization provoked
 113.221 +     *            by this method fails
 113.222 +     * @exception ClassNotFoundException if the class cannot be located by
 113.223 +     *            the specified class loader
 113.224 +     *
 113.225 +     * @see       java.lang.Class#forName(String)
 113.226 +     * @see       java.lang.ClassLoader
 113.227 +     * @since     1.2
 113.228 +     */
 113.229 +    public static Class<?> forName(String name, boolean initialize,
 113.230 +                                   ClassLoader loader)
 113.231 +        throws ClassNotFoundException
 113.232 +    {
 113.233 +        return forName(name);
 113.234 +    }
 113.235 +    
 113.236 +    @JavaScriptBody(args = {"n", "c" }, body =
 113.237 +        "if (vm[c]) return vm[c].$class;\n"
 113.238 +      + "if (vm.loadClass) {\n"
 113.239 +      + "  vm.loadClass(n);\n"
 113.240 +      + "  if (vm[c]) return vm[c].$class;\n"
 113.241 +      + "}\n"
 113.242 +      + "return null;"
 113.243 +    )
 113.244 +    private static native Class<?> loadCls(String n, String c);
 113.245 +
 113.246 +
 113.247 +    /**
 113.248 +     * Creates a new instance of the class represented by this {@code Class}
 113.249 +     * object.  The class is instantiated as if by a {@code new}
 113.250 +     * expression with an empty argument list.  The class is initialized if it
 113.251 +     * has not already been initialized.
 113.252 +     *
 113.253 +     * <p>Note that this method propagates any exception thrown by the
 113.254 +     * nullary constructor, including a checked exception.  Use of
 113.255 +     * this method effectively bypasses the compile-time exception
 113.256 +     * checking that would otherwise be performed by the compiler.
 113.257 +     * The {@link
 113.258 +     * java.lang.reflect.Constructor#newInstance(java.lang.Object...)
 113.259 +     * Constructor.newInstance} method avoids this problem by wrapping
 113.260 +     * any exception thrown by the constructor in a (checked) {@link
 113.261 +     * java.lang.reflect.InvocationTargetException}.
 113.262 +     *
 113.263 +     * @return     a newly allocated instance of the class represented by this
 113.264 +     *             object.
 113.265 +     * @exception  IllegalAccessException  if the class or its nullary
 113.266 +     *               constructor is not accessible.
 113.267 +     * @exception  InstantiationException
 113.268 +     *               if this {@code Class} represents an abstract class,
 113.269 +     *               an interface, an array class, a primitive type, or void;
 113.270 +     *               or if the class has no nullary constructor;
 113.271 +     *               or if the instantiation fails for some other reason.
 113.272 +     * @exception  ExceptionInInitializerError if the initialization
 113.273 +     *               provoked by this method fails.
 113.274 +     * @exception  SecurityException
 113.275 +     *             If a security manager, <i>s</i>, is present and any of the
 113.276 +     *             following conditions is met:
 113.277 +     *
 113.278 +     *             <ul>
 113.279 +     *
 113.280 +     *             <li> invocation of
 113.281 +     *             {@link SecurityManager#checkMemberAccess
 113.282 +     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 113.283 +     *             creation of new instances of this class
 113.284 +     *
 113.285 +     *             <li> the caller's class loader is not the same as or an
 113.286 +     *             ancestor of the class loader for the current class and
 113.287 +     *             invocation of {@link SecurityManager#checkPackageAccess
 113.288 +     *             s.checkPackageAccess()} denies access to the package
 113.289 +     *             of this class
 113.290 +     *
 113.291 +     *             </ul>
 113.292 +     *
 113.293 +     */
 113.294 +    @JavaScriptBody(args = { "self", "illegal" }, body =
 113.295 +          "\nvar c = self.cnstr;"
 113.296 +        + "\nif (c['cons__V']) {"
 113.297 +        + "\n  if ((c.cons__V.access & 0x1) != 0) {"
 113.298 +        + "\n    var inst = c();"
 113.299 +        + "\n    c.cons__V.call(inst);"
 113.300 +        + "\n    return inst;"
 113.301 +        + "\n  }"
 113.302 +        + "\n  return illegal;"
 113.303 +        + "\n}"
 113.304 +        + "\nreturn null;"
 113.305 +    )
 113.306 +    private static native Object newInstance0(Class<?> self, Object illegal);
 113.307 +    
 113.308 +    public T newInstance()
 113.309 +        throws InstantiationException, IllegalAccessException
 113.310 +    {
 113.311 +        Object illegal = new Object();
 113.312 +        Object inst = newInstance0(this, illegal);
 113.313 +        if (inst == null) {
 113.314 +            throw new InstantiationException(getName());
 113.315 +        }
 113.316 +        if (inst == illegal) {
 113.317 +            throw new IllegalAccessException();
 113.318 +        }
 113.319 +        return (T)inst;
 113.320 +    }
 113.321 +
 113.322 +    /**
 113.323 +     * Determines if the specified {@code Object} is assignment-compatible
 113.324 +     * with the object represented by this {@code Class}.  This method is
 113.325 +     * the dynamic equivalent of the Java language {@code instanceof}
 113.326 +     * operator. The method returns {@code true} if the specified
 113.327 +     * {@code Object} argument is non-null and can be cast to the
 113.328 +     * reference type represented by this {@code Class} object without
 113.329 +     * raising a {@code ClassCastException.} It returns {@code false}
 113.330 +     * otherwise.
 113.331 +     *
 113.332 +     * <p> Specifically, if this {@code Class} object represents a
 113.333 +     * declared class, this method returns {@code true} if the specified
 113.334 +     * {@code Object} argument is an instance of the represented class (or
 113.335 +     * of any of its subclasses); it returns {@code false} otherwise. If
 113.336 +     * this {@code Class} object represents an array class, this method
 113.337 +     * returns {@code true} if the specified {@code Object} argument
 113.338 +     * can be converted to an object of the array class by an identity
 113.339 +     * conversion or by a widening reference conversion; it returns
 113.340 +     * {@code false} otherwise. If this {@code Class} object
 113.341 +     * represents an interface, this method returns {@code true} if the
 113.342 +     * class or any superclass of the specified {@code Object} argument
 113.343 +     * implements this interface; it returns {@code false} otherwise. If
 113.344 +     * this {@code Class} object represents a primitive type, this method
 113.345 +     * returns {@code false}.
 113.346 +     *
 113.347 +     * @param   obj the object to check
 113.348 +     * @return  true if {@code obj} is an instance of this class
 113.349 +     *
 113.350 +     * @since JDK1.1
 113.351 +     */
 113.352 +    public boolean isInstance(Object obj) {
 113.353 +        if (isArray()) {
 113.354 +            return isAssignableFrom(obj.getClass());
 113.355 +        }
 113.356 +        
 113.357 +        String prop = "$instOf_" + getName().replace('.', '_');
 113.358 +        return hasProperty(obj, prop);
 113.359 +    }
 113.360 +    
 113.361 +    @JavaScriptBody(args = { "who", "prop" }, body = 
 113.362 +        "if (who[prop]) return true; else return false;"
 113.363 +    )
 113.364 +    private static native boolean hasProperty(Object who, String prop);
 113.365 +
 113.366 +
 113.367 +    /**
 113.368 +     * Determines if the class or interface represented by this
 113.369 +     * {@code Class} object is either the same as, or is a superclass or
 113.370 +     * superinterface of, the class or interface represented by the specified
 113.371 +     * {@code Class} parameter. It returns {@code true} if so;
 113.372 +     * otherwise it returns {@code false}. If this {@code Class}
 113.373 +     * object represents a primitive type, this method returns
 113.374 +     * {@code true} if the specified {@code Class} parameter is
 113.375 +     * exactly this {@code Class} object; otherwise it returns
 113.376 +     * {@code false}.
 113.377 +     *
 113.378 +     * <p> Specifically, this method tests whether the type represented by the
 113.379 +     * specified {@code Class} parameter can be converted to the type
 113.380 +     * represented by this {@code Class} object via an identity conversion
 113.381 +     * or via a widening reference conversion. See <em>The Java Language
 113.382 +     * Specification</em>, sections 5.1.1 and 5.1.4 , for details.
 113.383 +     *
 113.384 +     * @param cls the {@code Class} object to be checked
 113.385 +     * @return the {@code boolean} value indicating whether objects of the
 113.386 +     * type {@code cls} can be assigned to objects of this class
 113.387 +     * @exception NullPointerException if the specified Class parameter is
 113.388 +     *            null.
 113.389 +     * @since JDK1.1
 113.390 +     */
 113.391 +    public boolean isAssignableFrom(Class<?> cls) {
 113.392 +        if (this == cls) {
 113.393 +            return true;
 113.394 +        }
 113.395 +        
 113.396 +        if (isArray()) {
 113.397 +            final Class<?> cmpType = cls.getComponentType();
 113.398 +            if (isPrimitive()) {
 113.399 +                return this == cmpType;
 113.400 +            }
 113.401 +            return cmpType != null && getComponentType().isAssignableFrom(cmpType);
 113.402 +        }
 113.403 +        String prop = "$instOf_" + getName().replace('.', '_');
 113.404 +        return hasProperty(cls, prop);
 113.405 +    }
 113.406 +
 113.407 +
 113.408 +    /**
 113.409 +     * Determines if the specified {@code Class} object represents an
 113.410 +     * interface type.
 113.411 +     *
 113.412 +     * @return  {@code true} if this object represents an interface;
 113.413 +     *          {@code false} otherwise.
 113.414 +     */
 113.415 +    public boolean isInterface() {
 113.416 +        return (getAccess() & 0x200) != 0;
 113.417 +    }
 113.418 +    
 113.419 +    @JavaScriptBody(args = {}, body = "return this.access;")
 113.420 +    private native int getAccess();
 113.421 +
 113.422 +
 113.423 +    /**
 113.424 +     * Determines if this {@code Class} object represents an array class.
 113.425 +     *
 113.426 +     * @return  {@code true} if this object represents an array class;
 113.427 +     *          {@code false} otherwise.
 113.428 +     * @since   JDK1.1
 113.429 +     */
 113.430 +    public boolean isArray() {
 113.431 +        return hasProperty(this, "array"); // NOI18N
 113.432 +    }
 113.433 +
 113.434 +
 113.435 +    /**
 113.436 +     * Determines if the specified {@code Class} object represents a
 113.437 +     * primitive type.
 113.438 +     *
 113.439 +     * <p> There are nine predefined {@code Class} objects to represent
 113.440 +     * the eight primitive types and void.  These are created by the Java
 113.441 +     * Virtual Machine, and have the same names as the primitive types that
 113.442 +     * they represent, namely {@code boolean}, {@code byte},
 113.443 +     * {@code char}, {@code short}, {@code int},
 113.444 +     * {@code long}, {@code float}, and {@code double}.
 113.445 +     *
 113.446 +     * <p> These objects may only be accessed via the following public static
 113.447 +     * final variables, and are the only {@code Class} objects for which
 113.448 +     * this method returns {@code true}.
 113.449 +     *
 113.450 +     * @return true if and only if this class represents a primitive type
 113.451 +     *
 113.452 +     * @see     java.lang.Boolean#TYPE
 113.453 +     * @see     java.lang.Character#TYPE
 113.454 +     * @see     java.lang.Byte#TYPE
 113.455 +     * @see     java.lang.Short#TYPE
 113.456 +     * @see     java.lang.Integer#TYPE
 113.457 +     * @see     java.lang.Long#TYPE
 113.458 +     * @see     java.lang.Float#TYPE
 113.459 +     * @see     java.lang.Double#TYPE
 113.460 +     * @see     java.lang.Void#TYPE
 113.461 +     * @since JDK1.1
 113.462 +     */
 113.463 +    @JavaScriptBody(args = {}, body = 
 113.464 +           "if (this.primitive) return true;"
 113.465 +        + "else return false;"
 113.466 +    )
 113.467 +    public native boolean isPrimitive();
 113.468 +
 113.469 +    /**
 113.470 +     * Returns true if this {@code Class} object represents an annotation
 113.471 +     * type.  Note that if this method returns true, {@link #isInterface()}
 113.472 +     * would also return true, as all annotation types are also interfaces.
 113.473 +     *
 113.474 +     * @return {@code true} if this class object represents an annotation
 113.475 +     *      type; {@code false} otherwise
 113.476 +     * @since 1.5
 113.477 +     */
 113.478 +    public boolean isAnnotation() {
 113.479 +        return (getModifiers() & ANNOTATION) != 0;
 113.480 +    }
 113.481 +
 113.482 +    /**
 113.483 +     * Returns {@code true} if this class is a synthetic class;
 113.484 +     * returns {@code false} otherwise.
 113.485 +     * @return {@code true} if and only if this class is a synthetic class as
 113.486 +     *         defined by the Java Language Specification.
 113.487 +     * @since 1.5
 113.488 +     */
 113.489 +    public boolean isSynthetic() {
 113.490 +        return (getModifiers() & SYNTHETIC) != 0;
 113.491 +    }
 113.492 +
 113.493 +    /**
 113.494 +     * Returns the  name of the entity (class, interface, array class,
 113.495 +     * primitive type, or void) represented by this {@code Class} object,
 113.496 +     * as a {@code String}.
 113.497 +     *
 113.498 +     * <p> If this class object represents a reference type that is not an
 113.499 +     * array type then the binary name of the class is returned, as specified
 113.500 +     * by
 113.501 +     * <cite>The Java&trade; Language Specification</cite>.
 113.502 +     *
 113.503 +     * <p> If this class object represents a primitive type or void, then the
 113.504 +     * name returned is a {@code String} equal to the Java language
 113.505 +     * keyword corresponding to the primitive type or void.
 113.506 +     *
 113.507 +     * <p> If this class object represents a class of arrays, then the internal
 113.508 +     * form of the name consists of the name of the element type preceded by
 113.509 +     * one or more '{@code [}' characters representing the depth of the array
 113.510 +     * nesting.  The encoding of element type names is as follows:
 113.511 +     *
 113.512 +     * <blockquote><table summary="Element types and encodings">
 113.513 +     * <tr><th> Element Type <th> &nbsp;&nbsp;&nbsp; <th> Encoding
 113.514 +     * <tr><td> boolean      <td> &nbsp;&nbsp;&nbsp; <td align=center> Z
 113.515 +     * <tr><td> byte         <td> &nbsp;&nbsp;&nbsp; <td align=center> B
 113.516 +     * <tr><td> char         <td> &nbsp;&nbsp;&nbsp; <td align=center> C
 113.517 +     * <tr><td> class or interface
 113.518 +     *                       <td> &nbsp;&nbsp;&nbsp; <td align=center> L<i>classname</i>;
 113.519 +     * <tr><td> double       <td> &nbsp;&nbsp;&nbsp; <td align=center> D
 113.520 +     * <tr><td> float        <td> &nbsp;&nbsp;&nbsp; <td align=center> F
 113.521 +     * <tr><td> int          <td> &nbsp;&nbsp;&nbsp; <td align=center> I
 113.522 +     * <tr><td> long         <td> &nbsp;&nbsp;&nbsp; <td align=center> J
 113.523 +     * <tr><td> short        <td> &nbsp;&nbsp;&nbsp; <td align=center> S
 113.524 +     * </table></blockquote>
 113.525 +     *
 113.526 +     * <p> The class or interface name <i>classname</i> is the binary name of
 113.527 +     * the class specified above.
 113.528 +     *
 113.529 +     * <p> Examples:
 113.530 +     * <blockquote><pre>
 113.531 +     * String.class.getName()
 113.532 +     *     returns "java.lang.String"
 113.533 +     * byte.class.getName()
 113.534 +     *     returns "byte"
 113.535 +     * (new Object[3]).getClass().getName()
 113.536 +     *     returns "[Ljava.lang.Object;"
 113.537 +     * (new int[3][4][5][6][7][8][9]).getClass().getName()
 113.538 +     *     returns "[[[[[[[I"
 113.539 +     * </pre></blockquote>
 113.540 +     *
 113.541 +     * @return  the name of the class or interface
 113.542 +     *          represented by this object.
 113.543 +     */
 113.544 +    public String getName() {
 113.545 +        return jvmName().replace('/', '.');
 113.546 +    }
 113.547 +
 113.548 +    @JavaScriptBody(args = {}, body = "return this.jvmName;")
 113.549 +    private native String jvmName();
 113.550 +
 113.551 +    
 113.552 +    /**
 113.553 +     * Returns an array of {@code TypeVariable} objects that represent the
 113.554 +     * type variables declared by the generic declaration represented by this
 113.555 +     * {@code GenericDeclaration} object, in declaration order.  Returns an
 113.556 +     * array of length 0 if the underlying generic declaration declares no type
 113.557 +     * variables.
 113.558 +     *
 113.559 +     * @return an array of {@code TypeVariable} objects that represent
 113.560 +     *     the type variables declared by this generic declaration
 113.561 +     * @throws java.lang.reflect.GenericSignatureFormatError if the generic
 113.562 +     *     signature of this generic declaration does not conform to
 113.563 +     *     the format specified in
 113.564 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 113.565 +     * @since 1.5
 113.566 +     */
 113.567 +    public TypeVariable<Class<T>>[] getTypeParameters() {
 113.568 +        throw new UnsupportedOperationException();
 113.569 +    }
 113.570 + 
 113.571 +    /**
 113.572 +     * Returns the {@code Class} representing the superclass of the entity
 113.573 +     * (class, interface, primitive type or void) represented by this
 113.574 +     * {@code Class}.  If this {@code Class} represents either the
 113.575 +     * {@code Object} class, an interface, a primitive type, or void, then
 113.576 +     * null is returned.  If this object represents an array class then the
 113.577 +     * {@code Class} object representing the {@code Object} class is
 113.578 +     * returned.
 113.579 +     *
 113.580 +     * @return the superclass of the class represented by this object.
 113.581 +     */
 113.582 +    @JavaScriptBody(args = {}, body = "return this.superclass;")
 113.583 +    public native Class<? super T> getSuperclass();
 113.584 +
 113.585 +    /**
 113.586 +     * Returns the Java language modifiers for this class or interface, encoded
 113.587 +     * in an integer. The modifiers consist of the Java Virtual Machine's
 113.588 +     * constants for {@code public}, {@code protected},
 113.589 +     * {@code private}, {@code final}, {@code static},
 113.590 +     * {@code abstract} and {@code interface}; they should be decoded
 113.591 +     * using the methods of class {@code Modifier}.
 113.592 +     *
 113.593 +     * <p> If the underlying class is an array class, then its
 113.594 +     * {@code public}, {@code private} and {@code protected}
 113.595 +     * modifiers are the same as those of its component type.  If this
 113.596 +     * {@code Class} represents a primitive type or void, its
 113.597 +     * {@code public} modifier is always {@code true}, and its
 113.598 +     * {@code protected} and {@code private} modifiers are always
 113.599 +     * {@code false}. If this object represents an array class, a
 113.600 +     * primitive type or void, then its {@code final} modifier is always
 113.601 +     * {@code true} and its interface modifier is always
 113.602 +     * {@code false}. The values of its other modifiers are not determined
 113.603 +     * by this specification.
 113.604 +     *
 113.605 +     * <p> The modifier encodings are defined in <em>The Java Virtual Machine
 113.606 +     * Specification</em>, table 4.1.
 113.607 +     *
 113.608 +     * @return the {@code int} representing the modifiers for this class
 113.609 +     * @see     java.lang.reflect.Modifier
 113.610 +     * @since JDK1.1
 113.611 +     */
 113.612 +    public int getModifiers() {
 113.613 +        return getAccess();
 113.614 +    }
 113.615 +
 113.616 +
 113.617 +    /**
 113.618 +     * Returns the simple name of the underlying class as given in the
 113.619 +     * source code. Returns an empty string if the underlying class is
 113.620 +     * anonymous.
 113.621 +     *
 113.622 +     * <p>The simple name of an array is the simple name of the
 113.623 +     * component type with "[]" appended.  In particular the simple
 113.624 +     * name of an array whose component type is anonymous is "[]".
 113.625 +     *
 113.626 +     * @return the simple name of the underlying class
 113.627 +     * @since 1.5
 113.628 +     */
 113.629 +    public String getSimpleName() {
 113.630 +        if (isArray())
 113.631 +            return getComponentType().getSimpleName()+"[]";
 113.632 +
 113.633 +        String simpleName = getSimpleBinaryName();
 113.634 +        if (simpleName == null) { // top level class
 113.635 +            simpleName = getName();
 113.636 +            return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
 113.637 +        }
 113.638 +        // According to JLS3 "Binary Compatibility" (13.1) the binary
 113.639 +        // name of non-package classes (not top level) is the binary
 113.640 +        // name of the immediately enclosing class followed by a '$' followed by:
 113.641 +        // (for nested and inner classes): the simple name.
 113.642 +        // (for local classes): 1 or more digits followed by the simple name.
 113.643 +        // (for anonymous classes): 1 or more digits.
 113.644 +
 113.645 +        // Since getSimpleBinaryName() will strip the binary name of
 113.646 +        // the immediatly enclosing class, we are now looking at a
 113.647 +        // string that matches the regular expression "\$[0-9]*"
 113.648 +        // followed by a simple name (considering the simple of an
 113.649 +        // anonymous class to be the empty string).
 113.650 +
 113.651 +        // Remove leading "\$[0-9]*" from the name
 113.652 +        int length = simpleName.length();
 113.653 +        if (length < 1 || simpleName.charAt(0) != '$')
 113.654 +            throw new IllegalStateException("Malformed class name");
 113.655 +        int index = 1;
 113.656 +        while (index < length && isAsciiDigit(simpleName.charAt(index)))
 113.657 +            index++;
 113.658 +        // Eventually, this is the empty string iff this is an anonymous class
 113.659 +        return simpleName.substring(index);
 113.660 +    }
 113.661 +
 113.662 +    /**
 113.663 +     * Returns the "simple binary name" of the underlying class, i.e.,
 113.664 +     * the binary name without the leading enclosing class name.
 113.665 +     * Returns {@code null} if the underlying class is a top level
 113.666 +     * class.
 113.667 +     */
 113.668 +    private String getSimpleBinaryName() {
 113.669 +        Class<?> enclosingClass = null; // XXX getEnclosingClass();
 113.670 +        if (enclosingClass == null) // top level class
 113.671 +            return null;
 113.672 +        // Otherwise, strip the enclosing class' name
 113.673 +        try {
 113.674 +            return getName().substring(enclosingClass.getName().length());
 113.675 +        } catch (IndexOutOfBoundsException ex) {
 113.676 +            throw new IllegalStateException("Malformed class name");
 113.677 +        }
 113.678 +    }
 113.679 +
 113.680 +    /**
 113.681 +     * Returns an array containing {@code Field} objects reflecting all
 113.682 +     * the accessible public fields of the class or interface represented by
 113.683 +     * this {@code Class} object.  The elements in the array returned are
 113.684 +     * not sorted and are not in any particular order.  This method returns an
 113.685 +     * array of length 0 if the class or interface has no accessible public
 113.686 +     * fields, or if it represents an array class, a primitive type, or void.
 113.687 +     *
 113.688 +     * <p> Specifically, if this {@code Class} object represents a class,
 113.689 +     * this method returns the public fields of this class and of all its
 113.690 +     * superclasses.  If this {@code Class} object represents an
 113.691 +     * interface, this method returns the fields of this interface and of all
 113.692 +     * its superinterfaces.
 113.693 +     *
 113.694 +     * <p> The implicit length field for array class is not reflected by this
 113.695 +     * method. User code should use the methods of class {@code Array} to
 113.696 +     * manipulate arrays.
 113.697 +     *
 113.698 +     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
 113.699 +     *
 113.700 +     * @return the array of {@code Field} objects representing the
 113.701 +     * public fields
 113.702 +     * @exception  SecurityException
 113.703 +     *             If a security manager, <i>s</i>, is present and any of the
 113.704 +     *             following conditions is met:
 113.705 +     *
 113.706 +     *             <ul>
 113.707 +     *
 113.708 +     *             <li> invocation of
 113.709 +     *             {@link SecurityManager#checkMemberAccess
 113.710 +     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 113.711 +     *             access to the fields within this class
 113.712 +     *
 113.713 +     *             <li> the caller's class loader is not the same as or an
 113.714 +     *             ancestor of the class loader for the current class and
 113.715 +     *             invocation of {@link SecurityManager#checkPackageAccess
 113.716 +     *             s.checkPackageAccess()} denies access to the package
 113.717 +     *             of this class
 113.718 +     *
 113.719 +     *             </ul>
 113.720 +     *
 113.721 +     * @since JDK1.1
 113.722 +     */
 113.723 +    public Field[] getFields() throws SecurityException {
 113.724 +        throw new SecurityException();
 113.725 +    }
 113.726 +
 113.727 +    /**
 113.728 +     * Returns an array containing {@code Method} objects reflecting all
 113.729 +     * the public <em>member</em> methods of the class or interface represented
 113.730 +     * by this {@code Class} object, including those declared by the class
 113.731 +     * or interface and those inherited from superclasses and
 113.732 +     * superinterfaces.  Array classes return all the (public) member methods
 113.733 +     * inherited from the {@code Object} class.  The elements in the array
 113.734 +     * returned are not sorted and are not in any particular order.  This
 113.735 +     * method returns an array of length 0 if this {@code Class} object
 113.736 +     * represents a class or interface that has no public member methods, or if
 113.737 +     * this {@code Class} object represents a primitive type or void.
 113.738 +     *
 113.739 +     * <p> The class initialization method {@code <clinit>} is not
 113.740 +     * included in the returned array. If the class declares multiple public
 113.741 +     * member methods with the same parameter types, they are all included in
 113.742 +     * the returned array.
 113.743 +     *
 113.744 +     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
 113.745 +     *
 113.746 +     * @return the array of {@code Method} objects representing the
 113.747 +     * public methods of this class
 113.748 +     * @exception  SecurityException
 113.749 +     *             If a security manager, <i>s</i>, is present and any of the
 113.750 +     *             following conditions is met:
 113.751 +     *
 113.752 +     *             <ul>
 113.753 +     *
 113.754 +     *             <li> invocation of
 113.755 +     *             {@link SecurityManager#checkMemberAccess
 113.756 +     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 113.757 +     *             access to the methods within this class
 113.758 +     *
 113.759 +     *             <li> the caller's class loader is not the same as or an
 113.760 +     *             ancestor of the class loader for the current class and
 113.761 +     *             invocation of {@link SecurityManager#checkPackageAccess
 113.762 +     *             s.checkPackageAccess()} denies access to the package
 113.763 +     *             of this class
 113.764 +     *
 113.765 +     *             </ul>
 113.766 +     *
 113.767 +     * @since JDK1.1
 113.768 +     */
 113.769 +    public Method[] getMethods() throws SecurityException {
 113.770 +        return MethodImpl.findMethods(this, 0x01);
 113.771 +    }
 113.772 +
 113.773 +    /**
 113.774 +     * Returns a {@code Field} object that reflects the specified public
 113.775 +     * member field of the class or interface represented by this
 113.776 +     * {@code Class} object. The {@code name} parameter is a
 113.777 +     * {@code String} specifying the simple name of the desired field.
 113.778 +     *
 113.779 +     * <p> The field to be reflected is determined by the algorithm that
 113.780 +     * follows.  Let C be the class represented by this object:
 113.781 +     * <OL>
 113.782 +     * <LI> If C declares a public field with the name specified, that is the
 113.783 +     *      field to be reflected.</LI>
 113.784 +     * <LI> If no field was found in step 1 above, this algorithm is applied
 113.785 +     *      recursively to each direct superinterface of C. The direct
 113.786 +     *      superinterfaces are searched in the order they were declared.</LI>
 113.787 +     * <LI> If no field was found in steps 1 and 2 above, and C has a
 113.788 +     *      superclass S, then this algorithm is invoked recursively upon S.
 113.789 +     *      If C has no superclass, then a {@code NoSuchFieldException}
 113.790 +     *      is thrown.</LI>
 113.791 +     * </OL>
 113.792 +     *
 113.793 +     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
 113.794 +     *
 113.795 +     * @param name the field name
 113.796 +     * @return  the {@code Field} object of this class specified by
 113.797 +     * {@code name}
 113.798 +     * @exception NoSuchFieldException if a field with the specified name is
 113.799 +     *              not found.
 113.800 +     * @exception NullPointerException if {@code name} is {@code null}
 113.801 +     * @exception  SecurityException
 113.802 +     *             If a security manager, <i>s</i>, is present and any of the
 113.803 +     *             following conditions is met:
 113.804 +     *
 113.805 +     *             <ul>
 113.806 +     *
 113.807 +     *             <li> invocation of
 113.808 +     *             {@link SecurityManager#checkMemberAccess
 113.809 +     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 113.810 +     *             access to the field
 113.811 +     *
 113.812 +     *             <li> the caller's class loader is not the same as or an
 113.813 +     *             ancestor of the class loader for the current class and
 113.814 +     *             invocation of {@link SecurityManager#checkPackageAccess
 113.815 +     *             s.checkPackageAccess()} denies access to the package
 113.816 +     *             of this class
 113.817 +     *
 113.818 +     *             </ul>
 113.819 +     *
 113.820 +     * @since JDK1.1
 113.821 +     */
 113.822 +    public Field getField(String name)
 113.823 +        throws SecurityException {
 113.824 +        throw new SecurityException();
 113.825 +    }
 113.826 +    
 113.827 +    
 113.828 +    /**
 113.829 +     * Returns a {@code Method} object that reflects the specified public
 113.830 +     * member method of the class or interface represented by this
 113.831 +     * {@code Class} object. The {@code name} parameter is a
 113.832 +     * {@code String} specifying the simple name of the desired method. The
 113.833 +     * {@code parameterTypes} parameter is an array of {@code Class}
 113.834 +     * objects that identify the method's formal parameter types, in declared
 113.835 +     * order. If {@code parameterTypes} is {@code null}, it is
 113.836 +     * treated as if it were an empty array.
 113.837 +     *
 113.838 +     * <p> If the {@code name} is "{@code <init>};"or "{@code <clinit>}" a
 113.839 +     * {@code NoSuchMethodException} is raised. Otherwise, the method to
 113.840 +     * be reflected is determined by the algorithm that follows.  Let C be the
 113.841 +     * class represented by this object:
 113.842 +     * <OL>
 113.843 +     * <LI> C is searched for any <I>matching methods</I>. If no matching
 113.844 +     *      method is found, the algorithm of step 1 is invoked recursively on
 113.845 +     *      the superclass of C.</LI>
 113.846 +     * <LI> If no method was found in step 1 above, the superinterfaces of C
 113.847 +     *      are searched for a matching method. If any such method is found, it
 113.848 +     *      is reflected.</LI>
 113.849 +     * </OL>
 113.850 +     *
 113.851 +     * To find a matching method in a class C:&nbsp; If C declares exactly one
 113.852 +     * public method with the specified name and exactly the same formal
 113.853 +     * parameter types, that is the method reflected. If more than one such
 113.854 +     * method is found in C, and one of these methods has a return type that is
 113.855 +     * more specific than any of the others, that method is reflected;
 113.856 +     * otherwise one of the methods is chosen arbitrarily.
 113.857 +     *
 113.858 +     * <p>Note that there may be more than one matching method in a
 113.859 +     * class because while the Java language forbids a class to
 113.860 +     * declare multiple methods with the same signature but different
 113.861 +     * return types, the Java virtual machine does not.  This
 113.862 +     * increased flexibility in the virtual machine can be used to
 113.863 +     * implement various language features.  For example, covariant
 113.864 +     * returns can be implemented with {@linkplain
 113.865 +     * java.lang.reflect.Method#isBridge bridge methods}; the bridge
 113.866 +     * method and the method being overridden would have the same
 113.867 +     * signature but different return types.
 113.868 +     *
 113.869 +     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
 113.870 +     *
 113.871 +     * @param name the name of the method
 113.872 +     * @param parameterTypes the list of parameters
 113.873 +     * @return the {@code Method} object that matches the specified
 113.874 +     * {@code name} and {@code parameterTypes}
 113.875 +     * @exception NoSuchMethodException if a matching method is not found
 113.876 +     *            or if the name is "&lt;init&gt;"or "&lt;clinit&gt;".
 113.877 +     * @exception NullPointerException if {@code name} is {@code null}
 113.878 +     * @exception  SecurityException
 113.879 +     *             If a security manager, <i>s</i>, is present and any of the
 113.880 +     *             following conditions is met:
 113.881 +     *
 113.882 +     *             <ul>
 113.883 +     *
 113.884 +     *             <li> invocation of
 113.885 +     *             {@link SecurityManager#checkMemberAccess
 113.886 +     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 113.887 +     *             access to the method
 113.888 +     *
 113.889 +     *             <li> the caller's class loader is not the same as or an
 113.890 +     *             ancestor of the class loader for the current class and
 113.891 +     *             invocation of {@link SecurityManager#checkPackageAccess
 113.892 +     *             s.checkPackageAccess()} denies access to the package
 113.893 +     *             of this class
 113.894 +     *
 113.895 +     *             </ul>
 113.896 +     *
 113.897 +     * @since JDK1.1
 113.898 +     */
 113.899 +    public Method getMethod(String name, Class<?>... parameterTypes)
 113.900 +        throws SecurityException, NoSuchMethodException {
 113.901 +        Method m = MethodImpl.findMethod(this, name, parameterTypes);
 113.902 +        if (m == null) {
 113.903 +            StringBuilder sb = new StringBuilder();
 113.904 +            sb.append(getName()).append('.').append(name).append('(');
 113.905 +            String sep = "";
 113.906 +            for (int i = 0; i < parameterTypes.length; i++) {
 113.907 +                sb.append(sep).append(parameterTypes[i].getName());
 113.908 +                sep = ", ";
 113.909 +            }
 113.910 +            sb.append(')');
 113.911 +            throw new NoSuchMethodException(sb.toString());
 113.912 +        }
 113.913 +        return m;
 113.914 +    }
 113.915 +
 113.916 +    /**
 113.917 +     * Character.isDigit answers {@code true} to some non-ascii
 113.918 +     * digits.  This one does not.
 113.919 +     */
 113.920 +    private static boolean isAsciiDigit(char c) {
 113.921 +        return '0' <= c && c <= '9';
 113.922 +    }
 113.923 +
 113.924 +    /**
 113.925 +     * Returns the canonical name of the underlying class as
 113.926 +     * defined by the Java Language Specification.  Returns null if
 113.927 +     * the underlying class does not have a canonical name (i.e., if
 113.928 +     * it is a local or anonymous class or an array whose component
 113.929 +     * type does not have a canonical name).
 113.930 +     * @return the canonical name of the underlying class if it exists, and
 113.931 +     * {@code null} otherwise.
 113.932 +     * @since 1.5
 113.933 +     */
 113.934 +    public String getCanonicalName() {
 113.935 +        if (isArray()) {
 113.936 +            String canonicalName = getComponentType().getCanonicalName();
 113.937 +            if (canonicalName != null)
 113.938 +                return canonicalName + "[]";
 113.939 +            else
 113.940 +                return null;
 113.941 +        }
 113.942 +//        if (isLocalOrAnonymousClass())
 113.943 +//            return null;
 113.944 +//        Class<?> enclosingClass = getEnclosingClass();
 113.945 +        Class<?> enclosingClass = null;
 113.946 +        if (enclosingClass == null) { // top level class
 113.947 +            return getName();
 113.948 +        } else {
 113.949 +            String enclosingName = enclosingClass.getCanonicalName();
 113.950 +            if (enclosingName == null)
 113.951 +                return null;
 113.952 +            return enclosingName + "." + getSimpleName();
 113.953 +        }
 113.954 +    }
 113.955 +
 113.956 +    /**
 113.957 +     * Finds a resource with a given name.  The rules for searching resources
 113.958 +     * associated with a given class are implemented by the defining
 113.959 +     * {@linkplain ClassLoader class loader} of the class.  This method
 113.960 +     * delegates to this object's class loader.  If this object was loaded by
 113.961 +     * the bootstrap class loader, the method delegates to {@link
 113.962 +     * ClassLoader#getSystemResourceAsStream}.
 113.963 +     *
 113.964 +     * <p> Before delegation, an absolute resource name is constructed from the
 113.965 +     * given resource name using this algorithm:
 113.966 +     *
 113.967 +     * <ul>
 113.968 +     *
 113.969 +     * <li> If the {@code name} begins with a {@code '/'}
 113.970 +     * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
 113.971 +     * portion of the {@code name} following the {@code '/'}.
 113.972 +     *
 113.973 +     * <li> Otherwise, the absolute name is of the following form:
 113.974 +     *
 113.975 +     * <blockquote>
 113.976 +     *   {@code modified_package_name/name}
 113.977 +     * </blockquote>
 113.978 +     *
 113.979 +     * <p> Where the {@code modified_package_name} is the package name of this
 113.980 +     * object with {@code '/'} substituted for {@code '.'}
 113.981 +     * (<tt>'&#92;u002e'</tt>).
 113.982 +     *
 113.983 +     * </ul>
 113.984 +     *
 113.985 +     * @param  name name of the desired resource
 113.986 +     * @return      A {@link java.io.InputStream} object or {@code null} if
 113.987 +     *              no resource with this name is found
 113.988 +     * @throws  NullPointerException If {@code name} is {@code null}
 113.989 +     * @since  JDK1.1
 113.990 +     */
 113.991 +     public InputStream getResourceAsStream(String name) {
 113.992 +        name = resolveName(name);
 113.993 +        byte[] arr = getResourceAsStream0(name);
 113.994 +        return arr == null ? null : new ByteArrayInputStream(arr);
 113.995 +     }
 113.996 +     
 113.997 +     @JavaScriptBody(args = "name", body = 
 113.998 +         "return (vm.loadBytes) ? vm.loadBytes(name) : null;"
 113.999 +     )
113.1000 +     private static native byte[] getResourceAsStream0(String name);
113.1001 +
113.1002 +    /**
113.1003 +     * Finds a resource with a given name.  The rules for searching resources
113.1004 +     * associated with a given class are implemented by the defining
113.1005 +     * {@linkplain ClassLoader class loader} of the class.  This method
113.1006 +     * delegates to this object's class loader.  If this object was loaded by
113.1007 +     * the bootstrap class loader, the method delegates to {@link
113.1008 +     * ClassLoader#getSystemResource}.
113.1009 +     *
113.1010 +     * <p> Before delegation, an absolute resource name is constructed from the
113.1011 +     * given resource name using this algorithm:
113.1012 +     *
113.1013 +     * <ul>
113.1014 +     *
113.1015 +     * <li> If the {@code name} begins with a {@code '/'}
113.1016 +     * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
113.1017 +     * portion of the {@code name} following the {@code '/'}.
113.1018 +     *
113.1019 +     * <li> Otherwise, the absolute name is of the following form:
113.1020 +     *
113.1021 +     * <blockquote>
113.1022 +     *   {@code modified_package_name/name}
113.1023 +     * </blockquote>
113.1024 +     *
113.1025 +     * <p> Where the {@code modified_package_name} is the package name of this
113.1026 +     * object with {@code '/'} substituted for {@code '.'}
113.1027 +     * (<tt>'&#92;u002e'</tt>).
113.1028 +     *
113.1029 +     * </ul>
113.1030 +     *
113.1031 +     * @param  name name of the desired resource
113.1032 +     * @return      A  {@link java.net.URL} object or {@code null} if no
113.1033 +     *              resource with this name is found
113.1034 +     * @since  JDK1.1
113.1035 +     */
113.1036 +    public java.net.URL getResource(String name) {
113.1037 +        InputStream is = getResourceAsStream(name);
113.1038 +        return is == null ? null : newResourceURL(URL.class, "res:/" + name, is);
113.1039 +    }
113.1040 +    
113.1041 +    @JavaScriptBody(args = { "url", "spec", "is" }, body = 
113.1042 +        "var u = url.cnstr(true);\n"
113.1043 +      + "u.constructor.cons__VLjava_lang_String_2Ljava_io_InputStream_2.call(u, spec, is);\n"
113.1044 +      + "return u;"
113.1045 +    )
113.1046 +    private static native URL newResourceURL(Class<URL> url, String spec, InputStream is);
113.1047 +
113.1048 +   /**
113.1049 +     * Add a package name prefix if the name is not absolute Remove leading "/"
113.1050 +     * if name is absolute
113.1051 +     */
113.1052 +    private String resolveName(String name) {
113.1053 +        if (name == null) {
113.1054 +            return name;
113.1055 +        }
113.1056 +        if (!name.startsWith("/")) {
113.1057 +            Class<?> c = this;
113.1058 +            while (c.isArray()) {
113.1059 +                c = c.getComponentType();
113.1060 +            }
113.1061 +            String baseName = c.getName();
113.1062 +            int index = baseName.lastIndexOf('.');
113.1063 +            if (index != -1) {
113.1064 +                name = baseName.substring(0, index).replace('.', '/')
113.1065 +                    +"/"+name;
113.1066 +            }
113.1067 +        } else {
113.1068 +            name = name.substring(1);
113.1069 +        }
113.1070 +        return name;
113.1071 +    }
113.1072 +    
113.1073 +    /**
113.1074 +     * Returns the class loader for the class.  Some implementations may use
113.1075 +     * null to represent the bootstrap class loader. This method will return
113.1076 +     * null in such implementations if this class was loaded by the bootstrap
113.1077 +     * class loader.
113.1078 +     *
113.1079 +     * <p> If a security manager is present, and the caller's class loader is
113.1080 +     * not null and the caller's class loader is not the same as or an ancestor of
113.1081 +     * the class loader for the class whose class loader is requested, then
113.1082 +     * this method calls the security manager's {@code checkPermission}
113.1083 +     * method with a {@code RuntimePermission("getClassLoader")}
113.1084 +     * permission to ensure it's ok to access the class loader for the class.
113.1085 +     *
113.1086 +     * <p>If this object
113.1087 +     * represents a primitive type or void, null is returned.
113.1088 +     *
113.1089 +     * @return  the class loader that loaded the class or interface
113.1090 +     *          represented by this object.
113.1091 +     * @throws SecurityException
113.1092 +     *    if a security manager exists and its
113.1093 +     *    {@code checkPermission} method denies
113.1094 +     *    access to the class loader for the class.
113.1095 +     * @see java.lang.ClassLoader
113.1096 +     * @see SecurityManager#checkPermission
113.1097 +     * @see java.lang.RuntimePermission
113.1098 +     */
113.1099 +    public ClassLoader getClassLoader() {
113.1100 +        throw new SecurityException();
113.1101 +    }
113.1102 +    
113.1103 +    /**
113.1104 +     * Returns the {@code Class} representing the component type of an
113.1105 +     * array.  If this class does not represent an array class this method
113.1106 +     * returns null.
113.1107 +     *
113.1108 +     * @return the {@code Class} representing the component type of this
113.1109 +     * class if this class is an array
113.1110 +     * @see     java.lang.reflect.Array
113.1111 +     * @since JDK1.1
113.1112 +     */
113.1113 +    public Class<?> getComponentType() {
113.1114 +        if (isArray()) {
113.1115 +            try {
113.1116 +                return getComponentType0();
113.1117 +            } catch (ClassNotFoundException cnfe) {
113.1118 +                throw new IllegalStateException(cnfe);
113.1119 +            }
113.1120 +        }
113.1121 +        return null;
113.1122 +    }
113.1123 +
113.1124 +    private Class<?> getComponentType0() throws ClassNotFoundException {
113.1125 +        String n = getName().substring(1);
113.1126 +        switch (n.charAt(0)) {
113.1127 +            case 'L': 
113.1128 +                n = n.substring(1, n.length() - 1);
113.1129 +                return Class.forName(n);
113.1130 +            case 'I':
113.1131 +                return Integer.TYPE;
113.1132 +            case 'J':
113.1133 +                return Long.TYPE;
113.1134 +            case 'D':
113.1135 +                return Double.TYPE;
113.1136 +            case 'F':
113.1137 +                return Float.TYPE;
113.1138 +            case 'B':
113.1139 +                return Byte.TYPE;
113.1140 +            case 'Z':
113.1141 +                return Boolean.TYPE;
113.1142 +            case 'S':
113.1143 +                return Short.TYPE;
113.1144 +            case 'V':
113.1145 +                return Void.TYPE;
113.1146 +            case 'C':
113.1147 +                return Character.TYPE;
113.1148 +            case '[':
113.1149 +                return defineArray(n);
113.1150 +            default:
113.1151 +                throw new ClassNotFoundException("Unknown component type of " + getName());
113.1152 +        }
113.1153 +    }
113.1154 +    
113.1155 +    @JavaScriptBody(args = { "sig" }, body = 
113.1156 +        "var c = Array[sig];\n" +
113.1157 +        "if (c) return c;\n" +
113.1158 +        "c = vm.java_lang_Class(true);\n" +
113.1159 +        "c.jvmName = sig;\n" +
113.1160 +        "c.superclass = vm.java_lang_Object(false).$class;\n" +
113.1161 +        "c.array = true;\n" +
113.1162 +        "Array[sig] = c;\n" +
113.1163 +        "return c;"
113.1164 +    )
113.1165 +    private static native Class<?> defineArray(String sig);
113.1166 +    
113.1167 +    /**
113.1168 +     * Returns true if and only if this class was declared as an enum in the
113.1169 +     * source code.
113.1170 +     *
113.1171 +     * @return true if and only if this class was declared as an enum in the
113.1172 +     *     source code
113.1173 +     * @since 1.5
113.1174 +     */
113.1175 +    public boolean isEnum() {
113.1176 +        // An enum must both directly extend java.lang.Enum and have
113.1177 +        // the ENUM bit set; classes for specialized enum constants
113.1178 +        // don't do the former.
113.1179 +        return (this.getModifiers() & ENUM) != 0 &&
113.1180 +        this.getSuperclass() == java.lang.Enum.class;
113.1181 +    }
113.1182 +
113.1183 +    /**
113.1184 +     * Casts an object to the class or interface represented
113.1185 +     * by this {@code Class} object.
113.1186 +     *
113.1187 +     * @param obj the object to be cast
113.1188 +     * @return the object after casting, or null if obj is null
113.1189 +     *
113.1190 +     * @throws ClassCastException if the object is not
113.1191 +     * null and is not assignable to the type T.
113.1192 +     *
113.1193 +     * @since 1.5
113.1194 +     */
113.1195 +    public T cast(Object obj) {
113.1196 +        if (obj != null && !isInstance(obj))
113.1197 +            throw new ClassCastException(cannotCastMsg(obj));
113.1198 +        return (T) obj;
113.1199 +    }
113.1200 +
113.1201 +    private String cannotCastMsg(Object obj) {
113.1202 +        return "Cannot cast " + obj.getClass().getName() + " to " + getName();
113.1203 +    }
113.1204 +
113.1205 +    /**
113.1206 +     * Casts this {@code Class} object to represent a subclass of the class
113.1207 +     * represented by the specified class object.  Checks that that the cast
113.1208 +     * is valid, and throws a {@code ClassCastException} if it is not.  If
113.1209 +     * this method succeeds, it always returns a reference to this class object.
113.1210 +     *
113.1211 +     * <p>This method is useful when a client needs to "narrow" the type of
113.1212 +     * a {@code Class} object to pass it to an API that restricts the
113.1213 +     * {@code Class} objects that it is willing to accept.  A cast would
113.1214 +     * generate a compile-time warning, as the correctness of the cast
113.1215 +     * could not be checked at runtime (because generic types are implemented
113.1216 +     * by erasure).
113.1217 +     *
113.1218 +     * @return this {@code Class} object, cast to represent a subclass of
113.1219 +     *    the specified class object.
113.1220 +     * @throws ClassCastException if this {@code Class} object does not
113.1221 +     *    represent a subclass of the specified class (here "subclass" includes
113.1222 +     *    the class itself).
113.1223 +     * @since 1.5
113.1224 +     */
113.1225 +    public <U> Class<? extends U> asSubclass(Class<U> clazz) {
113.1226 +        if (clazz.isAssignableFrom(this))
113.1227 +            return (Class<? extends U>) this;
113.1228 +        else
113.1229 +            throw new ClassCastException(this.toString());
113.1230 +    }
113.1231 +
113.1232 +    @JavaScriptBody(args = { "ac" }, 
113.1233 +        body = 
113.1234 +          "if (this.anno) {"
113.1235 +        + "  return this.anno['L' + ac.jvmName + ';'];"
113.1236 +        + "} else return null;"
113.1237 +    )
113.1238 +    private Object getAnnotationData(Class<?> annotationClass) {
113.1239 +        throw new UnsupportedOperationException();
113.1240 +    }
113.1241 +    /**
113.1242 +     * @throws NullPointerException {@inheritDoc}
113.1243 +     * @since 1.5
113.1244 +     */
113.1245 +    public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
113.1246 +        Object data = getAnnotationData(annotationClass);
113.1247 +        return data == null ? null : AnnotationImpl.create(annotationClass, data);
113.1248 +    }
113.1249 +
113.1250 +    /**
113.1251 +     * @throws NullPointerException {@inheritDoc}
113.1252 +     * @since 1.5
113.1253 +     */
113.1254 +    @JavaScriptBody(args = { "ac" }, 
113.1255 +        body = "if (this.anno && this.anno['L' + ac.jvmName + ';']) { return true; }"
113.1256 +        + "else return false;"
113.1257 +    )
113.1258 +    public boolean isAnnotationPresent(
113.1259 +        Class<? extends Annotation> annotationClass) {
113.1260 +        if (annotationClass == null)
113.1261 +            throw new NullPointerException();
113.1262 +
113.1263 +        return getAnnotation(annotationClass) != null;
113.1264 +    }
113.1265 +
113.1266 +    @JavaScriptBody(args = {}, body = "return this.anno;")
113.1267 +    private Object getAnnotationData() {
113.1268 +        throw new UnsupportedOperationException();
113.1269 +    }
113.1270 +
113.1271 +    /**
113.1272 +     * @since 1.5
113.1273 +     */
113.1274 +    public Annotation[] getAnnotations() {
113.1275 +        Object data = getAnnotationData();
113.1276 +        return data == null ? new Annotation[0] : AnnotationImpl.create(data);
113.1277 +    }
113.1278 +
113.1279 +    /**
113.1280 +     * @since 1.5
113.1281 +     */
113.1282 +    public Annotation[] getDeclaredAnnotations()  {
113.1283 +        throw new UnsupportedOperationException();
113.1284 +    }
113.1285 +
113.1286 +    @JavaScriptBody(args = "type", body = ""
113.1287 +        + "var c = vm.java_lang_Class(true);"
113.1288 +        + "c.jvmName = type;"
113.1289 +        + "c.primitive = true;"
113.1290 +        + "return c;"
113.1291 +    )
113.1292 +    native static Class getPrimitiveClass(String type);
113.1293 +
113.1294 +    @JavaScriptBody(args = {}, body = 
113.1295 +        "return vm.desiredAssertionStatus ? vm.desiredAssertionStatus : false;"
113.1296 +    )
113.1297 +    public native boolean desiredAssertionStatus();
113.1298 +}
   114.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   114.2 +++ b/emul/mini/src/main/java/java/lang/ClassCastException.java	Sun Feb 03 07:48:42 2013 +0100
   114.3 @@ -0,0 +1,60 @@
   114.4 +/*
   114.5 + * Copyright (c) 1994, 2008, 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 + * Thrown to indicate that the code has attempted to cast an object
  114.33 + * to a subclass of which it is not an instance. For example, the
  114.34 + * following code generates a <code>ClassCastException</code>:
  114.35 + * <p><blockquote><pre>
  114.36 + *     Object x = new Integer(0);
  114.37 + *     System.out.println((String)x);
  114.38 + * </pre></blockquote>
  114.39 + *
  114.40 + * @author  unascribed
  114.41 + * @since   JDK1.0
  114.42 + */
  114.43 +public
  114.44 +class ClassCastException extends RuntimeException {
  114.45 +    private static final long serialVersionUID = -9223365651070458532L;
  114.46 +
  114.47 +    /**
  114.48 +     * Constructs a <code>ClassCastException</code> with no detail message.
  114.49 +     */
  114.50 +    public ClassCastException() {
  114.51 +        super();
  114.52 +    }
  114.53 +
  114.54 +    /**
  114.55 +     * Constructs a <code>ClassCastException</code> with the specified
  114.56 +     * detail message.
  114.57 +     *
  114.58 +     * @param   s   the detail message.
  114.59 +     */
  114.60 +    public ClassCastException(String s) {
  114.61 +        super(s);
  114.62 +    }
  114.63 +}
   115.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   115.2 +++ b/emul/mini/src/main/java/java/lang/ClassFormatError.java	Sun Feb 03 07:48:42 2013 +0100
   115.3 @@ -0,0 +1,56 @@
   115.4 +/*
   115.5 + * Copyright (c) 1994, 2008, 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 + * Thrown when the Java Virtual Machine attempts to read a class
  115.33 + * file and determines that the file is malformed or otherwise cannot
  115.34 + * be interpreted as a class file.
  115.35 + *
  115.36 + * @author  unascribed
  115.37 + * @since   JDK1.0
  115.38 + */
  115.39 +public
  115.40 +class ClassFormatError extends LinkageError {
  115.41 +    private static final long serialVersionUID = -8420114879011949195L;
  115.42 +
  115.43 +    /**
  115.44 +     * Constructs a <code>ClassFormatError</code> with no detail message.
  115.45 +     */
  115.46 +    public ClassFormatError() {
  115.47 +        super();
  115.48 +    }
  115.49 +
  115.50 +    /**
  115.51 +     * Constructs a <code>ClassFormatError</code> with the specified
  115.52 +     * detail message.
  115.53 +     *
  115.54 +     * @param   s   the detail message.
  115.55 +     */
  115.56 +    public ClassFormatError(String s) {
  115.57 +        super(s);
  115.58 +    }
  115.59 +}
   116.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   116.2 +++ b/emul/mini/src/main/java/java/lang/ClassLoader.java	Sun Feb 03 07:48:42 2013 +0100
   116.3 @@ -0,0 +1,936 @@
   116.4 +/*
   116.5 + * Copyright (c) 1994, 2011, 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 +package java.lang;
  116.29 +
  116.30 +import java.io.InputStream;
  116.31 +import java.io.IOException;
  116.32 +import java.net.URL;
  116.33 +import java.util.Enumeration;
  116.34 +import java.util.NoSuchElementException;
  116.35 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  116.36 +
  116.37 +/**
  116.38 + * A class loader is an object that is responsible for loading classes. The
  116.39 + * class <tt>ClassLoader</tt> is an abstract class.  Given the <a
  116.40 + * href="#name">binary name</a> of a class, a class loader should attempt to
  116.41 + * locate or generate data that constitutes a definition for the class.  A
  116.42 + * typical strategy is to transform the name into a file name and then read a
  116.43 + * "class file" of that name from a file system.
  116.44 + *
  116.45 + * <p> Every {@link Class <tt>Class</tt>} object contains a {@link
  116.46 + * Class#getClassLoader() reference} to the <tt>ClassLoader</tt> that defined
  116.47 + * it.
  116.48 + *
  116.49 + * <p> <tt>Class</tt> objects for array classes are not created by class
  116.50 + * loaders, but are created automatically as required by the Java runtime.
  116.51 + * The class loader for an array class, as returned by {@link
  116.52 + * Class#getClassLoader()} is the same as the class loader for its element
  116.53 + * type; if the element type is a primitive type, then the array class has no
  116.54 + * class loader.
  116.55 + *
  116.56 + * <p> Applications implement subclasses of <tt>ClassLoader</tt> in order to
  116.57 + * extend the manner in which the Java virtual machine dynamically loads
  116.58 + * classes.
  116.59 + *
  116.60 + * <p> Class loaders may typically be used by security managers to indicate
  116.61 + * security domains.
  116.62 + *
  116.63 + * <p> The <tt>ClassLoader</tt> class uses a delegation model to search for
  116.64 + * classes and resources.  Each instance of <tt>ClassLoader</tt> has an
  116.65 + * associated parent class loader.  When requested to find a class or
  116.66 + * resource, a <tt>ClassLoader</tt> instance will delegate the search for the
  116.67 + * class or resource to its parent class loader before attempting to find the
  116.68 + * class or resource itself.  The virtual machine's built-in class loader,
  116.69 + * called the "bootstrap class loader", does not itself have a parent but may
  116.70 + * serve as the parent of a <tt>ClassLoader</tt> instance.
  116.71 + *
  116.72 + * <p> Class loaders that support concurrent loading of classes are known as
  116.73 + * <em>parallel capable</em> class loaders and are required to register
  116.74 + * themselves at their class initialization time by invoking the
  116.75 + * {@link
  116.76 + * #registerAsParallelCapable <tt>ClassLoader.registerAsParallelCapable</tt>}
  116.77 + * method. Note that the <tt>ClassLoader</tt> class is registered as parallel
  116.78 + * capable by default. However, its subclasses still need to register themselves
  116.79 + * if they are parallel capable. <br>
  116.80 + * In environments in which the delegation model is not strictly
  116.81 + * hierarchical, class loaders need to be parallel capable, otherwise class
  116.82 + * loading can lead to deadlocks because the loader lock is held for the
  116.83 + * duration of the class loading process (see {@link #loadClass
  116.84 + * <tt>loadClass</tt>} methods).
  116.85 + *
  116.86 + * <p> Normally, the Java virtual machine loads classes from the local file
  116.87 + * system in a platform-dependent manner.  For example, on UNIX systems, the
  116.88 + * virtual machine loads classes from the directory defined by the
  116.89 + * <tt>CLASSPATH</tt> environment variable.
  116.90 + *
  116.91 + * <p> However, some classes may not originate from a file; they may originate
  116.92 + * from other sources, such as the network, or they could be constructed by an
  116.93 + * application.  The method {@link #defineClass(String, byte[], int, int)
  116.94 + * <tt>defineClass</tt>} converts an array of bytes into an instance of class
  116.95 + * <tt>Class</tt>. Instances of this newly defined class can be created using
  116.96 + * {@link Class#newInstance <tt>Class.newInstance</tt>}.
  116.97 + *
  116.98 + * <p> The methods and constructors of objects created by a class loader may
  116.99 + * reference other classes.  To determine the class(es) referred to, the Java
 116.100 + * virtual machine invokes the {@link #loadClass <tt>loadClass</tt>} method of
 116.101 + * the class loader that originally created the class.
 116.102 + *
 116.103 + * <p> For example, an application could create a network class loader to
 116.104 + * download class files from a server.  Sample code might look like:
 116.105 + *
 116.106 + * <blockquote><pre>
 116.107 + *   ClassLoader loader&nbsp;= new NetworkClassLoader(host,&nbsp;port);
 116.108 + *   Object main&nbsp;= loader.loadClass("Main", true).newInstance();
 116.109 + *       &nbsp;.&nbsp;.&nbsp;.
 116.110 + * </pre></blockquote>
 116.111 + *
 116.112 + * <p> The network class loader subclass must define the methods {@link
 116.113 + * #findClass <tt>findClass</tt>} and <tt>loadClassData</tt> to load a class
 116.114 + * from the network.  Once it has downloaded the bytes that make up the class,
 116.115 + * it should use the method {@link #defineClass <tt>defineClass</tt>} to
 116.116 + * create a class instance.  A sample implementation is:
 116.117 + *
 116.118 + * <blockquote><pre>
 116.119 + *     class NetworkClassLoader extends ClassLoader {
 116.120 + *         String host;
 116.121 + *         int port;
 116.122 + *
 116.123 + *         public Class findClass(String name) {
 116.124 + *             byte[] b = loadClassData(name);
 116.125 + *             return defineClass(name, b, 0, b.length);
 116.126 + *         }
 116.127 + *
 116.128 + *         private byte[] loadClassData(String name) {
 116.129 + *             // load the class data from the connection
 116.130 + *             &nbsp;.&nbsp;.&nbsp;.
 116.131 + *         }
 116.132 + *     }
 116.133 + * </pre></blockquote>
 116.134 + *
 116.135 + * <h4> <a name="name">Binary names</a> </h4>
 116.136 + *
 116.137 + * <p> Any class name provided as a {@link String} parameter to methods in
 116.138 + * <tt>ClassLoader</tt> must be a binary name as defined by
 116.139 + * <cite>The Java&trade; Language Specification</cite>.
 116.140 + *
 116.141 + * <p> Examples of valid class names include:
 116.142 + * <blockquote><pre>
 116.143 + *   "java.lang.String"
 116.144 + *   "javax.swing.JSpinner$DefaultEditor"
 116.145 + *   "java.security.KeyStore$Builder$FileBuilder$1"
 116.146 + *   "java.net.URLClassLoader$3$1"
 116.147 + * </pre></blockquote>
 116.148 + *
 116.149 + * @see      #resolveClass(Class)
 116.150 + * @since 1.0
 116.151 + */
 116.152 +public abstract class ClassLoader {
 116.153 +
 116.154 +    @JavaScriptBody(args = {}, body = "")
 116.155 +    private static native void registerNatives();
 116.156 +    static {
 116.157 +        registerNatives();
 116.158 +    }
 116.159 +
 116.160 +    // The parent class loader for delegation
 116.161 +    // Note: VM hardcoded the offset of this field, thus all new fields
 116.162 +    // must be added *after* it.
 116.163 +    private final ClassLoader parent;
 116.164 +
 116.165 +
 116.166 +    /**
 116.167 +     * Creates a new class loader using the specified parent class loader for
 116.168 +     * delegation.
 116.169 +     *
 116.170 +     * <p> If there is a security manager, its {@link
 116.171 +     * SecurityManager#checkCreateClassLoader()
 116.172 +     * <tt>checkCreateClassLoader</tt>} method is invoked.  This may result in
 116.173 +     * a security exception.  </p>
 116.174 +     *
 116.175 +     * @param  parent
 116.176 +     *         The parent class loader
 116.177 +     *
 116.178 +     * @throws  SecurityException
 116.179 +     *          If a security manager exists and its
 116.180 +     *          <tt>checkCreateClassLoader</tt> method doesn't allow creation
 116.181 +     *          of a new class loader.
 116.182 +     *
 116.183 +     * @since  1.2
 116.184 +     */
 116.185 +    protected ClassLoader(ClassLoader parent) {
 116.186 +        throw new SecurityException();
 116.187 +    }
 116.188 +
 116.189 +    /**
 116.190 +     * Creates a new class loader using the <tt>ClassLoader</tt> returned by
 116.191 +     * the method {@link #getSystemClassLoader()
 116.192 +     * <tt>getSystemClassLoader()</tt>} as the parent class loader.
 116.193 +     *
 116.194 +     * <p> If there is a security manager, its {@link
 116.195 +     * SecurityManager#checkCreateClassLoader()
 116.196 +     * <tt>checkCreateClassLoader</tt>} method is invoked.  This may result in
 116.197 +     * a security exception.  </p>
 116.198 +     *
 116.199 +     * @throws  SecurityException
 116.200 +     *          If a security manager exists and its
 116.201 +     *          <tt>checkCreateClassLoader</tt> method doesn't allow creation
 116.202 +     *          of a new class loader.
 116.203 +     */
 116.204 +    protected ClassLoader() {
 116.205 +        throw new SecurityException();
 116.206 +    }
 116.207 +
 116.208 +    // -- Class --
 116.209 +
 116.210 +    /**
 116.211 +     * Loads the class with the specified <a href="#name">binary name</a>.
 116.212 +     * This method searches for classes in the same manner as the {@link
 116.213 +     * #loadClass(String, boolean)} method.  It is invoked by the Java virtual
 116.214 +     * machine to resolve class references.  Invoking this method is equivalent
 116.215 +     * to invoking {@link #loadClass(String, boolean) <tt>loadClass(name,
 116.216 +     * false)</tt>}.  </p>
 116.217 +     *
 116.218 +     * @param  name
 116.219 +     *         The <a href="#name">binary name</a> of the class
 116.220 +     *
 116.221 +     * @return  The resulting <tt>Class</tt> object
 116.222 +     *
 116.223 +     * @throws  ClassNotFoundException
 116.224 +     *          If the class was not found
 116.225 +     */
 116.226 +    public Class<?> loadClass(String name) throws ClassNotFoundException {
 116.227 +        return loadClass(name, false);
 116.228 +    }
 116.229 +
 116.230 +    /**
 116.231 +     * Loads the class with the specified <a href="#name">binary name</a>.  The
 116.232 +     * default implementation of this method searches for classes in the
 116.233 +     * following order:
 116.234 +     *
 116.235 +     * <p><ol>
 116.236 +     *
 116.237 +     *   <li><p> Invoke {@link #findLoadedClass(String)} to check if the class
 116.238 +     *   has already been loaded.  </p></li>
 116.239 +     *
 116.240 +     *   <li><p> Invoke the {@link #loadClass(String) <tt>loadClass</tt>} method
 116.241 +     *   on the parent class loader.  If the parent is <tt>null</tt> the class
 116.242 +     *   loader built-in to the virtual machine is used, instead.  </p></li>
 116.243 +     *
 116.244 +     *   <li><p> Invoke the {@link #findClass(String)} method to find the
 116.245 +     *   class.  </p></li>
 116.246 +     *
 116.247 +     * </ol>
 116.248 +     *
 116.249 +     * <p> If the class was found using the above steps, and the
 116.250 +     * <tt>resolve</tt> flag is true, this method will then invoke the {@link
 116.251 +     * #resolveClass(Class)} method on the resulting <tt>Class</tt> object.
 116.252 +     *
 116.253 +     * <p> Subclasses of <tt>ClassLoader</tt> are encouraged to override {@link
 116.254 +     * #findClass(String)}, rather than this method.  </p>
 116.255 +     *
 116.256 +     * <p> Unless overridden, this method synchronizes on the result of
 116.257 +     * {@link #getClassLoadingLock <tt>getClassLoadingLock</tt>} method
 116.258 +     * during the entire class loading process.
 116.259 +     *
 116.260 +     * @param  name
 116.261 +     *         The <a href="#name">binary name</a> of the class
 116.262 +     *
 116.263 +     * @param  resolve
 116.264 +     *         If <tt>true</tt> then resolve the class
 116.265 +     *
 116.266 +     * @return  The resulting <tt>Class</tt> object
 116.267 +     *
 116.268 +     * @throws  ClassNotFoundException
 116.269 +     *          If the class could not be found
 116.270 +     */
 116.271 +    protected Class<?> loadClass(String name, boolean resolve)
 116.272 +        throws ClassNotFoundException
 116.273 +    {
 116.274 +        synchronized (getClassLoadingLock(name)) {
 116.275 +            // First, check if the class has already been loaded
 116.276 +            Class c = findLoadedClass(name);
 116.277 +            if (c == null) {
 116.278 +                try {
 116.279 +                    if (parent != null) {
 116.280 +                        c = parent.loadClass(name, false);
 116.281 +                    } else {
 116.282 +                        c = findBootstrapClassOrNull(name);
 116.283 +                    }
 116.284 +                } catch (ClassNotFoundException e) {
 116.285 +                    // ClassNotFoundException thrown if class not found
 116.286 +                    // from the non-null parent class loader
 116.287 +                }
 116.288 +
 116.289 +                if (c == null) {
 116.290 +                    // If still not found, then invoke findClass in order
 116.291 +                    // to find the class.
 116.292 +                    c = findClass(name);
 116.293 +
 116.294 +//                    // this is the defining class loader; record the stats
 116.295 +//                    sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
 116.296 +//                    sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
 116.297 +//                    sun.misc.PerfCounter.getFindClasses().increment();
 116.298 +                }
 116.299 +            }
 116.300 +            if (resolve) {
 116.301 +                resolveClass(c);
 116.302 +            }
 116.303 +            return c;
 116.304 +        }
 116.305 +    }
 116.306 +
 116.307 +    /**
 116.308 +     * Returns the lock object for class loading operations.
 116.309 +     * For backward compatibility, the default implementation of this method
 116.310 +     * behaves as follows. If this ClassLoader object is registered as
 116.311 +     * parallel capable, the method returns a dedicated object associated
 116.312 +     * with the specified class name. Otherwise, the method returns this
 116.313 +     * ClassLoader object. </p>
 116.314 +     *
 116.315 +     * @param  className
 116.316 +     *         The name of the to-be-loaded class
 116.317 +     *
 116.318 +     * @return the lock for class loading operations
 116.319 +     *
 116.320 +     * @throws NullPointerException
 116.321 +     *         If registered as parallel capable and <tt>className</tt> is null
 116.322 +     *
 116.323 +     * @see #loadClass(String, boolean)
 116.324 +     *
 116.325 +     * @since  1.7
 116.326 +     */
 116.327 +    protected Object getClassLoadingLock(String className) {
 116.328 +        Object lock = this;
 116.329 +        return lock;
 116.330 +    }
 116.331 +
 116.332 +    /**
 116.333 +     * Finds the class with the specified <a href="#name">binary name</a>.
 116.334 +     * This method should be overridden by class loader implementations that
 116.335 +     * follow the delegation model for loading classes, and will be invoked by
 116.336 +     * the {@link #loadClass <tt>loadClass</tt>} method after checking the
 116.337 +     * parent class loader for the requested class.  The default implementation
 116.338 +     * throws a <tt>ClassNotFoundException</tt>.  </p>
 116.339 +     *
 116.340 +     * @param  name
 116.341 +     *         The <a href="#name">binary name</a> of the class
 116.342 +     *
 116.343 +     * @return  The resulting <tt>Class</tt> object
 116.344 +     *
 116.345 +     * @throws  ClassNotFoundException
 116.346 +     *          If the class could not be found
 116.347 +     *
 116.348 +     * @since  1.2
 116.349 +     */
 116.350 +    protected Class<?> findClass(String name) throws ClassNotFoundException {
 116.351 +        throw new ClassNotFoundException(name);
 116.352 +    }
 116.353 +
 116.354 +    /**
 116.355 +     * Converts an array of bytes into an instance of class <tt>Class</tt>.
 116.356 +     * Before the <tt>Class</tt> can be used it must be resolved.  This method
 116.357 +     * is deprecated in favor of the version that takes a <a
 116.358 +     * href="#name">binary name</a> as its first argument, and is more secure.
 116.359 +     *
 116.360 +     * @param  b
 116.361 +     *         The bytes that make up the class data.  The bytes in positions
 116.362 +     *         <tt>off</tt> through <tt>off+len-1</tt> should have the format
 116.363 +     *         of a valid class file as defined by
 116.364 +     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
 116.365 +     *
 116.366 +     * @param  off
 116.367 +     *         The start offset in <tt>b</tt> of the class data
 116.368 +     *
 116.369 +     * @param  len
 116.370 +     *         The length of the class data
 116.371 +     *
 116.372 +     * @return  The <tt>Class</tt> object that was created from the specified
 116.373 +     *          class data
 116.374 +     *
 116.375 +     * @throws  ClassFormatError
 116.376 +     *          If the data did not contain a valid class
 116.377 +     *
 116.378 +     * @throws  IndexOutOfBoundsException
 116.379 +     *          If either <tt>off</tt> or <tt>len</tt> is negative, or if
 116.380 +     *          <tt>off+len</tt> is greater than <tt>b.length</tt>.
 116.381 +     *
 116.382 +     * @throws  SecurityException
 116.383 +     *          If an attempt is made to add this class to a package that
 116.384 +     *          contains classes that were signed by a different set of
 116.385 +     *          certificates than this class, or if an attempt is made
 116.386 +     *          to define a class in a package with a fully-qualified name
 116.387 +     *          that starts with "{@code java.}".
 116.388 +     *
 116.389 +     * @see  #loadClass(String, boolean)
 116.390 +     * @see  #resolveClass(Class)
 116.391 +     *
 116.392 +     * @deprecated  Replaced by {@link #defineClass(String, byte[], int, int)
 116.393 +     * defineClass(String, byte[], int, int)}
 116.394 +     */
 116.395 +    @Deprecated
 116.396 +    protected final Class<?> defineClass(byte[] b, int off, int len)
 116.397 +        throws ClassFormatError
 116.398 +    {
 116.399 +        throw new SecurityException();
 116.400 +    }
 116.401 +
 116.402 +    /**
 116.403 +     * Converts an array of bytes into an instance of class <tt>Class</tt>.
 116.404 +     * Before the <tt>Class</tt> can be used it must be resolved.
 116.405 +     *
 116.406 +     * <p> This method assigns a default {@link java.security.ProtectionDomain
 116.407 +     * <tt>ProtectionDomain</tt>} to the newly defined class.  The
 116.408 +     * <tt>ProtectionDomain</tt> is effectively granted the same set of
 116.409 +     * permissions returned when {@link
 116.410 +     * java.security.Policy#getPermissions(java.security.CodeSource)
 116.411 +     * <tt>Policy.getPolicy().getPermissions(new CodeSource(null, null))</tt>}
 116.412 +     * is invoked.  The default domain is created on the first invocation of
 116.413 +     * {@link #defineClass(String, byte[], int, int) <tt>defineClass</tt>},
 116.414 +     * and re-used on subsequent invocations.
 116.415 +     *
 116.416 +     * <p> To assign a specific <tt>ProtectionDomain</tt> to the class, use
 116.417 +     * the {@link #defineClass(String, byte[], int, int,
 116.418 +     * java.security.ProtectionDomain) <tt>defineClass</tt>} method that takes a
 116.419 +     * <tt>ProtectionDomain</tt> as one of its arguments.  </p>
 116.420 +     *
 116.421 +     * @param  name
 116.422 +     *         The expected <a href="#name">binary name</a> of the class, or
 116.423 +     *         <tt>null</tt> if not known
 116.424 +     *
 116.425 +     * @param  b
 116.426 +     *         The bytes that make up the class data.  The bytes in positions
 116.427 +     *         <tt>off</tt> through <tt>off+len-1</tt> should have the format
 116.428 +     *         of a valid class file as defined by
 116.429 +     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
 116.430 +     *
 116.431 +     * @param  off
 116.432 +     *         The start offset in <tt>b</tt> of the class data
 116.433 +     *
 116.434 +     * @param  len
 116.435 +     *         The length of the class data
 116.436 +     *
 116.437 +     * @return  The <tt>Class</tt> object that was created from the specified
 116.438 +     *          class data.
 116.439 +     *
 116.440 +     * @throws  ClassFormatError
 116.441 +     *          If the data did not contain a valid class
 116.442 +     *
 116.443 +     * @throws  IndexOutOfBoundsException
 116.444 +     *          If either <tt>off</tt> or <tt>len</tt> is negative, or if
 116.445 +     *          <tt>off+len</tt> is greater than <tt>b.length</tt>.
 116.446 +     *
 116.447 +     * @throws  SecurityException
 116.448 +     *          If an attempt is made to add this class to a package that
 116.449 +     *          contains classes that were signed by a different set of
 116.450 +     *          certificates than this class (which is unsigned), or if
 116.451 +     *          <tt>name</tt> begins with "<tt>java.</tt>".
 116.452 +     *
 116.453 +     * @see  #loadClass(String, boolean)
 116.454 +     * @see  #resolveClass(Class)
 116.455 +     * @see  java.security.CodeSource
 116.456 +     * @see  java.security.SecureClassLoader
 116.457 +     *
 116.458 +     * @since  1.1
 116.459 +     */
 116.460 +    protected final Class<?> defineClass(String name, byte[] b, int off, int len)
 116.461 +        throws ClassFormatError
 116.462 +    {
 116.463 +        throw new SecurityException();
 116.464 +    }
 116.465 +
 116.466 +    /**
 116.467 +     * Links the specified class.  This (misleadingly named) method may be
 116.468 +     * used by a class loader to link a class.  If the class <tt>c</tt> has
 116.469 +     * already been linked, then this method simply returns. Otherwise, the
 116.470 +     * class is linked as described in the "Execution" chapter of
 116.471 +     * <cite>The Java&trade; Language Specification</cite>.
 116.472 +     * </p>
 116.473 +     *
 116.474 +     * @param  c
 116.475 +     *         The class to link
 116.476 +     *
 116.477 +     * @throws  NullPointerException
 116.478 +     *          If <tt>c</tt> is <tt>null</tt>.
 116.479 +     *
 116.480 +     * @see  #defineClass(String, byte[], int, int)
 116.481 +     */
 116.482 +    protected final void resolveClass(Class<?> c) {
 116.483 +        resolveClass0(c);
 116.484 +    }
 116.485 +
 116.486 +    private native void resolveClass0(Class c);
 116.487 +
 116.488 +
 116.489 +    /**
 116.490 +     * Returns the class with the given <a href="#name">binary name</a> if this
 116.491 +     * loader has been recorded by the Java virtual machine as an initiating
 116.492 +     * loader of a class with that <a href="#name">binary name</a>.  Otherwise
 116.493 +     * <tt>null</tt> is returned.  </p>
 116.494 +     *
 116.495 +     * @param  name
 116.496 +     *         The <a href="#name">binary name</a> of the class
 116.497 +     *
 116.498 +     * @return  The <tt>Class</tt> object, or <tt>null</tt> if the class has
 116.499 +     *          not been loaded
 116.500 +     *
 116.501 +     * @since  1.1
 116.502 +     */
 116.503 +    protected final Class<?> findLoadedClass(String name) {
 116.504 +        if (!checkName(name))
 116.505 +            return null;
 116.506 +        return findLoadedClass0(name);
 116.507 +    }
 116.508 +
 116.509 +    private native final Class findLoadedClass0(String name);
 116.510 +
 116.511 +    /**
 116.512 +     * Sets the signers of a class.  This should be invoked after defining a
 116.513 +     * class.  </p>
 116.514 +     *
 116.515 +     * @param  c
 116.516 +     *         The <tt>Class</tt> object
 116.517 +     *
 116.518 +     * @param  signers
 116.519 +     *         The signers for the class
 116.520 +     *
 116.521 +     * @since  1.1
 116.522 +     */
 116.523 +    protected final void setSigners(Class<?> c, Object[] signers) {
 116.524 +        //c.setSigners(signers);
 116.525 +        throw new UnsupportedOperationException();
 116.526 +    }
 116.527 +
 116.528 +
 116.529 +    // -- Resource --
 116.530 +
 116.531 +    /**
 116.532 +     * Finds the resource with the given name.  A resource is some data
 116.533 +     * (images, audio, text, etc) that can be accessed by class code in a way
 116.534 +     * that is independent of the location of the code.
 116.535 +     *
 116.536 +     * <p> The name of a resource is a '<tt>/</tt>'-separated path name that
 116.537 +     * identifies the resource.
 116.538 +     *
 116.539 +     * <p> This method will first search the parent class loader for the
 116.540 +     * resource; if the parent is <tt>null</tt> the path of the class loader
 116.541 +     * built-in to the virtual machine is searched.  That failing, this method
 116.542 +     * will invoke {@link #findResource(String)} to find the resource.  </p>
 116.543 +     *
 116.544 +     * @param  name
 116.545 +     *         The resource name
 116.546 +     *
 116.547 +     * @return  A <tt>URL</tt> object for reading the resource, or
 116.548 +     *          <tt>null</tt> if the resource could not be found or the invoker
 116.549 +     *          doesn't have adequate  privileges to get the resource.
 116.550 +     *
 116.551 +     * @since  1.1
 116.552 +     */
 116.553 +    public URL getResource(String name) {
 116.554 +        URL url;
 116.555 +        if (parent != null) {
 116.556 +            url = parent.getResource(name);
 116.557 +        } else {
 116.558 +            url = getBootstrapResource(name);
 116.559 +        }
 116.560 +        if (url == null) {
 116.561 +            url = findResource(name);
 116.562 +        }
 116.563 +        return url;
 116.564 +    }
 116.565 +
 116.566 +    /**
 116.567 +     * Finds all the resources with the given name. A resource is some data
 116.568 +     * (images, audio, text, etc) that can be accessed by class code in a way
 116.569 +     * that is independent of the location of the code.
 116.570 +     *
 116.571 +     * <p>The name of a resource is a <tt>/</tt>-separated path name that
 116.572 +     * identifies the resource.
 116.573 +     *
 116.574 +     * <p> The search order is described in the documentation for {@link
 116.575 +     * #getResource(String)}.  </p>
 116.576 +     *
 116.577 +     * @param  name
 116.578 +     *         The resource name
 116.579 +     *
 116.580 +     * @return  An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
 116.581 +     *          the resource.  If no resources could  be found, the enumeration
 116.582 +     *          will be empty.  Resources that the class loader doesn't have
 116.583 +     *          access to will not be in the enumeration.
 116.584 +     *
 116.585 +     * @throws  IOException
 116.586 +     *          If I/O errors occur
 116.587 +     *
 116.588 +     * @see  #findResources(String)
 116.589 +     *
 116.590 +     * @since  1.2
 116.591 +     */
 116.592 +    public Enumeration<URL> getResources(String name) throws IOException {
 116.593 +        Enumeration[] tmp = new Enumeration[2];
 116.594 +        if (parent != null) {
 116.595 +            tmp[0] = parent.getResources(name);
 116.596 +        } else {
 116.597 +            tmp[0] = getBootstrapResources(name);
 116.598 +        }
 116.599 +        tmp[1] = findResources(name);
 116.600 +
 116.601 +        return new CompoundEnumeration(tmp);
 116.602 +    }
 116.603 +
 116.604 +    /**
 116.605 +     * Finds the resource with the given name. Class loader implementations
 116.606 +     * should override this method to specify where to find resources.  </p>
 116.607 +     *
 116.608 +     * @param  name
 116.609 +     *         The resource name
 116.610 +     *
 116.611 +     * @return  A <tt>URL</tt> object for reading the resource, or
 116.612 +     *          <tt>null</tt> if the resource could not be found
 116.613 +     *
 116.614 +     * @since  1.2
 116.615 +     */
 116.616 +    protected URL findResource(String name) {
 116.617 +        return null;
 116.618 +    }
 116.619 +
 116.620 +    /**
 116.621 +     * Returns an enumeration of {@link java.net.URL <tt>URL</tt>} objects
 116.622 +     * representing all the resources with the given name. Class loader
 116.623 +     * implementations should override this method to specify where to load
 116.624 +     * resources from.  </p>
 116.625 +     *
 116.626 +     * @param  name
 116.627 +     *         The resource name
 116.628 +     *
 116.629 +     * @return  An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
 116.630 +     *          the resources
 116.631 +     *
 116.632 +     * @throws  IOException
 116.633 +     *          If I/O errors occur
 116.634 +     *
 116.635 +     * @since  1.2
 116.636 +     */
 116.637 +    protected Enumeration<URL> findResources(String name) throws IOException {
 116.638 +        return new CompoundEnumeration(new Enumeration[0]);
 116.639 +    }
 116.640 +
 116.641 +    // index 0: java.lang.ClassLoader.class
 116.642 +    // index 1: the immediate caller of index 0.
 116.643 +    // index 2: the immediate caller of index 1.
 116.644 +    private static native Class<? extends ClassLoader> getCaller(int index);
 116.645 +
 116.646 +    /**
 116.647 +     * Registers the caller as parallel capable.</p>
 116.648 +     * The registration succeeds if and only if all of the following
 116.649 +     * conditions are met: <br>
 116.650 +     * 1. no instance of the caller has been created</p>
 116.651 +     * 2. all of the super classes (except class Object) of the caller are
 116.652 +     * registered as parallel capable</p>
 116.653 +     * Note that once a class loader is registered as parallel capable, there
 116.654 +     * is no way to change it back. </p>
 116.655 +     *
 116.656 +     * @return  true if the caller is successfully registered as
 116.657 +     *          parallel capable and false if otherwise.
 116.658 +     *
 116.659 +     * @since   1.7
 116.660 +     */
 116.661 +//    protected static boolean registerAsParallelCapable() {
 116.662 +//        return false;
 116.663 +//    }
 116.664 +
 116.665 +    /**
 116.666 +     * Find a resource of the specified name from the search path used to load
 116.667 +     * classes.  This method locates the resource through the system class
 116.668 +     * loader (see {@link #getSystemClassLoader()}).  </p>
 116.669 +     *
 116.670 +     * @param  name
 116.671 +     *         The resource name
 116.672 +     *
 116.673 +     * @return  A {@link java.net.URL <tt>URL</tt>} object for reading the
 116.674 +     *          resource, or <tt>null</tt> if the resource could not be found
 116.675 +     *
 116.676 +     * @since  1.1
 116.677 +     */
 116.678 +    public static URL getSystemResource(String name) {
 116.679 +        ClassLoader system = getSystemClassLoader();
 116.680 +        if (system == null) {
 116.681 +            return getBootstrapResource(name);
 116.682 +        }
 116.683 +        return system.getResource(name);
 116.684 +    }
 116.685 +
 116.686 +    /**
 116.687 +     * Finds all resources of the specified name from the search path used to
 116.688 +     * load classes.  The resources thus found are returned as an
 116.689 +     * {@link java.util.Enumeration <tt>Enumeration</tt>} of {@link
 116.690 +     * java.net.URL <tt>URL</tt>} objects.
 116.691 +     *
 116.692 +     * <p> The search order is described in the documentation for {@link
 116.693 +     * #getSystemResource(String)}.  </p>
 116.694 +     *
 116.695 +     * @param  name
 116.696 +     *         The resource name
 116.697 +     *
 116.698 +     * @return  An enumeration of resource {@link java.net.URL <tt>URL</tt>}
 116.699 +     *          objects
 116.700 +     *
 116.701 +     * @throws  IOException
 116.702 +     *          If I/O errors occur
 116.703 +
 116.704 +     * @since  1.2
 116.705 +     */
 116.706 +    public static Enumeration<URL> getSystemResources(String name)
 116.707 +        throws IOException
 116.708 +    {
 116.709 +        ClassLoader system = null; // getSystemClassLoader();
 116.710 +        if (system == null) {
 116.711 +            return getBootstrapResources(name);
 116.712 +        }
 116.713 +        return system.getResources(name);
 116.714 +    }
 116.715 +
 116.716 +
 116.717 +
 116.718 +    /**
 116.719 +     * Returns an input stream for reading the specified resource.
 116.720 +     *
 116.721 +     * <p> The search order is described in the documentation for {@link
 116.722 +     * #getResource(String)}.  </p>
 116.723 +     *
 116.724 +     * @param  name
 116.725 +     *         The resource name
 116.726 +     *
 116.727 +     * @return  An input stream for reading the resource, or <tt>null</tt>
 116.728 +     *          if the resource could not be found
 116.729 +     *
 116.730 +     * @since  1.1
 116.731 +     */
 116.732 +    public InputStream getResourceAsStream(String name) {
 116.733 +        URL url = getResource(name);
 116.734 +        try {
 116.735 +            return url != null ? url.openStream() : null;
 116.736 +        } catch (IOException e) {
 116.737 +            return null;
 116.738 +        }
 116.739 +    }
 116.740 +
 116.741 +    /**
 116.742 +     * Open for reading, a resource of the specified name from the search path
 116.743 +     * used to load classes.  This method locates the resource through the
 116.744 +     * system class loader (see {@link #getSystemClassLoader()}).  </p>
 116.745 +     *
 116.746 +     * @param  name
 116.747 +     *         The resource name
 116.748 +     *
 116.749 +     * @return  An input stream for reading the resource, or <tt>null</tt>
 116.750 +     *          if the resource could not be found
 116.751 +     *
 116.752 +     * @since  1.1
 116.753 +     */
 116.754 +    public static InputStream getSystemResourceAsStream(String name) {
 116.755 +        URL url = getSystemResource(name);
 116.756 +        try {
 116.757 +            return url != null ? url.openStream() : null;
 116.758 +        } catch (IOException e) {
 116.759 +            return null;
 116.760 +        }
 116.761 +    }
 116.762 +
 116.763 +
 116.764 +    // -- Hierarchy --
 116.765 +
 116.766 +    /**
 116.767 +     * Returns the parent class loader for delegation. Some implementations may
 116.768 +     * use <tt>null</tt> to represent the bootstrap class loader. This method
 116.769 +     * will return <tt>null</tt> in such implementations if this class loader's
 116.770 +     * parent is the bootstrap class loader.
 116.771 +     *
 116.772 +     * <p> If a security manager is present, and the invoker's class loader is
 116.773 +     * not <tt>null</tt> and is not an ancestor of this class loader, then this
 116.774 +     * method invokes the security manager's {@link
 116.775 +     * SecurityManager#checkPermission(java.security.Permission)
 116.776 +     * <tt>checkPermission</tt>} method with a {@link
 116.777 +     * RuntimePermission#RuntimePermission(String)
 116.778 +     * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
 116.779 +     * access to the parent class loader is permitted.  If not, a
 116.780 +     * <tt>SecurityException</tt> will be thrown.  </p>
 116.781 +     *
 116.782 +     * @return  The parent <tt>ClassLoader</tt>
 116.783 +     *
 116.784 +     * @throws  SecurityException
 116.785 +     *          If a security manager exists and its <tt>checkPermission</tt>
 116.786 +     *          method doesn't allow access to this class loader's parent class
 116.787 +     *          loader.
 116.788 +     *
 116.789 +     * @since  1.2
 116.790 +     */
 116.791 +    public final ClassLoader getParent() {
 116.792 +        throw new SecurityException();
 116.793 +    }
 116.794 +
 116.795 +    /**
 116.796 +     * Returns the system class loader for delegation.  This is the default
 116.797 +     * delegation parent for new <tt>ClassLoader</tt> instances, and is
 116.798 +     * typically the class loader used to start the application.
 116.799 +     *
 116.800 +     * <p> This method is first invoked early in the runtime's startup
 116.801 +     * sequence, at which point it creates the system class loader and sets it
 116.802 +     * as the context class loader of the invoking <tt>Thread</tt>.
 116.803 +     *
 116.804 +     * <p> The default system class loader is an implementation-dependent
 116.805 +     * instance of this class.
 116.806 +     *
 116.807 +     * <p> If the system property "<tt>java.system.class.loader</tt>" is defined
 116.808 +     * when this method is first invoked then the value of that property is
 116.809 +     * taken to be the name of a class that will be returned as the system
 116.810 +     * class loader.  The class is loaded using the default system class loader
 116.811 +     * and must define a public constructor that takes a single parameter of
 116.812 +     * type <tt>ClassLoader</tt> which is used as the delegation parent.  An
 116.813 +     * instance is then created using this constructor with the default system
 116.814 +     * class loader as the parameter.  The resulting class loader is defined
 116.815 +     * to be the system class loader.
 116.816 +     *
 116.817 +     * <p> If a security manager is present, and the invoker's class loader is
 116.818 +     * not <tt>null</tt> and the invoker's class loader is not the same as or
 116.819 +     * an ancestor of the system class loader, then this method invokes the
 116.820 +     * security manager's {@link
 116.821 +     * SecurityManager#checkPermission(java.security.Permission)
 116.822 +     * <tt>checkPermission</tt>} method with a {@link
 116.823 +     * RuntimePermission#RuntimePermission(String)
 116.824 +     * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
 116.825 +     * access to the system class loader.  If not, a
 116.826 +     * <tt>SecurityException</tt> will be thrown.  </p>
 116.827 +     *
 116.828 +     * @return  The system <tt>ClassLoader</tt> for delegation, or
 116.829 +     *          <tt>null</tt> if none
 116.830 +     *
 116.831 +     * @throws  SecurityException
 116.832 +     *          If a security manager exists and its <tt>checkPermission</tt>
 116.833 +     *          method doesn't allow access to the system class loader.
 116.834 +     *
 116.835 +     * @throws  IllegalStateException
 116.836 +     *          If invoked recursively during the construction of the class
 116.837 +     *          loader specified by the "<tt>java.system.class.loader</tt>"
 116.838 +     *          property.
 116.839 +     *
 116.840 +     * @throws  Error
 116.841 +     *          If the system property "<tt>java.system.class.loader</tt>"
 116.842 +     *          is defined but the named class could not be loaded, the
 116.843 +     *          provider class does not define the required constructor, or an
 116.844 +     *          exception is thrown by that constructor when it is invoked. The
 116.845 +     *          underlying cause of the error can be retrieved via the
 116.846 +     *          {@link Throwable#getCause()} method.
 116.847 +     *
 116.848 +     * @revised  1.4
 116.849 +     */
 116.850 +    public static ClassLoader getSystemClassLoader() {
 116.851 +        throw new SecurityException();
 116.852 +    }
 116.853 +
 116.854 +    // Returns true if the specified class loader can be found in this class
 116.855 +    // loader's delegation chain.
 116.856 +    boolean isAncestor(ClassLoader cl) {
 116.857 +        ClassLoader acl = this;
 116.858 +        do {
 116.859 +            acl = acl.parent;
 116.860 +            if (cl == acl) {
 116.861 +                return true;
 116.862 +            }
 116.863 +        } while (acl != null);
 116.864 +        return false;
 116.865 +    }
 116.866 +
 116.867 +    private boolean checkName(String name) {
 116.868 +        throw new UnsupportedOperationException(); 
 116.869 +    }
 116.870 +
 116.871 +    private Class findBootstrapClassOrNull(String name) {
 116.872 +        throw new UnsupportedOperationException();
 116.873 +    }
 116.874 +
 116.875 +    private static URL getBootstrapResource(String name) {
 116.876 +        throw new UnsupportedOperationException();
 116.877 +    }
 116.878 +
 116.879 +    private static Enumeration<URL> getBootstrapResources(String name) {
 116.880 +        URL u = Object.class.getResource("/" + name);
 116.881 +        return new OneOrZeroEnum(u);
 116.882 +    }
 116.883 +    
 116.884 +    private static class OneOrZeroEnum implements Enumeration<URL> {
 116.885 +        private URL u;
 116.886 +
 116.887 +        public OneOrZeroEnum(URL u) {
 116.888 +            this.u = u;
 116.889 +        }
 116.890 +
 116.891 +        public boolean hasMoreElements() {
 116.892 +            return u != null;
 116.893 +        }
 116.894 +
 116.895 +        public URL nextElement() {
 116.896 +            URL r = u;
 116.897 +            if (r == null) {
 116.898 +                throw new NoSuchElementException();
 116.899 +            }
 116.900 +            u = null;
 116.901 +            return r;
 116.902 +        }
 116.903 +    }
 116.904 +
 116.905 +    private static class CompoundEnumeration implements Enumeration<URL> {
 116.906 +        private URL next;
 116.907 +        private int index;
 116.908 +        private final Enumeration[] arr;
 116.909 +
 116.910 +        public CompoundEnumeration(Enumeration[] arr) {
 116.911 +            this.arr = arr;
 116.912 +            this.index = 0;
 116.913 +        }
 116.914 +
 116.915 +        public boolean hasMoreElements() {
 116.916 +            if (next == null) {
 116.917 +                if (arr[index].hasMoreElements()) {
 116.918 +                    next = (URL) arr[index].nextElement();
 116.919 +                } else {
 116.920 +                    if (index < arr.length) {
 116.921 +                        index++;
 116.922 +                        return hasMoreElements();
 116.923 +                    }
 116.924 +                }
 116.925 +            }
 116.926 +            return next != null;
 116.927 +        }
 116.928 +
 116.929 +        public URL nextElement() {
 116.930 +            if (!hasMoreElements()) {
 116.931 +                throw new NoSuchElementException();
 116.932 +            }
 116.933 +            URL r = next;
 116.934 +            next = null;
 116.935 +            return r;
 116.936 +        }
 116.937 +        
 116.938 +    }
 116.939 +}
   117.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   117.2 +++ b/emul/mini/src/main/java/java/lang/ClassNotFoundException.java	Sun Feb 03 07:48:42 2013 +0100
   117.3 @@ -0,0 +1,125 @@
   117.4 +/*
   117.5 + * Copyright (c) 1995, 2004, 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 +/**
  117.32 + * Thrown when an application tries to load in a class through its
  117.33 + * string name using:
  117.34 + * <ul>
  117.35 + * <li>The <code>forName</code> method in class <code>Class</code>.
  117.36 + * <li>The <code>findSystemClass</code> method in class
  117.37 + *     <code>ClassLoader</code> .
  117.38 + * <li>The <code>loadClass</code> method in class <code>ClassLoader</code>.
  117.39 + * </ul>
  117.40 + * <p>
  117.41 + * but no definition for the class with the specified name could be found.
  117.42 + *
  117.43 + * <p>As of release 1.4, this exception has been retrofitted to conform to
  117.44 + * the general purpose exception-chaining mechanism.  The "optional exception
  117.45 + * that was raised while loading the class" that may be provided at
  117.46 + * construction time and accessed via the {@link #getException()} method is
  117.47 + * now known as the <i>cause</i>, and may be accessed via the {@link
  117.48 + * Throwable#getCause()} method, as well as the aforementioned "legacy method."
  117.49 + *
  117.50 + * @author  unascribed
  117.51 + * @see     java.lang.Class#forName(java.lang.String)
  117.52 + * @see     java.lang.ClassLoader#findSystemClass(java.lang.String)
  117.53 + * @see     java.lang.ClassLoader#loadClass(java.lang.String, boolean)
  117.54 + * @since   JDK1.0
  117.55 + */
  117.56 +public class ClassNotFoundException extends ReflectiveOperationException {
  117.57 +    /**
  117.58 +     * use serialVersionUID from JDK 1.1.X for interoperability
  117.59 +     */
  117.60 +     private static final long serialVersionUID = 9176873029745254542L;
  117.61 +
  117.62 +    /**
  117.63 +     * This field holds the exception ex if the
  117.64 +     * ClassNotFoundException(String s, Throwable ex) constructor was
  117.65 +     * used to instantiate the object
  117.66 +     * @serial
  117.67 +     * @since 1.2
  117.68 +     */
  117.69 +    private Throwable ex;
  117.70 +
  117.71 +    /**
  117.72 +     * Constructs a <code>ClassNotFoundException</code> with no detail message.
  117.73 +     */
  117.74 +    public ClassNotFoundException() {
  117.75 +        super((Throwable)null);  // Disallow initCause
  117.76 +    }
  117.77 +
  117.78 +    /**
  117.79 +     * Constructs a <code>ClassNotFoundException</code> with the
  117.80 +     * specified detail message.
  117.81 +     *
  117.82 +     * @param   s   the detail message.
  117.83 +     */
  117.84 +    public ClassNotFoundException(String s) {
  117.85 +        super(s, null);  //  Disallow initCause
  117.86 +    }
  117.87 +
  117.88 +    /**
  117.89 +     * Constructs a <code>ClassNotFoundException</code> with the
  117.90 +     * specified detail message and optional exception that was
  117.91 +     * raised while loading the class.
  117.92 +     *
  117.93 +     * @param s the detail message
  117.94 +     * @param ex the exception that was raised while loading the class
  117.95 +     * @since 1.2
  117.96 +     */
  117.97 +    public ClassNotFoundException(String s, Throwable ex) {
  117.98 +        super(s, null);  //  Disallow initCause
  117.99 +        this.ex = ex;
 117.100 +    }
 117.101 +
 117.102 +    /**
 117.103 +     * Returns the exception that was raised if an error occurred while
 117.104 +     * attempting to load the class. Otherwise, returns <tt>null</tt>.
 117.105 +     *
 117.106 +     * <p>This method predates the general-purpose exception chaining facility.
 117.107 +     * The {@link Throwable#getCause()} method is now the preferred means of
 117.108 +     * obtaining this information.
 117.109 +     *
 117.110 +     * @return the <code>Exception</code> that was raised while loading a class
 117.111 +     * @since 1.2
 117.112 +     */
 117.113 +    public Throwable getException() {
 117.114 +        return ex;
 117.115 +    }
 117.116 +
 117.117 +    /**
 117.118 +     * Returns the cause of this exception (the exception that was raised
 117.119 +     * if an error occurred while attempting to load the class; otherwise
 117.120 +     * <tt>null</tt>).
 117.121 +     *
 117.122 +     * @return  the cause of this exception.
 117.123 +     * @since   1.4
 117.124 +     */
 117.125 +    public Throwable getCause() {
 117.126 +        return ex;
 117.127 +    }
 117.128 +}
   118.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   118.2 +++ b/emul/mini/src/main/java/java/lang/CloneNotSupportedException.java	Sun Feb 03 07:48:42 2013 +0100
   118.3 @@ -0,0 +1,65 @@
   118.4 +/*
   118.5 + * Copyright (c) 1995, 2008, 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 +/**
  118.32 + * Thrown to indicate that the <code>clone</code> method in class
  118.33 + * <code>Object</code> has been called to clone an object, but that
  118.34 + * the object's class does not implement the <code>Cloneable</code>
  118.35 + * interface.
  118.36 + * <p>
  118.37 + * Applications that override the <code>clone</code> method can also
  118.38 + * throw this exception to indicate that an object could not or
  118.39 + * should not be cloned.
  118.40 + *
  118.41 + * @author  unascribed
  118.42 + * @see     java.lang.Cloneable
  118.43 + * @see     java.lang.Object#clone()
  118.44 + * @since   JDK1.0
  118.45 + */
  118.46 +
  118.47 +public
  118.48 +class CloneNotSupportedException extends Exception {
  118.49 +    private static final long serialVersionUID = 5195511250079656443L;
  118.50 +
  118.51 +    /**
  118.52 +     * Constructs a <code>CloneNotSupportedException</code> with no
  118.53 +     * detail message.
  118.54 +     */
  118.55 +    public CloneNotSupportedException() {
  118.56 +        super();
  118.57 +    }
  118.58 +
  118.59 +    /**
  118.60 +     * Constructs a <code>CloneNotSupportedException</code> with the
  118.61 +     * specified detail message.
  118.62 +     *
  118.63 +     * @param   s   the detail message.
  118.64 +     */
  118.65 +    public CloneNotSupportedException(String s) {
  118.66 +        super(s);
  118.67 +    }
  118.68 +}
   119.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   119.2 +++ b/emul/mini/src/main/java/java/lang/Comparable.java	Sun Feb 03 07:48:42 2013 +0100
   119.3 @@ -0,0 +1,137 @@
   119.4 +/*
   119.5 + * Copyright (c) 1997, 2007, 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 + * This interface imposes a total ordering on the objects of each class that
  119.33 + * implements it.  This ordering is referred to as the class's <i>natural
  119.34 + * ordering</i>, and the class's <tt>compareTo</tt> method is referred to as
  119.35 + * its <i>natural comparison method</i>.<p>
  119.36 + *
  119.37 + * Lists (and arrays) of objects that implement this interface can be sorted
  119.38 + * automatically by {@link Collections#sort(List) Collections.sort} (and
  119.39 + * {@link Arrays#sort(Object[]) Arrays.sort}).  Objects that implement this
  119.40 + * interface can be used as keys in a {@linkplain SortedMap sorted map} or as
  119.41 + * elements in a {@linkplain SortedSet sorted set}, without the need to
  119.42 + * specify a {@linkplain Comparator comparator}.<p>
  119.43 + *
  119.44 + * The natural ordering for a class <tt>C</tt> is said to be <i>consistent
  119.45 + * with equals</i> if and only if <tt>e1.compareTo(e2) == 0</tt> has
  119.46 + * the same boolean value as <tt>e1.equals(e2)</tt> for every
  119.47 + * <tt>e1</tt> and <tt>e2</tt> of class <tt>C</tt>.  Note that <tt>null</tt>
  119.48 + * is not an instance of any class, and <tt>e.compareTo(null)</tt> should
  119.49 + * throw a <tt>NullPointerException</tt> even though <tt>e.equals(null)</tt>
  119.50 + * returns <tt>false</tt>.<p>
  119.51 + *
  119.52 + * It is strongly recommended (though not required) that natural orderings be
  119.53 + * consistent with equals.  This is so because sorted sets (and sorted maps)
  119.54 + * without explicit comparators behave "strangely" when they are used with
  119.55 + * elements (or keys) whose natural ordering is inconsistent with equals.  In
  119.56 + * particular, such a sorted set (or sorted map) violates the general contract
  119.57 + * for set (or map), which is defined in terms of the <tt>equals</tt>
  119.58 + * method.<p>
  119.59 + *
  119.60 + * For example, if one adds two keys <tt>a</tt> and <tt>b</tt> such that
  119.61 + * <tt>(!a.equals(b) && a.compareTo(b) == 0)</tt> to a sorted
  119.62 + * set that does not use an explicit comparator, the second <tt>add</tt>
  119.63 + * operation returns false (and the size of the sorted set does not increase)
  119.64 + * because <tt>a</tt> and <tt>b</tt> are equivalent from the sorted set's
  119.65 + * perspective.<p>
  119.66 + *
  119.67 + * Virtually all Java core classes that implement <tt>Comparable</tt> have natural
  119.68 + * orderings that are consistent with equals.  One exception is
  119.69 + * <tt>java.math.BigDecimal</tt>, whose natural ordering equates
  119.70 + * <tt>BigDecimal</tt> objects with equal values and different precisions
  119.71 + * (such as 4.0 and 4.00).<p>
  119.72 + *
  119.73 + * For the mathematically inclined, the <i>relation</i> that defines
  119.74 + * the natural ordering on a given class C is:<pre>
  119.75 + *       {(x, y) such that x.compareTo(y) &lt;= 0}.
  119.76 + * </pre> The <i>quotient</i> for this total order is: <pre>
  119.77 + *       {(x, y) such that x.compareTo(y) == 0}.
  119.78 + * </pre>
  119.79 + *
  119.80 + * It follows immediately from the contract for <tt>compareTo</tt> that the
  119.81 + * quotient is an <i>equivalence relation</i> on <tt>C</tt>, and that the
  119.82 + * natural ordering is a <i>total order</i> on <tt>C</tt>.  When we say that a
  119.83 + * class's natural ordering is <i>consistent with equals</i>, we mean that the
  119.84 + * quotient for the natural ordering is the equivalence relation defined by
  119.85 + * the class's {@link Object#equals(Object) equals(Object)} method:<pre>
  119.86 + *     {(x, y) such that x.equals(y)}. </pre><p>
  119.87 + *
  119.88 + * This interface is a member of the
  119.89 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  119.90 + * Java Collections Framework</a>.
  119.91 + *
  119.92 + * @param <T> the type of objects that this object may be compared to
  119.93 + *
  119.94 + * @author  Josh Bloch
  119.95 + * @see java.util.Comparator
  119.96 + * @since 1.2
  119.97 + */
  119.98 +
  119.99 +public interface Comparable<T> {
 119.100 +    /**
 119.101 +     * Compares this object with the specified object for order.  Returns a
 119.102 +     * negative integer, zero, or a positive integer as this object is less
 119.103 +     * than, equal to, or greater than the specified object.
 119.104 +     *
 119.105 +     * <p>The implementor must ensure <tt>sgn(x.compareTo(y)) ==
 119.106 +     * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
 119.107 +     * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
 119.108 +     * <tt>y.compareTo(x)</tt> throws an exception.)
 119.109 +     *
 119.110 +     * <p>The implementor must also ensure that the relation is transitive:
 119.111 +     * <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
 119.112 +     * <tt>x.compareTo(z)&gt;0</tt>.
 119.113 +     *
 119.114 +     * <p>Finally, the implementor must ensure that <tt>x.compareTo(y)==0</tt>
 119.115 +     * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
 119.116 +     * all <tt>z</tt>.
 119.117 +     *
 119.118 +     * <p>It is strongly recommended, but <i>not</i> strictly required that
 119.119 +     * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>.  Generally speaking, any
 119.120 +     * class that implements the <tt>Comparable</tt> interface and violates
 119.121 +     * this condition should clearly indicate this fact.  The recommended
 119.122 +     * language is "Note: this class has a natural ordering that is
 119.123 +     * inconsistent with equals."
 119.124 +     *
 119.125 +     * <p>In the foregoing description, the notation
 119.126 +     * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
 119.127 +     * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
 119.128 +     * <tt>0</tt>, or <tt>1</tt> according to whether the value of
 119.129 +     * <i>expression</i> is negative, zero or positive.
 119.130 +     *
 119.131 +     * @param   o the object to be compared.
 119.132 +     * @return  a negative integer, zero, or a positive integer as this object
 119.133 +     *          is less than, equal to, or greater than the specified object.
 119.134 +     *
 119.135 +     * @throws NullPointerException if the specified object is null
 119.136 +     * @throws ClassCastException if the specified object's type prevents it
 119.137 +     *         from being compared to this object.
 119.138 +     */
 119.139 +    public int compareTo(T o);
 119.140 +}
   120.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   120.2 +++ b/emul/mini/src/main/java/java/lang/Deprecated.java	Sun Feb 03 07:48:42 2013 +0100
   120.3 @@ -0,0 +1,44 @@
   120.4 +/*
   120.5 + * Copyright (c) 2003, 2010, 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 +import java.lang.annotation.*;
  120.32 +import static java.lang.annotation.ElementType.*;
  120.33 +
  120.34 +/**
  120.35 + * A program element annotated &#64;Deprecated is one that programmers
  120.36 + * are discouraged from using, typically because it is dangerous,
  120.37 + * or because a better alternative exists.  Compilers warn when a
  120.38 + * deprecated program element is used or overridden in non-deprecated code.
  120.39 + *
  120.40 + * @author  Neal Gafter
  120.41 + * @since 1.5
  120.42 + */
  120.43 +@Documented
  120.44 +@Retention(RetentionPolicy.RUNTIME)
  120.45 +@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
  120.46 +public @interface Deprecated {
  120.47 +}
   121.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   121.2 +++ b/emul/mini/src/main/java/java/lang/Double.java	Sun Feb 03 07:48:42 2013 +0100
   121.3 @@ -0,0 +1,994 @@
   121.4 +/*
   121.5 + * Copyright (c) 1994, 2010, 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 +
  121.29 +package java.lang;
  121.30 +
  121.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  121.32 +
  121.33 +/**
  121.34 + * The {@code Double} class wraps a value of the primitive type
  121.35 + * {@code double} in an object. An object of type
  121.36 + * {@code Double} contains a single field whose type is
  121.37 + * {@code double}.
  121.38 + *
  121.39 + * <p>In addition, this class provides several methods for converting a
  121.40 + * {@code double} to a {@code String} and a
  121.41 + * {@code String} to a {@code double}, as well as other
  121.42 + * constants and methods useful when dealing with a
  121.43 + * {@code double}.
  121.44 + *
  121.45 + * @author  Lee Boynton
  121.46 + * @author  Arthur van Hoff
  121.47 + * @author  Joseph D. Darcy
  121.48 + * @since JDK1.0
  121.49 + */
  121.50 +public final class Double extends Number implements Comparable<Double> {
  121.51 +    /**
  121.52 +     * A constant holding the positive infinity of type
  121.53 +     * {@code double}. It is equal to the value returned by
  121.54 +     * {@code Double.longBitsToDouble(0x7ff0000000000000L)}.
  121.55 +     */
  121.56 +    public static final double POSITIVE_INFINITY = 1.0 / 0.0;
  121.57 +
  121.58 +    /**
  121.59 +     * A constant holding the negative infinity of type
  121.60 +     * {@code double}. It is equal to the value returned by
  121.61 +     * {@code Double.longBitsToDouble(0xfff0000000000000L)}.
  121.62 +     */
  121.63 +    public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
  121.64 +
  121.65 +    /**
  121.66 +     * A constant holding a Not-a-Number (NaN) value of type
  121.67 +     * {@code double}. It is equivalent to the value returned by
  121.68 +     * {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
  121.69 +     */
  121.70 +    public static final double NaN = 0.0d / 0.0;
  121.71 +
  121.72 +    /**
  121.73 +     * A constant holding the largest positive finite value of type
  121.74 +     * {@code double},
  121.75 +     * (2-2<sup>-52</sup>)&middot;2<sup>1023</sup>.  It is equal to
  121.76 +     * the hexadecimal floating-point literal
  121.77 +     * {@code 0x1.fffffffffffffP+1023} and also equal to
  121.78 +     * {@code Double.longBitsToDouble(0x7fefffffffffffffL)}.
  121.79 +     */
  121.80 +    public static final double MAX_VALUE = 0x1.fffffffffffffP+1023; // 1.7976931348623157e+308
  121.81 +
  121.82 +    /**
  121.83 +     * A constant holding the smallest positive normal value of type
  121.84 +     * {@code double}, 2<sup>-1022</sup>.  It is equal to the
  121.85 +     * hexadecimal floating-point literal {@code 0x1.0p-1022} and also
  121.86 +     * equal to {@code Double.longBitsToDouble(0x0010000000000000L)}.
  121.87 +     *
  121.88 +     * @since 1.6
  121.89 +     */
  121.90 +    public static final double MIN_NORMAL = 0x1.0p-1022; // 2.2250738585072014E-308
  121.91 +
  121.92 +    /**
  121.93 +     * A constant holding the smallest positive nonzero value of type
  121.94 +     * {@code double}, 2<sup>-1074</sup>. It is equal to the
  121.95 +     * hexadecimal floating-point literal
  121.96 +     * {@code 0x0.0000000000001P-1022} and also equal to
  121.97 +     * {@code Double.longBitsToDouble(0x1L)}.
  121.98 +     */
  121.99 +    public static final double MIN_VALUE = 0x0.0000000000001P-1022; // 4.9e-324
 121.100 +
 121.101 +    /**
 121.102 +     * Maximum exponent a finite {@code double} variable may have.
 121.103 +     * It is equal to the value returned by
 121.104 +     * {@code Math.getExponent(Double.MAX_VALUE)}.
 121.105 +     *
 121.106 +     * @since 1.6
 121.107 +     */
 121.108 +    public static final int MAX_EXPONENT = 1023;
 121.109 +
 121.110 +    /**
 121.111 +     * Minimum exponent a normalized {@code double} variable may
 121.112 +     * have.  It is equal to the value returned by
 121.113 +     * {@code Math.getExponent(Double.MIN_NORMAL)}.
 121.114 +     *
 121.115 +     * @since 1.6
 121.116 +     */
 121.117 +    public static final int MIN_EXPONENT = -1022;
 121.118 +
 121.119 +    /**
 121.120 +     * The number of bits used to represent a {@code double} value.
 121.121 +     *
 121.122 +     * @since 1.5
 121.123 +     */
 121.124 +    public static final int SIZE = 64;
 121.125 +
 121.126 +    /**
 121.127 +     * The {@code Class} instance representing the primitive type
 121.128 +     * {@code double}.
 121.129 +     *
 121.130 +     * @since JDK1.1
 121.131 +     */
 121.132 +    public static final Class<Double>   TYPE = (Class<Double>) Class.getPrimitiveClass("double");
 121.133 +
 121.134 +    /**
 121.135 +     * Returns a string representation of the {@code double}
 121.136 +     * argument. All characters mentioned below are ASCII characters.
 121.137 +     * <ul>
 121.138 +     * <li>If the argument is NaN, the result is the string
 121.139 +     *     "{@code NaN}".
 121.140 +     * <li>Otherwise, the result is a string that represents the sign and
 121.141 +     * magnitude (absolute value) of the argument. If the sign is negative,
 121.142 +     * the first character of the result is '{@code -}'
 121.143 +     * (<code>'&#92;u002D'</code>); if the sign is positive, no sign character
 121.144 +     * appears in the result. As for the magnitude <i>m</i>:
 121.145 +     * <ul>
 121.146 +     * <li>If <i>m</i> is infinity, it is represented by the characters
 121.147 +     * {@code "Infinity"}; thus, positive infinity produces the result
 121.148 +     * {@code "Infinity"} and negative infinity produces the result
 121.149 +     * {@code "-Infinity"}.
 121.150 +     *
 121.151 +     * <li>If <i>m</i> is zero, it is represented by the characters
 121.152 +     * {@code "0.0"}; thus, negative zero produces the result
 121.153 +     * {@code "-0.0"} and positive zero produces the result
 121.154 +     * {@code "0.0"}.
 121.155 +     *
 121.156 +     * <li>If <i>m</i> is greater than or equal to 10<sup>-3</sup> but less
 121.157 +     * than 10<sup>7</sup>, then it is represented as the integer part of
 121.158 +     * <i>m</i>, in decimal form with no leading zeroes, followed by
 121.159 +     * '{@code .}' (<code>'&#92;u002E'</code>), followed by one or
 121.160 +     * more decimal digits representing the fractional part of <i>m</i>.
 121.161 +     *
 121.162 +     * <li>If <i>m</i> is less than 10<sup>-3</sup> or greater than or
 121.163 +     * equal to 10<sup>7</sup>, then it is represented in so-called
 121.164 +     * "computerized scientific notation." Let <i>n</i> be the unique
 121.165 +     * integer such that 10<sup><i>n</i></sup> &le; <i>m</i> {@literal <}
 121.166 +     * 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
 121.167 +     * mathematically exact quotient of <i>m</i> and
 121.168 +     * 10<sup><i>n</i></sup> so that 1 &le; <i>a</i> {@literal <} 10. The
 121.169 +     * magnitude is then represented as the integer part of <i>a</i>,
 121.170 +     * as a single decimal digit, followed by '{@code .}'
 121.171 +     * (<code>'&#92;u002E'</code>), followed by decimal digits
 121.172 +     * representing the fractional part of <i>a</i>, followed by the
 121.173 +     * letter '{@code E}' (<code>'&#92;u0045'</code>), followed
 121.174 +     * by a representation of <i>n</i> as a decimal integer, as
 121.175 +     * produced by the method {@link Integer#toString(int)}.
 121.176 +     * </ul>
 121.177 +     * </ul>
 121.178 +     * How many digits must be printed for the fractional part of
 121.179 +     * <i>m</i> or <i>a</i>? There must be at least one digit to represent
 121.180 +     * the fractional part, and beyond that as many, but only as many, more
 121.181 +     * digits as are needed to uniquely distinguish the argument value from
 121.182 +     * adjacent values of type {@code double}. That is, suppose that
 121.183 +     * <i>x</i> is the exact mathematical value represented by the decimal
 121.184 +     * representation produced by this method for a finite nonzero argument
 121.185 +     * <i>d</i>. Then <i>d</i> must be the {@code double} value nearest
 121.186 +     * to <i>x</i>; or if two {@code double} values are equally close
 121.187 +     * to <i>x</i>, then <i>d</i> must be one of them and the least
 121.188 +     * significant bit of the significand of <i>d</i> must be {@code 0}.
 121.189 +     *
 121.190 +     * <p>To create localized string representations of a floating-point
 121.191 +     * value, use subclasses of {@link java.text.NumberFormat}.
 121.192 +     *
 121.193 +     * @param   d   the {@code double} to be converted.
 121.194 +     * @return a string representation of the argument.
 121.195 +     */
 121.196 +    @JavaScriptBody(args="d", body="var r = d.toString();"
 121.197 +        + "if (r.indexOf('.') === -1) r = r + '.0';"
 121.198 +        + "return r;")
 121.199 +    public static String toString(double d) {
 121.200 +        throw new UnsupportedOperationException();
 121.201 +    }
 121.202 +
 121.203 +    /**
 121.204 +     * Returns a hexadecimal string representation of the
 121.205 +     * {@code double} argument. All characters mentioned below
 121.206 +     * are ASCII characters.
 121.207 +     *
 121.208 +     * <ul>
 121.209 +     * <li>If the argument is NaN, the result is the string
 121.210 +     *     "{@code NaN}".
 121.211 +     * <li>Otherwise, the result is a string that represents the sign
 121.212 +     * and magnitude of the argument. If the sign is negative, the
 121.213 +     * first character of the result is '{@code -}'
 121.214 +     * (<code>'&#92;u002D'</code>); if the sign is positive, no sign
 121.215 +     * character appears in the result. As for the magnitude <i>m</i>:
 121.216 +     *
 121.217 +     * <ul>
 121.218 +     * <li>If <i>m</i> is infinity, it is represented by the string
 121.219 +     * {@code "Infinity"}; thus, positive infinity produces the
 121.220 +     * result {@code "Infinity"} and negative infinity produces
 121.221 +     * the result {@code "-Infinity"}.
 121.222 +     *
 121.223 +     * <li>If <i>m</i> is zero, it is represented by the string
 121.224 +     * {@code "0x0.0p0"}; thus, negative zero produces the result
 121.225 +     * {@code "-0x0.0p0"} and positive zero produces the result
 121.226 +     * {@code "0x0.0p0"}.
 121.227 +     *
 121.228 +     * <li>If <i>m</i> is a {@code double} value with a
 121.229 +     * normalized representation, substrings are used to represent the
 121.230 +     * significand and exponent fields.  The significand is
 121.231 +     * represented by the characters {@code "0x1."}
 121.232 +     * followed by a lowercase hexadecimal representation of the rest
 121.233 +     * of the significand as a fraction.  Trailing zeros in the
 121.234 +     * hexadecimal representation are removed unless all the digits
 121.235 +     * are zero, in which case a single zero is used. Next, the
 121.236 +     * exponent is represented by {@code "p"} followed
 121.237 +     * by a decimal string of the unbiased exponent as if produced by
 121.238 +     * a call to {@link Integer#toString(int) Integer.toString} on the
 121.239 +     * exponent value.
 121.240 +     *
 121.241 +     * <li>If <i>m</i> is a {@code double} value with a subnormal
 121.242 +     * representation, the significand is represented by the
 121.243 +     * characters {@code "0x0."} followed by a
 121.244 +     * hexadecimal representation of the rest of the significand as a
 121.245 +     * fraction.  Trailing zeros in the hexadecimal representation are
 121.246 +     * removed. Next, the exponent is represented by
 121.247 +     * {@code "p-1022"}.  Note that there must be at
 121.248 +     * least one nonzero digit in a subnormal significand.
 121.249 +     *
 121.250 +     * </ul>
 121.251 +     *
 121.252 +     * </ul>
 121.253 +     *
 121.254 +     * <table border>
 121.255 +     * <caption><h3>Examples</h3></caption>
 121.256 +     * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
 121.257 +     * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
 121.258 +     * <tr><td>{@code -1.0}</td>        <td>{@code -0x1.0p0}</td>
 121.259 +     * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
 121.260 +     * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
 121.261 +     * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
 121.262 +     * <tr><td>{@code 0.25}</td>        <td>{@code 0x1.0p-2}</td>
 121.263 +     * <tr><td>{@code Double.MAX_VALUE}</td>
 121.264 +     *     <td>{@code 0x1.fffffffffffffp1023}</td>
 121.265 +     * <tr><td>{@code Minimum Normal Value}</td>
 121.266 +     *     <td>{@code 0x1.0p-1022}</td>
 121.267 +     * <tr><td>{@code Maximum Subnormal Value}</td>
 121.268 +     *     <td>{@code 0x0.fffffffffffffp-1022}</td>
 121.269 +     * <tr><td>{@code Double.MIN_VALUE}</td>
 121.270 +     *     <td>{@code 0x0.0000000000001p-1022}</td>
 121.271 +     * </table>
 121.272 +     * @param   d   the {@code double} to be converted.
 121.273 +     * @return a hex string representation of the argument.
 121.274 +     * @since 1.5
 121.275 +     * @author Joseph D. Darcy
 121.276 +     */
 121.277 +    public static String toHexString(double d) {
 121.278 +        throw new UnsupportedOperationException();
 121.279 +//        /*
 121.280 +//         * Modeled after the "a" conversion specifier in C99, section
 121.281 +//         * 7.19.6.1; however, the output of this method is more
 121.282 +//         * tightly specified.
 121.283 +//         */
 121.284 +//        if (!FpUtils.isFinite(d) )
 121.285 +//            // For infinity and NaN, use the decimal output.
 121.286 +//            return Double.toString(d);
 121.287 +//        else {
 121.288 +//            // Initialized to maximum size of output.
 121.289 +//            StringBuffer answer = new StringBuffer(24);
 121.290 +//
 121.291 +//            if (FpUtils.rawCopySign(1.0, d) == -1.0) // value is negative,
 121.292 +//                answer.append("-");                  // so append sign info
 121.293 +//
 121.294 +//            answer.append("0x");
 121.295 +//
 121.296 +//            d = Math.abs(d);
 121.297 +//
 121.298 +//            if(d == 0.0) {
 121.299 +//                answer.append("0.0p0");
 121.300 +//            }
 121.301 +//            else {
 121.302 +//                boolean subnormal = (d < DoubleConsts.MIN_NORMAL);
 121.303 +//
 121.304 +//                // Isolate significand bits and OR in a high-order bit
 121.305 +//                // so that the string representation has a known
 121.306 +//                // length.
 121.307 +//                long signifBits = (Double.doubleToLongBits(d)
 121.308 +//                                   & DoubleConsts.SIGNIF_BIT_MASK) |
 121.309 +//                    0x1000000000000000L;
 121.310 +//
 121.311 +//                // Subnormal values have a 0 implicit bit; normal
 121.312 +//                // values have a 1 implicit bit.
 121.313 +//                answer.append(subnormal ? "0." : "1.");
 121.314 +//
 121.315 +//                // Isolate the low-order 13 digits of the hex
 121.316 +//                // representation.  If all the digits are zero,
 121.317 +//                // replace with a single 0; otherwise, remove all
 121.318 +//                // trailing zeros.
 121.319 +//                String signif = Long.toHexString(signifBits).substring(3,16);
 121.320 +//                answer.append(signif.equals("0000000000000") ? // 13 zeros
 121.321 +//                              "0":
 121.322 +//                              signif.replaceFirst("0{1,12}$", ""));
 121.323 +//
 121.324 +//                // If the value is subnormal, use the E_min exponent
 121.325 +//                // value for double; otherwise, extract and report d's
 121.326 +//                // exponent (the representation of a subnormal uses
 121.327 +//                // E_min -1).
 121.328 +//                answer.append("p" + (subnormal ?
 121.329 +//                               DoubleConsts.MIN_EXPONENT:
 121.330 +//                               FpUtils.getExponent(d) ));
 121.331 +//            }
 121.332 +//            return answer.toString();
 121.333 +//        }
 121.334 +    }
 121.335 +
 121.336 +    /**
 121.337 +     * Returns a {@code Double} object holding the
 121.338 +     * {@code double} value represented by the argument string
 121.339 +     * {@code s}.
 121.340 +     *
 121.341 +     * <p>If {@code s} is {@code null}, then a
 121.342 +     * {@code NullPointerException} is thrown.
 121.343 +     *
 121.344 +     * <p>Leading and trailing whitespace characters in {@code s}
 121.345 +     * are ignored.  Whitespace is removed as if by the {@link
 121.346 +     * String#trim} method; that is, both ASCII space and control
 121.347 +     * characters are removed. The rest of {@code s} should
 121.348 +     * constitute a <i>FloatValue</i> as described by the lexical
 121.349 +     * syntax rules:
 121.350 +     *
 121.351 +     * <blockquote>
 121.352 +     * <dl>
 121.353 +     * <dt><i>FloatValue:</i>
 121.354 +     * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
 121.355 +     * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
 121.356 +     * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
 121.357 +     * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
 121.358 +     * <dd><i>SignedInteger</i>
 121.359 +     * </dl>
 121.360 +     *
 121.361 +     * <p>
 121.362 +     *
 121.363 +     * <dl>
 121.364 +     * <dt><i>HexFloatingPointLiteral</i>:
 121.365 +     * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
 121.366 +     * </dl>
 121.367 +     *
 121.368 +     * <p>
 121.369 +     *
 121.370 +     * <dl>
 121.371 +     * <dt><i>HexSignificand:</i>
 121.372 +     * <dd><i>HexNumeral</i>
 121.373 +     * <dd><i>HexNumeral</i> {@code .}
 121.374 +     * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
 121.375 +     *     </i>{@code .}<i> HexDigits</i>
 121.376 +     * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
 121.377 +     *     </i>{@code .} <i>HexDigits</i>
 121.378 +     * </dl>
 121.379 +     *
 121.380 +     * <p>
 121.381 +     *
 121.382 +     * <dl>
 121.383 +     * <dt><i>BinaryExponent:</i>
 121.384 +     * <dd><i>BinaryExponentIndicator SignedInteger</i>
 121.385 +     * </dl>
 121.386 +     *
 121.387 +     * <p>
 121.388 +     *
 121.389 +     * <dl>
 121.390 +     * <dt><i>BinaryExponentIndicator:</i>
 121.391 +     * <dd>{@code p}
 121.392 +     * <dd>{@code P}
 121.393 +     * </dl>
 121.394 +     *
 121.395 +     * </blockquote>
 121.396 +     *
 121.397 +     * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
 121.398 +     * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
 121.399 +     * <i>FloatTypeSuffix</i> are as defined in the lexical structure
 121.400 +     * sections of
 121.401 +     * <cite>The Java&trade; Language Specification</cite>,
 121.402 +     * except that underscores are not accepted between digits.
 121.403 +     * If {@code s} does not have the form of
 121.404 +     * a <i>FloatValue</i>, then a {@code NumberFormatException}
 121.405 +     * is thrown. Otherwise, {@code s} is regarded as
 121.406 +     * representing an exact decimal value in the usual
 121.407 +     * "computerized scientific notation" or as an exact
 121.408 +     * hexadecimal value; this exact numerical value is then
 121.409 +     * conceptually converted to an "infinitely precise"
 121.410 +     * binary value that is then rounded to type {@code double}
 121.411 +     * by the usual round-to-nearest rule of IEEE 754 floating-point
 121.412 +     * arithmetic, which includes preserving the sign of a zero
 121.413 +     * value.
 121.414 +     *
 121.415 +     * Note that the round-to-nearest rule also implies overflow and
 121.416 +     * underflow behaviour; if the exact value of {@code s} is large
 121.417 +     * enough in magnitude (greater than or equal to ({@link
 121.418 +     * #MAX_VALUE} + {@link Math#ulp(double) ulp(MAX_VALUE)}/2),
 121.419 +     * rounding to {@code double} will result in an infinity and if the
 121.420 +     * exact value of {@code s} is small enough in magnitude (less
 121.421 +     * than or equal to {@link #MIN_VALUE}/2), rounding to float will
 121.422 +     * result in a zero.
 121.423 +     *
 121.424 +     * Finally, after rounding a {@code Double} object representing
 121.425 +     * this {@code double} value is returned.
 121.426 +     *
 121.427 +     * <p> To interpret localized string representations of a
 121.428 +     * floating-point value, use subclasses of {@link
 121.429 +     * java.text.NumberFormat}.
 121.430 +     *
 121.431 +     * <p>Note that trailing format specifiers, specifiers that
 121.432 +     * determine the type of a floating-point literal
 121.433 +     * ({@code 1.0f} is a {@code float} value;
 121.434 +     * {@code 1.0d} is a {@code double} value), do
 121.435 +     * <em>not</em> influence the results of this method.  In other
 121.436 +     * words, the numerical value of the input string is converted
 121.437 +     * directly to the target floating-point type.  The two-step
 121.438 +     * sequence of conversions, string to {@code float} followed
 121.439 +     * by {@code float} to {@code double}, is <em>not</em>
 121.440 +     * equivalent to converting a string directly to
 121.441 +     * {@code double}. For example, the {@code float}
 121.442 +     * literal {@code 0.1f} is equal to the {@code double}
 121.443 +     * value {@code 0.10000000149011612}; the {@code float}
 121.444 +     * literal {@code 0.1f} represents a different numerical
 121.445 +     * value than the {@code double} literal
 121.446 +     * {@code 0.1}. (The numerical value 0.1 cannot be exactly
 121.447 +     * represented in a binary floating-point number.)
 121.448 +     *
 121.449 +     * <p>To avoid calling this method on an invalid string and having
 121.450 +     * a {@code NumberFormatException} be thrown, the regular
 121.451 +     * expression below can be used to screen the input string:
 121.452 +     *
 121.453 +     * <code>
 121.454 +     * <pre>
 121.455 +     *  final String Digits     = "(\\p{Digit}+)";
 121.456 +     *  final String HexDigits  = "(\\p{XDigit}+)";
 121.457 +     *  // an exponent is 'e' or 'E' followed by an optionally
 121.458 +     *  // signed decimal integer.
 121.459 +     *  final String Exp        = "[eE][+-]?"+Digits;
 121.460 +     *  final String fpRegex    =
 121.461 +     *      ("[\\x00-\\x20]*"+  // Optional leading "whitespace"
 121.462 +     *       "[+-]?(" + // Optional sign character
 121.463 +     *       "NaN|" +           // "NaN" string
 121.464 +     *       "Infinity|" +      // "Infinity" string
 121.465 +     *
 121.466 +     *       // A decimal floating-point string representing a finite positive
 121.467 +     *       // number without a leading sign has at most five basic pieces:
 121.468 +     *       // Digits . Digits ExponentPart FloatTypeSuffix
 121.469 +     *       //
 121.470 +     *       // Since this method allows integer-only strings as input
 121.471 +     *       // in addition to strings of floating-point literals, the
 121.472 +     *       // two sub-patterns below are simplifications of the grammar
 121.473 +     *       // productions from section 3.10.2 of
 121.474 +     *       // <cite>The Java&trade; Language Specification</cite>.
 121.475 +     *
 121.476 +     *       // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
 121.477 +     *       "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
 121.478 +     *
 121.479 +     *       // . Digits ExponentPart_opt FloatTypeSuffix_opt
 121.480 +     *       "(\\.("+Digits+")("+Exp+")?)|"+
 121.481 +     *
 121.482 +     *       // Hexadecimal strings
 121.483 +     *       "((" +
 121.484 +     *        // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
 121.485 +     *        "(0[xX]" + HexDigits + "(\\.)?)|" +
 121.486 +     *
 121.487 +     *        // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
 121.488 +     *        "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
 121.489 +     *
 121.490 +     *        ")[pP][+-]?" + Digits + "))" +
 121.491 +     *       "[fFdD]?))" +
 121.492 +     *       "[\\x00-\\x20]*");// Optional trailing "whitespace"
 121.493 +     *
 121.494 +     *  if (Pattern.matches(fpRegex, myString))
 121.495 +     *      Double.valueOf(myString); // Will not throw NumberFormatException
 121.496 +     *  else {
 121.497 +     *      // Perform suitable alternative action
 121.498 +     *  }
 121.499 +     * </pre>
 121.500 +     * </code>
 121.501 +     *
 121.502 +     * @param      s   the string to be parsed.
 121.503 +     * @return     a {@code Double} object holding the value
 121.504 +     *             represented by the {@code String} argument.
 121.505 +     * @throws     NumberFormatException  if the string does not contain a
 121.506 +     *             parsable number.
 121.507 +     */
 121.508 +    @JavaScriptBody(args="s", body="return parseFloat(s);")
 121.509 +    public static Double valueOf(String s) throws NumberFormatException {
 121.510 +        throw new UnsupportedOperationException();
 121.511 +//        return new Double(FloatingDecimal.readJavaFormatString(s).doubleValue());
 121.512 +    }
 121.513 +
 121.514 +    /**
 121.515 +     * Returns a {@code Double} instance representing the specified
 121.516 +     * {@code double} value.
 121.517 +     * If a new {@code Double} instance is not required, this method
 121.518 +     * should generally be used in preference to the constructor
 121.519 +     * {@link #Double(double)}, as this method is likely to yield
 121.520 +     * significantly better space and time performance by caching
 121.521 +     * frequently requested values.
 121.522 +     *
 121.523 +     * @param  d a double value.
 121.524 +     * @return a {@code Double} instance representing {@code d}.
 121.525 +     * @since  1.5
 121.526 +     */
 121.527 +    public static Double valueOf(double d) {
 121.528 +        return new Double(d);
 121.529 +    }
 121.530 +
 121.531 +    /**
 121.532 +     * Returns a new {@code double} initialized to the value
 121.533 +     * represented by the specified {@code String}, as performed
 121.534 +     * by the {@code valueOf} method of class
 121.535 +     * {@code Double}.
 121.536 +     *
 121.537 +     * @param  s   the string to be parsed.
 121.538 +     * @return the {@code double} value represented by the string
 121.539 +     *         argument.
 121.540 +     * @throws NullPointerException  if the string is null
 121.541 +     * @throws NumberFormatException if the string does not contain
 121.542 +     *         a parsable {@code double}.
 121.543 +     * @see    java.lang.Double#valueOf(String)
 121.544 +     * @since 1.2
 121.545 +     */
 121.546 +    @JavaScriptBody(args="s", body="return parseFloat(s);")
 121.547 +    public static double parseDouble(String s) throws NumberFormatException {
 121.548 +        throw new UnsupportedOperationException();
 121.549 +//        return FloatingDecimal.readJavaFormatString(s).doubleValue();
 121.550 +    }
 121.551 +
 121.552 +    /**
 121.553 +     * Returns {@code true} if the specified number is a
 121.554 +     * Not-a-Number (NaN) value, {@code false} otherwise.
 121.555 +     *
 121.556 +     * @param   v   the value to be tested.
 121.557 +     * @return  {@code true} if the value of the argument is NaN;
 121.558 +     *          {@code false} otherwise.
 121.559 +     */
 121.560 +    static public boolean isNaN(double v) {
 121.561 +        return (v != v);
 121.562 +    }
 121.563 +
 121.564 +    /**
 121.565 +     * Returns {@code true} if the specified number is infinitely
 121.566 +     * large in magnitude, {@code false} otherwise.
 121.567 +     *
 121.568 +     * @param   v   the value to be tested.
 121.569 +     * @return  {@code true} if the value of the argument is positive
 121.570 +     *          infinity or negative infinity; {@code false} otherwise.
 121.571 +     */
 121.572 +    static public boolean isInfinite(double v) {
 121.573 +        return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
 121.574 +    }
 121.575 +
 121.576 +    /**
 121.577 +     * The value of the Double.
 121.578 +     *
 121.579 +     * @serial
 121.580 +     */
 121.581 +    private final double value;
 121.582 +
 121.583 +    /**
 121.584 +     * Constructs a newly allocated {@code Double} object that
 121.585 +     * represents the primitive {@code double} argument.
 121.586 +     *
 121.587 +     * @param   value   the value to be represented by the {@code Double}.
 121.588 +     */
 121.589 +    public Double(double value) {
 121.590 +        this.value = value;
 121.591 +    }
 121.592 +
 121.593 +    /**
 121.594 +     * Constructs a newly allocated {@code Double} object that
 121.595 +     * represents the floating-point value of type {@code double}
 121.596 +     * represented by the string. The string is converted to a
 121.597 +     * {@code double} value as if by the {@code valueOf} method.
 121.598 +     *
 121.599 +     * @param  s  a string to be converted to a {@code Double}.
 121.600 +     * @throws    NumberFormatException  if the string does not contain a
 121.601 +     *            parsable number.
 121.602 +     * @see       java.lang.Double#valueOf(java.lang.String)
 121.603 +     */
 121.604 +    public Double(String s) throws NumberFormatException {
 121.605 +        // REMIND: this is inefficient
 121.606 +        this(valueOf(s).doubleValue());
 121.607 +    }
 121.608 +
 121.609 +    /**
 121.610 +     * Returns {@code true} if this {@code Double} value is
 121.611 +     * a Not-a-Number (NaN), {@code false} otherwise.
 121.612 +     *
 121.613 +     * @return  {@code true} if the value represented by this object is
 121.614 +     *          NaN; {@code false} otherwise.
 121.615 +     */
 121.616 +    public boolean isNaN() {
 121.617 +        return isNaN(value);
 121.618 +    }
 121.619 +
 121.620 +    /**
 121.621 +     * Returns {@code true} if this {@code Double} value is
 121.622 +     * infinitely large in magnitude, {@code false} otherwise.
 121.623 +     *
 121.624 +     * @return  {@code true} if the value represented by this object is
 121.625 +     *          positive infinity or negative infinity;
 121.626 +     *          {@code false} otherwise.
 121.627 +     */
 121.628 +    public boolean isInfinite() {
 121.629 +        return isInfinite(value);
 121.630 +    }
 121.631 +
 121.632 +    /**
 121.633 +     * Returns a string representation of this {@code Double} object.
 121.634 +     * The primitive {@code double} value represented by this
 121.635 +     * object is converted to a string exactly as if by the method
 121.636 +     * {@code toString} of one argument.
 121.637 +     *
 121.638 +     * @return  a {@code String} representation of this object.
 121.639 +     * @see java.lang.Double#toString(double)
 121.640 +     */
 121.641 +    public String toString() {
 121.642 +        return toString(value);
 121.643 +    }
 121.644 +
 121.645 +    /**
 121.646 +     * Returns the value of this {@code Double} as a {@code byte} (by
 121.647 +     * casting to a {@code byte}).
 121.648 +     *
 121.649 +     * @return  the {@code double} value represented by this object
 121.650 +     *          converted to type {@code byte}
 121.651 +     * @since JDK1.1
 121.652 +     */
 121.653 +    public byte byteValue() {
 121.654 +        return (byte)value;
 121.655 +    }
 121.656 +
 121.657 +    /**
 121.658 +     * Returns the value of this {@code Double} as a
 121.659 +     * {@code short} (by casting to a {@code short}).
 121.660 +     *
 121.661 +     * @return  the {@code double} value represented by this object
 121.662 +     *          converted to type {@code short}
 121.663 +     * @since JDK1.1
 121.664 +     */
 121.665 +    public short shortValue() {
 121.666 +        return (short)value;
 121.667 +    }
 121.668 +
 121.669 +    /**
 121.670 +     * Returns the value of this {@code Double} as an
 121.671 +     * {@code int} (by casting to type {@code int}).
 121.672 +     *
 121.673 +     * @return  the {@code double} value represented by this object
 121.674 +     *          converted to type {@code int}
 121.675 +     */
 121.676 +    public int intValue() {
 121.677 +        return (int)value;
 121.678 +    }
 121.679 +
 121.680 +    /**
 121.681 +     * Returns the value of this {@code Double} as a
 121.682 +     * {@code long} (by casting to type {@code long}).
 121.683 +     *
 121.684 +     * @return  the {@code double} value represented by this object
 121.685 +     *          converted to type {@code long}
 121.686 +     */
 121.687 +    public long longValue() {
 121.688 +        return (long)value;
 121.689 +    }
 121.690 +
 121.691 +    /**
 121.692 +     * Returns the {@code float} value of this
 121.693 +     * {@code Double} object.
 121.694 +     *
 121.695 +     * @return  the {@code double} value represented by this object
 121.696 +     *          converted to type {@code float}
 121.697 +     * @since JDK1.0
 121.698 +     */
 121.699 +    public float floatValue() {
 121.700 +        return (float)value;
 121.701 +    }
 121.702 +
 121.703 +    /**
 121.704 +     * Returns the {@code double} value of this
 121.705 +     * {@code Double} object.
 121.706 +     *
 121.707 +     * @return the {@code double} value represented by this object
 121.708 +     */
 121.709 +    public double doubleValue() {
 121.710 +        return (double)value;
 121.711 +    }
 121.712 +
 121.713 +    /**
 121.714 +     * Returns a hash code for this {@code Double} object. The
 121.715 +     * result is the exclusive OR of the two halves of the
 121.716 +     * {@code long} integer bit representation, exactly as
 121.717 +     * produced by the method {@link #doubleToLongBits(double)}, of
 121.718 +     * the primitive {@code double} value represented by this
 121.719 +     * {@code Double} object. That is, the hash code is the value
 121.720 +     * of the expression:
 121.721 +     *
 121.722 +     * <blockquote>
 121.723 +     *  {@code (int)(v^(v>>>32))}
 121.724 +     * </blockquote>
 121.725 +     *
 121.726 +     * where {@code v} is defined by:
 121.727 +     *
 121.728 +     * <blockquote>
 121.729 +     *  {@code long v = Double.doubleToLongBits(this.doubleValue());}
 121.730 +     * </blockquote>
 121.731 +     *
 121.732 +     * @return  a {@code hash code} value for this object.
 121.733 +     */
 121.734 +    public int hashCode() {
 121.735 +        long bits = doubleToLongBits(value);
 121.736 +        return (int)(bits ^ (bits >>> 32));
 121.737 +    }
 121.738 +
 121.739 +    /**
 121.740 +     * Compares this object against the specified object.  The result
 121.741 +     * is {@code true} if and only if the argument is not
 121.742 +     * {@code null} and is a {@code Double} object that
 121.743 +     * represents a {@code double} that has the same value as the
 121.744 +     * {@code double} represented by this object. For this
 121.745 +     * purpose, two {@code double} values are considered to be
 121.746 +     * the same if and only if the method {@link
 121.747 +     * #doubleToLongBits(double)} returns the identical
 121.748 +     * {@code long} value when applied to each.
 121.749 +     *
 121.750 +     * <p>Note that in most cases, for two instances of class
 121.751 +     * {@code Double}, {@code d1} and {@code d2}, the
 121.752 +     * value of {@code d1.equals(d2)} is {@code true} if and
 121.753 +     * only if
 121.754 +     *
 121.755 +     * <blockquote>
 121.756 +     *  {@code d1.doubleValue() == d2.doubleValue()}
 121.757 +     * </blockquote>
 121.758 +     *
 121.759 +     * <p>also has the value {@code true}. However, there are two
 121.760 +     * exceptions:
 121.761 +     * <ul>
 121.762 +     * <li>If {@code d1} and {@code d2} both represent
 121.763 +     *     {@code Double.NaN}, then the {@code equals} method
 121.764 +     *     returns {@code true}, even though
 121.765 +     *     {@code Double.NaN==Double.NaN} has the value
 121.766 +     *     {@code false}.
 121.767 +     * <li>If {@code d1} represents {@code +0.0} while
 121.768 +     *     {@code d2} represents {@code -0.0}, or vice versa,
 121.769 +     *     the {@code equal} test has the value {@code false},
 121.770 +     *     even though {@code +0.0==-0.0} has the value {@code true}.
 121.771 +     * </ul>
 121.772 +     * This definition allows hash tables to operate properly.
 121.773 +     * @param   obj   the object to compare with.
 121.774 +     * @return  {@code true} if the objects are the same;
 121.775 +     *          {@code false} otherwise.
 121.776 +     * @see java.lang.Double#doubleToLongBits(double)
 121.777 +     */
 121.778 +    public boolean equals(Object obj) {
 121.779 +        return (obj instanceof Double)
 121.780 +               && (((Double)obj).value) == value;
 121.781 +    }
 121.782 +
 121.783 +    /**
 121.784 +     * Returns a representation of the specified floating-point value
 121.785 +     * according to the IEEE 754 floating-point "double
 121.786 +     * format" bit layout.
 121.787 +     *
 121.788 +     * <p>Bit 63 (the bit that is selected by the mask
 121.789 +     * {@code 0x8000000000000000L}) represents the sign of the
 121.790 +     * floating-point number. Bits
 121.791 +     * 62-52 (the bits that are selected by the mask
 121.792 +     * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
 121.793 +     * (the bits that are selected by the mask
 121.794 +     * {@code 0x000fffffffffffffL}) represent the significand
 121.795 +     * (sometimes called the mantissa) of the floating-point number.
 121.796 +     *
 121.797 +     * <p>If the argument is positive infinity, the result is
 121.798 +     * {@code 0x7ff0000000000000L}.
 121.799 +     *
 121.800 +     * <p>If the argument is negative infinity, the result is
 121.801 +     * {@code 0xfff0000000000000L}.
 121.802 +     *
 121.803 +     * <p>If the argument is NaN, the result is
 121.804 +     * {@code 0x7ff8000000000000L}.
 121.805 +     *
 121.806 +     * <p>In all cases, the result is a {@code long} integer that, when
 121.807 +     * given to the {@link #longBitsToDouble(long)} method, will produce a
 121.808 +     * floating-point value the same as the argument to
 121.809 +     * {@code doubleToLongBits} (except all NaN values are
 121.810 +     * collapsed to a single "canonical" NaN value).
 121.811 +     *
 121.812 +     * @param   value   a {@code double} precision floating-point number.
 121.813 +     * @return the bits that represent the floating-point number.
 121.814 +     */
 121.815 +    public static long doubleToLongBits(double value) {
 121.816 +        throw new UnsupportedOperationException();
 121.817 +//        long result = doubleToRawLongBits(value);
 121.818 +//        // Check for NaN based on values of bit fields, maximum
 121.819 +//        // exponent and nonzero significand.
 121.820 +//        if ( ((result & DoubleConsts.EXP_BIT_MASK) ==
 121.821 +//              DoubleConsts.EXP_BIT_MASK) &&
 121.822 +//             (result & DoubleConsts.SIGNIF_BIT_MASK) != 0L)
 121.823 +//            result = 0x7ff8000000000000L;
 121.824 +//        return result;
 121.825 +    }
 121.826 +
 121.827 +    /**
 121.828 +     * Returns a representation of the specified floating-point value
 121.829 +     * according to the IEEE 754 floating-point "double
 121.830 +     * format" bit layout, preserving Not-a-Number (NaN) values.
 121.831 +     *
 121.832 +     * <p>Bit 63 (the bit that is selected by the mask
 121.833 +     * {@code 0x8000000000000000L}) represents the sign of the
 121.834 +     * floating-point number. Bits
 121.835 +     * 62-52 (the bits that are selected by the mask
 121.836 +     * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
 121.837 +     * (the bits that are selected by the mask
 121.838 +     * {@code 0x000fffffffffffffL}) represent the significand
 121.839 +     * (sometimes called the mantissa) of the floating-point number.
 121.840 +     *
 121.841 +     * <p>If the argument is positive infinity, the result is
 121.842 +     * {@code 0x7ff0000000000000L}.
 121.843 +     *
 121.844 +     * <p>If the argument is negative infinity, the result is
 121.845 +     * {@code 0xfff0000000000000L}.
 121.846 +     *
 121.847 +     * <p>If the argument is NaN, the result is the {@code long}
 121.848 +     * integer representing the actual NaN value.  Unlike the
 121.849 +     * {@code doubleToLongBits} method,
 121.850 +     * {@code doubleToRawLongBits} does not collapse all the bit
 121.851 +     * patterns encoding a NaN to a single "canonical" NaN
 121.852 +     * value.
 121.853 +     *
 121.854 +     * <p>In all cases, the result is a {@code long} integer that,
 121.855 +     * when given to the {@link #longBitsToDouble(long)} method, will
 121.856 +     * produce a floating-point value the same as the argument to
 121.857 +     * {@code doubleToRawLongBits}.
 121.858 +     *
 121.859 +     * @param   value   a {@code double} precision floating-point number.
 121.860 +     * @return the bits that represent the floating-point number.
 121.861 +     * @since 1.3
 121.862 +     */
 121.863 +    public static native long doubleToRawLongBits(double value);
 121.864 +
 121.865 +    /**
 121.866 +     * Returns the {@code double} value corresponding to a given
 121.867 +     * bit representation.
 121.868 +     * The argument is considered to be a representation of a
 121.869 +     * floating-point value according to the IEEE 754 floating-point
 121.870 +     * "double format" bit layout.
 121.871 +     *
 121.872 +     * <p>If the argument is {@code 0x7ff0000000000000L}, the result
 121.873 +     * is positive infinity.
 121.874 +     *
 121.875 +     * <p>If the argument is {@code 0xfff0000000000000L}, the result
 121.876 +     * is negative infinity.
 121.877 +     *
 121.878 +     * <p>If the argument is any value in the range
 121.879 +     * {@code 0x7ff0000000000001L} through
 121.880 +     * {@code 0x7fffffffffffffffL} or in the range
 121.881 +     * {@code 0xfff0000000000001L} through
 121.882 +     * {@code 0xffffffffffffffffL}, the result is a NaN.  No IEEE
 121.883 +     * 754 floating-point operation provided by Java can distinguish
 121.884 +     * between two NaN values of the same type with different bit
 121.885 +     * patterns.  Distinct values of NaN are only distinguishable by
 121.886 +     * use of the {@code Double.doubleToRawLongBits} method.
 121.887 +     *
 121.888 +     * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
 121.889 +     * values that can be computed from the argument:
 121.890 +     *
 121.891 +     * <blockquote><pre>
 121.892 +     * int s = ((bits &gt;&gt; 63) == 0) ? 1 : -1;
 121.893 +     * int e = (int)((bits &gt;&gt; 52) & 0x7ffL);
 121.894 +     * long m = (e == 0) ?
 121.895 +     *                 (bits & 0xfffffffffffffL) &lt;&lt; 1 :
 121.896 +     *                 (bits & 0xfffffffffffffL) | 0x10000000000000L;
 121.897 +     * </pre></blockquote>
 121.898 +     *
 121.899 +     * Then the floating-point result equals the value of the mathematical
 121.900 +     * expression <i>s</i>&middot;<i>m</i>&middot;2<sup><i>e</i>-1075</sup>.
 121.901 +     *
 121.902 +     * <p>Note that this method may not be able to return a
 121.903 +     * {@code double} NaN with exactly same bit pattern as the
 121.904 +     * {@code long} argument.  IEEE 754 distinguishes between two
 121.905 +     * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>.  The
 121.906 +     * differences between the two kinds of NaN are generally not
 121.907 +     * visible in Java.  Arithmetic operations on signaling NaNs turn
 121.908 +     * them into quiet NaNs with a different, but often similar, bit
 121.909 +     * pattern.  However, on some processors merely copying a
 121.910 +     * signaling NaN also performs that conversion.  In particular,
 121.911 +     * copying a signaling NaN to return it to the calling method
 121.912 +     * may perform this conversion.  So {@code longBitsToDouble}
 121.913 +     * may not be able to return a {@code double} with a
 121.914 +     * signaling NaN bit pattern.  Consequently, for some
 121.915 +     * {@code long} values,
 121.916 +     * {@code doubleToRawLongBits(longBitsToDouble(start))} may
 121.917 +     * <i>not</i> equal {@code start}.  Moreover, which
 121.918 +     * particular bit patterns represent signaling NaNs is platform
 121.919 +     * dependent; although all NaN bit patterns, quiet or signaling,
 121.920 +     * must be in the NaN range identified above.
 121.921 +     *
 121.922 +     * @param   bits   any {@code long} integer.
 121.923 +     * @return  the {@code double} floating-point value with the same
 121.924 +     *          bit pattern.
 121.925 +     */
 121.926 +    public static native double longBitsToDouble(long bits);
 121.927 +
 121.928 +    /**
 121.929 +     * Compares two {@code Double} objects numerically.  There
 121.930 +     * are two ways in which comparisons performed by this method
 121.931 +     * differ from those performed by the Java language numerical
 121.932 +     * comparison operators ({@code <, <=, ==, >=, >})
 121.933 +     * when applied to primitive {@code double} values:
 121.934 +     * <ul><li>
 121.935 +     *          {@code Double.NaN} is considered by this method
 121.936 +     *          to be equal to itself and greater than all other
 121.937 +     *          {@code double} values (including
 121.938 +     *          {@code Double.POSITIVE_INFINITY}).
 121.939 +     * <li>
 121.940 +     *          {@code 0.0d} is considered by this method to be greater
 121.941 +     *          than {@code -0.0d}.
 121.942 +     * </ul>
 121.943 +     * This ensures that the <i>natural ordering</i> of
 121.944 +     * {@code Double} objects imposed by this method is <i>consistent
 121.945 +     * with equals</i>.
 121.946 +     *
 121.947 +     * @param   anotherDouble   the {@code Double} to be compared.
 121.948 +     * @return  the value {@code 0} if {@code anotherDouble} is
 121.949 +     *          numerically equal to this {@code Double}; a value
 121.950 +     *          less than {@code 0} if this {@code Double}
 121.951 +     *          is numerically less than {@code anotherDouble};
 121.952 +     *          and a value greater than {@code 0} if this
 121.953 +     *          {@code Double} is numerically greater than
 121.954 +     *          {@code anotherDouble}.
 121.955 +     *
 121.956 +     * @since   1.2
 121.957 +     */
 121.958 +    public int compareTo(Double anotherDouble) {
 121.959 +        return Double.compare(value, anotherDouble.value);
 121.960 +    }
 121.961 +
 121.962 +    /**
 121.963 +     * Compares the two specified {@code double} values. The sign
 121.964 +     * of the integer value returned is the same as that of the
 121.965 +     * integer that would be returned by the call:
 121.966 +     * <pre>
 121.967 +     *    new Double(d1).compareTo(new Double(d2))
 121.968 +     * </pre>
 121.969 +     *
 121.970 +     * @param   d1        the first {@code double} to compare
 121.971 +     * @param   d2        the second {@code double} to compare
 121.972 +     * @return  the value {@code 0} if {@code d1} is
 121.973 +     *          numerically equal to {@code d2}; a value less than
 121.974 +     *          {@code 0} if {@code d1} is numerically less than
 121.975 +     *          {@code d2}; and a value greater than {@code 0}
 121.976 +     *          if {@code d1} is numerically greater than
 121.977 +     *          {@code d2}.
 121.978 +     * @since 1.4
 121.979 +     */
 121.980 +    public static int compare(double d1, double d2) {
 121.981 +        if (d1 < d2)
 121.982 +            return -1;           // Neither val is NaN, thisVal is smaller
 121.983 +        if (d1 > d2)
 121.984 +            return 1;            // Neither val is NaN, thisVal is larger
 121.985 +
 121.986 +        // Cannot use doubleToRawLongBits because of possibility of NaNs.
 121.987 +        long thisBits    = Double.doubleToLongBits(d1);
 121.988 +        long anotherBits = Double.doubleToLongBits(d2);
 121.989 +
 121.990 +        return (thisBits == anotherBits ?  0 : // Values are equal
 121.991 +                (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
 121.992 +                 1));                          // (0.0, -0.0) or (NaN, !NaN)
 121.993 +    }
 121.994 +
 121.995 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 121.996 +    private static final long serialVersionUID = -9172774392245257468L;
 121.997 +}
   122.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   122.2 +++ b/emul/mini/src/main/java/java/lang/Enum.java	Sun Feb 03 07:48:42 2013 +0100
   122.3 @@ -0,0 +1,254 @@
   122.4 +/*
   122.5 + * Copyright (c) 2003, 2009, 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 +import java.io.Serializable;
  122.32 +import java.io.IOException;
  122.33 +
  122.34 +/**
  122.35 + * This is the common base class of all Java language enumeration types.
  122.36 + *
  122.37 + * More information about enums, including descriptions of the
  122.38 + * implicitly declared methods synthesized by the compiler, can be
  122.39 + * found in section 8.9 of
  122.40 + * <cite>The Java&trade; Language Specification</cite>.
  122.41 + *
  122.42 + * <p> Note that when using an enumeration type as the type of a set
  122.43 + * or as the type of the keys in a map, specialized and efficient
  122.44 + * {@linkplain java.util.EnumSet set} and {@linkplain
  122.45 + * java.util.EnumMap map} implementations are available.
  122.46 + *
  122.47 + * @param <E> The enum type subclass
  122.48 + * @author  Josh Bloch
  122.49 + * @author  Neal Gafter
  122.50 + * @see     Class#getEnumConstants()
  122.51 + * @see     java.util.EnumSet
  122.52 + * @see     java.util.EnumMap
  122.53 + * @since   1.5
  122.54 + */
  122.55 +public abstract class Enum<E extends Enum<E>>
  122.56 +        implements Comparable<E>, Serializable {
  122.57 +    /**
  122.58 +     * The name of this enum constant, as declared in the enum declaration.
  122.59 +     * Most programmers should use the {@link #toString} method rather than
  122.60 +     * accessing this field.
  122.61 +     */
  122.62 +    private final String name;
  122.63 +
  122.64 +    /**
  122.65 +     * Returns the name of this enum constant, exactly as declared in its
  122.66 +     * enum declaration.
  122.67 +     *
  122.68 +     * <b>Most programmers should use the {@link #toString} method in
  122.69 +     * preference to this one, as the toString method may return
  122.70 +     * a more user-friendly name.</b>  This method is designed primarily for
  122.71 +     * use in specialized situations where correctness depends on getting the
  122.72 +     * exact name, which will not vary from release to release.
  122.73 +     *
  122.74 +     * @return the name of this enum constant
  122.75 +     */
  122.76 +    public final String name() {
  122.77 +        return name;
  122.78 +    }
  122.79 +
  122.80 +    /**
  122.81 +     * The ordinal of this enumeration constant (its position
  122.82 +     * in the enum declaration, where the initial constant is assigned
  122.83 +     * an ordinal of zero).
  122.84 +     *
  122.85 +     * Most programmers will have no use for this field.  It is designed
  122.86 +     * for use by sophisticated enum-based data structures, such as
  122.87 +     * {@link java.util.EnumSet} and {@link java.util.EnumMap}.
  122.88 +     */
  122.89 +    private final int ordinal;
  122.90 +
  122.91 +    /**
  122.92 +     * Returns the ordinal of this enumeration constant (its position
  122.93 +     * in its enum declaration, where the initial constant is assigned
  122.94 +     * an ordinal of zero).
  122.95 +     *
  122.96 +     * Most programmers will have no use for this method.  It is
  122.97 +     * designed for use by sophisticated enum-based data structures, such
  122.98 +     * as {@link java.util.EnumSet} and {@link java.util.EnumMap}.
  122.99 +     *
 122.100 +     * @return the ordinal of this enumeration constant
 122.101 +     */
 122.102 +    public final int ordinal() {
 122.103 +        return ordinal;
 122.104 +    }
 122.105 +
 122.106 +    /**
 122.107 +     * Sole constructor.  Programmers cannot invoke this constructor.
 122.108 +     * It is for use by code emitted by the compiler in response to
 122.109 +     * enum type declarations.
 122.110 +     *
 122.111 +     * @param name - The name of this enum constant, which is the identifier
 122.112 +     *               used to declare it.
 122.113 +     * @param ordinal - The ordinal of this enumeration constant (its position
 122.114 +     *         in the enum declaration, where the initial constant is assigned
 122.115 +     *         an ordinal of zero).
 122.116 +     */
 122.117 +    protected Enum(String name, int ordinal) {
 122.118 +        this.name = name;
 122.119 +        this.ordinal = ordinal;
 122.120 +    }
 122.121 +
 122.122 +    /**
 122.123 +     * Returns the name of this enum constant, as contained in the
 122.124 +     * declaration.  This method may be overridden, though it typically
 122.125 +     * isn't necessary or desirable.  An enum type should override this
 122.126 +     * method when a more "programmer-friendly" string form exists.
 122.127 +     *
 122.128 +     * @return the name of this enum constant
 122.129 +     */
 122.130 +    public String toString() {
 122.131 +        return name;
 122.132 +    }
 122.133 +
 122.134 +    /**
 122.135 +     * Returns true if the specified object is equal to this
 122.136 +     * enum constant.
 122.137 +     *
 122.138 +     * @param other the object to be compared for equality with this object.
 122.139 +     * @return  true if the specified object is equal to this
 122.140 +     *          enum constant.
 122.141 +     */
 122.142 +    public final boolean equals(Object other) {
 122.143 +        return this==other;
 122.144 +    }
 122.145 +
 122.146 +    /**
 122.147 +     * Returns a hash code for this enum constant.
 122.148 +     *
 122.149 +     * @return a hash code for this enum constant.
 122.150 +     */
 122.151 +    public final int hashCode() {
 122.152 +        return super.hashCode();
 122.153 +    }
 122.154 +
 122.155 +    /**
 122.156 +     * Throws CloneNotSupportedException.  This guarantees that enums
 122.157 +     * are never cloned, which is necessary to preserve their "singleton"
 122.158 +     * status.
 122.159 +     *
 122.160 +     * @return (never returns)
 122.161 +     */
 122.162 +    protected final Object clone() throws CloneNotSupportedException {
 122.163 +        throw new CloneNotSupportedException();
 122.164 +    }
 122.165 +
 122.166 +    /**
 122.167 +     * Compares this enum with the specified object for order.  Returns a
 122.168 +     * negative integer, zero, or a positive integer as this object is less
 122.169 +     * than, equal to, or greater than the specified object.
 122.170 +     *
 122.171 +     * Enum constants are only comparable to other enum constants of the
 122.172 +     * same enum type.  The natural order implemented by this
 122.173 +     * method is the order in which the constants are declared.
 122.174 +     */
 122.175 +    public final int compareTo(E o) {
 122.176 +        Enum other = (Enum)o;
 122.177 +        Enum self = this;
 122.178 +        if (self.getClass() != other.getClass() && // optimization
 122.179 +            self.getDeclaringClass() != other.getDeclaringClass())
 122.180 +            throw new ClassCastException();
 122.181 +        return self.ordinal - other.ordinal;
 122.182 +    }
 122.183 +
 122.184 +    /**
 122.185 +     * Returns the Class object corresponding to this enum constant's
 122.186 +     * enum type.  Two enum constants e1 and  e2 are of the
 122.187 +     * same enum type if and only if
 122.188 +     *   e1.getDeclaringClass() == e2.getDeclaringClass().
 122.189 +     * (The value returned by this method may differ from the one returned
 122.190 +     * by the {@link Object#getClass} method for enum constants with
 122.191 +     * constant-specific class bodies.)
 122.192 +     *
 122.193 +     * @return the Class object corresponding to this enum constant's
 122.194 +     *     enum type
 122.195 +     */
 122.196 +    public final Class<E> getDeclaringClass() {
 122.197 +        Class clazz = getClass();
 122.198 +        Class zuper = clazz.getSuperclass();
 122.199 +        return (zuper == Enum.class) ? clazz : zuper;
 122.200 +    }
 122.201 +
 122.202 +    /**
 122.203 +     * Returns the enum constant of the specified enum type with the
 122.204 +     * specified name.  The name must match exactly an identifier used
 122.205 +     * to declare an enum constant in this type.  (Extraneous whitespace
 122.206 +     * characters are not permitted.)
 122.207 +     *
 122.208 +     * <p>Note that for a particular enum type {@code T}, the
 122.209 +     * implicitly declared {@code public static T valueOf(String)}
 122.210 +     * method on that enum may be used instead of this method to map
 122.211 +     * from a name to the corresponding enum constant.  All the
 122.212 +     * constants of an enum type can be obtained by calling the
 122.213 +     * implicit {@code public static T[] values()} method of that
 122.214 +     * type.
 122.215 +     *
 122.216 +     * @param <T> The enum type whose constant is to be returned
 122.217 +     * @param enumType the {@code Class} object of the enum type from which
 122.218 +     *      to return a constant
 122.219 +     * @param name the name of the constant to return
 122.220 +     * @return the enum constant of the specified enum type with the
 122.221 +     *      specified name
 122.222 +     * @throws IllegalArgumentException if the specified enum type has
 122.223 +     *         no constant with the specified name, or the specified
 122.224 +     *         class object does not represent an enum type
 122.225 +     * @throws NullPointerException if {@code enumType} or {@code name}
 122.226 +     *         is null
 122.227 +     * @since 1.5
 122.228 +     */
 122.229 +    public static <T extends Enum<T>> T valueOf(Class<T> enumType,
 122.230 +                                                String name) {
 122.231 +        throw new UnsupportedOperationException();
 122.232 +//        T result = enumType.enumConstantDirectory().get(name);
 122.233 +//        if (result != null)
 122.234 +//            return result;
 122.235 +//        if (name == null)
 122.236 +//            throw new NullPointerException("Name is null");
 122.237 +//        throw new IllegalArgumentException(
 122.238 +//            "No enum constant " + enumType.getCanonicalName() + "." + name);
 122.239 +    }
 122.240 +
 122.241 +    /**
 122.242 +     * enum classes cannot have finalize methods.
 122.243 +     */
 122.244 +    protected final void finalize() { }
 122.245 +
 122.246 +    /**
 122.247 +     * prevent default deserialization
 122.248 +     */
 122.249 +//    private void readObject(ObjectInputStream in) throws IOException,
 122.250 +//        ClassNotFoundException {
 122.251 +//        throw new InvalidObjectException("can't deserialize enum");
 122.252 +//    }
 122.253 +//
 122.254 +//    private void readObjectNoData() throws ObjectStreamException {
 122.255 +//        throw new InvalidObjectException("can't deserialize enum");
 122.256 +//    }
 122.257 +}
   123.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   123.2 +++ b/emul/mini/src/main/java/java/lang/Error.java	Sun Feb 03 07:48:42 2013 +0100
   123.3 @@ -0,0 +1,128 @@
   123.4 +/*
   123.5 + * Copyright (c) 1995, 2011, 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 + * An {@code Error} is a subclass of {@code Throwable}
  123.33 + * that indicates serious problems that a reasonable application
  123.34 + * should not try to catch. Most such errors are abnormal conditions.
  123.35 + * The {@code ThreadDeath} error, though a "normal" condition,
  123.36 + * is also a subclass of {@code Error} because most applications
  123.37 + * should not try to catch it.
  123.38 + * <p>
  123.39 + * A method is not required to declare in its {@code throws}
  123.40 + * clause any subclasses of {@code Error} that might be thrown
  123.41 + * during the execution of the method but not caught, since these
  123.42 + * errors are abnormal conditions that should never occur.
  123.43 + *
  123.44 + * That is, {@code Error} and its subclasses are regarded as unchecked
  123.45 + * exceptions for the purposes of compile-time checking of exceptions.
  123.46 + *
  123.47 + * @author  Frank Yellin
  123.48 + * @see     java.lang.ThreadDeath
  123.49 + * @jls 11.2 Compile-Time Checking of Exceptions
  123.50 + * @since   JDK1.0
  123.51 + */
  123.52 +public class Error extends Throwable {
  123.53 +    static final long serialVersionUID = 4980196508277280342L;
  123.54 +
  123.55 +    /**
  123.56 +     * Constructs a new error with {@code null} as its detail message.
  123.57 +     * The cause is not initialized, and may subsequently be initialized by a
  123.58 +     * call to {@link #initCause}.
  123.59 +     */
  123.60 +    public Error() {
  123.61 +        super();
  123.62 +    }
  123.63 +
  123.64 +    /**
  123.65 +     * Constructs a new error with the specified detail message.  The
  123.66 +     * cause is not initialized, and may subsequently be initialized by
  123.67 +     * a call to {@link #initCause}.
  123.68 +     *
  123.69 +     * @param   message   the detail message. The detail message is saved for
  123.70 +     *          later retrieval by the {@link #getMessage()} method.
  123.71 +     */
  123.72 +    public Error(String message) {
  123.73 +        super(message);
  123.74 +    }
  123.75 +
  123.76 +    /**
  123.77 +     * Constructs a new error with the specified detail message and
  123.78 +     * cause.  <p>Note that the detail message associated with
  123.79 +     * {@code cause} is <i>not</i> automatically incorporated in
  123.80 +     * this error's detail message.
  123.81 +     *
  123.82 +     * @param  message the detail message (which is saved for later retrieval
  123.83 +     *         by the {@link #getMessage()} method).
  123.84 +     * @param  cause the cause (which is saved for later retrieval by the
  123.85 +     *         {@link #getCause()} method).  (A {@code null} value is
  123.86 +     *         permitted, and indicates that the cause is nonexistent or
  123.87 +     *         unknown.)
  123.88 +     * @since  1.4
  123.89 +     */
  123.90 +    public Error(String message, Throwable cause) {
  123.91 +        super(message, cause);
  123.92 +    }
  123.93 +
  123.94 +    /**
  123.95 +     * Constructs a new error with the specified cause and a detail
  123.96 +     * message of {@code (cause==null ? null : cause.toString())} (which
  123.97 +     * typically contains the class and detail message of {@code cause}).
  123.98 +     * This constructor is useful for errors that are little more than
  123.99 +     * wrappers for other throwables.
 123.100 +     *
 123.101 +     * @param  cause the cause (which is saved for later retrieval by the
 123.102 +     *         {@link #getCause()} method).  (A {@code null} value is
 123.103 +     *         permitted, and indicates that the cause is nonexistent or
 123.104 +     *         unknown.)
 123.105 +     * @since  1.4
 123.106 +     */
 123.107 +    public Error(Throwable cause) {
 123.108 +        super(cause);
 123.109 +    }
 123.110 +
 123.111 +    /**
 123.112 +     * Constructs a new error with the specified detail message,
 123.113 +     * cause, suppression enabled or disabled, and writable stack
 123.114 +     * trace enabled or disabled.
 123.115 +     *
 123.116 +     * @param  message the detail message.
 123.117 +     * @param cause the cause.  (A {@code null} value is permitted,
 123.118 +     * and indicates that the cause is nonexistent or unknown.)
 123.119 +     * @param enableSuppression whether or not suppression is enabled
 123.120 +     *                          or disabled
 123.121 +     * @param writableStackTrace whether or not the stack trace should
 123.122 +     *                           be writable
 123.123 +     *
 123.124 +     * @since 1.7
 123.125 +     */
 123.126 +    protected Error(String message, Throwable cause,
 123.127 +                    boolean enableSuppression,
 123.128 +                    boolean writableStackTrace) {
 123.129 +        super(message, cause, enableSuppression, writableStackTrace);
 123.130 +    }
 123.131 +}
   124.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   124.2 +++ b/emul/mini/src/main/java/java/lang/Exception.java	Sun Feb 03 07:48:42 2013 +0100
   124.3 @@ -0,0 +1,124 @@
   124.4 +/*
   124.5 + * Copyright (c) 1994, 2011, 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 + * The class {@code Exception} and its subclasses are a form of
  124.33 + * {@code Throwable} that indicates conditions that a reasonable
  124.34 + * application might want to catch.
  124.35 + *
  124.36 + * <p>The class {@code Exception} and any subclasses that are not also
  124.37 + * subclasses of {@link RuntimeException} are <em>checked
  124.38 + * exceptions</em>.  Checked exceptions need to be declared in a
  124.39 + * method or constructor's {@code throws} clause if they can be thrown
  124.40 + * by the execution of the method or constructor and propagate outside
  124.41 + * the method or constructor boundary.
  124.42 + *
  124.43 + * @author  Frank Yellin
  124.44 + * @see     java.lang.Error
  124.45 + * @jls 11.2 Compile-Time Checking of Exceptions
  124.46 + * @since   JDK1.0
  124.47 + */
  124.48 +public class Exception extends Throwable {
  124.49 +    static final long serialVersionUID = -3387516993124229948L;
  124.50 +
  124.51 +    /**
  124.52 +     * Constructs a new exception with {@code null} as its detail message.
  124.53 +     * The cause is not initialized, and may subsequently be initialized by a
  124.54 +     * call to {@link #initCause}.
  124.55 +     */
  124.56 +    public Exception() {
  124.57 +        super();
  124.58 +    }
  124.59 +
  124.60 +    /**
  124.61 +     * Constructs a new exception with the specified detail message.  The
  124.62 +     * cause is not initialized, and may subsequently be initialized by
  124.63 +     * a call to {@link #initCause}.
  124.64 +     *
  124.65 +     * @param   message   the detail message. The detail message is saved for
  124.66 +     *          later retrieval by the {@link #getMessage()} method.
  124.67 +     */
  124.68 +    public Exception(String message) {
  124.69 +        super(message);
  124.70 +    }
  124.71 +
  124.72 +    /**
  124.73 +     * Constructs a new exception with the specified detail message and
  124.74 +     * cause.  <p>Note that the detail message associated with
  124.75 +     * {@code cause} is <i>not</i> automatically incorporated in
  124.76 +     * this exception's detail message.
  124.77 +     *
  124.78 +     * @param  message the detail message (which is saved for later retrieval
  124.79 +     *         by the {@link #getMessage()} method).
  124.80 +     * @param  cause the cause (which is saved for later retrieval by the
  124.81 +     *         {@link #getCause()} method).  (A <tt>null</tt> value is
  124.82 +     *         permitted, and indicates that the cause is nonexistent or
  124.83 +     *         unknown.)
  124.84 +     * @since  1.4
  124.85 +     */
  124.86 +    public Exception(String message, Throwable cause) {
  124.87 +        super(message, cause);
  124.88 +    }
  124.89 +
  124.90 +    /**
  124.91 +     * Constructs a new exception with the specified cause and a detail
  124.92 +     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  124.93 +     * typically contains the class and detail message of <tt>cause</tt>).
  124.94 +     * This constructor is useful for exceptions that are little more than
  124.95 +     * wrappers for other throwables (for example, {@link
  124.96 +     * java.security.PrivilegedActionException}).
  124.97 +     *
  124.98 +     * @param  cause the cause (which is saved for later retrieval by the
  124.99 +     *         {@link #getCause()} method).  (A <tt>null</tt> value is
 124.100 +     *         permitted, and indicates that the cause is nonexistent or
 124.101 +     *         unknown.)
 124.102 +     * @since  1.4
 124.103 +     */
 124.104 +    public Exception(Throwable cause) {
 124.105 +        super(cause);
 124.106 +    }
 124.107 +
 124.108 +    /**
 124.109 +     * Constructs a new exception with the specified detail message,
 124.110 +     * cause, suppression enabled or disabled, and writable stack
 124.111 +     * trace enabled or disabled.
 124.112 +     *
 124.113 +     * @param  message the detail message.
 124.114 +     * @param cause the cause.  (A {@code null} value is permitted,
 124.115 +     * and indicates that the cause is nonexistent or unknown.)
 124.116 +     * @param enableSuppression whether or not suppression is enabled
 124.117 +     *                          or disabled
 124.118 +     * @param writableStackTrace whether or not the stack trace should
 124.119 +     *                           be writable
 124.120 +     * @since 1.7
 124.121 +     */
 124.122 +    protected Exception(String message, Throwable cause,
 124.123 +                        boolean enableSuppression,
 124.124 +                        boolean writableStackTrace) {
 124.125 +        super(message, cause, enableSuppression, writableStackTrace);
 124.126 +    }
 124.127 +}
   125.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   125.2 +++ b/emul/mini/src/main/java/java/lang/Float.java	Sun Feb 03 07:48:42 2013 +0100
   125.3 @@ -0,0 +1,905 @@
   125.4 +/*
   125.5 + * Copyright (c) 1994, 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 org.apidesign.bck2brwsr.core.JavaScriptBody;
  125.32 +
  125.33 +/**
  125.34 + * The {@code Float} class wraps a value of primitive type
  125.35 + * {@code float} in an object. An object of type
  125.36 + * {@code Float} contains a single field whose type is
  125.37 + * {@code float}.
  125.38 + *
  125.39 + * <p>In addition, this class provides several methods for converting a
  125.40 + * {@code float} to a {@code String} and a
  125.41 + * {@code String} to a {@code float}, as well as other
  125.42 + * constants and methods useful when dealing with a
  125.43 + * {@code float}.
  125.44 + *
  125.45 + * @author  Lee Boynton
  125.46 + * @author  Arthur van Hoff
  125.47 + * @author  Joseph D. Darcy
  125.48 + * @since JDK1.0
  125.49 + */
  125.50 +public final class Float extends Number implements Comparable<Float> {
  125.51 +    /**
  125.52 +     * A constant holding the positive infinity of type
  125.53 +     * {@code float}. It is equal to the value returned by
  125.54 +     * {@code Float.intBitsToFloat(0x7f800000)}.
  125.55 +     */
  125.56 +    public static final float POSITIVE_INFINITY = 1.0f / 0.0f;
  125.57 +
  125.58 +    /**
  125.59 +     * A constant holding the negative infinity of type
  125.60 +     * {@code float}. It is equal to the value returned by
  125.61 +     * {@code Float.intBitsToFloat(0xff800000)}.
  125.62 +     */
  125.63 +    public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;
  125.64 +
  125.65 +    /**
  125.66 +     * A constant holding a Not-a-Number (NaN) value of type
  125.67 +     * {@code float}.  It is equivalent to the value returned by
  125.68 +     * {@code Float.intBitsToFloat(0x7fc00000)}.
  125.69 +     */
  125.70 +    public static final float NaN = 0.0f / 0.0f;
  125.71 +
  125.72 +    /**
  125.73 +     * A constant holding the largest positive finite value of type
  125.74 +     * {@code float}, (2-2<sup>-23</sup>)&middot;2<sup>127</sup>.
  125.75 +     * It is equal to the hexadecimal floating-point literal
  125.76 +     * {@code 0x1.fffffeP+127f} and also equal to
  125.77 +     * {@code Float.intBitsToFloat(0x7f7fffff)}.
  125.78 +     */
  125.79 +    public static final float MAX_VALUE = 0x1.fffffeP+127f; // 3.4028235e+38f
  125.80 +
  125.81 +    /**
  125.82 +     * A constant holding the smallest positive normal value of type
  125.83 +     * {@code float}, 2<sup>-126</sup>.  It is equal to the
  125.84 +     * hexadecimal floating-point literal {@code 0x1.0p-126f} and also
  125.85 +     * equal to {@code Float.intBitsToFloat(0x00800000)}.
  125.86 +     *
  125.87 +     * @since 1.6
  125.88 +     */
  125.89 +    public static final float MIN_NORMAL = 0x1.0p-126f; // 1.17549435E-38f
  125.90 +
  125.91 +    /**
  125.92 +     * A constant holding the smallest positive nonzero value of type
  125.93 +     * {@code float}, 2<sup>-149</sup>. It is equal to the
  125.94 +     * hexadecimal floating-point literal {@code 0x0.000002P-126f}
  125.95 +     * and also equal to {@code Float.intBitsToFloat(0x1)}.
  125.96 +     */
  125.97 +    public static final float MIN_VALUE = 0x0.000002P-126f; // 1.4e-45f
  125.98 +
  125.99 +    /**
 125.100 +     * Maximum exponent a finite {@code float} variable may have.  It
 125.101 +     * is equal to the value returned by {@code
 125.102 +     * Math.getExponent(Float.MAX_VALUE)}.
 125.103 +     *
 125.104 +     * @since 1.6
 125.105 +     */
 125.106 +    public static final int MAX_EXPONENT = 127;
 125.107 +
 125.108 +    /**
 125.109 +     * Minimum exponent a normalized {@code float} variable may have.
 125.110 +     * It is equal to the value returned by {@code
 125.111 +     * Math.getExponent(Float.MIN_NORMAL)}.
 125.112 +     *
 125.113 +     * @since 1.6
 125.114 +     */
 125.115 +    public static final int MIN_EXPONENT = -126;
 125.116 +
 125.117 +    /**
 125.118 +     * The number of bits used to represent a {@code float} value.
 125.119 +     *
 125.120 +     * @since 1.5
 125.121 +     */
 125.122 +    public static final int SIZE = 32;
 125.123 +
 125.124 +    /**
 125.125 +     * The {@code Class} instance representing the primitive type
 125.126 +     * {@code float}.
 125.127 +     *
 125.128 +     * @since JDK1.1
 125.129 +     */
 125.130 +    public static final Class<Float> TYPE = Class.getPrimitiveClass("float");
 125.131 +
 125.132 +    /**
 125.133 +     * Returns a string representation of the {@code float}
 125.134 +     * argument. All characters mentioned below are ASCII characters.
 125.135 +     * <ul>
 125.136 +     * <li>If the argument is NaN, the result is the string
 125.137 +     * "{@code NaN}".
 125.138 +     * <li>Otherwise, the result is a string that represents the sign and
 125.139 +     *     magnitude (absolute value) of the argument. If the sign is
 125.140 +     *     negative, the first character of the result is
 125.141 +     *     '{@code -}' (<code>'&#92;u002D'</code>); if the sign is
 125.142 +     *     positive, no sign character appears in the result. As for
 125.143 +     *     the magnitude <i>m</i>:
 125.144 +     * <ul>
 125.145 +     * <li>If <i>m</i> is infinity, it is represented by the characters
 125.146 +     *     {@code "Infinity"}; thus, positive infinity produces
 125.147 +     *     the result {@code "Infinity"} and negative infinity
 125.148 +     *     produces the result {@code "-Infinity"}.
 125.149 +     * <li>If <i>m</i> is zero, it is represented by the characters
 125.150 +     *     {@code "0.0"}; thus, negative zero produces the result
 125.151 +     *     {@code "-0.0"} and positive zero produces the result
 125.152 +     *     {@code "0.0"}.
 125.153 +     * <li> If <i>m</i> is greater than or equal to 10<sup>-3</sup> but
 125.154 +     *      less than 10<sup>7</sup>, then it is represented as the
 125.155 +     *      integer part of <i>m</i>, in decimal form with no leading
 125.156 +     *      zeroes, followed by '{@code .}'
 125.157 +     *      (<code>'&#92;u002E'</code>), followed by one or more
 125.158 +     *      decimal digits representing the fractional part of
 125.159 +     *      <i>m</i>.
 125.160 +     * <li> If <i>m</i> is less than 10<sup>-3</sup> or greater than or
 125.161 +     *      equal to 10<sup>7</sup>, then it is represented in
 125.162 +     *      so-called "computerized scientific notation." Let <i>n</i>
 125.163 +     *      be the unique integer such that 10<sup><i>n</i> </sup>&le;
 125.164 +     *      <i>m</i> {@literal <} 10<sup><i>n</i>+1</sup>; then let <i>a</i>
 125.165 +     *      be the mathematically exact quotient of <i>m</i> and
 125.166 +     *      10<sup><i>n</i></sup> so that 1 &le; <i>a</i> {@literal <} 10.
 125.167 +     *      The magnitude is then represented as the integer part of
 125.168 +     *      <i>a</i>, as a single decimal digit, followed by
 125.169 +     *      '{@code .}' (<code>'&#92;u002E'</code>), followed by
 125.170 +     *      decimal digits representing the fractional part of
 125.171 +     *      <i>a</i>, followed by the letter '{@code E}'
 125.172 +     *      (<code>'&#92;u0045'</code>), followed by a representation
 125.173 +     *      of <i>n</i> as a decimal integer, as produced by the
 125.174 +     *      method {@link java.lang.Integer#toString(int)}.
 125.175 +     *
 125.176 +     * </ul>
 125.177 +     * </ul>
 125.178 +     * How many digits must be printed for the fractional part of
 125.179 +     * <i>m</i> or <i>a</i>? There must be at least one digit
 125.180 +     * to represent the fractional part, and beyond that as many, but
 125.181 +     * only as many, more digits as are needed to uniquely distinguish
 125.182 +     * the argument value from adjacent values of type
 125.183 +     * {@code float}. That is, suppose that <i>x</i> is the
 125.184 +     * exact mathematical value represented by the decimal
 125.185 +     * representation produced by this method for a finite nonzero
 125.186 +     * argument <i>f</i>. Then <i>f</i> must be the {@code float}
 125.187 +     * value nearest to <i>x</i>; or, if two {@code float} values are
 125.188 +     * equally close to <i>x</i>, then <i>f</i> must be one of
 125.189 +     * them and the least significant bit of the significand of
 125.190 +     * <i>f</i> must be {@code 0}.
 125.191 +     *
 125.192 +     * <p>To create localized string representations of a floating-point
 125.193 +     * value, use subclasses of {@link java.text.NumberFormat}.
 125.194 +     *
 125.195 +     * @param   f   the float to be converted.
 125.196 +     * @return a string representation of the argument.
 125.197 +     */
 125.198 +    public static String toString(float f) {
 125.199 +        return Double.toString(f);
 125.200 +    }
 125.201 +
 125.202 +    /**
 125.203 +     * Returns a hexadecimal string representation of the
 125.204 +     * {@code float} argument. All characters mentioned below are
 125.205 +     * ASCII characters.
 125.206 +     *
 125.207 +     * <ul>
 125.208 +     * <li>If the argument is NaN, the result is the string
 125.209 +     *     "{@code NaN}".
 125.210 +     * <li>Otherwise, the result is a string that represents the sign and
 125.211 +     * magnitude (absolute value) of the argument. If the sign is negative,
 125.212 +     * the first character of the result is '{@code -}'
 125.213 +     * (<code>'&#92;u002D'</code>); if the sign is positive, no sign character
 125.214 +     * appears in the result. As for the magnitude <i>m</i>:
 125.215 +     *
 125.216 +     * <ul>
 125.217 +     * <li>If <i>m</i> is infinity, it is represented by the string
 125.218 +     * {@code "Infinity"}; thus, positive infinity produces the
 125.219 +     * result {@code "Infinity"} and negative infinity produces
 125.220 +     * the result {@code "-Infinity"}.
 125.221 +     *
 125.222 +     * <li>If <i>m</i> is zero, it is represented by the string
 125.223 +     * {@code "0x0.0p0"}; thus, negative zero produces the result
 125.224 +     * {@code "-0x0.0p0"} and positive zero produces the result
 125.225 +     * {@code "0x0.0p0"}.
 125.226 +     *
 125.227 +     * <li>If <i>m</i> is a {@code float} value with a
 125.228 +     * normalized representation, substrings are used to represent the
 125.229 +     * significand and exponent fields.  The significand is
 125.230 +     * represented by the characters {@code "0x1."}
 125.231 +     * followed by a lowercase hexadecimal representation of the rest
 125.232 +     * of the significand as a fraction.  Trailing zeros in the
 125.233 +     * hexadecimal representation are removed unless all the digits
 125.234 +     * are zero, in which case a single zero is used. Next, the
 125.235 +     * exponent is represented by {@code "p"} followed
 125.236 +     * by a decimal string of the unbiased exponent as if produced by
 125.237 +     * a call to {@link Integer#toString(int) Integer.toString} on the
 125.238 +     * exponent value.
 125.239 +     *
 125.240 +     * <li>If <i>m</i> is a {@code float} value with a subnormal
 125.241 +     * representation, the significand is represented by the
 125.242 +     * characters {@code "0x0."} followed by a
 125.243 +     * hexadecimal representation of the rest of the significand as a
 125.244 +     * fraction.  Trailing zeros in the hexadecimal representation are
 125.245 +     * removed. Next, the exponent is represented by
 125.246 +     * {@code "p-126"}.  Note that there must be at
 125.247 +     * least one nonzero digit in a subnormal significand.
 125.248 +     *
 125.249 +     * </ul>
 125.250 +     *
 125.251 +     * </ul>
 125.252 +     *
 125.253 +     * <table border>
 125.254 +     * <caption><h3>Examples</h3></caption>
 125.255 +     * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
 125.256 +     * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
 125.257 +     * <tr><td>{@code -1.0}</td>        <td>{@code -0x1.0p0}</td>
 125.258 +     * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
 125.259 +     * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
 125.260 +     * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
 125.261 +     * <tr><td>{@code 0.25}</td>        <td>{@code 0x1.0p-2}</td>
 125.262 +     * <tr><td>{@code Float.MAX_VALUE}</td>
 125.263 +     *     <td>{@code 0x1.fffffep127}</td>
 125.264 +     * <tr><td>{@code Minimum Normal Value}</td>
 125.265 +     *     <td>{@code 0x1.0p-126}</td>
 125.266 +     * <tr><td>{@code Maximum Subnormal Value}</td>
 125.267 +     *     <td>{@code 0x0.fffffep-126}</td>
 125.268 +     * <tr><td>{@code Float.MIN_VALUE}</td>
 125.269 +     *     <td>{@code 0x0.000002p-126}</td>
 125.270 +     * </table>
 125.271 +     * @param   f   the {@code float} to be converted.
 125.272 +     * @return a hex string representation of the argument.
 125.273 +     * @since 1.5
 125.274 +     * @author Joseph D. Darcy
 125.275 +     */
 125.276 +    public static String toHexString(float f) {
 125.277 +        throw new UnsupportedOperationException();
 125.278 +//        if (Math.abs(f) < FloatConsts.MIN_NORMAL
 125.279 +//            &&  f != 0.0f ) {// float subnormal
 125.280 +//            // Adjust exponent to create subnormal double, then
 125.281 +//            // replace subnormal double exponent with subnormal float
 125.282 +//            // exponent
 125.283 +//            String s = Double.toHexString(FpUtils.scalb((double)f,
 125.284 +//                                                        /* -1022+126 */
 125.285 +//                                                        DoubleConsts.MIN_EXPONENT-
 125.286 +//                                                        FloatConsts.MIN_EXPONENT));
 125.287 +//            return s.replaceFirst("p-1022$", "p-126");
 125.288 +//        }
 125.289 +//        else // double string will be the same as float string
 125.290 +//            return Double.toHexString(f);
 125.291 +    }
 125.292 +
 125.293 +    /**
 125.294 +     * Returns a {@code Float} object holding the
 125.295 +     * {@code float} value represented by the argument string
 125.296 +     * {@code s}.
 125.297 +     *
 125.298 +     * <p>If {@code s} is {@code null}, then a
 125.299 +     * {@code NullPointerException} is thrown.
 125.300 +     *
 125.301 +     * <p>Leading and trailing whitespace characters in {@code s}
 125.302 +     * are ignored.  Whitespace is removed as if by the {@link
 125.303 +     * String#trim} method; that is, both ASCII space and control
 125.304 +     * characters are removed. The rest of {@code s} should
 125.305 +     * constitute a <i>FloatValue</i> as described by the lexical
 125.306 +     * syntax rules:
 125.307 +     *
 125.308 +     * <blockquote>
 125.309 +     * <dl>
 125.310 +     * <dt><i>FloatValue:</i>
 125.311 +     * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
 125.312 +     * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
 125.313 +     * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
 125.314 +     * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
 125.315 +     * <dd><i>SignedInteger</i>
 125.316 +     * </dl>
 125.317 +     *
 125.318 +     * <p>
 125.319 +     *
 125.320 +     * <dl>
 125.321 +     * <dt><i>HexFloatingPointLiteral</i>:
 125.322 +     * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
 125.323 +     * </dl>
 125.324 +     *
 125.325 +     * <p>
 125.326 +     *
 125.327 +     * <dl>
 125.328 +     * <dt><i>HexSignificand:</i>
 125.329 +     * <dd><i>HexNumeral</i>
 125.330 +     * <dd><i>HexNumeral</i> {@code .}
 125.331 +     * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
 125.332 +     *     </i>{@code .}<i> HexDigits</i>
 125.333 +     * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
 125.334 +     *     </i>{@code .} <i>HexDigits</i>
 125.335 +     * </dl>
 125.336 +     *
 125.337 +     * <p>
 125.338 +     *
 125.339 +     * <dl>
 125.340 +     * <dt><i>BinaryExponent:</i>
 125.341 +     * <dd><i>BinaryExponentIndicator SignedInteger</i>
 125.342 +     * </dl>
 125.343 +     *
 125.344 +     * <p>
 125.345 +     *
 125.346 +     * <dl>
 125.347 +     * <dt><i>BinaryExponentIndicator:</i>
 125.348 +     * <dd>{@code p}
 125.349 +     * <dd>{@code P}
 125.350 +     * </dl>
 125.351 +     *
 125.352 +     * </blockquote>
 125.353 +     *
 125.354 +     * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
 125.355 +     * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
 125.356 +     * <i>FloatTypeSuffix</i> are as defined in the lexical structure
 125.357 +     * sections of
 125.358 +     * <cite>The Java&trade; Language Specification</cite>,
 125.359 +     * except that underscores are not accepted between digits.
 125.360 +     * If {@code s} does not have the form of
 125.361 +     * a <i>FloatValue</i>, then a {@code NumberFormatException}
 125.362 +     * is thrown. Otherwise, {@code s} is regarded as
 125.363 +     * representing an exact decimal value in the usual
 125.364 +     * "computerized scientific notation" or as an exact
 125.365 +     * hexadecimal value; this exact numerical value is then
 125.366 +     * conceptually converted to an "infinitely precise"
 125.367 +     * binary value that is then rounded to type {@code float}
 125.368 +     * by the usual round-to-nearest rule of IEEE 754 floating-point
 125.369 +     * arithmetic, which includes preserving the sign of a zero
 125.370 +     * value.
 125.371 +     *
 125.372 +     * Note that the round-to-nearest rule also implies overflow and
 125.373 +     * underflow behaviour; if the exact value of {@code s} is large
 125.374 +     * enough in magnitude (greater than or equal to ({@link
 125.375 +     * #MAX_VALUE} + {@link Math#ulp(float) ulp(MAX_VALUE)}/2),
 125.376 +     * rounding to {@code float} will result in an infinity and if the
 125.377 +     * exact value of {@code s} is small enough in magnitude (less
 125.378 +     * than or equal to {@link #MIN_VALUE}/2), rounding to float will
 125.379 +     * result in a zero.
 125.380 +     *
 125.381 +     * Finally, after rounding a {@code Float} object representing
 125.382 +     * this {@code float} value is returned.
 125.383 +     *
 125.384 +     * <p>To interpret localized string representations of a
 125.385 +     * floating-point value, use subclasses of {@link
 125.386 +     * java.text.NumberFormat}.
 125.387 +     *
 125.388 +     * <p>Note that trailing format specifiers, specifiers that
 125.389 +     * determine the type of a floating-point literal
 125.390 +     * ({@code 1.0f} is a {@code float} value;
 125.391 +     * {@code 1.0d} is a {@code double} value), do
 125.392 +     * <em>not</em> influence the results of this method.  In other
 125.393 +     * words, the numerical value of the input string is converted
 125.394 +     * directly to the target floating-point type.  In general, the
 125.395 +     * two-step sequence of conversions, string to {@code double}
 125.396 +     * followed by {@code double} to {@code float}, is
 125.397 +     * <em>not</em> equivalent to converting a string directly to
 125.398 +     * {@code float}.  For example, if first converted to an
 125.399 +     * intermediate {@code double} and then to
 125.400 +     * {@code float}, the string<br>
 125.401 +     * {@code "1.00000017881393421514957253748434595763683319091796875001d"}<br>
 125.402 +     * results in the {@code float} value
 125.403 +     * {@code 1.0000002f}; if the string is converted directly to
 125.404 +     * {@code float}, <code>1.000000<b>1</b>f</code> results.
 125.405 +     *
 125.406 +     * <p>To avoid calling this method on an invalid string and having
 125.407 +     * a {@code NumberFormatException} be thrown, the documentation
 125.408 +     * for {@link Double#valueOf Double.valueOf} lists a regular
 125.409 +     * expression which can be used to screen the input.
 125.410 +     *
 125.411 +     * @param   s   the string to be parsed.
 125.412 +     * @return  a {@code Float} object holding the value
 125.413 +     *          represented by the {@code String} argument.
 125.414 +     * @throws  NumberFormatException  if the string does not contain a
 125.415 +     *          parsable number.
 125.416 +     */
 125.417 +    public static Float valueOf(String s) throws NumberFormatException {
 125.418 +        throw new UnsupportedOperationException();
 125.419 +//        return new Float(FloatingDecimal.readJavaFormatString(s).floatValue());
 125.420 +    }
 125.421 +
 125.422 +    /**
 125.423 +     * Returns a {@code Float} instance representing the specified
 125.424 +     * {@code float} value.
 125.425 +     * If a new {@code Float} instance is not required, this method
 125.426 +     * should generally be used in preference to the constructor
 125.427 +     * {@link #Float(float)}, as this method is likely to yield
 125.428 +     * significantly better space and time performance by caching
 125.429 +     * frequently requested values.
 125.430 +     *
 125.431 +     * @param  f a float value.
 125.432 +     * @return a {@code Float} instance representing {@code f}.
 125.433 +     * @since  1.5
 125.434 +     */
 125.435 +    public static Float valueOf(float f) {
 125.436 +        return new Float(f);
 125.437 +    }
 125.438 +
 125.439 +    /**
 125.440 +     * Returns a new {@code float} initialized to the value
 125.441 +     * represented by the specified {@code String}, as performed
 125.442 +     * by the {@code valueOf} method of class {@code Float}.
 125.443 +     *
 125.444 +     * @param  s the string to be parsed.
 125.445 +     * @return the {@code float} value represented by the string
 125.446 +     *         argument.
 125.447 +     * @throws NullPointerException  if the string is null
 125.448 +     * @throws NumberFormatException if the string does not contain a
 125.449 +     *               parsable {@code float}.
 125.450 +     * @see    java.lang.Float#valueOf(String)
 125.451 +     * @since 1.2
 125.452 +     */
 125.453 +    public static float parseFloat(String s) throws NumberFormatException {
 125.454 +        throw new UnsupportedOperationException();
 125.455 +//        return FloatingDecimal.readJavaFormatString(s).floatValue();
 125.456 +    }
 125.457 +
 125.458 +    /**
 125.459 +     * Returns {@code true} if the specified number is a
 125.460 +     * Not-a-Number (NaN) value, {@code false} otherwise.
 125.461 +     *
 125.462 +     * @param   v   the value to be tested.
 125.463 +     * @return  {@code true} if the argument is NaN;
 125.464 +     *          {@code false} otherwise.
 125.465 +     */
 125.466 +    static public boolean isNaN(float v) {
 125.467 +        return (v != v);
 125.468 +    }
 125.469 +
 125.470 +    /**
 125.471 +     * Returns {@code true} if the specified number is infinitely
 125.472 +     * large in magnitude, {@code false} otherwise.
 125.473 +     *
 125.474 +     * @param   v   the value to be tested.
 125.475 +     * @return  {@code true} if the argument is positive infinity or
 125.476 +     *          negative infinity; {@code false} otherwise.
 125.477 +     */
 125.478 +    static public boolean isInfinite(float v) {
 125.479 +        return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
 125.480 +    }
 125.481 +
 125.482 +    /**
 125.483 +     * The value of the Float.
 125.484 +     *
 125.485 +     * @serial
 125.486 +     */
 125.487 +    private final float value;
 125.488 +
 125.489 +    /**
 125.490 +     * Constructs a newly allocated {@code Float} object that
 125.491 +     * represents the primitive {@code float} argument.
 125.492 +     *
 125.493 +     * @param   value   the value to be represented by the {@code Float}.
 125.494 +     */
 125.495 +    public Float(float value) {
 125.496 +        this.value = value;
 125.497 +    }
 125.498 +
 125.499 +    /**
 125.500 +     * Constructs a newly allocated {@code Float} object that
 125.501 +     * represents the argument converted to type {@code float}.
 125.502 +     *
 125.503 +     * @param   value   the value to be represented by the {@code Float}.
 125.504 +     */
 125.505 +    public Float(double value) {
 125.506 +        this.value = (float)value;
 125.507 +    }
 125.508 +
 125.509 +    /**
 125.510 +     * Constructs a newly allocated {@code Float} object that
 125.511 +     * represents the floating-point value of type {@code float}
 125.512 +     * represented by the string. The string is converted to a
 125.513 +     * {@code float} value as if by the {@code valueOf} method.
 125.514 +     *
 125.515 +     * @param      s   a string to be converted to a {@code Float}.
 125.516 +     * @throws  NumberFormatException  if the string does not contain a
 125.517 +     *               parsable number.
 125.518 +     * @see        java.lang.Float#valueOf(java.lang.String)
 125.519 +     */
 125.520 +    public Float(String s) throws NumberFormatException {
 125.521 +        // REMIND: this is inefficient
 125.522 +        this(valueOf(s).floatValue());
 125.523 +    }
 125.524 +
 125.525 +    /**
 125.526 +     * Returns {@code true} if this {@code Float} value is a
 125.527 +     * Not-a-Number (NaN), {@code false} otherwise.
 125.528 +     *
 125.529 +     * @return  {@code true} if the value represented by this object is
 125.530 +     *          NaN; {@code false} otherwise.
 125.531 +     */
 125.532 +    public boolean isNaN() {
 125.533 +        return isNaN(value);
 125.534 +    }
 125.535 +
 125.536 +    /**
 125.537 +     * Returns {@code true} if this {@code Float} value is
 125.538 +     * infinitely large in magnitude, {@code false} otherwise.
 125.539 +     *
 125.540 +     * @return  {@code true} if the value represented by this object is
 125.541 +     *          positive infinity or negative infinity;
 125.542 +     *          {@code false} otherwise.
 125.543 +     */
 125.544 +    public boolean isInfinite() {
 125.545 +        return isInfinite(value);
 125.546 +    }
 125.547 +
 125.548 +    /**
 125.549 +     * Returns a string representation of this {@code Float} object.
 125.550 +     * The primitive {@code float} value represented by this object
 125.551 +     * is converted to a {@code String} exactly as if by the method
 125.552 +     * {@code toString} of one argument.
 125.553 +     *
 125.554 +     * @return  a {@code String} representation of this object.
 125.555 +     * @see java.lang.Float#toString(float)
 125.556 +     */
 125.557 +    public String toString() {
 125.558 +        return Float.toString(value);
 125.559 +    }
 125.560 +
 125.561 +    /**
 125.562 +     * Returns the value of this {@code Float} as a {@code byte} (by
 125.563 +     * casting to a {@code byte}).
 125.564 +     *
 125.565 +     * @return  the {@code float} value represented by this object
 125.566 +     *          converted to type {@code byte}
 125.567 +     */
 125.568 +    public byte byteValue() {
 125.569 +        return (byte)value;
 125.570 +    }
 125.571 +
 125.572 +    /**
 125.573 +     * Returns the value of this {@code Float} as a {@code short} (by
 125.574 +     * casting to a {@code short}).
 125.575 +     *
 125.576 +     * @return  the {@code float} value represented by this object
 125.577 +     *          converted to type {@code short}
 125.578 +     * @since JDK1.1
 125.579 +     */
 125.580 +    public short shortValue() {
 125.581 +        return (short)value;
 125.582 +    }
 125.583 +
 125.584 +    /**
 125.585 +     * Returns the value of this {@code Float} as an {@code int} (by
 125.586 +     * casting to type {@code int}).
 125.587 +     *
 125.588 +     * @return  the {@code float} value represented by this object
 125.589 +     *          converted to type {@code int}
 125.590 +     */
 125.591 +    public int intValue() {
 125.592 +        return (int)value;
 125.593 +    }
 125.594 +
 125.595 +    /**
 125.596 +     * Returns value of this {@code Float} as a {@code long} (by
 125.597 +     * casting to type {@code long}).
 125.598 +     *
 125.599 +     * @return  the {@code float} value represented by this object
 125.600 +     *          converted to type {@code long}
 125.601 +     */
 125.602 +    public long longValue() {
 125.603 +        return (long)value;
 125.604 +    }
 125.605 +
 125.606 +    /**
 125.607 +     * Returns the {@code float} value of this {@code Float} object.
 125.608 +     *
 125.609 +     * @return the {@code float} value represented by this object
 125.610 +     */
 125.611 +    public float floatValue() {
 125.612 +        return value;
 125.613 +    }
 125.614 +
 125.615 +    /**
 125.616 +     * Returns the {@code double} value of this {@code Float} object.
 125.617 +     *
 125.618 +     * @return the {@code float} value represented by this
 125.619 +     *         object is converted to type {@code double} and the
 125.620 +     *         result of the conversion is returned.
 125.621 +     */
 125.622 +    public double doubleValue() {
 125.623 +        return (double)value;
 125.624 +    }
 125.625 +
 125.626 +    /**
 125.627 +     * Returns a hash code for this {@code Float} object. The
 125.628 +     * result is the integer bit representation, exactly as produced
 125.629 +     * by the method {@link #floatToIntBits(float)}, of the primitive
 125.630 +     * {@code float} value represented by this {@code Float}
 125.631 +     * object.
 125.632 +     *
 125.633 +     * @return a hash code value for this object.
 125.634 +     */
 125.635 +    public int hashCode() {
 125.636 +        return floatToIntBits(value);
 125.637 +    }
 125.638 +
 125.639 +    /**
 125.640 +
 125.641 +     * Compares this object against the specified object.  The result
 125.642 +     * is {@code true} if and only if the argument is not
 125.643 +     * {@code null} and is a {@code Float} object that
 125.644 +     * represents a {@code float} with the same value as the
 125.645 +     * {@code float} represented by this object. For this
 125.646 +     * purpose, two {@code float} values are considered to be the
 125.647 +     * same if and only if the method {@link #floatToIntBits(float)}
 125.648 +     * returns the identical {@code int} value when applied to
 125.649 +     * each.
 125.650 +     *
 125.651 +     * <p>Note that in most cases, for two instances of class
 125.652 +     * {@code Float}, {@code f1} and {@code f2}, the value
 125.653 +     * of {@code f1.equals(f2)} is {@code true} if and only if
 125.654 +     *
 125.655 +     * <blockquote><pre>
 125.656 +     *   f1.floatValue() == f2.floatValue()
 125.657 +     * </pre></blockquote>
 125.658 +     *
 125.659 +     * <p>also has the value {@code true}. However, there are two exceptions:
 125.660 +     * <ul>
 125.661 +     * <li>If {@code f1} and {@code f2} both represent
 125.662 +     *     {@code Float.NaN}, then the {@code equals} method returns
 125.663 +     *     {@code true}, even though {@code Float.NaN==Float.NaN}
 125.664 +     *     has the value {@code false}.
 125.665 +     * <li>If {@code f1} represents {@code +0.0f} while
 125.666 +     *     {@code f2} represents {@code -0.0f}, or vice
 125.667 +     *     versa, the {@code equal} test has the value
 125.668 +     *     {@code false}, even though {@code 0.0f==-0.0f}
 125.669 +     *     has the value {@code true}.
 125.670 +     * </ul>
 125.671 +     *
 125.672 +     * This definition allows hash tables to operate properly.
 125.673 +     *
 125.674 +     * @param obj the object to be compared
 125.675 +     * @return  {@code true} if the objects are the same;
 125.676 +     *          {@code false} otherwise.
 125.677 +     * @see java.lang.Float#floatToIntBits(float)
 125.678 +     */
 125.679 +    public boolean equals(Object obj) {
 125.680 +        return (obj instanceof Float)
 125.681 +               && (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
 125.682 +    }
 125.683 +
 125.684 +    /**
 125.685 +     * Returns a representation of the specified floating-point value
 125.686 +     * according to the IEEE 754 floating-point "single format" bit
 125.687 +     * layout.
 125.688 +     *
 125.689 +     * <p>Bit 31 (the bit that is selected by the mask
 125.690 +     * {@code 0x80000000}) represents the sign of the floating-point
 125.691 +     * number.
 125.692 +     * Bits 30-23 (the bits that are selected by the mask
 125.693 +     * {@code 0x7f800000}) represent the exponent.
 125.694 +     * Bits 22-0 (the bits that are selected by the mask
 125.695 +     * {@code 0x007fffff}) represent the significand (sometimes called
 125.696 +     * the mantissa) of the floating-point number.
 125.697 +     *
 125.698 +     * <p>If the argument is positive infinity, the result is
 125.699 +     * {@code 0x7f800000}.
 125.700 +     *
 125.701 +     * <p>If the argument is negative infinity, the result is
 125.702 +     * {@code 0xff800000}.
 125.703 +     *
 125.704 +     * <p>If the argument is NaN, the result is {@code 0x7fc00000}.
 125.705 +     *
 125.706 +     * <p>In all cases, the result is an integer that, when given to the
 125.707 +     * {@link #intBitsToFloat(int)} method, will produce a floating-point
 125.708 +     * value the same as the argument to {@code floatToIntBits}
 125.709 +     * (except all NaN values are collapsed to a single
 125.710 +     * "canonical" NaN value).
 125.711 +     *
 125.712 +     * @param   value   a floating-point number.
 125.713 +     * @return the bits that represent the floating-point number.
 125.714 +     */
 125.715 +    public static int floatToIntBits(float value) {
 125.716 +        throw new UnsupportedOperationException();
 125.717 +//        int result = floatToRawIntBits(value);
 125.718 +//        // Check for NaN based on values of bit fields, maximum
 125.719 +//        // exponent and nonzero significand.
 125.720 +//        if ( ((result & FloatConsts.EXP_BIT_MASK) ==
 125.721 +//              FloatConsts.EXP_BIT_MASK) &&
 125.722 +//             (result & FloatConsts.SIGNIF_BIT_MASK) != 0)
 125.723 +//            result = 0x7fc00000;
 125.724 +//        return result;
 125.725 +    }
 125.726 +
 125.727 +    /**
 125.728 +     * Returns a representation of the specified floating-point value
 125.729 +     * according to the IEEE 754 floating-point "single format" bit
 125.730 +     * layout, preserving Not-a-Number (NaN) values.
 125.731 +     *
 125.732 +     * <p>Bit 31 (the bit that is selected by the mask
 125.733 +     * {@code 0x80000000}) represents the sign of the floating-point
 125.734 +     * number.
 125.735 +     * Bits 30-23 (the bits that are selected by the mask
 125.736 +     * {@code 0x7f800000}) represent the exponent.
 125.737 +     * Bits 22-0 (the bits that are selected by the mask
 125.738 +     * {@code 0x007fffff}) represent the significand (sometimes called
 125.739 +     * the mantissa) of the floating-point number.
 125.740 +     *
 125.741 +     * <p>If the argument is positive infinity, the result is
 125.742 +     * {@code 0x7f800000}.
 125.743 +     *
 125.744 +     * <p>If the argument is negative infinity, the result is
 125.745 +     * {@code 0xff800000}.
 125.746 +     *
 125.747 +     * <p>If the argument is NaN, the result is the integer representing
 125.748 +     * the actual NaN value.  Unlike the {@code floatToIntBits}
 125.749 +     * method, {@code floatToRawIntBits} does not collapse all the
 125.750 +     * bit patterns encoding a NaN to a single "canonical"
 125.751 +     * NaN value.
 125.752 +     *
 125.753 +     * <p>In all cases, the result is an integer that, when given to the
 125.754 +     * {@link #intBitsToFloat(int)} method, will produce a
 125.755 +     * floating-point value the same as the argument to
 125.756 +     * {@code floatToRawIntBits}.
 125.757 +     *
 125.758 +     * @param   value   a floating-point number.
 125.759 +     * @return the bits that represent the floating-point number.
 125.760 +     * @since 1.3
 125.761 +     */
 125.762 +    public static native int floatToRawIntBits(float value);
 125.763 +
 125.764 +    /**
 125.765 +     * Returns the {@code float} value corresponding to a given
 125.766 +     * bit representation.
 125.767 +     * The argument is considered to be a representation of a
 125.768 +     * floating-point value according to the IEEE 754 floating-point
 125.769 +     * "single format" bit layout.
 125.770 +     *
 125.771 +     * <p>If the argument is {@code 0x7f800000}, the result is positive
 125.772 +     * infinity.
 125.773 +     *
 125.774 +     * <p>If the argument is {@code 0xff800000}, the result is negative
 125.775 +     * infinity.
 125.776 +     *
 125.777 +     * <p>If the argument is any value in the range
 125.778 +     * {@code 0x7f800001} through {@code 0x7fffffff} or in
 125.779 +     * the range {@code 0xff800001} through
 125.780 +     * {@code 0xffffffff}, the result is a NaN.  No IEEE 754
 125.781 +     * floating-point operation provided by Java can distinguish
 125.782 +     * between two NaN values of the same type with different bit
 125.783 +     * patterns.  Distinct values of NaN are only distinguishable by
 125.784 +     * use of the {@code Float.floatToRawIntBits} method.
 125.785 +     *
 125.786 +     * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
 125.787 +     * values that can be computed from the argument:
 125.788 +     *
 125.789 +     * <blockquote><pre>
 125.790 +     * int s = ((bits &gt;&gt; 31) == 0) ? 1 : -1;
 125.791 +     * int e = ((bits &gt;&gt; 23) & 0xff);
 125.792 +     * int m = (e == 0) ?
 125.793 +     *                 (bits & 0x7fffff) &lt;&lt; 1 :
 125.794 +     *                 (bits & 0x7fffff) | 0x800000;
 125.795 +     * </pre></blockquote>
 125.796 +     *
 125.797 +     * Then the floating-point result equals the value of the mathematical
 125.798 +     * expression <i>s</i>&middot;<i>m</i>&middot;2<sup><i>e</i>-150</sup>.
 125.799 +     *
 125.800 +     * <p>Note that this method may not be able to return a
 125.801 +     * {@code float} NaN with exactly same bit pattern as the
 125.802 +     * {@code int} argument.  IEEE 754 distinguishes between two
 125.803 +     * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>.  The
 125.804 +     * differences between the two kinds of NaN are generally not
 125.805 +     * visible in Java.  Arithmetic operations on signaling NaNs turn
 125.806 +     * them into quiet NaNs with a different, but often similar, bit
 125.807 +     * pattern.  However, on some processors merely copying a
 125.808 +     * signaling NaN also performs that conversion.  In particular,
 125.809 +     * copying a signaling NaN to return it to the calling method may
 125.810 +     * perform this conversion.  So {@code intBitsToFloat} may
 125.811 +     * not be able to return a {@code float} with a signaling NaN
 125.812 +     * bit pattern.  Consequently, for some {@code int} values,
 125.813 +     * {@code floatToRawIntBits(intBitsToFloat(start))} may
 125.814 +     * <i>not</i> equal {@code start}.  Moreover, which
 125.815 +     * particular bit patterns represent signaling NaNs is platform
 125.816 +     * dependent; although all NaN bit patterns, quiet or signaling,
 125.817 +     * must be in the NaN range identified above.
 125.818 +     *
 125.819 +     * @param   bits   an integer.
 125.820 +     * @return  the {@code float} floating-point value with the same bit
 125.821 +     *          pattern.
 125.822 +     */
 125.823 +    @JavaScriptBody(args = "bits",
 125.824 +        body = 
 125.825 +          "if (bits === 0x7f800000) return Number.POSITIVE_INFINITY;\n"
 125.826 +        + "if (bits === 0xff800000) return Number.NEGATIVE_INFINITY;\n"
 125.827 +        + "if (bits >= 0x7f800001 && bits <= 0xffffffff) return Number.NaN;\n"
 125.828 +        + "var s = ((bits >> 31) == 0) ? 1 : -1;\n"
 125.829 +        + "var e = ((bits >> 23) & 0xff);\n"
 125.830 +        + "var m = (e == 0) ?\n"
 125.831 +        + "  (bits & 0x7fffff) << 1 :\n"
 125.832 +        + "  (bits & 0x7fffff) | 0x800000;\n"
 125.833 +        + "return s * m * Math.pow(2.0, e - 150);\n"
 125.834 +    )
 125.835 +    public static native float intBitsToFloat(int bits);
 125.836 +
 125.837 +    /**
 125.838 +     * Compares two {@code Float} objects numerically.  There are
 125.839 +     * two ways in which comparisons performed by this method differ
 125.840 +     * from those performed by the Java language numerical comparison
 125.841 +     * operators ({@code <, <=, ==, >=, >}) when
 125.842 +     * applied to primitive {@code float} values:
 125.843 +     *
 125.844 +     * <ul><li>
 125.845 +     *          {@code Float.NaN} is considered by this method to
 125.846 +     *          be equal to itself and greater than all other
 125.847 +     *          {@code float} values
 125.848 +     *          (including {@code Float.POSITIVE_INFINITY}).
 125.849 +     * <li>
 125.850 +     *          {@code 0.0f} is considered by this method to be greater
 125.851 +     *          than {@code -0.0f}.
 125.852 +     * </ul>
 125.853 +     *
 125.854 +     * This ensures that the <i>natural ordering</i> of {@code Float}
 125.855 +     * objects imposed by this method is <i>consistent with equals</i>.
 125.856 +     *
 125.857 +     * @param   anotherFloat   the {@code Float} to be compared.
 125.858 +     * @return  the value {@code 0} if {@code anotherFloat} is
 125.859 +     *          numerically equal to this {@code Float}; a value
 125.860 +     *          less than {@code 0} if this {@code Float}
 125.861 +     *          is numerically less than {@code anotherFloat};
 125.862 +     *          and a value greater than {@code 0} if this
 125.863 +     *          {@code Float} is numerically greater than
 125.864 +     *          {@code anotherFloat}.
 125.865 +     *
 125.866 +     * @since   1.2
 125.867 +     * @see Comparable#compareTo(Object)
 125.868 +     */
 125.869 +    public int compareTo(Float anotherFloat) {
 125.870 +        return Float.compare(value, anotherFloat.value);
 125.871 +    }
 125.872 +
 125.873 +    /**
 125.874 +     * Compares the two specified {@code float} values. The sign
 125.875 +     * of the integer value returned is the same as that of the
 125.876 +     * integer that would be returned by the call:
 125.877 +     * <pre>
 125.878 +     *    new Float(f1).compareTo(new Float(f2))
 125.879 +     * </pre>
 125.880 +     *
 125.881 +     * @param   f1        the first {@code float} to compare.
 125.882 +     * @param   f2        the second {@code float} to compare.
 125.883 +     * @return  the value {@code 0} if {@code f1} is
 125.884 +     *          numerically equal to {@code f2}; a value less than
 125.885 +     *          {@code 0} if {@code f1} is numerically less than
 125.886 +     *          {@code f2}; and a value greater than {@code 0}
 125.887 +     *          if {@code f1} is numerically greater than
 125.888 +     *          {@code f2}.
 125.889 +     * @since 1.4
 125.890 +     */
 125.891 +    public static int compare(float f1, float f2) {
 125.892 +        if (f1 < f2)
 125.893 +            return -1;           // Neither val is NaN, thisVal is smaller
 125.894 +        if (f1 > f2)
 125.895 +            return 1;            // Neither val is NaN, thisVal is larger
 125.896 +
 125.897 +        // Cannot use floatToRawIntBits because of possibility of NaNs.
 125.898 +        int thisBits    = Float.floatToIntBits(f1);
 125.899 +        int anotherBits = Float.floatToIntBits(f2);
 125.900 +
 125.901 +        return (thisBits == anotherBits ?  0 : // Values are equal
 125.902 +                (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
 125.903 +                 1));                          // (0.0, -0.0) or (NaN, !NaN)
 125.904 +    }
 125.905 +
 125.906 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 125.907 +    private static final long serialVersionUID = -2671257302660747028L;
 125.908 +}
   126.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   126.2 +++ b/emul/mini/src/main/java/java/lang/IllegalAccessException.java	Sun Feb 03 07:48:42 2013 +0100
   126.3 @@ -0,0 +1,78 @@
   126.4 +/*
   126.5 + * Copyright (c) 1995, 2008, 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 +/**
  126.32 + * An IllegalAccessException is thrown when an application tries
  126.33 + * to reflectively create an instance (other than an array),
  126.34 + * set or get a field, or invoke a method, but the currently
  126.35 + * executing method does not have access to the definition of
  126.36 + * the specified class, field, method or constructor.
  126.37 + *
  126.38 + * @author  unascribed
  126.39 + * @see     Class#newInstance()
  126.40 + * @see     java.lang.reflect.Field#set(Object, Object)
  126.41 + * @see     java.lang.reflect.Field#setBoolean(Object, boolean)
  126.42 + * @see     java.lang.reflect.Field#setByte(Object, byte)
  126.43 + * @see     java.lang.reflect.Field#setShort(Object, short)
  126.44 + * @see     java.lang.reflect.Field#setChar(Object, char)
  126.45 + * @see     java.lang.reflect.Field#setInt(Object, int)
  126.46 + * @see     java.lang.reflect.Field#setLong(Object, long)
  126.47 + * @see     java.lang.reflect.Field#setFloat(Object, float)
  126.48 + * @see     java.lang.reflect.Field#setDouble(Object, double)
  126.49 + * @see     java.lang.reflect.Field#get(Object)
  126.50 + * @see     java.lang.reflect.Field#getBoolean(Object)
  126.51 + * @see     java.lang.reflect.Field#getByte(Object)
  126.52 + * @see     java.lang.reflect.Field#getShort(Object)
  126.53 + * @see     java.lang.reflect.Field#getChar(Object)
  126.54 + * @see     java.lang.reflect.Field#getInt(Object)
  126.55 + * @see     java.lang.reflect.Field#getLong(Object)
  126.56 + * @see     java.lang.reflect.Field#getFloat(Object)
  126.57 + * @see     java.lang.reflect.Field#getDouble(Object)
  126.58 + * @see     java.lang.reflect.Method#invoke(Object, Object[])
  126.59 + * @see     java.lang.reflect.Constructor#newInstance(Object[])
  126.60 + * @since   JDK1.0
  126.61 + */
  126.62 +public class IllegalAccessException extends ReflectiveOperationException {
  126.63 +    private static final long serialVersionUID = 6616958222490762034L;
  126.64 +
  126.65 +    /**
  126.66 +     * Constructs an <code>IllegalAccessException</code> without a
  126.67 +     * detail message.
  126.68 +     */
  126.69 +    public IllegalAccessException() {
  126.70 +        super();
  126.71 +    }
  126.72 +
  126.73 +    /**
  126.74 +     * Constructs an <code>IllegalAccessException</code> with a detail message.
  126.75 +     *
  126.76 +     * @param   s   the detail message.
  126.77 +     */
  126.78 +    public IllegalAccessException(String s) {
  126.79 +        super(s);
  126.80 +    }
  126.81 +}
   127.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   127.2 +++ b/emul/mini/src/main/java/java/lang/IllegalArgumentException.java	Sun Feb 03 07:48:42 2013 +0100
   127.3 @@ -0,0 +1,95 @@
   127.4 +/*
   127.5 + * Copyright (c) 1994, 2003, 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 +/**
  127.32 + * Thrown to indicate that a method has been passed an illegal or
  127.33 + * inappropriate argument.
  127.34 + *
  127.35 + * @author  unascribed
  127.36 + * @see     java.lang.Thread#setPriority(int)
  127.37 + * @since   JDK1.0
  127.38 + */
  127.39 +public
  127.40 +class IllegalArgumentException extends RuntimeException {
  127.41 +    /**
  127.42 +     * Constructs an <code>IllegalArgumentException</code> with no
  127.43 +     * detail message.
  127.44 +     */
  127.45 +    public IllegalArgumentException() {
  127.46 +        super();
  127.47 +    }
  127.48 +
  127.49 +    /**
  127.50 +     * Constructs an <code>IllegalArgumentException</code> with the
  127.51 +     * specified detail message.
  127.52 +     *
  127.53 +     * @param   s   the detail message.
  127.54 +     */
  127.55 +    public IllegalArgumentException(String s) {
  127.56 +        super(s);
  127.57 +    }
  127.58 +
  127.59 +    /**
  127.60 +     * Constructs a new exception with the specified detail message and
  127.61 +     * cause.
  127.62 +     *
  127.63 +     * <p>Note that the detail message associated with <code>cause</code> is
  127.64 +     * <i>not</i> automatically incorporated in this exception's detail
  127.65 +     * message.
  127.66 +     *
  127.67 +     * @param  message the detail message (which is saved for later retrieval
  127.68 +     *         by the {@link Throwable#getMessage()} method).
  127.69 +     * @param  cause the cause (which is saved for later retrieval by the
  127.70 +     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value
  127.71 +     *         is permitted, and indicates that the cause is nonexistent or
  127.72 +     *         unknown.)
  127.73 +     * @since 1.5
  127.74 +     */
  127.75 +    public IllegalArgumentException(String message, Throwable cause) {
  127.76 +        super(message, cause);
  127.77 +    }
  127.78 +
  127.79 +    /**
  127.80 +     * Constructs a new exception with the specified cause and a detail
  127.81 +     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  127.82 +     * typically contains the class and detail message of <tt>cause</tt>).
  127.83 +     * This constructor is useful for exceptions that are little more than
  127.84 +     * wrappers for other throwables (for example, {@link
  127.85 +     * java.security.PrivilegedActionException}).
  127.86 +     *
  127.87 +     * @param  cause the cause (which is saved for later retrieval by the
  127.88 +     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value is
  127.89 +     *         permitted, and indicates that the cause is nonexistent or
  127.90 +     *         unknown.)
  127.91 +     * @since  1.5
  127.92 +     */
  127.93 +    public IllegalArgumentException(Throwable cause) {
  127.94 +        super(cause);
  127.95 +    }
  127.96 +
  127.97 +    private static final long serialVersionUID = -5365630128856068164L;
  127.98 +}
   128.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   128.2 +++ b/emul/mini/src/main/java/java/lang/IllegalStateException.java	Sun Feb 03 07:48:42 2013 +0100
   128.3 @@ -0,0 +1,97 @@
   128.4 +/*
   128.5 + * Copyright (c) 1996, 2003, 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 + * Signals that a method has been invoked at an illegal or
  128.33 + * inappropriate time.  In other words, the Java environment or
  128.34 + * Java application is not in an appropriate state for the requested
  128.35 + * operation.
  128.36 + *
  128.37 + * @author  Jonni Kanerva
  128.38 + * @since   JDK1.1
  128.39 + */
  128.40 +public
  128.41 +class IllegalStateException extends RuntimeException {
  128.42 +    /**
  128.43 +     * Constructs an IllegalStateException with no detail message.
  128.44 +     * A detail message is a String that describes this particular exception.
  128.45 +     */
  128.46 +    public IllegalStateException() {
  128.47 +        super();
  128.48 +    }
  128.49 +
  128.50 +    /**
  128.51 +     * Constructs an IllegalStateException with the specified detail
  128.52 +     * message.  A detail message is a String that describes this particular
  128.53 +     * exception.
  128.54 +     *
  128.55 +     * @param s the String that contains a detailed message
  128.56 +     */
  128.57 +    public IllegalStateException(String s) {
  128.58 +        super(s);
  128.59 +    }
  128.60 +
  128.61 +    /**
  128.62 +     * Constructs a new exception with the specified detail message and
  128.63 +     * cause.
  128.64 +     *
  128.65 +     * <p>Note that the detail message associated with <code>cause</code> is
  128.66 +     * <i>not</i> automatically incorporated in this exception's detail
  128.67 +     * message.
  128.68 +     *
  128.69 +     * @param  message the detail message (which is saved for later retrieval
  128.70 +     *         by the {@link Throwable#getMessage()} method).
  128.71 +     * @param  cause the cause (which is saved for later retrieval by the
  128.72 +     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value
  128.73 +     *         is permitted, and indicates that the cause is nonexistent or
  128.74 +     *         unknown.)
  128.75 +     * @since 1.5
  128.76 +     */
  128.77 +    public IllegalStateException(String message, Throwable cause) {
  128.78 +        super(message, cause);
  128.79 +    }
  128.80 +
  128.81 +    /**
  128.82 +     * Constructs a new exception with the specified cause and a detail
  128.83 +     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  128.84 +     * typically contains the class and detail message of <tt>cause</tt>).
  128.85 +     * This constructor is useful for exceptions that are little more than
  128.86 +     * wrappers for other throwables (for example, {@link
  128.87 +     * java.security.PrivilegedActionException}).
  128.88 +     *
  128.89 +     * @param  cause the cause (which is saved for later retrieval by the
  128.90 +     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value is
  128.91 +     *         permitted, and indicates that the cause is nonexistent or
  128.92 +     *         unknown.)
  128.93 +     * @since  1.5
  128.94 +     */
  128.95 +    public IllegalStateException(Throwable cause) {
  128.96 +        super(cause);
  128.97 +    }
  128.98 +
  128.99 +    static final long serialVersionUID = -1848914673093119416L;
 128.100 +}
   129.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   129.2 +++ b/emul/mini/src/main/java/java/lang/IndexOutOfBoundsException.java	Sun Feb 03 07:48:42 2013 +0100
   129.3 @@ -0,0 +1,58 @@
   129.4 +/*
   129.5 + * Copyright (c) 1995, 2008, 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 + * Thrown to indicate that an index of some sort (such as to an array, to a
  129.33 + * string, or to a vector) is out of range.
  129.34 + * <p>
  129.35 + * Applications can subclass this class to indicate similar exceptions.
  129.36 + *
  129.37 + * @author  Frank Yellin
  129.38 + * @since   JDK1.0
  129.39 + */
  129.40 +public
  129.41 +class IndexOutOfBoundsException extends RuntimeException {
  129.42 +    private static final long serialVersionUID = 234122996006267687L;
  129.43 +
  129.44 +    /**
  129.45 +     * Constructs an <code>IndexOutOfBoundsException</code> with no
  129.46 +     * detail message.
  129.47 +     */
  129.48 +    public IndexOutOfBoundsException() {
  129.49 +        super();
  129.50 +    }
  129.51 +
  129.52 +    /**
  129.53 +     * Constructs an <code>IndexOutOfBoundsException</code> with the
  129.54 +     * specified detail message.
  129.55 +     *
  129.56 +     * @param   s   the detail message.
  129.57 +     */
  129.58 +    public IndexOutOfBoundsException(String s) {
  129.59 +        super(s);
  129.60 +    }
  129.61 +}
   130.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   130.2 +++ b/emul/mini/src/main/java/java/lang/InstantiationException.java	Sun Feb 03 07:48:42 2013 +0100
   130.3 @@ -0,0 +1,65 @@
   130.4 +/*
   130.5 + * Copyright (c) 1995, 2008, 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 +/**
  130.32 + * Thrown when an application tries to create an instance of a class
  130.33 + * using the {@code newInstance} method in class
  130.34 + * {@code Class}, but the specified class object cannot be
  130.35 + * instantiated.  The instantiation can fail for a variety of
  130.36 + * reasons including but not limited to:
  130.37 + *
  130.38 + * <ul>
  130.39 + * <li> the class object represents an abstract class, an interface,
  130.40 + *      an array class, a primitive type, or {@code void}
  130.41 + * <li> the class has no nullary constructor
  130.42 + *</ul>
  130.43 + *
  130.44 + * @author  unascribed
  130.45 + * @see     java.lang.Class#newInstance()
  130.46 + * @since   JDK1.0
  130.47 + */
  130.48 +public
  130.49 +class InstantiationException extends ReflectiveOperationException {
  130.50 +    private static final long serialVersionUID = -8441929162975509110L;
  130.51 +
  130.52 +    /**
  130.53 +     * Constructs an {@code InstantiationException} with no detail message.
  130.54 +     */
  130.55 +    public InstantiationException() {
  130.56 +        super();
  130.57 +    }
  130.58 +
  130.59 +    /**
  130.60 +     * Constructs an {@code InstantiationException} with the
  130.61 +     * specified detail message.
  130.62 +     *
  130.63 +     * @param   s   the detail message.
  130.64 +     */
  130.65 +    public InstantiationException(String s) {
  130.66 +        super(s);
  130.67 +    }
  130.68 +}
   131.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   131.2 +++ b/emul/mini/src/main/java/java/lang/Integer.java	Sun Feb 03 07:48:42 2013 +0100
   131.3 @@ -0,0 +1,1246 @@
   131.4 +/*
   131.5 + * Copyright (c) 1994, 2010, 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 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  131.32 +
  131.33 +/**
  131.34 + * The {@code Integer} class wraps a value of the primitive type
  131.35 + * {@code int} in an object. An object of type {@code Integer}
  131.36 + * contains a single field whose type is {@code int}.
  131.37 + *
  131.38 + * <p>In addition, this class provides several methods for converting
  131.39 + * an {@code int} to a {@code String} and a {@code String} to an
  131.40 + * {@code int}, as well as other constants and methods useful when
  131.41 + * dealing with an {@code int}.
  131.42 + *
  131.43 + * <p>Implementation note: The implementations of the "bit twiddling"
  131.44 + * methods (such as {@link #highestOneBit(int) highestOneBit} and
  131.45 + * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
  131.46 + * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  131.47 + * Delight</i>, (Addison Wesley, 2002).
  131.48 + *
  131.49 + * @author  Lee Boynton
  131.50 + * @author  Arthur van Hoff
  131.51 + * @author  Josh Bloch
  131.52 + * @author  Joseph D. Darcy
  131.53 + * @since JDK1.0
  131.54 + */
  131.55 +public final class Integer extends Number implements Comparable<Integer> {
  131.56 +    /**
  131.57 +     * A constant holding the minimum value an {@code int} can
  131.58 +     * have, -2<sup>31</sup>.
  131.59 +     */
  131.60 +    public static final int   MIN_VALUE = 0x80000000;
  131.61 +
  131.62 +    /**
  131.63 +     * A constant holding the maximum value an {@code int} can
  131.64 +     * have, 2<sup>31</sup>-1.
  131.65 +     */
  131.66 +    public static final int   MAX_VALUE = 0x7fffffff;
  131.67 +
  131.68 +    /**
  131.69 +     * The {@code Class} instance representing the primitive type
  131.70 +     * {@code int}.
  131.71 +     *
  131.72 +     * @since   JDK1.1
  131.73 +     */
  131.74 +    public static final Class<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");
  131.75 +
  131.76 +    /**
  131.77 +     * All possible chars for representing a number as a String
  131.78 +     */
  131.79 +    final static char[] digits = {
  131.80 +        '0' , '1' , '2' , '3' , '4' , '5' ,
  131.81 +        '6' , '7' , '8' , '9' , 'a' , 'b' ,
  131.82 +        'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
  131.83 +        'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
  131.84 +        'o' , 'p' , 'q' , 'r' , 's' , 't' ,
  131.85 +        'u' , 'v' , 'w' , 'x' , 'y' , 'z'
  131.86 +    };
  131.87 +
  131.88 +    /**
  131.89 +     * Returns a string representation of the first argument in the
  131.90 +     * radix specified by the second argument.
  131.91 +     *
  131.92 +     * <p>If the radix is smaller than {@code Character.MIN_RADIX}
  131.93 +     * or larger than {@code Character.MAX_RADIX}, then the radix
  131.94 +     * {@code 10} is used instead.
  131.95 +     *
  131.96 +     * <p>If the first argument is negative, the first element of the
  131.97 +     * result is the ASCII minus character {@code '-'}
  131.98 +     * (<code>'&#92;u002D'</code>). If the first argument is not
  131.99 +     * negative, no sign character appears in the result.
 131.100 +     *
 131.101 +     * <p>The remaining characters of the result represent the magnitude
 131.102 +     * of the first argument. If the magnitude is zero, it is
 131.103 +     * represented by a single zero character {@code '0'}
 131.104 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 131.105 +     * the representation of the magnitude will not be the zero
 131.106 +     * character.  The following ASCII characters are used as digits:
 131.107 +     *
 131.108 +     * <blockquote>
 131.109 +     *   {@code 0123456789abcdefghijklmnopqrstuvwxyz}
 131.110 +     * </blockquote>
 131.111 +     *
 131.112 +     * These are <code>'&#92;u0030'</code> through
 131.113 +     * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
 131.114 +     * <code>'&#92;u007A'</code>. If {@code radix} is
 131.115 +     * <var>N</var>, then the first <var>N</var> of these characters
 131.116 +     * are used as radix-<var>N</var> digits in the order shown. Thus,
 131.117 +     * the digits for hexadecimal (radix 16) are
 131.118 +     * {@code 0123456789abcdef}. If uppercase letters are
 131.119 +     * desired, the {@link java.lang.String#toUpperCase()} method may
 131.120 +     * be called on the result:
 131.121 +     *
 131.122 +     * <blockquote>
 131.123 +     *  {@code Integer.toString(n, 16).toUpperCase()}
 131.124 +     * </blockquote>
 131.125 +     *
 131.126 +     * @param   i       an integer to be converted to a string.
 131.127 +     * @param   radix   the radix to use in the string representation.
 131.128 +     * @return  a string representation of the argument in the specified radix.
 131.129 +     * @see     java.lang.Character#MAX_RADIX
 131.130 +     * @see     java.lang.Character#MIN_RADIX
 131.131 +     */
 131.132 +    public static String toString(int i, int radix) {
 131.133 +
 131.134 +        if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
 131.135 +            radix = 10;
 131.136 +
 131.137 +        /* Use the faster version */
 131.138 +        if (radix == 10) {
 131.139 +            return toString(i);
 131.140 +        }
 131.141 +
 131.142 +        char buf[] = new char[33];
 131.143 +        boolean negative = (i < 0);
 131.144 +        int charPos = 32;
 131.145 +
 131.146 +        if (!negative) {
 131.147 +            i = -i;
 131.148 +        }
 131.149 +
 131.150 +        while (i <= -radix) {
 131.151 +            buf[charPos--] = digits[-(i % radix)];
 131.152 +            i = i / radix;
 131.153 +        }
 131.154 +        buf[charPos] = digits[-i];
 131.155 +
 131.156 +        if (negative) {
 131.157 +            buf[--charPos] = '-';
 131.158 +        }
 131.159 +
 131.160 +        return new String(buf, charPos, (33 - charPos));
 131.161 +    }
 131.162 +
 131.163 +    /**
 131.164 +     * Returns a string representation of the integer argument as an
 131.165 +     * unsigned integer in base&nbsp;16.
 131.166 +     *
 131.167 +     * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
 131.168 +     * if the argument is negative; otherwise, it is equal to the
 131.169 +     * argument.  This value is converted to a string of ASCII digits
 131.170 +     * in hexadecimal (base&nbsp;16) with no extra leading
 131.171 +     * {@code 0}s. If the unsigned magnitude is zero, it is
 131.172 +     * represented by a single zero character {@code '0'}
 131.173 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 131.174 +     * the representation of the unsigned magnitude will not be the
 131.175 +     * zero character. The following characters are used as
 131.176 +     * hexadecimal digits:
 131.177 +     *
 131.178 +     * <blockquote>
 131.179 +     *  {@code 0123456789abcdef}
 131.180 +     * </blockquote>
 131.181 +     *
 131.182 +     * These are the characters <code>'&#92;u0030'</code> through
 131.183 +     * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
 131.184 +     * <code>'&#92;u0066'</code>. If uppercase letters are
 131.185 +     * desired, the {@link java.lang.String#toUpperCase()} method may
 131.186 +     * be called on the result:
 131.187 +     *
 131.188 +     * <blockquote>
 131.189 +     *  {@code Integer.toHexString(n).toUpperCase()}
 131.190 +     * </blockquote>
 131.191 +     *
 131.192 +     * @param   i   an integer to be converted to a string.
 131.193 +     * @return  the string representation of the unsigned integer value
 131.194 +     *          represented by the argument in hexadecimal (base&nbsp;16).
 131.195 +     * @since   JDK1.0.2
 131.196 +     */
 131.197 +    public static String toHexString(int i) {
 131.198 +        return toUnsignedString(i, 4);
 131.199 +    }
 131.200 +
 131.201 +    /**
 131.202 +     * Returns a string representation of the integer argument as an
 131.203 +     * unsigned integer in base&nbsp;8.
 131.204 +     *
 131.205 +     * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
 131.206 +     * if the argument is negative; otherwise, it is equal to the
 131.207 +     * argument.  This value is converted to a string of ASCII digits
 131.208 +     * in octal (base&nbsp;8) with no extra leading {@code 0}s.
 131.209 +     *
 131.210 +     * <p>If the unsigned magnitude is zero, it is represented by a
 131.211 +     * single zero character {@code '0'}
 131.212 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 131.213 +     * the representation of the unsigned magnitude will not be the
 131.214 +     * zero character. The following characters are used as octal
 131.215 +     * digits:
 131.216 +     *
 131.217 +     * <blockquote>
 131.218 +     * {@code 01234567}
 131.219 +     * </blockquote>
 131.220 +     *
 131.221 +     * These are the characters <code>'&#92;u0030'</code> through
 131.222 +     * <code>'&#92;u0037'</code>.
 131.223 +     *
 131.224 +     * @param   i   an integer to be converted to a string.
 131.225 +     * @return  the string representation of the unsigned integer value
 131.226 +     *          represented by the argument in octal (base&nbsp;8).
 131.227 +     * @since   JDK1.0.2
 131.228 +     */
 131.229 +    public static String toOctalString(int i) {
 131.230 +        return toUnsignedString(i, 3);
 131.231 +    }
 131.232 +
 131.233 +    /**
 131.234 +     * Returns a string representation of the integer argument as an
 131.235 +     * unsigned integer in base&nbsp;2.
 131.236 +     *
 131.237 +     * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
 131.238 +     * if the argument is negative; otherwise it is equal to the
 131.239 +     * argument.  This value is converted to a string of ASCII digits
 131.240 +     * in binary (base&nbsp;2) with no extra leading {@code 0}s.
 131.241 +     * If the unsigned magnitude is zero, it is represented by a
 131.242 +     * single zero character {@code '0'}
 131.243 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 131.244 +     * the representation of the unsigned magnitude will not be the
 131.245 +     * zero character. The characters {@code '0'}
 131.246 +     * (<code>'&#92;u0030'</code>) and {@code '1'}
 131.247 +     * (<code>'&#92;u0031'</code>) are used as binary digits.
 131.248 +     *
 131.249 +     * @param   i   an integer to be converted to a string.
 131.250 +     * @return  the string representation of the unsigned integer value
 131.251 +     *          represented by the argument in binary (base&nbsp;2).
 131.252 +     * @since   JDK1.0.2
 131.253 +     */
 131.254 +    public static String toBinaryString(int i) {
 131.255 +        return toUnsignedString(i, 1);
 131.256 +    }
 131.257 +
 131.258 +    /**
 131.259 +     * Convert the integer to an unsigned number.
 131.260 +     */
 131.261 +    private static String toUnsignedString(int i, int shift) {
 131.262 +        char[] buf = new char[32];
 131.263 +        int charPos = 32;
 131.264 +        int radix = 1 << shift;
 131.265 +        int mask = radix - 1;
 131.266 +        do {
 131.267 +            buf[--charPos] = digits[i & mask];
 131.268 +            i >>>= shift;
 131.269 +        } while (i != 0);
 131.270 +
 131.271 +        return new String(buf, charPos, (32 - charPos));
 131.272 +    }
 131.273 +
 131.274 +
 131.275 +    final static char [] DigitTens = {
 131.276 +        '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
 131.277 +        '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
 131.278 +        '2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
 131.279 +        '3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
 131.280 +        '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
 131.281 +        '5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
 131.282 +        '6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
 131.283 +        '7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
 131.284 +        '8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
 131.285 +        '9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
 131.286 +        } ;
 131.287 +
 131.288 +    final static char [] DigitOnes = {
 131.289 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 131.290 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 131.291 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 131.292 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 131.293 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 131.294 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 131.295 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 131.296 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 131.297 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 131.298 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 131.299 +        } ;
 131.300 +
 131.301 +        // I use the "invariant division by multiplication" trick to
 131.302 +        // accelerate Integer.toString.  In particular we want to
 131.303 +        // avoid division by 10.
 131.304 +        //
 131.305 +        // The "trick" has roughly the same performance characteristics
 131.306 +        // as the "classic" Integer.toString code on a non-JIT VM.
 131.307 +        // The trick avoids .rem and .div calls but has a longer code
 131.308 +        // path and is thus dominated by dispatch overhead.  In the
 131.309 +        // JIT case the dispatch overhead doesn't exist and the
 131.310 +        // "trick" is considerably faster than the classic code.
 131.311 +        //
 131.312 +        // TODO-FIXME: convert (x * 52429) into the equiv shift-add
 131.313 +        // sequence.
 131.314 +        //
 131.315 +        // RE:  Division by Invariant Integers using Multiplication
 131.316 +        //      T Gralund, P Montgomery
 131.317 +        //      ACM PLDI 1994
 131.318 +        //
 131.319 +
 131.320 +    /**
 131.321 +     * Returns a {@code String} object representing the
 131.322 +     * specified integer. The argument is converted to signed decimal
 131.323 +     * representation and returned as a string, exactly as if the
 131.324 +     * argument and radix 10 were given as arguments to the {@link
 131.325 +     * #toString(int, int)} method.
 131.326 +     *
 131.327 +     * @param   i   an integer to be converted.
 131.328 +     * @return  a string representation of the argument in base&nbsp;10.
 131.329 +     */
 131.330 +    @JavaScriptBody(args = "i", body = "return i.toString();")
 131.331 +    public static String toString(int i) {
 131.332 +        if (i == Integer.MIN_VALUE)
 131.333 +            return "-2147483648";
 131.334 +        int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
 131.335 +        char[] buf = new char[size];
 131.336 +        getChars(i, size, buf);
 131.337 +        return new String(buf, 0, size);
 131.338 +    }
 131.339 +
 131.340 +    /**
 131.341 +     * Places characters representing the integer i into the
 131.342 +     * character array buf. The characters are placed into
 131.343 +     * the buffer backwards starting with the least significant
 131.344 +     * digit at the specified index (exclusive), and working
 131.345 +     * backwards from there.
 131.346 +     *
 131.347 +     * Will fail if i == Integer.MIN_VALUE
 131.348 +     */
 131.349 +    static void getChars(int i, int index, char[] buf) {
 131.350 +        int q, r;
 131.351 +        int charPos = index;
 131.352 +        char sign = 0;
 131.353 +
 131.354 +        if (i < 0) {
 131.355 +            sign = '-';
 131.356 +            i = -i;
 131.357 +        }
 131.358 +
 131.359 +        // Generate two digits per iteration
 131.360 +        while (i >= 65536) {
 131.361 +            q = i / 100;
 131.362 +        // really: r = i - (q * 100);
 131.363 +            r = i - ((q << 6) + (q << 5) + (q << 2));
 131.364 +            i = q;
 131.365 +            buf [--charPos] = DigitOnes[r];
 131.366 +            buf [--charPos] = DigitTens[r];
 131.367 +        }
 131.368 +
 131.369 +        // Fall thru to fast mode for smaller numbers
 131.370 +        // assert(i <= 65536, i);
 131.371 +        for (;;) {
 131.372 +            q = (i * 52429) >>> (16+3);
 131.373 +            r = i - ((q << 3) + (q << 1));  // r = i-(q*10) ...
 131.374 +            buf [--charPos] = digits [r];
 131.375 +            i = q;
 131.376 +            if (i == 0) break;
 131.377 +        }
 131.378 +        if (sign != 0) {
 131.379 +            buf [--charPos] = sign;
 131.380 +        }
 131.381 +    }
 131.382 +
 131.383 +    final static int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
 131.384 +                                      99999999, 999999999, Integer.MAX_VALUE };
 131.385 +
 131.386 +    // Requires positive x
 131.387 +    static int stringSize(int x) {
 131.388 +        for (int i=0; ; i++)
 131.389 +            if (x <= sizeTable[i])
 131.390 +                return i+1;
 131.391 +    }
 131.392 +
 131.393 +    /**
 131.394 +     * Parses the string argument as a signed integer in the radix
 131.395 +     * specified by the second argument. The characters in the string
 131.396 +     * must all be digits of the specified radix (as determined by
 131.397 +     * whether {@link java.lang.Character#digit(char, int)} returns a
 131.398 +     * nonnegative value), except that the first character may be an
 131.399 +     * ASCII minus sign {@code '-'} (<code>'&#92;u002D'</code>) to
 131.400 +     * indicate a negative value or an ASCII plus sign {@code '+'}
 131.401 +     * (<code>'&#92;u002B'</code>) to indicate a positive value. The
 131.402 +     * resulting integer value is returned.
 131.403 +     *
 131.404 +     * <p>An exception of type {@code NumberFormatException} is
 131.405 +     * thrown if any of the following situations occurs:
 131.406 +     * <ul>
 131.407 +     * <li>The first argument is {@code null} or is a string of
 131.408 +     * length zero.
 131.409 +     *
 131.410 +     * <li>The radix is either smaller than
 131.411 +     * {@link java.lang.Character#MIN_RADIX} or
 131.412 +     * larger than {@link java.lang.Character#MAX_RADIX}.
 131.413 +     *
 131.414 +     * <li>Any character of the string is not a digit of the specified
 131.415 +     * radix, except that the first character may be a minus sign
 131.416 +     * {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
 131.417 +     * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
 131.418 +     * string is longer than length 1.
 131.419 +     *
 131.420 +     * <li>The value represented by the string is not a value of type
 131.421 +     * {@code int}.
 131.422 +     * </ul>
 131.423 +     *
 131.424 +     * <p>Examples:
 131.425 +     * <blockquote><pre>
 131.426 +     * parseInt("0", 10) returns 0
 131.427 +     * parseInt("473", 10) returns 473
 131.428 +     * parseInt("+42", 10) returns 42
 131.429 +     * parseInt("-0", 10) returns 0
 131.430 +     * parseInt("-FF", 16) returns -255
 131.431 +     * parseInt("1100110", 2) returns 102
 131.432 +     * parseInt("2147483647", 10) returns 2147483647
 131.433 +     * parseInt("-2147483648", 10) returns -2147483648
 131.434 +     * parseInt("2147483648", 10) throws a NumberFormatException
 131.435 +     * parseInt("99", 8) throws a NumberFormatException
 131.436 +     * parseInt("Kona", 10) throws a NumberFormatException
 131.437 +     * parseInt("Kona", 27) returns 411787
 131.438 +     * </pre></blockquote>
 131.439 +     *
 131.440 +     * @param      s   the {@code String} containing the integer
 131.441 +     *                  representation to be parsed
 131.442 +     * @param      radix   the radix to be used while parsing {@code s}.
 131.443 +     * @return     the integer represented by the string argument in the
 131.444 +     *             specified radix.
 131.445 +     * @exception  NumberFormatException if the {@code String}
 131.446 +     *             does not contain a parsable {@code int}.
 131.447 +     */
 131.448 +    @JavaScriptBody(args={"s", "radix"}, body="return parseInt(s,radix);")
 131.449 +    public static int parseInt(String s, int radix)
 131.450 +                throws NumberFormatException
 131.451 +    {
 131.452 +        /*
 131.453 +         * WARNING: This method may be invoked early during VM initialization
 131.454 +         * before IntegerCache is initialized. Care must be taken to not use
 131.455 +         * the valueOf method.
 131.456 +         */
 131.457 +
 131.458 +        if (s == null) {
 131.459 +            throw new NumberFormatException("null");
 131.460 +        }
 131.461 +
 131.462 +        if (radix < Character.MIN_RADIX) {
 131.463 +            throw new NumberFormatException("radix " + radix +
 131.464 +                                            " less than Character.MIN_RADIX");
 131.465 +        }
 131.466 +
 131.467 +        if (radix > Character.MAX_RADIX) {
 131.468 +            throw new NumberFormatException("radix " + radix +
 131.469 +                                            " greater than Character.MAX_RADIX");
 131.470 +        }
 131.471 +
 131.472 +        int result = 0;
 131.473 +        boolean negative = false;
 131.474 +        int i = 0, len = s.length();
 131.475 +        int limit = -Integer.MAX_VALUE;
 131.476 +        int multmin;
 131.477 +        int digit;
 131.478 +
 131.479 +        if (len > 0) {
 131.480 +            char firstChar = s.charAt(0);
 131.481 +            if (firstChar < '0') { // Possible leading "+" or "-"
 131.482 +                if (firstChar == '-') {
 131.483 +                    negative = true;
 131.484 +                    limit = Integer.MIN_VALUE;
 131.485 +                } else if (firstChar != '+')
 131.486 +                    throw NumberFormatException.forInputString(s);
 131.487 +
 131.488 +                if (len == 1) // Cannot have lone "+" or "-"
 131.489 +                    throw NumberFormatException.forInputString(s);
 131.490 +                i++;
 131.491 +            }
 131.492 +            multmin = limit / radix;
 131.493 +            while (i < len) {
 131.494 +                // Accumulating negatively avoids surprises near MAX_VALUE
 131.495 +                digit = Character.digit(s.charAt(i++),radix);
 131.496 +                if (digit < 0) {
 131.497 +                    throw NumberFormatException.forInputString(s);
 131.498 +                }
 131.499 +                if (result < multmin) {
 131.500 +                    throw NumberFormatException.forInputString(s);
 131.501 +                }
 131.502 +                result *= radix;
 131.503 +                if (result < limit + digit) {
 131.504 +                    throw NumberFormatException.forInputString(s);
 131.505 +                }
 131.506 +                result -= digit;
 131.507 +            }
 131.508 +        } else {
 131.509 +            throw NumberFormatException.forInputString(s);
 131.510 +        }
 131.511 +        return negative ? result : -result;
 131.512 +    }
 131.513 +
 131.514 +    /**
 131.515 +     * Parses the string argument as a signed decimal integer. The
 131.516 +     * characters in the string must all be decimal digits, except
 131.517 +     * that the first character may be an ASCII minus sign {@code '-'}
 131.518 +     * (<code>'&#92;u002D'</code>) to indicate a negative value or an
 131.519 +     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
 131.520 +     * indicate a positive value. The resulting integer value is
 131.521 +     * returned, exactly as if the argument and the radix 10 were
 131.522 +     * given as arguments to the {@link #parseInt(java.lang.String,
 131.523 +     * int)} method.
 131.524 +     *
 131.525 +     * @param s    a {@code String} containing the {@code int}
 131.526 +     *             representation to be parsed
 131.527 +     * @return     the integer value represented by the argument in decimal.
 131.528 +     * @exception  NumberFormatException  if the string does not contain a
 131.529 +     *               parsable integer.
 131.530 +     */
 131.531 +    public static int parseInt(String s) throws NumberFormatException {
 131.532 +        return parseInt(s,10);
 131.533 +    }
 131.534 +
 131.535 +    /**
 131.536 +     * Returns an {@code Integer} object holding the value
 131.537 +     * extracted from the specified {@code String} when parsed
 131.538 +     * with the radix given by the second argument. The first argument
 131.539 +     * is interpreted as representing a signed integer in the radix
 131.540 +     * specified by the second argument, exactly as if the arguments
 131.541 +     * were given to the {@link #parseInt(java.lang.String, int)}
 131.542 +     * method. The result is an {@code Integer} object that
 131.543 +     * represents the integer value specified by the string.
 131.544 +     *
 131.545 +     * <p>In other words, this method returns an {@code Integer}
 131.546 +     * object equal to the value of:
 131.547 +     *
 131.548 +     * <blockquote>
 131.549 +     *  {@code new Integer(Integer.parseInt(s, radix))}
 131.550 +     * </blockquote>
 131.551 +     *
 131.552 +     * @param      s   the string to be parsed.
 131.553 +     * @param      radix the radix to be used in interpreting {@code s}
 131.554 +     * @return     an {@code Integer} object holding the value
 131.555 +     *             represented by the string argument in the specified
 131.556 +     *             radix.
 131.557 +     * @exception NumberFormatException if the {@code String}
 131.558 +     *            does not contain a parsable {@code int}.
 131.559 +     */
 131.560 +    public static Integer valueOf(String s, int radix) throws NumberFormatException {
 131.561 +        return Integer.valueOf(parseInt(s,radix));
 131.562 +    }
 131.563 +
 131.564 +    /**
 131.565 +     * Returns an {@code Integer} object holding the
 131.566 +     * value of the specified {@code String}. The argument is
 131.567 +     * interpreted as representing a signed decimal integer, exactly
 131.568 +     * as if the argument were given to the {@link
 131.569 +     * #parseInt(java.lang.String)} method. The result is an
 131.570 +     * {@code Integer} object that represents the integer value
 131.571 +     * specified by the string.
 131.572 +     *
 131.573 +     * <p>In other words, this method returns an {@code Integer}
 131.574 +     * object equal to the value of:
 131.575 +     *
 131.576 +     * <blockquote>
 131.577 +     *  {@code new Integer(Integer.parseInt(s))}
 131.578 +     * </blockquote>
 131.579 +     *
 131.580 +     * @param      s   the string to be parsed.
 131.581 +     * @return     an {@code Integer} object holding the value
 131.582 +     *             represented by the string argument.
 131.583 +     * @exception  NumberFormatException  if the string cannot be parsed
 131.584 +     *             as an integer.
 131.585 +     */
 131.586 +    public static Integer valueOf(String s) throws NumberFormatException {
 131.587 +        return Integer.valueOf(parseInt(s, 10));
 131.588 +    }
 131.589 +
 131.590 +    /**
 131.591 +     * Cache to support the object identity semantics of autoboxing for values between
 131.592 +     * -128 and 127 (inclusive) as required by JLS.
 131.593 +     *
 131.594 +     * The cache is initialized on first usage.  The size of the cache
 131.595 +     * may be controlled by the -XX:AutoBoxCacheMax=<size> option.
 131.596 +     * During VM initialization, java.lang.Integer.IntegerCache.high property
 131.597 +     * may be set and saved in the private system properties in the
 131.598 +     * sun.misc.VM class.
 131.599 +     */
 131.600 +
 131.601 +    private static class IntegerCache {
 131.602 +        static final int low = -128;
 131.603 +        static final int high;
 131.604 +        static final Integer cache[];
 131.605 +
 131.606 +        static {
 131.607 +            // high value may be configured by property
 131.608 +            int h = 127;
 131.609 +            String integerCacheHighPropValue =
 131.610 +                AbstractStringBuilder.getProperty("java.lang.Integer.IntegerCache.high");
 131.611 +            if (integerCacheHighPropValue != null) {
 131.612 +                int i = parseInt(integerCacheHighPropValue);
 131.613 +                i = Math.max(i, 127);
 131.614 +                // Maximum array size is Integer.MAX_VALUE
 131.615 +                h = Math.min(i, Integer.MAX_VALUE - (-low));
 131.616 +            }
 131.617 +            high = h;
 131.618 +
 131.619 +            cache = new Integer[(high - low) + 1];
 131.620 +            int j = low;
 131.621 +            for(int k = 0; k < cache.length; k++)
 131.622 +                cache[k] = new Integer(j++);
 131.623 +        }
 131.624 +
 131.625 +        private IntegerCache() {}
 131.626 +    }
 131.627 +
 131.628 +    /**
 131.629 +     * Returns an {@code Integer} instance representing the specified
 131.630 +     * {@code int} value.  If a new {@code Integer} instance is not
 131.631 +     * required, this method should generally be used in preference to
 131.632 +     * the constructor {@link #Integer(int)}, as this method is likely
 131.633 +     * to yield significantly better space and time performance by
 131.634 +     * caching frequently requested values.
 131.635 +     *
 131.636 +     * This method will always cache values in the range -128 to 127,
 131.637 +     * inclusive, and may cache other values outside of this range.
 131.638 +     *
 131.639 +     * @param  i an {@code int} value.
 131.640 +     * @return an {@code Integer} instance representing {@code i}.
 131.641 +     * @since  1.5
 131.642 +     */
 131.643 +    public static Integer valueOf(int i) {
 131.644 +        //assert IntegerCache.high >= 127;
 131.645 +        if (i >= IntegerCache.low && i <= IntegerCache.high)
 131.646 +            return IntegerCache.cache[i + (-IntegerCache.low)];
 131.647 +        return new Integer(i);
 131.648 +    }
 131.649 +
 131.650 +    /**
 131.651 +     * The value of the {@code Integer}.
 131.652 +     *
 131.653 +     * @serial
 131.654 +     */
 131.655 +    private final int value;
 131.656 +
 131.657 +    /**
 131.658 +     * Constructs a newly allocated {@code Integer} object that
 131.659 +     * represents the specified {@code int} value.
 131.660 +     *
 131.661 +     * @param   value   the value to be represented by the
 131.662 +     *                  {@code Integer} object.
 131.663 +     */
 131.664 +    public Integer(int value) {
 131.665 +        this.value = value;
 131.666 +    }
 131.667 +
 131.668 +    /**
 131.669 +     * Constructs a newly allocated {@code Integer} object that
 131.670 +     * represents the {@code int} value indicated by the
 131.671 +     * {@code String} parameter. The string is converted to an
 131.672 +     * {@code int} value in exactly the manner used by the
 131.673 +     * {@code parseInt} method for radix 10.
 131.674 +     *
 131.675 +     * @param      s   the {@code String} to be converted to an
 131.676 +     *                 {@code Integer}.
 131.677 +     * @exception  NumberFormatException  if the {@code String} does not
 131.678 +     *               contain a parsable integer.
 131.679 +     * @see        java.lang.Integer#parseInt(java.lang.String, int)
 131.680 +     */
 131.681 +    public Integer(String s) throws NumberFormatException {
 131.682 +        this.value = parseInt(s, 10);
 131.683 +    }
 131.684 +
 131.685 +    /**
 131.686 +     * Returns the value of this {@code Integer} as a
 131.687 +     * {@code byte}.
 131.688 +     */
 131.689 +    public byte byteValue() {
 131.690 +        return (byte)value;
 131.691 +    }
 131.692 +
 131.693 +    /**
 131.694 +     * Returns the value of this {@code Integer} as a
 131.695 +     * {@code short}.
 131.696 +     */
 131.697 +    public short shortValue() {
 131.698 +        return (short)value;
 131.699 +    }
 131.700 +
 131.701 +    /**
 131.702 +     * Returns the value of this {@code Integer} as an
 131.703 +     * {@code int}.
 131.704 +     */
 131.705 +    public int intValue() {
 131.706 +        return value;
 131.707 +    }
 131.708 +
 131.709 +    /**
 131.710 +     * Returns the value of this {@code Integer} as a
 131.711 +     * {@code long}.
 131.712 +     */
 131.713 +    public long longValue() {
 131.714 +        return (long)value;
 131.715 +    }
 131.716 +
 131.717 +    /**
 131.718 +     * Returns the value of this {@code Integer} as a
 131.719 +     * {@code float}.
 131.720 +     */
 131.721 +    public float floatValue() {
 131.722 +        return (float)value;
 131.723 +    }
 131.724 +
 131.725 +    /**
 131.726 +     * Returns the value of this {@code Integer} as a
 131.727 +     * {@code double}.
 131.728 +     */
 131.729 +    public double doubleValue() {
 131.730 +        return (double)value;
 131.731 +    }
 131.732 +
 131.733 +    /**
 131.734 +     * Returns a {@code String} object representing this
 131.735 +     * {@code Integer}'s value. The value is converted to signed
 131.736 +     * decimal representation and returned as a string, exactly as if
 131.737 +     * the integer value were given as an argument to the {@link
 131.738 +     * java.lang.Integer#toString(int)} method.
 131.739 +     *
 131.740 +     * @return  a string representation of the value of this object in
 131.741 +     *          base&nbsp;10.
 131.742 +     */
 131.743 +    public String toString() {
 131.744 +        return toString(value);
 131.745 +    }
 131.746 +
 131.747 +    /**
 131.748 +     * Returns a hash code for this {@code Integer}.
 131.749 +     *
 131.750 +     * @return  a hash code value for this object, equal to the
 131.751 +     *          primitive {@code int} value represented by this
 131.752 +     *          {@code Integer} object.
 131.753 +     */
 131.754 +    public int hashCode() {
 131.755 +        return value;
 131.756 +    }
 131.757 +
 131.758 +    /**
 131.759 +     * Compares this object to the specified object.  The result is
 131.760 +     * {@code true} if and only if the argument is not
 131.761 +     * {@code null} and is an {@code Integer} object that
 131.762 +     * contains the same {@code int} value as this object.
 131.763 +     *
 131.764 +     * @param   obj   the object to compare with.
 131.765 +     * @return  {@code true} if the objects are the same;
 131.766 +     *          {@code false} otherwise.
 131.767 +     */
 131.768 +    public boolean equals(Object obj) {
 131.769 +        if (obj instanceof Integer) {
 131.770 +            return value == ((Integer)obj).intValue();
 131.771 +        }
 131.772 +        return false;
 131.773 +    }
 131.774 +
 131.775 +    /**
 131.776 +     * Determines the integer value of the system property with the
 131.777 +     * specified name.
 131.778 +     *
 131.779 +     * <p>The first argument is treated as the name of a system property.
 131.780 +     * System properties are accessible through the
 131.781 +     * {@link java.lang.System#getProperty(java.lang.String)} method. The
 131.782 +     * string value of this property is then interpreted as an integer
 131.783 +     * value and an {@code Integer} object representing this value is
 131.784 +     * returned. Details of possible numeric formats can be found with
 131.785 +     * the definition of {@code getProperty}.
 131.786 +     *
 131.787 +     * <p>If there is no property with the specified name, if the specified name
 131.788 +     * is empty or {@code null}, or if the property does not have
 131.789 +     * the correct numeric format, then {@code null} is returned.
 131.790 +     *
 131.791 +     * <p>In other words, this method returns an {@code Integer}
 131.792 +     * object equal to the value of:
 131.793 +     *
 131.794 +     * <blockquote>
 131.795 +     *  {@code getInteger(nm, null)}
 131.796 +     * </blockquote>
 131.797 +     *
 131.798 +     * @param   nm   property name.
 131.799 +     * @return  the {@code Integer} value of the property.
 131.800 +     * @see     java.lang.System#getProperty(java.lang.String)
 131.801 +     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 131.802 +     */
 131.803 +    public static Integer getInteger(String nm) {
 131.804 +        return getInteger(nm, null);
 131.805 +    }
 131.806 +
 131.807 +    /**
 131.808 +     * Determines the integer value of the system property with the
 131.809 +     * specified name.
 131.810 +     *
 131.811 +     * <p>The first argument is treated as the name of a system property.
 131.812 +     * System properties are accessible through the {@link
 131.813 +     * java.lang.System#getProperty(java.lang.String)} method. The
 131.814 +     * string value of this property is then interpreted as an integer
 131.815 +     * value and an {@code Integer} object representing this value is
 131.816 +     * returned. Details of possible numeric formats can be found with
 131.817 +     * the definition of {@code getProperty}.
 131.818 +     *
 131.819 +     * <p>The second argument is the default value. An {@code Integer} object
 131.820 +     * that represents the value of the second argument is returned if there
 131.821 +     * is no property of the specified name, if the property does not have
 131.822 +     * the correct numeric format, or if the specified name is empty or
 131.823 +     * {@code null}.
 131.824 +     *
 131.825 +     * <p>In other words, this method returns an {@code Integer} object
 131.826 +     * equal to the value of:
 131.827 +     *
 131.828 +     * <blockquote>
 131.829 +     *  {@code getInteger(nm, new Integer(val))}
 131.830 +     * </blockquote>
 131.831 +     *
 131.832 +     * but in practice it may be implemented in a manner such as:
 131.833 +     *
 131.834 +     * <blockquote><pre>
 131.835 +     * Integer result = getInteger(nm, null);
 131.836 +     * return (result == null) ? new Integer(val) : result;
 131.837 +     * </pre></blockquote>
 131.838 +     *
 131.839 +     * to avoid the unnecessary allocation of an {@code Integer}
 131.840 +     * object when the default value is not needed.
 131.841 +     *
 131.842 +     * @param   nm   property name.
 131.843 +     * @param   val   default value.
 131.844 +     * @return  the {@code Integer} value of the property.
 131.845 +     * @see     java.lang.System#getProperty(java.lang.String)
 131.846 +     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 131.847 +     */
 131.848 +    public static Integer getInteger(String nm, int val) {
 131.849 +        Integer result = getInteger(nm, null);
 131.850 +        return (result == null) ? Integer.valueOf(val) : result;
 131.851 +    }
 131.852 +
 131.853 +    /**
 131.854 +     * Returns the integer value of the system property with the
 131.855 +     * specified name.  The first argument is treated as the name of a
 131.856 +     * system property.  System properties are accessible through the
 131.857 +     * {@link java.lang.System#getProperty(java.lang.String)} method.
 131.858 +     * The string value of this property is then interpreted as an
 131.859 +     * integer value, as per the {@code Integer.decode} method,
 131.860 +     * and an {@code Integer} object representing this value is
 131.861 +     * returned.
 131.862 +     *
 131.863 +     * <ul><li>If the property value begins with the two ASCII characters
 131.864 +     *         {@code 0x} or the ASCII character {@code #}, not
 131.865 +     *      followed by a minus sign, then the rest of it is parsed as a
 131.866 +     *      hexadecimal integer exactly as by the method
 131.867 +     *      {@link #valueOf(java.lang.String, int)} with radix 16.
 131.868 +     * <li>If the property value begins with the ASCII character
 131.869 +     *     {@code 0} followed by another character, it is parsed as an
 131.870 +     *     octal integer exactly as by the method
 131.871 +     *     {@link #valueOf(java.lang.String, int)} with radix 8.
 131.872 +     * <li>Otherwise, the property value is parsed as a decimal integer
 131.873 +     * exactly as by the method {@link #valueOf(java.lang.String, int)}
 131.874 +     * with radix 10.
 131.875 +     * </ul>
 131.876 +     *
 131.877 +     * <p>The second argument is the default value. The default value is
 131.878 +     * returned if there is no property of the specified name, if the
 131.879 +     * property does not have the correct numeric format, or if the
 131.880 +     * specified name is empty or {@code null}.
 131.881 +     *
 131.882 +     * @param   nm   property name.
 131.883 +     * @param   val   default value.
 131.884 +     * @return  the {@code Integer} value of the property.
 131.885 +     * @see     java.lang.System#getProperty(java.lang.String)
 131.886 +     * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
 131.887 +     * @see java.lang.Integer#decode
 131.888 +     */
 131.889 +    public static Integer getInteger(String nm, Integer val) {
 131.890 +        String v = null;
 131.891 +        try {
 131.892 +            v = AbstractStringBuilder.getProperty(nm);
 131.893 +        } catch (IllegalArgumentException e) {
 131.894 +        } catch (NullPointerException e) {
 131.895 +        }
 131.896 +        if (v != null) {
 131.897 +            try {
 131.898 +                return Integer.decode(v);
 131.899 +            } catch (NumberFormatException e) {
 131.900 +            }
 131.901 +        }
 131.902 +        return val;
 131.903 +    }
 131.904 +
 131.905 +    /**
 131.906 +     * Decodes a {@code String} into an {@code Integer}.
 131.907 +     * Accepts decimal, hexadecimal, and octal numbers given
 131.908 +     * by the following grammar:
 131.909 +     *
 131.910 +     * <blockquote>
 131.911 +     * <dl>
 131.912 +     * <dt><i>DecodableString:</i>
 131.913 +     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 131.914 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 131.915 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 131.916 +     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 131.917 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 131.918 +     * <p>
 131.919 +     * <dt><i>Sign:</i>
 131.920 +     * <dd>{@code -}
 131.921 +     * <dd>{@code +}
 131.922 +     * </dl>
 131.923 +     * </blockquote>
 131.924 +     *
 131.925 +     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 131.926 +     * are as defined in section 3.10.1 of
 131.927 +     * <cite>The Java&trade; Language Specification</cite>,
 131.928 +     * except that underscores are not accepted between digits.
 131.929 +     *
 131.930 +     * <p>The sequence of characters following an optional
 131.931 +     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 131.932 +     * "{@code #}", or leading zero) is parsed as by the {@code
 131.933 +     * Integer.parseInt} method with the indicated radix (10, 16, or
 131.934 +     * 8).  This sequence of characters must represent a positive
 131.935 +     * value or a {@link NumberFormatException} will be thrown.  The
 131.936 +     * result is negated if first character of the specified {@code
 131.937 +     * String} is the minus sign.  No whitespace characters are
 131.938 +     * permitted in the {@code String}.
 131.939 +     *
 131.940 +     * @param     nm the {@code String} to decode.
 131.941 +     * @return    an {@code Integer} object holding the {@code int}
 131.942 +     *             value represented by {@code nm}
 131.943 +     * @exception NumberFormatException  if the {@code String} does not
 131.944 +     *            contain a parsable integer.
 131.945 +     * @see java.lang.Integer#parseInt(java.lang.String, int)
 131.946 +     */
 131.947 +    public static Integer decode(String nm) throws NumberFormatException {
 131.948 +        int radix = 10;
 131.949 +        int index = 0;
 131.950 +        boolean negative = false;
 131.951 +        Integer result;
 131.952 +
 131.953 +        if (nm.length() == 0)
 131.954 +            throw new NumberFormatException("Zero length string");
 131.955 +        char firstChar = nm.charAt(0);
 131.956 +        // Handle sign, if present
 131.957 +        if (firstChar == '-') {
 131.958 +            negative = true;
 131.959 +            index++;
 131.960 +        } else if (firstChar == '+')
 131.961 +            index++;
 131.962 +
 131.963 +        // Handle radix specifier, if present
 131.964 +        if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
 131.965 +            index += 2;
 131.966 +            radix = 16;
 131.967 +        }
 131.968 +        else if (nm.startsWith("#", index)) {
 131.969 +            index ++;
 131.970 +            radix = 16;
 131.971 +        }
 131.972 +        else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
 131.973 +            index ++;
 131.974 +            radix = 8;
 131.975 +        }
 131.976 +
 131.977 +        if (nm.startsWith("-", index) || nm.startsWith("+", index))
 131.978 +            throw new NumberFormatException("Sign character in wrong position");
 131.979 +
 131.980 +        try {
 131.981 +            result = Integer.valueOf(nm.substring(index), radix);
 131.982 +            result = negative ? Integer.valueOf(-result.intValue()) : result;
 131.983 +        } catch (NumberFormatException e) {
 131.984 +            // If number is Integer.MIN_VALUE, we'll end up here. The next line
 131.985 +            // handles this case, and causes any genuine format error to be
 131.986 +            // rethrown.
 131.987 +            String constant = negative ? ("-" + nm.substring(index))
 131.988 +                                       : nm.substring(index);
 131.989 +            result = Integer.valueOf(constant, radix);
 131.990 +        }
 131.991 +        return result;
 131.992 +    }
 131.993 +
 131.994 +    /**
 131.995 +     * Compares two {@code Integer} objects numerically.
 131.996 +     *
 131.997 +     * @param   anotherInteger   the {@code Integer} to be compared.
 131.998 +     * @return  the value {@code 0} if this {@code Integer} is
 131.999 +     *          equal to the argument {@code Integer}; a value less than
131.1000 +     *          {@code 0} if this {@code Integer} is numerically less
131.1001 +     *          than the argument {@code Integer}; and a value greater
131.1002 +     *          than {@code 0} if this {@code Integer} is numerically
131.1003 +     *           greater than the argument {@code Integer} (signed
131.1004 +     *           comparison).
131.1005 +     * @since   1.2
131.1006 +     */
131.1007 +    public int compareTo(Integer anotherInteger) {
131.1008 +        return compare(this.value, anotherInteger.value);
131.1009 +    }
131.1010 +
131.1011 +    /**
131.1012 +     * Compares two {@code int} values numerically.
131.1013 +     * The value returned is identical to what would be returned by:
131.1014 +     * <pre>
131.1015 +     *    Integer.valueOf(x).compareTo(Integer.valueOf(y))
131.1016 +     * </pre>
131.1017 +     *
131.1018 +     * @param  x the first {@code int} to compare
131.1019 +     * @param  y the second {@code int} to compare
131.1020 +     * @return the value {@code 0} if {@code x == y};
131.1021 +     *         a value less than {@code 0} if {@code x < y}; and
131.1022 +     *         a value greater than {@code 0} if {@code x > y}
131.1023 +     * @since 1.7
131.1024 +     */
131.1025 +    public static int compare(int x, int y) {
131.1026 +        return (x < y) ? -1 : ((x == y) ? 0 : 1);
131.1027 +    }
131.1028 +
131.1029 +
131.1030 +    // Bit twiddling
131.1031 +
131.1032 +    /**
131.1033 +     * The number of bits used to represent an {@code int} value in two's
131.1034 +     * complement binary form.
131.1035 +     *
131.1036 +     * @since 1.5
131.1037 +     */
131.1038 +    public static final int SIZE = 32;
131.1039 +
131.1040 +    /**
131.1041 +     * Returns an {@code int} value with at most a single one-bit, in the
131.1042 +     * position of the highest-order ("leftmost") one-bit in the specified
131.1043 +     * {@code int} value.  Returns zero if the specified value has no
131.1044 +     * one-bits in its two's complement binary representation, that is, if it
131.1045 +     * is equal to zero.
131.1046 +     *
131.1047 +     * @return an {@code int} value with a single one-bit, in the position
131.1048 +     *     of the highest-order one-bit in the specified value, or zero if
131.1049 +     *     the specified value is itself equal to zero.
131.1050 +     * @since 1.5
131.1051 +     */
131.1052 +    public static int highestOneBit(int i) {
131.1053 +        // HD, Figure 3-1
131.1054 +        i |= (i >>  1);
131.1055 +        i |= (i >>  2);
131.1056 +        i |= (i >>  4);
131.1057 +        i |= (i >>  8);
131.1058 +        i |= (i >> 16);
131.1059 +        return i - (i >>> 1);
131.1060 +    }
131.1061 +
131.1062 +    /**
131.1063 +     * Returns an {@code int} value with at most a single one-bit, in the
131.1064 +     * position of the lowest-order ("rightmost") one-bit in the specified
131.1065 +     * {@code int} value.  Returns zero if the specified value has no
131.1066 +     * one-bits in its two's complement binary representation, that is, if it
131.1067 +     * is equal to zero.
131.1068 +     *
131.1069 +     * @return an {@code int} value with a single one-bit, in the position
131.1070 +     *     of the lowest-order one-bit in the specified value, or zero if
131.1071 +     *     the specified value is itself equal to zero.
131.1072 +     * @since 1.5
131.1073 +     */
131.1074 +    public static int lowestOneBit(int i) {
131.1075 +        // HD, Section 2-1
131.1076 +        return i & -i;
131.1077 +    }
131.1078 +
131.1079 +    /**
131.1080 +     * Returns the number of zero bits preceding the highest-order
131.1081 +     * ("leftmost") one-bit in the two's complement binary representation
131.1082 +     * of the specified {@code int} value.  Returns 32 if the
131.1083 +     * specified value has no one-bits in its two's complement representation,
131.1084 +     * in other words if it is equal to zero.
131.1085 +     *
131.1086 +     * <p>Note that this method is closely related to the logarithm base 2.
131.1087 +     * For all positive {@code int} values x:
131.1088 +     * <ul>
131.1089 +     * <li>floor(log<sub>2</sub>(x)) = {@code 31 - numberOfLeadingZeros(x)}
131.1090 +     * <li>ceil(log<sub>2</sub>(x)) = {@code 32 - numberOfLeadingZeros(x - 1)}
131.1091 +     * </ul>
131.1092 +     *
131.1093 +     * @return the number of zero bits preceding the highest-order
131.1094 +     *     ("leftmost") one-bit in the two's complement binary representation
131.1095 +     *     of the specified {@code int} value, or 32 if the value
131.1096 +     *     is equal to zero.
131.1097 +     * @since 1.5
131.1098 +     */
131.1099 +    public static int numberOfLeadingZeros(int i) {
131.1100 +        // HD, Figure 5-6
131.1101 +        if (i == 0)
131.1102 +            return 32;
131.1103 +        int n = 1;
131.1104 +        if (i >>> 16 == 0) { n += 16; i <<= 16; }
131.1105 +        if (i >>> 24 == 0) { n +=  8; i <<=  8; }
131.1106 +        if (i >>> 28 == 0) { n +=  4; i <<=  4; }
131.1107 +        if (i >>> 30 == 0) { n +=  2; i <<=  2; }
131.1108 +        n -= i >>> 31;
131.1109 +        return n;
131.1110 +    }
131.1111 +
131.1112 +    /**
131.1113 +     * Returns the number of zero bits following the lowest-order ("rightmost")
131.1114 +     * one-bit in the two's complement binary representation of the specified
131.1115 +     * {@code int} value.  Returns 32 if the specified value has no
131.1116 +     * one-bits in its two's complement representation, in other words if it is
131.1117 +     * equal to zero.
131.1118 +     *
131.1119 +     * @return the number of zero bits following the lowest-order ("rightmost")
131.1120 +     *     one-bit in the two's complement binary representation of the
131.1121 +     *     specified {@code int} value, or 32 if the value is equal
131.1122 +     *     to zero.
131.1123 +     * @since 1.5
131.1124 +     */
131.1125 +    public static int numberOfTrailingZeros(int i) {
131.1126 +        // HD, Figure 5-14
131.1127 +        int y;
131.1128 +        if (i == 0) return 32;
131.1129 +        int n = 31;
131.1130 +        y = i <<16; if (y != 0) { n = n -16; i = y; }
131.1131 +        y = i << 8; if (y != 0) { n = n - 8; i = y; }
131.1132 +        y = i << 4; if (y != 0) { n = n - 4; i = y; }
131.1133 +        y = i << 2; if (y != 0) { n = n - 2; i = y; }
131.1134 +        return n - ((i << 1) >>> 31);
131.1135 +    }
131.1136 +
131.1137 +    /**
131.1138 +     * Returns the number of one-bits in the two's complement binary
131.1139 +     * representation of the specified {@code int} value.  This function is
131.1140 +     * sometimes referred to as the <i>population count</i>.
131.1141 +     *
131.1142 +     * @return the number of one-bits in the two's complement binary
131.1143 +     *     representation of the specified {@code int} value.
131.1144 +     * @since 1.5
131.1145 +     */
131.1146 +    public static int bitCount(int i) {
131.1147 +        // HD, Figure 5-2
131.1148 +        i = i - ((i >>> 1) & 0x55555555);
131.1149 +        i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
131.1150 +        i = (i + (i >>> 4)) & 0x0f0f0f0f;
131.1151 +        i = i + (i >>> 8);
131.1152 +        i = i + (i >>> 16);
131.1153 +        return i & 0x3f;
131.1154 +    }
131.1155 +
131.1156 +    /**
131.1157 +     * Returns the value obtained by rotating the two's complement binary
131.1158 +     * representation of the specified {@code int} value left by the
131.1159 +     * specified number of bits.  (Bits shifted out of the left hand, or
131.1160 +     * high-order, side reenter on the right, or low-order.)
131.1161 +     *
131.1162 +     * <p>Note that left rotation with a negative distance is equivalent to
131.1163 +     * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val,
131.1164 +     * distance)}.  Note also that rotation by any multiple of 32 is a
131.1165 +     * no-op, so all but the last five bits of the rotation distance can be
131.1166 +     * ignored, even if the distance is negative: {@code rotateLeft(val,
131.1167 +     * distance) == rotateLeft(val, distance & 0x1F)}.
131.1168 +     *
131.1169 +     * @return the value obtained by rotating the two's complement binary
131.1170 +     *     representation of the specified {@code int} value left by the
131.1171 +     *     specified number of bits.
131.1172 +     * @since 1.5
131.1173 +     */
131.1174 +    public static int rotateLeft(int i, int distance) {
131.1175 +        return (i << distance) | (i >>> -distance);
131.1176 +    }
131.1177 +
131.1178 +    /**
131.1179 +     * Returns the value obtained by rotating the two's complement binary
131.1180 +     * representation of the specified {@code int} value right by the
131.1181 +     * specified number of bits.  (Bits shifted out of the right hand, or
131.1182 +     * low-order, side reenter on the left, or high-order.)
131.1183 +     *
131.1184 +     * <p>Note that right rotation with a negative distance is equivalent to
131.1185 +     * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val,
131.1186 +     * distance)}.  Note also that rotation by any multiple of 32 is a
131.1187 +     * no-op, so all but the last five bits of the rotation distance can be
131.1188 +     * ignored, even if the distance is negative: {@code rotateRight(val,
131.1189 +     * distance) == rotateRight(val, distance & 0x1F)}.
131.1190 +     *
131.1191 +     * @return the value obtained by rotating the two's complement binary
131.1192 +     *     representation of the specified {@code int} value right by the
131.1193 +     *     specified number of bits.
131.1194 +     * @since 1.5
131.1195 +     */
131.1196 +    public static int rotateRight(int i, int distance) {
131.1197 +        return (i >>> distance) | (i << -distance);
131.1198 +    }
131.1199 +
131.1200 +    /**
131.1201 +     * Returns the value obtained by reversing the order of the bits in the
131.1202 +     * two's complement binary representation of the specified {@code int}
131.1203 +     * value.
131.1204 +     *
131.1205 +     * @return the value obtained by reversing order of the bits in the
131.1206 +     *     specified {@code int} value.
131.1207 +     * @since 1.5
131.1208 +     */
131.1209 +    public static int reverse(int i) {
131.1210 +        // HD, Figure 7-1
131.1211 +        i = (i & 0x55555555) << 1 | (i >>> 1) & 0x55555555;
131.1212 +        i = (i & 0x33333333) << 2 | (i >>> 2) & 0x33333333;
131.1213 +        i = (i & 0x0f0f0f0f) << 4 | (i >>> 4) & 0x0f0f0f0f;
131.1214 +        i = (i << 24) | ((i & 0xff00) << 8) |
131.1215 +            ((i >>> 8) & 0xff00) | (i >>> 24);
131.1216 +        return i;
131.1217 +    }
131.1218 +
131.1219 +    /**
131.1220 +     * Returns the signum function of the specified {@code int} value.  (The
131.1221 +     * return value is -1 if the specified value is negative; 0 if the
131.1222 +     * specified value is zero; and 1 if the specified value is positive.)
131.1223 +     *
131.1224 +     * @return the signum function of the specified {@code int} value.
131.1225 +     * @since 1.5
131.1226 +     */
131.1227 +    public static int signum(int i) {
131.1228 +        // HD, Section 2-7
131.1229 +        return (i >> 31) | (-i >>> 31);
131.1230 +    }
131.1231 +
131.1232 +    /**
131.1233 +     * Returns the value obtained by reversing the order of the bytes in the
131.1234 +     * two's complement representation of the specified {@code int} value.
131.1235 +     *
131.1236 +     * @return the value obtained by reversing the bytes in the specified
131.1237 +     *     {@code int} value.
131.1238 +     * @since 1.5
131.1239 +     */
131.1240 +    public static int reverseBytes(int i) {
131.1241 +        return ((i >>> 24)           ) |
131.1242 +               ((i >>   8) &   0xFF00) |
131.1243 +               ((i <<   8) & 0xFF0000) |
131.1244 +               ((i << 24));
131.1245 +    }
131.1246 +
131.1247 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
131.1248 +    private static final long serialVersionUID = 1360826667806852920L;
131.1249 +}
   132.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   132.2 +++ b/emul/mini/src/main/java/java/lang/InterruptedException.java	Sun Feb 03 07:48:42 2013 +0100
   132.3 @@ -0,0 +1,69 @@
   132.4 +/*
   132.5 + * Copyright (c) 1995, 2008, 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 when a thread is waiting, sleeping, or otherwise occupied,
  132.33 + * and the thread is interrupted, either before or during the activity.
  132.34 + * Occasionally a method may wish to test whether the current
  132.35 + * thread has been interrupted, and if so, to immediately throw
  132.36 + * this exception.  The following code can be used to achieve
  132.37 + * this effect:
  132.38 + * <pre>
  132.39 + *  if (Thread.interrupted())  // Clears interrupted status!
  132.40 + *      throw new InterruptedException();
  132.41 + * </pre>
  132.42 + *
  132.43 + * @author  Frank Yellin
  132.44 + * @see     java.lang.Object#wait()
  132.45 + * @see     java.lang.Object#wait(long)
  132.46 + * @see     java.lang.Object#wait(long, int)
  132.47 + * @see     java.lang.Thread#sleep(long)
  132.48 + * @see     java.lang.Thread#interrupt()
  132.49 + * @see     java.lang.Thread#interrupted()
  132.50 + * @since   JDK1.0
  132.51 + */
  132.52 +public
  132.53 +class InterruptedException extends Exception {
  132.54 +    private static final long serialVersionUID = 6700697376100628473L;
  132.55 +
  132.56 +    /**
  132.57 +     * Constructs an <code>InterruptedException</code> with no detail  message.
  132.58 +     */
  132.59 +    public InterruptedException() {
  132.60 +        super();
  132.61 +    }
  132.62 +
  132.63 +    /**
  132.64 +     * Constructs an <code>InterruptedException</code> with the
  132.65 +     * specified detail message.
  132.66 +     *
  132.67 +     * @param   s   the detail message.
  132.68 +     */
  132.69 +    public InterruptedException(String s) {
  132.70 +        super(s);
  132.71 +    }
  132.72 +}
   133.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   133.2 +++ b/emul/mini/src/main/java/java/lang/LinkageError.java	Sun Feb 03 07:48:42 2013 +0100
   133.3 @@ -0,0 +1,69 @@
   133.4 +/*
   133.5 + * Copyright (c) 1995, 2010, 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 + * Subclasses of {@code LinkageError} indicate that a class has
  133.33 + * some dependency on another class; however, the latter class has
  133.34 + * incompatibly changed after the compilation of the former class.
  133.35 + *
  133.36 + *
  133.37 + * @author  Frank Yellin
  133.38 + * @since   JDK1.0
  133.39 + */
  133.40 +public
  133.41 +class LinkageError extends Error {
  133.42 +    private static final long serialVersionUID = 3579600108157160122L;
  133.43 +
  133.44 +    /**
  133.45 +     * Constructs a {@code LinkageError} with no detail message.
  133.46 +     */
  133.47 +    public LinkageError() {
  133.48 +        super();
  133.49 +    }
  133.50 +
  133.51 +    /**
  133.52 +     * Constructs a {@code LinkageError} with the specified detail
  133.53 +     * message.
  133.54 +     *
  133.55 +     * @param   s   the detail message.
  133.56 +     */
  133.57 +    public LinkageError(String s) {
  133.58 +        super(s);
  133.59 +    }
  133.60 +
  133.61 +    /**
  133.62 +     * Constructs a {@code LinkageError} with the specified detail
  133.63 +     * message and cause.
  133.64 +     *
  133.65 +     * @param s     the detail message.
  133.66 +     * @param cause the cause, may be {@code null}
  133.67 +     * @since 1.7
  133.68 +     */
  133.69 +    public LinkageError(String s, Throwable cause) {
  133.70 +        super(s, cause);
  133.71 +    }
  133.72 +}
   134.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   134.2 +++ b/emul/mini/src/main/java/java/lang/Long.java	Sun Feb 03 07:48:42 2013 +0100
   134.3 @@ -0,0 +1,1202 @@
   134.4 +/*
   134.5 + * Copyright (c) 1994, 2009, 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 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  134.32 +
  134.33 +/**
  134.34 + * The {@code Long} class wraps a value of the primitive type {@code
  134.35 + * long} in an object. An object of type {@code Long} contains a
  134.36 + * single field whose type is {@code long}.
  134.37 + *
  134.38 + * <p> In addition, this class provides several methods for converting
  134.39 + * a {@code long} to a {@code String} and a {@code String} to a {@code
  134.40 + * long}, as well as other constants and methods useful when dealing
  134.41 + * with a {@code long}.
  134.42 + *
  134.43 + * <p>Implementation note: The implementations of the "bit twiddling"
  134.44 + * methods (such as {@link #highestOneBit(long) highestOneBit} and
  134.45 + * {@link #numberOfTrailingZeros(long) numberOfTrailingZeros}) are
  134.46 + * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  134.47 + * Delight</i>, (Addison Wesley, 2002).
  134.48 + *
  134.49 + * @author  Lee Boynton
  134.50 + * @author  Arthur van Hoff
  134.51 + * @author  Josh Bloch
  134.52 + * @author  Joseph D. Darcy
  134.53 + * @since   JDK1.0
  134.54 + */
  134.55 +public final class Long extends Number implements Comparable<Long> {
  134.56 +    /**
  134.57 +     * A constant holding the minimum value a {@code long} can
  134.58 +     * have, -2<sup>63</sup>.
  134.59 +     */
  134.60 +    public static final long MIN_VALUE = 0x8000000000000000L;
  134.61 +
  134.62 +    /**
  134.63 +     * A constant holding the maximum value a {@code long} can
  134.64 +     * have, 2<sup>63</sup>-1.
  134.65 +     */
  134.66 +    public static final long MAX_VALUE = 0x7fffffffffffffffL;
  134.67 +
  134.68 +    /**
  134.69 +     * The {@code Class} instance representing the primitive type
  134.70 +     * {@code long}.
  134.71 +     *
  134.72 +     * @since   JDK1.1
  134.73 +     */
  134.74 +    public static final Class<Long>     TYPE = (Class<Long>) Class.getPrimitiveClass("long");
  134.75 +
  134.76 +    /**
  134.77 +     * Returns a string representation of the first argument in the
  134.78 +     * radix specified by the second argument.
  134.79 +     *
  134.80 +     * <p>If the radix is smaller than {@code Character.MIN_RADIX}
  134.81 +     * or larger than {@code Character.MAX_RADIX}, then the radix
  134.82 +     * {@code 10} is used instead.
  134.83 +     *
  134.84 +     * <p>If the first argument is negative, the first element of the
  134.85 +     * result is the ASCII minus sign {@code '-'}
  134.86 +     * (<code>'&#92;u002d'</code>). If the first argument is not
  134.87 +     * negative, no sign character appears in the result.
  134.88 +     *
  134.89 +     * <p>The remaining characters of the result represent the magnitude
  134.90 +     * of the first argument. If the magnitude is zero, it is
  134.91 +     * represented by a single zero character {@code '0'}
  134.92 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
  134.93 +     * the representation of the magnitude will not be the zero
  134.94 +     * character.  The following ASCII characters are used as digits:
  134.95 +     *
  134.96 +     * <blockquote>
  134.97 +     *   {@code 0123456789abcdefghijklmnopqrstuvwxyz}
  134.98 +     * </blockquote>
  134.99 +     *
 134.100 +     * These are <code>'&#92;u0030'</code> through
 134.101 +     * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
 134.102 +     * <code>'&#92;u007a'</code>. If {@code radix} is
 134.103 +     * <var>N</var>, then the first <var>N</var> of these characters
 134.104 +     * are used as radix-<var>N</var> digits in the order shown. Thus,
 134.105 +     * the digits for hexadecimal (radix 16) are
 134.106 +     * {@code 0123456789abcdef}. If uppercase letters are
 134.107 +     * desired, the {@link java.lang.String#toUpperCase()} method may
 134.108 +     * be called on the result:
 134.109 +     *
 134.110 +     * <blockquote>
 134.111 +     *  {@code Long.toString(n, 16).toUpperCase()}
 134.112 +     * </blockquote>
 134.113 +     *
 134.114 +     * @param   i       a {@code long} to be converted to a string.
 134.115 +     * @param   radix   the radix to use in the string representation.
 134.116 +     * @return  a string representation of the argument in the specified radix.
 134.117 +     * @see     java.lang.Character#MAX_RADIX
 134.118 +     * @see     java.lang.Character#MIN_RADIX
 134.119 +     */
 134.120 +    public static String toString(long i, int radix) {
 134.121 +        if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
 134.122 +            radix = 10;
 134.123 +        if (radix == 10)
 134.124 +            return toString(i);
 134.125 +        char[] buf = new char[65];
 134.126 +        int charPos = 64;
 134.127 +        boolean negative = (i < 0);
 134.128 +
 134.129 +        if (!negative) {
 134.130 +            i = -i;
 134.131 +        }
 134.132 +
 134.133 +        while (i <= -radix) {
 134.134 +            buf[charPos--] = Integer.digits[(int)(-(i % radix))];
 134.135 +            i = i / radix;
 134.136 +        }
 134.137 +        buf[charPos] = Integer.digits[(int)(-i)];
 134.138 +
 134.139 +        if (negative) {
 134.140 +            buf[--charPos] = '-';
 134.141 +        }
 134.142 +
 134.143 +        return new String(buf, charPos, (65 - charPos));
 134.144 +    }
 134.145 +
 134.146 +    /**
 134.147 +     * Returns a string representation of the {@code long}
 134.148 +     * argument as an unsigned integer in base&nbsp;16.
 134.149 +     *
 134.150 +     * <p>The unsigned {@code long} value is the argument plus
 134.151 +     * 2<sup>64</sup> if the argument is negative; otherwise, it is
 134.152 +     * equal to the argument.  This value is converted to a string of
 134.153 +     * ASCII digits in hexadecimal (base&nbsp;16) with no extra
 134.154 +     * leading {@code 0}s.  If the unsigned magnitude is zero, it
 134.155 +     * is represented by a single zero character {@code '0'}
 134.156 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 134.157 +     * the representation of the unsigned magnitude will not be the
 134.158 +     * zero character. The following characters are used as
 134.159 +     * hexadecimal digits:
 134.160 +     *
 134.161 +     * <blockquote>
 134.162 +     *  {@code 0123456789abcdef}
 134.163 +     * </blockquote>
 134.164 +     *
 134.165 +     * These are the characters <code>'&#92;u0030'</code> through
 134.166 +     * <code>'&#92;u0039'</code> and  <code>'&#92;u0061'</code> through
 134.167 +     * <code>'&#92;u0066'</code>.  If uppercase letters are desired,
 134.168 +     * the {@link java.lang.String#toUpperCase()} method may be called
 134.169 +     * on the result:
 134.170 +     *
 134.171 +     * <blockquote>
 134.172 +     *  {@code Long.toHexString(n).toUpperCase()}
 134.173 +     * </blockquote>
 134.174 +     *
 134.175 +     * @param   i   a {@code long} to be converted to a string.
 134.176 +     * @return  the string representation of the unsigned {@code long}
 134.177 +     *          value represented by the argument in hexadecimal
 134.178 +     *          (base&nbsp;16).
 134.179 +     * @since   JDK 1.0.2
 134.180 +     */
 134.181 +    public static String toHexString(long i) {
 134.182 +        return toUnsignedString(i, 4);
 134.183 +    }
 134.184 +
 134.185 +    /**
 134.186 +     * Returns a string representation of the {@code long}
 134.187 +     * argument as an unsigned integer in base&nbsp;8.
 134.188 +     *
 134.189 +     * <p>The unsigned {@code long} value is the argument plus
 134.190 +     * 2<sup>64</sup> if the argument is negative; otherwise, it is
 134.191 +     * equal to the argument.  This value is converted to a string of
 134.192 +     * ASCII digits in octal (base&nbsp;8) with no extra leading
 134.193 +     * {@code 0}s.
 134.194 +     *
 134.195 +     * <p>If the unsigned magnitude is zero, it is represented by a
 134.196 +     * single zero character {@code '0'}
 134.197 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 134.198 +     * the representation of the unsigned magnitude will not be the
 134.199 +     * zero character. The following characters are used as octal
 134.200 +     * digits:
 134.201 +     *
 134.202 +     * <blockquote>
 134.203 +     *  {@code 01234567}
 134.204 +     * </blockquote>
 134.205 +     *
 134.206 +     * These are the characters <code>'&#92;u0030'</code> through
 134.207 +     * <code>'&#92;u0037'</code>.
 134.208 +     *
 134.209 +     * @param   i   a {@code long} to be converted to a string.
 134.210 +     * @return  the string representation of the unsigned {@code long}
 134.211 +     *          value represented by the argument in octal (base&nbsp;8).
 134.212 +     * @since   JDK 1.0.2
 134.213 +     */
 134.214 +    public static String toOctalString(long i) {
 134.215 +        return toUnsignedString(i, 3);
 134.216 +    }
 134.217 +
 134.218 +    /**
 134.219 +     * Returns a string representation of the {@code long}
 134.220 +     * argument as an unsigned integer in base&nbsp;2.
 134.221 +     *
 134.222 +     * <p>The unsigned {@code long} value is the argument plus
 134.223 +     * 2<sup>64</sup> if the argument is negative; otherwise, it is
 134.224 +     * equal to the argument.  This value is converted to a string of
 134.225 +     * ASCII digits in binary (base&nbsp;2) with no extra leading
 134.226 +     * {@code 0}s.  If the unsigned magnitude is zero, it is
 134.227 +     * represented by a single zero character {@code '0'}
 134.228 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 134.229 +     * the representation of the unsigned magnitude will not be the
 134.230 +     * zero character. The characters {@code '0'}
 134.231 +     * (<code>'&#92;u0030'</code>) and {@code '1'}
 134.232 +     * (<code>'&#92;u0031'</code>) are used as binary digits.
 134.233 +     *
 134.234 +     * @param   i   a {@code long} to be converted to a string.
 134.235 +     * @return  the string representation of the unsigned {@code long}
 134.236 +     *          value represented by the argument in binary (base&nbsp;2).
 134.237 +     * @since   JDK 1.0.2
 134.238 +     */
 134.239 +    public static String toBinaryString(long i) {
 134.240 +        return toUnsignedString(i, 1);
 134.241 +    }
 134.242 +
 134.243 +    /**
 134.244 +     * Convert the integer to an unsigned number.
 134.245 +     */
 134.246 +    private static String toUnsignedString(long i, int shift) {
 134.247 +        char[] buf = new char[64];
 134.248 +        int charPos = 64;
 134.249 +        int radix = 1 << shift;
 134.250 +        long mask = radix - 1;
 134.251 +        do {
 134.252 +            buf[--charPos] = Integer.digits[(int)(i & mask)];
 134.253 +            i >>>= shift;
 134.254 +        } while (i != 0);
 134.255 +        return new String(buf, charPos, (64 - charPos));
 134.256 +    }
 134.257 +
 134.258 +    /**
 134.259 +     * Returns a {@code String} object representing the specified
 134.260 +     * {@code long}.  The argument is converted to signed decimal
 134.261 +     * representation and returned as a string, exactly as if the
 134.262 +     * argument and the radix 10 were given as arguments to the {@link
 134.263 +     * #toString(long, int)} method.
 134.264 +     *
 134.265 +     * @param   i   a {@code long} to be converted.
 134.266 +     * @return  a string representation of the argument in base&nbsp;10.
 134.267 +     */
 134.268 +    @JavaScriptBody(args = "i", body = "return i.toString();")
 134.269 +    public static String toString(long i) {
 134.270 +        if (i == Long.MIN_VALUE)
 134.271 +            return "-9223372036854775808";
 134.272 +        int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
 134.273 +        char[] buf = new char[size];
 134.274 +        getChars(i, size, buf);
 134.275 +        return new String(buf, 0, size);
 134.276 +    }
 134.277 +
 134.278 +    /**
 134.279 +     * Places characters representing the integer i into the
 134.280 +     * character array buf. The characters are placed into
 134.281 +     * the buffer backwards starting with the least significant
 134.282 +     * digit at the specified index (exclusive), and working
 134.283 +     * backwards from there.
 134.284 +     *
 134.285 +     * Will fail if i == Long.MIN_VALUE
 134.286 +     */
 134.287 +    static void getChars(long i, int index, char[] buf) {
 134.288 +        long q;
 134.289 +        int r;
 134.290 +        int charPos = index;
 134.291 +        char sign = 0;
 134.292 +
 134.293 +        if (i < 0) {
 134.294 +            sign = '-';
 134.295 +            i = -i;
 134.296 +        }
 134.297 +
 134.298 +        // Get 2 digits/iteration using longs until quotient fits into an int
 134.299 +        while (i > Integer.MAX_VALUE) {
 134.300 +            q = i / 100;
 134.301 +            // really: r = i - (q * 100);
 134.302 +            r = (int)(i - ((q << 6) + (q << 5) + (q << 2)));
 134.303 +            i = q;
 134.304 +            buf[--charPos] = Integer.DigitOnes[r];
 134.305 +            buf[--charPos] = Integer.DigitTens[r];
 134.306 +        }
 134.307 +
 134.308 +        // Get 2 digits/iteration using ints
 134.309 +        int q2;
 134.310 +        int i2 = (int)i;
 134.311 +        while (i2 >= 65536) {
 134.312 +            q2 = i2 / 100;
 134.313 +            // really: r = i2 - (q * 100);
 134.314 +            r = i2 - ((q2 << 6) + (q2 << 5) + (q2 << 2));
 134.315 +            i2 = q2;
 134.316 +            buf[--charPos] = Integer.DigitOnes[r];
 134.317 +            buf[--charPos] = Integer.DigitTens[r];
 134.318 +        }
 134.319 +
 134.320 +        // Fall thru to fast mode for smaller numbers
 134.321 +        // assert(i2 <= 65536, i2);
 134.322 +        for (;;) {
 134.323 +            q2 = (i2 * 52429) >>> (16+3);
 134.324 +            r = i2 - ((q2 << 3) + (q2 << 1));  // r = i2-(q2*10) ...
 134.325 +            buf[--charPos] = Integer.digits[r];
 134.326 +            i2 = q2;
 134.327 +            if (i2 == 0) break;
 134.328 +        }
 134.329 +        if (sign != 0) {
 134.330 +            buf[--charPos] = sign;
 134.331 +        }
 134.332 +    }
 134.333 +
 134.334 +    // Requires positive x
 134.335 +    static int stringSize(long x) {
 134.336 +        long p = 10;
 134.337 +        for (int i=1; i<19; i++) {
 134.338 +            if (x < p)
 134.339 +                return i;
 134.340 +            p = 10*p;
 134.341 +        }
 134.342 +        return 19;
 134.343 +    }
 134.344 +
 134.345 +    /**
 134.346 +     * Parses the string argument as a signed {@code long} in the
 134.347 +     * radix specified by the second argument. The characters in the
 134.348 +     * string must all be digits of the specified radix (as determined
 134.349 +     * by whether {@link java.lang.Character#digit(char, int)} returns
 134.350 +     * a nonnegative value), except that the first character may be an
 134.351 +     * ASCII minus sign {@code '-'} (<code>'&#92;u002D'</code>) to
 134.352 +     * indicate a negative value or an ASCII plus sign {@code '+'}
 134.353 +     * (<code>'&#92;u002B'</code>) to indicate a positive value. The
 134.354 +     * resulting {@code long} value is returned.
 134.355 +     *
 134.356 +     * <p>Note that neither the character {@code L}
 134.357 +     * (<code>'&#92;u004C'</code>) nor {@code l}
 134.358 +     * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 134.359 +     * of the string as a type indicator, as would be permitted in
 134.360 +     * Java programming language source code - except that either
 134.361 +     * {@code L} or {@code l} may appear as a digit for a
 134.362 +     * radix greater than 22.
 134.363 +     *
 134.364 +     * <p>An exception of type {@code NumberFormatException} is
 134.365 +     * thrown if any of the following situations occurs:
 134.366 +     * <ul>
 134.367 +     *
 134.368 +     * <li>The first argument is {@code null} or is a string of
 134.369 +     * length zero.
 134.370 +     *
 134.371 +     * <li>The {@code radix} is either smaller than {@link
 134.372 +     * java.lang.Character#MIN_RADIX} or larger than {@link
 134.373 +     * java.lang.Character#MAX_RADIX}.
 134.374 +     *
 134.375 +     * <li>Any character of the string is not a digit of the specified
 134.376 +     * radix, except that the first character may be a minus sign
 134.377 +     * {@code '-'} (<code>'&#92;u002d'</code>) or plus sign {@code
 134.378 +     * '+'} (<code>'&#92;u002B'</code>) provided that the string is
 134.379 +     * longer than length 1.
 134.380 +     *
 134.381 +     * <li>The value represented by the string is not a value of type
 134.382 +     *      {@code long}.
 134.383 +     * </ul>
 134.384 +     *
 134.385 +     * <p>Examples:
 134.386 +     * <blockquote><pre>
 134.387 +     * parseLong("0", 10) returns 0L
 134.388 +     * parseLong("473", 10) returns 473L
 134.389 +     * parseLong("+42", 10) returns 42L
 134.390 +     * parseLong("-0", 10) returns 0L
 134.391 +     * parseLong("-FF", 16) returns -255L
 134.392 +     * parseLong("1100110", 2) returns 102L
 134.393 +     * parseLong("99", 8) throws a NumberFormatException
 134.394 +     * parseLong("Hazelnut", 10) throws a NumberFormatException
 134.395 +     * parseLong("Hazelnut", 36) returns 1356099454469L
 134.396 +     * </pre></blockquote>
 134.397 +     *
 134.398 +     * @param      s       the {@code String} containing the
 134.399 +     *                     {@code long} representation to be parsed.
 134.400 +     * @param      radix   the radix to be used while parsing {@code s}.
 134.401 +     * @return     the {@code long} represented by the string argument in
 134.402 +     *             the specified radix.
 134.403 +     * @throws     NumberFormatException  if the string does not contain a
 134.404 +     *             parsable {@code long}.
 134.405 +     */
 134.406 +    public static long parseLong(String s, int radix)
 134.407 +              throws NumberFormatException
 134.408 +    {
 134.409 +        if (s == null) {
 134.410 +            throw new NumberFormatException("null");
 134.411 +        }
 134.412 +
 134.413 +        if (radix < Character.MIN_RADIX) {
 134.414 +            throw new NumberFormatException("radix " + radix +
 134.415 +                                            " less than Character.MIN_RADIX");
 134.416 +        }
 134.417 +        if (radix > Character.MAX_RADIX) {
 134.418 +            throw new NumberFormatException("radix " + radix +
 134.419 +                                            " greater than Character.MAX_RADIX");
 134.420 +        }
 134.421 +
 134.422 +        long result = 0;
 134.423 +        boolean negative = false;
 134.424 +        int i = 0, len = s.length();
 134.425 +        long limit = -Long.MAX_VALUE;
 134.426 +        long multmin;
 134.427 +        int digit;
 134.428 +
 134.429 +        if (len > 0) {
 134.430 +            char firstChar = s.charAt(0);
 134.431 +            if (firstChar < '0') { // Possible leading "+" or "-"
 134.432 +                if (firstChar == '-') {
 134.433 +                    negative = true;
 134.434 +                    limit = Long.MIN_VALUE;
 134.435 +                } else if (firstChar != '+')
 134.436 +                    throw NumberFormatException.forInputString(s);
 134.437 +
 134.438 +                if (len == 1) // Cannot have lone "+" or "-"
 134.439 +                    throw NumberFormatException.forInputString(s);
 134.440 +                i++;
 134.441 +            }
 134.442 +            multmin = limit / radix;
 134.443 +            while (i < len) {
 134.444 +                // Accumulating negatively avoids surprises near MAX_VALUE
 134.445 +                digit = Character.digit(s.charAt(i++),radix);
 134.446 +                if (digit < 0) {
 134.447 +                    throw NumberFormatException.forInputString(s);
 134.448 +                }
 134.449 +                if (result < multmin) {
 134.450 +                    throw NumberFormatException.forInputString(s);
 134.451 +                }
 134.452 +                result *= radix;
 134.453 +                if (result < limit + digit) {
 134.454 +                    throw NumberFormatException.forInputString(s);
 134.455 +                }
 134.456 +                result -= digit;
 134.457 +            }
 134.458 +        } else {
 134.459 +            throw NumberFormatException.forInputString(s);
 134.460 +        }
 134.461 +        return negative ? result : -result;
 134.462 +    }
 134.463 +
 134.464 +    /**
 134.465 +     * Parses the string argument as a signed decimal {@code long}.
 134.466 +     * The characters in the string must all be decimal digits, except
 134.467 +     * that the first character may be an ASCII minus sign {@code '-'}
 134.468 +     * (<code>&#92;u002D'</code>) to indicate a negative value or an
 134.469 +     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
 134.470 +     * indicate a positive value. The resulting {@code long} value is
 134.471 +     * returned, exactly as if the argument and the radix {@code 10}
 134.472 +     * were given as arguments to the {@link
 134.473 +     * #parseLong(java.lang.String, int)} method.
 134.474 +     *
 134.475 +     * <p>Note that neither the character {@code L}
 134.476 +     * (<code>'&#92;u004C'</code>) nor {@code l}
 134.477 +     * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 134.478 +     * of the string as a type indicator, as would be permitted in
 134.479 +     * Java programming language source code.
 134.480 +     *
 134.481 +     * @param      s   a {@code String} containing the {@code long}
 134.482 +     *             representation to be parsed
 134.483 +     * @return     the {@code long} represented by the argument in
 134.484 +     *             decimal.
 134.485 +     * @throws     NumberFormatException  if the string does not contain a
 134.486 +     *             parsable {@code long}.
 134.487 +     */
 134.488 +    public static long parseLong(String s) throws NumberFormatException {
 134.489 +        return parseLong(s, 10);
 134.490 +    }
 134.491 +
 134.492 +    /**
 134.493 +     * Returns a {@code Long} object holding the value
 134.494 +     * extracted from the specified {@code String} when parsed
 134.495 +     * with the radix given by the second argument.  The first
 134.496 +     * argument is interpreted as representing a signed
 134.497 +     * {@code long} in the radix specified by the second
 134.498 +     * argument, exactly as if the arguments were given to the {@link
 134.499 +     * #parseLong(java.lang.String, int)} method. The result is a
 134.500 +     * {@code Long} object that represents the {@code long}
 134.501 +     * value specified by the string.
 134.502 +     *
 134.503 +     * <p>In other words, this method returns a {@code Long} object equal
 134.504 +     * to the value of:
 134.505 +     *
 134.506 +     * <blockquote>
 134.507 +     *  {@code new Long(Long.parseLong(s, radix))}
 134.508 +     * </blockquote>
 134.509 +     *
 134.510 +     * @param      s       the string to be parsed
 134.511 +     * @param      radix   the radix to be used in interpreting {@code s}
 134.512 +     * @return     a {@code Long} object holding the value
 134.513 +     *             represented by the string argument in the specified
 134.514 +     *             radix.
 134.515 +     * @throws     NumberFormatException  If the {@code String} does not
 134.516 +     *             contain a parsable {@code long}.
 134.517 +     */
 134.518 +    public static Long valueOf(String s, int radix) throws NumberFormatException {
 134.519 +        return Long.valueOf(parseLong(s, radix));
 134.520 +    }
 134.521 +
 134.522 +    /**
 134.523 +     * Returns a {@code Long} object holding the value
 134.524 +     * of the specified {@code String}. The argument is
 134.525 +     * interpreted as representing a signed decimal {@code long},
 134.526 +     * exactly as if the argument were given to the {@link
 134.527 +     * #parseLong(java.lang.String)} method. The result is a
 134.528 +     * {@code Long} object that represents the integer value
 134.529 +     * specified by the string.
 134.530 +     *
 134.531 +     * <p>In other words, this method returns a {@code Long} object
 134.532 +     * equal to the value of:
 134.533 +     *
 134.534 +     * <blockquote>
 134.535 +     *  {@code new Long(Long.parseLong(s))}
 134.536 +     * </blockquote>
 134.537 +     *
 134.538 +     * @param      s   the string to be parsed.
 134.539 +     * @return     a {@code Long} object holding the value
 134.540 +     *             represented by the string argument.
 134.541 +     * @throws     NumberFormatException  If the string cannot be parsed
 134.542 +     *             as a {@code long}.
 134.543 +     */
 134.544 +    public static Long valueOf(String s) throws NumberFormatException
 134.545 +    {
 134.546 +        return Long.valueOf(parseLong(s, 10));
 134.547 +    }
 134.548 +
 134.549 +    private static class LongCache {
 134.550 +        private LongCache(){}
 134.551 +
 134.552 +        static final Long cache[] = new Long[-(-128) + 127 + 1];
 134.553 +
 134.554 +        static {
 134.555 +            for(int i = 0; i < cache.length; i++)
 134.556 +                cache[i] = new Long(i - 128);
 134.557 +        }
 134.558 +    }
 134.559 +
 134.560 +    /**
 134.561 +     * Returns a {@code Long} instance representing the specified
 134.562 +     * {@code long} value.
 134.563 +     * If a new {@code Long} instance is not required, this method
 134.564 +     * should generally be used in preference to the constructor
 134.565 +     * {@link #Long(long)}, as this method is likely to yield
 134.566 +     * significantly better space and time performance by caching
 134.567 +     * frequently requested values.
 134.568 +     *
 134.569 +     * Note that unlike the {@linkplain Integer#valueOf(int)
 134.570 +     * corresponding method} in the {@code Integer} class, this method
 134.571 +     * is <em>not</em> required to cache values within a particular
 134.572 +     * range.
 134.573 +     *
 134.574 +     * @param  l a long value.
 134.575 +     * @return a {@code Long} instance representing {@code l}.
 134.576 +     * @since  1.5
 134.577 +     */
 134.578 +    public static Long valueOf(long l) {
 134.579 +        final int offset = 128;
 134.580 +        if (l >= -128 && l <= 127) { // will cache
 134.581 +            return LongCache.cache[(int)l + offset];
 134.582 +        }
 134.583 +        return new Long(l);
 134.584 +    }
 134.585 +
 134.586 +    /**
 134.587 +     * Decodes a {@code String} into a {@code Long}.
 134.588 +     * Accepts decimal, hexadecimal, and octal numbers given by the
 134.589 +     * following grammar:
 134.590 +     *
 134.591 +     * <blockquote>
 134.592 +     * <dl>
 134.593 +     * <dt><i>DecodableString:</i>
 134.594 +     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 134.595 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 134.596 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 134.597 +     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 134.598 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 134.599 +     * <p>
 134.600 +     * <dt><i>Sign:</i>
 134.601 +     * <dd>{@code -}
 134.602 +     * <dd>{@code +}
 134.603 +     * </dl>
 134.604 +     * </blockquote>
 134.605 +     *
 134.606 +     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 134.607 +     * are as defined in section 3.10.1 of
 134.608 +     * <cite>The Java&trade; Language Specification</cite>,
 134.609 +     * except that underscores are not accepted between digits.
 134.610 +     *
 134.611 +     * <p>The sequence of characters following an optional
 134.612 +     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 134.613 +     * "{@code #}", or leading zero) is parsed as by the {@code
 134.614 +     * Long.parseLong} method with the indicated radix (10, 16, or 8).
 134.615 +     * This sequence of characters must represent a positive value or
 134.616 +     * a {@link NumberFormatException} will be thrown.  The result is
 134.617 +     * negated if first character of the specified {@code String} is
 134.618 +     * the minus sign.  No whitespace characters are permitted in the
 134.619 +     * {@code String}.
 134.620 +     *
 134.621 +     * @param     nm the {@code String} to decode.
 134.622 +     * @return    a {@code Long} object holding the {@code long}
 134.623 +     *            value represented by {@code nm}
 134.624 +     * @throws    NumberFormatException  if the {@code String} does not
 134.625 +     *            contain a parsable {@code long}.
 134.626 +     * @see java.lang.Long#parseLong(String, int)
 134.627 +     * @since 1.2
 134.628 +     */
 134.629 +    public static Long decode(String nm) throws NumberFormatException {
 134.630 +        int radix = 10;
 134.631 +        int index = 0;
 134.632 +        boolean negative = false;
 134.633 +        Long result;
 134.634 +
 134.635 +        if (nm.length() == 0)
 134.636 +            throw new NumberFormatException("Zero length string");
 134.637 +        char firstChar = nm.charAt(0);
 134.638 +        // Handle sign, if present
 134.639 +        if (firstChar == '-') {
 134.640 +            negative = true;
 134.641 +            index++;
 134.642 +        } else if (firstChar == '+')
 134.643 +            index++;
 134.644 +
 134.645 +        // Handle radix specifier, if present
 134.646 +        if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
 134.647 +            index += 2;
 134.648 +            radix = 16;
 134.649 +        }
 134.650 +        else if (nm.startsWith("#", index)) {
 134.651 +            index ++;
 134.652 +            radix = 16;
 134.653 +        }
 134.654 +        else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
 134.655 +            index ++;
 134.656 +            radix = 8;
 134.657 +        }
 134.658 +
 134.659 +        if (nm.startsWith("-", index) || nm.startsWith("+", index))
 134.660 +            throw new NumberFormatException("Sign character in wrong position");
 134.661 +
 134.662 +        try {
 134.663 +            result = Long.valueOf(nm.substring(index), radix);
 134.664 +            result = negative ? Long.valueOf(-result.longValue()) : result;
 134.665 +        } catch (NumberFormatException e) {
 134.666 +            // If number is Long.MIN_VALUE, we'll end up here. The next line
 134.667 +            // handles this case, and causes any genuine format error to be
 134.668 +            // rethrown.
 134.669 +            String constant = negative ? ("-" + nm.substring(index))
 134.670 +                                       : nm.substring(index);
 134.671 +            result = Long.valueOf(constant, radix);
 134.672 +        }
 134.673 +        return result;
 134.674 +    }
 134.675 +
 134.676 +    /**
 134.677 +     * The value of the {@code Long}.
 134.678 +     *
 134.679 +     * @serial
 134.680 +     */
 134.681 +    private final long value;
 134.682 +
 134.683 +    /**
 134.684 +     * Constructs a newly allocated {@code Long} object that
 134.685 +     * represents the specified {@code long} argument.
 134.686 +     *
 134.687 +     * @param   value   the value to be represented by the
 134.688 +     *          {@code Long} object.
 134.689 +     */
 134.690 +    public Long(long value) {
 134.691 +        this.value = value;
 134.692 +    }
 134.693 +
 134.694 +    /**
 134.695 +     * Constructs a newly allocated {@code Long} object that
 134.696 +     * represents the {@code long} value indicated by the
 134.697 +     * {@code String} parameter. The string is converted to a
 134.698 +     * {@code long} value in exactly the manner used by the
 134.699 +     * {@code parseLong} method for radix 10.
 134.700 +     *
 134.701 +     * @param      s   the {@code String} to be converted to a
 134.702 +     *             {@code Long}.
 134.703 +     * @throws     NumberFormatException  if the {@code String} does not
 134.704 +     *             contain a parsable {@code long}.
 134.705 +     * @see        java.lang.Long#parseLong(java.lang.String, int)
 134.706 +     */
 134.707 +    public Long(String s) throws NumberFormatException {
 134.708 +        this.value = parseLong(s, 10);
 134.709 +    }
 134.710 +
 134.711 +    /**
 134.712 +     * Returns the value of this {@code Long} as a
 134.713 +     * {@code byte}.
 134.714 +     */
 134.715 +    public byte byteValue() {
 134.716 +        return (byte)value;
 134.717 +    }
 134.718 +
 134.719 +    /**
 134.720 +     * Returns the value of this {@code Long} as a
 134.721 +     * {@code short}.
 134.722 +     */
 134.723 +    public short shortValue() {
 134.724 +        return (short)value;
 134.725 +    }
 134.726 +
 134.727 +    /**
 134.728 +     * Returns the value of this {@code Long} as an
 134.729 +     * {@code int}.
 134.730 +     */
 134.731 +    public int intValue() {
 134.732 +        return (int)value;
 134.733 +    }
 134.734 +
 134.735 +    /**
 134.736 +     * Returns the value of this {@code Long} as a
 134.737 +     * {@code long} value.
 134.738 +     */
 134.739 +    public long longValue() {
 134.740 +        return (long)value;
 134.741 +    }
 134.742 +
 134.743 +    /**
 134.744 +     * Returns the value of this {@code Long} as a
 134.745 +     * {@code float}.
 134.746 +     */
 134.747 +    public float floatValue() {
 134.748 +        return (float)value;
 134.749 +    }
 134.750 +
 134.751 +    /**
 134.752 +     * Returns the value of this {@code Long} as a
 134.753 +     * {@code double}.
 134.754 +     */
 134.755 +    public double doubleValue() {
 134.756 +        return (double)value;
 134.757 +    }
 134.758 +
 134.759 +    /**
 134.760 +     * Returns a {@code String} object representing this
 134.761 +     * {@code Long}'s value.  The value is converted to signed
 134.762 +     * decimal representation and returned as a string, exactly as if
 134.763 +     * the {@code long} value were given as an argument to the
 134.764 +     * {@link java.lang.Long#toString(long)} method.
 134.765 +     *
 134.766 +     * @return  a string representation of the value of this object in
 134.767 +     *          base&nbsp;10.
 134.768 +     */
 134.769 +    public String toString() {
 134.770 +        return toString(value);
 134.771 +    }
 134.772 +
 134.773 +    /**
 134.774 +     * Returns a hash code for this {@code Long}. The result is
 134.775 +     * the exclusive OR of the two halves of the primitive
 134.776 +     * {@code long} value held by this {@code Long}
 134.777 +     * object. That is, the hashcode is the value of the expression:
 134.778 +     *
 134.779 +     * <blockquote>
 134.780 +     *  {@code (int)(this.longValue()^(this.longValue()>>>32))}
 134.781 +     * </blockquote>
 134.782 +     *
 134.783 +     * @return  a hash code value for this object.
 134.784 +     */
 134.785 +    public int hashCode() {
 134.786 +        return (int)(value ^ (value >>> 32));
 134.787 +    }
 134.788 +
 134.789 +    /**
 134.790 +     * Compares this object to the specified object.  The result is
 134.791 +     * {@code true} if and only if the argument is not
 134.792 +     * {@code null} and is a {@code Long} object that
 134.793 +     * contains the same {@code long} value as this object.
 134.794 +     *
 134.795 +     * @param   obj   the object to compare with.
 134.796 +     * @return  {@code true} if the objects are the same;
 134.797 +     *          {@code false} otherwise.
 134.798 +     */
 134.799 +    public boolean equals(Object obj) {
 134.800 +        if (obj instanceof Long) {
 134.801 +            return value == ((Long)obj).longValue();
 134.802 +        }
 134.803 +        return false;
 134.804 +    }
 134.805 +
 134.806 +    /**
 134.807 +     * Determines the {@code long} value of the system property
 134.808 +     * with the specified name.
 134.809 +     *
 134.810 +     * <p>The first argument is treated as the name of a system property.
 134.811 +     * System properties are accessible through the {@link
 134.812 +     * java.lang.System#getProperty(java.lang.String)} method. The
 134.813 +     * string value of this property is then interpreted as a
 134.814 +     * {@code long} value and a {@code Long} object
 134.815 +     * representing this value is returned.  Details of possible
 134.816 +     * numeric formats can be found with the definition of
 134.817 +     * {@code getProperty}.
 134.818 +     *
 134.819 +     * <p>If there is no property with the specified name, if the
 134.820 +     * specified name is empty or {@code null}, or if the
 134.821 +     * property does not have the correct numeric format, then
 134.822 +     * {@code null} is returned.
 134.823 +     *
 134.824 +     * <p>In other words, this method returns a {@code Long} object equal to
 134.825 +     * the value of:
 134.826 +     *
 134.827 +     * <blockquote>
 134.828 +     *  {@code getLong(nm, null)}
 134.829 +     * </blockquote>
 134.830 +     *
 134.831 +     * @param   nm   property name.
 134.832 +     * @return  the {@code Long} value of the property.
 134.833 +     * @see     java.lang.System#getProperty(java.lang.String)
 134.834 +     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 134.835 +     */
 134.836 +    public static Long getLong(String nm) {
 134.837 +        return getLong(nm, null);
 134.838 +    }
 134.839 +
 134.840 +    /**
 134.841 +     * Determines the {@code long} value of the system property
 134.842 +     * with the specified name.
 134.843 +     *
 134.844 +     * <p>The first argument is treated as the name of a system property.
 134.845 +     * System properties are accessible through the {@link
 134.846 +     * java.lang.System#getProperty(java.lang.String)} method. The
 134.847 +     * string value of this property is then interpreted as a
 134.848 +     * {@code long} value and a {@code Long} object
 134.849 +     * representing this value is returned.  Details of possible
 134.850 +     * numeric formats can be found with the definition of
 134.851 +     * {@code getProperty}.
 134.852 +     *
 134.853 +     * <p>The second argument is the default value. A {@code Long} object
 134.854 +     * that represents the value of the second argument is returned if there
 134.855 +     * is no property of the specified name, if the property does not have
 134.856 +     * the correct numeric format, or if the specified name is empty or null.
 134.857 +     *
 134.858 +     * <p>In other words, this method returns a {@code Long} object equal
 134.859 +     * to the value of:
 134.860 +     *
 134.861 +     * <blockquote>
 134.862 +     *  {@code getLong(nm, new Long(val))}
 134.863 +     * </blockquote>
 134.864 +     *
 134.865 +     * but in practice it may be implemented in a manner such as:
 134.866 +     *
 134.867 +     * <blockquote><pre>
 134.868 +     * Long result = getLong(nm, null);
 134.869 +     * return (result == null) ? new Long(val) : result;
 134.870 +     * </pre></blockquote>
 134.871 +     *
 134.872 +     * to avoid the unnecessary allocation of a {@code Long} object when
 134.873 +     * the default value is not needed.
 134.874 +     *
 134.875 +     * @param   nm    property name.
 134.876 +     * @param   val   default value.
 134.877 +     * @return  the {@code Long} value of the property.
 134.878 +     * @see     java.lang.System#getProperty(java.lang.String)
 134.879 +     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 134.880 +     */
 134.881 +    public static Long getLong(String nm, long val) {
 134.882 +        Long result = Long.getLong(nm, null);
 134.883 +        return (result == null) ? Long.valueOf(val) : result;
 134.884 +    }
 134.885 +
 134.886 +    /**
 134.887 +     * Returns the {@code long} value of the system property with
 134.888 +     * the specified name.  The first argument is treated as the name
 134.889 +     * of a system property.  System properties are accessible through
 134.890 +     * the {@link java.lang.System#getProperty(java.lang.String)}
 134.891 +     * method. The string value of this property is then interpreted
 134.892 +     * as a {@code long} value, as per the
 134.893 +     * {@code Long.decode} method, and a {@code Long} object
 134.894 +     * representing this value is returned.
 134.895 +     *
 134.896 +     * <ul>
 134.897 +     * <li>If the property value begins with the two ASCII characters
 134.898 +     * {@code 0x} or the ASCII character {@code #}, not followed by
 134.899 +     * a minus sign, then the rest of it is parsed as a hexadecimal integer
 134.900 +     * exactly as for the method {@link #valueOf(java.lang.String, int)}
 134.901 +     * with radix 16.
 134.902 +     * <li>If the property value begins with the ASCII character
 134.903 +     * {@code 0} followed by another character, it is parsed as
 134.904 +     * an octal integer exactly as by the method {@link
 134.905 +     * #valueOf(java.lang.String, int)} with radix 8.
 134.906 +     * <li>Otherwise the property value is parsed as a decimal
 134.907 +     * integer exactly as by the method
 134.908 +     * {@link #valueOf(java.lang.String, int)} with radix 10.
 134.909 +     * </ul>
 134.910 +     *
 134.911 +     * <p>Note that, in every case, neither {@code L}
 134.912 +     * (<code>'&#92;u004C'</code>) nor {@code l}
 134.913 +     * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 134.914 +     * of the property value as a type indicator, as would be
 134.915 +     * permitted in Java programming language source code.
 134.916 +     *
 134.917 +     * <p>The second argument is the default value. The default value is
 134.918 +     * returned if there is no property of the specified name, if the
 134.919 +     * property does not have the correct numeric format, or if the
 134.920 +     * specified name is empty or {@code null}.
 134.921 +     *
 134.922 +     * @param   nm   property name.
 134.923 +     * @param   val   default value.
 134.924 +     * @return  the {@code Long} value of the property.
 134.925 +     * @see     java.lang.System#getProperty(java.lang.String)
 134.926 +     * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
 134.927 +     * @see java.lang.Long#decode
 134.928 +     */
 134.929 +    public static Long getLong(String nm, Long val) {
 134.930 +        String v = null;
 134.931 +        try {
 134.932 +            v = AbstractStringBuilder.getProperty(nm);
 134.933 +        } catch (IllegalArgumentException e) {
 134.934 +        } catch (NullPointerException e) {
 134.935 +        }
 134.936 +        if (v != null) {
 134.937 +            try {
 134.938 +                return Long.decode(v);
 134.939 +            } catch (NumberFormatException e) {
 134.940 +            }
 134.941 +        }
 134.942 +        return val;
 134.943 +    }
 134.944 +
 134.945 +    /**
 134.946 +     * Compares two {@code Long} objects numerically.
 134.947 +     *
 134.948 +     * @param   anotherLong   the {@code Long} to be compared.
 134.949 +     * @return  the value {@code 0} if this {@code Long} is
 134.950 +     *          equal to the argument {@code Long}; a value less than
 134.951 +     *          {@code 0} if this {@code Long} is numerically less
 134.952 +     *          than the argument {@code Long}; and a value greater
 134.953 +     *          than {@code 0} if this {@code Long} is numerically
 134.954 +     *           greater than the argument {@code Long} (signed
 134.955 +     *           comparison).
 134.956 +     * @since   1.2
 134.957 +     */
 134.958 +    public int compareTo(Long anotherLong) {
 134.959 +        return compare(this.value, anotherLong.value);
 134.960 +    }
 134.961 +
 134.962 +    /**
 134.963 +     * Compares two {@code long} values numerically.
 134.964 +     * The value returned is identical to what would be returned by:
 134.965 +     * <pre>
 134.966 +     *    Long.valueOf(x).compareTo(Long.valueOf(y))
 134.967 +     * </pre>
 134.968 +     *
 134.969 +     * @param  x the first {@code long} to compare
 134.970 +     * @param  y the second {@code long} to compare
 134.971 +     * @return the value {@code 0} if {@code x == y};
 134.972 +     *         a value less than {@code 0} if {@code x < y}; and
 134.973 +     *         a value greater than {@code 0} if {@code x > y}
 134.974 +     * @since 1.7
 134.975 +     */
 134.976 +    public static int compare(long x, long y) {
 134.977 +        return (x < y) ? -1 : ((x == y) ? 0 : 1);
 134.978 +    }
 134.979 +
 134.980 +
 134.981 +    // Bit Twiddling
 134.982 +
 134.983 +    /**
 134.984 +     * The number of bits used to represent a {@code long} value in two's
 134.985 +     * complement binary form.
 134.986 +     *
 134.987 +     * @since 1.5
 134.988 +     */
 134.989 +    public static final int SIZE = 64;
 134.990 +
 134.991 +    /**
 134.992 +     * Returns a {@code long} value with at most a single one-bit, in the
 134.993 +     * position of the highest-order ("leftmost") one-bit in the specified
 134.994 +     * {@code long} value.  Returns zero if the specified value has no
 134.995 +     * one-bits in its two's complement binary representation, that is, if it
 134.996 +     * is equal to zero.
 134.997 +     *
 134.998 +     * @return a {@code long} value with a single one-bit, in the position
 134.999 +     *     of the highest-order one-bit in the specified value, or zero if
134.1000 +     *     the specified value is itself equal to zero.
134.1001 +     * @since 1.5
134.1002 +     */
134.1003 +    public static long highestOneBit(long i) {
134.1004 +        // HD, Figure 3-1
134.1005 +        i |= (i >>  1);
134.1006 +        i |= (i >>  2);
134.1007 +        i |= (i >>  4);
134.1008 +        i |= (i >>  8);
134.1009 +        i |= (i >> 16);
134.1010 +        i |= (i >> 32);
134.1011 +        return i - (i >>> 1);
134.1012 +    }
134.1013 +
134.1014 +    /**
134.1015 +     * Returns a {@code long} value with at most a single one-bit, in the
134.1016 +     * position of the lowest-order ("rightmost") one-bit in the specified
134.1017 +     * {@code long} value.  Returns zero if the specified value has no
134.1018 +     * one-bits in its two's complement binary representation, that is, if it
134.1019 +     * is equal to zero.
134.1020 +     *
134.1021 +     * @return a {@code long} value with a single one-bit, in the position
134.1022 +     *     of the lowest-order one-bit in the specified value, or zero if
134.1023 +     *     the specified value is itself equal to zero.
134.1024 +     * @since 1.5
134.1025 +     */
134.1026 +    public static long lowestOneBit(long i) {
134.1027 +        // HD, Section 2-1
134.1028 +        return i & -i;
134.1029 +    }
134.1030 +
134.1031 +    /**
134.1032 +     * Returns the number of zero bits preceding the highest-order
134.1033 +     * ("leftmost") one-bit in the two's complement binary representation
134.1034 +     * of the specified {@code long} value.  Returns 64 if the
134.1035 +     * specified value has no one-bits in its two's complement representation,
134.1036 +     * in other words if it is equal to zero.
134.1037 +     *
134.1038 +     * <p>Note that this method is closely related to the logarithm base 2.
134.1039 +     * For all positive {@code long} values x:
134.1040 +     * <ul>
134.1041 +     * <li>floor(log<sub>2</sub>(x)) = {@code 63 - numberOfLeadingZeros(x)}
134.1042 +     * <li>ceil(log<sub>2</sub>(x)) = {@code 64 - numberOfLeadingZeros(x - 1)}
134.1043 +     * </ul>
134.1044 +     *
134.1045 +     * @return the number of zero bits preceding the highest-order
134.1046 +     *     ("leftmost") one-bit in the two's complement binary representation
134.1047 +     *     of the specified {@code long} value, or 64 if the value
134.1048 +     *     is equal to zero.
134.1049 +     * @since 1.5
134.1050 +     */
134.1051 +    public static int numberOfLeadingZeros(long i) {
134.1052 +        // HD, Figure 5-6
134.1053 +         if (i == 0)
134.1054 +            return 64;
134.1055 +        int n = 1;
134.1056 +        int x = (int)(i >>> 32);
134.1057 +        if (x == 0) { n += 32; x = (int)i; }
134.1058 +        if (x >>> 16 == 0) { n += 16; x <<= 16; }
134.1059 +        if (x >>> 24 == 0) { n +=  8; x <<=  8; }
134.1060 +        if (x >>> 28 == 0) { n +=  4; x <<=  4; }
134.1061 +        if (x >>> 30 == 0) { n +=  2; x <<=  2; }
134.1062 +        n -= x >>> 31;
134.1063 +        return n;
134.1064 +    }
134.1065 +
134.1066 +    /**
134.1067 +     * Returns the number of zero bits following the lowest-order ("rightmost")
134.1068 +     * one-bit in the two's complement binary representation of the specified
134.1069 +     * {@code long} value.  Returns 64 if the specified value has no
134.1070 +     * one-bits in its two's complement representation, in other words if it is
134.1071 +     * equal to zero.
134.1072 +     *
134.1073 +     * @return the number of zero bits following the lowest-order ("rightmost")
134.1074 +     *     one-bit in the two's complement binary representation of the
134.1075 +     *     specified {@code long} value, or 64 if the value is equal
134.1076 +     *     to zero.
134.1077 +     * @since 1.5
134.1078 +     */
134.1079 +    public static int numberOfTrailingZeros(long i) {
134.1080 +        // HD, Figure 5-14
134.1081 +        int x, y;
134.1082 +        if (i == 0) return 64;
134.1083 +        int n = 63;
134.1084 +        y = (int)i; if (y != 0) { n = n -32; x = y; } else x = (int)(i>>>32);
134.1085 +        y = x <<16; if (y != 0) { n = n -16; x = y; }
134.1086 +        y = x << 8; if (y != 0) { n = n - 8; x = y; }
134.1087 +        y = x << 4; if (y != 0) { n = n - 4; x = y; }
134.1088 +        y = x << 2; if (y != 0) { n = n - 2; x = y; }
134.1089 +        return n - ((x << 1) >>> 31);
134.1090 +    }
134.1091 +
134.1092 +    /**
134.1093 +     * Returns the number of one-bits in the two's complement binary
134.1094 +     * representation of the specified {@code long} value.  This function is
134.1095 +     * sometimes referred to as the <i>population count</i>.
134.1096 +     *
134.1097 +     * @return the number of one-bits in the two's complement binary
134.1098 +     *     representation of the specified {@code long} value.
134.1099 +     * @since 1.5
134.1100 +     */
134.1101 +     public static int bitCount(long i) {
134.1102 +        // HD, Figure 5-14
134.1103 +        i = i - ((i >>> 1) & 0x5555555555555555L);
134.1104 +        i = (i & 0x3333333333333333L) + ((i >>> 2) & 0x3333333333333333L);
134.1105 +        i = (i + (i >>> 4)) & 0x0f0f0f0f0f0f0f0fL;
134.1106 +        i = i + (i >>> 8);
134.1107 +        i = i + (i >>> 16);
134.1108 +        i = i + (i >>> 32);
134.1109 +        return (int)i & 0x7f;
134.1110 +     }
134.1111 +
134.1112 +    /**
134.1113 +     * Returns the value obtained by rotating the two's complement binary
134.1114 +     * representation of the specified {@code long} value left by the
134.1115 +     * specified number of bits.  (Bits shifted out of the left hand, or
134.1116 +     * high-order, side reenter on the right, or low-order.)
134.1117 +     *
134.1118 +     * <p>Note that left rotation with a negative distance is equivalent to
134.1119 +     * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val,
134.1120 +     * distance)}.  Note also that rotation by any multiple of 64 is a
134.1121 +     * no-op, so all but the last six bits of the rotation distance can be
134.1122 +     * ignored, even if the distance is negative: {@code rotateLeft(val,
134.1123 +     * distance) == rotateLeft(val, distance & 0x3F)}.
134.1124 +     *
134.1125 +     * @return the value obtained by rotating the two's complement binary
134.1126 +     *     representation of the specified {@code long} value left by the
134.1127 +     *     specified number of bits.
134.1128 +     * @since 1.5
134.1129 +     */
134.1130 +    public static long rotateLeft(long i, int distance) {
134.1131 +        return (i << distance) | (i >>> -distance);
134.1132 +    }
134.1133 +
134.1134 +    /**
134.1135 +     * Returns the value obtained by rotating the two's complement binary
134.1136 +     * representation of the specified {@code long} value right by the
134.1137 +     * specified number of bits.  (Bits shifted out of the right hand, or
134.1138 +     * low-order, side reenter on the left, or high-order.)
134.1139 +     *
134.1140 +     * <p>Note that right rotation with a negative distance is equivalent to
134.1141 +     * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val,
134.1142 +     * distance)}.  Note also that rotation by any multiple of 64 is a
134.1143 +     * no-op, so all but the last six bits of the rotation distance can be
134.1144 +     * ignored, even if the distance is negative: {@code rotateRight(val,
134.1145 +     * distance) == rotateRight(val, distance & 0x3F)}.
134.1146 +     *
134.1147 +     * @return the value obtained by rotating the two's complement binary
134.1148 +     *     representation of the specified {@code long} value right by the
134.1149 +     *     specified number of bits.
134.1150 +     * @since 1.5
134.1151 +     */
134.1152 +    public static long rotateRight(long i, int distance) {
134.1153 +        return (i >>> distance) | (i << -distance);
134.1154 +    }
134.1155 +
134.1156 +    /**
134.1157 +     * Returns the value obtained by reversing the order of the bits in the
134.1158 +     * two's complement binary representation of the specified {@code long}
134.1159 +     * value.
134.1160 +     *
134.1161 +     * @return the value obtained by reversing order of the bits in the
134.1162 +     *     specified {@code long} value.
134.1163 +     * @since 1.5
134.1164 +     */
134.1165 +    public static long reverse(long i) {
134.1166 +        // HD, Figure 7-1
134.1167 +        i = (i & 0x5555555555555555L) << 1 | (i >>> 1) & 0x5555555555555555L;
134.1168 +        i = (i & 0x3333333333333333L) << 2 | (i >>> 2) & 0x3333333333333333L;
134.1169 +        i = (i & 0x0f0f0f0f0f0f0f0fL) << 4 | (i >>> 4) & 0x0f0f0f0f0f0f0f0fL;
134.1170 +        i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;
134.1171 +        i = (i << 48) | ((i & 0xffff0000L) << 16) |
134.1172 +            ((i >>> 16) & 0xffff0000L) | (i >>> 48);
134.1173 +        return i;
134.1174 +    }
134.1175 +
134.1176 +    /**
134.1177 +     * Returns the signum function of the specified {@code long} value.  (The
134.1178 +     * return value is -1 if the specified value is negative; 0 if the
134.1179 +     * specified value is zero; and 1 if the specified value is positive.)
134.1180 +     *
134.1181 +     * @return the signum function of the specified {@code long} value.
134.1182 +     * @since 1.5
134.1183 +     */
134.1184 +    public static int signum(long i) {
134.1185 +        // HD, Section 2-7
134.1186 +        return (int) ((i >> 63) | (-i >>> 63));
134.1187 +    }
134.1188 +
134.1189 +    /**
134.1190 +     * Returns the value obtained by reversing the order of the bytes in the
134.1191 +     * two's complement representation of the specified {@code long} value.
134.1192 +     *
134.1193 +     * @return the value obtained by reversing the bytes in the specified
134.1194 +     *     {@code long} value.
134.1195 +     * @since 1.5
134.1196 +     */
134.1197 +    public static long reverseBytes(long i) {
134.1198 +        i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;
134.1199 +        return (i << 48) | ((i & 0xffff0000L) << 16) |
134.1200 +            ((i >>> 16) & 0xffff0000L) | (i >>> 48);
134.1201 +    }
134.1202 +
134.1203 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
134.1204 +    private static final long serialVersionUID = 4290774380558885855L;
134.1205 +}
   135.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   135.2 +++ b/emul/mini/src/main/java/java/lang/Math.java	Sun Feb 03 07:48:42 2013 +0100
   135.3 @@ -0,0 +1,1310 @@
   135.4 +/*
   135.5 + * Copyright (c) 1994, 2011, 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 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  135.32 +
  135.33 +
  135.34 +/**
  135.35 + * The class {@code Math} contains methods for performing basic
  135.36 + * numeric operations such as the elementary exponential, logarithm,
  135.37 + * square root, and trigonometric functions.
  135.38 + *
  135.39 + * <p>Unlike some of the numeric methods of class
  135.40 + * {@code StrictMath}, all implementations of the equivalent
  135.41 + * functions of class {@code Math} are not defined to return the
  135.42 + * bit-for-bit same results.  This relaxation permits
  135.43 + * better-performing implementations where strict reproducibility is
  135.44 + * not required.
  135.45 + *
  135.46 + * <p>By default many of the {@code Math} methods simply call
  135.47 + * the equivalent method in {@code StrictMath} for their
  135.48 + * implementation.  Code generators are encouraged to use
  135.49 + * platform-specific native libraries or microprocessor instructions,
  135.50 + * where available, to provide higher-performance implementations of
  135.51 + * {@code Math} methods.  Such higher-performance
  135.52 + * implementations still must conform to the specification for
  135.53 + * {@code Math}.
  135.54 + *
  135.55 + * <p>The quality of implementation specifications concern two
  135.56 + * properties, accuracy of the returned result and monotonicity of the
  135.57 + * method.  Accuracy of the floating-point {@code Math} methods
  135.58 + * is measured in terms of <i>ulps</i>, units in the last place.  For
  135.59 + * a given floating-point format, an ulp of a specific real number
  135.60 + * value is the distance between the two floating-point values
  135.61 + * bracketing that numerical value.  When discussing the accuracy of a
  135.62 + * method as a whole rather than at a specific argument, the number of
  135.63 + * ulps cited is for the worst-case error at any argument.  If a
  135.64 + * method always has an error less than 0.5 ulps, the method always
  135.65 + * returns the floating-point number nearest the exact result; such a
  135.66 + * method is <i>correctly rounded</i>.  A correctly rounded method is
  135.67 + * generally the best a floating-point approximation can be; however,
  135.68 + * it is impractical for many floating-point methods to be correctly
  135.69 + * rounded.  Instead, for the {@code Math} class, a larger error
  135.70 + * bound of 1 or 2 ulps is allowed for certain methods.  Informally,
  135.71 + * with a 1 ulp error bound, when the exact result is a representable
  135.72 + * number, the exact result should be returned as the computed result;
  135.73 + * otherwise, either of the two floating-point values which bracket
  135.74 + * the exact result may be returned.  For exact results large in
  135.75 + * magnitude, one of the endpoints of the bracket may be infinite.
  135.76 + * Besides accuracy at individual arguments, maintaining proper
  135.77 + * relations between the method at different arguments is also
  135.78 + * important.  Therefore, most methods with more than 0.5 ulp errors
  135.79 + * are required to be <i>semi-monotonic</i>: whenever the mathematical
  135.80 + * function is non-decreasing, so is the floating-point approximation,
  135.81 + * likewise, whenever the mathematical function is non-increasing, so
  135.82 + * is the floating-point approximation.  Not all approximations that
  135.83 + * have 1 ulp accuracy will automatically meet the monotonicity
  135.84 + * requirements.
  135.85 + *
  135.86 + * @author  unascribed
  135.87 + * @author  Joseph D. Darcy
  135.88 + * @since   JDK1.0
  135.89 + */
  135.90 +
  135.91 +public final class Math {
  135.92 +
  135.93 +    /**
  135.94 +     * Don't let anyone instantiate this class.
  135.95 +     */
  135.96 +    private Math() {}
  135.97 +
  135.98 +    /**
  135.99 +     * The {@code double} value that is closer than any other to
 135.100 +     * <i>e</i>, the base of the natural logarithms.
 135.101 +     */
 135.102 +    public static final double E = 2.7182818284590452354;
 135.103 +
 135.104 +    /**
 135.105 +     * The {@code double} value that is closer than any other to
 135.106 +     * <i>pi</i>, the ratio of the circumference of a circle to its
 135.107 +     * diameter.
 135.108 +     */
 135.109 +    public static final double PI = 3.14159265358979323846;
 135.110 +
 135.111 +    /**
 135.112 +     * Returns the trigonometric sine of an angle.  Special cases:
 135.113 +     * <ul><li>If the argument is NaN or an infinity, then the
 135.114 +     * result is NaN.
 135.115 +     * <li>If the argument is zero, then the result is a zero with the
 135.116 +     * same sign as the argument.</ul>
 135.117 +     *
 135.118 +     * <p>The computed result must be within 1 ulp of the exact result.
 135.119 +     * Results must be semi-monotonic.
 135.120 +     *
 135.121 +     * @param   a   an angle, in radians.
 135.122 +     * @return  the sine of the argument.
 135.123 +     */
 135.124 +    @JavaScriptBody(args="a", body="return Math.sin(a);")
 135.125 +    public static double sin(double a) {
 135.126 +        throw new UnsupportedOperationException();
 135.127 +    }
 135.128 +
 135.129 +    /**
 135.130 +     * Returns the trigonometric cosine of an angle. Special cases:
 135.131 +     * <ul><li>If the argument is NaN or an infinity, then the
 135.132 +     * result is NaN.</ul>
 135.133 +     *
 135.134 +     * <p>The computed result must be within 1 ulp of the exact result.
 135.135 +     * Results must be semi-monotonic.
 135.136 +     *
 135.137 +     * @param   a   an angle, in radians.
 135.138 +     * @return  the cosine of the argument.
 135.139 +     */
 135.140 +    @JavaScriptBody(args="a", body="return Math.cos(a);")
 135.141 +    public static double cos(double a) {
 135.142 +        throw new UnsupportedOperationException();
 135.143 +    }
 135.144 +
 135.145 +    /**
 135.146 +     * Returns the trigonometric tangent of an angle.  Special cases:
 135.147 +     * <ul><li>If the argument is NaN or an infinity, then the result
 135.148 +     * is NaN.
 135.149 +     * <li>If the argument is zero, then the result is a zero with the
 135.150 +     * same sign as the argument.</ul>
 135.151 +     *
 135.152 +     * <p>The computed result must be within 1 ulp of the exact result.
 135.153 +     * Results must be semi-monotonic.
 135.154 +     *
 135.155 +     * @param   a   an angle, in radians.
 135.156 +     * @return  the tangent of the argument.
 135.157 +     */
 135.158 +    @JavaScriptBody(args="a", body="return Math.tan(a);")
 135.159 +    public static double tan(double a) {
 135.160 +        throw new UnsupportedOperationException();
 135.161 +    }
 135.162 +
 135.163 +    /**
 135.164 +     * Returns the arc sine of a value; the returned angle is in the
 135.165 +     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
 135.166 +     * <ul><li>If the argument is NaN or its absolute value is greater
 135.167 +     * than 1, then the result is NaN.
 135.168 +     * <li>If the argument is zero, then the result is a zero with the
 135.169 +     * same sign as the argument.</ul>
 135.170 +     *
 135.171 +     * <p>The computed result must be within 1 ulp of the exact result.
 135.172 +     * Results must be semi-monotonic.
 135.173 +     *
 135.174 +     * @param   a   the value whose arc sine is to be returned.
 135.175 +     * @return  the arc sine of the argument.
 135.176 +     */
 135.177 +    @JavaScriptBody(args="a", body="return Math.asin(a);")
 135.178 +    public static double asin(double a) {
 135.179 +        throw new UnsupportedOperationException();
 135.180 +    }
 135.181 +
 135.182 +    /**
 135.183 +     * Returns the arc cosine of a value; the returned angle is in the
 135.184 +     * range 0.0 through <i>pi</i>.  Special case:
 135.185 +     * <ul><li>If the argument is NaN or its absolute value is greater
 135.186 +     * than 1, then the result is NaN.</ul>
 135.187 +     *
 135.188 +     * <p>The computed result must be within 1 ulp of the exact result.
 135.189 +     * Results must be semi-monotonic.
 135.190 +     *
 135.191 +     * @param   a   the value whose arc cosine is to be returned.
 135.192 +     * @return  the arc cosine of the argument.
 135.193 +     */
 135.194 +    @JavaScriptBody(args="a", body="return Math.acos(a);")
 135.195 +    public static double acos(double a) {
 135.196 +        throw new UnsupportedOperationException();
 135.197 +    }
 135.198 +
 135.199 +    /**
 135.200 +     * Returns the arc tangent of a value; the returned angle is in the
 135.201 +     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
 135.202 +     * <ul><li>If the argument is NaN, then the result is NaN.
 135.203 +     * <li>If the argument is zero, then the result is a zero with the
 135.204 +     * same sign as the argument.</ul>
 135.205 +     *
 135.206 +     * <p>The computed result must be within 1 ulp of the exact result.
 135.207 +     * Results must be semi-monotonic.
 135.208 +     *
 135.209 +     * @param   a   the value whose arc tangent is to be returned.
 135.210 +     * @return  the arc tangent of the argument.
 135.211 +     */
 135.212 +    @JavaScriptBody(args="a", body="return Math.atan(a);")
 135.213 +    public static double atan(double a) {
 135.214 +        throw new UnsupportedOperationException();
 135.215 +    }
 135.216 +
 135.217 +    /**
 135.218 +     * Converts an angle measured in degrees to an approximately
 135.219 +     * equivalent angle measured in radians.  The conversion from
 135.220 +     * degrees to radians is generally inexact.
 135.221 +     *
 135.222 +     * @param   angdeg   an angle, in degrees
 135.223 +     * @return  the measurement of the angle {@code angdeg}
 135.224 +     *          in radians.
 135.225 +     * @since   1.2
 135.226 +     */
 135.227 +    public static double toRadians(double angdeg) {
 135.228 +        return angdeg / 180.0 * PI;
 135.229 +    }
 135.230 +
 135.231 +    /**
 135.232 +     * Converts an angle measured in radians to an approximately
 135.233 +     * equivalent angle measured in degrees.  The conversion from
 135.234 +     * radians to degrees is generally inexact; users should
 135.235 +     * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
 135.236 +     * equal {@code 0.0}.
 135.237 +     *
 135.238 +     * @param   angrad   an angle, in radians
 135.239 +     * @return  the measurement of the angle {@code angrad}
 135.240 +     *          in degrees.
 135.241 +     * @since   1.2
 135.242 +     */
 135.243 +    public static double toDegrees(double angrad) {
 135.244 +        return angrad * 180.0 / PI;
 135.245 +    }
 135.246 +
 135.247 +    /**
 135.248 +     * Returns Euler's number <i>e</i> raised to the power of a
 135.249 +     * {@code double} value.  Special cases:
 135.250 +     * <ul><li>If the argument is NaN, the result is NaN.
 135.251 +     * <li>If the argument is positive infinity, then the result is
 135.252 +     * positive infinity.
 135.253 +     * <li>If the argument is negative infinity, then the result is
 135.254 +     * positive zero.</ul>
 135.255 +     *
 135.256 +     * <p>The computed result must be within 1 ulp of the exact result.
 135.257 +     * Results must be semi-monotonic.
 135.258 +     *
 135.259 +     * @param   a   the exponent to raise <i>e</i> to.
 135.260 +     * @return  the value <i>e</i><sup>{@code a}</sup>,
 135.261 +     *          where <i>e</i> is the base of the natural logarithms.
 135.262 +     */
 135.263 +    @JavaScriptBody(args="a", body="return Math.exp(a);")
 135.264 +    public static double exp(double a) {
 135.265 +        throw new UnsupportedOperationException();
 135.266 +    }
 135.267 +
 135.268 +    /**
 135.269 +     * Returns the natural logarithm (base <i>e</i>) of a {@code double}
 135.270 +     * value.  Special cases:
 135.271 +     * <ul><li>If the argument is NaN or less than zero, then the result
 135.272 +     * is NaN.
 135.273 +     * <li>If the argument is positive infinity, then the result is
 135.274 +     * positive infinity.
 135.275 +     * <li>If the argument is positive zero or negative zero, then the
 135.276 +     * result is negative infinity.</ul>
 135.277 +     *
 135.278 +     * <p>The computed result must be within 1 ulp of the exact result.
 135.279 +     * Results must be semi-monotonic.
 135.280 +     *
 135.281 +     * @param   a   a value
 135.282 +     * @return  the value ln&nbsp;{@code a}, the natural logarithm of
 135.283 +     *          {@code a}.
 135.284 +     */
 135.285 +    @JavaScriptBody(args="a", body="return Math.log(a);")
 135.286 +    public static double log(double a) {
 135.287 +        throw new UnsupportedOperationException();
 135.288 +    }
 135.289 +
 135.290 +    /**
 135.291 +     * Returns the base 10 logarithm of a {@code double} value.
 135.292 +     * Special cases:
 135.293 +     *
 135.294 +     * <ul><li>If the argument is NaN or less than zero, then the result
 135.295 +     * is NaN.
 135.296 +     * <li>If the argument is positive infinity, then the result is
 135.297 +     * positive infinity.
 135.298 +     * <li>If the argument is positive zero or negative zero, then the
 135.299 +     * result is negative infinity.
 135.300 +     * <li> If the argument is equal to 10<sup><i>n</i></sup> for
 135.301 +     * integer <i>n</i>, then the result is <i>n</i>.
 135.302 +     * </ul>
 135.303 +     *
 135.304 +     * <p>The computed result must be within 1 ulp of the exact result.
 135.305 +     * Results must be semi-monotonic.
 135.306 +     *
 135.307 +     * @param   a   a value
 135.308 +     * @return  the base 10 logarithm of  {@code a}.
 135.309 +     * @since 1.5
 135.310 +     */
 135.311 +    @JavaScriptBody(args="a", body="return Math.log(a) / Math.LN10;")
 135.312 +    public static double log10(double a) {
 135.313 +        throw new UnsupportedOperationException();
 135.314 +    }
 135.315 +
 135.316 +    /**
 135.317 +     * Returns the correctly rounded positive square root of a
 135.318 +     * {@code double} value.
 135.319 +     * Special cases:
 135.320 +     * <ul><li>If the argument is NaN or less than zero, then the result
 135.321 +     * is NaN.
 135.322 +     * <li>If the argument is positive infinity, then the result is positive
 135.323 +     * infinity.
 135.324 +     * <li>If the argument is positive zero or negative zero, then the
 135.325 +     * result is the same as the argument.</ul>
 135.326 +     * Otherwise, the result is the {@code double} value closest to
 135.327 +     * the true mathematical square root of the argument value.
 135.328 +     *
 135.329 +     * @param   a   a value.
 135.330 +     * @return  the positive square root of {@code a}.
 135.331 +     *          If the argument is NaN or less than zero, the result is NaN.
 135.332 +     */
 135.333 +    @JavaScriptBody(args="a", body="return Math.sqrt(a);")
 135.334 +    public static double sqrt(double a) {
 135.335 +        throw new UnsupportedOperationException();
 135.336 +    }
 135.337 +
 135.338 +    /**
 135.339 +     * Returns the smallest (closest to negative infinity)
 135.340 +     * {@code double} value that is greater than or equal to the
 135.341 +     * argument and is equal to a mathematical integer. Special cases:
 135.342 +     * <ul><li>If the argument value is already equal to a
 135.343 +     * mathematical integer, then the result is the same as the
 135.344 +     * argument.  <li>If the argument is NaN or an infinity or
 135.345 +     * positive zero or negative zero, then the result is the same as
 135.346 +     * the argument.  <li>If the argument value is less than zero but
 135.347 +     * greater than -1.0, then the result is negative zero.</ul> Note
 135.348 +     * that the value of {@code Math.ceil(x)} is exactly the
 135.349 +     * value of {@code -Math.floor(-x)}.
 135.350 +     *
 135.351 +     *
 135.352 +     * @param   a   a value.
 135.353 +     * @return  the smallest (closest to negative infinity)
 135.354 +     *          floating-point value that is greater than or equal to
 135.355 +     *          the argument and is equal to a mathematical integer.
 135.356 +     */
 135.357 +    @JavaScriptBody(args="a", body="return Math.ceil(a);")
 135.358 +    public static double ceil(double a) {
 135.359 +        throw new UnsupportedOperationException();
 135.360 +    }
 135.361 +
 135.362 +    /**
 135.363 +     * Returns the largest (closest to positive infinity)
 135.364 +     * {@code double} value that is less than or equal to the
 135.365 +     * argument and is equal to a mathematical integer. Special cases:
 135.366 +     * <ul><li>If the argument value is already equal to a
 135.367 +     * mathematical integer, then the result is the same as the
 135.368 +     * argument.  <li>If the argument is NaN or an infinity or
 135.369 +     * positive zero or negative zero, then the result is the same as
 135.370 +     * the argument.</ul>
 135.371 +     *
 135.372 +     * @param   a   a value.
 135.373 +     * @return  the largest (closest to positive infinity)
 135.374 +     *          floating-point value that less than or equal to the argument
 135.375 +     *          and is equal to a mathematical integer.
 135.376 +     */
 135.377 +    @JavaScriptBody(args="a", body="return Math.floor(a);")
 135.378 +    public static double floor(double a) {
 135.379 +        throw new UnsupportedOperationException();
 135.380 +    }
 135.381 +    /**
 135.382 +     * Computes the remainder operation on two arguments as prescribed
 135.383 +     * by the IEEE 754 standard.
 135.384 +     * The remainder value is mathematically equal to
 135.385 +     * <code>f1&nbsp;-&nbsp;f2</code>&nbsp;&times;&nbsp;<i>n</i>,
 135.386 +     * where <i>n</i> is the mathematical integer closest to the exact
 135.387 +     * mathematical value of the quotient {@code f1/f2}, and if two
 135.388 +     * mathematical integers are equally close to {@code f1/f2},
 135.389 +     * then <i>n</i> is the integer that is even. If the remainder is
 135.390 +     * zero, its sign is the same as the sign of the first argument.
 135.391 +     * Special cases:
 135.392 +     * <ul><li>If either argument is NaN, or the first argument is infinite,
 135.393 +     * or the second argument is positive zero or negative zero, then the
 135.394 +     * result is NaN.
 135.395 +     * <li>If the first argument is finite and the second argument is
 135.396 +     * infinite, then the result is the same as the first argument.</ul>
 135.397 +     *
 135.398 +     * @param   f1   the dividend.
 135.399 +     * @param   f2   the divisor.
 135.400 +     * @return  the remainder when {@code f1} is divided by
 135.401 +     *          {@code f2}.
 135.402 +     */
 135.403 +    public static double IEEEremainder(double f1, double f2) {
 135.404 +        return f1 - (f2 * Math.round(f1 / f2));
 135.405 +    }
 135.406 +
 135.407 +    /**
 135.408 +     * Returns the {@code double} value that is closest in value
 135.409 +     * to the argument and is equal to a mathematical integer. If two
 135.410 +     * {@code double} values that are mathematical integers are
 135.411 +     * equally close, the result is the integer value that is
 135.412 +     * even. Special cases:
 135.413 +     * <ul><li>If the argument value is already equal to a mathematical
 135.414 +     * integer, then the result is the same as the argument.
 135.415 +     * <li>If the argument is NaN or an infinity or positive zero or negative
 135.416 +     * zero, then the result is the same as the argument.</ul>
 135.417 +     *
 135.418 +     * @param   a   a {@code double} value.
 135.419 +     * @return  the closest floating-point value to {@code a} that is
 135.420 +     *          equal to a mathematical integer.
 135.421 +     */
 135.422 +    public static double rint(double a) {
 135.423 +        double ceil = ceil(a);
 135.424 +        double floor = floor(a);
 135.425 +        
 135.426 +        double dc = ceil - a;
 135.427 +        double df = a - floor;
 135.428 +        
 135.429 +        if (dc < df) {
 135.430 +            return ceil;
 135.431 +        } else if (dc > df) {
 135.432 +            return floor;
 135.433 +        }
 135.434 +        
 135.435 +        int tenC = (int) (ceil % 10.0);
 135.436 +        
 135.437 +        if (tenC % 2 == 0) {
 135.438 +            return ceil;
 135.439 +        } else {
 135.440 +            return floor;
 135.441 +        }
 135.442 +    }
 135.443 +
 135.444 +    /**
 135.445 +     * Returns the angle <i>theta</i> from the conversion of rectangular
 135.446 +     * coordinates ({@code x},&nbsp;{@code y}) to polar
 135.447 +     * coordinates (r,&nbsp;<i>theta</i>).
 135.448 +     * This method computes the phase <i>theta</i> by computing an arc tangent
 135.449 +     * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
 135.450 +     * cases:
 135.451 +     * <ul><li>If either argument is NaN, then the result is NaN.
 135.452 +     * <li>If the first argument is positive zero and the second argument
 135.453 +     * is positive, or the first argument is positive and finite and the
 135.454 +     * second argument is positive infinity, then the result is positive
 135.455 +     * zero.
 135.456 +     * <li>If the first argument is negative zero and the second argument
 135.457 +     * is positive, or the first argument is negative and finite and the
 135.458 +     * second argument is positive infinity, then the result is negative zero.
 135.459 +     * <li>If the first argument is positive zero and the second argument
 135.460 +     * is negative, or the first argument is positive and finite and the
 135.461 +     * second argument is negative infinity, then the result is the
 135.462 +     * {@code double} value closest to <i>pi</i>.
 135.463 +     * <li>If the first argument is negative zero and the second argument
 135.464 +     * is negative, or the first argument is negative and finite and the
 135.465 +     * second argument is negative infinity, then the result is the
 135.466 +     * {@code double} value closest to -<i>pi</i>.
 135.467 +     * <li>If the first argument is positive and the second argument is
 135.468 +     * positive zero or negative zero, or the first argument is positive
 135.469 +     * infinity and the second argument is finite, then the result is the
 135.470 +     * {@code double} value closest to <i>pi</i>/2.
 135.471 +     * <li>If the first argument is negative and the second argument is
 135.472 +     * positive zero or negative zero, or the first argument is negative
 135.473 +     * infinity and the second argument is finite, then the result is the
 135.474 +     * {@code double} value closest to -<i>pi</i>/2.
 135.475 +     * <li>If both arguments are positive infinity, then the result is the
 135.476 +     * {@code double} value closest to <i>pi</i>/4.
 135.477 +     * <li>If the first argument is positive infinity and the second argument
 135.478 +     * is negative infinity, then the result is the {@code double}
 135.479 +     * value closest to 3*<i>pi</i>/4.
 135.480 +     * <li>If the first argument is negative infinity and the second argument
 135.481 +     * is positive infinity, then the result is the {@code double} value
 135.482 +     * closest to -<i>pi</i>/4.
 135.483 +     * <li>If both arguments are negative infinity, then the result is the
 135.484 +     * {@code double} value closest to -3*<i>pi</i>/4.</ul>
 135.485 +     *
 135.486 +     * <p>The computed result must be within 2 ulps of the exact result.
 135.487 +     * Results must be semi-monotonic.
 135.488 +     *
 135.489 +     * @param   y   the ordinate coordinate
 135.490 +     * @param   x   the abscissa coordinate
 135.491 +     * @return  the <i>theta</i> component of the point
 135.492 +     *          (<i>r</i>,&nbsp;<i>theta</i>)
 135.493 +     *          in polar coordinates that corresponds to the point
 135.494 +     *          (<i>x</i>,&nbsp;<i>y</i>) in Cartesian coordinates.
 135.495 +     */
 135.496 +    @JavaScriptBody(args={"y", "x"}, body="return Math.atan2(y, x);")
 135.497 +    public static double atan2(double y, double x) {
 135.498 +        throw new UnsupportedOperationException();
 135.499 +    }
 135.500 +
 135.501 +    /**
 135.502 +     * Returns the value of the first argument raised to the power of the
 135.503 +     * second argument. Special cases:
 135.504 +     *
 135.505 +     * <ul><li>If the second argument is positive or negative zero, then the
 135.506 +     * result is 1.0.
 135.507 +     * <li>If the second argument is 1.0, then the result is the same as the
 135.508 +     * first argument.
 135.509 +     * <li>If the second argument is NaN, then the result is NaN.
 135.510 +     * <li>If the first argument is NaN and the second argument is nonzero,
 135.511 +     * then the result is NaN.
 135.512 +     *
 135.513 +     * <li>If
 135.514 +     * <ul>
 135.515 +     * <li>the absolute value of the first argument is greater than 1
 135.516 +     * and the second argument is positive infinity, or
 135.517 +     * <li>the absolute value of the first argument is less than 1 and
 135.518 +     * the second argument is negative infinity,
 135.519 +     * </ul>
 135.520 +     * then the result is positive infinity.
 135.521 +     *
 135.522 +     * <li>If
 135.523 +     * <ul>
 135.524 +     * <li>the absolute value of the first argument is greater than 1 and
 135.525 +     * the second argument is negative infinity, or
 135.526 +     * <li>the absolute value of the
 135.527 +     * first argument is less than 1 and the second argument is positive
 135.528 +     * infinity,
 135.529 +     * </ul>
 135.530 +     * then the result is positive zero.
 135.531 +     *
 135.532 +     * <li>If the absolute value of the first argument equals 1 and the
 135.533 +     * second argument is infinite, then the result is NaN.
 135.534 +     *
 135.535 +     * <li>If
 135.536 +     * <ul>
 135.537 +     * <li>the first argument is positive zero and the second argument
 135.538 +     * is greater than zero, or
 135.539 +     * <li>the first argument is positive infinity and the second
 135.540 +     * argument is less than zero,
 135.541 +     * </ul>
 135.542 +     * then the result is positive zero.
 135.543 +     *
 135.544 +     * <li>If
 135.545 +     * <ul>
 135.546 +     * <li>the first argument is positive zero and the second argument
 135.547 +     * is less than zero, or
 135.548 +     * <li>the first argument is positive infinity and the second
 135.549 +     * argument is greater than zero,
 135.550 +     * </ul>
 135.551 +     * then the result is positive infinity.
 135.552 +     *
 135.553 +     * <li>If
 135.554 +     * <ul>
 135.555 +     * <li>the first argument is negative zero and the second argument
 135.556 +     * is greater than zero but not a finite odd integer, or
 135.557 +     * <li>the first argument is negative infinity and the second
 135.558 +     * argument is less than zero but not a finite odd integer,
 135.559 +     * </ul>
 135.560 +     * then the result is positive zero.
 135.561 +     *
 135.562 +     * <li>If
 135.563 +     * <ul>
 135.564 +     * <li>the first argument is negative zero and the second argument
 135.565 +     * is a positive finite odd integer, or
 135.566 +     * <li>the first argument is negative infinity and the second
 135.567 +     * argument is a negative finite odd integer,
 135.568 +     * </ul>
 135.569 +     * then the result is negative zero.
 135.570 +     *
 135.571 +     * <li>If
 135.572 +     * <ul>
 135.573 +     * <li>the first argument is negative zero and the second argument
 135.574 +     * is less than zero but not a finite odd integer, or
 135.575 +     * <li>the first argument is negative infinity and the second
 135.576 +     * argument is greater than zero but not a finite odd integer,
 135.577 +     * </ul>
 135.578 +     * then the result is positive infinity.
 135.579 +     *
 135.580 +     * <li>If
 135.581 +     * <ul>
 135.582 +     * <li>the first argument is negative zero and the second argument
 135.583 +     * is a negative finite odd integer, or
 135.584 +     * <li>the first argument is negative infinity and the second
 135.585 +     * argument is a positive finite odd integer,
 135.586 +     * </ul>
 135.587 +     * then the result is negative infinity.
 135.588 +     *
 135.589 +     * <li>If the first argument is finite and less than zero
 135.590 +     * <ul>
 135.591 +     * <li> if the second argument is a finite even integer, the
 135.592 +     * result is equal to the result of raising the absolute value of
 135.593 +     * the first argument to the power of the second argument
 135.594 +     *
 135.595 +     * <li>if the second argument is a finite odd integer, the result
 135.596 +     * is equal to the negative of the result of raising the absolute
 135.597 +     * value of the first argument to the power of the second
 135.598 +     * argument
 135.599 +     *
 135.600 +     * <li>if the second argument is finite and not an integer, then
 135.601 +     * the result is NaN.
 135.602 +     * </ul>
 135.603 +     *
 135.604 +     * <li>If both arguments are integers, then the result is exactly equal
 135.605 +     * to the mathematical result of raising the first argument to the power
 135.606 +     * of the second argument if that result can in fact be represented
 135.607 +     * exactly as a {@code double} value.</ul>
 135.608 +     *
 135.609 +     * <p>(In the foregoing descriptions, a floating-point value is
 135.610 +     * considered to be an integer if and only if it is finite and a
 135.611 +     * fixed point of the method {@link #ceil ceil} or,
 135.612 +     * equivalently, a fixed point of the method {@link #floor
 135.613 +     * floor}. A value is a fixed point of a one-argument
 135.614 +     * method if and only if the result of applying the method to the
 135.615 +     * value is equal to the value.)
 135.616 +     *
 135.617 +     * <p>The computed result must be within 1 ulp of the exact result.
 135.618 +     * Results must be semi-monotonic.
 135.619 +     *
 135.620 +     * @param   a   the base.
 135.621 +     * @param   b   the exponent.
 135.622 +     * @return  the value {@code a}<sup>{@code b}</sup>.
 135.623 +     */
 135.624 +    @JavaScriptBody(args={"a", "b"}, body="return Math.pow(a, b);")
 135.625 +    public static double pow(double a, double b) {
 135.626 +        throw new UnsupportedOperationException();
 135.627 +    }
 135.628 +
 135.629 +    /**
 135.630 +     * Returns the closest {@code int} to the argument, with ties
 135.631 +     * rounding up.
 135.632 +     *
 135.633 +     * <p>
 135.634 +     * Special cases:
 135.635 +     * <ul><li>If the argument is NaN, the result is 0.
 135.636 +     * <li>If the argument is negative infinity or any value less than or
 135.637 +     * equal to the value of {@code Integer.MIN_VALUE}, the result is
 135.638 +     * equal to the value of {@code Integer.MIN_VALUE}.
 135.639 +     * <li>If the argument is positive infinity or any value greater than or
 135.640 +     * equal to the value of {@code Integer.MAX_VALUE}, the result is
 135.641 +     * equal to the value of {@code Integer.MAX_VALUE}.</ul>
 135.642 +     *
 135.643 +     * @param   a   a floating-point value to be rounded to an integer.
 135.644 +     * @return  the value of the argument rounded to the nearest
 135.645 +     *          {@code int} value.
 135.646 +     * @see     java.lang.Integer#MAX_VALUE
 135.647 +     * @see     java.lang.Integer#MIN_VALUE
 135.648 +     */
 135.649 +    @JavaScriptBody(args="a", body="return Math.round(a);")
 135.650 +    public static int round(float a) {
 135.651 +        throw new UnsupportedOperationException();
 135.652 +    }
 135.653 +
 135.654 +    /**
 135.655 +     * Returns the closest {@code long} to the argument, with ties
 135.656 +     * rounding up.
 135.657 +     *
 135.658 +     * <p>Special cases:
 135.659 +     * <ul><li>If the argument is NaN, the result is 0.
 135.660 +     * <li>If the argument is negative infinity or any value less than or
 135.661 +     * equal to the value of {@code Long.MIN_VALUE}, the result is
 135.662 +     * equal to the value of {@code Long.MIN_VALUE}.
 135.663 +     * <li>If the argument is positive infinity or any value greater than or
 135.664 +     * equal to the value of {@code Long.MAX_VALUE}, the result is
 135.665 +     * equal to the value of {@code Long.MAX_VALUE}.</ul>
 135.666 +     *
 135.667 +     * @param   a   a floating-point value to be rounded to a
 135.668 +     *          {@code long}.
 135.669 +     * @return  the value of the argument rounded to the nearest
 135.670 +     *          {@code long} value.
 135.671 +     * @see     java.lang.Long#MAX_VALUE
 135.672 +     * @see     java.lang.Long#MIN_VALUE
 135.673 +     */
 135.674 +    @JavaScriptBody(args="a", body="return Math.round(a);")
 135.675 +    public static long round(double a) {
 135.676 +        throw new UnsupportedOperationException();
 135.677 +    }
 135.678 +
 135.679 +//    private static Random randomNumberGenerator;
 135.680 +//
 135.681 +//    private static synchronized Random initRNG() {
 135.682 +//        Random rnd = randomNumberGenerator;
 135.683 +//        return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
 135.684 +//    }
 135.685 +
 135.686 +    /**
 135.687 +     * Returns a {@code double} value with a positive sign, greater
 135.688 +     * than or equal to {@code 0.0} and less than {@code 1.0}.
 135.689 +     * Returned values are chosen pseudorandomly with (approximately)
 135.690 +     * uniform distribution from that range.
 135.691 +     *
 135.692 +     * <p>When this method is first called, it creates a single new
 135.693 +     * pseudorandom-number generator, exactly as if by the expression
 135.694 +     *
 135.695 +     * <blockquote>{@code new java.util.Random()}</blockquote>
 135.696 +     *
 135.697 +     * This new pseudorandom-number generator is used thereafter for
 135.698 +     * all calls to this method and is used nowhere else.
 135.699 +     *
 135.700 +     * <p>This method is properly synchronized to allow correct use by
 135.701 +     * more than one thread. However, if many threads need to generate
 135.702 +     * pseudorandom numbers at a great rate, it may reduce contention
 135.703 +     * for each thread to have its own pseudorandom-number generator.
 135.704 +     *
 135.705 +     * @return  a pseudorandom {@code double} greater than or equal
 135.706 +     * to {@code 0.0} and less than {@code 1.0}.
 135.707 +     * @see Random#nextDouble()
 135.708 +     */
 135.709 +    @JavaScriptBody(args={}, body="return Math.random();")
 135.710 +    public static double random() {
 135.711 +        throw new UnsupportedOperationException();
 135.712 +    }
 135.713 +
 135.714 +    /**
 135.715 +     * Returns the absolute value of an {@code int} value.
 135.716 +     * If the argument is not negative, the argument is returned.
 135.717 +     * If the argument is negative, the negation of the argument is returned.
 135.718 +     *
 135.719 +     * <p>Note that if the argument is equal to the value of
 135.720 +     * {@link Integer#MIN_VALUE}, the most negative representable
 135.721 +     * {@code int} value, the result is that same value, which is
 135.722 +     * negative.
 135.723 +     *
 135.724 +     * @param   a   the argument whose absolute value is to be determined
 135.725 +     * @return  the absolute value of the argument.
 135.726 +     */
 135.727 +    public static int abs(int a) {
 135.728 +        return (a < 0) ? -a : a;
 135.729 +    }
 135.730 +
 135.731 +    /**
 135.732 +     * Returns the absolute value of a {@code long} value.
 135.733 +     * If the argument is not negative, the argument is returned.
 135.734 +     * If the argument is negative, the negation of the argument is returned.
 135.735 +     *
 135.736 +     * <p>Note that if the argument is equal to the value of
 135.737 +     * {@link Long#MIN_VALUE}, the most negative representable
 135.738 +     * {@code long} value, the result is that same value, which
 135.739 +     * is negative.
 135.740 +     *
 135.741 +     * @param   a   the argument whose absolute value is to be determined
 135.742 +     * @return  the absolute value of the argument.
 135.743 +     */
 135.744 +    public static long abs(long a) {
 135.745 +        return (a < 0) ? -a : a;
 135.746 +    }
 135.747 +
 135.748 +    /**
 135.749 +     * Returns the absolute value of a {@code float} value.
 135.750 +     * If the argument is not negative, the argument is returned.
 135.751 +     * If the argument is negative, the negation of the argument is returned.
 135.752 +     * Special cases:
 135.753 +     * <ul><li>If the argument is positive zero or negative zero, the
 135.754 +     * result is positive zero.
 135.755 +     * <li>If the argument is infinite, the result is positive infinity.
 135.756 +     * <li>If the argument is NaN, the result is NaN.</ul>
 135.757 +     * In other words, the result is the same as the value of the expression:
 135.758 +     * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
 135.759 +     *
 135.760 +     * @param   a   the argument whose absolute value is to be determined
 135.761 +     * @return  the absolute value of the argument.
 135.762 +     */
 135.763 +    public static float abs(float a) {
 135.764 +        return (a <= 0.0F) ? 0.0F - a : a;
 135.765 +    }
 135.766 +
 135.767 +    /**
 135.768 +     * Returns the absolute value of a {@code double} value.
 135.769 +     * If the argument is not negative, the argument is returned.
 135.770 +     * If the argument is negative, the negation of the argument is returned.
 135.771 +     * Special cases:
 135.772 +     * <ul><li>If the argument is positive zero or negative zero, the result
 135.773 +     * is positive zero.
 135.774 +     * <li>If the argument is infinite, the result is positive infinity.
 135.775 +     * <li>If the argument is NaN, the result is NaN.</ul>
 135.776 +     * In other words, the result is the same as the value of the expression:
 135.777 +     * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
 135.778 +     *
 135.779 +     * @param   a   the argument whose absolute value is to be determined
 135.780 +     * @return  the absolute value of the argument.
 135.781 +     */
 135.782 +    public static double abs(double a) {
 135.783 +        return (a <= 0.0D) ? 0.0D - a : a;
 135.784 +    }
 135.785 +
 135.786 +    /**
 135.787 +     * Returns the greater of two {@code int} values. That is, the
 135.788 +     * result is the argument closer to the value of
 135.789 +     * {@link Integer#MAX_VALUE}. If the arguments have the same value,
 135.790 +     * the result is that same value.
 135.791 +     *
 135.792 +     * @param   a   an argument.
 135.793 +     * @param   b   another argument.
 135.794 +     * @return  the larger of {@code a} and {@code b}.
 135.795 +     */
 135.796 +    public static int max(int a, int b) {
 135.797 +        return (a >= b) ? a : b;
 135.798 +    }
 135.799 +
 135.800 +    /**
 135.801 +     * Returns the greater of two {@code long} values. That is, the
 135.802 +     * result is the argument closer to the value of
 135.803 +     * {@link Long#MAX_VALUE}. If the arguments have the same value,
 135.804 +     * the result is that same value.
 135.805 +     *
 135.806 +     * @param   a   an argument.
 135.807 +     * @param   b   another argument.
 135.808 +     * @return  the larger of {@code a} and {@code b}.
 135.809 +     */
 135.810 +    public static long max(long a, long b) {
 135.811 +        return (a >= b) ? a : b;
 135.812 +    }
 135.813 +
 135.814 +    /**
 135.815 +     * Returns the greater of two {@code float} values.  That is,
 135.816 +     * the result is the argument closer to positive infinity. If the
 135.817 +     * arguments have the same value, the result is that same
 135.818 +     * value. If either value is NaN, then the result is NaN.  Unlike
 135.819 +     * the numerical comparison operators, this method considers
 135.820 +     * negative zero to be strictly smaller than positive zero. If one
 135.821 +     * argument is positive zero and the other negative zero, the
 135.822 +     * result is positive zero.
 135.823 +     *
 135.824 +     * @param   a   an argument.
 135.825 +     * @param   b   another argument.
 135.826 +     * @return  the larger of {@code a} and {@code b}.
 135.827 +     */
 135.828 +    @JavaScriptBody(args={"a", "b"},
 135.829 +        body="return Math.max(a,b);"
 135.830 +    )
 135.831 +    public static float max(float a, float b) {
 135.832 +        throw new UnsupportedOperationException();
 135.833 +    }
 135.834 +
 135.835 +    /**
 135.836 +     * Returns the greater of two {@code double} values.  That
 135.837 +     * is, the result is the argument closer to positive infinity. If
 135.838 +     * the arguments have the same value, the result is that same
 135.839 +     * value. If either value is NaN, then the result is NaN.  Unlike
 135.840 +     * the numerical comparison operators, this method considers
 135.841 +     * negative zero to be strictly smaller than positive zero. If one
 135.842 +     * argument is positive zero and the other negative zero, the
 135.843 +     * result is positive zero.
 135.844 +     *
 135.845 +     * @param   a   an argument.
 135.846 +     * @param   b   another argument.
 135.847 +     * @return  the larger of {@code a} and {@code b}.
 135.848 +     */
 135.849 +    @JavaScriptBody(args={"a", "b"},
 135.850 +        body="return Math.max(a,b);"
 135.851 +    )
 135.852 +    public static double max(double a, double b) {
 135.853 +        throw new UnsupportedOperationException();
 135.854 +    }
 135.855 +
 135.856 +    /**
 135.857 +     * Returns the smaller of two {@code int} values. That is,
 135.858 +     * the result the argument closer to the value of
 135.859 +     * {@link Integer#MIN_VALUE}.  If the arguments have the same
 135.860 +     * value, the result is that same value.
 135.861 +     *
 135.862 +     * @param   a   an argument.
 135.863 +     * @param   b   another argument.
 135.864 +     * @return  the smaller of {@code a} and {@code b}.
 135.865 +     */
 135.866 +    public static int min(int a, int b) {
 135.867 +        return (a <= b) ? a : b;
 135.868 +    }
 135.869 +
 135.870 +    /**
 135.871 +     * Returns the smaller of two {@code long} values. That is,
 135.872 +     * the result is the argument closer to the value of
 135.873 +     * {@link Long#MIN_VALUE}. If the arguments have the same
 135.874 +     * value, the result is that same value.
 135.875 +     *
 135.876 +     * @param   a   an argument.
 135.877 +     * @param   b   another argument.
 135.878 +     * @return  the smaller of {@code a} and {@code b}.
 135.879 +     */
 135.880 +    public static long min(long a, long b) {
 135.881 +        return (a <= b) ? a : b;
 135.882 +    }
 135.883 +
 135.884 +    /**
 135.885 +     * Returns the smaller of two {@code float} values.  That is,
 135.886 +     * the result is the value closer to negative infinity. If the
 135.887 +     * arguments have the same value, the result is that same
 135.888 +     * value. If either value is NaN, then the result is NaN.  Unlike
 135.889 +     * the numerical comparison operators, this method considers
 135.890 +     * negative zero to be strictly smaller than positive zero.  If
 135.891 +     * one argument is positive zero and the other is negative zero,
 135.892 +     * the result is negative zero.
 135.893 +     *
 135.894 +     * @param   a   an argument.
 135.895 +     * @param   b   another argument.
 135.896 +     * @return  the smaller of {@code a} and {@code b}.
 135.897 +     */
 135.898 +    @JavaScriptBody(args={"a", "b"},
 135.899 +        body="return Math.min(a,b);"
 135.900 +    )
 135.901 +    public static float min(float a, float b) {
 135.902 +        throw new UnsupportedOperationException();
 135.903 +    }
 135.904 +
 135.905 +    /**
 135.906 +     * Returns the smaller of two {@code double} values.  That
 135.907 +     * is, the result is the value closer to negative infinity. If the
 135.908 +     * arguments have the same value, the result is that same
 135.909 +     * value. If either value is NaN, then the result is NaN.  Unlike
 135.910 +     * the numerical comparison operators, this method considers
 135.911 +     * negative zero to be strictly smaller than positive zero. If one
 135.912 +     * argument is positive zero and the other is negative zero, the
 135.913 +     * result is negative zero.
 135.914 +     *
 135.915 +     * @param   a   an argument.
 135.916 +     * @param   b   another argument.
 135.917 +     * @return  the smaller of {@code a} and {@code b}.
 135.918 +     */
 135.919 +    @JavaScriptBody(args={"a", "b"},
 135.920 +        body="return Math.min(a,b);"
 135.921 +    )
 135.922 +    public static double min(double a, double b) {
 135.923 +        throw new UnsupportedOperationException();
 135.924 +    }
 135.925 +
 135.926 +    /**
 135.927 +     * Returns the size of an ulp of the argument.  An ulp of a
 135.928 +     * {@code double} value is the positive distance between this
 135.929 +     * floating-point value and the {@code double} value next
 135.930 +     * larger in magnitude.  Note that for non-NaN <i>x</i>,
 135.931 +     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
 135.932 +     *
 135.933 +     * <p>Special Cases:
 135.934 +     * <ul>
 135.935 +     * <li> If the argument is NaN, then the result is NaN.
 135.936 +     * <li> If the argument is positive or negative infinity, then the
 135.937 +     * result is positive infinity.
 135.938 +     * <li> If the argument is positive or negative zero, then the result is
 135.939 +     * {@code Double.MIN_VALUE}.
 135.940 +     * <li> If the argument is &plusmn;{@code Double.MAX_VALUE}, then
 135.941 +     * the result is equal to 2<sup>971</sup>.
 135.942 +     * </ul>
 135.943 +     *
 135.944 +     * @param d the floating-point value whose ulp is to be returned
 135.945 +     * @return the size of an ulp of the argument
 135.946 +     * @author Joseph D. Darcy
 135.947 +     * @since 1.5
 135.948 +     */
 135.949 +//    public static double ulp(double d) {
 135.950 +//        return sun.misc.FpUtils.ulp(d);
 135.951 +//    }
 135.952 +
 135.953 +    /**
 135.954 +     * Returns the size of an ulp of the argument.  An ulp of a
 135.955 +     * {@code float} value is the positive distance between this
 135.956 +     * floating-point value and the {@code float} value next
 135.957 +     * larger in magnitude.  Note that for non-NaN <i>x</i>,
 135.958 +     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
 135.959 +     *
 135.960 +     * <p>Special Cases:
 135.961 +     * <ul>
 135.962 +     * <li> If the argument is NaN, then the result is NaN.
 135.963 +     * <li> If the argument is positive or negative infinity, then the
 135.964 +     * result is positive infinity.
 135.965 +     * <li> If the argument is positive or negative zero, then the result is
 135.966 +     * {@code Float.MIN_VALUE}.
 135.967 +     * <li> If the argument is &plusmn;{@code Float.MAX_VALUE}, then
 135.968 +     * the result is equal to 2<sup>104</sup>.
 135.969 +     * </ul>
 135.970 +     *
 135.971 +     * @param f the floating-point value whose ulp is to be returned
 135.972 +     * @return the size of an ulp of the argument
 135.973 +     * @author Joseph D. Darcy
 135.974 +     * @since 1.5
 135.975 +     */
 135.976 +//    public static float ulp(float f) {
 135.977 +//        return sun.misc.FpUtils.ulp(f);
 135.978 +//    }
 135.979 +
 135.980 +    /**
 135.981 +     * Returns the signum function of the argument; zero if the argument
 135.982 +     * is zero, 1.0 if the argument is greater than zero, -1.0 if the
 135.983 +     * argument is less than zero.
 135.984 +     *
 135.985 +     * <p>Special Cases:
 135.986 +     * <ul>
 135.987 +     * <li> If the argument is NaN, then the result is NaN.
 135.988 +     * <li> If the argument is positive zero or negative zero, then the
 135.989 +     *      result is the same as the argument.
 135.990 +     * </ul>
 135.991 +     *
 135.992 +     * @param d the floating-point value whose signum is to be returned
 135.993 +     * @return the signum function of the argument
 135.994 +     * @author Joseph D. Darcy
 135.995 +     * @since 1.5
 135.996 +     */
 135.997 +    public static double signum(double d) {
 135.998 +        if (d < 0.0) { return -1.0; }
 135.999 +        if (d > 0.0) { return 1.0; }
135.1000 +        return d;
135.1001 +    }
135.1002 +
135.1003 +    /**
135.1004 +     * Returns the signum function of the argument; zero if the argument
135.1005 +     * is zero, 1.0f if the argument is greater than zero, -1.0f if the
135.1006 +     * argument is less than zero.
135.1007 +     *
135.1008 +     * <p>Special Cases:
135.1009 +     * <ul>
135.1010 +     * <li> If the argument is NaN, then the result is NaN.
135.1011 +     * <li> If the argument is positive zero or negative zero, then the
135.1012 +     *      result is the same as the argument.
135.1013 +     * </ul>
135.1014 +     *
135.1015 +     * @param f the floating-point value whose signum is to be returned
135.1016 +     * @return the signum function of the argument
135.1017 +     * @author Joseph D. Darcy
135.1018 +     * @since 1.5
135.1019 +     */
135.1020 +    public static float signum(float f) {
135.1021 +        if (f < 0.0f) { return -1.0f; }
135.1022 +        if (f > 0.0f) { return 1.0f; }
135.1023 +        return f;
135.1024 +    }
135.1025 +
135.1026 +    /**
135.1027 +     * Returns the first floating-point argument with the sign of the
135.1028 +     * second floating-point argument.  Note that unlike the {@link
135.1029 +     * StrictMath#copySign(double, double) StrictMath.copySign}
135.1030 +     * method, this method does not require NaN {@code sign}
135.1031 +     * arguments to be treated as positive values; implementations are
135.1032 +     * permitted to treat some NaN arguments as positive and other NaN
135.1033 +     * arguments as negative to allow greater performance.
135.1034 +     *
135.1035 +     * @param magnitude  the parameter providing the magnitude of the result
135.1036 +     * @param sign   the parameter providing the sign of the result
135.1037 +     * @return a value with the magnitude of {@code magnitude}
135.1038 +     * and the sign of {@code sign}.
135.1039 +     * @since 1.6
135.1040 +     */
135.1041 +//    public static double copySign(double magnitude, double sign) {
135.1042 +//        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
135.1043 +//    }
135.1044 +
135.1045 +    /**
135.1046 +     * Returns the first floating-point argument with the sign of the
135.1047 +     * second floating-point argument.  Note that unlike the {@link
135.1048 +     * StrictMath#copySign(float, float) StrictMath.copySign}
135.1049 +     * method, this method does not require NaN {@code sign}
135.1050 +     * arguments to be treated as positive values; implementations are
135.1051 +     * permitted to treat some NaN arguments as positive and other NaN
135.1052 +     * arguments as negative to allow greater performance.
135.1053 +     *
135.1054 +     * @param magnitude  the parameter providing the magnitude of the result
135.1055 +     * @param sign   the parameter providing the sign of the result
135.1056 +     * @return a value with the magnitude of {@code magnitude}
135.1057 +     * and the sign of {@code sign}.
135.1058 +     * @since 1.6
135.1059 +     */
135.1060 +//    public static float copySign(float magnitude, float sign) {
135.1061 +//        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
135.1062 +//    }
135.1063 +
135.1064 +    /**
135.1065 +     * Returns the unbiased exponent used in the representation of a
135.1066 +     * {@code float}.  Special cases:
135.1067 +     *
135.1068 +     * <ul>
135.1069 +     * <li>If the argument is NaN or infinite, then the result is
135.1070 +     * {@link Float#MAX_EXPONENT} + 1.
135.1071 +     * <li>If the argument is zero or subnormal, then the result is
135.1072 +     * {@link Float#MIN_EXPONENT} -1.
135.1073 +     * </ul>
135.1074 +     * @param f a {@code float} value
135.1075 +     * @return the unbiased exponent of the argument
135.1076 +     * @since 1.6
135.1077 +     */
135.1078 +//    public static int getExponent(float f) {
135.1079 +//        return sun.misc.FpUtils.getExponent(f);
135.1080 +//    }
135.1081 +
135.1082 +    /**
135.1083 +     * Returns the unbiased exponent used in the representation of a
135.1084 +     * {@code double}.  Special cases:
135.1085 +     *
135.1086 +     * <ul>
135.1087 +     * <li>If the argument is NaN or infinite, then the result is
135.1088 +     * {@link Double#MAX_EXPONENT} + 1.
135.1089 +     * <li>If the argument is zero or subnormal, then the result is
135.1090 +     * {@link Double#MIN_EXPONENT} -1.
135.1091 +     * </ul>
135.1092 +     * @param d a {@code double} value
135.1093 +     * @return the unbiased exponent of the argument
135.1094 +     * @since 1.6
135.1095 +     */
135.1096 +//    public static int getExponent(double d) {
135.1097 +//        return sun.misc.FpUtils.getExponent(d);
135.1098 +//    }
135.1099 +
135.1100 +    /**
135.1101 +     * Returns the floating-point number adjacent to the first
135.1102 +     * argument in the direction of the second argument.  If both
135.1103 +     * arguments compare as equal the second argument is returned.
135.1104 +     *
135.1105 +     * <p>
135.1106 +     * Special cases:
135.1107 +     * <ul>
135.1108 +     * <li> If either argument is a NaN, then NaN is returned.
135.1109 +     *
135.1110 +     * <li> If both arguments are signed zeros, {@code direction}
135.1111 +     * is returned unchanged (as implied by the requirement of
135.1112 +     * returning the second argument if the arguments compare as
135.1113 +     * equal).
135.1114 +     *
135.1115 +     * <li> If {@code start} is
135.1116 +     * &plusmn;{@link Double#MIN_VALUE} and {@code direction}
135.1117 +     * has a value such that the result should have a smaller
135.1118 +     * magnitude, then a zero with the same sign as {@code start}
135.1119 +     * is returned.
135.1120 +     *
135.1121 +     * <li> If {@code start} is infinite and
135.1122 +     * {@code direction} has a value such that the result should
135.1123 +     * have a smaller magnitude, {@link Double#MAX_VALUE} with the
135.1124 +     * same sign as {@code start} is returned.
135.1125 +     *
135.1126 +     * <li> If {@code start} is equal to &plusmn;
135.1127 +     * {@link Double#MAX_VALUE} and {@code direction} has a
135.1128 +     * value such that the result should have a larger magnitude, an
135.1129 +     * infinity with same sign as {@code start} is returned.
135.1130 +     * </ul>
135.1131 +     *
135.1132 +     * @param start  starting floating-point value
135.1133 +     * @param direction value indicating which of
135.1134 +     * {@code start}'s neighbors or {@code start} should
135.1135 +     * be returned
135.1136 +     * @return The floating-point number adjacent to {@code start} in the
135.1137 +     * direction of {@code direction}.
135.1138 +     * @since 1.6
135.1139 +     */
135.1140 +//    public static double nextAfter(double start, double direction) {
135.1141 +//        return sun.misc.FpUtils.nextAfter(start, direction);
135.1142 +//    }
135.1143 +
135.1144 +    /**
135.1145 +     * Returns the floating-point number adjacent to the first
135.1146 +     * argument in the direction of the second argument.  If both
135.1147 +     * arguments compare as equal a value equivalent to the second argument
135.1148 +     * is returned.
135.1149 +     *
135.1150 +     * <p>
135.1151 +     * Special cases:
135.1152 +     * <ul>
135.1153 +     * <li> If either argument is a NaN, then NaN is returned.
135.1154 +     *
135.1155 +     * <li> If both arguments are signed zeros, a value equivalent
135.1156 +     * to {@code direction} is returned.
135.1157 +     *
135.1158 +     * <li> If {@code start} is
135.1159 +     * &plusmn;{@link Float#MIN_VALUE} and {@code direction}
135.1160 +     * has a value such that the result should have a smaller
135.1161 +     * magnitude, then a zero with the same sign as {@code start}
135.1162 +     * is returned.
135.1163 +     *
135.1164 +     * <li> If {@code start} is infinite and
135.1165 +     * {@code direction} has a value such that the result should
135.1166 +     * have a smaller magnitude, {@link Float#MAX_VALUE} with the
135.1167 +     * same sign as {@code start} is returned.
135.1168 +     *
135.1169 +     * <li> If {@code start} is equal to &plusmn;
135.1170 +     * {@link Float#MAX_VALUE} and {@code direction} has a
135.1171 +     * value such that the result should have a larger magnitude, an
135.1172 +     * infinity with same sign as {@code start} is returned.
135.1173 +     * </ul>
135.1174 +     *
135.1175 +     * @param start  starting floating-point value
135.1176 +     * @param direction value indicating which of
135.1177 +     * {@code start}'s neighbors or {@code start} should
135.1178 +     * be returned
135.1179 +     * @return The floating-point number adjacent to {@code start} in the
135.1180 +     * direction of {@code direction}.
135.1181 +     * @since 1.6
135.1182 +     */
135.1183 +//    public static float nextAfter(float start, double direction) {
135.1184 +//        return sun.misc.FpUtils.nextAfter(start, direction);
135.1185 +//    }
135.1186 +
135.1187 +    /**
135.1188 +     * Returns the floating-point value adjacent to {@code d} in
135.1189 +     * the direction of positive infinity.  This method is
135.1190 +     * semantically equivalent to {@code nextAfter(d,
135.1191 +     * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
135.1192 +     * implementation may run faster than its equivalent
135.1193 +     * {@code nextAfter} call.
135.1194 +     *
135.1195 +     * <p>Special Cases:
135.1196 +     * <ul>
135.1197 +     * <li> If the argument is NaN, the result is NaN.
135.1198 +     *
135.1199 +     * <li> If the argument is positive infinity, the result is
135.1200 +     * positive infinity.
135.1201 +     *
135.1202 +     * <li> If the argument is zero, the result is
135.1203 +     * {@link Double#MIN_VALUE}
135.1204 +     *
135.1205 +     * </ul>
135.1206 +     *
135.1207 +     * @param d starting floating-point value
135.1208 +     * @return The adjacent floating-point value closer to positive
135.1209 +     * infinity.
135.1210 +     * @since 1.6
135.1211 +     */
135.1212 +//    public static double nextUp(double d) {
135.1213 +//        return sun.misc.FpUtils.nextUp(d);
135.1214 +//    }
135.1215 +
135.1216 +    /**
135.1217 +     * Returns the floating-point value adjacent to {@code f} in
135.1218 +     * the direction of positive infinity.  This method is
135.1219 +     * semantically equivalent to {@code nextAfter(f,
135.1220 +     * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
135.1221 +     * implementation may run faster than its equivalent
135.1222 +     * {@code nextAfter} call.
135.1223 +     *
135.1224 +     * <p>Special Cases:
135.1225 +     * <ul>
135.1226 +     * <li> If the argument is NaN, the result is NaN.
135.1227 +     *
135.1228 +     * <li> If the argument is positive infinity, the result is
135.1229 +     * positive infinity.
135.1230 +     *
135.1231 +     * <li> If the argument is zero, the result is
135.1232 +     * {@link Float#MIN_VALUE}
135.1233 +     *
135.1234 +     * </ul>
135.1235 +     *
135.1236 +     * @param f starting floating-point value
135.1237 +     * @return The adjacent floating-point value closer to positive
135.1238 +     * infinity.
135.1239 +     * @since 1.6
135.1240 +     */
135.1241 +//    public static float nextUp(float f) {
135.1242 +//        return sun.misc.FpUtils.nextUp(f);
135.1243 +//    }
135.1244 +
135.1245 +
135.1246 +    /**
135.1247 +     * Return {@code d} &times;
135.1248 +     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
135.1249 +     * by a single correctly rounded floating-point multiply to a
135.1250 +     * member of the double value set.  See the Java
135.1251 +     * Language Specification for a discussion of floating-point
135.1252 +     * value sets.  If the exponent of the result is between {@link
135.1253 +     * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
135.1254 +     * answer is calculated exactly.  If the exponent of the result
135.1255 +     * would be larger than {@code Double.MAX_EXPONENT}, an
135.1256 +     * infinity is returned.  Note that if the result is subnormal,
135.1257 +     * precision may be lost; that is, when {@code scalb(x, n)}
135.1258 +     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
135.1259 +     * <i>x</i>.  When the result is non-NaN, the result has the same
135.1260 +     * sign as {@code d}.
135.1261 +     *
135.1262 +     * <p>Special cases:
135.1263 +     * <ul>
135.1264 +     * <li> If the first argument is NaN, NaN is returned.
135.1265 +     * <li> If the first argument is infinite, then an infinity of the
135.1266 +     * same sign is returned.
135.1267 +     * <li> If the first argument is zero, then a zero of the same
135.1268 +     * sign is returned.
135.1269 +     * </ul>
135.1270 +     *
135.1271 +     * @param d number to be scaled by a power of two.
135.1272 +     * @param scaleFactor power of 2 used to scale {@code d}
135.1273 +     * @return {@code d} &times; 2<sup>{@code scaleFactor}</sup>
135.1274 +     * @since 1.6
135.1275 +     */
135.1276 +//    public static double scalb(double d, int scaleFactor) {
135.1277 +//        return sun.misc.FpUtils.scalb(d, scaleFactor);
135.1278 +//    }
135.1279 +
135.1280 +    /**
135.1281 +     * Return {@code f} &times;
135.1282 +     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
135.1283 +     * by a single correctly rounded floating-point multiply to a
135.1284 +     * member of the float value set.  See the Java
135.1285 +     * Language Specification for a discussion of floating-point
135.1286 +     * value sets.  If the exponent of the result is between {@link
135.1287 +     * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
135.1288 +     * answer is calculated exactly.  If the exponent of the result
135.1289 +     * would be larger than {@code Float.MAX_EXPONENT}, an
135.1290 +     * infinity is returned.  Note that if the result is subnormal,
135.1291 +     * precision may be lost; that is, when {@code scalb(x, n)}
135.1292 +     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
135.1293 +     * <i>x</i>.  When the result is non-NaN, the result has the same
135.1294 +     * sign as {@code f}.
135.1295 +     *
135.1296 +     * <p>Special cases:
135.1297 +     * <ul>
135.1298 +     * <li> If the first argument is NaN, NaN is returned.
135.1299 +     * <li> If the first argument is infinite, then an infinity of the
135.1300 +     * same sign is returned.
135.1301 +     * <li> If the first argument is zero, then a zero of the same
135.1302 +     * sign is returned.
135.1303 +     * </ul>
135.1304 +     *
135.1305 +     * @param f number to be scaled by a power of two.
135.1306 +     * @param scaleFactor power of 2 used to scale {@code f}
135.1307 +     * @return {@code f} &times; 2<sup>{@code scaleFactor}</sup>
135.1308 +     * @since 1.6
135.1309 +     */
135.1310 +//    public static float scalb(float f, int scaleFactor) {
135.1311 +//        return sun.misc.FpUtils.scalb(f, scaleFactor);
135.1312 +//    }
135.1313 +}
   136.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   136.2 +++ b/emul/mini/src/main/java/java/lang/NegativeArraySizeException.java	Sun Feb 03 07:48:42 2013 +0100
   136.3 @@ -0,0 +1,55 @@
   136.4 +/*
   136.5 + * Copyright (c) 1994, 2008, 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 +/**
  136.32 + * Thrown if an application tries to create an array with negative size.
  136.33 + *
  136.34 + * @author  unascribed
  136.35 + * @since   JDK1.0
  136.36 + */
  136.37 +public
  136.38 +class NegativeArraySizeException extends RuntimeException {
  136.39 +    private static final long serialVersionUID = -8960118058596991861L;
  136.40 +
  136.41 +    /**
  136.42 +     * Constructs a <code>NegativeArraySizeException</code> with no
  136.43 +     * detail message.
  136.44 +     */
  136.45 +    public NegativeArraySizeException() {
  136.46 +        super();
  136.47 +    }
  136.48 +
  136.49 +    /**
  136.50 +     * Constructs a <code>NegativeArraySizeException</code> with the
  136.51 +     * specified detail message.
  136.52 +     *
  136.53 +     * @param   s   the detail message.
  136.54 +     */
  136.55 +    public NegativeArraySizeException(String s) {
  136.56 +        super(s);
  136.57 +    }
  136.58 +}
   137.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   137.2 +++ b/emul/mini/src/main/java/java/lang/NoSuchMethodException.java	Sun Feb 03 07:48:42 2013 +0100
   137.3 @@ -0,0 +1,53 @@
   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 particular method cannot be found.
  137.33 + *
  137.34 + * @author     unascribed
  137.35 + * @since      JDK1.0
  137.36 + */
  137.37 +public
  137.38 +class NoSuchMethodException extends ReflectiveOperationException {
  137.39 +    private static final long serialVersionUID = 5034388446362600923L;
  137.40 +
  137.41 +    /**
  137.42 +     * Constructs a <code>NoSuchMethodException</code> without a detail message.
  137.43 +     */
  137.44 +    public NoSuchMethodException() {
  137.45 +        super();
  137.46 +    }
  137.47 +
  137.48 +    /**
  137.49 +     * Constructs a <code>NoSuchMethodException</code> with a detail message.
  137.50 +     *
  137.51 +     * @param      s   the detail message.
  137.52 +     */
  137.53 +    public NoSuchMethodException(String s) {
  137.54 +        super(s);
  137.55 +    }
  137.56 +}
   138.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   138.2 +++ b/emul/mini/src/main/java/java/lang/NullPointerException.java	Sun Feb 03 07:48:42 2013 +0100
   138.3 @@ -0,0 +1,72 @@
   138.4 +/*
   138.5 + * Copyright (c) 1994, 2011, 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 + * Thrown when an application attempts to use {@code null} in a
  138.33 + * case where an object is required. These include:
  138.34 + * <ul>
  138.35 + * <li>Calling the instance method of a {@code null} object.
  138.36 + * <li>Accessing or modifying the field of a {@code null} object.
  138.37 + * <li>Taking the length of {@code null} as if it were an array.
  138.38 + * <li>Accessing or modifying the slots of {@code null} as if it
  138.39 + *     were an array.
  138.40 + * <li>Throwing {@code null} as if it were a {@code Throwable}
  138.41 + *     value.
  138.42 + * </ul>
  138.43 + * <p>
  138.44 + * Applications should throw instances of this class to indicate
  138.45 + * other illegal uses of the {@code null} object.
  138.46 + *
  138.47 + * {@code NullPointerException} objects may be constructed by the
  138.48 + * virtual machine as if {@linkplain Throwable#Throwable(String,
  138.49 + * Throwable, boolean, boolean) suppression were disabled and/or the
  138.50 + * stack trace was not writable}.
  138.51 + *
  138.52 + * @author  unascribed
  138.53 + * @since   JDK1.0
  138.54 + */
  138.55 +public
  138.56 +class NullPointerException extends RuntimeException {
  138.57 +    private static final long serialVersionUID = 5162710183389028792L;
  138.58 +
  138.59 +    /**
  138.60 +     * Constructs a {@code NullPointerException} with no detail message.
  138.61 +     */
  138.62 +    public NullPointerException() {
  138.63 +        super();
  138.64 +    }
  138.65 +
  138.66 +    /**
  138.67 +     * Constructs a {@code NullPointerException} with the specified
  138.68 +     * detail message.
  138.69 +     *
  138.70 +     * @param   s   the detail message.
  138.71 +     */
  138.72 +    public NullPointerException(String s) {
  138.73 +        super(s);
  138.74 +    }
  138.75 +}
   139.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   139.2 +++ b/emul/mini/src/main/java/java/lang/Number.java	Sun Feb 03 07:48:42 2013 +0100
   139.3 @@ -0,0 +1,118 @@
   139.4 +/*
   139.5 + * Copyright (c) 1994, 2001, 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.ExtraJavaScript;
  139.32 +
  139.33 +/**
  139.34 + * The abstract class <code>Number</code> is the superclass of classes
  139.35 + * <code>BigDecimal</code>, <code>BigInteger</code>,
  139.36 + * <code>Byte</code>, <code>Double</code>, <code>Float</code>,
  139.37 + * <code>Integer</code>, <code>Long</code>, and <code>Short</code>.
  139.38 + * <p>
  139.39 + * Subclasses of <code>Number</code> must provide methods to convert
  139.40 + * the represented numeric value to <code>byte</code>, <code>double</code>,
  139.41 + * <code>float</code>, <code>int</code>, <code>long</code>, and
  139.42 + * <code>short</code>.
  139.43 + *
  139.44 + * @author      Lee Boynton
  139.45 + * @author      Arthur van Hoff
  139.46 + * @see     java.lang.Byte
  139.47 + * @see     java.lang.Double
  139.48 + * @see     java.lang.Float
  139.49 + * @see     java.lang.Integer
  139.50 + * @see     java.lang.Long
  139.51 + * @see     java.lang.Short
  139.52 + * @since   JDK1.0
  139.53 + */
  139.54 +@ExtraJavaScript(
  139.55 +    resource="/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js",
  139.56 +    processByteCode=true
  139.57 +)
  139.58 +public abstract class Number implements java.io.Serializable {
  139.59 +    /**
  139.60 +     * Returns the value of the specified number as an <code>int</code>.
  139.61 +     * This may involve rounding or truncation.
  139.62 +     *
  139.63 +     * @return  the numeric value represented by this object after conversion
  139.64 +     *          to type <code>int</code>.
  139.65 +     */
  139.66 +    public abstract int intValue();
  139.67 +
  139.68 +    /**
  139.69 +     * Returns the value of the specified number as a <code>long</code>.
  139.70 +     * This may involve rounding or truncation.
  139.71 +     *
  139.72 +     * @return  the numeric value represented by this object after conversion
  139.73 +     *          to type <code>long</code>.
  139.74 +     */
  139.75 +    public abstract long longValue();
  139.76 +
  139.77 +    /**
  139.78 +     * Returns the value of the specified number as a <code>float</code>.
  139.79 +     * This may involve rounding.
  139.80 +     *
  139.81 +     * @return  the numeric value represented by this object after conversion
  139.82 +     *          to type <code>float</code>.
  139.83 +     */
  139.84 +    public abstract float floatValue();
  139.85 +
  139.86 +    /**
  139.87 +     * Returns the value of the specified number as a <code>double</code>.
  139.88 +     * This may involve rounding.
  139.89 +     *
  139.90 +     * @return  the numeric value represented by this object after conversion
  139.91 +     *          to type <code>double</code>.
  139.92 +     */
  139.93 +    public abstract double doubleValue();
  139.94 +
  139.95 +    /**
  139.96 +     * Returns the value of the specified number as a <code>byte</code>.
  139.97 +     * This may involve rounding or truncation.
  139.98 +     *
  139.99 +     * @return  the numeric value represented by this object after conversion
 139.100 +     *          to type <code>byte</code>.
 139.101 +     * @since   JDK1.1
 139.102 +     */
 139.103 +    public byte byteValue() {
 139.104 +        return (byte)intValue();
 139.105 +    }
 139.106 +
 139.107 +    /**
 139.108 +     * Returns the value of the specified number as a <code>short</code>.
 139.109 +     * This may involve rounding or truncation.
 139.110 +     *
 139.111 +     * @return  the numeric value represented by this object after conversion
 139.112 +     *          to type <code>short</code>.
 139.113 +     * @since   JDK1.1
 139.114 +     */
 139.115 +    public short shortValue() {
 139.116 +        return (short)intValue();
 139.117 +    }
 139.118 +
 139.119 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 139.120 +    private static final long serialVersionUID = -8742448824652078965L;
 139.121 +}
   140.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   140.2 +++ b/emul/mini/src/main/java/java/lang/NumberFormatException.java	Sun Feb 03 07:48:42 2013 +0100
   140.3 @@ -0,0 +1,67 @@
   140.4 +/*
   140.5 + * Copyright (c) 1994, 2001, 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 +/**
  140.32 + * Thrown to indicate that the application has attempted to convert
  140.33 + * a string to one of the numeric types, but that the string does not
  140.34 + * have the appropriate format.
  140.35 + *
  140.36 + * @author  unascribed
  140.37 + * @see     java.lang.Integer#toString()
  140.38 + * @since   JDK1.0
  140.39 + */
  140.40 +public
  140.41 +class NumberFormatException extends IllegalArgumentException {
  140.42 +    static final long serialVersionUID = -2848938806368998894L;
  140.43 +
  140.44 +    /**
  140.45 +     * Constructs a <code>NumberFormatException</code> with no detail message.
  140.46 +     */
  140.47 +    public NumberFormatException () {
  140.48 +        super();
  140.49 +    }
  140.50 +
  140.51 +    /**
  140.52 +     * Constructs a <code>NumberFormatException</code> with the
  140.53 +     * specified detail message.
  140.54 +     *
  140.55 +     * @param   s   the detail message.
  140.56 +     */
  140.57 +    public NumberFormatException (String s) {
  140.58 +        super (s);
  140.59 +    }
  140.60 +
  140.61 +    /**
  140.62 +     * Factory method for making a <code>NumberFormatException</code>
  140.63 +     * given the specified input which caused the error.
  140.64 +     *
  140.65 +     * @param   s   the input causing the error
  140.66 +     */
  140.67 +    static NumberFormatException forInputString(String s) {
  140.68 +        return new NumberFormatException("For input string: \"" + s + "\"");
  140.69 +    }
  140.70 +}
   141.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   141.2 +++ b/emul/mini/src/main/java/java/lang/Object.java	Sun Feb 03 07:48:42 2013 +0100
   141.3 @@ -0,0 +1,595 @@
   141.4 +/*
   141.5 + * Copyright (c) 1994, 2010, 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 +import java.lang.reflect.Array;
  141.32 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  141.33 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  141.34 +
  141.35 +/**
  141.36 + * Class {@code Object} is the root of the class hierarchy.
  141.37 + * Every class has {@code Object} as a superclass. All objects,
  141.38 + * including arrays, implement the methods of this class.
  141.39 + *
  141.40 + * @author  unascribed
  141.41 + * @see     java.lang.Class
  141.42 + * @since   JDK1.0
  141.43 + */
  141.44 +@JavaScriptPrototype(container = "Object.prototype", prototype = "new Object")
  141.45 +public class Object {
  141.46 +
  141.47 +    private static void registerNatives() {
  141.48 +        try {
  141.49 +            Array.get(null, 0);
  141.50 +        } catch (Throwable ex) {
  141.51 +            // ignore
  141.52 +        }
  141.53 +    }
  141.54 +    static {
  141.55 +        registerNatives();
  141.56 +    }
  141.57 +
  141.58 +    /**
  141.59 +     * Returns the runtime class of this {@code Object}. The returned
  141.60 +     * {@code Class} object is the object that is locked by {@code
  141.61 +     * static synchronized} methods of the represented class.
  141.62 +     *
  141.63 +     * <p><b>The actual result type is {@code Class<? extends |X|>}
  141.64 +     * where {@code |X|} is the erasure of the static type of the
  141.65 +     * expression on which {@code getClass} is called.</b> For
  141.66 +     * example, no cast is required in this code fragment:</p>
  141.67 +     *
  141.68 +     * <p>
  141.69 +     * {@code Number n = 0;                             }<br>
  141.70 +     * {@code Class<? extends Number> c = n.getClass(); }
  141.71 +     * </p>
  141.72 +     *
  141.73 +     * @return The {@code Class} object that represents the runtime
  141.74 +     *         class of this object.
  141.75 +     * @see    Class Literals, section 15.8.2 of
  141.76 +     *         <cite>The Java&trade; Language Specification</cite>.
  141.77 +     */
  141.78 +    @JavaScriptBody(args={}, body="return this.constructor.$class;")
  141.79 +    public final native Class<?> getClass();
  141.80 +
  141.81 +    /**
  141.82 +     * Returns a hash code value for the object. This method is
  141.83 +     * supported for the benefit of hash tables such as those provided by
  141.84 +     * {@link java.util.HashMap}.
  141.85 +     * <p>
  141.86 +     * The general contract of {@code hashCode} is:
  141.87 +     * <ul>
  141.88 +     * <li>Whenever it is invoked on the same object more than once during
  141.89 +     *     an execution of a Java application, the {@code hashCode} method
  141.90 +     *     must consistently return the same integer, provided no information
  141.91 +     *     used in {@code equals} comparisons on the object is modified.
  141.92 +     *     This integer need not remain consistent from one execution of an
  141.93 +     *     application to another execution of the same application.
  141.94 +     * <li>If two objects are equal according to the {@code equals(Object)}
  141.95 +     *     method, then calling the {@code hashCode} method on each of
  141.96 +     *     the two objects must produce the same integer result.
  141.97 +     * <li>It is <em>not</em> required that if two objects are unequal
  141.98 +     *     according to the {@link java.lang.Object#equals(java.lang.Object)}
  141.99 +     *     method, then calling the {@code hashCode} method on each of the
 141.100 +     *     two objects must produce distinct integer results.  However, the
 141.101 +     *     programmer should be aware that producing distinct integer results
 141.102 +     *     for unequal objects may improve the performance of hash tables.
 141.103 +     * </ul>
 141.104 +     * <p>
 141.105 +     * As much as is reasonably practical, the hashCode method defined by
 141.106 +     * class {@code Object} does return distinct integers for distinct
 141.107 +     * objects. (This is typically implemented by converting the internal
 141.108 +     * address of the object into an integer, but this implementation
 141.109 +     * technique is not required by the
 141.110 +     * Java<font size="-2"><sup>TM</sup></font> programming language.)
 141.111 +     *
 141.112 +     * @return  a hash code value for this object.
 141.113 +     * @see     java.lang.Object#equals(java.lang.Object)
 141.114 +     * @see     java.lang.System#identityHashCode
 141.115 +     */
 141.116 +    @JavaScriptBody(args = {}, body = 
 141.117 +        "if (this.$hashCode) return this.$hashCode;\n"
 141.118 +        + "var h = this.computeHashCode__I();\n"
 141.119 +        + "return this.$hashCode = h & h;"
 141.120 +    )
 141.121 +    public native int hashCode();
 141.122 +
 141.123 +    @JavaScriptBody(args = {}, body = "Math.random() * Math.pow(2, 32);")
 141.124 +    native int computeHashCode();
 141.125 +    
 141.126 +    /**
 141.127 +     * Indicates whether some other object is "equal to" this one.
 141.128 +     * <p>
 141.129 +     * The {@code equals} method implements an equivalence relation
 141.130 +     * on non-null object references:
 141.131 +     * <ul>
 141.132 +     * <li>It is <i>reflexive</i>: for any non-null reference value
 141.133 +     *     {@code x}, {@code x.equals(x)} should return
 141.134 +     *     {@code true}.
 141.135 +     * <li>It is <i>symmetric</i>: for any non-null reference values
 141.136 +     *     {@code x} and {@code y}, {@code x.equals(y)}
 141.137 +     *     should return {@code true} if and only if
 141.138 +     *     {@code y.equals(x)} returns {@code true}.
 141.139 +     * <li>It is <i>transitive</i>: for any non-null reference values
 141.140 +     *     {@code x}, {@code y}, and {@code z}, if
 141.141 +     *     {@code x.equals(y)} returns {@code true} and
 141.142 +     *     {@code y.equals(z)} returns {@code true}, then
 141.143 +     *     {@code x.equals(z)} should return {@code true}.
 141.144 +     * <li>It is <i>consistent</i>: for any non-null reference values
 141.145 +     *     {@code x} and {@code y}, multiple invocations of
 141.146 +     *     {@code x.equals(y)} consistently return {@code true}
 141.147 +     *     or consistently return {@code false}, provided no
 141.148 +     *     information used in {@code equals} comparisons on the
 141.149 +     *     objects is modified.
 141.150 +     * <li>For any non-null reference value {@code x},
 141.151 +     *     {@code x.equals(null)} should return {@code false}.
 141.152 +     * </ul>
 141.153 +     * <p>
 141.154 +     * The {@code equals} method for class {@code Object} implements
 141.155 +     * the most discriminating possible equivalence relation on objects;
 141.156 +     * that is, for any non-null reference values {@code x} and
 141.157 +     * {@code y}, this method returns {@code true} if and only
 141.158 +     * if {@code x} and {@code y} refer to the same object
 141.159 +     * ({@code x == y} has the value {@code true}).
 141.160 +     * <p>
 141.161 +     * Note that it is generally necessary to override the {@code hashCode}
 141.162 +     * method whenever this method is overridden, so as to maintain the
 141.163 +     * general contract for the {@code hashCode} method, which states
 141.164 +     * that equal objects must have equal hash codes.
 141.165 +     *
 141.166 +     * @param   obj   the reference object with which to compare.
 141.167 +     * @return  {@code true} if this object is the same as the obj
 141.168 +     *          argument; {@code false} otherwise.
 141.169 +     * @see     #hashCode()
 141.170 +     * @see     java.util.HashMap
 141.171 +     */
 141.172 +    public boolean equals(Object obj) {
 141.173 +        return (this == obj);
 141.174 +    }
 141.175 +
 141.176 +    /**
 141.177 +     * Creates and returns a copy of this object.  The precise meaning
 141.178 +     * of "copy" may depend on the class of the object. The general
 141.179 +     * intent is that, for any object {@code x}, the expression:
 141.180 +     * <blockquote>
 141.181 +     * <pre>
 141.182 +     * x.clone() != x</pre></blockquote>
 141.183 +     * will be true, and that the expression:
 141.184 +     * <blockquote>
 141.185 +     * <pre>
 141.186 +     * x.clone().getClass() == x.getClass()</pre></blockquote>
 141.187 +     * will be {@code true}, but these are not absolute requirements.
 141.188 +     * While it is typically the case that:
 141.189 +     * <blockquote>
 141.190 +     * <pre>
 141.191 +     * x.clone().equals(x)</pre></blockquote>
 141.192 +     * will be {@code true}, this is not an absolute requirement.
 141.193 +     * <p>
 141.194 +     * By convention, the returned object should be obtained by calling
 141.195 +     * {@code super.clone}.  If a class and all of its superclasses (except
 141.196 +     * {@code Object}) obey this convention, it will be the case that
 141.197 +     * {@code x.clone().getClass() == x.getClass()}.
 141.198 +     * <p>
 141.199 +     * By convention, the object returned by this method should be independent
 141.200 +     * of this object (which is being cloned).  To achieve this independence,
 141.201 +     * it may be necessary to modify one or more fields of the object returned
 141.202 +     * by {@code super.clone} before returning it.  Typically, this means
 141.203 +     * copying any mutable objects that comprise the internal "deep structure"
 141.204 +     * of the object being cloned and replacing the references to these
 141.205 +     * objects with references to the copies.  If a class contains only
 141.206 +     * primitive fields or references to immutable objects, then it is usually
 141.207 +     * the case that no fields in the object returned by {@code super.clone}
 141.208 +     * need to be modified.
 141.209 +     * <p>
 141.210 +     * The method {@code clone} for class {@code Object} performs a
 141.211 +     * specific cloning operation. First, if the class of this object does
 141.212 +     * not implement the interface {@code Cloneable}, then a
 141.213 +     * {@code CloneNotSupportedException} is thrown. Note that all arrays
 141.214 +     * are considered to implement the interface {@code Cloneable} and that
 141.215 +     * the return type of the {@code clone} method of an array type {@code T[]}
 141.216 +     * is {@code T[]} where T is any reference or primitive type.
 141.217 +     * Otherwise, this method creates a new instance of the class of this
 141.218 +     * object and initializes all its fields with exactly the contents of
 141.219 +     * the corresponding fields of this object, as if by assignment; the
 141.220 +     * contents of the fields are not themselves cloned. Thus, this method
 141.221 +     * performs a "shallow copy" of this object, not a "deep copy" operation.
 141.222 +     * <p>
 141.223 +     * The class {@code Object} does not itself implement the interface
 141.224 +     * {@code Cloneable}, so calling the {@code clone} method on an object
 141.225 +     * whose class is {@code Object} will result in throwing an
 141.226 +     * exception at run time.
 141.227 +     *
 141.228 +     * @return     a clone of this instance.
 141.229 +     * @exception  CloneNotSupportedException  if the object's class does not
 141.230 +     *               support the {@code Cloneable} interface. Subclasses
 141.231 +     *               that override the {@code clone} method can also
 141.232 +     *               throw this exception to indicate that an instance cannot
 141.233 +     *               be cloned.
 141.234 +     * @see java.lang.Cloneable
 141.235 +     */
 141.236 +    protected Object clone() throws CloneNotSupportedException {
 141.237 +        Object ret = clone(this);
 141.238 +        if (ret == null) {
 141.239 +            throw new CloneNotSupportedException(getClass().getName());
 141.240 +        }
 141.241 +        return ret;
 141.242 +    }
 141.243 +
 141.244 +    @JavaScriptBody(args = "self", body = 
 141.245 +          "\nif (!self.$instOf_java_lang_Cloneable) {"
 141.246 +        + "\n  return null;"
 141.247 +        + "\n} else {"
 141.248 +        + "\n  var clone = self.constructor(true);"
 141.249 +        + "\n  var props = Object.getOwnPropertyNames(self);"
 141.250 +        + "\n  for (var i = 0; i < props.length; i++) {"
 141.251 +        + "\n    var p = props[i];"
 141.252 +        + "\n    clone[p] = self[p];"
 141.253 +        + "\n  };"
 141.254 +        + "\n  return clone;"
 141.255 +        + "\n}"
 141.256 +    )
 141.257 +    private static native Object clone(Object self) throws CloneNotSupportedException;
 141.258 +
 141.259 +    /**
 141.260 +     * Returns a string representation of the object. In general, the
 141.261 +     * {@code toString} method returns a string that
 141.262 +     * "textually represents" this object. The result should
 141.263 +     * be a concise but informative representation that is easy for a
 141.264 +     * person to read.
 141.265 +     * It is recommended that all subclasses override this method.
 141.266 +     * <p>
 141.267 +     * The {@code toString} method for class {@code Object}
 141.268 +     * returns a string consisting of the name of the class of which the
 141.269 +     * object is an instance, the at-sign character `{@code @}', and
 141.270 +     * the unsigned hexadecimal representation of the hash code of the
 141.271 +     * object. In other words, this method returns a string equal to the
 141.272 +     * value of:
 141.273 +     * <blockquote>
 141.274 +     * <pre>
 141.275 +     * getClass().getName() + '@' + Integer.toHexString(hashCode())
 141.276 +     * </pre></blockquote>
 141.277 +     *
 141.278 +     * @return  a string representation of the object.
 141.279 +     */
 141.280 +    public String toString() {
 141.281 +        return getClass().getName() + "@" + Integer.toHexString(hashCode());
 141.282 +    }
 141.283 +
 141.284 +    /**
 141.285 +     * Wakes up a single thread that is waiting on this object's
 141.286 +     * monitor. If any threads are waiting on this object, one of them
 141.287 +     * is chosen to be awakened. The choice is arbitrary and occurs at
 141.288 +     * the discretion of the implementation. A thread waits on an object's
 141.289 +     * monitor by calling one of the {@code wait} methods.
 141.290 +     * <p>
 141.291 +     * The awakened thread will not be able to proceed until the current
 141.292 +     * thread relinquishes the lock on this object. The awakened thread will
 141.293 +     * compete in the usual manner with any other threads that might be
 141.294 +     * actively competing to synchronize on this object; for example, the
 141.295 +     * awakened thread enjoys no reliable privilege or disadvantage in being
 141.296 +     * the next thread to lock this object.
 141.297 +     * <p>
 141.298 +     * This method should only be called by a thread that is the owner
 141.299 +     * of this object's monitor. A thread becomes the owner of the
 141.300 +     * object's monitor in one of three ways:
 141.301 +     * <ul>
 141.302 +     * <li>By executing a synchronized instance method of that object.
 141.303 +     * <li>By executing the body of a {@code synchronized} statement
 141.304 +     *     that synchronizes on the object.
 141.305 +     * <li>For objects of type {@code Class,} by executing a
 141.306 +     *     synchronized static method of that class.
 141.307 +     * </ul>
 141.308 +     * <p>
 141.309 +     * Only one thread at a time can own an object's monitor.
 141.310 +     *
 141.311 +     * @exception  IllegalMonitorStateException  if the current thread is not
 141.312 +     *               the owner of this object's monitor.
 141.313 +     * @see        java.lang.Object#notifyAll()
 141.314 +     * @see        java.lang.Object#wait()
 141.315 +     */
 141.316 +    public final native void notify();
 141.317 +
 141.318 +    /**
 141.319 +     * Wakes up all threads that are waiting on this object's monitor. A
 141.320 +     * thread waits on an object's monitor by calling one of the
 141.321 +     * {@code wait} methods.
 141.322 +     * <p>
 141.323 +     * The awakened threads will not be able to proceed until the current
 141.324 +     * thread relinquishes the lock on this object. The awakened threads
 141.325 +     * will compete in the usual manner with any other threads that might
 141.326 +     * be actively competing to synchronize on this object; for example,
 141.327 +     * the awakened threads enjoy no reliable privilege or disadvantage in
 141.328 +     * being the next thread to lock this object.
 141.329 +     * <p>
 141.330 +     * This method should only be called by a thread that is the owner
 141.331 +     * of this object's monitor. See the {@code notify} method for a
 141.332 +     * description of the ways in which a thread can become the owner of
 141.333 +     * a monitor.
 141.334 +     *
 141.335 +     * @exception  IllegalMonitorStateException  if the current thread is not
 141.336 +     *               the owner of this object's monitor.
 141.337 +     * @see        java.lang.Object#notify()
 141.338 +     * @see        java.lang.Object#wait()
 141.339 +     */
 141.340 +    public final native void notifyAll();
 141.341 +
 141.342 +    /**
 141.343 +     * Causes the current thread to wait until either another thread invokes the
 141.344 +     * {@link java.lang.Object#notify()} method or the
 141.345 +     * {@link java.lang.Object#notifyAll()} method for this object, or a
 141.346 +     * specified amount of time has elapsed.
 141.347 +     * <p>
 141.348 +     * The current thread must own this object's monitor.
 141.349 +     * <p>
 141.350 +     * This method causes the current thread (call it <var>T</var>) to
 141.351 +     * place itself in the wait set for this object and then to relinquish
 141.352 +     * any and all synchronization claims on this object. Thread <var>T</var>
 141.353 +     * becomes disabled for thread scheduling purposes and lies dormant
 141.354 +     * until one of four things happens:
 141.355 +     * <ul>
 141.356 +     * <li>Some other thread invokes the {@code notify} method for this
 141.357 +     * object and thread <var>T</var> happens to be arbitrarily chosen as
 141.358 +     * the thread to be awakened.
 141.359 +     * <li>Some other thread invokes the {@code notifyAll} method for this
 141.360 +     * object.
 141.361 +     * <li>Some other thread {@linkplain Thread#interrupt() interrupts}
 141.362 +     * thread <var>T</var>.
 141.363 +     * <li>The specified amount of real time has elapsed, more or less.  If
 141.364 +     * {@code timeout} is zero, however, then real time is not taken into
 141.365 +     * consideration and the thread simply waits until notified.
 141.366 +     * </ul>
 141.367 +     * The thread <var>T</var> is then removed from the wait set for this
 141.368 +     * object and re-enabled for thread scheduling. It then competes in the
 141.369 +     * usual manner with other threads for the right to synchronize on the
 141.370 +     * object; once it has gained control of the object, all its
 141.371 +     * synchronization claims on the object are restored to the status quo
 141.372 +     * ante - that is, to the situation as of the time that the {@code wait}
 141.373 +     * method was invoked. Thread <var>T</var> then returns from the
 141.374 +     * invocation of the {@code wait} method. Thus, on return from the
 141.375 +     * {@code wait} method, the synchronization state of the object and of
 141.376 +     * thread {@code T} is exactly as it was when the {@code wait} method
 141.377 +     * was invoked.
 141.378 +     * <p>
 141.379 +     * A thread can also wake up without being notified, interrupted, or
 141.380 +     * timing out, a so-called <i>spurious wakeup</i>.  While this will rarely
 141.381 +     * occur in practice, applications must guard against it by testing for
 141.382 +     * the condition that should have caused the thread to be awakened, and
 141.383 +     * continuing to wait if the condition is not satisfied.  In other words,
 141.384 +     * waits should always occur in loops, like this one:
 141.385 +     * <pre>
 141.386 +     *     synchronized (obj) {
 141.387 +     *         while (&lt;condition does not hold&gt;)
 141.388 +     *             obj.wait(timeout);
 141.389 +     *         ... // Perform action appropriate to condition
 141.390 +     *     }
 141.391 +     * </pre>
 141.392 +     * (For more information on this topic, see Section 3.2.3 in Doug Lea's
 141.393 +     * "Concurrent Programming in Java (Second Edition)" (Addison-Wesley,
 141.394 +     * 2000), or Item 50 in Joshua Bloch's "Effective Java Programming
 141.395 +     * Language Guide" (Addison-Wesley, 2001).
 141.396 +     *
 141.397 +     * <p>If the current thread is {@linkplain java.lang.Thread#interrupt()
 141.398 +     * interrupted} by any thread before or while it is waiting, then an
 141.399 +     * {@code InterruptedException} is thrown.  This exception is not
 141.400 +     * thrown until the lock status of this object has been restored as
 141.401 +     * described above.
 141.402 +     *
 141.403 +     * <p>
 141.404 +     * Note that the {@code wait} method, as it places the current thread
 141.405 +     * into the wait set for this object, unlocks only this object; any
 141.406 +     * other objects on which the current thread may be synchronized remain
 141.407 +     * locked while the thread waits.
 141.408 +     * <p>
 141.409 +     * This method should only be called by a thread that is the owner
 141.410 +     * of this object's monitor. See the {@code notify} method for a
 141.411 +     * description of the ways in which a thread can become the owner of
 141.412 +     * a monitor.
 141.413 +     *
 141.414 +     * @param      timeout   the maximum time to wait in milliseconds.
 141.415 +     * @exception  IllegalArgumentException      if the value of timeout is
 141.416 +     *               negative.
 141.417 +     * @exception  IllegalMonitorStateException  if the current thread is not
 141.418 +     *               the owner of the object's monitor.
 141.419 +     * @exception  InterruptedException if any thread interrupted the
 141.420 +     *             current thread before or while the current thread
 141.421 +     *             was waiting for a notification.  The <i>interrupted
 141.422 +     *             status</i> of the current thread is cleared when
 141.423 +     *             this exception is thrown.
 141.424 +     * @see        java.lang.Object#notify()
 141.425 +     * @see        java.lang.Object#notifyAll()
 141.426 +     */
 141.427 +    public final native void wait(long timeout) throws InterruptedException;
 141.428 +
 141.429 +    /**
 141.430 +     * Causes the current thread to wait until another thread invokes the
 141.431 +     * {@link java.lang.Object#notify()} method or the
 141.432 +     * {@link java.lang.Object#notifyAll()} method for this object, or
 141.433 +     * some other thread interrupts the current thread, or a certain
 141.434 +     * amount of real time has elapsed.
 141.435 +     * <p>
 141.436 +     * This method is similar to the {@code wait} method of one
 141.437 +     * argument, but it allows finer control over the amount of time to
 141.438 +     * wait for a notification before giving up. The amount of real time,
 141.439 +     * measured in nanoseconds, is given by:
 141.440 +     * <blockquote>
 141.441 +     * <pre>
 141.442 +     * 1000000*timeout+nanos</pre></blockquote>
 141.443 +     * <p>
 141.444 +     * In all other respects, this method does the same thing as the
 141.445 +     * method {@link #wait(long)} of one argument. In particular,
 141.446 +     * {@code wait(0, 0)} means the same thing as {@code wait(0)}.
 141.447 +     * <p>
 141.448 +     * The current thread must own this object's monitor. The thread
 141.449 +     * releases ownership of this monitor and waits until either of the
 141.450 +     * following two conditions has occurred:
 141.451 +     * <ul>
 141.452 +     * <li>Another thread notifies threads waiting on this object's monitor
 141.453 +     *     to wake up either through a call to the {@code notify} method
 141.454 +     *     or the {@code notifyAll} method.
 141.455 +     * <li>The timeout period, specified by {@code timeout}
 141.456 +     *     milliseconds plus {@code nanos} nanoseconds arguments, has
 141.457 +     *     elapsed.
 141.458 +     * </ul>
 141.459 +     * <p>
 141.460 +     * The thread then waits until it can re-obtain ownership of the
 141.461 +     * monitor and resumes execution.
 141.462 +     * <p>
 141.463 +     * As in the one argument version, interrupts and spurious wakeups are
 141.464 +     * possible, and this method should always be used in a loop:
 141.465 +     * <pre>
 141.466 +     *     synchronized (obj) {
 141.467 +     *         while (&lt;condition does not hold&gt;)
 141.468 +     *             obj.wait(timeout, nanos);
 141.469 +     *         ... // Perform action appropriate to condition
 141.470 +     *     }
 141.471 +     * </pre>
 141.472 +     * This method should only be called by a thread that is the owner
 141.473 +     * of this object's monitor. See the {@code notify} method for a
 141.474 +     * description of the ways in which a thread can become the owner of
 141.475 +     * a monitor.
 141.476 +     *
 141.477 +     * @param      timeout   the maximum time to wait in milliseconds.
 141.478 +     * @param      nanos      additional time, in nanoseconds range
 141.479 +     *                       0-999999.
 141.480 +     * @exception  IllegalArgumentException      if the value of timeout is
 141.481 +     *                      negative or the value of nanos is
 141.482 +     *                      not in the range 0-999999.
 141.483 +     * @exception  IllegalMonitorStateException  if the current thread is not
 141.484 +     *               the owner of this object's monitor.
 141.485 +     * @exception  InterruptedException if any thread interrupted the
 141.486 +     *             current thread before or while the current thread
 141.487 +     *             was waiting for a notification.  The <i>interrupted
 141.488 +     *             status</i> of the current thread is cleared when
 141.489 +     *             this exception is thrown.
 141.490 +     */
 141.491 +    public final void wait(long timeout, int nanos) throws InterruptedException {
 141.492 +        if (timeout < 0) {
 141.493 +            throw new IllegalArgumentException("timeout value is negative");
 141.494 +        }
 141.495 +
 141.496 +        if (nanos < 0 || nanos > 999999) {
 141.497 +            throw new IllegalArgumentException(
 141.498 +                                "nanosecond timeout value out of range");
 141.499 +        }
 141.500 +
 141.501 +        if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
 141.502 +            timeout++;
 141.503 +        }
 141.504 +
 141.505 +        wait(timeout);
 141.506 +    }
 141.507 +
 141.508 +    /**
 141.509 +     * Causes the current thread to wait until another thread invokes the
 141.510 +     * {@link java.lang.Object#notify()} method or the
 141.511 +     * {@link java.lang.Object#notifyAll()} method for this object.
 141.512 +     * In other words, this method behaves exactly as if it simply
 141.513 +     * performs the call {@code wait(0)}.
 141.514 +     * <p>
 141.515 +     * The current thread must own this object's monitor. The thread
 141.516 +     * releases ownership of this monitor and waits until another thread
 141.517 +     * notifies threads waiting on this object's monitor to wake up
 141.518 +     * either through a call to the {@code notify} method or the
 141.519 +     * {@code notifyAll} method. The thread then waits until it can
 141.520 +     * re-obtain ownership of the monitor and resumes execution.
 141.521 +     * <p>
 141.522 +     * As in the one argument version, interrupts and spurious wakeups are
 141.523 +     * possible, and this method should always be used in a loop:
 141.524 +     * <pre>
 141.525 +     *     synchronized (obj) {
 141.526 +     *         while (&lt;condition does not hold&gt;)
 141.527 +     *             obj.wait();
 141.528 +     *         ... // Perform action appropriate to condition
 141.529 +     *     }
 141.530 +     * </pre>
 141.531 +     * This method should only be called by a thread that is the owner
 141.532 +     * of this object's monitor. See the {@code notify} method for a
 141.533 +     * description of the ways in which a thread can become the owner of
 141.534 +     * a monitor.
 141.535 +     *
 141.536 +     * @exception  IllegalMonitorStateException  if the current thread is not
 141.537 +     *               the owner of the object's monitor.
 141.538 +     * @exception  InterruptedException if any thread interrupted the
 141.539 +     *             current thread before or while the current thread
 141.540 +     *             was waiting for a notification.  The <i>interrupted
 141.541 +     *             status</i> of the current thread is cleared when
 141.542 +     *             this exception is thrown.
 141.543 +     * @see        java.lang.Object#notify()
 141.544 +     * @see        java.lang.Object#notifyAll()
 141.545 +     */
 141.546 +    public final void wait() throws InterruptedException {
 141.547 +        wait(0);
 141.548 +    }
 141.549 +
 141.550 +    /**
 141.551 +     * Called by the garbage collector on an object when garbage collection
 141.552 +     * determines that there are no more references to the object.
 141.553 +     * A subclass overrides the {@code finalize} method to dispose of
 141.554 +     * system resources or to perform other cleanup.
 141.555 +     * <p>
 141.556 +     * The general contract of {@code finalize} is that it is invoked
 141.557 +     * if and when the Java<font size="-2"><sup>TM</sup></font> virtual
 141.558 +     * machine has determined that there is no longer any
 141.559 +     * means by which this object can be accessed by any thread that has
 141.560 +     * not yet died, except as a result of an action taken by the
 141.561 +     * finalization of some other object or class which is ready to be
 141.562 +     * finalized. The {@code finalize} method may take any action, including
 141.563 +     * making this object available again to other threads; the usual purpose
 141.564 +     * of {@code finalize}, however, is to perform cleanup actions before
 141.565 +     * the object is irrevocably discarded. For example, the finalize method
 141.566 +     * for an object that represents an input/output connection might perform
 141.567 +     * explicit I/O transactions to break the connection before the object is
 141.568 +     * permanently discarded.
 141.569 +     * <p>
 141.570 +     * The {@code finalize} method of class {@code Object} performs no
 141.571 +     * special action; it simply returns normally. Subclasses of
 141.572 +     * {@code Object} may override this definition.
 141.573 +     * <p>
 141.574 +     * The Java programming language does not guarantee which thread will
 141.575 +     * invoke the {@code finalize} method for any given object. It is
 141.576 +     * guaranteed, however, that the thread that invokes finalize will not
 141.577 +     * be holding any user-visible synchronization locks when finalize is
 141.578 +     * invoked. If an uncaught exception is thrown by the finalize method,
 141.579 +     * the exception is ignored and finalization of that object terminates.
 141.580 +     * <p>
 141.581 +     * After the {@code finalize} method has been invoked for an object, no
 141.582 +     * further action is taken until the Java virtual machine has again
 141.583 +     * determined that there is no longer any means by which this object can
 141.584 +     * be accessed by any thread that has not yet died, including possible
 141.585 +     * actions by other objects or classes which are ready to be finalized,
 141.586 +     * at which point the object may be discarded.
 141.587 +     * <p>
 141.588 +     * The {@code finalize} method is never invoked more than once by a Java
 141.589 +     * virtual machine for any given object.
 141.590 +     * <p>
 141.591 +     * Any exception thrown by the {@code finalize} method causes
 141.592 +     * the finalization of this object to be halted, but is otherwise
 141.593 +     * ignored.
 141.594 +     *
 141.595 +     * @throws Throwable the {@code Exception} raised by this method
 141.596 +     */
 141.597 +    protected void finalize() throws Throwable { }
 141.598 +}
   142.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   142.2 +++ b/emul/mini/src/main/java/java/lang/OutOfMemoryError.java	Sun Feb 03 07:48:42 2013 +0100
   142.3 @@ -0,0 +1,60 @@
   142.4 +/*
   142.5 + * Copyright (c) 1994, 2011, 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 the Java Virtual Machine cannot allocate an object
  142.33 + * because it is out of memory, and no more memory could be made
  142.34 + * available by the garbage collector.
  142.35 + *
  142.36 + * {@code OutOfMemoryError} objects may be constructed by the virtual
  142.37 + * machine as if {@linkplain Throwable#Throwable(String, Throwable,
  142.38 + * boolean, boolean) suppression were disabled and/or the stack trace was not
  142.39 + * writable}.
  142.40 + *
  142.41 + * @author  unascribed
  142.42 + * @since   JDK1.0
  142.43 + */
  142.44 +public class OutOfMemoryError extends VirtualMachineError {
  142.45 +    private static final long serialVersionUID = 8228564086184010517L;
  142.46 +
  142.47 +    /**
  142.48 +     * Constructs an {@code OutOfMemoryError} with no detail message.
  142.49 +     */
  142.50 +    public OutOfMemoryError() {
  142.51 +        super();
  142.52 +    }
  142.53 +
  142.54 +    /**
  142.55 +     * Constructs an {@code OutOfMemoryError} with the specified
  142.56 +     * detail message.
  142.57 +     *
  142.58 +     * @param   s   the detail message.
  142.59 +     */
  142.60 +    public OutOfMemoryError(String s) {
  142.61 +        super(s);
  142.62 +    }
  142.63 +}
   143.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   143.2 +++ b/emul/mini/src/main/java/java/lang/Override.java	Sun Feb 03 07:48:42 2013 +0100
   143.3 @@ -0,0 +1,52 @@
   143.4 +/*
   143.5 + * Copyright (c) 2003, 2006, 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 +import java.lang.annotation.*;
  143.32 +
  143.33 +/**
  143.34 + * Indicates that a method declaration is intended to override a
  143.35 + * method declaration in a supertype. If a method is annotated with
  143.36 + * this annotation type compilers are required to generate an error
  143.37 + * message unless at least one of the following conditions hold:
  143.38 + *
  143.39 + * <ul><li>
  143.40 + * The method does override or implement a method declared in a
  143.41 + * supertype.
  143.42 + * </li><li>
  143.43 + * The method has a signature that is override-equivalent to that of
  143.44 + * any public method declared in {@linkplain Object}.
  143.45 + * </li></ul>
  143.46 + *
  143.47 + * @author  Peter von der Ah&eacute;
  143.48 + * @author  Joshua Bloch
  143.49 + * @jls 9.6.1.4 Override
  143.50 + * @since 1.5
  143.51 + */
  143.52 +@Target(ElementType.METHOD)
  143.53 +@Retention(RetentionPolicy.SOURCE)
  143.54 +public @interface Override {
  143.55 +}
   144.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   144.2 +++ b/emul/mini/src/main/java/java/lang/ReflectiveOperationException.java	Sun Feb 03 07:48:42 2013 +0100
   144.3 @@ -0,0 +1,91 @@
   144.4 +/*
   144.5 + * Copyright (c) 2009, 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 +/**
  144.32 + * Common superclass of exceptions thrown by reflective operations in
  144.33 + * core reflection.
  144.34 + *
  144.35 + * @see LinkageError
  144.36 + * @since 1.7
  144.37 + */
  144.38 +public class ReflectiveOperationException extends Exception {
  144.39 +    static final long serialVersionUID = 123456789L;
  144.40 +
  144.41 +    /**
  144.42 +     * Constructs a new exception with {@code null} as its detail
  144.43 +     * message.  The cause is not initialized, and may subsequently be
  144.44 +     * initialized by a call to {@link #initCause}.
  144.45 +     */
  144.46 +    public ReflectiveOperationException() {
  144.47 +        super();
  144.48 +    }
  144.49 +
  144.50 +    /**
  144.51 +     * Constructs a new exception with the specified detail message.
  144.52 +     * The cause is not initialized, and may subsequently be
  144.53 +     * initialized by a call to {@link #initCause}.
  144.54 +     *
  144.55 +     * @param   message   the detail message. The detail message is saved for
  144.56 +     *          later retrieval by the {@link #getMessage()} method.
  144.57 +     */
  144.58 +    public ReflectiveOperationException(String message) {
  144.59 +        super(message);
  144.60 +    }
  144.61 +
  144.62 +    /**
  144.63 +     * Constructs a new exception with the specified detail message
  144.64 +     * and cause.
  144.65 +     *
  144.66 +     * <p>Note that the detail message associated with
  144.67 +     * {@code cause} is <em>not</em> automatically incorporated in
  144.68 +     * this exception's detail message.
  144.69 +     *
  144.70 +     * @param  message the detail message (which is saved for later retrieval
  144.71 +     *         by the {@link #getMessage()} method).
  144.72 +     * @param  cause the cause (which is saved for later retrieval by the
  144.73 +     *         {@link #getCause()} method).  (A {@code null} value is
  144.74 +     *         permitted, and indicates that the cause is nonexistent or
  144.75 +     *         unknown.)
  144.76 +     */
  144.77 +    public ReflectiveOperationException(String message, Throwable cause) {
  144.78 +        super(message, cause);
  144.79 +    }
  144.80 +
  144.81 +    /**
  144.82 +     * Constructs a new exception with the specified cause and a detail
  144.83 +     * message of {@code (cause==null ? null : cause.toString())} (which
  144.84 +     * typically contains the class and detail message of {@code cause}).
  144.85 +     *
  144.86 +     * @param  cause the cause (which is saved for later retrieval by the
  144.87 +     *         {@link #getCause()} method).  (A {@code null} value is
  144.88 +     *         permitted, and indicates that the cause is nonexistent or
  144.89 +     *         unknown.)
  144.90 +     */
  144.91 +    public ReflectiveOperationException(Throwable cause) {
  144.92 +        super(cause);
  144.93 +    }
  144.94 +}
   145.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   145.2 +++ b/emul/mini/src/main/java/java/lang/Runnable.java	Sun Feb 03 07:48:42 2013 +0100
   145.3 @@ -0,0 +1,69 @@
   145.4 +/*
   145.5 + * Copyright (c) 1994, 2005, 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 + * The <code>Runnable</code> interface should be implemented by any
  145.33 + * class whose instances are intended to be executed by a thread. The
  145.34 + * class must define a method of no arguments called <code>run</code>.
  145.35 + * <p>
  145.36 + * This interface is designed to provide a common protocol for objects that
  145.37 + * wish to execute code while they are active. For example,
  145.38 + * <code>Runnable</code> is implemented by class <code>Thread</code>.
  145.39 + * Being active simply means that a thread has been started and has not
  145.40 + * yet been stopped.
  145.41 + * <p>
  145.42 + * In addition, <code>Runnable</code> provides the means for a class to be
  145.43 + * active while not subclassing <code>Thread</code>. A class that implements
  145.44 + * <code>Runnable</code> can run without subclassing <code>Thread</code>
  145.45 + * by instantiating a <code>Thread</code> instance and passing itself in
  145.46 + * as the target.  In most cases, the <code>Runnable</code> interface should
  145.47 + * be used if you are only planning to override the <code>run()</code>
  145.48 + * method and no other <code>Thread</code> methods.
  145.49 + * This is important because classes should not be subclassed
  145.50 + * unless the programmer intends on modifying or enhancing the fundamental
  145.51 + * behavior of the class.
  145.52 + *
  145.53 + * @author  Arthur van Hoff
  145.54 + * @see     java.lang.Thread
  145.55 + * @see     java.util.concurrent.Callable
  145.56 + * @since   JDK1.0
  145.57 + */
  145.58 +public
  145.59 +interface Runnable {
  145.60 +    /**
  145.61 +     * When an object implementing interface <code>Runnable</code> is used
  145.62 +     * to create a thread, starting the thread causes the object's
  145.63 +     * <code>run</code> method to be called in that separately executing
  145.64 +     * thread.
  145.65 +     * <p>
  145.66 +     * The general contract of the method <code>run</code> is that it may
  145.67 +     * take any action whatsoever.
  145.68 +     *
  145.69 +     * @see     java.lang.Thread#run()
  145.70 +     */
  145.71 +    public abstract void run();
  145.72 +}
   146.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   146.2 +++ b/emul/mini/src/main/java/java/lang/RuntimeException.java	Sun Feb 03 07:48:42 2013 +0100
   146.3 @@ -0,0 +1,119 @@
   146.4 +/*
   146.5 + * Copyright (c) 1995, 2011, 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 +/**
  146.32 + * {@code RuntimeException} is the superclass of those
  146.33 + * exceptions that can be thrown during the normal operation of the
  146.34 + * Java Virtual Machine.
  146.35 + *
  146.36 + * <p>{@code RuntimeException} and its subclasses are <em>unchecked
  146.37 + * exceptions</em>.  Unchecked exceptions do <em>not</em> need to be
  146.38 + * declared in a method or constructor's {@code throws} clause if they
  146.39 + * can be thrown by the execution of the method or constructor and
  146.40 + * propagate outside the method or constructor boundary.
  146.41 + *
  146.42 + * @author  Frank Yellin
  146.43 + * @jls 11.2 Compile-Time Checking of Exceptions
  146.44 + * @since   JDK1.0
  146.45 + */
  146.46 +public class RuntimeException extends Exception {
  146.47 +    static final long serialVersionUID = -7034897190745766939L;
  146.48 +
  146.49 +    /** Constructs a new runtime exception with {@code null} as its
  146.50 +     * detail message.  The cause is not initialized, and may subsequently be
  146.51 +     * initialized by a call to {@link #initCause}.
  146.52 +     */
  146.53 +    public RuntimeException() {
  146.54 +        super();
  146.55 +    }
  146.56 +
  146.57 +    /** Constructs a new runtime exception with the specified detail message.
  146.58 +     * The cause is not initialized, and may subsequently be initialized by a
  146.59 +     * call to {@link #initCause}.
  146.60 +     *
  146.61 +     * @param   message   the detail message. The detail message is saved for
  146.62 +     *          later retrieval by the {@link #getMessage()} method.
  146.63 +     */
  146.64 +    public RuntimeException(String message) {
  146.65 +        super(message);
  146.66 +    }
  146.67 +
  146.68 +    /**
  146.69 +     * Constructs a new runtime exception with the specified detail message and
  146.70 +     * cause.  <p>Note that the detail message associated with
  146.71 +     * {@code cause} is <i>not</i> automatically incorporated in
  146.72 +     * this runtime exception's detail message.
  146.73 +     *
  146.74 +     * @param  message the detail message (which is saved for later retrieval
  146.75 +     *         by the {@link #getMessage()} method).
  146.76 +     * @param  cause the cause (which is saved for later retrieval by the
  146.77 +     *         {@link #getCause()} method).  (A <tt>null</tt> value is
  146.78 +     *         permitted, and indicates that the cause is nonexistent or
  146.79 +     *         unknown.)
  146.80 +     * @since  1.4
  146.81 +     */
  146.82 +    public RuntimeException(String message, Throwable cause) {
  146.83 +        super(message, cause);
  146.84 +    }
  146.85 +
  146.86 +    /** Constructs a new runtime exception with the specified cause and a
  146.87 +     * detail message of <tt>(cause==null ? null : cause.toString())</tt>
  146.88 +     * (which typically contains the class and detail message of
  146.89 +     * <tt>cause</tt>).  This constructor is useful for runtime exceptions
  146.90 +     * that are little more than wrappers for other throwables.
  146.91 +     *
  146.92 +     * @param  cause the cause (which is saved for later retrieval by the
  146.93 +     *         {@link #getCause()} method).  (A <tt>null</tt> value is
  146.94 +     *         permitted, and indicates that the cause is nonexistent or
  146.95 +     *         unknown.)
  146.96 +     * @since  1.4
  146.97 +     */
  146.98 +    public RuntimeException(Throwable cause) {
  146.99 +        super(cause);
 146.100 +    }
 146.101 +
 146.102 +    /**
 146.103 +     * Constructs a new runtime exception with the specified detail
 146.104 +     * message, cause, suppression enabled or disabled, and writable
 146.105 +     * stack trace enabled or disabled.
 146.106 +     *
 146.107 +     * @param  message the detail message.
 146.108 +     * @param cause the cause.  (A {@code null} value is permitted,
 146.109 +     * and indicates that the cause is nonexistent or unknown.)
 146.110 +     * @param enableSuppression whether or not suppression is enabled
 146.111 +     *                          or disabled
 146.112 +     * @param writableStackTrace whether or not the stack trace should
 146.113 +     *                           be writable
 146.114 +     *
 146.115 +     * @since 1.7
 146.116 +     */
 146.117 +    protected RuntimeException(String message, Throwable cause,
 146.118 +                               boolean enableSuppression,
 146.119 +                               boolean writableStackTrace) {
 146.120 +        super(message, cause, enableSuppression, writableStackTrace);
 146.121 +    }
 146.122 +}
   147.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   147.2 +++ b/emul/mini/src/main/java/java/lang/SecurityException.java	Sun Feb 03 07:48:42 2013 +0100
   147.3 @@ -0,0 +1,84 @@
   147.4 +/*
   147.5 + * Copyright (c) 1995, 2003, 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 +package java.lang;
  147.29 +
  147.30 +/**
  147.31 + * Thrown by the security manager to indicate a security violation.
  147.32 + *
  147.33 + * @author  unascribed
  147.34 + * @see     java.lang.SecurityManager
  147.35 + * @since   JDK1.0
  147.36 + */
  147.37 +public class SecurityException extends RuntimeException {
  147.38 +
  147.39 +    private static final long serialVersionUID = 6878364983674394167L;
  147.40 +
  147.41 +    /**
  147.42 +     * Constructs a <code>SecurityException</code> with no detail  message.
  147.43 +     */
  147.44 +    public SecurityException() {
  147.45 +        super();
  147.46 +    }
  147.47 +
  147.48 +    /**
  147.49 +     * Constructs a <code>SecurityException</code> with the specified
  147.50 +     * detail message.
  147.51 +     *
  147.52 +     * @param   s   the detail message.
  147.53 +     */
  147.54 +    public SecurityException(String s) {
  147.55 +        super(s);
  147.56 +    }
  147.57 +
  147.58 +    /**
  147.59 +     * Creates a <code>SecurityException</code> with the specified
  147.60 +     * detail message and cause.
  147.61 +     *
  147.62 +     * @param message the detail message (which is saved for later retrieval
  147.63 +     *        by the {@link #getMessage()} method).
  147.64 +     * @param cause the cause (which is saved for later retrieval by the
  147.65 +     *        {@link #getCause()} method).  (A <tt>null</tt> value is permitted,
  147.66 +     *        and indicates that the cause is nonexistent or unknown.)
  147.67 +     * @since 1.5
  147.68 +     */
  147.69 +    public SecurityException(String message, Throwable cause) {
  147.70 +        super(message, cause);
  147.71 +    }
  147.72 +
  147.73 +    /**
  147.74 +     * Creates a <code>SecurityException</code> with the specified cause
  147.75 +     * and a detail message of <tt>(cause==null ? null : cause.toString())</tt>
  147.76 +     * (which typically contains the class and detail message of
  147.77 +     * <tt>cause</tt>).
  147.78 +     *
  147.79 +     * @param cause the cause (which is saved for later retrieval by the
  147.80 +     *        {@link #getCause()} method).  (A <tt>null</tt> value is permitted,
  147.81 +     *        and indicates that the cause is nonexistent or unknown.)
  147.82 +     * @since 1.5
  147.83 +     */
  147.84 +    public SecurityException(Throwable cause) {
  147.85 +        super(cause);
  147.86 +    }
  147.87 +}
   148.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   148.2 +++ b/emul/mini/src/main/java/java/lang/Short.java	Sun Feb 03 07:48:42 2013 +0100
   148.3 @@ -0,0 +1,468 @@
   148.4 +/*
   148.5 + * Copyright (c) 1996, 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 + * The {@code Short} class wraps a value of primitive type {@code
  148.33 + * short} in an object.  An object of type {@code Short} contains a
  148.34 + * single field whose type is {@code short}.
  148.35 + *
  148.36 + * <p>In addition, this class provides several methods for converting
  148.37 + * a {@code short} to a {@code String} and a {@code String} to a
  148.38 + * {@code short}, as well as other constants and methods useful when
  148.39 + * dealing with a {@code short}.
  148.40 + *
  148.41 + * @author  Nakul Saraiya
  148.42 + * @author  Joseph D. Darcy
  148.43 + * @see     java.lang.Number
  148.44 + * @since   JDK1.1
  148.45 + */
  148.46 +public final class Short extends Number implements Comparable<Short> {
  148.47 +
  148.48 +    /**
  148.49 +     * A constant holding the minimum value a {@code short} can
  148.50 +     * have, -2<sup>15</sup>.
  148.51 +     */
  148.52 +    public static final short   MIN_VALUE = -32768;
  148.53 +
  148.54 +    /**
  148.55 +     * A constant holding the maximum value a {@code short} can
  148.56 +     * have, 2<sup>15</sup>-1.
  148.57 +     */
  148.58 +    public static final short   MAX_VALUE = 32767;
  148.59 +
  148.60 +    /**
  148.61 +     * The {@code Class} instance representing the primitive type
  148.62 +     * {@code short}.
  148.63 +     */
  148.64 +    public static final Class<Short>    TYPE = (Class<Short>) Class.getPrimitiveClass("short");
  148.65 +
  148.66 +    /**
  148.67 +     * Returns a new {@code String} object representing the
  148.68 +     * specified {@code short}. The radix is assumed to be 10.
  148.69 +     *
  148.70 +     * @param s the {@code short} to be converted
  148.71 +     * @return the string representation of the specified {@code short}
  148.72 +     * @see java.lang.Integer#toString(int)
  148.73 +     */
  148.74 +    public static String toString(short s) {
  148.75 +        return Integer.toString((int)s, 10);
  148.76 +    }
  148.77 +
  148.78 +    /**
  148.79 +     * Parses the string argument as a signed {@code short} in the
  148.80 +     * radix specified by the second argument. The characters in the
  148.81 +     * string must all be digits, of the specified radix (as
  148.82 +     * determined by whether {@link java.lang.Character#digit(char,
  148.83 +     * int)} returns a nonnegative value) except that the first
  148.84 +     * character may be an ASCII minus sign {@code '-'}
  148.85 +     * (<code>'&#92;u002D'</code>) to indicate a negative value or an
  148.86 +     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
  148.87 +     * indicate a positive value.  The resulting {@code short} value
  148.88 +     * is returned.
  148.89 +     *
  148.90 +     * <p>An exception of type {@code NumberFormatException} is
  148.91 +     * thrown if any of the following situations occurs:
  148.92 +     * <ul>
  148.93 +     * <li> The first argument is {@code null} or is a string of
  148.94 +     * length zero.
  148.95 +     *
  148.96 +     * <li> The radix is either smaller than {@link
  148.97 +     * java.lang.Character#MIN_RADIX} or larger than {@link
  148.98 +     * java.lang.Character#MAX_RADIX}.
  148.99 +     *
 148.100 +     * <li> Any character of the string is not a digit of the
 148.101 +     * specified radix, except that the first character may be a minus
 148.102 +     * sign {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
 148.103 +     * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
 148.104 +     * string is longer than length 1.
 148.105 +     *
 148.106 +     * <li> The value represented by the string is not a value of type
 148.107 +     * {@code short}.
 148.108 +     * </ul>
 148.109 +     *
 148.110 +     * @param s         the {@code String} containing the
 148.111 +     *                  {@code short} representation to be parsed
 148.112 +     * @param radix     the radix to be used while parsing {@code s}
 148.113 +     * @return          the {@code short} represented by the string
 148.114 +     *                  argument in the specified radix.
 148.115 +     * @throws          NumberFormatException If the {@code String}
 148.116 +     *                  does not contain a parsable {@code short}.
 148.117 +     */
 148.118 +    public static short parseShort(String s, int radix)
 148.119 +        throws NumberFormatException {
 148.120 +        int i = Integer.parseInt(s, radix);
 148.121 +        if (i < MIN_VALUE || i > MAX_VALUE)
 148.122 +            throw new NumberFormatException(
 148.123 +                "Value out of range. Value:\"" + s + "\" Radix:" + radix);
 148.124 +        return (short)i;
 148.125 +    }
 148.126 +
 148.127 +    /**
 148.128 +     * Parses the string argument as a signed decimal {@code
 148.129 +     * short}. The characters in the string must all be decimal
 148.130 +     * digits, except that the first character may be an ASCII minus
 148.131 +     * sign {@code '-'} (<code>'&#92;u002D'</code>) to indicate a
 148.132 +     * negative value or an ASCII plus sign {@code '+'}
 148.133 +     * (<code>'&#92;u002B'</code>) to indicate a positive value.  The
 148.134 +     * resulting {@code short} value is returned, exactly as if the
 148.135 +     * argument and the radix 10 were given as arguments to the {@link
 148.136 +     * #parseShort(java.lang.String, int)} method.
 148.137 +     *
 148.138 +     * @param s a {@code String} containing the {@code short}
 148.139 +     *          representation to be parsed
 148.140 +     * @return  the {@code short} value represented by the
 148.141 +     *          argument in decimal.
 148.142 +     * @throws  NumberFormatException If the string does not
 148.143 +     *          contain a parsable {@code short}.
 148.144 +     */
 148.145 +    public static short parseShort(String s) throws NumberFormatException {
 148.146 +        return parseShort(s, 10);
 148.147 +    }
 148.148 +
 148.149 +    /**
 148.150 +     * Returns a {@code Short} object holding the value
 148.151 +     * extracted from the specified {@code String} when parsed
 148.152 +     * with the radix given by the second argument. The first argument
 148.153 +     * is interpreted as representing a signed {@code short} in
 148.154 +     * the radix specified by the second argument, exactly as if the
 148.155 +     * argument were given to the {@link #parseShort(java.lang.String,
 148.156 +     * int)} method. The result is a {@code Short} object that
 148.157 +     * represents the {@code short} value specified by the string.
 148.158 +     *
 148.159 +     * <p>In other words, this method returns a {@code Short} object
 148.160 +     * equal to the value of:
 148.161 +     *
 148.162 +     * <blockquote>
 148.163 +     *  {@code new Short(Short.parseShort(s, radix))}
 148.164 +     * </blockquote>
 148.165 +     *
 148.166 +     * @param s         the string to be parsed
 148.167 +     * @param radix     the radix to be used in interpreting {@code s}
 148.168 +     * @return          a {@code Short} object holding the value
 148.169 +     *                  represented by the string argument in the
 148.170 +     *                  specified radix.
 148.171 +     * @throws          NumberFormatException If the {@code String} does
 148.172 +     *                  not contain a parsable {@code short}.
 148.173 +     */
 148.174 +    public static Short valueOf(String s, int radix)
 148.175 +        throws NumberFormatException {
 148.176 +        return valueOf(parseShort(s, radix));
 148.177 +    }
 148.178 +
 148.179 +    /**
 148.180 +     * Returns a {@code Short} object holding the
 148.181 +     * value given by the specified {@code String}. The argument
 148.182 +     * is interpreted as representing a signed decimal
 148.183 +     * {@code short}, exactly as if the argument were given to
 148.184 +     * the {@link #parseShort(java.lang.String)} method. The result is
 148.185 +     * a {@code Short} object that represents the
 148.186 +     * {@code short} value specified by the string.
 148.187 +     *
 148.188 +     * <p>In other words, this method returns a {@code Short} object
 148.189 +     * equal to the value of:
 148.190 +     *
 148.191 +     * <blockquote>
 148.192 +     *  {@code new Short(Short.parseShort(s))}
 148.193 +     * </blockquote>
 148.194 +     *
 148.195 +     * @param s the string to be parsed
 148.196 +     * @return  a {@code Short} object holding the value
 148.197 +     *          represented by the string argument
 148.198 +     * @throws  NumberFormatException If the {@code String} does
 148.199 +     *          not contain a parsable {@code short}.
 148.200 +     */
 148.201 +    public static Short valueOf(String s) throws NumberFormatException {
 148.202 +        return valueOf(s, 10);
 148.203 +    }
 148.204 +
 148.205 +    private static class ShortCache {
 148.206 +        private ShortCache(){}
 148.207 +
 148.208 +        static final Short cache[] = new Short[-(-128) + 127 + 1];
 148.209 +
 148.210 +        static {
 148.211 +            for(int i = 0; i < cache.length; i++)
 148.212 +                cache[i] = new Short((short)(i - 128));
 148.213 +        }
 148.214 +    }
 148.215 +
 148.216 +    /**
 148.217 +     * Returns a {@code Short} instance representing the specified
 148.218 +     * {@code short} value.
 148.219 +     * If a new {@code Short} instance is not required, this method
 148.220 +     * should generally be used in preference to the constructor
 148.221 +     * {@link #Short(short)}, as this method is likely to yield
 148.222 +     * significantly better space and time performance by caching
 148.223 +     * frequently requested values.
 148.224 +     *
 148.225 +     * This method will always cache values in the range -128 to 127,
 148.226 +     * inclusive, and may cache other values outside of this range.
 148.227 +     *
 148.228 +     * @param  s a short value.
 148.229 +     * @return a {@code Short} instance representing {@code s}.
 148.230 +     * @since  1.5
 148.231 +     */
 148.232 +    public static Short valueOf(short s) {
 148.233 +        final int offset = 128;
 148.234 +        int sAsInt = s;
 148.235 +        if (sAsInt >= -128 && sAsInt <= 127) { // must cache
 148.236 +            return ShortCache.cache[sAsInt + offset];
 148.237 +        }
 148.238 +        return new Short(s);
 148.239 +    }
 148.240 +
 148.241 +    /**
 148.242 +     * Decodes a {@code String} into a {@code Short}.
 148.243 +     * Accepts decimal, hexadecimal, and octal numbers given by
 148.244 +     * the following grammar:
 148.245 +     *
 148.246 +     * <blockquote>
 148.247 +     * <dl>
 148.248 +     * <dt><i>DecodableString:</i>
 148.249 +     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 148.250 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 148.251 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 148.252 +     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 148.253 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 148.254 +     * <p>
 148.255 +     * <dt><i>Sign:</i>
 148.256 +     * <dd>{@code -}
 148.257 +     * <dd>{@code +}
 148.258 +     * </dl>
 148.259 +     * </blockquote>
 148.260 +     *
 148.261 +     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 148.262 +     * are as defined in section 3.10.1 of
 148.263 +     * <cite>The Java&trade; Language Specification</cite>,
 148.264 +     * except that underscores are not accepted between digits.
 148.265 +     *
 148.266 +     * <p>The sequence of characters following an optional
 148.267 +     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 148.268 +     * "{@code #}", or leading zero) is parsed as by the {@code
 148.269 +     * Short.parseShort} method with the indicated radix (10, 16, or
 148.270 +     * 8).  This sequence of characters must represent a positive
 148.271 +     * value or a {@link NumberFormatException} will be thrown.  The
 148.272 +     * result is negated if first character of the specified {@code
 148.273 +     * String} is the minus sign.  No whitespace characters are
 148.274 +     * permitted in the {@code String}.
 148.275 +     *
 148.276 +     * @param     nm the {@code String} to decode.
 148.277 +     * @return    a {@code Short} object holding the {@code short}
 148.278 +     *            value represented by {@code nm}
 148.279 +     * @throws    NumberFormatException  if the {@code String} does not
 148.280 +     *            contain a parsable {@code short}.
 148.281 +     * @see java.lang.Short#parseShort(java.lang.String, int)
 148.282 +     */
 148.283 +    public static Short decode(String nm) throws NumberFormatException {
 148.284 +        int i = Integer.decode(nm);
 148.285 +        if (i < MIN_VALUE || i > MAX_VALUE)
 148.286 +            throw new NumberFormatException(
 148.287 +                    "Value " + i + " out of range from input " + nm);
 148.288 +        return valueOf((short)i);
 148.289 +    }
 148.290 +
 148.291 +    /**
 148.292 +     * The value of the {@code Short}.
 148.293 +     *
 148.294 +     * @serial
 148.295 +     */
 148.296 +    private final short value;
 148.297 +
 148.298 +    /**
 148.299 +     * Constructs a newly allocated {@code Short} object that
 148.300 +     * represents the specified {@code short} value.
 148.301 +     *
 148.302 +     * @param value     the value to be represented by the
 148.303 +     *                  {@code Short}.
 148.304 +     */
 148.305 +    public Short(short value) {
 148.306 +        this.value = value;
 148.307 +    }
 148.308 +
 148.309 +    /**
 148.310 +     * Constructs a newly allocated {@code Short} object that
 148.311 +     * represents the {@code short} value indicated by the
 148.312 +     * {@code String} parameter. The string is converted to a
 148.313 +     * {@code short} value in exactly the manner used by the
 148.314 +     * {@code parseShort} method for radix 10.
 148.315 +     *
 148.316 +     * @param s the {@code String} to be converted to a
 148.317 +     *          {@code Short}
 148.318 +     * @throws  NumberFormatException If the {@code String}
 148.319 +     *          does not contain a parsable {@code short}.
 148.320 +     * @see     java.lang.Short#parseShort(java.lang.String, int)
 148.321 +     */
 148.322 +    public Short(String s) throws NumberFormatException {
 148.323 +        this.value = parseShort(s, 10);
 148.324 +    }
 148.325 +
 148.326 +    /**
 148.327 +     * Returns the value of this {@code Short} as a
 148.328 +     * {@code byte}.
 148.329 +     */
 148.330 +    public byte byteValue() {
 148.331 +        return (byte)value;
 148.332 +    }
 148.333 +
 148.334 +    /**
 148.335 +     * Returns the value of this {@code Short} as a
 148.336 +     * {@code short}.
 148.337 +     */
 148.338 +    public short shortValue() {
 148.339 +        return value;
 148.340 +    }
 148.341 +
 148.342 +    /**
 148.343 +     * Returns the value of this {@code Short} as an
 148.344 +     * {@code int}.
 148.345 +     */
 148.346 +    public int intValue() {
 148.347 +        return (int)value;
 148.348 +    }
 148.349 +
 148.350 +    /**
 148.351 +     * Returns the value of this {@code Short} as a
 148.352 +     * {@code long}.
 148.353 +     */
 148.354 +    public long longValue() {
 148.355 +        return (long)value;
 148.356 +    }
 148.357 +
 148.358 +    /**
 148.359 +     * Returns the value of this {@code Short} as a
 148.360 +     * {@code float}.
 148.361 +     */
 148.362 +    public float floatValue() {
 148.363 +        return (float)value;
 148.364 +    }
 148.365 +
 148.366 +    /**
 148.367 +     * Returns the value of this {@code Short} as a
 148.368 +     * {@code double}.
 148.369 +     */
 148.370 +    public double doubleValue() {
 148.371 +        return (double)value;
 148.372 +    }
 148.373 +
 148.374 +    /**
 148.375 +     * Returns a {@code String} object representing this
 148.376 +     * {@code Short}'s value.  The value is converted to signed
 148.377 +     * decimal representation and returned as a string, exactly as if
 148.378 +     * the {@code short} value were given as an argument to the
 148.379 +     * {@link java.lang.Short#toString(short)} method.
 148.380 +     *
 148.381 +     * @return  a string representation of the value of this object in
 148.382 +     *          base&nbsp;10.
 148.383 +     */
 148.384 +    public String toString() {
 148.385 +        return Integer.toString((int)value);
 148.386 +    }
 148.387 +
 148.388 +    /**
 148.389 +     * Returns a hash code for this {@code Short}; equal to the result
 148.390 +     * of invoking {@code intValue()}.
 148.391 +     *
 148.392 +     * @return a hash code value for this {@code Short}
 148.393 +     */
 148.394 +    public int hashCode() {
 148.395 +        return (int)value;
 148.396 +    }
 148.397 +
 148.398 +    /**
 148.399 +     * Compares this object to the specified object.  The result is
 148.400 +     * {@code true} if and only if the argument is not
 148.401 +     * {@code null} and is a {@code Short} object that
 148.402 +     * contains the same {@code short} value as this object.
 148.403 +     *
 148.404 +     * @param obj       the object to compare with
 148.405 +     * @return          {@code true} if the objects are the same;
 148.406 +     *                  {@code false} otherwise.
 148.407 +     */
 148.408 +    public boolean equals(Object obj) {
 148.409 +        if (obj instanceof Short) {
 148.410 +            return value == ((Short)obj).shortValue();
 148.411 +        }
 148.412 +        return false;
 148.413 +    }
 148.414 +
 148.415 +    /**
 148.416 +     * Compares two {@code Short} objects numerically.
 148.417 +     *
 148.418 +     * @param   anotherShort   the {@code Short} to be compared.
 148.419 +     * @return  the value {@code 0} if this {@code Short} is
 148.420 +     *          equal to the argument {@code Short}; a value less than
 148.421 +     *          {@code 0} if this {@code Short} is numerically less
 148.422 +     *          than the argument {@code Short}; and a value greater than
 148.423 +     *           {@code 0} if this {@code Short} is numerically
 148.424 +     *           greater than the argument {@code Short} (signed
 148.425 +     *           comparison).
 148.426 +     * @since   1.2
 148.427 +     */
 148.428 +    public int compareTo(Short anotherShort) {
 148.429 +        return compare(this.value, anotherShort.value);
 148.430 +    }
 148.431 +
 148.432 +    /**
 148.433 +     * Compares two {@code short} values numerically.
 148.434 +     * The value returned is identical to what would be returned by:
 148.435 +     * <pre>
 148.436 +     *    Short.valueOf(x).compareTo(Short.valueOf(y))
 148.437 +     * </pre>
 148.438 +     *
 148.439 +     * @param  x the first {@code short} to compare
 148.440 +     * @param  y the second {@code short} to compare
 148.441 +     * @return the value {@code 0} if {@code x == y};
 148.442 +     *         a value less than {@code 0} if {@code x < y}; and
 148.443 +     *         a value greater than {@code 0} if {@code x > y}
 148.444 +     * @since 1.7
 148.445 +     */
 148.446 +    public static int compare(short x, short y) {
 148.447 +        return x - y;
 148.448 +    }
 148.449 +
 148.450 +    /**
 148.451 +     * The number of bits used to represent a {@code short} value in two's
 148.452 +     * complement binary form.
 148.453 +     * @since 1.5
 148.454 +     */
 148.455 +    public static final int SIZE = 16;
 148.456 +
 148.457 +    /**
 148.458 +     * Returns the value obtained by reversing the order of the bytes in the
 148.459 +     * two's complement representation of the specified {@code short} value.
 148.460 +     *
 148.461 +     * @return the value obtained by reversing (or, equivalently, swapping)
 148.462 +     *     the bytes in the specified {@code short} value.
 148.463 +     * @since 1.5
 148.464 +     */
 148.465 +    public static short reverseBytes(short i) {
 148.466 +        return (short) (((i & 0xFF00) >> 8) | (i << 8));
 148.467 +    }
 148.468 +
 148.469 +    /** use serialVersionUID from JDK 1.1. for interoperability */
 148.470 +    private static final long serialVersionUID = 7515723908773894738L;
 148.471 +}
   149.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   149.2 +++ b/emul/mini/src/main/java/java/lang/StackTraceElement.java	Sun Feb 03 07:48:42 2013 +0100
   149.3 @@ -0,0 +1,223 @@
   149.4 +/*
   149.5 + * Copyright (c) 2000, 2011, 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 + * An element in a stack trace, as returned by {@link
  149.33 + * Throwable#getStackTrace()}.  Each element represents a single stack frame.
  149.34 + * All stack frames except for the one at the top of the stack represent
  149.35 + * a method invocation.  The frame at the top of the stack represents the
  149.36 + * execution point at which the stack trace was generated.  Typically,
  149.37 + * this is the point at which the throwable corresponding to the stack trace
  149.38 + * was created.
  149.39 + *
  149.40 + * @since  1.4
  149.41 + * @author Josh Bloch
  149.42 + */
  149.43 +public final class StackTraceElement implements java.io.Serializable {
  149.44 +    // Normally initialized by VM (public constructor added in 1.5)
  149.45 +    private String declaringClass;
  149.46 +    private String methodName;
  149.47 +    private String fileName;
  149.48 +    private int    lineNumber;
  149.49 +
  149.50 +    /**
  149.51 +     * Creates a stack trace element representing the specified execution
  149.52 +     * point.
  149.53 +     *
  149.54 +     * @param declaringClass the fully qualified name of the class containing
  149.55 +     *        the execution point represented by the stack trace element
  149.56 +     * @param methodName the name of the method containing the execution point
  149.57 +     *        represented by the stack trace element
  149.58 +     * @param fileName the name of the file containing the execution point
  149.59 +     *         represented by the stack trace element, or {@code null} if
  149.60 +     *         this information is unavailable
  149.61 +     * @param lineNumber the line number of the source line containing the
  149.62 +     *         execution point represented by this stack trace element, or
  149.63 +     *         a negative number if this information is unavailable. A value
  149.64 +     *         of -2 indicates that the method containing the execution point
  149.65 +     *         is a native method
  149.66 +     * @throws NullPointerException if {@code declaringClass} or
  149.67 +     *         {@code methodName} is null
  149.68 +     * @since 1.5
  149.69 +     */
  149.70 +    public StackTraceElement(String declaringClass, String methodName,
  149.71 +                             String fileName, int lineNumber) {
  149.72 +        this.declaringClass = declaringClass;
  149.73 +        this.methodName     = methodName;
  149.74 +        this.fileName       = fileName;
  149.75 +        this.lineNumber     = lineNumber;
  149.76 +    }
  149.77 +
  149.78 +    /**
  149.79 +     * Returns the name of the source file containing the execution point
  149.80 +     * represented by this stack trace element.  Generally, this corresponds
  149.81 +     * to the {@code SourceFile} attribute of the relevant {@code class}
  149.82 +     * file (as per <i>The Java Virtual Machine Specification</i>, Section
  149.83 +     * 4.7.7).  In some systems, the name may refer to some source code unit
  149.84 +     * other than a file, such as an entry in source repository.
  149.85 +     *
  149.86 +     * @return the name of the file containing the execution point
  149.87 +     *         represented by this stack trace element, or {@code null} if
  149.88 +     *         this information is unavailable.
  149.89 +     */
  149.90 +    public String getFileName() {
  149.91 +        return fileName;
  149.92 +    }
  149.93 +
  149.94 +    /**
  149.95 +     * Returns the line number of the source line containing the execution
  149.96 +     * point represented by this stack trace element.  Generally, this is
  149.97 +     * derived from the {@code LineNumberTable} attribute of the relevant
  149.98 +     * {@code class} file (as per <i>The Java Virtual Machine
  149.99 +     * Specification</i>, Section 4.7.8).
 149.100 +     *
 149.101 +     * @return the line number of the source line containing the execution
 149.102 +     *         point represented by this stack trace element, or a negative
 149.103 +     *         number if this information is unavailable.
 149.104 +     */
 149.105 +    public int getLineNumber() {
 149.106 +        return lineNumber;
 149.107 +    }
 149.108 +
 149.109 +    /**
 149.110 +     * Returns the fully qualified name of the class containing the
 149.111 +     * execution point represented by this stack trace element.
 149.112 +     *
 149.113 +     * @return the fully qualified name of the {@code Class} containing
 149.114 +     *         the execution point represented by this stack trace element.
 149.115 +     */
 149.116 +    public String getClassName() {
 149.117 +        return declaringClass;
 149.118 +    }
 149.119 +
 149.120 +    /**
 149.121 +     * Returns the name of the method containing the execution point
 149.122 +     * represented by this stack trace element.  If the execution point is
 149.123 +     * contained in an instance or class initializer, this method will return
 149.124 +     * the appropriate <i>special method name</i>, {@code <init>} or
 149.125 +     * {@code <clinit>}, as per Section 3.9 of <i>The Java Virtual
 149.126 +     * Machine Specification</i>.
 149.127 +     *
 149.128 +     * @return the name of the method containing the execution point
 149.129 +     *         represented by this stack trace element.
 149.130 +     */
 149.131 +    public String getMethodName() {
 149.132 +        return methodName;
 149.133 +    }
 149.134 +
 149.135 +    /**
 149.136 +     * Returns true if the method containing the execution point
 149.137 +     * represented by this stack trace element is a native method.
 149.138 +     *
 149.139 +     * @return {@code true} if the method containing the execution point
 149.140 +     *         represented by this stack trace element is a native method.
 149.141 +     */
 149.142 +    public boolean isNativeMethod() {
 149.143 +        return lineNumber == -2;
 149.144 +    }
 149.145 +
 149.146 +    /**
 149.147 +     * Returns a string representation of this stack trace element.  The
 149.148 +     * format of this string depends on the implementation, but the following
 149.149 +     * examples may be regarded as typical:
 149.150 +     * <ul>
 149.151 +     * <li>
 149.152 +     *   {@code "MyClass.mash(MyClass.java:9)"} - Here, {@code "MyClass"}
 149.153 +     *   is the <i>fully-qualified name</i> of the class containing the
 149.154 +     *   execution point represented by this stack trace element,
 149.155 +     *   {@code "mash"} is the name of the method containing the execution
 149.156 +     *   point, {@code "MyClass.java"} is the source file containing the
 149.157 +     *   execution point, and {@code "9"} is the line number of the source
 149.158 +     *   line containing the execution point.
 149.159 +     * <li>
 149.160 +     *   {@code "MyClass.mash(MyClass.java)"} - As above, but the line
 149.161 +     *   number is unavailable.
 149.162 +     * <li>
 149.163 +     *   {@code "MyClass.mash(Unknown Source)"} - As above, but neither
 149.164 +     *   the file name nor the line  number are available.
 149.165 +     * <li>
 149.166 +     *   {@code "MyClass.mash(Native Method)"} - As above, but neither
 149.167 +     *   the file name nor the line  number are available, and the method
 149.168 +     *   containing the execution point is known to be a native method.
 149.169 +     * </ul>
 149.170 +     * @see    Throwable#printStackTrace()
 149.171 +     */
 149.172 +    public String toString() {
 149.173 +        return getClassName() + "." + methodName +
 149.174 +            (isNativeMethod() ? "(Native Method)" :
 149.175 +             (fileName != null && lineNumber >= 0 ?
 149.176 +              "(" + fileName + ":" + lineNumber + ")" :
 149.177 +              (fileName != null ?  "("+fileName+")" : "(Unknown Source)")));
 149.178 +    }
 149.179 +
 149.180 +    /**
 149.181 +     * Returns true if the specified object is another
 149.182 +     * {@code StackTraceElement} instance representing the same execution
 149.183 +     * point as this instance.  Two stack trace elements {@code a} and
 149.184 +     * {@code b} are equal if and only if:
 149.185 +     * <pre>
 149.186 +     *     equals(a.getFileName(), b.getFileName()) &&
 149.187 +     *     a.getLineNumber() == b.getLineNumber()) &&
 149.188 +     *     equals(a.getClassName(), b.getClassName()) &&
 149.189 +     *     equals(a.getMethodName(), b.getMethodName())
 149.190 +     * </pre>
 149.191 +     * where {@code equals} has the semantics of {@link
 149.192 +     * java.util.Objects#equals(Object, Object) Objects.equals}.
 149.193 +     *
 149.194 +     * @param  obj the object to be compared with this stack trace element.
 149.195 +     * @return true if the specified object is another
 149.196 +     *         {@code StackTraceElement} instance representing the same
 149.197 +     *         execution point as this instance.
 149.198 +     */
 149.199 +    public boolean equals(Object obj) {
 149.200 +        if (obj==this)
 149.201 +            return true;
 149.202 +        if (!(obj instanceof StackTraceElement))
 149.203 +            return false;
 149.204 +        StackTraceElement e = (StackTraceElement)obj;
 149.205 +        return e.declaringClass.equals(declaringClass) &&
 149.206 +            e.lineNumber == lineNumber &&
 149.207 +            equals(methodName, e.methodName) &&
 149.208 +            equals(fileName, e.fileName);
 149.209 +    }
 149.210 +
 149.211 +    /**
 149.212 +     * Returns a hash code value for this stack trace element.
 149.213 +     */
 149.214 +    public int hashCode() {
 149.215 +        int result = 31*declaringClass.hashCode() + methodName.hashCode();
 149.216 +        result = 31*result + (fileName == null ? 0 : fileName.hashCode());
 149.217 +        result = 31*result + lineNumber;
 149.218 +        return result;
 149.219 +    }
 149.220 +    
 149.221 +    private static boolean equals(Object a, Object b) {
 149.222 +        return (a == b) || (a != null && a.equals(b));
 149.223 +    }
 149.224 +
 149.225 +    private static final long serialVersionUID = 6992337162326171013L;
 149.226 +}
   150.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   150.2 +++ b/emul/mini/src/main/java/java/lang/String.java	Sun Feb 03 07:48:42 2013 +0100
   150.3 @@ -0,0 +1,3024 @@
   150.4 +/*
   150.5 + * Copyright (c) 1994, 2010, 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 +import java.util.Comparator;
  150.32 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
  150.33 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  150.34 +import org.apidesign.bck2brwsr.core.JavaScriptOnly;
  150.35 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  150.36 +import org.apidesign.bck2brwsr.emul.lang.System;
  150.37 +
  150.38 +/**
  150.39 + * The <code>String</code> class represents character strings. All
  150.40 + * string literals in Java programs, such as <code>"abc"</code>, are
  150.41 + * implemented as instances of this class.
  150.42 + * <p>
  150.43 + * Strings are constant; their values cannot be changed after they
  150.44 + * are created. String buffers support mutable strings.
  150.45 + * Because String objects are immutable they can be shared. For example:
  150.46 + * <p><blockquote><pre>
  150.47 + *     String str = "abc";
  150.48 + * </pre></blockquote><p>
  150.49 + * is equivalent to:
  150.50 + * <p><blockquote><pre>
  150.51 + *     char data[] = {'a', 'b', 'c'};
  150.52 + *     String str = new String(data);
  150.53 + * </pre></blockquote><p>
  150.54 + * Here are some more examples of how strings can be used:
  150.55 + * <p><blockquote><pre>
  150.56 + *     System.out.println("abc");
  150.57 + *     String cde = "cde";
  150.58 + *     System.out.println("abc" + cde);
  150.59 + *     String c = "abc".substring(2,3);
  150.60 + *     String d = cde.substring(1, 2);
  150.61 + * </pre></blockquote>
  150.62 + * <p>
  150.63 + * The class <code>String</code> includes methods for examining
  150.64 + * individual characters of the sequence, for comparing strings, for
  150.65 + * searching strings, for extracting substrings, and for creating a
  150.66 + * copy of a string with all characters translated to uppercase or to
  150.67 + * lowercase. Case mapping is based on the Unicode Standard version
  150.68 + * specified by the {@link java.lang.Character Character} class.
  150.69 + * <p>
  150.70 + * The Java language provides special support for the string
  150.71 + * concatenation operator (&nbsp;+&nbsp;), and for conversion of
  150.72 + * other objects to strings. String concatenation is implemented
  150.73 + * through the <code>StringBuilder</code>(or <code>StringBuffer</code>)
  150.74 + * class and its <code>append</code> method.
  150.75 + * String conversions are implemented through the method
  150.76 + * <code>toString</code>, defined by <code>Object</code> and
  150.77 + * inherited by all classes in Java. For additional information on
  150.78 + * string concatenation and conversion, see Gosling, Joy, and Steele,
  150.79 + * <i>The Java Language Specification</i>.
  150.80 + *
  150.81 + * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
  150.82 + * or method in this class will cause a {@link NullPointerException} to be
  150.83 + * thrown.
  150.84 + *
  150.85 + * <p>A <code>String</code> represents a string in the UTF-16 format
  150.86 + * in which <em>supplementary characters</em> are represented by <em>surrogate
  150.87 + * pairs</em> (see the section <a href="Character.html#unicode">Unicode
  150.88 + * Character Representations</a> in the <code>Character</code> class for
  150.89 + * more information).
  150.90 + * Index values refer to <code>char</code> code units, so a supplementary
  150.91 + * character uses two positions in a <code>String</code>.
  150.92 + * <p>The <code>String</code> class provides methods for dealing with
  150.93 + * Unicode code points (i.e., characters), in addition to those for
  150.94 + * dealing with Unicode code units (i.e., <code>char</code> values).
  150.95 + *
  150.96 + * @author  Lee Boynton
  150.97 + * @author  Arthur van Hoff
  150.98 + * @author  Martin Buchholz
  150.99 + * @author  Ulf Zibis
 150.100 + * @see     java.lang.Object#toString()
 150.101 + * @see     java.lang.StringBuffer
 150.102 + * @see     java.lang.StringBuilder
 150.103 + * @see     java.nio.charset.Charset
 150.104 + * @since   JDK1.0
 150.105 + */
 150.106 +
 150.107 +@ExtraJavaScript(
 150.108 +    resource="/org/apidesign/vm4brwsr/emul/lang/java_lang_String.js",
 150.109 +    processByteCode=true
 150.110 +)
 150.111 +@JavaScriptPrototype(container = "String.prototype", prototype = "new String")
 150.112 +public final class String
 150.113 +    implements java.io.Serializable, Comparable<String>, CharSequence
 150.114 +{
 150.115 +    /** real string to delegate to */
 150.116 +    private Object r;
 150.117 +
 150.118 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 150.119 +    private static final long serialVersionUID = -6849794470754667710L;
 150.120 +    
 150.121 +    @JavaScriptOnly(name="toString", value="String.prototype._r")
 150.122 +    private static void jsToString() {
 150.123 +    }
 150.124 +    
 150.125 +    @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
 150.126 +    private static void jsValudOf() {
 150.127 +    }
 150.128 +
 150.129 +    /**
 150.130 +     * Class String is special cased within the Serialization Stream Protocol.
 150.131 +     *
 150.132 +     * A String instance is written initially into an ObjectOutputStream in the
 150.133 +     * following format:
 150.134 +     * <pre>
 150.135 +     *      <code>TC_STRING</code> (utf String)
 150.136 +     * </pre>
 150.137 +     * The String is written by method <code>DataOutput.writeUTF</code>.
 150.138 +     * A new handle is generated to  refer to all future references to the
 150.139 +     * string instance within the stream.
 150.140 +     */
 150.141 +//    private static final ObjectStreamField[] serialPersistentFields =
 150.142 +//        new ObjectStreamField[0];
 150.143 +
 150.144 +    /**
 150.145 +     * Initializes a newly created {@code String} object so that it represents
 150.146 +     * an empty character sequence.  Note that use of this constructor is
 150.147 +     * unnecessary since Strings are immutable.
 150.148 +     */
 150.149 +    public String() {
 150.150 +        this.r = "";
 150.151 +    }
 150.152 +
 150.153 +    /**
 150.154 +     * Initializes a newly created {@code String} object so that it represents
 150.155 +     * the same sequence of characters as the argument; in other words, the
 150.156 +     * newly created string is a copy of the argument string. Unless an
 150.157 +     * explicit copy of {@code original} is needed, use of this constructor is
 150.158 +     * unnecessary since Strings are immutable.
 150.159 +     *
 150.160 +     * @param  original
 150.161 +     *         A {@code String}
 150.162 +     */
 150.163 +    public String(String original) {
 150.164 +        this.r = original.toString();
 150.165 +    }
 150.166 +
 150.167 +    /**
 150.168 +     * Allocates a new {@code String} so that it represents the sequence of
 150.169 +     * characters currently contained in the character array argument. The
 150.170 +     * contents of the character array are copied; subsequent modification of
 150.171 +     * the character array does not affect the newly created string.
 150.172 +     *
 150.173 +     * @param  value
 150.174 +     *         The initial value of the string
 150.175 +     */
 150.176 +    @JavaScriptBody(args = { "charArr" }, body=
 150.177 +        "for (var i = 0; i < charArr.length; i++) {\n"
 150.178 +      + "  if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n"
 150.179 +      + "}\n"
 150.180 +      + "this._r(charArr.join(''));\n"
 150.181 +    )
 150.182 +    public String(char value[]) {
 150.183 +    }
 150.184 +
 150.185 +    /**
 150.186 +     * Allocates a new {@code String} that contains characters from a subarray
 150.187 +     * of the character array argument. The {@code offset} argument is the
 150.188 +     * index of the first character of the subarray and the {@code count}
 150.189 +     * argument specifies the length of the subarray. The contents of the
 150.190 +     * subarray are copied; subsequent modification of the character array does
 150.191 +     * not affect the newly created string.
 150.192 +     *
 150.193 +     * @param  value
 150.194 +     *         Array that is the source of characters
 150.195 +     *
 150.196 +     * @param  offset
 150.197 +     *         The initial offset
 150.198 +     *
 150.199 +     * @param  count
 150.200 +     *         The length
 150.201 +     *
 150.202 +     * @throws  IndexOutOfBoundsException
 150.203 +     *          If the {@code offset} and {@code count} arguments index
 150.204 +     *          characters outside the bounds of the {@code value} array
 150.205 +     */
 150.206 +    @JavaScriptBody(args = { "charArr", "off", "cnt" }, body =
 150.207 +        "var up = off + cnt;\n" +
 150.208 +        "for (var i = off; i < up; i++) {\n" +
 150.209 +        "  if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n" +
 150.210 +        "}\n" +
 150.211 +        "this._r(charArr.slice(off, up).join(\"\"));\n"
 150.212 +    )
 150.213 +    public String(char value[], int offset, int count) {
 150.214 +    }
 150.215 +
 150.216 +    /**
 150.217 +     * Allocates a new {@code String} that contains characters from a subarray
 150.218 +     * of the <a href="Character.html#unicode">Unicode code point</a> array
 150.219 +     * argument.  The {@code offset} argument is the index of the first code
 150.220 +     * point of the subarray and the {@code count} argument specifies the
 150.221 +     * length of the subarray.  The contents of the subarray are converted to
 150.222 +     * {@code char}s; subsequent modification of the {@code int} array does not
 150.223 +     * affect the newly created string.
 150.224 +     *
 150.225 +     * @param  codePoints
 150.226 +     *         Array that is the source of Unicode code points
 150.227 +     *
 150.228 +     * @param  offset
 150.229 +     *         The initial offset
 150.230 +     *
 150.231 +     * @param  count
 150.232 +     *         The length
 150.233 +     *
 150.234 +     * @throws  IllegalArgumentException
 150.235 +     *          If any invalid Unicode code point is found in {@code
 150.236 +     *          codePoints}
 150.237 +     *
 150.238 +     * @throws  IndexOutOfBoundsException
 150.239 +     *          If the {@code offset} and {@code count} arguments index
 150.240 +     *          characters outside the bounds of the {@code codePoints} array
 150.241 +     *
 150.242 +     * @since  1.5
 150.243 +     */
 150.244 +    public String(int[] codePoints, int offset, int count) {
 150.245 +        if (offset < 0) {
 150.246 +            throw new StringIndexOutOfBoundsException(offset);
 150.247 +        }
 150.248 +        if (count < 0) {
 150.249 +            throw new StringIndexOutOfBoundsException(count);
 150.250 +        }
 150.251 +        // Note: offset or count might be near -1>>>1.
 150.252 +        if (offset > codePoints.length - count) {
 150.253 +            throw new StringIndexOutOfBoundsException(offset + count);
 150.254 +        }
 150.255 +
 150.256 +        final int end = offset + count;
 150.257 +
 150.258 +        // Pass 1: Compute precise size of char[]
 150.259 +        int n = count;
 150.260 +        for (int i = offset; i < end; i++) {
 150.261 +            int c = codePoints[i];
 150.262 +            if (Character.isBmpCodePoint(c))
 150.263 +                continue;
 150.264 +            else if (Character.isValidCodePoint(c))
 150.265 +                n++;
 150.266 +            else throw new IllegalArgumentException(Integer.toString(c));
 150.267 +        }
 150.268 +
 150.269 +        // Pass 2: Allocate and fill in char[]
 150.270 +        final char[] v = new char[n];
 150.271 +
 150.272 +        for (int i = offset, j = 0; i < end; i++, j++) {
 150.273 +            int c = codePoints[i];
 150.274 +            if (Character.isBmpCodePoint(c))
 150.275 +                v[j] = (char) c;
 150.276 +            else
 150.277 +                Character.toSurrogates(c, v, j++);
 150.278 +        }
 150.279 +
 150.280 +        this.r = new String(v, 0, n);
 150.281 +    }
 150.282 +
 150.283 +    /**
 150.284 +     * Allocates a new {@code String} constructed from a subarray of an array
 150.285 +     * of 8-bit integer values.
 150.286 +     *
 150.287 +     * <p> The {@code offset} argument is the index of the first byte of the
 150.288 +     * subarray, and the {@code count} argument specifies the length of the
 150.289 +     * subarray.
 150.290 +     *
 150.291 +     * <p> Each {@code byte} in the subarray is converted to a {@code char} as
 150.292 +     * specified in the method above.
 150.293 +     *
 150.294 +     * @deprecated This method does not properly convert bytes into characters.
 150.295 +     * As of JDK&nbsp;1.1, the preferred way to do this is via the
 150.296 +     * {@code String} constructors that take a {@link
 150.297 +     * java.nio.charset.Charset}, charset name, or that use the platform's
 150.298 +     * default charset.
 150.299 +     *
 150.300 +     * @param  ascii
 150.301 +     *         The bytes to be converted to characters
 150.302 +     *
 150.303 +     * @param  hibyte
 150.304 +     *         The top 8 bits of each 16-bit Unicode code unit
 150.305 +     *
 150.306 +     * @param  offset
 150.307 +     *         The initial offset
 150.308 +     * @param  count
 150.309 +     *         The length
 150.310 +     *
 150.311 +     * @throws  IndexOutOfBoundsException
 150.312 +     *          If the {@code offset} or {@code count} argument is invalid
 150.313 +     *
 150.314 +     * @see  #String(byte[], int)
 150.315 +     * @see  #String(byte[], int, int, java.lang.String)
 150.316 +     * @see  #String(byte[], int, int, java.nio.charset.Charset)
 150.317 +     * @see  #String(byte[], int, int)
 150.318 +     * @see  #String(byte[], java.lang.String)
 150.319 +     * @see  #String(byte[], java.nio.charset.Charset)
 150.320 +     * @see  #String(byte[])
 150.321 +     */
 150.322 +    @Deprecated
 150.323 +    public String(byte ascii[], int hibyte, int offset, int count) {
 150.324 +        checkBounds(ascii, offset, count);
 150.325 +        char value[] = new char[count];
 150.326 +
 150.327 +        if (hibyte == 0) {
 150.328 +            for (int i = count ; i-- > 0 ;) {
 150.329 +                value[i] = (char) (ascii[i + offset] & 0xff);
 150.330 +            }
 150.331 +        } else {
 150.332 +            hibyte <<= 8;
 150.333 +            for (int i = count ; i-- > 0 ;) {
 150.334 +                value[i] = (char) (hibyte | (ascii[i + offset] & 0xff));
 150.335 +            }
 150.336 +        }
 150.337 +        this.r = new String(value, 0, count);
 150.338 +    }
 150.339 +
 150.340 +    /**
 150.341 +     * Allocates a new {@code String} containing characters constructed from
 150.342 +     * an array of 8-bit integer values. Each character <i>c</i>in the
 150.343 +     * resulting string is constructed from the corresponding component
 150.344 +     * <i>b</i> in the byte array such that:
 150.345 +     *
 150.346 +     * <blockquote><pre>
 150.347 +     *     <b><i>c</i></b> == (char)(((hibyte &amp; 0xff) &lt;&lt; 8)
 150.348 +     *                         | (<b><i>b</i></b> &amp; 0xff))
 150.349 +     * </pre></blockquote>
 150.350 +     *
 150.351 +     * @deprecated  This method does not properly convert bytes into
 150.352 +     * characters.  As of JDK&nbsp;1.1, the preferred way to do this is via the
 150.353 +     * {@code String} constructors that take a {@link
 150.354 +     * java.nio.charset.Charset}, charset name, or that use the platform's
 150.355 +     * default charset.
 150.356 +     *
 150.357 +     * @param  ascii
 150.358 +     *         The bytes to be converted to characters
 150.359 +     *
 150.360 +     * @param  hibyte
 150.361 +     *         The top 8 bits of each 16-bit Unicode code unit
 150.362 +     *
 150.363 +     * @see  #String(byte[], int, int, java.lang.String)
 150.364 +     * @see  #String(byte[], int, int, java.nio.charset.Charset)
 150.365 +     * @see  #String(byte[], int, int)
 150.366 +     * @see  #String(byte[], java.lang.String)
 150.367 +     * @see  #String(byte[], java.nio.charset.Charset)
 150.368 +     * @see  #String(byte[])
 150.369 +     */
 150.370 +    @Deprecated
 150.371 +    public String(byte ascii[], int hibyte) {
 150.372 +        this(ascii, hibyte, 0, ascii.length);
 150.373 +    }
 150.374 +
 150.375 +    /* Common private utility method used to bounds check the byte array
 150.376 +     * and requested offset & length values used by the String(byte[],..)
 150.377 +     * constructors.
 150.378 +     */
 150.379 +    private static void checkBounds(byte[] bytes, int offset, int length) {
 150.380 +        if (length < 0)
 150.381 +            throw new StringIndexOutOfBoundsException(length);
 150.382 +        if (offset < 0)
 150.383 +            throw new StringIndexOutOfBoundsException(offset);
 150.384 +        if (offset > bytes.length - length)
 150.385 +            throw new StringIndexOutOfBoundsException(offset + length);
 150.386 +    }
 150.387 +
 150.388 +    /**
 150.389 +     * Constructs a new {@code String} by decoding the specified subarray of
 150.390 +     * bytes using the specified charset.  The length of the new {@code String}
 150.391 +     * is a function of the charset, and hence may not be equal to the length
 150.392 +     * of the subarray.
 150.393 +     *
 150.394 +     * <p> The behavior of this constructor when the given bytes are not valid
 150.395 +     * in the given charset is unspecified.  The {@link
 150.396 +     * java.nio.charset.CharsetDecoder} class should be used when more control
 150.397 +     * over the decoding process is required.
 150.398 +     *
 150.399 +     * @param  bytes
 150.400 +     *         The bytes to be decoded into characters
 150.401 +     *
 150.402 +     * @param  offset
 150.403 +     *         The index of the first byte to decode
 150.404 +     *
 150.405 +     * @param  length
 150.406 +     *         The number of bytes to decode
 150.407 +
 150.408 +     * @param  charsetName
 150.409 +     *         The name of a supported {@linkplain java.nio.charset.Charset
 150.410 +     *         charset}
 150.411 +     *
 150.412 +     * @throws  UnsupportedEncodingException
 150.413 +     *          If the named charset is not supported
 150.414 +     *
 150.415 +     * @throws  IndexOutOfBoundsException
 150.416 +     *          If the {@code offset} and {@code length} arguments index
 150.417 +     *          characters outside the bounds of the {@code bytes} array
 150.418 +     *
 150.419 +     * @since  JDK1.1
 150.420 +     */
 150.421 +//    public String(byte bytes[], int offset, int length, String charsetName)
 150.422 +//        throws UnsupportedEncodingException
 150.423 +//    {
 150.424 +//        if (charsetName == null)
 150.425 +//            throw new NullPointerException("charsetName");
 150.426 +//        checkBounds(bytes, offset, length);
 150.427 +//        char[] v = StringCoding.decode(charsetName, bytes, offset, length);
 150.428 +//        this.offset = 0;
 150.429 +//        this.count = v.length;
 150.430 +//        this.value = v;
 150.431 +//    }
 150.432 +
 150.433 +    /**
 150.434 +     * Constructs a new {@code String} by decoding the specified subarray of
 150.435 +     * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
 150.436 +     * The length of the new {@code String} is a function of the charset, and
 150.437 +     * hence may not be equal to the length of the subarray.
 150.438 +     *
 150.439 +     * <p> This method always replaces malformed-input and unmappable-character
 150.440 +     * sequences with this charset's default replacement string.  The {@link
 150.441 +     * java.nio.charset.CharsetDecoder} class should be used when more control
 150.442 +     * over the decoding process is required.
 150.443 +     *
 150.444 +     * @param  bytes
 150.445 +     *         The bytes to be decoded into characters
 150.446 +     *
 150.447 +     * @param  offset
 150.448 +     *         The index of the first byte to decode
 150.449 +     *
 150.450 +     * @param  length
 150.451 +     *         The number of bytes to decode
 150.452 +     *
 150.453 +     * @param  charset
 150.454 +     *         The {@linkplain java.nio.charset.Charset charset} to be used to
 150.455 +     *         decode the {@code bytes}
 150.456 +     *
 150.457 +     * @throws  IndexOutOfBoundsException
 150.458 +     *          If the {@code offset} and {@code length} arguments index
 150.459 +     *          characters outside the bounds of the {@code bytes} array
 150.460 +     *
 150.461 +     * @since  1.6
 150.462 +     */
 150.463 +    /* don't want dependnecy on Charset
 150.464 +    public String(byte bytes[], int offset, int length, Charset charset) {
 150.465 +        if (charset == null)
 150.466 +            throw new NullPointerException("charset");
 150.467 +        checkBounds(bytes, offset, length);
 150.468 +        char[] v = StringCoding.decode(charset, bytes, offset, length);
 150.469 +        this.offset = 0;
 150.470 +        this.count = v.length;
 150.471 +        this.value = v;
 150.472 +    }
 150.473 +    */
 150.474 +
 150.475 +    /**
 150.476 +     * Constructs a new {@code String} by decoding the specified array of bytes
 150.477 +     * using the specified {@linkplain java.nio.charset.Charset charset}.  The
 150.478 +     * length of the new {@code String} is a function of the charset, and hence
 150.479 +     * may not be equal to the length of the byte array.
 150.480 +     *
 150.481 +     * <p> The behavior of this constructor when the given bytes are not valid
 150.482 +     * in the given charset is unspecified.  The {@link
 150.483 +     * java.nio.charset.CharsetDecoder} class should be used when more control
 150.484 +     * over the decoding process is required.
 150.485 +     *
 150.486 +     * @param  bytes
 150.487 +     *         The bytes to be decoded into characters
 150.488 +     *
 150.489 +     * @param  charsetName
 150.490 +     *         The name of a supported {@linkplain java.nio.charset.Charset
 150.491 +     *         charset}
 150.492 +     *
 150.493 +     * @throws  UnsupportedEncodingException
 150.494 +     *          If the named charset is not supported
 150.495 +     *
 150.496 +     * @since  JDK1.1
 150.497 +     */
 150.498 +//    public String(byte bytes[], String charsetName)
 150.499 +//        throws UnsupportedEncodingException
 150.500 +//    {
 150.501 +//        this(bytes, 0, bytes.length, charsetName);
 150.502 +//    }
 150.503 +
 150.504 +    /**
 150.505 +     * Constructs a new {@code String} by decoding the specified array of
 150.506 +     * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
 150.507 +     * The length of the new {@code String} is a function of the charset, and
 150.508 +     * hence may not be equal to the length of the byte array.
 150.509 +     *
 150.510 +     * <p> This method always replaces malformed-input and unmappable-character
 150.511 +     * sequences with this charset's default replacement string.  The {@link
 150.512 +     * java.nio.charset.CharsetDecoder} class should be used when more control
 150.513 +     * over the decoding process is required.
 150.514 +     *
 150.515 +     * @param  bytes
 150.516 +     *         The bytes to be decoded into characters
 150.517 +     *
 150.518 +     * @param  charset
 150.519 +     *         The {@linkplain java.nio.charset.Charset charset} to be used to
 150.520 +     *         decode the {@code bytes}
 150.521 +     *
 150.522 +     * @since  1.6
 150.523 +     */
 150.524 +    /* don't want dep on Charset
 150.525 +    public String(byte bytes[], Charset charset) {
 150.526 +        this(bytes, 0, bytes.length, charset);
 150.527 +    }
 150.528 +    */
 150.529 +
 150.530 +    /**
 150.531 +     * Constructs a new {@code String} by decoding the specified subarray of
 150.532 +     * bytes using the platform's default charset.  The length of the new
 150.533 +     * {@code String} is a function of the charset, and hence may not be equal
 150.534 +     * to the length of the subarray.
 150.535 +     *
 150.536 +     * <p> The behavior of this constructor when the given bytes are not valid
 150.537 +     * in the default charset is unspecified.  The {@link
 150.538 +     * java.nio.charset.CharsetDecoder} class should be used when more control
 150.539 +     * over the decoding process is required.
 150.540 +     *
 150.541 +     * @param  bytes
 150.542 +     *         The bytes to be decoded into characters
 150.543 +     *
 150.544 +     * @param  offset
 150.545 +     *         The index of the first byte to decode
 150.546 +     *
 150.547 +     * @param  length
 150.548 +     *         The number of bytes to decode
 150.549 +     *
 150.550 +     * @throws  IndexOutOfBoundsException
 150.551 +     *          If the {@code offset} and the {@code length} arguments index
 150.552 +     *          characters outside the bounds of the {@code bytes} array
 150.553 +     *
 150.554 +     * @since  JDK1.1
 150.555 +     */
 150.556 +    public String(byte bytes[], int offset, int length) {
 150.557 +        checkBounds(bytes, offset, length);
 150.558 +        char[] v  = new char[length];
 150.559 +        for (int i = 0; i < length; i++) {
 150.560 +            v[i] = (char)bytes[offset++];
 150.561 +        }
 150.562 +        this.r = new String(v, 0, v.length);
 150.563 +    }
 150.564 +
 150.565 +    /**
 150.566 +     * Constructs a new {@code String} by decoding the specified array of bytes
 150.567 +     * using the platform's default charset.  The length of the new {@code
 150.568 +     * String} is a function of the charset, and hence may not be equal to the
 150.569 +     * length of the byte array.
 150.570 +     *
 150.571 +     * <p> The behavior of this constructor when the given bytes are not valid
 150.572 +     * in the default charset is unspecified.  The {@link
 150.573 +     * java.nio.charset.CharsetDecoder} class should be used when more control
 150.574 +     * over the decoding process is required.
 150.575 +     *
 150.576 +     * @param  bytes
 150.577 +     *         The bytes to be decoded into characters
 150.578 +     *
 150.579 +     * @since  JDK1.1
 150.580 +     */
 150.581 +    public String(byte bytes[]) {
 150.582 +        this(bytes, 0, bytes.length);
 150.583 +    }
 150.584 +
 150.585 +    /**
 150.586 +     * Allocates a new string that contains the sequence of characters
 150.587 +     * currently contained in the string buffer argument. The contents of the
 150.588 +     * string buffer are copied; subsequent modification of the string buffer
 150.589 +     * does not affect the newly created string.
 150.590 +     *
 150.591 +     * @param  buffer
 150.592 +     *         A {@code StringBuffer}
 150.593 +     */
 150.594 +    public String(StringBuffer buffer) {
 150.595 +        this.r = buffer.toString();
 150.596 +    }
 150.597 +
 150.598 +    /**
 150.599 +     * Allocates a new string that contains the sequence of characters
 150.600 +     * currently contained in the string builder argument. The contents of the
 150.601 +     * string builder are copied; subsequent modification of the string builder
 150.602 +     * does not affect the newly created string.
 150.603 +     *
 150.604 +     * <p> This constructor is provided to ease migration to {@code
 150.605 +     * StringBuilder}. Obtaining a string from a string builder via the {@code
 150.606 +     * toString} method is likely to run faster and is generally preferred.
 150.607 +     *
 150.608 +     * @param   builder
 150.609 +     *          A {@code StringBuilder}
 150.610 +     *
 150.611 +     * @since  1.5
 150.612 +     */
 150.613 +    public String(StringBuilder builder) {
 150.614 +        this.r = builder.toString();
 150.615 +    }
 150.616 +
 150.617 +    /**
 150.618 +     * Returns the length of this string.
 150.619 +     * The length is equal to the number of <a href="Character.html#unicode">Unicode
 150.620 +     * code units</a> in the string.
 150.621 +     *
 150.622 +     * @return  the length of the sequence of characters represented by this
 150.623 +     *          object.
 150.624 +     */
 150.625 +    @JavaScriptBody(args = {}, body = "return this.toString().length;")
 150.626 +    public int length() {
 150.627 +        throw new UnsupportedOperationException();
 150.628 +    }
 150.629 +
 150.630 +    /**
 150.631 +     * Returns <tt>true</tt> if, and only if, {@link #length()} is <tt>0</tt>.
 150.632 +     *
 150.633 +     * @return <tt>true</tt> if {@link #length()} is <tt>0</tt>, otherwise
 150.634 +     * <tt>false</tt>
 150.635 +     *
 150.636 +     * @since 1.6
 150.637 +     */
 150.638 +    @JavaScriptBody(args = {}, body="return this.toString().length === 0;")
 150.639 +    public boolean isEmpty() {
 150.640 +        return length() == 0;
 150.641 +    }
 150.642 +
 150.643 +    /**
 150.644 +     * Returns the <code>char</code> value at the
 150.645 +     * specified index. An index ranges from <code>0</code> to
 150.646 +     * <code>length() - 1</code>. The first <code>char</code> value of the sequence
 150.647 +     * is at index <code>0</code>, the next at index <code>1</code>,
 150.648 +     * and so on, as for array indexing.
 150.649 +     *
 150.650 +     * <p>If the <code>char</code> value specified by the index is a
 150.651 +     * <a href="Character.html#unicode">surrogate</a>, the surrogate
 150.652 +     * value is returned.
 150.653 +     *
 150.654 +     * @param      index   the index of the <code>char</code> value.
 150.655 +     * @return     the <code>char</code> value at the specified index of this string.
 150.656 +     *             The first <code>char</code> value is at index <code>0</code>.
 150.657 +     * @exception  IndexOutOfBoundsException  if the <code>index</code>
 150.658 +     *             argument is negative or not less than the length of this
 150.659 +     *             string.
 150.660 +     */
 150.661 +    @JavaScriptBody(args = { "index" }, 
 150.662 +        body = "return this.toString().charCodeAt(index);"
 150.663 +    )
 150.664 +    public char charAt(int index) {
 150.665 +        throw new UnsupportedOperationException();
 150.666 +    }
 150.667 +
 150.668 +    /**
 150.669 +     * Returns the character (Unicode code point) at the specified
 150.670 +     * index. The index refers to <code>char</code> values
 150.671 +     * (Unicode code units) and ranges from <code>0</code> to
 150.672 +     * {@link #length()}<code> - 1</code>.
 150.673 +     *
 150.674 +     * <p> If the <code>char</code> value specified at the given index
 150.675 +     * is in the high-surrogate range, the following index is less
 150.676 +     * than the length of this <code>String</code>, and the
 150.677 +     * <code>char</code> value at the following index is in the
 150.678 +     * low-surrogate range, then the supplementary code point
 150.679 +     * corresponding to this surrogate pair is returned. Otherwise,
 150.680 +     * the <code>char</code> value at the given index is returned.
 150.681 +     *
 150.682 +     * @param      index the index to the <code>char</code> values
 150.683 +     * @return     the code point value of the character at the
 150.684 +     *             <code>index</code>
 150.685 +     * @exception  IndexOutOfBoundsException  if the <code>index</code>
 150.686 +     *             argument is negative or not less than the length of this
 150.687 +     *             string.
 150.688 +     * @since      1.5
 150.689 +     */
 150.690 +    public int codePointAt(int index) {
 150.691 +        if ((index < 0) || (index >= length())) {
 150.692 +            throw new StringIndexOutOfBoundsException(index);
 150.693 +        }
 150.694 +        return Character.codePointAtImpl(toCharArray(), offset() + index, offset() + length());
 150.695 +    }
 150.696 +
 150.697 +    /**
 150.698 +     * Returns the character (Unicode code point) before the specified
 150.699 +     * index. The index refers to <code>char</code> values
 150.700 +     * (Unicode code units) and ranges from <code>1</code> to {@link
 150.701 +     * CharSequence#length() length}.
 150.702 +     *
 150.703 +     * <p> If the <code>char</code> value at <code>(index - 1)</code>
 150.704 +     * is in the low-surrogate range, <code>(index - 2)</code> is not
 150.705 +     * negative, and the <code>char</code> value at <code>(index -
 150.706 +     * 2)</code> is in the high-surrogate range, then the
 150.707 +     * supplementary code point value of the surrogate pair is
 150.708 +     * returned. If the <code>char</code> value at <code>index -
 150.709 +     * 1</code> is an unpaired low-surrogate or a high-surrogate, the
 150.710 +     * surrogate value is returned.
 150.711 +     *
 150.712 +     * @param     index the index following the code point that should be returned
 150.713 +     * @return    the Unicode code point value before the given index.
 150.714 +     * @exception IndexOutOfBoundsException if the <code>index</code>
 150.715 +     *            argument is less than 1 or greater than the length
 150.716 +     *            of this string.
 150.717 +     * @since     1.5
 150.718 +     */
 150.719 +    public int codePointBefore(int index) {
 150.720 +        int i = index - 1;
 150.721 +        if ((i < 0) || (i >= length())) {
 150.722 +            throw new StringIndexOutOfBoundsException(index);
 150.723 +        }
 150.724 +        return Character.codePointBeforeImpl(toCharArray(), offset() + index, offset());
 150.725 +    }
 150.726 +
 150.727 +    /**
 150.728 +     * Returns the number of Unicode code points in the specified text
 150.729 +     * range of this <code>String</code>. The text range begins at the
 150.730 +     * specified <code>beginIndex</code> and extends to the
 150.731 +     * <code>char</code> at index <code>endIndex - 1</code>. Thus the
 150.732 +     * length (in <code>char</code>s) of the text range is
 150.733 +     * <code>endIndex-beginIndex</code>. Unpaired surrogates within
 150.734 +     * the text range count as one code point each.
 150.735 +     *
 150.736 +     * @param beginIndex the index to the first <code>char</code> of
 150.737 +     * the text range.
 150.738 +     * @param endIndex the index after the last <code>char</code> of
 150.739 +     * the text range.
 150.740 +     * @return the number of Unicode code points in the specified text
 150.741 +     * range
 150.742 +     * @exception IndexOutOfBoundsException if the
 150.743 +     * <code>beginIndex</code> is negative, or <code>endIndex</code>
 150.744 +     * is larger than the length of this <code>String</code>, or
 150.745 +     * <code>beginIndex</code> is larger than <code>endIndex</code>.
 150.746 +     * @since  1.5
 150.747 +     */
 150.748 +    public int codePointCount(int beginIndex, int endIndex) {
 150.749 +        if (beginIndex < 0 || endIndex > length() || beginIndex > endIndex) {
 150.750 +            throw new IndexOutOfBoundsException();
 150.751 +        }
 150.752 +        return Character.codePointCountImpl(toCharArray(), offset()+beginIndex, endIndex-beginIndex);
 150.753 +    }
 150.754 +
 150.755 +    /**
 150.756 +     * Returns the index within this <code>String</code> that is
 150.757 +     * offset from the given <code>index</code> by
 150.758 +     * <code>codePointOffset</code> code points. Unpaired surrogates
 150.759 +     * within the text range given by <code>index</code> and
 150.760 +     * <code>codePointOffset</code> count as one code point each.
 150.761 +     *
 150.762 +     * @param index the index to be offset
 150.763 +     * @param codePointOffset the offset in code points
 150.764 +     * @return the index within this <code>String</code>
 150.765 +     * @exception IndexOutOfBoundsException if <code>index</code>
 150.766 +     *   is negative or larger then the length of this
 150.767 +     *   <code>String</code>, or if <code>codePointOffset</code> is positive
 150.768 +     *   and the substring starting with <code>index</code> has fewer
 150.769 +     *   than <code>codePointOffset</code> code points,
 150.770 +     *   or if <code>codePointOffset</code> is negative and the substring
 150.771 +     *   before <code>index</code> has fewer than the absolute value
 150.772 +     *   of <code>codePointOffset</code> code points.
 150.773 +     * @since 1.5
 150.774 +     */
 150.775 +    public int offsetByCodePoints(int index, int codePointOffset) {
 150.776 +        if (index < 0 || index > length()) {
 150.777 +            throw new IndexOutOfBoundsException();
 150.778 +        }
 150.779 +        return Character.offsetByCodePointsImpl(toCharArray(), offset(), length(),
 150.780 +                                                offset()+index, codePointOffset) - offset();
 150.781 +    }
 150.782 +
 150.783 +    /**
 150.784 +     * Copy characters from this string into dst starting at dstBegin.
 150.785 +     * This method doesn't perform any range checking.
 150.786 +     */
 150.787 +    @JavaScriptBody(args = { "arr", "to" }, body = 
 150.788 +        "var s = this.toString();\n" +
 150.789 +        "for (var i = 0; i < s.length; i++) {\n" +
 150.790 +        "   arr[to++] = s[i];\n" +
 150.791 +        "}"
 150.792 +    )
 150.793 +    void getChars(char dst[], int dstBegin) {
 150.794 +        System.arraycopy(toCharArray(), offset(), dst, dstBegin, length());
 150.795 +    }
 150.796 +
 150.797 +    /**
 150.798 +     * Copies characters from this string into the destination character
 150.799 +     * array.
 150.800 +     * <p>
 150.801 +     * The first character to be copied is at index <code>srcBegin</code>;
 150.802 +     * the last character to be copied is at index <code>srcEnd-1</code>
 150.803 +     * (thus the total number of characters to be copied is
 150.804 +     * <code>srcEnd-srcBegin</code>). The characters are copied into the
 150.805 +     * subarray of <code>dst</code> starting at index <code>dstBegin</code>
 150.806 +     * and ending at index:
 150.807 +     * <p><blockquote><pre>
 150.808 +     *     dstbegin + (srcEnd-srcBegin) - 1
 150.809 +     * </pre></blockquote>
 150.810 +     *
 150.811 +     * @param      srcBegin   index of the first character in the string
 150.812 +     *                        to copy.
 150.813 +     * @param      srcEnd     index after the last character in the string
 150.814 +     *                        to copy.
 150.815 +     * @param      dst        the destination array.
 150.816 +     * @param      dstBegin   the start offset in the destination array.
 150.817 +     * @exception IndexOutOfBoundsException If any of the following
 150.818 +     *            is true:
 150.819 +     *            <ul><li><code>srcBegin</code> is negative.
 150.820 +     *            <li><code>srcBegin</code> is greater than <code>srcEnd</code>
 150.821 +     *            <li><code>srcEnd</code> is greater than the length of this
 150.822 +     *                string
 150.823 +     *            <li><code>dstBegin</code> is negative
 150.824 +     *            <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
 150.825 +     *                <code>dst.length</code></ul>
 150.826 +     */
 150.827 +    @JavaScriptBody(args = { "beg", "end", "arr", "dst" }, body=
 150.828 +        "var s = this.toString();\n" +
 150.829 +        "while (beg < end) {\n" +
 150.830 +        "  arr[dst++] = s.charCodeAt(beg++);\n" +
 150.831 +        "}\n"
 150.832 +    )
 150.833 +    public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
 150.834 +        if (srcBegin < 0) {
 150.835 +            throw new StringIndexOutOfBoundsException(srcBegin);
 150.836 +        }
 150.837 +        if (srcEnd > length()) {
 150.838 +            throw new StringIndexOutOfBoundsException(srcEnd);
 150.839 +        }
 150.840 +        if (srcBegin > srcEnd) {
 150.841 +            throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
 150.842 +        }
 150.843 +        System.arraycopy(toCharArray(), offset() + srcBegin, dst, dstBegin,
 150.844 +             srcEnd - srcBegin);
 150.845 +    }
 150.846 +
 150.847 +    /**
 150.848 +     * Copies characters from this string into the destination byte array. Each
 150.849 +     * byte receives the 8 low-order bits of the corresponding character. The
 150.850 +     * eight high-order bits of each character are not copied and do not
 150.851 +     * participate in the transfer in any way.
 150.852 +     *
 150.853 +     * <p> The first character to be copied is at index {@code srcBegin}; the
 150.854 +     * last character to be copied is at index {@code srcEnd-1}.  The total
 150.855 +     * number of characters to be copied is {@code srcEnd-srcBegin}. The
 150.856 +     * characters, converted to bytes, are copied into the subarray of {@code
 150.857 +     * dst} starting at index {@code dstBegin} and ending at index:
 150.858 +     *
 150.859 +     * <blockquote><pre>
 150.860 +     *     dstbegin + (srcEnd-srcBegin) - 1
 150.861 +     * </pre></blockquote>
 150.862 +     *
 150.863 +     * @deprecated  This method does not properly convert characters into
 150.864 +     * bytes.  As of JDK&nbsp;1.1, the preferred way to do this is via the
 150.865 +     * {@link #getBytes()} method, which uses the platform's default charset.
 150.866 +     *
 150.867 +     * @param  srcBegin
 150.868 +     *         Index of the first character in the string to copy
 150.869 +     *
 150.870 +     * @param  srcEnd
 150.871 +     *         Index after the last character in the string to copy
 150.872 +     *
 150.873 +     * @param  dst
 150.874 +     *         The destination array
 150.875 +     *
 150.876 +     * @param  dstBegin
 150.877 +     *         The start offset in the destination array
 150.878 +     *
 150.879 +     * @throws  IndexOutOfBoundsException
 150.880 +     *          If any of the following is true:
 150.881 +     *          <ul>
 150.882 +     *            <li> {@code srcBegin} is negative
 150.883 +     *            <li> {@code srcBegin} is greater than {@code srcEnd}
 150.884 +     *            <li> {@code srcEnd} is greater than the length of this String
 150.885 +     *            <li> {@code dstBegin} is negative
 150.886 +     *            <li> {@code dstBegin+(srcEnd-srcBegin)} is larger than {@code
 150.887 +     *                 dst.length}
 150.888 +     *          </ul>
 150.889 +     */
 150.890 +    @Deprecated
 150.891 +    public void getBytes(int srcBegin, int srcEnd, byte dst[], int dstBegin) {
 150.892 +        if (srcBegin < 0) {
 150.893 +            throw new StringIndexOutOfBoundsException(srcBegin);
 150.894 +        }
 150.895 +        if (srcEnd > length()) {
 150.896 +            throw new StringIndexOutOfBoundsException(srcEnd);
 150.897 +        }
 150.898 +        if (srcBegin > srcEnd) {
 150.899 +            throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
 150.900 +        }
 150.901 +        int j = dstBegin;
 150.902 +        int n = offset() + srcEnd;
 150.903 +        int i = offset() + srcBegin;
 150.904 +        char[] val = toCharArray();   /* avoid getfield opcode */
 150.905 +
 150.906 +        while (i < n) {
 150.907 +            dst[j++] = (byte)val[i++];
 150.908 +        }
 150.909 +    }
 150.910 +
 150.911 +    /**
 150.912 +     * Encodes this {@code String} into a sequence of bytes using the named
 150.913 +     * charset, storing the result into a new byte array.
 150.914 +     *
 150.915 +     * <p> The behavior of this method when this string cannot be encoded in
 150.916 +     * the given charset is unspecified.  The {@link
 150.917 +     * java.nio.charset.CharsetEncoder} class should be used when more control
 150.918 +     * over the encoding process is required.
 150.919 +     *
 150.920 +     * @param  charsetName
 150.921 +     *         The name of a supported {@linkplain java.nio.charset.Charset
 150.922 +     *         charset}
 150.923 +     *
 150.924 +     * @return  The resultant byte array
 150.925 +     *
 150.926 +     * @throws  UnsupportedEncodingException
 150.927 +     *          If the named charset is not supported
 150.928 +     *
 150.929 +     * @since  JDK1.1
 150.930 +     */
 150.931 +//    public byte[] getBytes(String charsetName)
 150.932 +//        throws UnsupportedEncodingException
 150.933 +//    {
 150.934 +//        if (charsetName == null) throw new NullPointerException();
 150.935 +//        return StringCoding.encode(charsetName, value, offset, count);
 150.936 +//    }
 150.937 +
 150.938 +    /**
 150.939 +     * Encodes this {@code String} into a sequence of bytes using the given
 150.940 +     * {@linkplain java.nio.charset.Charset charset}, storing the result into a
 150.941 +     * new byte array.
 150.942 +     *
 150.943 +     * <p> This method always replaces malformed-input and unmappable-character
 150.944 +     * sequences with this charset's default replacement byte array.  The
 150.945 +     * {@link java.nio.charset.CharsetEncoder} class should be used when more
 150.946 +     * control over the encoding process is required.
 150.947 +     *
 150.948 +     * @param  charset
 150.949 +     *         The {@linkplain java.nio.charset.Charset} to be used to encode
 150.950 +     *         the {@code String}
 150.951 +     *
 150.952 +     * @return  The resultant byte array
 150.953 +     *
 150.954 +     * @since  1.6
 150.955 +     */
 150.956 +    /* don't want dep on Charset
 150.957 +    public byte[] getBytes(Charset charset) {
 150.958 +        if (charset == null) throw new NullPointerException();
 150.959 +        return StringCoding.encode(charset, value, offset, count);
 150.960 +    }
 150.961 +    */
 150.962 +
 150.963 +    /**
 150.964 +     * Encodes this {@code String} into a sequence of bytes using the
 150.965 +     * platform's default charset, storing the result into a new byte array.
 150.966 +     *
 150.967 +     * <p> The behavior of this method when this string cannot be encoded in
 150.968 +     * the default charset is unspecified.  The {@link
 150.969 +     * java.nio.charset.CharsetEncoder} class should be used when more control
 150.970 +     * over the encoding process is required.
 150.971 +     *
 150.972 +     * @return  The resultant byte array
 150.973 +     *
 150.974 +     * @since      JDK1.1
 150.975 +     */
 150.976 +    public byte[] getBytes() {
 150.977 +        int len = length();
 150.978 +        byte[] arr = new byte[len];
 150.979 +        for (int i = 0, j = 0; j < len; j++) {
 150.980 +            final int v = charAt(j);
 150.981 +            if (v < 128) {
 150.982 +                arr[i++] = (byte) v;
 150.983 +                continue;
 150.984 +            }
 150.985 +            if (v < 0x0800) {
 150.986 +                arr = System.expandArray(arr, i + 1);
 150.987 +                arr[i++] = (byte) (0xC0 | (v >> 6));
 150.988 +                arr[i++] = (byte) (0x80 | (0x3F & v));
 150.989 +                continue;
 150.990 +            }
 150.991 +            arr = System.expandArray(arr, i + 2);
 150.992 +            arr[i++] = (byte) (0xE0 | (v >> 12));
 150.993 +            arr[i++] = (byte) (0x80 | ((v >> 6) & 0x7F));
 150.994 +            arr[i++] = (byte) (0x80 | (0x3F & v));
 150.995 +        }
 150.996 +        return arr;
 150.997 +    }
 150.998 +
 150.999 +    /**
150.1000 +     * Compares this string to the specified object.  The result is {@code
150.1001 +     * true} if and only if the argument is not {@code null} and is a {@code
150.1002 +     * String} object that represents the same sequence of characters as this
150.1003 +     * object.
150.1004 +     *
150.1005 +     * @param  anObject
150.1006 +     *         The object to compare this {@code String} against
150.1007 +     *
150.1008 +     * @return  {@code true} if the given object represents a {@code String}
150.1009 +     *          equivalent to this string, {@code false} otherwise
150.1010 +     *
150.1011 +     * @see  #compareTo(String)
150.1012 +     * @see  #equalsIgnoreCase(String)
150.1013 +     */
150.1014 +    @JavaScriptBody(args = { "obj" }, body = 
150.1015 +        "return obj != null && obj.$instOf_java_lang_String && "
150.1016 +        + "this.toString() === obj.toString();"
150.1017 +    )
150.1018 +    public boolean equals(Object anObject) {
150.1019 +        if (this == anObject) {
150.1020 +            return true;
150.1021 +        }
150.1022 +        if (anObject instanceof String) {
150.1023 +            String anotherString = (String)anObject;
150.1024 +            int n = length();
150.1025 +            if (n == anotherString.length()) {
150.1026 +                char v1[] = toCharArray();
150.1027 +                char v2[] = anotherString.toCharArray();
150.1028 +                int i = offset();
150.1029 +                int j = anotherString.offset();
150.1030 +                while (n-- != 0) {
150.1031 +                    if (v1[i++] != v2[j++])
150.1032 +                        return false;
150.1033 +                }
150.1034 +                return true;
150.1035 +            }
150.1036 +        }
150.1037 +        return false;
150.1038 +    }
150.1039 +
150.1040 +    /**
150.1041 +     * Compares this string to the specified {@code StringBuffer}.  The result
150.1042 +     * is {@code true} if and only if this {@code String} represents the same
150.1043 +     * sequence of characters as the specified {@code StringBuffer}.
150.1044 +     *
150.1045 +     * @param  sb
150.1046 +     *         The {@code StringBuffer} to compare this {@code String} against
150.1047 +     *
150.1048 +     * @return  {@code true} if this {@code String} represents the same
150.1049 +     *          sequence of characters as the specified {@code StringBuffer},
150.1050 +     *          {@code false} otherwise
150.1051 +     *
150.1052 +     * @since  1.4
150.1053 +     */
150.1054 +    public boolean contentEquals(StringBuffer sb) {
150.1055 +        synchronized(sb) {
150.1056 +            return contentEquals((CharSequence)sb);
150.1057 +        }
150.1058 +    }
150.1059 +
150.1060 +    /**
150.1061 +     * Compares this string to the specified {@code CharSequence}.  The result
150.1062 +     * is {@code true} if and only if this {@code String} represents the same
150.1063 +     * sequence of char values as the specified sequence.
150.1064 +     *
150.1065 +     * @param  cs
150.1066 +     *         The sequence to compare this {@code String} against
150.1067 +     *
150.1068 +     * @return  {@code true} if this {@code String} represents the same
150.1069 +     *          sequence of char values as the specified sequence, {@code
150.1070 +     *          false} otherwise
150.1071 +     *
150.1072 +     * @since  1.5
150.1073 +     */
150.1074 +    public boolean contentEquals(CharSequence cs) {
150.1075 +        if (length() != cs.length())
150.1076 +            return false;
150.1077 +        // Argument is a StringBuffer, StringBuilder
150.1078 +        if (cs instanceof AbstractStringBuilder) {
150.1079 +            char v1[] = toCharArray();
150.1080 +            char v2[] = ((AbstractStringBuilder)cs).getValue();
150.1081 +            int i = offset();
150.1082 +            int j = 0;
150.1083 +            int n = length();
150.1084 +            while (n-- != 0) {
150.1085 +                if (v1[i++] != v2[j++])
150.1086 +                    return false;
150.1087 +            }
150.1088 +            return true;
150.1089 +        }
150.1090 +        // Argument is a String
150.1091 +        if (cs.equals(this))
150.1092 +            return true;
150.1093 +        // Argument is a generic CharSequence
150.1094 +        char v1[] = toCharArray();
150.1095 +        int i = offset();
150.1096 +        int j = 0;
150.1097 +        int n = length();
150.1098 +        while (n-- != 0) {
150.1099 +            if (v1[i++] != cs.charAt(j++))
150.1100 +                return false;
150.1101 +        }
150.1102 +        return true;
150.1103 +    }
150.1104 +
150.1105 +    /**
150.1106 +     * Compares this {@code String} to another {@code String}, ignoring case
150.1107 +     * considerations.  Two strings are considered equal ignoring case if they
150.1108 +     * are of the same length and corresponding characters in the two strings
150.1109 +     * are equal ignoring case.
150.1110 +     *
150.1111 +     * <p> Two characters {@code c1} and {@code c2} are considered the same
150.1112 +     * ignoring case if at least one of the following is true:
150.1113 +     * <ul>
150.1114 +     *   <li> The two characters are the same (as compared by the
150.1115 +     *        {@code ==} operator)
150.1116 +     *   <li> Applying the method {@link
150.1117 +     *        java.lang.Character#toUpperCase(char)} to each character
150.1118 +     *        produces the same result
150.1119 +     *   <li> Applying the method {@link
150.1120 +     *        java.lang.Character#toLowerCase(char)} to each character
150.1121 +     *        produces the same result
150.1122 +     * </ul>
150.1123 +     *
150.1124 +     * @param  anotherString
150.1125 +     *         The {@code String} to compare this {@code String} against
150.1126 +     *
150.1127 +     * @return  {@code true} if the argument is not {@code null} and it
150.1128 +     *          represents an equivalent {@code String} ignoring case; {@code
150.1129 +     *          false} otherwise
150.1130 +     *
150.1131 +     * @see  #equals(Object)
150.1132 +     */
150.1133 +    public boolean equalsIgnoreCase(String anotherString) {
150.1134 +        return (this == anotherString) ? true :
150.1135 +               (anotherString != null) && (anotherString.length() == length()) &&
150.1136 +               regionMatches(true, 0, anotherString, 0, length());
150.1137 +    }
150.1138 +
150.1139 +    /**
150.1140 +     * Compares two strings lexicographically.
150.1141 +     * The comparison is based on the Unicode value of each character in
150.1142 +     * the strings. The character sequence represented by this
150.1143 +     * <code>String</code> object is compared lexicographically to the
150.1144 +     * character sequence represented by the argument string. The result is
150.1145 +     * a negative integer if this <code>String</code> object
150.1146 +     * lexicographically precedes the argument string. The result is a
150.1147 +     * positive integer if this <code>String</code> object lexicographically
150.1148 +     * follows the argument string. The result is zero if the strings
150.1149 +     * are equal; <code>compareTo</code> returns <code>0</code> exactly when
150.1150 +     * the {@link #equals(Object)} method would return <code>true</code>.
150.1151 +     * <p>
150.1152 +     * This is the definition of lexicographic ordering. If two strings are
150.1153 +     * different, then either they have different characters at some index
150.1154 +     * that is a valid index for both strings, or their lengths are different,
150.1155 +     * or both. If they have different characters at one or more index
150.1156 +     * positions, let <i>k</i> be the smallest such index; then the string
150.1157 +     * whose character at position <i>k</i> has the smaller value, as
150.1158 +     * determined by using the &lt; operator, lexicographically precedes the
150.1159 +     * other string. In this case, <code>compareTo</code> returns the
150.1160 +     * difference of the two character values at position <code>k</code> in
150.1161 +     * the two string -- that is, the value:
150.1162 +     * <blockquote><pre>
150.1163 +     * this.charAt(k)-anotherString.charAt(k)
150.1164 +     * </pre></blockquote>
150.1165 +     * If there is no index position at which they differ, then the shorter
150.1166 +     * string lexicographically precedes the longer string. In this case,
150.1167 +     * <code>compareTo</code> returns the difference of the lengths of the
150.1168 +     * strings -- that is, the value:
150.1169 +     * <blockquote><pre>
150.1170 +     * this.length()-anotherString.length()
150.1171 +     * </pre></blockquote>
150.1172 +     *
150.1173 +     * @param   anotherString   the <code>String</code> to be compared.
150.1174 +     * @return  the value <code>0</code> if the argument string is equal to
150.1175 +     *          this string; a value less than <code>0</code> if this string
150.1176 +     *          is lexicographically less than the string argument; and a
150.1177 +     *          value greater than <code>0</code> if this string is
150.1178 +     *          lexicographically greater than the string argument.
150.1179 +     */
150.1180 +    public int compareTo(String anotherString) {
150.1181 +        int len1 = length();
150.1182 +        int len2 = anotherString.length();
150.1183 +        int n = Math.min(len1, len2);
150.1184 +        char v1[] = toCharArray();
150.1185 +        char v2[] = anotherString.toCharArray();
150.1186 +        int i = offset();
150.1187 +        int j = anotherString.offset();
150.1188 +
150.1189 +        if (i == j) {
150.1190 +            int k = i;
150.1191 +            int lim = n + i;
150.1192 +            while (k < lim) {
150.1193 +                char c1 = v1[k];
150.1194 +                char c2 = v2[k];
150.1195 +                if (c1 != c2) {
150.1196 +                    return c1 - c2;
150.1197 +                }
150.1198 +                k++;
150.1199 +            }
150.1200 +        } else {
150.1201 +            while (n-- != 0) {
150.1202 +                char c1 = v1[i++];
150.1203 +                char c2 = v2[j++];
150.1204 +                if (c1 != c2) {
150.1205 +                    return c1 - c2;
150.1206 +                }
150.1207 +            }
150.1208 +        }
150.1209 +        return len1 - len2;
150.1210 +    }
150.1211 +
150.1212 +    /**
150.1213 +     * A Comparator that orders <code>String</code> objects as by
150.1214 +     * <code>compareToIgnoreCase</code>. This comparator is serializable.
150.1215 +     * <p>
150.1216 +     * Note that this Comparator does <em>not</em> take locale into account,
150.1217 +     * and will result in an unsatisfactory ordering for certain locales.
150.1218 +     * The java.text package provides <em>Collators</em> to allow
150.1219 +     * locale-sensitive ordering.
150.1220 +     *
150.1221 +     * @see     java.text.Collator#compare(String, String)
150.1222 +     * @since   1.2
150.1223 +     */
150.1224 +    public static final Comparator<String> CASE_INSENSITIVE_ORDER
150.1225 +                                         = new CaseInsensitiveComparator();
150.1226 +
150.1227 +    private static int offset() {
150.1228 +        return 0;
150.1229 +    }
150.1230 +    
150.1231 +    private static class CaseInsensitiveComparator
150.1232 +                         implements Comparator<String>, java.io.Serializable {
150.1233 +        // use serialVersionUID from JDK 1.2.2 for interoperability
150.1234 +        private static final long serialVersionUID = 8575799808933029326L;
150.1235 +
150.1236 +        public int compare(String s1, String s2) {
150.1237 +            int n1 = s1.length();
150.1238 +            int n2 = s2.length();
150.1239 +            int min = Math.min(n1, n2);
150.1240 +            for (int i = 0; i < min; i++) {
150.1241 +                char c1 = s1.charAt(i);
150.1242 +                char c2 = s2.charAt(i);
150.1243 +                if (c1 != c2) {
150.1244 +                    c1 = Character.toUpperCase(c1);
150.1245 +                    c2 = Character.toUpperCase(c2);
150.1246 +                    if (c1 != c2) {
150.1247 +                        c1 = Character.toLowerCase(c1);
150.1248 +                        c2 = Character.toLowerCase(c2);
150.1249 +                        if (c1 != c2) {
150.1250 +                            // No overflow because of numeric promotion
150.1251 +                            return c1 - c2;
150.1252 +                        }
150.1253 +                    }
150.1254 +                }
150.1255 +            }
150.1256 +            return n1 - n2;
150.1257 +        }
150.1258 +    }
150.1259 +
150.1260 +    /**
150.1261 +     * Compares two strings lexicographically, ignoring case
150.1262 +     * differences. This method returns an integer whose sign is that of
150.1263 +     * calling <code>compareTo</code> with normalized versions of the strings
150.1264 +     * where case differences have been eliminated by calling
150.1265 +     * <code>Character.toLowerCase(Character.toUpperCase(character))</code> on
150.1266 +     * each character.
150.1267 +     * <p>
150.1268 +     * Note that this method does <em>not</em> take locale into account,
150.1269 +     * and will result in an unsatisfactory ordering for certain locales.
150.1270 +     * The java.text package provides <em>collators</em> to allow
150.1271 +     * locale-sensitive ordering.
150.1272 +     *
150.1273 +     * @param   str   the <code>String</code> to be compared.
150.1274 +     * @return  a negative integer, zero, or a positive integer as the
150.1275 +     *          specified String is greater than, equal to, or less
150.1276 +     *          than this String, ignoring case considerations.
150.1277 +     * @see     java.text.Collator#compare(String, String)
150.1278 +     * @since   1.2
150.1279 +     */
150.1280 +    public int compareToIgnoreCase(String str) {
150.1281 +        return CASE_INSENSITIVE_ORDER.compare(this, str);
150.1282 +    }
150.1283 +
150.1284 +    /**
150.1285 +     * Tests if two string regions are equal.
150.1286 +     * <p>
150.1287 +     * A substring of this <tt>String</tt> object is compared to a substring
150.1288 +     * of the argument other. The result is true if these substrings
150.1289 +     * represent identical character sequences. The substring of this
150.1290 +     * <tt>String</tt> object to be compared begins at index <tt>toffset</tt>
150.1291 +     * and has length <tt>len</tt>. The substring of other to be compared
150.1292 +     * begins at index <tt>ooffset</tt> and has length <tt>len</tt>. The
150.1293 +     * result is <tt>false</tt> if and only if at least one of the following
150.1294 +     * is true:
150.1295 +     * <ul><li><tt>toffset</tt> is negative.
150.1296 +     * <li><tt>ooffset</tt> is negative.
150.1297 +     * <li><tt>toffset+len</tt> is greater than the length of this
150.1298 +     * <tt>String</tt> object.
150.1299 +     * <li><tt>ooffset+len</tt> is greater than the length of the other
150.1300 +     * argument.
150.1301 +     * <li>There is some nonnegative integer <i>k</i> less than <tt>len</tt>
150.1302 +     * such that:
150.1303 +     * <tt>this.charAt(toffset+<i>k</i>)&nbsp;!=&nbsp;other.charAt(ooffset+<i>k</i>)</tt>
150.1304 +     * </ul>
150.1305 +     *
150.1306 +     * @param   toffset   the starting offset of the subregion in this string.
150.1307 +     * @param   other     the string argument.
150.1308 +     * @param   ooffset   the starting offset of the subregion in the string
150.1309 +     *                    argument.
150.1310 +     * @param   len       the number of characters to compare.
150.1311 +     * @return  <code>true</code> if the specified subregion of this string
150.1312 +     *          exactly matches the specified subregion of the string argument;
150.1313 +     *          <code>false</code> otherwise.
150.1314 +     */
150.1315 +    public boolean regionMatches(int toffset, String other, int ooffset,
150.1316 +                                 int len) {
150.1317 +        char ta[] = toCharArray();
150.1318 +        int to = offset() + toffset;
150.1319 +        char pa[] = other.toCharArray();
150.1320 +        int po = other.offset() + ooffset;
150.1321 +        // Note: toffset, ooffset, or len might be near -1>>>1.
150.1322 +        if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len)
150.1323 +            || (ooffset > (long)other.length() - len)) {
150.1324 +            return false;
150.1325 +        }
150.1326 +        while (len-- > 0) {
150.1327 +            if (ta[to++] != pa[po++]) {
150.1328 +                return false;
150.1329 +            }
150.1330 +        }
150.1331 +        return true;
150.1332 +    }
150.1333 +
150.1334 +    /**
150.1335 +     * Tests if two string regions are equal.
150.1336 +     * <p>
150.1337 +     * A substring of this <tt>String</tt> object is compared to a substring
150.1338 +     * of the argument <tt>other</tt>. The result is <tt>true</tt> if these
150.1339 +     * substrings represent character sequences that are the same, ignoring
150.1340 +     * case if and only if <tt>ignoreCase</tt> is true. The substring of
150.1341 +     * this <tt>String</tt> object to be compared begins at index
150.1342 +     * <tt>toffset</tt> and has length <tt>len</tt>. The substring of
150.1343 +     * <tt>other</tt> to be compared begins at index <tt>ooffset</tt> and
150.1344 +     * has length <tt>len</tt>. The result is <tt>false</tt> if and only if
150.1345 +     * at least one of the following is true:
150.1346 +     * <ul><li><tt>toffset</tt> is negative.
150.1347 +     * <li><tt>ooffset</tt> is negative.
150.1348 +     * <li><tt>toffset+len</tt> is greater than the length of this
150.1349 +     * <tt>String</tt> object.
150.1350 +     * <li><tt>ooffset+len</tt> is greater than the length of the other
150.1351 +     * argument.
150.1352 +     * <li><tt>ignoreCase</tt> is <tt>false</tt> and there is some nonnegative
150.1353 +     * integer <i>k</i> less than <tt>len</tt> such that:
150.1354 +     * <blockquote><pre>
150.1355 +     * this.charAt(toffset+k) != other.charAt(ooffset+k)
150.1356 +     * </pre></blockquote>
150.1357 +     * <li><tt>ignoreCase</tt> is <tt>true</tt> and there is some nonnegative
150.1358 +     * integer <i>k</i> less than <tt>len</tt> such that:
150.1359 +     * <blockquote><pre>
150.1360 +     * Character.toLowerCase(this.charAt(toffset+k)) !=
150.1361 +               Character.toLowerCase(other.charAt(ooffset+k))
150.1362 +     * </pre></blockquote>
150.1363 +     * and:
150.1364 +     * <blockquote><pre>
150.1365 +     * Character.toUpperCase(this.charAt(toffset+k)) !=
150.1366 +     *         Character.toUpperCase(other.charAt(ooffset+k))
150.1367 +     * </pre></blockquote>
150.1368 +     * </ul>
150.1369 +     *
150.1370 +     * @param   ignoreCase   if <code>true</code>, ignore case when comparing
150.1371 +     *                       characters.
150.1372 +     * @param   toffset      the starting offset of the subregion in this
150.1373 +     *                       string.
150.1374 +     * @param   other        the string argument.
150.1375 +     * @param   ooffset      the starting offset of the subregion in the string
150.1376 +     *                       argument.
150.1377 +     * @param   len          the number of characters to compare.
150.1378 +     * @return  <code>true</code> if the specified subregion of this string
150.1379 +     *          matches the specified subregion of the string argument;
150.1380 +     *          <code>false</code> otherwise. Whether the matching is exact
150.1381 +     *          or case insensitive depends on the <code>ignoreCase</code>
150.1382 +     *          argument.
150.1383 +     */
150.1384 +    public boolean regionMatches(boolean ignoreCase, int toffset,
150.1385 +                           String other, int ooffset, int len) {
150.1386 +        char ta[] = toCharArray();
150.1387 +        int to = offset() + toffset;
150.1388 +        char pa[] = other.toCharArray();
150.1389 +        int po = other.offset() + ooffset;
150.1390 +        // Note: toffset, ooffset, or len might be near -1>>>1.
150.1391 +        if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len) ||
150.1392 +                (ooffset > (long)other.length() - len)) {
150.1393 +            return false;
150.1394 +        }
150.1395 +        while (len-- > 0) {
150.1396 +            char c1 = ta[to++];
150.1397 +            char c2 = pa[po++];
150.1398 +            if (c1 == c2) {
150.1399 +                continue;
150.1400 +            }
150.1401 +            if (ignoreCase) {
150.1402 +                // If characters don't match but case may be ignored,
150.1403 +                // try converting both characters to uppercase.
150.1404 +                // If the results match, then the comparison scan should
150.1405 +                // continue.
150.1406 +                char u1 = Character.toUpperCase(c1);
150.1407 +                char u2 = Character.toUpperCase(c2);
150.1408 +                if (u1 == u2) {
150.1409 +                    continue;
150.1410 +                }
150.1411 +                // Unfortunately, conversion to uppercase does not work properly
150.1412 +                // for the Georgian alphabet, which has strange rules about case
150.1413 +                // conversion.  So we need to make one last check before
150.1414 +                // exiting.
150.1415 +                if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
150.1416 +                    continue;
150.1417 +                }
150.1418 +            }
150.1419 +            return false;
150.1420 +        }
150.1421 +        return true;
150.1422 +    }
150.1423 +
150.1424 +    /**
150.1425 +     * Tests if the substring of this string beginning at the
150.1426 +     * specified index starts with the specified prefix.
150.1427 +     *
150.1428 +     * @param   prefix    the prefix.
150.1429 +     * @param   toffset   where to begin looking in this string.
150.1430 +     * @return  <code>true</code> if the character sequence represented by the
150.1431 +     *          argument is a prefix of the substring of this object starting
150.1432 +     *          at index <code>toffset</code>; <code>false</code> otherwise.
150.1433 +     *          The result is <code>false</code> if <code>toffset</code> is
150.1434 +     *          negative or greater than the length of this
150.1435 +     *          <code>String</code> object; otherwise the result is the same
150.1436 +     *          as the result of the expression
150.1437 +     *          <pre>
150.1438 +     *          this.substring(toffset).startsWith(prefix)
150.1439 +     *          </pre>
150.1440 +     */
150.1441 +    @JavaScriptBody(args = { "find", "from" }, body=
150.1442 +        "find = find.toString();\n" +
150.1443 +        "return this.toString().substring(from, from + find.length) === find;\n"
150.1444 +    )
150.1445 +    public boolean startsWith(String prefix, int toffset) {
150.1446 +        char ta[] = toCharArray();
150.1447 +        int to = offset() + toffset;
150.1448 +        char pa[] = prefix.toCharArray();
150.1449 +        int po = prefix.offset();
150.1450 +        int pc = prefix.length();
150.1451 +        // Note: toffset might be near -1>>>1.
150.1452 +        if ((toffset < 0) || (toffset > length() - pc)) {
150.1453 +            return false;
150.1454 +        }
150.1455 +        while (--pc >= 0) {
150.1456 +            if (ta[to++] != pa[po++]) {
150.1457 +                return false;
150.1458 +            }
150.1459 +        }
150.1460 +        return true;
150.1461 +    }
150.1462 +
150.1463 +    /**
150.1464 +     * Tests if this string starts with the specified prefix.
150.1465 +     *
150.1466 +     * @param   prefix   the prefix.
150.1467 +     * @return  <code>true</code> if the character sequence represented by the
150.1468 +     *          argument is a prefix of the character sequence represented by
150.1469 +     *          this string; <code>false</code> otherwise.
150.1470 +     *          Note also that <code>true</code> will be returned if the
150.1471 +     *          argument is an empty string or is equal to this
150.1472 +     *          <code>String</code> object as determined by the
150.1473 +     *          {@link #equals(Object)} method.
150.1474 +     * @since   1. 0
150.1475 +     */
150.1476 +    public boolean startsWith(String prefix) {
150.1477 +        return startsWith(prefix, 0);
150.1478 +    }
150.1479 +
150.1480 +    /**
150.1481 +     * Tests if this string ends with the specified suffix.
150.1482 +     *
150.1483 +     * @param   suffix   the suffix.
150.1484 +     * @return  <code>true</code> if the character sequence represented by the
150.1485 +     *          argument is a suffix of the character sequence represented by
150.1486 +     *          this object; <code>false</code> otherwise. Note that the
150.1487 +     *          result will be <code>true</code> if the argument is the
150.1488 +     *          empty string or is equal to this <code>String</code> object
150.1489 +     *          as determined by the {@link #equals(Object)} method.
150.1490 +     */
150.1491 +    public boolean endsWith(String suffix) {
150.1492 +        return startsWith(suffix, length() - suffix.length());
150.1493 +    }
150.1494 +
150.1495 +    /**
150.1496 +     * Returns a hash code for this string. The hash code for a
150.1497 +     * <code>String</code> object is computed as
150.1498 +     * <blockquote><pre>
150.1499 +     * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
150.1500 +     * </pre></blockquote>
150.1501 +     * using <code>int</code> arithmetic, where <code>s[i]</code> is the
150.1502 +     * <i>i</i>th character of the string, <code>n</code> is the length of
150.1503 +     * the string, and <code>^</code> indicates exponentiation.
150.1504 +     * (The hash value of the empty string is zero.)
150.1505 +     *
150.1506 +     * @return  a hash code value for this object.
150.1507 +     */
150.1508 +    public int hashCode() {
150.1509 +        return super.hashCode();
150.1510 +    }
150.1511 +    int computeHashCode() {
150.1512 +        int h = 0;
150.1513 +        if (h == 0 && length() > 0) {
150.1514 +            int off = offset();
150.1515 +            int len = length();
150.1516 +
150.1517 +            for (int i = 0; i < len; i++) {
150.1518 +                h = 31*h + charAt(off++);
150.1519 +            }
150.1520 +        }
150.1521 +        return h;
150.1522 +    }
150.1523 +
150.1524 +    /**
150.1525 +     * Returns the index within this string of the first occurrence of
150.1526 +     * the specified character. If a character with value
150.1527 +     * <code>ch</code> occurs in the character sequence represented by
150.1528 +     * this <code>String</code> object, then the index (in Unicode
150.1529 +     * code units) of the first such occurrence is returned. For
150.1530 +     * values of <code>ch</code> in the range from 0 to 0xFFFF
150.1531 +     * (inclusive), this is the smallest value <i>k</i> such that:
150.1532 +     * <blockquote><pre>
150.1533 +     * this.charAt(<i>k</i>) == ch
150.1534 +     * </pre></blockquote>
150.1535 +     * is true. For other values of <code>ch</code>, it is the
150.1536 +     * smallest value <i>k</i> such that:
150.1537 +     * <blockquote><pre>
150.1538 +     * this.codePointAt(<i>k</i>) == ch
150.1539 +     * </pre></blockquote>
150.1540 +     * is true. In either case, if no such character occurs in this
150.1541 +     * string, then <code>-1</code> is returned.
150.1542 +     *
150.1543 +     * @param   ch   a character (Unicode code point).
150.1544 +     * @return  the index of the first occurrence of the character in the
150.1545 +     *          character sequence represented by this object, or
150.1546 +     *          <code>-1</code> if the character does not occur.
150.1547 +     */
150.1548 +    public int indexOf(int ch) {
150.1549 +        return indexOf(ch, 0);
150.1550 +    }
150.1551 +
150.1552 +    /**
150.1553 +     * Returns the index within this string of the first occurrence of the
150.1554 +     * specified character, starting the search at the specified index.
150.1555 +     * <p>
150.1556 +     * If a character with value <code>ch</code> occurs in the
150.1557 +     * character sequence represented by this <code>String</code>
150.1558 +     * object at an index no smaller than <code>fromIndex</code>, then
150.1559 +     * the index of the first such occurrence is returned. For values
150.1560 +     * of <code>ch</code> in the range from 0 to 0xFFFF (inclusive),
150.1561 +     * this is the smallest value <i>k</i> such that:
150.1562 +     * <blockquote><pre>
150.1563 +     * (this.charAt(<i>k</i>) == ch) && (<i>k</i> &gt;= fromIndex)
150.1564 +     * </pre></blockquote>
150.1565 +     * is true. For other values of <code>ch</code>, it is the
150.1566 +     * smallest value <i>k</i> such that:
150.1567 +     * <blockquote><pre>
150.1568 +     * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> &gt;= fromIndex)
150.1569 +     * </pre></blockquote>
150.1570 +     * is true. In either case, if no such character occurs in this
150.1571 +     * string at or after position <code>fromIndex</code>, then
150.1572 +     * <code>-1</code> is returned.
150.1573 +     *
150.1574 +     * <p>
150.1575 +     * There is no restriction on the value of <code>fromIndex</code>. If it
150.1576 +     * is negative, it has the same effect as if it were zero: this entire
150.1577 +     * string may be searched. If it is greater than the length of this
150.1578 +     * string, it has the same effect as if it were equal to the length of
150.1579 +     * this string: <code>-1</code> is returned.
150.1580 +     *
150.1581 +     * <p>All indices are specified in <code>char</code> values
150.1582 +     * (Unicode code units).
150.1583 +     *
150.1584 +     * @param   ch          a character (Unicode code point).
150.1585 +     * @param   fromIndex   the index to start the search from.
150.1586 +     * @return  the index of the first occurrence of the character in the
150.1587 +     *          character sequence represented by this object that is greater
150.1588 +     *          than or equal to <code>fromIndex</code>, or <code>-1</code>
150.1589 +     *          if the character does not occur.
150.1590 +     */
150.1591 +    @JavaScriptBody(args = { "ch", "from" }, body = 
150.1592 +        "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
150.1593 +        "return this.toString().indexOf(ch, from);\n"
150.1594 +    )
150.1595 +    public int indexOf(int ch, int fromIndex) {
150.1596 +        if (fromIndex < 0) {
150.1597 +            fromIndex = 0;
150.1598 +        } else if (fromIndex >= length()) {
150.1599 +            // Note: fromIndex might be near -1>>>1.
150.1600 +            return -1;
150.1601 +        }
150.1602 +
150.1603 +        if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
150.1604 +            // handle most cases here (ch is a BMP code point or a
150.1605 +            // negative value (invalid code point))
150.1606 +            final char[] value = this.toCharArray();
150.1607 +            final int offset = this.offset();
150.1608 +            final int max = offset + length();
150.1609 +            for (int i = offset + fromIndex; i < max ; i++) {
150.1610 +                if (value[i] == ch) {
150.1611 +                    return i - offset;
150.1612 +                }
150.1613 +            }
150.1614 +            return -1;
150.1615 +        } else {
150.1616 +            return indexOfSupplementary(ch, fromIndex);
150.1617 +        }
150.1618 +    }
150.1619 +
150.1620 +    /**
150.1621 +     * Handles (rare) calls of indexOf with a supplementary character.
150.1622 +     */
150.1623 +    private int indexOfSupplementary(int ch, int fromIndex) {
150.1624 +        if (Character.isValidCodePoint(ch)) {
150.1625 +            final char[] value = this.toCharArray();
150.1626 +            final int offset = this.offset();
150.1627 +            final char hi = Character.highSurrogate(ch);
150.1628 +            final char lo = Character.lowSurrogate(ch);
150.1629 +            final int max = offset + length() - 1;
150.1630 +            for (int i = offset + fromIndex; i < max; i++) {
150.1631 +                if (value[i] == hi && value[i+1] == lo) {
150.1632 +                    return i - offset;
150.1633 +                }
150.1634 +            }
150.1635 +        }
150.1636 +        return -1;
150.1637 +    }
150.1638 +
150.1639 +    /**
150.1640 +     * Returns the index within this string of the last occurrence of
150.1641 +     * the specified character. For values of <code>ch</code> in the
150.1642 +     * range from 0 to 0xFFFF (inclusive), the index (in Unicode code
150.1643 +     * units) returned is the largest value <i>k</i> such that:
150.1644 +     * <blockquote><pre>
150.1645 +     * this.charAt(<i>k</i>) == ch
150.1646 +     * </pre></blockquote>
150.1647 +     * is true. For other values of <code>ch</code>, it is the
150.1648 +     * largest value <i>k</i> such that:
150.1649 +     * <blockquote><pre>
150.1650 +     * this.codePointAt(<i>k</i>) == ch
150.1651 +     * </pre></blockquote>
150.1652 +     * is true.  In either case, if no such character occurs in this
150.1653 +     * string, then <code>-1</code> is returned.  The
150.1654 +     * <code>String</code> is searched backwards starting at the last
150.1655 +     * character.
150.1656 +     *
150.1657 +     * @param   ch   a character (Unicode code point).
150.1658 +     * @return  the index of the last occurrence of the character in the
150.1659 +     *          character sequence represented by this object, or
150.1660 +     *          <code>-1</code> if the character does not occur.
150.1661 +     */
150.1662 +    public int lastIndexOf(int ch) {
150.1663 +        return lastIndexOf(ch, length() - 1);
150.1664 +    }
150.1665 +
150.1666 +    /**
150.1667 +     * Returns the index within this string of the last occurrence of
150.1668 +     * the specified character, searching backward starting at the
150.1669 +     * specified index. For values of <code>ch</code> in the range
150.1670 +     * from 0 to 0xFFFF (inclusive), the index returned is the largest
150.1671 +     * value <i>k</i> such that:
150.1672 +     * <blockquote><pre>
150.1673 +     * (this.charAt(<i>k</i>) == ch) && (<i>k</i> &lt;= fromIndex)
150.1674 +     * </pre></blockquote>
150.1675 +     * is true. For other values of <code>ch</code>, it is the
150.1676 +     * largest value <i>k</i> such that:
150.1677 +     * <blockquote><pre>
150.1678 +     * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> &lt;= fromIndex)
150.1679 +     * </pre></blockquote>
150.1680 +     * is true. In either case, if no such character occurs in this
150.1681 +     * string at or before position <code>fromIndex</code>, then
150.1682 +     * <code>-1</code> is returned.
150.1683 +     *
150.1684 +     * <p>All indices are specified in <code>char</code> values
150.1685 +     * (Unicode code units).
150.1686 +     *
150.1687 +     * @param   ch          a character (Unicode code point).
150.1688 +     * @param   fromIndex   the index to start the search from. There is no
150.1689 +     *          restriction on the value of <code>fromIndex</code>. If it is
150.1690 +     *          greater than or equal to the length of this string, it has
150.1691 +     *          the same effect as if it were equal to one less than the
150.1692 +     *          length of this string: this entire string may be searched.
150.1693 +     *          If it is negative, it has the same effect as if it were -1:
150.1694 +     *          -1 is returned.
150.1695 +     * @return  the index of the last occurrence of the character in the
150.1696 +     *          character sequence represented by this object that is less
150.1697 +     *          than or equal to <code>fromIndex</code>, or <code>-1</code>
150.1698 +     *          if the character does not occur before that point.
150.1699 +     */
150.1700 +    @JavaScriptBody(args = { "ch", "from" }, body = 
150.1701 +        "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
150.1702 +        "return this.toString().lastIndexOf(ch, from);"
150.1703 +    )
150.1704 +    public int lastIndexOf(int ch, int fromIndex) {
150.1705 +        if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
150.1706 +            // handle most cases here (ch is a BMP code point or a
150.1707 +            // negative value (invalid code point))
150.1708 +            final char[] value = this.toCharArray();
150.1709 +            final int offset = this.offset();
150.1710 +            int i = offset + Math.min(fromIndex, length() - 1);
150.1711 +            for (; i >= offset ; i--) {
150.1712 +                if (value[i] == ch) {
150.1713 +                    return i - offset;
150.1714 +                }
150.1715 +            }
150.1716 +            return -1;
150.1717 +        } else {
150.1718 +            return lastIndexOfSupplementary(ch, fromIndex);
150.1719 +        }
150.1720 +    }
150.1721 +
150.1722 +    /**
150.1723 +     * Handles (rare) calls of lastIndexOf with a supplementary character.
150.1724 +     */
150.1725 +    private int lastIndexOfSupplementary(int ch, int fromIndex) {
150.1726 +        if (Character.isValidCodePoint(ch)) {
150.1727 +            final char[] value = this.toCharArray();
150.1728 +            final int offset = this.offset();
150.1729 +            char hi = Character.highSurrogate(ch);
150.1730 +            char lo = Character.lowSurrogate(ch);
150.1731 +            int i = offset + Math.min(fromIndex, length() - 2);
150.1732 +            for (; i >= offset; i--) {
150.1733 +                if (value[i] == hi && value[i+1] == lo) {
150.1734 +                    return i - offset;
150.1735 +                }
150.1736 +            }
150.1737 +        }
150.1738 +        return -1;
150.1739 +    }
150.1740 +
150.1741 +    /**
150.1742 +     * Returns the index within this string of the first occurrence of the
150.1743 +     * specified substring.
150.1744 +     *
150.1745 +     * <p>The returned index is the smallest value <i>k</i> for which:
150.1746 +     * <blockquote><pre>
150.1747 +     * this.startsWith(str, <i>k</i>)
150.1748 +     * </pre></blockquote>
150.1749 +     * If no such value of <i>k</i> exists, then {@code -1} is returned.
150.1750 +     *
150.1751 +     * @param   str   the substring to search for.
150.1752 +     * @return  the index of the first occurrence of the specified substring,
150.1753 +     *          or {@code -1} if there is no such occurrence.
150.1754 +     */
150.1755 +    public int indexOf(String str) {
150.1756 +        return indexOf(str, 0);
150.1757 +    }
150.1758 +
150.1759 +    /**
150.1760 +     * Returns the index within this string of the first occurrence of the
150.1761 +     * specified substring, starting at the specified index.
150.1762 +     *
150.1763 +     * <p>The returned index is the smallest value <i>k</i> for which:
150.1764 +     * <blockquote><pre>
150.1765 +     * <i>k</i> &gt;= fromIndex && this.startsWith(str, <i>k</i>)
150.1766 +     * </pre></blockquote>
150.1767 +     * If no such value of <i>k</i> exists, then {@code -1} is returned.
150.1768 +     *
150.1769 +     * @param   str         the substring to search for.
150.1770 +     * @param   fromIndex   the index from which to start the search.
150.1771 +     * @return  the index of the first occurrence of the specified substring,
150.1772 +     *          starting at the specified index,
150.1773 +     *          or {@code -1} if there is no such occurrence.
150.1774 +     */
150.1775 +    @JavaScriptBody(args = { "str", "fromIndex" }, body =
150.1776 +        "return this.toString().indexOf(str.toString(), fromIndex);"
150.1777 +    )
150.1778 +    public native int indexOf(String str, int fromIndex);
150.1779 +
150.1780 +    /**
150.1781 +     * Returns the index within this string of the last occurrence of the
150.1782 +     * specified substring.  The last occurrence of the empty string ""
150.1783 +     * is considered to occur at the index value {@code this.length()}.
150.1784 +     *
150.1785 +     * <p>The returned index is the largest value <i>k</i> for which:
150.1786 +     * <blockquote><pre>
150.1787 +     * this.startsWith(str, <i>k</i>)
150.1788 +     * </pre></blockquote>
150.1789 +     * If no such value of <i>k</i> exists, then {@code -1} is returned.
150.1790 +     *
150.1791 +     * @param   str   the substring to search for.
150.1792 +     * @return  the index of the last occurrence of the specified substring,
150.1793 +     *          or {@code -1} if there is no such occurrence.
150.1794 +     */
150.1795 +    public int lastIndexOf(String str) {
150.1796 +        return lastIndexOf(str, length());
150.1797 +    }
150.1798 +
150.1799 +    /**
150.1800 +     * Returns the index within this string of the last occurrence of the
150.1801 +     * specified substring, searching backward starting at the specified index.
150.1802 +     *
150.1803 +     * <p>The returned index is the largest value <i>k</i> for which:
150.1804 +     * <blockquote><pre>
150.1805 +     * <i>k</i> &lt;= fromIndex && this.startsWith(str, <i>k</i>)
150.1806 +     * </pre></blockquote>
150.1807 +     * If no such value of <i>k</i> exists, then {@code -1} is returned.
150.1808 +     *
150.1809 +     * @param   str         the substring to search for.
150.1810 +     * @param   fromIndex   the index to start the search from.
150.1811 +     * @return  the index of the last occurrence of the specified substring,
150.1812 +     *          searching backward from the specified index,
150.1813 +     *          or {@code -1} if there is no such occurrence.
150.1814 +     */
150.1815 +    @JavaScriptBody(args = { "s", "from" }, body = 
150.1816 +        "return this.toString().lastIndexOf(s.toString(), from);"
150.1817 +    )
150.1818 +    public int lastIndexOf(String str, int fromIndex) {
150.1819 +        return lastIndexOf(toCharArray(), offset(), length(), str.toCharArray(), str.offset(), str.length(), fromIndex);
150.1820 +    }
150.1821 +
150.1822 +    /**
150.1823 +     * Code shared by String and StringBuffer to do searches. The
150.1824 +     * source is the character array being searched, and the target
150.1825 +     * is the string being searched for.
150.1826 +     *
150.1827 +     * @param   source       the characters being searched.
150.1828 +     * @param   sourceOffset offset of the source string.
150.1829 +     * @param   sourceCount  count of the source string.
150.1830 +     * @param   target       the characters being searched for.
150.1831 +     * @param   targetOffset offset of the target string.
150.1832 +     * @param   targetCount  count of the target string.
150.1833 +     * @param   fromIndex    the index to begin searching from.
150.1834 +     */
150.1835 +    static int lastIndexOf(char[] source, int sourceOffset, int sourceCount,
150.1836 +                           char[] target, int targetOffset, int targetCount,
150.1837 +                           int fromIndex) {
150.1838 +        /*
150.1839 +         * Check arguments; return immediately where possible. For
150.1840 +         * consistency, don't check for null str.
150.1841 +         */
150.1842 +        int rightIndex = sourceCount - targetCount;
150.1843 +        if (fromIndex < 0) {
150.1844 +            return -1;
150.1845 +        }
150.1846 +        if (fromIndex > rightIndex) {
150.1847 +            fromIndex = rightIndex;
150.1848 +        }
150.1849 +        /* Empty string always matches. */
150.1850 +        if (targetCount == 0) {
150.1851 +            return fromIndex;
150.1852 +        }
150.1853 +
150.1854 +        int strLastIndex = targetOffset + targetCount - 1;
150.1855 +        char strLastChar = target[strLastIndex];
150.1856 +        int min = sourceOffset + targetCount - 1;
150.1857 +        int i = min + fromIndex;
150.1858 +
150.1859 +    startSearchForLastChar:
150.1860 +        while (true) {
150.1861 +            while (i >= min && source[i] != strLastChar) {
150.1862 +                i--;
150.1863 +            }
150.1864 +            if (i < min) {
150.1865 +                return -1;
150.1866 +            }
150.1867 +            int j = i - 1;
150.1868 +            int start = j - (targetCount - 1);
150.1869 +            int k = strLastIndex - 1;
150.1870 +
150.1871 +            while (j > start) {
150.1872 +                if (source[j--] != target[k--]) {
150.1873 +                    i--;
150.1874 +                    continue startSearchForLastChar;
150.1875 +                }
150.1876 +            }
150.1877 +            return start - sourceOffset + 1;
150.1878 +        }
150.1879 +    }
150.1880 +
150.1881 +    /**
150.1882 +     * Returns a new string that is a substring of this string. The
150.1883 +     * substring begins with the character at the specified index and
150.1884 +     * extends to the end of this string. <p>
150.1885 +     * Examples:
150.1886 +     * <blockquote><pre>
150.1887 +     * "unhappy".substring(2) returns "happy"
150.1888 +     * "Harbison".substring(3) returns "bison"
150.1889 +     * "emptiness".substring(9) returns "" (an empty string)
150.1890 +     * </pre></blockquote>
150.1891 +     *
150.1892 +     * @param      beginIndex   the beginning index, inclusive.
150.1893 +     * @return     the specified substring.
150.1894 +     * @exception  IndexOutOfBoundsException  if
150.1895 +     *             <code>beginIndex</code> is negative or larger than the
150.1896 +     *             length of this <code>String</code> object.
150.1897 +     */
150.1898 +    public String substring(int beginIndex) {
150.1899 +        return substring(beginIndex, length());
150.1900 +    }
150.1901 +
150.1902 +    /**
150.1903 +     * Returns a new string that is a substring of this string. The
150.1904 +     * substring begins at the specified <code>beginIndex</code> and
150.1905 +     * extends to the character at index <code>endIndex - 1</code>.
150.1906 +     * Thus the length of the substring is <code>endIndex-beginIndex</code>.
150.1907 +     * <p>
150.1908 +     * Examples:
150.1909 +     * <blockquote><pre>
150.1910 +     * "hamburger".substring(4, 8) returns "urge"
150.1911 +     * "smiles".substring(1, 5) returns "mile"
150.1912 +     * </pre></blockquote>
150.1913 +     *
150.1914 +     * @param      beginIndex   the beginning index, inclusive.
150.1915 +     * @param      endIndex     the ending index, exclusive.
150.1916 +     * @return     the specified substring.
150.1917 +     * @exception  IndexOutOfBoundsException  if the
150.1918 +     *             <code>beginIndex</code> is negative, or
150.1919 +     *             <code>endIndex</code> is larger than the length of
150.1920 +     *             this <code>String</code> object, or
150.1921 +     *             <code>beginIndex</code> is larger than
150.1922 +     *             <code>endIndex</code>.
150.1923 +     */
150.1924 +    @JavaScriptBody(args = { "beginIndex", "endIndex" }, body = 
150.1925 +        "return this.toString().substring(beginIndex, endIndex);"
150.1926 +    )
150.1927 +    public String substring(int beginIndex, int endIndex) {
150.1928 +        if (beginIndex < 0) {
150.1929 +            throw new StringIndexOutOfBoundsException(beginIndex);
150.1930 +        }
150.1931 +        if (endIndex > length()) {
150.1932 +            throw new StringIndexOutOfBoundsException(endIndex);
150.1933 +        }
150.1934 +        if (beginIndex > endIndex) {
150.1935 +            throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
150.1936 +        }
150.1937 +        return ((beginIndex == 0) && (endIndex == length())) ? this :
150.1938 +            new String(toCharArray(), offset() + beginIndex, endIndex - beginIndex);
150.1939 +    }
150.1940 +
150.1941 +    /**
150.1942 +     * Returns a new character sequence that is a subsequence of this sequence.
150.1943 +     *
150.1944 +     * <p> An invocation of this method of the form
150.1945 +     *
150.1946 +     * <blockquote><pre>
150.1947 +     * str.subSequence(begin,&nbsp;end)</pre></blockquote>
150.1948 +     *
150.1949 +     * behaves in exactly the same way as the invocation
150.1950 +     *
150.1951 +     * <blockquote><pre>
150.1952 +     * str.substring(begin,&nbsp;end)</pre></blockquote>
150.1953 +     *
150.1954 +     * This method is defined so that the <tt>String</tt> class can implement
150.1955 +     * the {@link CharSequence} interface. </p>
150.1956 +     *
150.1957 +     * @param      beginIndex   the begin index, inclusive.
150.1958 +     * @param      endIndex     the end index, exclusive.
150.1959 +     * @return     the specified subsequence.
150.1960 +     *
150.1961 +     * @throws  IndexOutOfBoundsException
150.1962 +     *          if <tt>beginIndex</tt> or <tt>endIndex</tt> are negative,
150.1963 +     *          if <tt>endIndex</tt> is greater than <tt>length()</tt>,
150.1964 +     *          or if <tt>beginIndex</tt> is greater than <tt>startIndex</tt>
150.1965 +     *
150.1966 +     * @since 1.4
150.1967 +     * @spec JSR-51
150.1968 +     */
150.1969 +    public CharSequence subSequence(int beginIndex, int endIndex) {
150.1970 +        return this.substring(beginIndex, endIndex);
150.1971 +    }
150.1972 +
150.1973 +    /**
150.1974 +     * Concatenates the specified string to the end of this string.
150.1975 +     * <p>
150.1976 +     * If the length of the argument string is <code>0</code>, then this
150.1977 +     * <code>String</code> object is returned. Otherwise, a new
150.1978 +     * <code>String</code> object is created, representing a character
150.1979 +     * sequence that is the concatenation of the character sequence
150.1980 +     * represented by this <code>String</code> object and the character
150.1981 +     * sequence represented by the argument string.<p>
150.1982 +     * Examples:
150.1983 +     * <blockquote><pre>
150.1984 +     * "cares".concat("s") returns "caress"
150.1985 +     * "to".concat("get").concat("her") returns "together"
150.1986 +     * </pre></blockquote>
150.1987 +     *
150.1988 +     * @param   str   the <code>String</code> that is concatenated to the end
150.1989 +     *                of this <code>String</code>.
150.1990 +     * @return  a string that represents the concatenation of this object's
150.1991 +     *          characters followed by the string argument's characters.
150.1992 +     */
150.1993 +    public String concat(String str) {
150.1994 +        int otherLen = str.length();
150.1995 +        if (otherLen == 0) {
150.1996 +            return this;
150.1997 +        }
150.1998 +        char buf[] = new char[length() + otherLen];
150.1999 +        getChars(0, length(), buf, 0);
150.2000 +        str.getChars(0, otherLen, buf, length());
150.2001 +        return new String(buf, 0, length() + otherLen);
150.2002 +    }
150.2003 +
150.2004 +    /**
150.2005 +     * Returns a new string resulting from replacing all occurrences of
150.2006 +     * <code>oldChar</code> in this string with <code>newChar</code>.
150.2007 +     * <p>
150.2008 +     * If the character <code>oldChar</code> does not occur in the
150.2009 +     * character sequence represented by this <code>String</code> object,
150.2010 +     * then a reference to this <code>String</code> object is returned.
150.2011 +     * Otherwise, a new <code>String</code> object is created that
150.2012 +     * represents a character sequence identical to the character sequence
150.2013 +     * represented by this <code>String</code> object, except that every
150.2014 +     * occurrence of <code>oldChar</code> is replaced by an occurrence
150.2015 +     * of <code>newChar</code>.
150.2016 +     * <p>
150.2017 +     * Examples:
150.2018 +     * <blockquote><pre>
150.2019 +     * "mesquite in your cellar".replace('e', 'o')
150.2020 +     *         returns "mosquito in your collar"
150.2021 +     * "the war of baronets".replace('r', 'y')
150.2022 +     *         returns "the way of bayonets"
150.2023 +     * "sparring with a purple porpoise".replace('p', 't')
150.2024 +     *         returns "starring with a turtle tortoise"
150.2025 +     * "JonL".replace('q', 'x') returns "JonL" (no change)
150.2026 +     * </pre></blockquote>
150.2027 +     *
150.2028 +     * @param   oldChar   the old character.
150.2029 +     * @param   newChar   the new character.
150.2030 +     * @return  a string derived from this string by replacing every
150.2031 +     *          occurrence of <code>oldChar</code> with <code>newChar</code>.
150.2032 +     */
150.2033 +    @JavaScriptBody(args = { "arg1", "arg2" }, body =
150.2034 +        "if (typeof arg1 === 'number') arg1 = String.fromCharCode(arg1);\n" +
150.2035 +        "if (typeof arg2 === 'number') arg2 = String.fromCharCode(arg2);\n" +
150.2036 +        "var s = this.toString();\n" +
150.2037 +        "for (;;) {\n" +
150.2038 +        "  var ret = s.replace(arg1, arg2);\n" +
150.2039 +        "  if (ret === s) {\n" +
150.2040 +        "    return ret;\n" +
150.2041 +        "  }\n" +
150.2042 +        "  s = ret;\n" +
150.2043 +        "}"
150.2044 +    )
150.2045 +    public String replace(char oldChar, char newChar) {
150.2046 +        if (oldChar != newChar) {
150.2047 +            int len = length();
150.2048 +            int i = -1;
150.2049 +            char[] val = toCharArray(); /* avoid getfield opcode */
150.2050 +            int off = offset();   /* avoid getfield opcode */
150.2051 +
150.2052 +            while (++i < len) {
150.2053 +                if (val[off + i] == oldChar) {
150.2054 +                    break;
150.2055 +                }
150.2056 +            }
150.2057 +            if (i < len) {
150.2058 +                char buf[] = new char[len];
150.2059 +                for (int j = 0 ; j < i ; j++) {
150.2060 +                    buf[j] = val[off+j];
150.2061 +                }
150.2062 +                while (i < len) {
150.2063 +                    char c = val[off + i];
150.2064 +                    buf[i] = (c == oldChar) ? newChar : c;
150.2065 +                    i++;
150.2066 +                }
150.2067 +                return new String(buf, 0, len);
150.2068 +            }
150.2069 +        }
150.2070 +        return this;
150.2071 +    }
150.2072 +
150.2073 +    /**
150.2074 +     * Tells whether or not this string matches the given <a
150.2075 +     * href="../util/regex/Pattern.html#sum">regular expression</a>.
150.2076 +     *
150.2077 +     * <p> An invocation of this method of the form
150.2078 +     * <i>str</i><tt>.matches(</tt><i>regex</i><tt>)</tt> yields exactly the
150.2079 +     * same result as the expression
150.2080 +     *
150.2081 +     * <blockquote><tt> {@link java.util.regex.Pattern}.{@link
150.2082 +     * java.util.regex.Pattern#matches(String,CharSequence)
150.2083 +     * matches}(</tt><i>regex</i><tt>,</tt> <i>str</i><tt>)</tt></blockquote>
150.2084 +     *
150.2085 +     * @param   regex
150.2086 +     *          the regular expression to which this string is to be matched
150.2087 +     *
150.2088 +     * @return  <tt>true</tt> if, and only if, this string matches the
150.2089 +     *          given regular expression
150.2090 +     *
150.2091 +     * @throws  PatternSyntaxException
150.2092 +     *          if the regular expression's syntax is invalid
150.2093 +     *
150.2094 +     * @see java.util.regex.Pattern
150.2095 +     *
150.2096 +     * @since 1.4
150.2097 +     * @spec JSR-51
150.2098 +     */
150.2099 +    @JavaScriptBody(args = { "regex" }, body = 
150.2100 +          "var self = this.toString();\n"
150.2101 +        + "var re = new RegExp(regex.toString());\n"
150.2102 +        + "var r = re.exec(self);\n"
150.2103 +        + "return r != null && r.length > 0 && self.length == r[0].length;"
150.2104 +    )
150.2105 +    public boolean matches(String regex) {
150.2106 +        throw new UnsupportedOperationException();
150.2107 +    }
150.2108 +
150.2109 +    /**
150.2110 +     * Returns true if and only if this string contains the specified
150.2111 +     * sequence of char values.
150.2112 +     *
150.2113 +     * @param s the sequence to search for
150.2114 +     * @return true if this string contains <code>s</code>, false otherwise
150.2115 +     * @throws NullPointerException if <code>s</code> is <code>null</code>
150.2116 +     * @since 1.5
150.2117 +     */
150.2118 +    public boolean contains(CharSequence s) {
150.2119 +        return indexOf(s.toString()) > -1;
150.2120 +    }
150.2121 +
150.2122 +    /**
150.2123 +     * Replaces the first substring of this string that matches the given <a
150.2124 +     * href="../util/regex/Pattern.html#sum">regular expression</a> with the
150.2125 +     * given replacement.
150.2126 +     *
150.2127 +     * <p> An invocation of this method of the form
150.2128 +     * <i>str</i><tt>.replaceFirst(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
150.2129 +     * yields exactly the same result as the expression
150.2130 +     *
150.2131 +     * <blockquote><tt>
150.2132 +     * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
150.2133 +     * compile}(</tt><i>regex</i><tt>).{@link
150.2134 +     * java.util.regex.Pattern#matcher(java.lang.CharSequence)
150.2135 +     * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceFirst
150.2136 +     * replaceFirst}(</tt><i>repl</i><tt>)</tt></blockquote>
150.2137 +     *
150.2138 +     *<p>
150.2139 +     * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
150.2140 +     * replacement string may cause the results to be different than if it were
150.2141 +     * being treated as a literal replacement string; see
150.2142 +     * {@link java.util.regex.Matcher#replaceFirst}.
150.2143 +     * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
150.2144 +     * meaning of these characters, if desired.
150.2145 +     *
150.2146 +     * @param   regex
150.2147 +     *          the regular expression to which this string is to be matched
150.2148 +     * @param   replacement
150.2149 +     *          the string to be substituted for the first match
150.2150 +     *
150.2151 +     * @return  The resulting <tt>String</tt>
150.2152 +     *
150.2153 +     * @throws  PatternSyntaxException
150.2154 +     *          if the regular expression's syntax is invalid
150.2155 +     *
150.2156 +     * @see java.util.regex.Pattern
150.2157 +     *
150.2158 +     * @since 1.4
150.2159 +     * @spec JSR-51
150.2160 +     */
150.2161 +    public String replaceFirst(String regex, String replacement) {
150.2162 +        throw new UnsupportedOperationException();
150.2163 +    }
150.2164 +
150.2165 +    /**
150.2166 +     * Replaces each substring of this string that matches the given <a
150.2167 +     * href="../util/regex/Pattern.html#sum">regular expression</a> with the
150.2168 +     * given replacement.
150.2169 +     *
150.2170 +     * <p> An invocation of this method of the form
150.2171 +     * <i>str</i><tt>.replaceAll(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
150.2172 +     * yields exactly the same result as the expression
150.2173 +     *
150.2174 +     * <blockquote><tt>
150.2175 +     * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
150.2176 +     * compile}(</tt><i>regex</i><tt>).{@link
150.2177 +     * java.util.regex.Pattern#matcher(java.lang.CharSequence)
150.2178 +     * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceAll
150.2179 +     * replaceAll}(</tt><i>repl</i><tt>)</tt></blockquote>
150.2180 +     *
150.2181 +     *<p>
150.2182 +     * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
150.2183 +     * replacement string may cause the results to be different than if it were
150.2184 +     * being treated as a literal replacement string; see
150.2185 +     * {@link java.util.regex.Matcher#replaceAll Matcher.replaceAll}.
150.2186 +     * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
150.2187 +     * meaning of these characters, if desired.
150.2188 +     *
150.2189 +     * @param   regex
150.2190 +     *          the regular expression to which this string is to be matched
150.2191 +     * @param   replacement
150.2192 +     *          the string to be substituted for each match
150.2193 +     *
150.2194 +     * @return  The resulting <tt>String</tt>
150.2195 +     *
150.2196 +     * @throws  PatternSyntaxException
150.2197 +     *          if the regular expression's syntax is invalid
150.2198 +     *
150.2199 +     * @see java.util.regex.Pattern
150.2200 +     *
150.2201 +     * @since 1.4
150.2202 +     * @spec JSR-51
150.2203 +     */
150.2204 +    public String replaceAll(String regex, String replacement) {
150.2205 +        throw new UnsupportedOperationException();
150.2206 +    }
150.2207 +
150.2208 +    /**
150.2209 +     * Replaces each substring of this string that matches the literal target
150.2210 +     * sequence with the specified literal replacement sequence. The
150.2211 +     * replacement proceeds from the beginning of the string to the end, for
150.2212 +     * example, replacing "aa" with "b" in the string "aaa" will result in
150.2213 +     * "ba" rather than "ab".
150.2214 +     *
150.2215 +     * @param  target The sequence of char values to be replaced
150.2216 +     * @param  replacement The replacement sequence of char values
150.2217 +     * @return  The resulting string
150.2218 +     * @throws NullPointerException if <code>target</code> or
150.2219 +     *         <code>replacement</code> is <code>null</code>.
150.2220 +     * @since 1.5
150.2221 +     */
150.2222 +    public String replace(CharSequence target, CharSequence replacement) {
150.2223 +        throw new UnsupportedOperationException("This one should be supported, but without dep on rest of regexp");
150.2224 +    }
150.2225 +
150.2226 +    /**
150.2227 +     * Splits this string around matches of the given
150.2228 +     * <a href="../util/regex/Pattern.html#sum">regular expression</a>.
150.2229 +     *
150.2230 +     * <p> The array returned by this method contains each substring of this
150.2231 +     * string that is terminated by another substring that matches the given
150.2232 +     * expression or is terminated by the end of the string.  The substrings in
150.2233 +     * the array are in the order in which they occur in this string.  If the
150.2234 +     * expression does not match any part of the input then the resulting array
150.2235 +     * has just one element, namely this string.
150.2236 +     *
150.2237 +     * <p> The <tt>limit</tt> parameter controls the number of times the
150.2238 +     * pattern is applied and therefore affects the length of the resulting
150.2239 +     * array.  If the limit <i>n</i> is greater than zero then the pattern
150.2240 +     * will be applied at most <i>n</i>&nbsp;-&nbsp;1 times, the array's
150.2241 +     * length will be no greater than <i>n</i>, and the array's last entry
150.2242 +     * will contain all input beyond the last matched delimiter.  If <i>n</i>
150.2243 +     * is non-positive then the pattern will be applied as many times as
150.2244 +     * possible and the array can have any length.  If <i>n</i> is zero then
150.2245 +     * the pattern will be applied as many times as possible, the array can
150.2246 +     * have any length, and trailing empty strings will be discarded.
150.2247 +     *
150.2248 +     * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the
150.2249 +     * following results with these parameters:
150.2250 +     *
150.2251 +     * <blockquote><table cellpadding=1 cellspacing=0 summary="Split example showing regex, limit, and result">
150.2252 +     * <tr>
150.2253 +     *     <th>Regex</th>
150.2254 +     *     <th>Limit</th>
150.2255 +     *     <th>Result</th>
150.2256 +     * </tr>
150.2257 +     * <tr><td align=center>:</td>
150.2258 +     *     <td align=center>2</td>
150.2259 +     *     <td><tt>{ "boo", "and:foo" }</tt></td></tr>
150.2260 +     * <tr><td align=center>:</td>
150.2261 +     *     <td align=center>5</td>
150.2262 +     *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
150.2263 +     * <tr><td align=center>:</td>
150.2264 +     *     <td align=center>-2</td>
150.2265 +     *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
150.2266 +     * <tr><td align=center>o</td>
150.2267 +     *     <td align=center>5</td>
150.2268 +     *     <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
150.2269 +     * <tr><td align=center>o</td>
150.2270 +     *     <td align=center>-2</td>
150.2271 +     *     <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
150.2272 +     * <tr><td align=center>o</td>
150.2273 +     *     <td align=center>0</td>
150.2274 +     *     <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
150.2275 +     * </table></blockquote>
150.2276 +     *
150.2277 +     * <p> An invocation of this method of the form
150.2278 +     * <i>str.</i><tt>split(</tt><i>regex</i><tt>,</tt>&nbsp;<i>n</i><tt>)</tt>
150.2279 +     * yields the same result as the expression
150.2280 +     *
150.2281 +     * <blockquote>
150.2282 +     * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
150.2283 +     * compile}<tt>(</tt><i>regex</i><tt>)</tt>.{@link
150.2284 +     * java.util.regex.Pattern#split(java.lang.CharSequence,int)
150.2285 +     * split}<tt>(</tt><i>str</i><tt>,</tt>&nbsp;<i>n</i><tt>)</tt>
150.2286 +     * </blockquote>
150.2287 +     *
150.2288 +     *
150.2289 +     * @param  regex
150.2290 +     *         the delimiting regular expression
150.2291 +     *
150.2292 +     * @param  limit
150.2293 +     *         the result threshold, as described above
150.2294 +     *
150.2295 +     * @return  the array of strings computed by splitting this string
150.2296 +     *          around matches of the given regular expression
150.2297 +     *
150.2298 +     * @throws  PatternSyntaxException
150.2299 +     *          if the regular expression's syntax is invalid
150.2300 +     *
150.2301 +     * @see java.util.regex.Pattern
150.2302 +     *
150.2303 +     * @since 1.4
150.2304 +     * @spec JSR-51
150.2305 +     */
150.2306 +    public String[] split(String regex, int limit) {
150.2307 +        throw new UnsupportedOperationException("Needs regexp");
150.2308 +    }
150.2309 +
150.2310 +    /**
150.2311 +     * Splits this string around matches of the given <a
150.2312 +     * href="../util/regex/Pattern.html#sum">regular expression</a>.
150.2313 +     *
150.2314 +     * <p> This method works as if by invoking the two-argument {@link
150.2315 +     * #split(String, int) split} method with the given expression and a limit
150.2316 +     * argument of zero.  Trailing empty strings are therefore not included in
150.2317 +     * the resulting array.
150.2318 +     *
150.2319 +     * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the following
150.2320 +     * results with these expressions:
150.2321 +     *
150.2322 +     * <blockquote><table cellpadding=1 cellspacing=0 summary="Split examples showing regex and result">
150.2323 +     * <tr>
150.2324 +     *  <th>Regex</th>
150.2325 +     *  <th>Result</th>
150.2326 +     * </tr>
150.2327 +     * <tr><td align=center>:</td>
150.2328 +     *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
150.2329 +     * <tr><td align=center>o</td>
150.2330 +     *     <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
150.2331 +     * </table></blockquote>
150.2332 +     *
150.2333 +     *
150.2334 +     * @param  regex
150.2335 +     *         the delimiting regular expression
150.2336 +     *
150.2337 +     * @return  the array of strings computed by splitting this string
150.2338 +     *          around matches of the given regular expression
150.2339 +     *
150.2340 +     * @throws  PatternSyntaxException
150.2341 +     *          if the regular expression's syntax is invalid
150.2342 +     *
150.2343 +     * @see java.util.regex.Pattern
150.2344 +     *
150.2345 +     * @since 1.4
150.2346 +     * @spec JSR-51
150.2347 +     */
150.2348 +    public String[] split(String regex) {
150.2349 +        return split(regex, 0);
150.2350 +    }
150.2351 +
150.2352 +    /**
150.2353 +     * Converts all of the characters in this <code>String</code> to lower
150.2354 +     * case using the rules of the given <code>Locale</code>.  Case mapping is based
150.2355 +     * on the Unicode Standard version specified by the {@link java.lang.Character Character}
150.2356 +     * class. Since case mappings are not always 1:1 char mappings, the resulting
150.2357 +     * <code>String</code> may be a different length than the original <code>String</code>.
150.2358 +     * <p>
150.2359 +     * Examples of lowercase  mappings are in the following table:
150.2360 +     * <table border="1" summary="Lowercase mapping examples showing language code of locale, upper case, lower case, and description">
150.2361 +     * <tr>
150.2362 +     *   <th>Language Code of Locale</th>
150.2363 +     *   <th>Upper Case</th>
150.2364 +     *   <th>Lower Case</th>
150.2365 +     *   <th>Description</th>
150.2366 +     * </tr>
150.2367 +     * <tr>
150.2368 +     *   <td>tr (Turkish)</td>
150.2369 +     *   <td>&#92;u0130</td>
150.2370 +     *   <td>&#92;u0069</td>
150.2371 +     *   <td>capital letter I with dot above -&gt; small letter i</td>
150.2372 +     * </tr>
150.2373 +     * <tr>
150.2374 +     *   <td>tr (Turkish)</td>
150.2375 +     *   <td>&#92;u0049</td>
150.2376 +     *   <td>&#92;u0131</td>
150.2377 +     *   <td>capital letter I -&gt; small letter dotless i </td>
150.2378 +     * </tr>
150.2379 +     * <tr>
150.2380 +     *   <td>(all)</td>
150.2381 +     *   <td>French Fries</td>
150.2382 +     *   <td>french fries</td>
150.2383 +     *   <td>lowercased all chars in String</td>
150.2384 +     * </tr>
150.2385 +     * <tr>
150.2386 +     *   <td>(all)</td>
150.2387 +     *   <td><img src="doc-files/capiota.gif" alt="capiota"><img src="doc-files/capchi.gif" alt="capchi">
150.2388 +     *       <img src="doc-files/captheta.gif" alt="captheta"><img src="doc-files/capupsil.gif" alt="capupsil">
150.2389 +     *       <img src="doc-files/capsigma.gif" alt="capsigma"></td>
150.2390 +     *   <td><img src="doc-files/iota.gif" alt="iota"><img src="doc-files/chi.gif" alt="chi">
150.2391 +     *       <img src="doc-files/theta.gif" alt="theta"><img src="doc-files/upsilon.gif" alt="upsilon">
150.2392 +     *       <img src="doc-files/sigma1.gif" alt="sigma"></td>
150.2393 +     *   <td>lowercased all chars in String</td>
150.2394 +     * </tr>
150.2395 +     * </table>
150.2396 +     *
150.2397 +     * @param locale use the case transformation rules for this locale
150.2398 +     * @return the <code>String</code>, converted to lowercase.
150.2399 +     * @see     java.lang.String#toLowerCase()
150.2400 +     * @see     java.lang.String#toUpperCase()
150.2401 +     * @see     java.lang.String#toUpperCase(Locale)
150.2402 +     * @since   1.1
150.2403 +     */
150.2404 +//    public String toLowerCase(Locale locale) {
150.2405 +//        if (locale == null) {
150.2406 +//            throw new NullPointerException();
150.2407 +//        }
150.2408 +//
150.2409 +//        int     firstUpper;
150.2410 +//
150.2411 +//        /* Now check if there are any characters that need to be changed. */
150.2412 +//        scan: {
150.2413 +//            for (firstUpper = 0 ; firstUpper < count; ) {
150.2414 +//                char c = value[offset+firstUpper];
150.2415 +//                if ((c >= Character.MIN_HIGH_SURROGATE) &&
150.2416 +//                    (c <= Character.MAX_HIGH_SURROGATE)) {
150.2417 +//                    int supplChar = codePointAt(firstUpper);
150.2418 +//                    if (supplChar != Character.toLowerCase(supplChar)) {
150.2419 +//                        break scan;
150.2420 +//                    }
150.2421 +//                    firstUpper += Character.charCount(supplChar);
150.2422 +//                } else {
150.2423 +//                    if (c != Character.toLowerCase(c)) {
150.2424 +//                        break scan;
150.2425 +//                    }
150.2426 +//                    firstUpper++;
150.2427 +//                }
150.2428 +//            }
150.2429 +//            return this;
150.2430 +//        }
150.2431 +//
150.2432 +//        char[]  result = new char[count];
150.2433 +//        int     resultOffset = 0;  /* result may grow, so i+resultOffset
150.2434 +//                                    * is the write location in result */
150.2435 +//
150.2436 +//        /* Just copy the first few lowerCase characters. */
150.2437 +//        System.arraycopy(value, offset, result, 0, firstUpper);
150.2438 +//
150.2439 +//        String lang = locale.getLanguage();
150.2440 +//        boolean localeDependent =
150.2441 +//            (lang == "tr" || lang == "az" || lang == "lt");
150.2442 +//        char[] lowerCharArray;
150.2443 +//        int lowerChar;
150.2444 +//        int srcChar;
150.2445 +//        int srcCount;
150.2446 +//        for (int i = firstUpper; i < count; i += srcCount) {
150.2447 +//            srcChar = (int)value[offset+i];
150.2448 +//            if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
150.2449 +//                (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
150.2450 +//                srcChar = codePointAt(i);
150.2451 +//                srcCount = Character.charCount(srcChar);
150.2452 +//            } else {
150.2453 +//                srcCount = 1;
150.2454 +//            }
150.2455 +//            if (localeDependent || srcChar == '\u03A3') { // GREEK CAPITAL LETTER SIGMA
150.2456 +//                lowerChar = ConditionalSpecialCasing.toLowerCaseEx(this, i, locale);
150.2457 +//            } else if (srcChar == '\u0130') { // LATIN CAPITAL LETTER I DOT
150.2458 +//                lowerChar = Character.ERROR;
150.2459 +//            } else {
150.2460 +//                lowerChar = Character.toLowerCase(srcChar);
150.2461 +//            }
150.2462 +//            if ((lowerChar == Character.ERROR) ||
150.2463 +//                (lowerChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
150.2464 +//                if (lowerChar == Character.ERROR) {
150.2465 +//                     if (!localeDependent && srcChar == '\u0130') {
150.2466 +//                         lowerCharArray =
150.2467 +//                             ConditionalSpecialCasing.toLowerCaseCharArray(this, i, Locale.ENGLISH);
150.2468 +//                     } else {
150.2469 +//                        lowerCharArray =
150.2470 +//                            ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale);
150.2471 +//                     }
150.2472 +//                } else if (srcCount == 2) {
150.2473 +//                    resultOffset += Character.toChars(lowerChar, result, i + resultOffset) - srcCount;
150.2474 +//                    continue;
150.2475 +//                } else {
150.2476 +//                    lowerCharArray = Character.toChars(lowerChar);
150.2477 +//                }
150.2478 +//
150.2479 +//                /* Grow result if needed */
150.2480 +//                int mapLen = lowerCharArray.length;
150.2481 +//                if (mapLen > srcCount) {
150.2482 +//                    char[] result2 = new char[result.length + mapLen - srcCount];
150.2483 +//                    System.arraycopy(result, 0, result2, 0,
150.2484 +//                        i + resultOffset);
150.2485 +//                    result = result2;
150.2486 +//                }
150.2487 +//                for (int x=0; x<mapLen; ++x) {
150.2488 +//                    result[i+resultOffset+x] = lowerCharArray[x];
150.2489 +//                }
150.2490 +//                resultOffset += (mapLen - srcCount);
150.2491 +//            } else {
150.2492 +//                result[i+resultOffset] = (char)lowerChar;
150.2493 +//            }
150.2494 +//        }
150.2495 +//        return new String(0, count+resultOffset, result);
150.2496 +//    }
150.2497 +
150.2498 +    /**
150.2499 +     * Converts all of the characters in this <code>String</code> to lower
150.2500 +     * case using the rules of the default locale. This is equivalent to calling
150.2501 +     * <code>toLowerCase(Locale.getDefault())</code>.
150.2502 +     * <p>
150.2503 +     * <b>Note:</b> This method is locale sensitive, and may produce unexpected
150.2504 +     * results if used for strings that are intended to be interpreted locale
150.2505 +     * independently.
150.2506 +     * Examples are programming language identifiers, protocol keys, and HTML
150.2507 +     * tags.
150.2508 +     * For instance, <code>"TITLE".toLowerCase()</code> in a Turkish locale
150.2509 +     * returns <code>"t\u005Cu0131tle"</code>, where '\u005Cu0131' is the
150.2510 +     * LATIN SMALL LETTER DOTLESS I character.
150.2511 +     * To obtain correct results for locale insensitive strings, use
150.2512 +     * <code>toLowerCase(Locale.ENGLISH)</code>.
150.2513 +     * <p>
150.2514 +     * @return  the <code>String</code>, converted to lowercase.
150.2515 +     * @see     java.lang.String#toLowerCase(Locale)
150.2516 +     */
150.2517 +    @JavaScriptBody(args = {}, body = "return this.toLowerCase();")
150.2518 +    public String toLowerCase() {
150.2519 +        throw new UnsupportedOperationException("Should be supported but without connection to locale");
150.2520 +    }
150.2521 +
150.2522 +    /**
150.2523 +     * Converts all of the characters in this <code>String</code> to upper
150.2524 +     * case using the rules of the given <code>Locale</code>. Case mapping is based
150.2525 +     * on the Unicode Standard version specified by the {@link java.lang.Character Character}
150.2526 +     * class. Since case mappings are not always 1:1 char mappings, the resulting
150.2527 +     * <code>String</code> may be a different length than the original <code>String</code>.
150.2528 +     * <p>
150.2529 +     * Examples of locale-sensitive and 1:M case mappings are in the following table.
150.2530 +     * <p>
150.2531 +     * <table border="1" summary="Examples of locale-sensitive and 1:M case mappings. Shows Language code of locale, lower case, upper case, and description.">
150.2532 +     * <tr>
150.2533 +     *   <th>Language Code of Locale</th>
150.2534 +     *   <th>Lower Case</th>
150.2535 +     *   <th>Upper Case</th>
150.2536 +     *   <th>Description</th>
150.2537 +     * </tr>
150.2538 +     * <tr>
150.2539 +     *   <td>tr (Turkish)</td>
150.2540 +     *   <td>&#92;u0069</td>
150.2541 +     *   <td>&#92;u0130</td>
150.2542 +     *   <td>small letter i -&gt; capital letter I with dot above</td>
150.2543 +     * </tr>
150.2544 +     * <tr>
150.2545 +     *   <td>tr (Turkish)</td>
150.2546 +     *   <td>&#92;u0131</td>
150.2547 +     *   <td>&#92;u0049</td>
150.2548 +     *   <td>small letter dotless i -&gt; capital letter I</td>
150.2549 +     * </tr>
150.2550 +     * <tr>
150.2551 +     *   <td>(all)</td>
150.2552 +     *   <td>&#92;u00df</td>
150.2553 +     *   <td>&#92;u0053 &#92;u0053</td>
150.2554 +     *   <td>small letter sharp s -&gt; two letters: SS</td>
150.2555 +     * </tr>
150.2556 +     * <tr>
150.2557 +     *   <td>(all)</td>
150.2558 +     *   <td>Fahrvergn&uuml;gen</td>
150.2559 +     *   <td>FAHRVERGN&Uuml;GEN</td>
150.2560 +     *   <td></td>
150.2561 +     * </tr>
150.2562 +     * </table>
150.2563 +     * @param locale use the case transformation rules for this locale
150.2564 +     * @return the <code>String</code>, converted to uppercase.
150.2565 +     * @see     java.lang.String#toUpperCase()
150.2566 +     * @see     java.lang.String#toLowerCase()
150.2567 +     * @see     java.lang.String#toLowerCase(Locale)
150.2568 +     * @since   1.1
150.2569 +     */
150.2570 +    /* not for javascript 
150.2571 +    public String toUpperCase(Locale locale) {
150.2572 +        if (locale == null) {
150.2573 +            throw new NullPointerException();
150.2574 +        }
150.2575 +
150.2576 +        int     firstLower;
150.2577 +
150.2578 +        // Now check if there are any characters that need to be changed. 
150.2579 +        scan: {
150.2580 +            for (firstLower = 0 ; firstLower < count; ) {
150.2581 +                int c = (int)value[offset+firstLower];
150.2582 +                int srcCount;
150.2583 +                if ((c >= Character.MIN_HIGH_SURROGATE) &&
150.2584 +                    (c <= Character.MAX_HIGH_SURROGATE)) {
150.2585 +                    c = codePointAt(firstLower);
150.2586 +                    srcCount = Character.charCount(c);
150.2587 +                } else {
150.2588 +                    srcCount = 1;
150.2589 +                }
150.2590 +                int upperCaseChar = Character.toUpperCaseEx(c);
150.2591 +                if ((upperCaseChar == Character.ERROR) ||
150.2592 +                    (c != upperCaseChar)) {
150.2593 +                    break scan;
150.2594 +                }
150.2595 +                firstLower += srcCount;
150.2596 +            }
150.2597 +            return this;
150.2598 +        }
150.2599 +
150.2600 +        char[]  result       = new char[count]; /* may grow *
150.2601 +        int     resultOffset = 0;  /* result may grow, so i+resultOffset
150.2602 +                                    * is the write location in result *
150.2603 +
150.2604 +        /* Just copy the first few upperCase characters. *
150.2605 +        System.arraycopy(value, offset, result, 0, firstLower);
150.2606 +
150.2607 +        String lang = locale.getLanguage();
150.2608 +        boolean localeDependent =
150.2609 +            (lang == "tr" || lang == "az" || lang == "lt");
150.2610 +        char[] upperCharArray;
150.2611 +        int upperChar;
150.2612 +        int srcChar;
150.2613 +        int srcCount;
150.2614 +        for (int i = firstLower; i < count; i += srcCount) {
150.2615 +            srcChar = (int)value[offset+i];
150.2616 +            if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
150.2617 +                (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
150.2618 +                srcChar = codePointAt(i);
150.2619 +                srcCount = Character.charCount(srcChar);
150.2620 +            } else {
150.2621 +                srcCount = 1;
150.2622 +            }
150.2623 +            if (localeDependent) {
150.2624 +                upperChar = ConditionalSpecialCasing.toUpperCaseEx(this, i, locale);
150.2625 +            } else {
150.2626 +                upperChar = Character.toUpperCaseEx(srcChar);
150.2627 +            }
150.2628 +            if ((upperChar == Character.ERROR) ||
150.2629 +                (upperChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
150.2630 +                if (upperChar == Character.ERROR) {
150.2631 +                    if (localeDependent) {
150.2632 +                        upperCharArray =
150.2633 +                            ConditionalSpecialCasing.toUpperCaseCharArray(this, i, locale);
150.2634 +                    } else {
150.2635 +                        upperCharArray = Character.toUpperCaseCharArray(srcChar);
150.2636 +                    }
150.2637 +                } else if (srcCount == 2) {
150.2638 +                    resultOffset += Character.toChars(upperChar, result, i + resultOffset) - srcCount;
150.2639 +                    continue;
150.2640 +                } else {
150.2641 +                    upperCharArray = Character.toChars(upperChar);
150.2642 +                }
150.2643 +
150.2644 +                /* Grow result if needed *
150.2645 +                int mapLen = upperCharArray.length;
150.2646 +                if (mapLen > srcCount) {
150.2647 +                    char[] result2 = new char[result.length + mapLen - srcCount];
150.2648 +                    System.arraycopy(result, 0, result2, 0,
150.2649 +                        i + resultOffset);
150.2650 +                    result = result2;
150.2651 +                }
150.2652 +                for (int x=0; x<mapLen; ++x) {
150.2653 +                    result[i+resultOffset+x] = upperCharArray[x];
150.2654 +                }
150.2655 +                resultOffset += (mapLen - srcCount);
150.2656 +            } else {
150.2657 +                result[i+resultOffset] = (char)upperChar;
150.2658 +            }
150.2659 +        }
150.2660 +        return new String(0, count+resultOffset, result);
150.2661 +    }
150.2662 +    */
150.2663 +
150.2664 +    /**
150.2665 +     * Converts all of the characters in this <code>String</code> to upper
150.2666 +     * case using the rules of the default locale. This method is equivalent to
150.2667 +     * <code>toUpperCase(Locale.getDefault())</code>.
150.2668 +     * <p>
150.2669 +     * <b>Note:</b> This method is locale sensitive, and may produce unexpected
150.2670 +     * results if used for strings that are intended to be interpreted locale
150.2671 +     * independently.
150.2672 +     * Examples are programming language identifiers, protocol keys, and HTML
150.2673 +     * tags.
150.2674 +     * For instance, <code>"title".toUpperCase()</code> in a Turkish locale
150.2675 +     * returns <code>"T\u005Cu0130TLE"</code>, where '\u005Cu0130' is the
150.2676 +     * LATIN CAPITAL LETTER I WITH DOT ABOVE character.
150.2677 +     * To obtain correct results for locale insensitive strings, use
150.2678 +     * <code>toUpperCase(Locale.ENGLISH)</code>.
150.2679 +     * <p>
150.2680 +     * @return  the <code>String</code>, converted to uppercase.
150.2681 +     * @see     java.lang.String#toUpperCase(Locale)
150.2682 +     */
150.2683 +    @JavaScriptBody(args = {}, body = "return this.toUpperCase();")
150.2684 +    public String toUpperCase() {
150.2685 +        throw new UnsupportedOperationException();
150.2686 +    }
150.2687 +
150.2688 +    /**
150.2689 +     * Returns a copy of the string, with leading and trailing whitespace
150.2690 +     * omitted.
150.2691 +     * <p>
150.2692 +     * If this <code>String</code> object represents an empty character
150.2693 +     * sequence, or the first and last characters of character sequence
150.2694 +     * represented by this <code>String</code> object both have codes
150.2695 +     * greater than <code>'&#92;u0020'</code> (the space character), then a
150.2696 +     * reference to this <code>String</code> object is returned.
150.2697 +     * <p>
150.2698 +     * Otherwise, if there is no character with a code greater than
150.2699 +     * <code>'&#92;u0020'</code> in the string, then a new
150.2700 +     * <code>String</code> object representing an empty string is created
150.2701 +     * and returned.
150.2702 +     * <p>
150.2703 +     * Otherwise, let <i>k</i> be the index of the first character in the
150.2704 +     * string whose code is greater than <code>'&#92;u0020'</code>, and let
150.2705 +     * <i>m</i> be the index of the last character in the string whose code
150.2706 +     * is greater than <code>'&#92;u0020'</code>. A new <code>String</code>
150.2707 +     * object is created, representing the substring of this string that
150.2708 +     * begins with the character at index <i>k</i> and ends with the
150.2709 +     * character at index <i>m</i>-that is, the result of
150.2710 +     * <code>this.substring(<i>k</i>,&nbsp;<i>m</i>+1)</code>.
150.2711 +     * <p>
150.2712 +     * This method may be used to trim whitespace (as defined above) from
150.2713 +     * the beginning and end of a string.
150.2714 +     *
150.2715 +     * @return  A copy of this string with leading and trailing white
150.2716 +     *          space removed, or this string if it has no leading or
150.2717 +     *          trailing white space.
150.2718 +     */
150.2719 +    public String trim() {
150.2720 +        int len = length();
150.2721 +        int st = 0;
150.2722 +        int off = offset();      /* avoid getfield opcode */
150.2723 +        char[] val = toCharArray();    /* avoid getfield opcode */
150.2724 +
150.2725 +        while ((st < len) && (val[off + st] <= ' ')) {
150.2726 +            st++;
150.2727 +        }
150.2728 +        while ((st < len) && (val[off + len - 1] <= ' ')) {
150.2729 +            len--;
150.2730 +        }
150.2731 +        return ((st > 0) || (len < length())) ? substring(st, len) : this;
150.2732 +    }
150.2733 +
150.2734 +    /**
150.2735 +     * This object (which is already a string!) is itself returned.
150.2736 +     *
150.2737 +     * @return  the string itself.
150.2738 +     */
150.2739 +    @JavaScriptBody(args = {}, body = "return this.toString();")
150.2740 +    public String toString() {
150.2741 +        return this;
150.2742 +    }
150.2743 +
150.2744 +    /**
150.2745 +     * Converts this string to a new character array.
150.2746 +     *
150.2747 +     * @return  a newly allocated character array whose length is the length
150.2748 +     *          of this string and whose contents are initialized to contain
150.2749 +     *          the character sequence represented by this string.
150.2750 +     */
150.2751 +    public char[] toCharArray() {
150.2752 +        char result[] = new char[length()];
150.2753 +        getChars(0, length(), result, 0);
150.2754 +        return result;
150.2755 +    }
150.2756 +
150.2757 +    /**
150.2758 +     * Returns a formatted string using the specified format string and
150.2759 +     * arguments.
150.2760 +     *
150.2761 +     * <p> The locale always used is the one returned by {@link
150.2762 +     * java.util.Locale#getDefault() Locale.getDefault()}.
150.2763 +     *
150.2764 +     * @param  format
150.2765 +     *         A <a href="../util/Formatter.html#syntax">format string</a>
150.2766 +     *
150.2767 +     * @param  args
150.2768 +     *         Arguments referenced by the format specifiers in the format
150.2769 +     *         string.  If there are more arguments than format specifiers, the
150.2770 +     *         extra arguments are ignored.  The number of arguments is
150.2771 +     *         variable and may be zero.  The maximum number of arguments is
150.2772 +     *         limited by the maximum dimension of a Java array as defined by
150.2773 +     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
150.2774 +     *         The behaviour on a
150.2775 +     *         <tt>null</tt> argument depends on the <a
150.2776 +     *         href="../util/Formatter.html#syntax">conversion</a>.
150.2777 +     *
150.2778 +     * @throws  IllegalFormatException
150.2779 +     *          If a format string contains an illegal syntax, a format
150.2780 +     *          specifier that is incompatible with the given arguments,
150.2781 +     *          insufficient arguments given the format string, or other
150.2782 +     *          illegal conditions.  For specification of all possible
150.2783 +     *          formatting errors, see the <a
150.2784 +     *          href="../util/Formatter.html#detail">Details</a> section of the
150.2785 +     *          formatter class specification.
150.2786 +     *
150.2787 +     * @throws  NullPointerException
150.2788 +     *          If the <tt>format</tt> is <tt>null</tt>
150.2789 +     *
150.2790 +     * @return  A formatted string
150.2791 +     *
150.2792 +     * @see  java.util.Formatter
150.2793 +     * @since  1.5
150.2794 +     */
150.2795 +    public static String format(String format, Object ... args) {
150.2796 +        throw new UnsupportedOperationException();
150.2797 +    }
150.2798 +
150.2799 +    /**
150.2800 +     * Returns a formatted string using the specified locale, format string,
150.2801 +     * and arguments.
150.2802 +     *
150.2803 +     * @param  l
150.2804 +     *         The {@linkplain java.util.Locale locale} to apply during
150.2805 +     *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
150.2806 +     *         is applied.
150.2807 +     *
150.2808 +     * @param  format
150.2809 +     *         A <a href="../util/Formatter.html#syntax">format string</a>
150.2810 +     *
150.2811 +     * @param  args
150.2812 +     *         Arguments referenced by the format specifiers in the format
150.2813 +     *         string.  If there are more arguments than format specifiers, the
150.2814 +     *         extra arguments are ignored.  The number of arguments is
150.2815 +     *         variable and may be zero.  The maximum number of arguments is
150.2816 +     *         limited by the maximum dimension of a Java array as defined by
150.2817 +     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
150.2818 +     *         The behaviour on a
150.2819 +     *         <tt>null</tt> argument depends on the <a
150.2820 +     *         href="../util/Formatter.html#syntax">conversion</a>.
150.2821 +     *
150.2822 +     * @throws  IllegalFormatException
150.2823 +     *          If a format string contains an illegal syntax, a format
150.2824 +     *          specifier that is incompatible with the given arguments,
150.2825 +     *          insufficient arguments given the format string, or other
150.2826 +     *          illegal conditions.  For specification of all possible
150.2827 +     *          formatting errors, see the <a
150.2828 +     *          href="../util/Formatter.html#detail">Details</a> section of the
150.2829 +     *          formatter class specification
150.2830 +     *
150.2831 +     * @throws  NullPointerException
150.2832 +     *          If the <tt>format</tt> is <tt>null</tt>
150.2833 +     *
150.2834 +     * @return  A formatted string
150.2835 +     *
150.2836 +     * @see  java.util.Formatter
150.2837 +     * @since  1.5
150.2838 +     */
150.2839 +//    public static String format(Locale l, String format, Object ... args) {
150.2840 +//        return new Formatter(l).format(format, args).toString();
150.2841 +//    }
150.2842 +
150.2843 +    /**
150.2844 +     * Returns the string representation of the <code>Object</code> argument.
150.2845 +     *
150.2846 +     * @param   obj   an <code>Object</code>.
150.2847 +     * @return  if the argument is <code>null</code>, then a string equal to
150.2848 +     *          <code>"null"</code>; otherwise, the value of
150.2849 +     *          <code>obj.toString()</code> is returned.
150.2850 +     * @see     java.lang.Object#toString()
150.2851 +     */
150.2852 +    public static String valueOf(Object obj) {
150.2853 +        return (obj == null) ? "null" : obj.toString();
150.2854 +    }
150.2855 +
150.2856 +    /**
150.2857 +     * Returns the string representation of the <code>char</code> array
150.2858 +     * argument. The contents of the character array are copied; subsequent
150.2859 +     * modification of the character array does not affect the newly
150.2860 +     * created string.
150.2861 +     *
150.2862 +     * @param   data   a <code>char</code> array.
150.2863 +     * @return  a newly allocated string representing the same sequence of
150.2864 +     *          characters contained in the character array argument.
150.2865 +     */
150.2866 +    public static String valueOf(char data[]) {
150.2867 +        return new String(data);
150.2868 +    }
150.2869 +
150.2870 +    /**
150.2871 +     * Returns the string representation of a specific subarray of the
150.2872 +     * <code>char</code> array argument.
150.2873 +     * <p>
150.2874 +     * The <code>offset</code> argument is the index of the first
150.2875 +     * character of the subarray. The <code>count</code> argument
150.2876 +     * specifies the length of the subarray. The contents of the subarray
150.2877 +     * are copied; subsequent modification of the character array does not
150.2878 +     * affect the newly created string.
150.2879 +     *
150.2880 +     * @param   data     the character array.
150.2881 +     * @param   offset   the initial offset into the value of the
150.2882 +     *                  <code>String</code>.
150.2883 +     * @param   count    the length of the value of the <code>String</code>.
150.2884 +     * @return  a string representing the sequence of characters contained
150.2885 +     *          in the subarray of the character array argument.
150.2886 +     * @exception IndexOutOfBoundsException if <code>offset</code> is
150.2887 +     *          negative, or <code>count</code> is negative, or
150.2888 +     *          <code>offset+count</code> is larger than
150.2889 +     *          <code>data.length</code>.
150.2890 +     */
150.2891 +    public static String valueOf(char data[], int offset, int count) {
150.2892 +        return new String(data, offset, count);
150.2893 +    }
150.2894 +
150.2895 +    /**
150.2896 +     * Returns a String that represents the character sequence in the
150.2897 +     * array specified.
150.2898 +     *
150.2899 +     * @param   data     the character array.
150.2900 +     * @param   offset   initial offset of the subarray.
150.2901 +     * @param   count    length of the subarray.
150.2902 +     * @return  a <code>String</code> that contains the characters of the
150.2903 +     *          specified subarray of the character array.
150.2904 +     */
150.2905 +    public static String copyValueOf(char data[], int offset, int count) {
150.2906 +        // All public String constructors now copy the data.
150.2907 +        return new String(data, offset, count);
150.2908 +    }
150.2909 +
150.2910 +    /**
150.2911 +     * Returns a String that represents the character sequence in the
150.2912 +     * array specified.
150.2913 +     *
150.2914 +     * @param   data   the character array.
150.2915 +     * @return  a <code>String</code> that contains the characters of the
150.2916 +     *          character array.
150.2917 +     */
150.2918 +    public static String copyValueOf(char data[]) {
150.2919 +        return copyValueOf(data, 0, data.length);
150.2920 +    }
150.2921 +
150.2922 +    /**
150.2923 +     * Returns the string representation of the <code>boolean</code> argument.
150.2924 +     *
150.2925 +     * @param   b   a <code>boolean</code>.
150.2926 +     * @return  if the argument is <code>true</code>, a string equal to
150.2927 +     *          <code>"true"</code> is returned; otherwise, a string equal to
150.2928 +     *          <code>"false"</code> is returned.
150.2929 +     */
150.2930 +    public static String valueOf(boolean b) {
150.2931 +        return b ? "true" : "false";
150.2932 +    }
150.2933 +
150.2934 +    /**
150.2935 +     * Returns the string representation of the <code>char</code>
150.2936 +     * argument.
150.2937 +     *
150.2938 +     * @param   c   a <code>char</code>.
150.2939 +     * @return  a string of length <code>1</code> containing
150.2940 +     *          as its single character the argument <code>c</code>.
150.2941 +     */
150.2942 +    public static String valueOf(char c) {
150.2943 +        char data[] = {c};
150.2944 +        return new String(data, 0, 1);
150.2945 +    }
150.2946 +
150.2947 +    /**
150.2948 +     * Returns the string representation of the <code>int</code> argument.
150.2949 +     * <p>
150.2950 +     * The representation is exactly the one returned by the
150.2951 +     * <code>Integer.toString</code> method of one argument.
150.2952 +     *
150.2953 +     * @param   i   an <code>int</code>.
150.2954 +     * @return  a string representation of the <code>int</code> argument.
150.2955 +     * @see     java.lang.Integer#toString(int, int)
150.2956 +     */
150.2957 +    public static String valueOf(int i) {
150.2958 +        return Integer.toString(i);
150.2959 +    }
150.2960 +
150.2961 +    /**
150.2962 +     * Returns the string representation of the <code>long</code> argument.
150.2963 +     * <p>
150.2964 +     * The representation is exactly the one returned by the
150.2965 +     * <code>Long.toString</code> method of one argument.
150.2966 +     *
150.2967 +     * @param   l   a <code>long</code>.
150.2968 +     * @return  a string representation of the <code>long</code> argument.
150.2969 +     * @see     java.lang.Long#toString(long)
150.2970 +     */
150.2971 +    public static String valueOf(long l) {
150.2972 +        return Long.toString(l);
150.2973 +    }
150.2974 +
150.2975 +    /**
150.2976 +     * Returns the string representation of the <code>float</code> argument.
150.2977 +     * <p>
150.2978 +     * The representation is exactly the one returned by the
150.2979 +     * <code>Float.toString</code> method of one argument.
150.2980 +     *
150.2981 +     * @param   f   a <code>float</code>.
150.2982 +     * @return  a string representation of the <code>float</code> argument.
150.2983 +     * @see     java.lang.Float#toString(float)
150.2984 +     */
150.2985 +    public static String valueOf(float f) {
150.2986 +        return Float.toString(f);
150.2987 +    }
150.2988 +
150.2989 +    /**
150.2990 +     * Returns the string representation of the <code>double</code> argument.
150.2991 +     * <p>
150.2992 +     * The representation is exactly the one returned by the
150.2993 +     * <code>Double.toString</code> method of one argument.
150.2994 +     *
150.2995 +     * @param   d   a <code>double</code>.
150.2996 +     * @return  a  string representation of the <code>double</code> argument.
150.2997 +     * @see     java.lang.Double#toString(double)
150.2998 +     */
150.2999 +    public static String valueOf(double d) {
150.3000 +        return Double.toString(d);
150.3001 +    }
150.3002 +
150.3003 +    /**
150.3004 +     * Returns a canonical representation for the string object.
150.3005 +     * <p>
150.3006 +     * A pool of strings, initially empty, is maintained privately by the
150.3007 +     * class <code>String</code>.
150.3008 +     * <p>
150.3009 +     * When the intern method is invoked, if the pool already contains a
150.3010 +     * string equal to this <code>String</code> object as determined by
150.3011 +     * the {@link #equals(Object)} method, then the string from the pool is
150.3012 +     * returned. Otherwise, this <code>String</code> object is added to the
150.3013 +     * pool and a reference to this <code>String</code> object is returned.
150.3014 +     * <p>
150.3015 +     * It follows that for any two strings <code>s</code> and <code>t</code>,
150.3016 +     * <code>s.intern()&nbsp;==&nbsp;t.intern()</code> is <code>true</code>
150.3017 +     * if and only if <code>s.equals(t)</code> is <code>true</code>.
150.3018 +     * <p>
150.3019 +     * All literal strings and string-valued constant expressions are
150.3020 +     * interned. String literals are defined in section 3.10.5 of the
150.3021 +     * <cite>The Java&trade; Language Specification</cite>.
150.3022 +     *
150.3023 +     * @return  a string that has the same contents as this string, but is
150.3024 +     *          guaranteed to be from a pool of unique strings.
150.3025 +     */
150.3026 +    public native String intern();
150.3027 +}
   151.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   151.2 +++ b/emul/mini/src/main/java/java/lang/StringBuffer.java	Sun Feb 03 07:48:42 2013 +0100
   151.3 @@ -0,0 +1,604 @@
   151.4 +/*
   151.5 + * Copyright (c) 1994, 2008, 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 +
  151.29 +package java.lang;
  151.30 +
  151.31 +
  151.32 +/**
  151.33 + * A thread-safe, mutable sequence of characters.
  151.34 + * A string buffer is like a {@link String}, but can be modified. At any
  151.35 + * point in time it contains some particular sequence of characters, but
  151.36 + * the length and content of the sequence can be changed through certain
  151.37 + * method calls.
  151.38 + * <p>
  151.39 + * String buffers are safe for use by multiple threads. The methods
  151.40 + * are synchronized where necessary so that all the operations on any
  151.41 + * particular instance behave as if they occur in some serial order
  151.42 + * that is consistent with the order of the method calls made by each of
  151.43 + * the individual threads involved.
  151.44 + * <p>
  151.45 + * The principal operations on a <code>StringBuffer</code> are the
  151.46 + * <code>append</code> and <code>insert</code> methods, which are
  151.47 + * overloaded so as to accept data of any type. Each effectively
  151.48 + * converts a given datum to a string and then appends or inserts the
  151.49 + * characters of that string to the string buffer. The
  151.50 + * <code>append</code> method always adds these characters at the end
  151.51 + * of the buffer; the <code>insert</code> method adds the characters at
  151.52 + * a specified point.
  151.53 + * <p>
  151.54 + * For example, if <code>z</code> refers to a string buffer object
  151.55 + * whose current contents are "<code>start</code>", then
  151.56 + * the method call <code>z.append("le")</code> would cause the string
  151.57 + * buffer to contain "<code>startle</code>", whereas
  151.58 + * <code>z.insert(4, "le")</code> would alter the string buffer to
  151.59 + * contain "<code>starlet</code>".
  151.60 + * <p>
  151.61 + * In general, if sb refers to an instance of a <code>StringBuffer</code>,
  151.62 + * then <code>sb.append(x)</code> has the same effect as
  151.63 + * <code>sb.insert(sb.length(),&nbsp;x)</code>.
  151.64 + * <p>
  151.65 + * Whenever an operation occurs involving a source sequence (such as
  151.66 + * appending or inserting from a source sequence) this class synchronizes
  151.67 + * only on the string buffer performing the operation, not on the source.
  151.68 + * <p>
  151.69 + * Every string buffer has a capacity. As long as the length of the
  151.70 + * character sequence contained in the string buffer does not exceed
  151.71 + * the capacity, it is not necessary to allocate a new internal
  151.72 + * buffer array. If the internal buffer overflows, it is
  151.73 + * automatically made larger.
  151.74 + *
  151.75 + * As of  release JDK 5, this class has been supplemented with an equivalent
  151.76 + * class designed for use by a single thread, {@link StringBuilder}.  The
  151.77 + * <tt>StringBuilder</tt> class should generally be used in preference to
  151.78 + * this one, as it supports all of the same operations but it is faster, as
  151.79 + * it performs no synchronization.
  151.80 + *
  151.81 + * @author      Arthur van Hoff
  151.82 + * @see     java.lang.StringBuilder
  151.83 + * @see     java.lang.String
  151.84 + * @since   JDK1.0
  151.85 + */
  151.86 + public final class StringBuffer
  151.87 +    extends AbstractStringBuilder
  151.88 +    implements java.io.Serializable, CharSequence
  151.89 +{
  151.90 +
  151.91 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
  151.92 +    static final long serialVersionUID = 3388685877147921107L;
  151.93 +
  151.94 +    /**
  151.95 +     * Constructs a string buffer with no characters in it and an
  151.96 +     * initial capacity of 16 characters.
  151.97 +     */
  151.98 +    public StringBuffer() {
  151.99 +        super(16);
 151.100 +    }
 151.101 +
 151.102 +    /**
 151.103 +     * Constructs a string buffer with no characters in it and
 151.104 +     * the specified initial capacity.
 151.105 +     *
 151.106 +     * @param      capacity  the initial capacity.
 151.107 +     * @exception  NegativeArraySizeException  if the <code>capacity</code>
 151.108 +     *               argument is less than <code>0</code>.
 151.109 +     */
 151.110 +    public StringBuffer(int capacity) {
 151.111 +        super(capacity);
 151.112 +    }
 151.113 +
 151.114 +    /**
 151.115 +     * Constructs a string buffer initialized to the contents of the
 151.116 +     * specified string. The initial capacity of the string buffer is
 151.117 +     * <code>16</code> plus the length of the string argument.
 151.118 +     *
 151.119 +     * @param   str   the initial contents of the buffer.
 151.120 +     * @exception NullPointerException if <code>str</code> is <code>null</code>
 151.121 +     */
 151.122 +    public StringBuffer(String str) {
 151.123 +        super(str.length() + 16);
 151.124 +        append(str);
 151.125 +    }
 151.126 +
 151.127 +    /**
 151.128 +     * Constructs a string buffer that contains the same characters
 151.129 +     * as the specified <code>CharSequence</code>. The initial capacity of
 151.130 +     * the string buffer is <code>16</code> plus the length of the
 151.131 +     * <code>CharSequence</code> argument.
 151.132 +     * <p>
 151.133 +     * If the length of the specified <code>CharSequence</code> is
 151.134 +     * less than or equal to zero, then an empty buffer of capacity
 151.135 +     * <code>16</code> is returned.
 151.136 +     *
 151.137 +     * @param      seq   the sequence to copy.
 151.138 +     * @exception NullPointerException if <code>seq</code> is <code>null</code>
 151.139 +     * @since 1.5
 151.140 +     */
 151.141 +    public StringBuffer(CharSequence seq) {
 151.142 +        this(seq.length() + 16);
 151.143 +        append(seq);
 151.144 +    }
 151.145 +
 151.146 +    public synchronized int length() {
 151.147 +        return count;
 151.148 +    }
 151.149 +
 151.150 +    public synchronized int capacity() {
 151.151 +        return value.length;
 151.152 +    }
 151.153 +
 151.154 +
 151.155 +    public synchronized void ensureCapacity(int minimumCapacity) {
 151.156 +        if (minimumCapacity > value.length) {
 151.157 +            expandCapacity(minimumCapacity);
 151.158 +        }
 151.159 +    }
 151.160 +
 151.161 +    /**
 151.162 +     * @since      1.5
 151.163 +     */
 151.164 +    public synchronized void trimToSize() {
 151.165 +        super.trimToSize();
 151.166 +    }
 151.167 +
 151.168 +    /**
 151.169 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 151.170 +     * @see        #length()
 151.171 +     */
 151.172 +    public synchronized void setLength(int newLength) {
 151.173 +        super.setLength(newLength);
 151.174 +    }
 151.175 +
 151.176 +    /**
 151.177 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 151.178 +     * @see        #length()
 151.179 +     */
 151.180 +    public synchronized char charAt(int index) {
 151.181 +        if ((index < 0) || (index >= count))
 151.182 +            throw new StringIndexOutOfBoundsException(index);
 151.183 +        return value[index];
 151.184 +    }
 151.185 +
 151.186 +    /**
 151.187 +     * @since      1.5
 151.188 +     */
 151.189 +    public synchronized int codePointAt(int index) {
 151.190 +        return super.codePointAt(index);
 151.191 +    }
 151.192 +
 151.193 +    /**
 151.194 +     * @since     1.5
 151.195 +     */
 151.196 +    public synchronized int codePointBefore(int index) {
 151.197 +        return super.codePointBefore(index);
 151.198 +    }
 151.199 +
 151.200 +    /**
 151.201 +     * @since     1.5
 151.202 +     */
 151.203 +    public synchronized int codePointCount(int beginIndex, int endIndex) {
 151.204 +        return super.codePointCount(beginIndex, endIndex);
 151.205 +    }
 151.206 +
 151.207 +    /**
 151.208 +     * @since     1.5
 151.209 +     */
 151.210 +    public synchronized int offsetByCodePoints(int index, int codePointOffset) {
 151.211 +        return super.offsetByCodePoints(index, codePointOffset);
 151.212 +    }
 151.213 +
 151.214 +    /**
 151.215 +     * @throws NullPointerException {@inheritDoc}
 151.216 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 151.217 +     */
 151.218 +    public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
 151.219 +                                      int dstBegin)
 151.220 +    {
 151.221 +        super.getChars(srcBegin, srcEnd, dst, dstBegin);
 151.222 +    }
 151.223 +
 151.224 +    /**
 151.225 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 151.226 +     * @see        #length()
 151.227 +     */
 151.228 +    public synchronized void setCharAt(int index, char ch) {
 151.229 +        if ((index < 0) || (index >= count))
 151.230 +            throw new StringIndexOutOfBoundsException(index);
 151.231 +        value[index] = ch;
 151.232 +    }
 151.233 +
 151.234 +    public synchronized StringBuffer append(Object obj) {
 151.235 +        super.append(String.valueOf(obj));
 151.236 +        return this;
 151.237 +    }
 151.238 +
 151.239 +    public synchronized StringBuffer append(String str) {
 151.240 +        super.append(str);
 151.241 +        return this;
 151.242 +    }
 151.243 +
 151.244 +    /**
 151.245 +     * Appends the specified <tt>StringBuffer</tt> to this sequence.
 151.246 +     * <p>
 151.247 +     * The characters of the <tt>StringBuffer</tt> argument are appended,
 151.248 +     * in order, to the contents of this <tt>StringBuffer</tt>, increasing the
 151.249 +     * length of this <tt>StringBuffer</tt> by the length of the argument.
 151.250 +     * If <tt>sb</tt> is <tt>null</tt>, then the four characters
 151.251 +     * <tt>"null"</tt> are appended to this <tt>StringBuffer</tt>.
 151.252 +     * <p>
 151.253 +     * Let <i>n</i> be the length of the old character sequence, the one
 151.254 +     * contained in the <tt>StringBuffer</tt> just prior to execution of the
 151.255 +     * <tt>append</tt> method. Then the character at index <i>k</i> in
 151.256 +     * the new character sequence is equal to the character at index <i>k</i>
 151.257 +     * in the old character sequence, if <i>k</i> is less than <i>n</i>;
 151.258 +     * otherwise, it is equal to the character at index <i>k-n</i> in the
 151.259 +     * argument <code>sb</code>.
 151.260 +     * <p>
 151.261 +     * This method synchronizes on <code>this</code> (the destination)
 151.262 +     * object but does not synchronize on the source (<code>sb</code>).
 151.263 +     *
 151.264 +     * @param   sb   the <tt>StringBuffer</tt> to append.
 151.265 +     * @return  a reference to this object.
 151.266 +     * @since 1.4
 151.267 +     */
 151.268 +    public synchronized StringBuffer append(StringBuffer sb) {
 151.269 +        super.append(sb);
 151.270 +        return this;
 151.271 +    }
 151.272 +
 151.273 +
 151.274 +    /**
 151.275 +     * Appends the specified <code>CharSequence</code> to this
 151.276 +     * sequence.
 151.277 +     * <p>
 151.278 +     * The characters of the <code>CharSequence</code> argument are appended,
 151.279 +     * in order, increasing the length of this sequence by the length of the
 151.280 +     * argument.
 151.281 +     *
 151.282 +     * <p>The result of this method is exactly the same as if it were an
 151.283 +     * invocation of this.append(s, 0, s.length());
 151.284 +     *
 151.285 +     * <p>This method synchronizes on this (the destination)
 151.286 +     * object but does not synchronize on the source (<code>s</code>).
 151.287 +     *
 151.288 +     * <p>If <code>s</code> is <code>null</code>, then the four characters
 151.289 +     * <code>"null"</code> are appended.
 151.290 +     *
 151.291 +     * @param   s the <code>CharSequence</code> to append.
 151.292 +     * @return  a reference to this object.
 151.293 +     * @since 1.5
 151.294 +     */
 151.295 +    public StringBuffer append(CharSequence s) {
 151.296 +        // Note, synchronization achieved via other invocations
 151.297 +        if (s == null)
 151.298 +            s = "null";
 151.299 +        if (s instanceof String)
 151.300 +            return this.append((String)s);
 151.301 +        if (s instanceof StringBuffer)
 151.302 +            return this.append((StringBuffer)s);
 151.303 +        return this.append(s, 0, s.length());
 151.304 +    }
 151.305 +
 151.306 +    /**
 151.307 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 151.308 +     * @since      1.5
 151.309 +     */
 151.310 +    public synchronized StringBuffer append(CharSequence s, int start, int end)
 151.311 +    {
 151.312 +        super.append(s, start, end);
 151.313 +        return this;
 151.314 +    }
 151.315 +
 151.316 +    public synchronized StringBuffer append(char[] str) {
 151.317 +        super.append(str);
 151.318 +        return this;
 151.319 +    }
 151.320 +
 151.321 +    /**
 151.322 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 151.323 +     */
 151.324 +    public synchronized StringBuffer append(char[] str, int offset, int len) {
 151.325 +        super.append(str, offset, len);
 151.326 +        return this;
 151.327 +    }
 151.328 +
 151.329 +    public synchronized StringBuffer append(boolean b) {
 151.330 +        super.append(b);
 151.331 +        return this;
 151.332 +    }
 151.333 +
 151.334 +    public synchronized StringBuffer append(char c) {
 151.335 +        super.append(c);
 151.336 +        return this;
 151.337 +    }
 151.338 +
 151.339 +    public synchronized StringBuffer append(int i) {
 151.340 +        super.append(i);
 151.341 +        return this;
 151.342 +    }
 151.343 +
 151.344 +    /**
 151.345 +     * @since 1.5
 151.346 +     */
 151.347 +    public synchronized StringBuffer appendCodePoint(int codePoint) {
 151.348 +        super.appendCodePoint(codePoint);
 151.349 +        return this;
 151.350 +    }
 151.351 +
 151.352 +    public synchronized StringBuffer append(long lng) {
 151.353 +        super.append(lng);
 151.354 +        return this;
 151.355 +    }
 151.356 +
 151.357 +    public synchronized StringBuffer append(float f) {
 151.358 +        super.append(f);
 151.359 +        return this;
 151.360 +    }
 151.361 +
 151.362 +    public synchronized StringBuffer append(double d) {
 151.363 +        super.append(d);
 151.364 +        return this;
 151.365 +    }
 151.366 +
 151.367 +    /**
 151.368 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.369 +     * @since      1.2
 151.370 +     */
 151.371 +    public synchronized StringBuffer delete(int start, int end) {
 151.372 +        super.delete(start, end);
 151.373 +        return this;
 151.374 +    }
 151.375 +
 151.376 +    /**
 151.377 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.378 +     * @since      1.2
 151.379 +     */
 151.380 +    public synchronized StringBuffer deleteCharAt(int index) {
 151.381 +        super.deleteCharAt(index);
 151.382 +        return this;
 151.383 +    }
 151.384 +
 151.385 +    /**
 151.386 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.387 +     * @since      1.2
 151.388 +     */
 151.389 +    public synchronized StringBuffer replace(int start, int end, String str) {
 151.390 +        super.replace(start, end, str);
 151.391 +        return this;
 151.392 +    }
 151.393 +
 151.394 +    /**
 151.395 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.396 +     * @since      1.2
 151.397 +     */
 151.398 +    public synchronized String substring(int start) {
 151.399 +        return substring(start, count);
 151.400 +    }
 151.401 +
 151.402 +    /**
 151.403 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 151.404 +     * @since      1.4
 151.405 +     */
 151.406 +    public synchronized CharSequence subSequence(int start, int end) {
 151.407 +        return super.substring(start, end);
 151.408 +    }
 151.409 +
 151.410 +    /**
 151.411 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.412 +     * @since      1.2
 151.413 +     */
 151.414 +    public synchronized String substring(int start, int end) {
 151.415 +        return super.substring(start, end);
 151.416 +    }
 151.417 +
 151.418 +    /**
 151.419 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.420 +     * @since      1.2
 151.421 +     */
 151.422 +    public synchronized StringBuffer insert(int index, char[] str, int offset,
 151.423 +                                            int len)
 151.424 +    {
 151.425 +        super.insert(index, str, offset, len);
 151.426 +        return this;
 151.427 +    }
 151.428 +
 151.429 +    /**
 151.430 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.431 +     */
 151.432 +    public synchronized StringBuffer insert(int offset, Object obj) {
 151.433 +        super.insert(offset, String.valueOf(obj));
 151.434 +        return this;
 151.435 +    }
 151.436 +
 151.437 +    /**
 151.438 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.439 +     */
 151.440 +    public synchronized StringBuffer insert(int offset, String str) {
 151.441 +        super.insert(offset, str);
 151.442 +        return this;
 151.443 +    }
 151.444 +
 151.445 +    /**
 151.446 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.447 +     */
 151.448 +    public synchronized StringBuffer insert(int offset, char[] str) {
 151.449 +        super.insert(offset, str);
 151.450 +        return this;
 151.451 +    }
 151.452 +
 151.453 +    /**
 151.454 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 151.455 +     * @since      1.5
 151.456 +     */
 151.457 +    public StringBuffer insert(int dstOffset, CharSequence s) {
 151.458 +        // Note, synchronization achieved via other invocations
 151.459 +        if (s == null)
 151.460 +            s = "null";
 151.461 +        if (s instanceof String)
 151.462 +            return this.insert(dstOffset, (String)s);
 151.463 +        return this.insert(dstOffset, s, 0, s.length());
 151.464 +    }
 151.465 +
 151.466 +    /**
 151.467 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 151.468 +     * @since      1.5
 151.469 +     */
 151.470 +    public synchronized StringBuffer insert(int dstOffset, CharSequence s,
 151.471 +                                            int start, int end)
 151.472 +    {
 151.473 +        super.insert(dstOffset, s, start, end);
 151.474 +        return this;
 151.475 +    }
 151.476 +
 151.477 +    /**
 151.478 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.479 +     */
 151.480 +    public StringBuffer insert(int offset, boolean b) {
 151.481 +        return insert(offset, String.valueOf(b));
 151.482 +    }
 151.483 +
 151.484 +    /**
 151.485 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 151.486 +     */
 151.487 +    public synchronized StringBuffer insert(int offset, char c) {
 151.488 +        super.insert(offset, c);
 151.489 +        return this;
 151.490 +    }
 151.491 +
 151.492 +    /**
 151.493 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.494 +     */
 151.495 +    public StringBuffer insert(int offset, int i) {
 151.496 +        return insert(offset, String.valueOf(i));
 151.497 +    }
 151.498 +
 151.499 +    /**
 151.500 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.501 +     */
 151.502 +    public StringBuffer insert(int offset, long l) {
 151.503 +        return insert(offset, String.valueOf(l));
 151.504 +    }
 151.505 +
 151.506 +    /**
 151.507 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.508 +     */
 151.509 +    public StringBuffer insert(int offset, float f) {
 151.510 +        return insert(offset, String.valueOf(f));
 151.511 +    }
 151.512 +
 151.513 +    /**
 151.514 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 151.515 +     */
 151.516 +    public StringBuffer insert(int offset, double d) {
 151.517 +        return insert(offset, String.valueOf(d));
 151.518 +    }
 151.519 +
 151.520 +    /**
 151.521 +     * @throws NullPointerException {@inheritDoc}
 151.522 +     * @since      1.4
 151.523 +     */
 151.524 +    public int indexOf(String str) {
 151.525 +        return indexOf(str, 0);
 151.526 +    }
 151.527 +
 151.528 +    /**
 151.529 +     * @throws NullPointerException {@inheritDoc}
 151.530 +     * @since      1.4
 151.531 +     */
 151.532 +    public synchronized int indexOf(String str, int fromIndex) {
 151.533 +        return super.indexOf(str, fromIndex);
 151.534 +    }
 151.535 +
 151.536 +    /**
 151.537 +     * @throws NullPointerException {@inheritDoc}
 151.538 +     * @since      1.4
 151.539 +     */
 151.540 +    public int lastIndexOf(String str) {
 151.541 +        // Note, synchronization achieved via other invocations
 151.542 +        return lastIndexOf(str, count);
 151.543 +    }
 151.544 +
 151.545 +    /**
 151.546 +     * @throws NullPointerException {@inheritDoc}
 151.547 +     * @since      1.4
 151.548 +     */
 151.549 +    public synchronized int lastIndexOf(String str, int fromIndex) {
 151.550 +        return String.lastIndexOf(value, 0, count,
 151.551 +                              str.toCharArray(), 0, str.length(), fromIndex);
 151.552 +    }
 151.553 +
 151.554 +    /**
 151.555 +     * @since   JDK1.0.2
 151.556 +     */
 151.557 +    public synchronized StringBuffer reverse() {
 151.558 +        super.reverse();
 151.559 +        return this;
 151.560 +    }
 151.561 +
 151.562 +    public synchronized String toString() {
 151.563 +        return new String(value, 0, count);
 151.564 +    }
 151.565 +
 151.566 +//    /**
 151.567 +//     * Serializable fields for StringBuffer.
 151.568 +//     *
 151.569 +//     * @serialField value  char[]
 151.570 +//     *              The backing character array of this StringBuffer.
 151.571 +//     * @serialField count int
 151.572 +//     *              The number of characters in this StringBuffer.
 151.573 +//     * @serialField shared  boolean
 151.574 +//     *              A flag indicating whether the backing array is shared.
 151.575 +//     *              The value is ignored upon deserialization.
 151.576 +//     */
 151.577 +//    private static final java.io.ObjectStreamField[] serialPersistentFields =
 151.578 +//    {
 151.579 +//        new java.io.ObjectStreamField("value", char[].class),
 151.580 +//        new java.io.ObjectStreamField("count", Integer.TYPE),
 151.581 +//        new java.io.ObjectStreamField("shared", Boolean.TYPE),
 151.582 +//    };
 151.583 +//
 151.584 +//    /**
 151.585 +//     * readObject is called to restore the state of the StringBuffer from
 151.586 +//     * a stream.
 151.587 +//     */
 151.588 +//    private synchronized void writeObject(java.io.ObjectOutputStream s)
 151.589 +//        throws java.io.IOException {
 151.590 +//        java.io.ObjectOutputStream.PutField fields = s.putFields();
 151.591 +//        fields.put("value", value);
 151.592 +//        fields.put("count", count);
 151.593 +//        fields.put("shared", false);
 151.594 +//        s.writeFields();
 151.595 +//    }
 151.596 +//
 151.597 +//    /**
 151.598 +//     * readObject is called to restore the state of the StringBuffer from
 151.599 +//     * a stream.
 151.600 +//     */
 151.601 +//    private void readObject(java.io.ObjectInputStream s)
 151.602 +//        throws java.io.IOException, ClassNotFoundException {
 151.603 +//        java.io.ObjectInputStream.GetField fields = s.readFields();
 151.604 +//        value = (char[])fields.get("value", null);
 151.605 +//        count = fields.get("count", 0);
 151.606 +//    }
 151.607 +}
   152.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   152.2 +++ b/emul/mini/src/main/java/java/lang/StringBuilder.java	Sun Feb 03 07:48:42 2013 +0100
   152.3 @@ -0,0 +1,436 @@
   152.4 +/*
   152.5 + * Copyright (c) 2003, 2008, 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 +/**
  152.33 + * A mutable sequence of characters.  This class provides an API compatible
  152.34 + * with <code>StringBuffer</code>, but with no guarantee of synchronization.
  152.35 + * This class is designed for use as a drop-in replacement for
  152.36 + * <code>StringBuffer</code> in places where the string buffer was being
  152.37 + * used by a single thread (as is generally the case).   Where possible,
  152.38 + * it is recommended that this class be used in preference to
  152.39 + * <code>StringBuffer</code> as it will be faster under most implementations.
  152.40 + *
  152.41 + * <p>The principal operations on a <code>StringBuilder</code> are the
  152.42 + * <code>append</code> and <code>insert</code> methods, which are
  152.43 + * overloaded so as to accept data of any type. Each effectively
  152.44 + * converts a given datum to a string and then appends or inserts the
  152.45 + * characters of that string to the string builder. The
  152.46 + * <code>append</code> method always adds these characters at the end
  152.47 + * of the builder; the <code>insert</code> method adds the characters at
  152.48 + * a specified point.
  152.49 + * <p>
  152.50 + * For example, if <code>z</code> refers to a string builder object
  152.51 + * whose current contents are "<code>start</code>", then
  152.52 + * the method call <code>z.append("le")</code> would cause the string
  152.53 + * builder to contain "<code>startle</code>", whereas
  152.54 + * <code>z.insert(4, "le")</code> would alter the string builder to
  152.55 + * contain "<code>starlet</code>".
  152.56 + * <p>
  152.57 + * In general, if sb refers to an instance of a <code>StringBuilder</code>,
  152.58 + * then <code>sb.append(x)</code> has the same effect as
  152.59 + * <code>sb.insert(sb.length(),&nbsp;x)</code>.
  152.60 + *
  152.61 + * Every string builder has a capacity. As long as the length of the
  152.62 + * character sequence contained in the string builder does not exceed
  152.63 + * the capacity, it is not necessary to allocate a new internal
  152.64 + * buffer. If the internal buffer overflows, it is automatically made larger.
  152.65 + *
  152.66 + * <p>Instances of <code>StringBuilder</code> are not safe for
  152.67 + * use by multiple threads. If such synchronization is required then it is
  152.68 + * recommended that {@link java.lang.StringBuffer} be used.
  152.69 + *
  152.70 + * @author      Michael McCloskey
  152.71 + * @see         java.lang.StringBuffer
  152.72 + * @see         java.lang.String
  152.73 + * @since       1.5
  152.74 + */
  152.75 +public final class StringBuilder
  152.76 +    extends AbstractStringBuilder
  152.77 +    implements java.io.Serializable, CharSequence
  152.78 +{
  152.79 +
  152.80 +    /** use serialVersionUID for interoperability */
  152.81 +    static final long serialVersionUID = 4383685877147921099L;
  152.82 +
  152.83 +    /**
  152.84 +     * Constructs a string builder with no characters in it and an
  152.85 +     * initial capacity of 16 characters.
  152.86 +     */
  152.87 +    public StringBuilder() {
  152.88 +        super(16);
  152.89 +    }
  152.90 +
  152.91 +    /**
  152.92 +     * Constructs a string builder with no characters in it and an
  152.93 +     * initial capacity specified by the <code>capacity</code> argument.
  152.94 +     *
  152.95 +     * @param      capacity  the initial capacity.
  152.96 +     * @throws     NegativeArraySizeException  if the <code>capacity</code>
  152.97 +     *               argument is less than <code>0</code>.
  152.98 +     */
  152.99 +    public StringBuilder(int capacity) {
 152.100 +        super(capacity);
 152.101 +    }
 152.102 +
 152.103 +    /**
 152.104 +     * Constructs a string builder initialized to the contents of the
 152.105 +     * specified string. The initial capacity of the string builder is
 152.106 +     * <code>16</code> plus the length of the string argument.
 152.107 +     *
 152.108 +     * @param   str   the initial contents of the buffer.
 152.109 +     * @throws    NullPointerException if <code>str</code> is <code>null</code>
 152.110 +     */
 152.111 +    public StringBuilder(String str) {
 152.112 +        super(str.length() + 16);
 152.113 +        append(str);
 152.114 +    }
 152.115 +
 152.116 +    /**
 152.117 +     * Constructs a string builder that contains the same characters
 152.118 +     * as the specified <code>CharSequence</code>. The initial capacity of
 152.119 +     * the string builder is <code>16</code> plus the length of the
 152.120 +     * <code>CharSequence</code> argument.
 152.121 +     *
 152.122 +     * @param      seq   the sequence to copy.
 152.123 +     * @throws    NullPointerException if <code>seq</code> is <code>null</code>
 152.124 +     */
 152.125 +    public StringBuilder(CharSequence seq) {
 152.126 +        this(seq.length() + 16);
 152.127 +        append(seq);
 152.128 +    }
 152.129 +
 152.130 +    public StringBuilder append(Object obj) {
 152.131 +        return append(String.valueOf(obj));
 152.132 +    }
 152.133 +
 152.134 +    public StringBuilder append(String str) {
 152.135 +        super.append(str);
 152.136 +        return this;
 152.137 +    }
 152.138 +
 152.139 +    // Appends the specified string builder to this sequence.
 152.140 +    private StringBuilder append(StringBuilder sb) {
 152.141 +        if (sb == null)
 152.142 +            return append("null");
 152.143 +        int len = sb.length();
 152.144 +        int newcount = count + len;
 152.145 +        if (newcount > value.length)
 152.146 +            expandCapacity(newcount);
 152.147 +        sb.getChars(0, len, value, count);
 152.148 +        count = newcount;
 152.149 +        return this;
 152.150 +    }
 152.151 +
 152.152 +    /**
 152.153 +     * Appends the specified <tt>StringBuffer</tt> to this sequence.
 152.154 +     * <p>
 152.155 +     * The characters of the <tt>StringBuffer</tt> argument are appended,
 152.156 +     * in order, to this sequence, increasing the
 152.157 +     * length of this sequence by the length of the argument.
 152.158 +     * If <tt>sb</tt> is <tt>null</tt>, then the four characters
 152.159 +     * <tt>"null"</tt> are appended to this sequence.
 152.160 +     * <p>
 152.161 +     * Let <i>n</i> be the length of this character sequence just prior to
 152.162 +     * execution of the <tt>append</tt> method. Then the character at index
 152.163 +     * <i>k</i> in the new character sequence is equal to the character at
 152.164 +     * index <i>k</i> in the old character sequence, if <i>k</i> is less than
 152.165 +     * <i>n</i>; otherwise, it is equal to the character at index <i>k-n</i>
 152.166 +     * in the argument <code>sb</code>.
 152.167 +     *
 152.168 +     * @param   sb   the <tt>StringBuffer</tt> to append.
 152.169 +     * @return  a reference to this object.
 152.170 +     */
 152.171 +    public StringBuilder append(StringBuffer sb) {
 152.172 +        super.append(sb);
 152.173 +        return this;
 152.174 +    }
 152.175 +
 152.176 +    /**
 152.177 +     */
 152.178 +    public StringBuilder append(CharSequence s) {
 152.179 +        if (s == null)
 152.180 +            s = "null";
 152.181 +        if (s instanceof String)
 152.182 +            return this.append((String)s);
 152.183 +        if (s instanceof StringBuffer)
 152.184 +            return this.append((StringBuffer)s);
 152.185 +        if (s instanceof StringBuilder)
 152.186 +            return this.append((StringBuilder)s);
 152.187 +        return this.append(s, 0, s.length());
 152.188 +    }
 152.189 +
 152.190 +    /**
 152.191 +     * @throws     IndexOutOfBoundsException {@inheritDoc}
 152.192 +     */
 152.193 +    public StringBuilder append(CharSequence s, int start, int end) {
 152.194 +        super.append(s, start, end);
 152.195 +        return this;
 152.196 +    }
 152.197 +
 152.198 +    public StringBuilder append(char[] str) {
 152.199 +        super.append(str);
 152.200 +        return this;
 152.201 +    }
 152.202 +
 152.203 +    /**
 152.204 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 152.205 +     */
 152.206 +    public StringBuilder append(char[] str, int offset, int len) {
 152.207 +        super.append(str, offset, len);
 152.208 +        return this;
 152.209 +    }
 152.210 +
 152.211 +    public StringBuilder append(boolean b) {
 152.212 +        super.append(b);
 152.213 +        return this;
 152.214 +    }
 152.215 +
 152.216 +    public StringBuilder append(char c) {
 152.217 +        super.append(c);
 152.218 +        return this;
 152.219 +    }
 152.220 +
 152.221 +    public StringBuilder append(int i) {
 152.222 +        super.append(i);
 152.223 +        return this;
 152.224 +    }
 152.225 +
 152.226 +    public StringBuilder append(long lng) {
 152.227 +        super.append(lng);
 152.228 +        return this;
 152.229 +    }
 152.230 +
 152.231 +    public StringBuilder append(float f) {
 152.232 +        super.append(f);
 152.233 +        return this;
 152.234 +    }
 152.235 +
 152.236 +    public StringBuilder append(double d) {
 152.237 +        super.append(d);
 152.238 +        return this;
 152.239 +    }
 152.240 +
 152.241 +    /**
 152.242 +     * @since 1.5
 152.243 +     */
 152.244 +    public StringBuilder appendCodePoint(int codePoint) {
 152.245 +        super.appendCodePoint(codePoint);
 152.246 +        return this;
 152.247 +    }
 152.248 +
 152.249 +    /**
 152.250 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 152.251 +     */
 152.252 +    public StringBuilder delete(int start, int end) {
 152.253 +        super.delete(start, end);
 152.254 +        return this;
 152.255 +    }
 152.256 +
 152.257 +    /**
 152.258 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 152.259 +     */
 152.260 +    public StringBuilder deleteCharAt(int index) {
 152.261 +        super.deleteCharAt(index);
 152.262 +        return this;
 152.263 +    }
 152.264 +
 152.265 +    /**
 152.266 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 152.267 +     */
 152.268 +    public StringBuilder replace(int start, int end, String str) {
 152.269 +        super.replace(start, end, str);
 152.270 +        return this;
 152.271 +    }
 152.272 +
 152.273 +    /**
 152.274 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 152.275 +     */
 152.276 +    public StringBuilder insert(int index, char[] str, int offset,
 152.277 +                                int len)
 152.278 +    {
 152.279 +        super.insert(index, str, offset, len);
 152.280 +        return this;
 152.281 +    }
 152.282 +
 152.283 +    /**
 152.284 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 152.285 +     */
 152.286 +    public StringBuilder insert(int offset, Object obj) {
 152.287 +        return insert(offset, String.valueOf(obj));
 152.288 +    }
 152.289 +
 152.290 +    /**
 152.291 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 152.292 +     */
 152.293 +    public StringBuilder insert(int offset, String str) {
 152.294 +        super.insert(offset, str);
 152.295 +        return this;
 152.296 +    }
 152.297 +
 152.298 +    /**
 152.299 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 152.300 +     */
 152.301 +    public StringBuilder insert(int offset, char[] str) {
 152.302 +        super.insert(offset, str);
 152.303 +        return this;
 152.304 +    }
 152.305 +
 152.306 +    /**
 152.307 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 152.308 +     */
 152.309 +    public StringBuilder insert(int dstOffset, CharSequence s) {
 152.310 +        if (s == null)
 152.311 +            s = "null";
 152.312 +        if (s instanceof String)
 152.313 +            return this.insert(dstOffset, (String)s);
 152.314 +        return this.insert(dstOffset, s, 0, s.length());
 152.315 +    }
 152.316 +
 152.317 +    /**
 152.318 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 152.319 +     */
 152.320 +    public StringBuilder insert(int dstOffset, CharSequence s,
 152.321 +                                int start, int end)
 152.322 +    {
 152.323 +        super.insert(dstOffset, s, start, end);
 152.324 +        return this;
 152.325 +    }
 152.326 +
 152.327 +    /**
 152.328 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 152.329 +     */
 152.330 +    public StringBuilder insert(int offset, boolean b) {
 152.331 +        super.insert(offset, b);
 152.332 +        return this;
 152.333 +    }
 152.334 +
 152.335 +    /**
 152.336 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 152.337 +     */
 152.338 +    public StringBuilder insert(int offset, char c) {
 152.339 +        super.insert(offset, c);
 152.340 +        return this;
 152.341 +    }
 152.342 +
 152.343 +    /**
 152.344 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 152.345 +     */
 152.346 +    public StringBuilder insert(int offset, int i) {
 152.347 +        return insert(offset, String.valueOf(i));
 152.348 +    }
 152.349 +
 152.350 +    /**
 152.351 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 152.352 +     */
 152.353 +    public StringBuilder insert(int offset, long l) {
 152.354 +        return insert(offset, String.valueOf(l));
 152.355 +    }
 152.356 +
 152.357 +    /**
 152.358 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 152.359 +     */
 152.360 +    public StringBuilder insert(int offset, float f) {
 152.361 +        return insert(offset, String.valueOf(f));
 152.362 +    }
 152.363 +
 152.364 +    /**
 152.365 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 152.366 +     */
 152.367 +    public StringBuilder insert(int offset, double d) {
 152.368 +        return insert(offset, String.valueOf(d));
 152.369 +    }
 152.370 +
 152.371 +    /**
 152.372 +     * @throws NullPointerException {@inheritDoc}
 152.373 +     */
 152.374 +    public int indexOf(String str) {
 152.375 +        return indexOf(str, 0);
 152.376 +    }
 152.377 +
 152.378 +    /**
 152.379 +     * @throws NullPointerException {@inheritDoc}
 152.380 +     */
 152.381 +    public int indexOf(String str, int fromIndex) {
 152.382 +        return super.indexOf(str, fromIndex);
 152.383 +    }
 152.384 +
 152.385 +    /**
 152.386 +     * @throws NullPointerException {@inheritDoc}
 152.387 +     */
 152.388 +    public int lastIndexOf(String str) {
 152.389 +        return lastIndexOf(str, count);
 152.390 +    }
 152.391 +
 152.392 +    /**
 152.393 +     * @throws NullPointerException {@inheritDoc}
 152.394 +     */
 152.395 +    public int lastIndexOf(String str, int fromIndex) {
 152.396 +        return String.lastIndexOf(value, 0, count,
 152.397 +                              str.toCharArray(), 0, str.length(), fromIndex);
 152.398 +    }
 152.399 +
 152.400 +    public StringBuilder reverse() {
 152.401 +        super.reverse();
 152.402 +        return this;
 152.403 +    }
 152.404 +
 152.405 +    public String toString() {
 152.406 +        // Create a copy, don't share the array
 152.407 +        return new String(value, 0, count);
 152.408 +    }
 152.409 +
 152.410 +    /**
 152.411 +     * Save the state of the <tt>StringBuilder</tt> instance to a stream
 152.412 +     * (that is, serialize it).
 152.413 +     *
 152.414 +     * @serialData the number of characters currently stored in the string
 152.415 +     *             builder (<tt>int</tt>), followed by the characters in the
 152.416 +     *             string builder (<tt>char[]</tt>).   The length of the
 152.417 +     *             <tt>char</tt> array may be greater than the number of
 152.418 +     *             characters currently stored in the string builder, in which
 152.419 +     *             case extra characters are ignored.
 152.420 +     */
 152.421 +//    private void writeObject(java.io.ObjectOutputStream s)
 152.422 +//        throws java.io.IOException {
 152.423 +//        s.defaultWriteObject();
 152.424 +//        s.writeInt(count);
 152.425 +//        s.writeObject(value);
 152.426 +//    }
 152.427 +
 152.428 +    /**
 152.429 +     * readObject is called to restore the state of the StringBuffer from
 152.430 +     * a stream.
 152.431 +     */
 152.432 +//    private void readObject(java.io.ObjectInputStream s)
 152.433 +//        throws java.io.IOException, ClassNotFoundException {
 152.434 +//        s.defaultReadObject();
 152.435 +//        count = s.readInt();
 152.436 +//        value = (char[]) s.readObject();
 152.437 +//    }
 152.438 +
 152.439 +}
   153.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   153.2 +++ b/emul/mini/src/main/java/java/lang/StringIndexOutOfBoundsException.java	Sun Feb 03 07:48:42 2013 +0100
   153.3 @@ -0,0 +1,71 @@
   153.4 +/*
   153.5 + * Copyright (c) 1994, 2008, 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 + * Thrown by <code>String</code> methods to indicate that an index
  153.33 + * is either negative or greater than the size of the string.  For
  153.34 + * some methods such as the charAt method, this exception also is
  153.35 + * thrown when the index is equal to the size of the string.
  153.36 + *
  153.37 + * @author  unascribed
  153.38 + * @see     java.lang.String#charAt(int)
  153.39 + * @since   JDK1.0
  153.40 + */
  153.41 +public
  153.42 +class StringIndexOutOfBoundsException extends IndexOutOfBoundsException {
  153.43 +    private static final long serialVersionUID = -6762910422159637258L;
  153.44 +
  153.45 +    /**
  153.46 +     * Constructs a <code>StringIndexOutOfBoundsException</code> with no
  153.47 +     * detail message.
  153.48 +     *
  153.49 +     * @since   JDK1.0.
  153.50 +     */
  153.51 +    public StringIndexOutOfBoundsException() {
  153.52 +        super();
  153.53 +    }
  153.54 +
  153.55 +    /**
  153.56 +     * Constructs a <code>StringIndexOutOfBoundsException</code> with
  153.57 +     * the specified detail message.
  153.58 +     *
  153.59 +     * @param   s   the detail message.
  153.60 +     */
  153.61 +    public StringIndexOutOfBoundsException(String s) {
  153.62 +        super(s);
  153.63 +    }
  153.64 +
  153.65 +    /**
  153.66 +     * Constructs a new <code>StringIndexOutOfBoundsException</code>
  153.67 +     * class with an argument indicating the illegal index.
  153.68 +     *
  153.69 +     * @param   index   the illegal index.
  153.70 +     */
  153.71 +    public StringIndexOutOfBoundsException(int index) {
  153.72 +        super("String index out of range: " + index);
  153.73 +    }
  153.74 +}
   154.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   154.2 +++ b/emul/mini/src/main/java/java/lang/Throwable.java	Sun Feb 03 07:48:42 2013 +0100
   154.3 @@ -0,0 +1,1088 @@
   154.4 +/*
   154.5 + * Copyright (c) 1994, 2011, 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 +import  java.io.*;
  154.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  154.32 +import org.apidesign.bck2brwsr.core.JavaScriptOnly;
  154.33 +
  154.34 +/**
  154.35 + * The {@code Throwable} class is the superclass of all errors and
  154.36 + * exceptions in the Java language. Only objects that are instances of this
  154.37 + * class (or one of its subclasses) are thrown by the Java Virtual Machine or
  154.38 + * can be thrown by the Java {@code throw} statement. Similarly, only
  154.39 + * this class or one of its subclasses can be the argument type in a
  154.40 + * {@code catch} clause.
  154.41 + *
  154.42 + * For the purposes of compile-time checking of exceptions, {@code
  154.43 + * Throwable} and any subclass of {@code Throwable} that is not also a
  154.44 + * subclass of either {@link RuntimeException} or {@link Error} are
  154.45 + * regarded as checked exceptions.
  154.46 + *
  154.47 + * <p>Instances of two subclasses, {@link java.lang.Error} and
  154.48 + * {@link java.lang.Exception}, are conventionally used to indicate
  154.49 + * that exceptional situations have occurred. Typically, these instances
  154.50 + * are freshly created in the context of the exceptional situation so
  154.51 + * as to include relevant information (such as stack trace data).
  154.52 + *
  154.53 + * <p>A throwable contains a snapshot of the execution stack of its
  154.54 + * thread at the time it was created. It can also contain a message
  154.55 + * string that gives more information about the error. Over time, a
  154.56 + * throwable can {@linkplain Throwable#addSuppressed suppress} other
  154.57 + * throwables from being propagated.  Finally, the throwable can also
  154.58 + * contain a <i>cause</i>: another throwable that caused this
  154.59 + * throwable to be constructed.  The recording of this causal information
  154.60 + * is referred to as the <i>chained exception</i> facility, as the
  154.61 + * cause can, itself, have a cause, and so on, leading to a "chain" of
  154.62 + * exceptions, each caused by another.
  154.63 + *
  154.64 + * <p>One reason that a throwable may have a cause is that the class that
  154.65 + * throws it is built atop a lower layered abstraction, and an operation on
  154.66 + * the upper layer fails due to a failure in the lower layer.  It would be bad
  154.67 + * design to let the throwable thrown by the lower layer propagate outward, as
  154.68 + * it is generally unrelated to the abstraction provided by the upper layer.
  154.69 + * Further, doing so would tie the API of the upper layer to the details of
  154.70 + * its implementation, assuming the lower layer's exception was a checked
  154.71 + * exception.  Throwing a "wrapped exception" (i.e., an exception containing a
  154.72 + * cause) allows the upper layer to communicate the details of the failure to
  154.73 + * its caller without incurring either of these shortcomings.  It preserves
  154.74 + * the flexibility to change the implementation of the upper layer without
  154.75 + * changing its API (in particular, the set of exceptions thrown by its
  154.76 + * methods).
  154.77 + *
  154.78 + * <p>A second reason that a throwable may have a cause is that the method
  154.79 + * that throws it must conform to a general-purpose interface that does not
  154.80 + * permit the method to throw the cause directly.  For example, suppose
  154.81 + * a persistent collection conforms to the {@link java.util.Collection
  154.82 + * Collection} interface, and that its persistence is implemented atop
  154.83 + * {@code java.io}.  Suppose the internals of the {@code add} method
  154.84 + * can throw an {@link java.io.IOException IOException}.  The implementation
  154.85 + * can communicate the details of the {@code IOException} to its caller
  154.86 + * while conforming to the {@code Collection} interface by wrapping the
  154.87 + * {@code IOException} in an appropriate unchecked exception.  (The
  154.88 + * specification for the persistent collection should indicate that it is
  154.89 + * capable of throwing such exceptions.)
  154.90 + *
  154.91 + * <p>A cause can be associated with a throwable in two ways: via a
  154.92 + * constructor that takes the cause as an argument, or via the
  154.93 + * {@link #initCause(Throwable)} method.  New throwable classes that
  154.94 + * wish to allow causes to be associated with them should provide constructors
  154.95 + * that take a cause and delegate (perhaps indirectly) to one of the
  154.96 + * {@code Throwable} constructors that takes a cause.
  154.97 + *
  154.98 + * Because the {@code initCause} method is public, it allows a cause to be
  154.99 + * associated with any throwable, even a "legacy throwable" whose
 154.100 + * implementation predates the addition of the exception chaining mechanism to
 154.101 + * {@code Throwable}.
 154.102 + *
 154.103 + * <p>By convention, class {@code Throwable} and its subclasses have two
 154.104 + * constructors, one that takes no arguments and one that takes a
 154.105 + * {@code String} argument that can be used to produce a detail message.
 154.106 + * Further, those subclasses that might likely have a cause associated with
 154.107 + * them should have two more constructors, one that takes a
 154.108 + * {@code Throwable} (the cause), and one that takes a
 154.109 + * {@code String} (the detail message) and a {@code Throwable} (the
 154.110 + * cause).
 154.111 + *
 154.112 + * @author  unascribed
 154.113 + * @author  Josh Bloch (Added exception chaining and programmatic access to
 154.114 + *          stack trace in 1.4.)
 154.115 + * @jls 11.2 Compile-Time Checking of Exceptions
 154.116 + * @since JDK1.0
 154.117 + */
 154.118 +public class Throwable implements Serializable {
 154.119 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 154.120 +    private static final long serialVersionUID = -3042686055658047285L;
 154.121 +
 154.122 +    /**
 154.123 +     * Native code saves some indication of the stack backtrace in this slot.
 154.124 +     */
 154.125 +    private transient Object backtrace;
 154.126 +
 154.127 +    /**
 154.128 +     * Specific details about the Throwable.  For example, for
 154.129 +     * {@code FileNotFoundException}, this contains the name of
 154.130 +     * the file that could not be found.
 154.131 +     *
 154.132 +     * @serial
 154.133 +     */
 154.134 +    private String detailMessage;
 154.135 +
 154.136 +
 154.137 +    /**
 154.138 +     * Holder class to defer initializing sentinel objects only used
 154.139 +     * for serialization.
 154.140 +     */
 154.141 +    private static class SentinelHolder {
 154.142 +        /**
 154.143 +         * {@linkplain #setStackTrace(StackTraceElement[]) Setting the
 154.144 +         * stack trace} to a one-element array containing this sentinel
 154.145 +         * value indicates future attempts to set the stack trace will be
 154.146 +         * ignored.  The sentinal is equal to the result of calling:<br>
 154.147 +         * {@code new StackTraceElement("", "", null, Integer.MIN_VALUE)}
 154.148 +         */
 154.149 +        public static final StackTraceElement STACK_TRACE_ELEMENT_SENTINEL =
 154.150 +            new StackTraceElement("", "", null, Integer.MIN_VALUE);
 154.151 +
 154.152 +        /**
 154.153 +         * Sentinel value used in the serial form to indicate an immutable
 154.154 +         * stack trace.
 154.155 +         */
 154.156 +        public static final StackTraceElement[] STACK_TRACE_SENTINEL =
 154.157 +            new StackTraceElement[] {STACK_TRACE_ELEMENT_SENTINEL};
 154.158 +    }
 154.159 +
 154.160 +    /**
 154.161 +     * A shared value for an empty stack.
 154.162 +     */
 154.163 +    private static final StackTraceElement[] UNASSIGNED_STACK = new StackTraceElement[0];
 154.164 +
 154.165 +    /*
 154.166 +     * To allow Throwable objects to be made immutable and safely
 154.167 +     * reused by the JVM, such as OutOfMemoryErrors, fields of
 154.168 +     * Throwable that are writable in response to user actions, cause,
 154.169 +     * stackTrace, and suppressedExceptions obey the following
 154.170 +     * protocol:
 154.171 +     *
 154.172 +     * 1) The fields are initialized to a non-null sentinel value
 154.173 +     * which indicates the value has logically not been set.
 154.174 +     *
 154.175 +     * 2) Writing a null to the field indicates further writes
 154.176 +     * are forbidden
 154.177 +     *
 154.178 +     * 3) The sentinel value may be replaced with another non-null
 154.179 +     * value.
 154.180 +     *
 154.181 +     * For example, implementations of the HotSpot JVM have
 154.182 +     * preallocated OutOfMemoryError objects to provide for better
 154.183 +     * diagnosability of that situation.  These objects are created
 154.184 +     * without calling the constructor for that class and the fields
 154.185 +     * in question are initialized to null.  To support this
 154.186 +     * capability, any new fields added to Throwable that require
 154.187 +     * being initialized to a non-null value require a coordinated JVM
 154.188 +     * change.
 154.189 +     */
 154.190 +
 154.191 +    /**
 154.192 +     * The throwable that caused this throwable to get thrown, or null if this
 154.193 +     * throwable was not caused by another throwable, or if the causative
 154.194 +     * throwable is unknown.  If this field is equal to this throwable itself,
 154.195 +     * it indicates that the cause of this throwable has not yet been
 154.196 +     * initialized.
 154.197 +     *
 154.198 +     * @serial
 154.199 +     * @since 1.4
 154.200 +     */
 154.201 +    private Throwable cause = this;
 154.202 +
 154.203 +    /**
 154.204 +     * The stack trace, as returned by {@link #getStackTrace()}.
 154.205 +     *
 154.206 +     * The field is initialized to a zero-length array.  A {@code
 154.207 +     * null} value of this field indicates subsequent calls to {@link
 154.208 +     * #setStackTrace(StackTraceElement[])} and {@link
 154.209 +     * #fillInStackTrace()} will be be no-ops.
 154.210 +     *
 154.211 +     * @serial
 154.212 +     * @since 1.4
 154.213 +     */
 154.214 +    private StackTraceElement[] stackTrace = UNASSIGNED_STACK;
 154.215 +
 154.216 +    // Setting this static field introduces an acceptable
 154.217 +    // initialization dependency on a few java.util classes.
 154.218 +// I don't think this dependency is acceptable
 154.219 +//    private static final List<Throwable> SUPPRESSED_SENTINEL =
 154.220 +//        Collections.unmodifiableList(new ArrayList<Throwable>(0));
 154.221 +
 154.222 +    /**
 154.223 +     * The list of suppressed exceptions, as returned by {@link
 154.224 +     * #getSuppressed()}.  The list is initialized to a zero-element
 154.225 +     * unmodifiable sentinel list.  When a serialized Throwable is
 154.226 +     * read in, if the {@code suppressedExceptions} field points to a
 154.227 +     * zero-element list, the field is reset to the sentinel value.
 154.228 +     *
 154.229 +     * @serial
 154.230 +     * @since 1.7
 154.231 +     */
 154.232 +//    private List<Throwable> suppressedExceptions = SUPPRESSED_SENTINEL;
 154.233 +
 154.234 +    /** Message for trying to suppress a null exception. */
 154.235 +    private static final String NULL_CAUSE_MESSAGE = "Cannot suppress a null exception.";
 154.236 +
 154.237 +    /** Message for trying to suppress oneself. */
 154.238 +    private static final String SELF_SUPPRESSION_MESSAGE = "Self-suppression not permitted";
 154.239 +
 154.240 +    /** Caption  for labeling causative exception stack traces */
 154.241 +    @JavaScriptOnly(name="toString", value="function() { return this.toString__Ljava_lang_String_2().toString(); }")
 154.242 +    private static void jsToString() {
 154.243 +    }
 154.244 +    
 154.245 +    @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
 154.246 +    private static void jsValudOf() {
 154.247 +    }
 154.248 +    private static final String CAUSE_CAPTION = "Caused by: ";
 154.249 +
 154.250 +    /** Caption for labeling suppressed exception stack traces */
 154.251 +    private static final String SUPPRESSED_CAPTION = "Suppressed: ";
 154.252 +
 154.253 +    /**
 154.254 +     * Constructs a new throwable with {@code null} as its detail message.
 154.255 +     * The cause is not initialized, and may subsequently be initialized by a
 154.256 +     * call to {@link #initCause}.
 154.257 +     *
 154.258 +     * <p>The {@link #fillInStackTrace()} method is called to initialize
 154.259 +     * the stack trace data in the newly created throwable.
 154.260 +     */
 154.261 +    public Throwable() {
 154.262 +        fillInStackTrace();
 154.263 +    }
 154.264 +
 154.265 +    /**
 154.266 +     * Constructs a new throwable with the specified detail message.  The
 154.267 +     * cause is not initialized, and may subsequently be initialized by
 154.268 +     * a call to {@link #initCause}.
 154.269 +     *
 154.270 +     * <p>The {@link #fillInStackTrace()} method is called to initialize
 154.271 +     * the stack trace data in the newly created throwable.
 154.272 +     *
 154.273 +     * @param   message   the detail message. The detail message is saved for
 154.274 +     *          later retrieval by the {@link #getMessage()} method.
 154.275 +     */
 154.276 +    public Throwable(String message) {
 154.277 +        fillInStackTrace();
 154.278 +        detailMessage = message;
 154.279 +    }
 154.280 +
 154.281 +    /**
 154.282 +     * Constructs a new throwable with the specified detail message and
 154.283 +     * cause.  <p>Note that the detail message associated with
 154.284 +     * {@code cause} is <i>not</i> automatically incorporated in
 154.285 +     * this throwable's detail message.
 154.286 +     *
 154.287 +     * <p>The {@link #fillInStackTrace()} method is called to initialize
 154.288 +     * the stack trace data in the newly created throwable.
 154.289 +     *
 154.290 +     * @param  message the detail message (which is saved for later retrieval
 154.291 +     *         by the {@link #getMessage()} method).
 154.292 +     * @param  cause the cause (which is saved for later retrieval by the
 154.293 +     *         {@link #getCause()} method).  (A {@code null} value is
 154.294 +     *         permitted, and indicates that the cause is nonexistent or
 154.295 +     *         unknown.)
 154.296 +     * @since  1.4
 154.297 +     */
 154.298 +    public Throwable(String message, Throwable cause) {
 154.299 +        fillInStackTrace();
 154.300 +        detailMessage = message;
 154.301 +        this.cause = cause;
 154.302 +    }
 154.303 +
 154.304 +    /**
 154.305 +     * Constructs a new throwable with the specified cause and a detail
 154.306 +     * message of {@code (cause==null ? null : cause.toString())} (which
 154.307 +     * typically contains the class and detail message of {@code cause}).
 154.308 +     * This constructor is useful for throwables that are little more than
 154.309 +     * wrappers for other throwables (for example, {@link
 154.310 +     * java.security.PrivilegedActionException}).
 154.311 +     *
 154.312 +     * <p>The {@link #fillInStackTrace()} method is called to initialize
 154.313 +     * the stack trace data in the newly created throwable.
 154.314 +     *
 154.315 +     * @param  cause the cause (which is saved for later retrieval by the
 154.316 +     *         {@link #getCause()} method).  (A {@code null} value is
 154.317 +     *         permitted, and indicates that the cause is nonexistent or
 154.318 +     *         unknown.)
 154.319 +     * @since  1.4
 154.320 +     */
 154.321 +    public Throwable(Throwable cause) {
 154.322 +        fillInStackTrace();
 154.323 +        detailMessage = (cause==null ? null : cause.toString());
 154.324 +        this.cause = cause;
 154.325 +    }
 154.326 +
 154.327 +    /**
 154.328 +     * Constructs a new throwable with the specified detail message,
 154.329 +     * cause, {@linkplain #addSuppressed suppression} enabled or
 154.330 +     * disabled, and writable stack trace enabled or disabled.  If
 154.331 +     * suppression is disabled, {@link #getSuppressed} for this object
 154.332 +     * will return a zero-length array and calls to {@link
 154.333 +     * #addSuppressed} that would otherwise append an exception to the
 154.334 +     * suppressed list will have no effect.  If the writable stack
 154.335 +     * trace is false, this constructor will not call {@link
 154.336 +     * #fillInStackTrace()}, a {@code null} will be written to the
 154.337 +     * {@code stackTrace} field, and subsequent calls to {@code
 154.338 +     * fillInStackTrace} and {@link
 154.339 +     * #setStackTrace(StackTraceElement[])} will not set the stack
 154.340 +     * trace.  If the writable stack trace is false, {@link
 154.341 +     * #getStackTrace} will return a zero length array.
 154.342 +     *
 154.343 +     * <p>Note that the other constructors of {@code Throwable} treat
 154.344 +     * suppression as being enabled and the stack trace as being
 154.345 +     * writable.  Subclasses of {@code Throwable} should document any
 154.346 +     * conditions under which suppression is disabled and document
 154.347 +     * conditions under which the stack trace is not writable.
 154.348 +     * Disabling of suppression should only occur in exceptional
 154.349 +     * circumstances where special requirements exist, such as a
 154.350 +     * virtual machine reusing exception objects under low-memory
 154.351 +     * situations.  Circumstances where a given exception object is
 154.352 +     * repeatedly caught and rethrown, such as to implement control
 154.353 +     * flow between two sub-systems, is another situation where
 154.354 +     * immutable throwable objects would be appropriate.
 154.355 +     *
 154.356 +     * @param  message the detail message.
 154.357 +     * @param cause the cause.  (A {@code null} value is permitted,
 154.358 +     * and indicates that the cause is nonexistent or unknown.)
 154.359 +     * @param enableSuppression whether or not suppression is enabled or disabled
 154.360 +     * @param writableStackTrace whether or not the stack trace should be
 154.361 +     *                           writable
 154.362 +     *
 154.363 +     * @see OutOfMemoryError
 154.364 +     * @see NullPointerException
 154.365 +     * @see ArithmeticException
 154.366 +     * @since 1.7
 154.367 +     */
 154.368 +    protected Throwable(String message, Throwable cause,
 154.369 +                        boolean enableSuppression,
 154.370 +                        boolean writableStackTrace) {
 154.371 +        if (writableStackTrace) {
 154.372 +            fillInStackTrace();
 154.373 +        } else {
 154.374 +            stackTrace = null;
 154.375 +        }
 154.376 +        detailMessage = message;
 154.377 +        this.cause = cause;
 154.378 +//        if (!enableSuppression)
 154.379 +//            suppressedExceptions = null;
 154.380 +    }
 154.381 +
 154.382 +    /**
 154.383 +     * Returns the detail message string of this throwable.
 154.384 +     *
 154.385 +     * @return  the detail message string of this {@code Throwable} instance
 154.386 +     *          (which may be {@code null}).
 154.387 +     */
 154.388 +    public String getMessage() {
 154.389 +        return detailMessage;
 154.390 +    }
 154.391 +
 154.392 +    /**
 154.393 +     * Creates a localized description of this throwable.
 154.394 +     * Subclasses may override this method in order to produce a
 154.395 +     * locale-specific message.  For subclasses that do not override this
 154.396 +     * method, the default implementation returns the same result as
 154.397 +     * {@code getMessage()}.
 154.398 +     *
 154.399 +     * @return  The localized description of this throwable.
 154.400 +     * @since   JDK1.1
 154.401 +     */
 154.402 +    public String getLocalizedMessage() {
 154.403 +        return getMessage();
 154.404 +    }
 154.405 +
 154.406 +    /**
 154.407 +     * Returns the cause of this throwable or {@code null} if the
 154.408 +     * cause is nonexistent or unknown.  (The cause is the throwable that
 154.409 +     * caused this throwable to get thrown.)
 154.410 +     *
 154.411 +     * <p>This implementation returns the cause that was supplied via one of
 154.412 +     * the constructors requiring a {@code Throwable}, or that was set after
 154.413 +     * creation with the {@link #initCause(Throwable)} method.  While it is
 154.414 +     * typically unnecessary to override this method, a subclass can override
 154.415 +     * it to return a cause set by some other means.  This is appropriate for
 154.416 +     * a "legacy chained throwable" that predates the addition of chained
 154.417 +     * exceptions to {@code Throwable}.  Note that it is <i>not</i>
 154.418 +     * necessary to override any of the {@code PrintStackTrace} methods,
 154.419 +     * all of which invoke the {@code getCause} method to determine the
 154.420 +     * cause of a throwable.
 154.421 +     *
 154.422 +     * @return  the cause of this throwable or {@code null} if the
 154.423 +     *          cause is nonexistent or unknown.
 154.424 +     * @since 1.4
 154.425 +     */
 154.426 +    public synchronized Throwable getCause() {
 154.427 +        return (cause==this ? null : cause);
 154.428 +    }
 154.429 +
 154.430 +    /**
 154.431 +     * Initializes the <i>cause</i> of this throwable to the specified value.
 154.432 +     * (The cause is the throwable that caused this throwable to get thrown.)
 154.433 +     *
 154.434 +     * <p>This method can be called at most once.  It is generally called from
 154.435 +     * within the constructor, or immediately after creating the
 154.436 +     * throwable.  If this throwable was created
 154.437 +     * with {@link #Throwable(Throwable)} or
 154.438 +     * {@link #Throwable(String,Throwable)}, this method cannot be called
 154.439 +     * even once.
 154.440 +     *
 154.441 +     * <p>An example of using this method on a legacy throwable type
 154.442 +     * without other support for setting the cause is:
 154.443 +     *
 154.444 +     * <pre>
 154.445 +     * try {
 154.446 +     *     lowLevelOp();
 154.447 +     * } catch (LowLevelException le) {
 154.448 +     *     throw (HighLevelException)
 154.449 +     *           new HighLevelException().initCause(le); // Legacy constructor
 154.450 +     * }
 154.451 +     * </pre>
 154.452 +     *
 154.453 +     * @param  cause the cause (which is saved for later retrieval by the
 154.454 +     *         {@link #getCause()} method).  (A {@code null} value is
 154.455 +     *         permitted, and indicates that the cause is nonexistent or
 154.456 +     *         unknown.)
 154.457 +     * @return  a reference to this {@code Throwable} instance.
 154.458 +     * @throws IllegalArgumentException if {@code cause} is this
 154.459 +     *         throwable.  (A throwable cannot be its own cause.)
 154.460 +     * @throws IllegalStateException if this throwable was
 154.461 +     *         created with {@link #Throwable(Throwable)} or
 154.462 +     *         {@link #Throwable(String,Throwable)}, or this method has already
 154.463 +     *         been called on this throwable.
 154.464 +     * @since  1.4
 154.465 +     */
 154.466 +    public synchronized Throwable initCause(Throwable cause) {
 154.467 +        if (this.cause != this)
 154.468 +            throw new IllegalStateException("Can't overwrite cause");
 154.469 +        if (cause == this)
 154.470 +            throw new IllegalArgumentException("Self-causation not permitted");
 154.471 +        this.cause = cause;
 154.472 +        return this;
 154.473 +    }
 154.474 +
 154.475 +    /**
 154.476 +     * Returns a short description of this throwable.
 154.477 +     * The result is the concatenation of:
 154.478 +     * <ul>
 154.479 +     * <li> the {@linkplain Class#getName() name} of the class of this object
 154.480 +     * <li> ": " (a colon and a space)
 154.481 +     * <li> the result of invoking this object's {@link #getLocalizedMessage}
 154.482 +     *      method
 154.483 +     * </ul>
 154.484 +     * If {@code getLocalizedMessage} returns {@code null}, then just
 154.485 +     * the class name is returned.
 154.486 +     *
 154.487 +     * @return a string representation of this throwable.
 154.488 +     */
 154.489 +    public String toString() {
 154.490 +        String s = getClass().getName();
 154.491 +        String message = getLocalizedMessage();
 154.492 +        return (message != null) ? (s + ": " + message) : s;
 154.493 +    }
 154.494 +
 154.495 +    /**
 154.496 +     * Prints this throwable and its backtrace to the
 154.497 +     * standard error stream. This method prints a stack trace for this
 154.498 +     * {@code Throwable} object on the error output stream that is
 154.499 +     * the value of the field {@code System.err}. The first line of
 154.500 +     * output contains the result of the {@link #toString()} method for
 154.501 +     * this object.  Remaining lines represent data previously recorded by
 154.502 +     * the method {@link #fillInStackTrace()}. The format of this
 154.503 +     * information depends on the implementation, but the following
 154.504 +     * example may be regarded as typical:
 154.505 +     * <blockquote><pre>
 154.506 +     * java.lang.NullPointerException
 154.507 +     *         at MyClass.mash(MyClass.java:9)
 154.508 +     *         at MyClass.crunch(MyClass.java:6)
 154.509 +     *         at MyClass.main(MyClass.java:3)
 154.510 +     * </pre></blockquote>
 154.511 +     * This example was produced by running the program:
 154.512 +     * <pre>
 154.513 +     * class MyClass {
 154.514 +     *     public static void main(String[] args) {
 154.515 +     *         crunch(null);
 154.516 +     *     }
 154.517 +     *     static void crunch(int[] a) {
 154.518 +     *         mash(a);
 154.519 +     *     }
 154.520 +     *     static void mash(int[] b) {
 154.521 +     *         System.out.println(b[0]);
 154.522 +     *     }
 154.523 +     * }
 154.524 +     * </pre>
 154.525 +     * The backtrace for a throwable with an initialized, non-null cause
 154.526 +     * should generally include the backtrace for the cause.  The format
 154.527 +     * of this information depends on the implementation, but the following
 154.528 +     * example may be regarded as typical:
 154.529 +     * <pre>
 154.530 +     * HighLevelException: MidLevelException: LowLevelException
 154.531 +     *         at Junk.a(Junk.java:13)
 154.532 +     *         at Junk.main(Junk.java:4)
 154.533 +     * Caused by: MidLevelException: LowLevelException
 154.534 +     *         at Junk.c(Junk.java:23)
 154.535 +     *         at Junk.b(Junk.java:17)
 154.536 +     *         at Junk.a(Junk.java:11)
 154.537 +     *         ... 1 more
 154.538 +     * Caused by: LowLevelException
 154.539 +     *         at Junk.e(Junk.java:30)
 154.540 +     *         at Junk.d(Junk.java:27)
 154.541 +     *         at Junk.c(Junk.java:21)
 154.542 +     *         ... 3 more
 154.543 +     * </pre>
 154.544 +     * Note the presence of lines containing the characters {@code "..."}.
 154.545 +     * These lines indicate that the remainder of the stack trace for this
 154.546 +     * exception matches the indicated number of frames from the bottom of the
 154.547 +     * stack trace of the exception that was caused by this exception (the
 154.548 +     * "enclosing" exception).  This shorthand can greatly reduce the length
 154.549 +     * of the output in the common case where a wrapped exception is thrown
 154.550 +     * from same method as the "causative exception" is caught.  The above
 154.551 +     * example was produced by running the program:
 154.552 +     * <pre>
 154.553 +     * public class Junk {
 154.554 +     *     public static void main(String args[]) {
 154.555 +     *         try {
 154.556 +     *             a();
 154.557 +     *         } catch(HighLevelException e) {
 154.558 +     *             e.printStackTrace();
 154.559 +     *         }
 154.560 +     *     }
 154.561 +     *     static void a() throws HighLevelException {
 154.562 +     *         try {
 154.563 +     *             b();
 154.564 +     *         } catch(MidLevelException e) {
 154.565 +     *             throw new HighLevelException(e);
 154.566 +     *         }
 154.567 +     *     }
 154.568 +     *     static void b() throws MidLevelException {
 154.569 +     *         c();
 154.570 +     *     }
 154.571 +     *     static void c() throws MidLevelException {
 154.572 +     *         try {
 154.573 +     *             d();
 154.574 +     *         } catch(LowLevelException e) {
 154.575 +     *             throw new MidLevelException(e);
 154.576 +     *         }
 154.577 +     *     }
 154.578 +     *     static void d() throws LowLevelException {
 154.579 +     *        e();
 154.580 +     *     }
 154.581 +     *     static void e() throws LowLevelException {
 154.582 +     *         throw new LowLevelException();
 154.583 +     *     }
 154.584 +     * }
 154.585 +     *
 154.586 +     * class HighLevelException extends Exception {
 154.587 +     *     HighLevelException(Throwable cause) { super(cause); }
 154.588 +     * }
 154.589 +     *
 154.590 +     * class MidLevelException extends Exception {
 154.591 +     *     MidLevelException(Throwable cause)  { super(cause); }
 154.592 +     * }
 154.593 +     *
 154.594 +     * class LowLevelException extends Exception {
 154.595 +     * }
 154.596 +     * </pre>
 154.597 +     * As of release 7, the platform supports the notion of
 154.598 +     * <i>suppressed exceptions</i> (in conjunction with the {@code
 154.599 +     * try}-with-resources statement). Any exceptions that were
 154.600 +     * suppressed in order to deliver an exception are printed out
 154.601 +     * beneath the stack trace.  The format of this information
 154.602 +     * depends on the implementation, but the following example may be
 154.603 +     * regarded as typical:
 154.604 +     *
 154.605 +     * <pre>
 154.606 +     * Exception in thread "main" java.lang.Exception: Something happened
 154.607 +     *  at Foo.bar(Foo.java:10)
 154.608 +     *  at Foo.main(Foo.java:5)
 154.609 +     *  Suppressed: Resource$CloseFailException: Resource ID = 0
 154.610 +     *          at Resource.close(Resource.java:26)
 154.611 +     *          at Foo.bar(Foo.java:9)
 154.612 +     *          ... 1 more
 154.613 +     * </pre>
 154.614 +     * Note that the "... n more" notation is used on suppressed exceptions
 154.615 +     * just at it is used on causes. Unlike causes, suppressed exceptions are
 154.616 +     * indented beyond their "containing exceptions."
 154.617 +     *
 154.618 +     * <p>An exception can have both a cause and one or more suppressed
 154.619 +     * exceptions:
 154.620 +     * <pre>
 154.621 +     * Exception in thread "main" java.lang.Exception: Main block
 154.622 +     *  at Foo3.main(Foo3.java:7)
 154.623 +     *  Suppressed: Resource$CloseFailException: Resource ID = 2
 154.624 +     *          at Resource.close(Resource.java:26)
 154.625 +     *          at Foo3.main(Foo3.java:5)
 154.626 +     *  Suppressed: Resource$CloseFailException: Resource ID = 1
 154.627 +     *          at Resource.close(Resource.java:26)
 154.628 +     *          at Foo3.main(Foo3.java:5)
 154.629 +     * Caused by: java.lang.Exception: I did it
 154.630 +     *  at Foo3.main(Foo3.java:8)
 154.631 +     * </pre>
 154.632 +     * Likewise, a suppressed exception can have a cause:
 154.633 +     * <pre>
 154.634 +     * Exception in thread "main" java.lang.Exception: Main block
 154.635 +     *  at Foo4.main(Foo4.java:6)
 154.636 +     *  Suppressed: Resource2$CloseFailException: Resource ID = 1
 154.637 +     *          at Resource2.close(Resource2.java:20)
 154.638 +     *          at Foo4.main(Foo4.java:5)
 154.639 +     *  Caused by: java.lang.Exception: Rats, you caught me
 154.640 +     *          at Resource2$CloseFailException.<init>(Resource2.java:45)
 154.641 +     *          ... 2 more
 154.642 +     * </pre>
 154.643 +     */
 154.644 +//    public void printStackTrace() {
 154.645 +//        printStackTrace(System.err);
 154.646 +//    }
 154.647 +//
 154.648 +//    /**
 154.649 +//     * Prints this throwable and its backtrace to the specified print stream.
 154.650 +//     *
 154.651 +//     * @param s {@code PrintStream} to use for output
 154.652 +//     */
 154.653 +//    public void printStackTrace(PrintStream s) {
 154.654 +//        printStackTrace(new WrappedPrintStream(s));
 154.655 +//    }
 154.656 +//
 154.657 +//    private void printStackTrace(PrintStreamOrWriter s) {
 154.658 +//        // Guard against malicious overrides of Throwable.equals by
 154.659 +//        // using a Set with identity equality semantics.
 154.660 +////        Set<Throwable> dejaVu =
 154.661 +////            Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
 154.662 +////        dejaVu.add(this);
 154.663 +//
 154.664 +//        synchronized (s.lock()) {
 154.665 +//            // Print our stack trace
 154.666 +//            s.println(this);
 154.667 +//            StackTraceElement[] trace = getOurStackTrace();
 154.668 +//            for (StackTraceElement traceElement : trace)
 154.669 +//                s.println("\tat " + traceElement);
 154.670 +//
 154.671 +//            // Print suppressed exceptions, if any
 154.672 +////            for (Throwable se : getSuppressed())
 154.673 +////                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
 154.674 +//
 154.675 +//            // Print cause, if any
 154.676 +//            Throwable ourCause = getCause();
 154.677 +////            if (ourCause != null)
 154.678 +////                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
 154.679 +//        }
 154.680 +//    }
 154.681 +//
 154.682 +//    /**
 154.683 +//     * Print our stack trace as an enclosed exception for the specified
 154.684 +//     * stack trace.
 154.685 +//     */
 154.686 +//    private void printEnclosedStackTrace(PrintStreamOrWriter s,
 154.687 +//                                         StackTraceElement[] enclosingTrace,
 154.688 +//                                         String caption,
 154.689 +//                                         String prefix,
 154.690 +//                                         Object dejaVu) {
 154.691 +//        assert Thread.holdsLock(s.lock());
 154.692 +//        {
 154.693 +//            // Compute number of frames in common between this and enclosing trace
 154.694 +//            StackTraceElement[] trace = getOurStackTrace();
 154.695 +//            int m = trace.length - 1;
 154.696 +//            int n = enclosingTrace.length - 1;
 154.697 +//            while (m >= 0 && n >=0 && trace[m].equals(enclosingTrace[n])) {
 154.698 +//                m--; n--;
 154.699 +//            }
 154.700 +//            int framesInCommon = trace.length - 1 - m;
 154.701 +//
 154.702 +//            // Print our stack trace
 154.703 +//            s.println(prefix + caption + this);
 154.704 +//            for (int i = 0; i <= m; i++)
 154.705 +//                s.println(prefix + "\tat " + trace[i]);
 154.706 +//            if (framesInCommon != 0)
 154.707 +//                s.println(prefix + "\t... " + framesInCommon + " more");
 154.708 +//
 154.709 +//            // Print suppressed exceptions, if any
 154.710 +//            for (Throwable se : getSuppressed())
 154.711 +//                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION,
 154.712 +//                                           prefix +"\t", dejaVu);
 154.713 +//
 154.714 +//            // Print cause, if any
 154.715 +//            Throwable ourCause = getCause();
 154.716 +//            if (ourCause != null)
 154.717 +//                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, prefix, dejaVu);
 154.718 +//        }
 154.719 +//    }
 154.720 +//
 154.721 +//    /**
 154.722 +//     * Prints this throwable and its backtrace to the specified
 154.723 +//     * print writer.
 154.724 +//     *
 154.725 +//     * @param s {@code PrintWriter} to use for output
 154.726 +//     * @since   JDK1.1
 154.727 +//     */
 154.728 +//    public void printStackTrace(PrintWriter s) {
 154.729 +//        printStackTrace(new WrappedPrintWriter(s));
 154.730 +//    }
 154.731 +//
 154.732 +//    /**
 154.733 +//     * Wrapper class for PrintStream and PrintWriter to enable a single
 154.734 +//     * implementation of printStackTrace.
 154.735 +//     */
 154.736 +//    private abstract static class PrintStreamOrWriter {
 154.737 +//        /** Returns the object to be locked when using this StreamOrWriter */
 154.738 +//        abstract Object lock();
 154.739 +//
 154.740 +//        /** Prints the specified string as a line on this StreamOrWriter */
 154.741 +//        abstract void println(Object o);
 154.742 +//    }
 154.743 +//
 154.744 +//    private static class WrappedPrintStream extends PrintStreamOrWriter {
 154.745 +//        private final PrintStream printStream;
 154.746 +//
 154.747 +//        WrappedPrintStream(PrintStream printStream) {
 154.748 +//            this.printStream = printStream;
 154.749 +//        }
 154.750 +//
 154.751 +//        Object lock() {
 154.752 +//            return printStream;
 154.753 +//        }
 154.754 +//
 154.755 +//        void println(Object o) {
 154.756 +//            printStream.println(o);
 154.757 +//        }
 154.758 +//    }
 154.759 +//
 154.760 +//    private static class WrappedPrintWriter extends PrintStreamOrWriter {
 154.761 +//        private final PrintWriter printWriter;
 154.762 +//
 154.763 +//        WrappedPrintWriter(PrintWriter printWriter) {
 154.764 +//            this.printWriter = printWriter;
 154.765 +//        }
 154.766 +//
 154.767 +//        Object lock() {
 154.768 +//            return printWriter;
 154.769 +//        }
 154.770 +//
 154.771 +//        void println(Object o) {
 154.772 +//            printWriter.println(o);
 154.773 +//        }
 154.774 +//    }
 154.775 +
 154.776 +    /**
 154.777 +     * Fills in the execution stack trace. This method records within this
 154.778 +     * {@code Throwable} object information about the current state of
 154.779 +     * the stack frames for the current thread.
 154.780 +     *
 154.781 +     * <p>If the stack trace of this {@code Throwable} {@linkplain
 154.782 +     * Throwable#Throwable(String, Throwable, boolean, boolean) is not
 154.783 +     * writable}, calling this method has no effect.
 154.784 +     *
 154.785 +     * @return  a reference to this {@code Throwable} instance.
 154.786 +     * @see     java.lang.Throwable#printStackTrace()
 154.787 +     */
 154.788 +    public synchronized Throwable fillInStackTrace() {
 154.789 +        if (stackTrace != null ||
 154.790 +            backtrace != null /* Out of protocol state */ ) {
 154.791 +            fillInStackTrace(0);
 154.792 +            stackTrace = UNASSIGNED_STACK;
 154.793 +        }
 154.794 +        return this;
 154.795 +    }
 154.796 +
 154.797 +    @JavaScriptBody(args = { "dummy" }, body = "")
 154.798 +    private native Throwable fillInStackTrace(int dummy);
 154.799 +
 154.800 +    /**
 154.801 +     * Provides programmatic access to the stack trace information printed by
 154.802 +     * {@link #printStackTrace()}.  Returns an array of stack trace elements,
 154.803 +     * each representing one stack frame.  The zeroth element of the array
 154.804 +     * (assuming the array's length is non-zero) represents the top of the
 154.805 +     * stack, which is the last method invocation in the sequence.  Typically,
 154.806 +     * this is the point at which this throwable was created and thrown.
 154.807 +     * The last element of the array (assuming the array's length is non-zero)
 154.808 +     * represents the bottom of the stack, which is the first method invocation
 154.809 +     * in the sequence.
 154.810 +     *
 154.811 +     * <p>Some virtual machines may, under some circumstances, omit one
 154.812 +     * or more stack frames from the stack trace.  In the extreme case,
 154.813 +     * a virtual machine that has no stack trace information concerning
 154.814 +     * this throwable is permitted to return a zero-length array from this
 154.815 +     * method.  Generally speaking, the array returned by this method will
 154.816 +     * contain one element for every frame that would be printed by
 154.817 +     * {@code printStackTrace}.  Writes to the returned array do not
 154.818 +     * affect future calls to this method.
 154.819 +     *
 154.820 +     * @return an array of stack trace elements representing the stack trace
 154.821 +     *         pertaining to this throwable.
 154.822 +     * @since  1.4
 154.823 +     */
 154.824 +    public StackTraceElement[] getStackTrace() {
 154.825 +        return getOurStackTrace().clone();
 154.826 +    }
 154.827 +
 154.828 +    private synchronized StackTraceElement[] getOurStackTrace() {
 154.829 +        // Initialize stack trace field with information from
 154.830 +        // backtrace if this is the first call to this method
 154.831 +        if (stackTrace == UNASSIGNED_STACK ||
 154.832 +            (stackTrace == null && backtrace != null) /* Out of protocol state */) {
 154.833 +            int depth = getStackTraceDepth();
 154.834 +            stackTrace = new StackTraceElement[depth];
 154.835 +            for (int i=0; i < depth; i++)
 154.836 +                stackTrace[i] = getStackTraceElement(i);
 154.837 +        } else if (stackTrace == null) {
 154.838 +            return UNASSIGNED_STACK;
 154.839 +        }
 154.840 +        return stackTrace;
 154.841 +    }
 154.842 +
 154.843 +    /**
 154.844 +     * Sets the stack trace elements that will be returned by
 154.845 +     * {@link #getStackTrace()} and printed by {@link #printStackTrace()}
 154.846 +     * and related methods.
 154.847 +     *
 154.848 +     * This method, which is designed for use by RPC frameworks and other
 154.849 +     * advanced systems, allows the client to override the default
 154.850 +     * stack trace that is either generated by {@link #fillInStackTrace()}
 154.851 +     * when a throwable is constructed or deserialized when a throwable is
 154.852 +     * read from a serialization stream.
 154.853 +     *
 154.854 +     * <p>If the stack trace of this {@code Throwable} {@linkplain
 154.855 +     * Throwable#Throwable(String, Throwable, boolean, boolean) is not
 154.856 +     * writable}, calling this method has no effect other than
 154.857 +     * validating its argument.
 154.858 +     *
 154.859 +     * @param   stackTrace the stack trace elements to be associated with
 154.860 +     * this {@code Throwable}.  The specified array is copied by this
 154.861 +     * call; changes in the specified array after the method invocation
 154.862 +     * returns will have no affect on this {@code Throwable}'s stack
 154.863 +     * trace.
 154.864 +     *
 154.865 +     * @throws NullPointerException if {@code stackTrace} is
 154.866 +     *         {@code null} or if any of the elements of
 154.867 +     *         {@code stackTrace} are {@code null}
 154.868 +     *
 154.869 +     * @since  1.4
 154.870 +     */
 154.871 +    public void setStackTrace(StackTraceElement[] stackTrace) {
 154.872 +        // Validate argument
 154.873 +        StackTraceElement[] defensiveCopy = stackTrace.clone();
 154.874 +        for (int i = 0; i < defensiveCopy.length; i++) {
 154.875 +            if (defensiveCopy[i] == null)
 154.876 +                throw new NullPointerException("stackTrace[" + i + "]");
 154.877 +        }
 154.878 +
 154.879 +        synchronized (this) {
 154.880 +            if (this.stackTrace == null && // Immutable stack
 154.881 +                backtrace == null) // Test for out of protocol state
 154.882 +                return;
 154.883 +            this.stackTrace = defensiveCopy;
 154.884 +        }
 154.885 +    }
 154.886 +
 154.887 +    /**
 154.888 +     * Returns the number of elements in the stack trace (or 0 if the stack
 154.889 +     * trace is unavailable).
 154.890 +     *
 154.891 +     * package-protection for use by SharedSecrets.
 154.892 +     */
 154.893 +    native int getStackTraceDepth();
 154.894 +
 154.895 +    /**
 154.896 +     * Returns the specified element of the stack trace.
 154.897 +     *
 154.898 +     * package-protection for use by SharedSecrets.
 154.899 +     *
 154.900 +     * @param index index of the element to return.
 154.901 +     * @throws IndexOutOfBoundsException if {@code index < 0 ||
 154.902 +     *         index >= getStackTraceDepth() }
 154.903 +     */
 154.904 +    native StackTraceElement getStackTraceElement(int index);
 154.905 +
 154.906 +    /**
 154.907 +     * Reads a {@code Throwable} from a stream, enforcing
 154.908 +     * well-formedness constraints on fields.  Null entries and
 154.909 +     * self-pointers are not allowed in the list of {@code
 154.910 +     * suppressedExceptions}.  Null entries are not allowed for stack
 154.911 +     * trace elements.  A null stack trace in the serial form results
 154.912 +     * in a zero-length stack element array. A single-element stack
 154.913 +     * trace whose entry is equal to {@code new StackTraceElement("",
 154.914 +     * "", null, Integer.MIN_VALUE)} results in a {@code null} {@code
 154.915 +     * stackTrace} field.
 154.916 +     *
 154.917 +     * Note that there are no constraints on the value the {@code
 154.918 +     * cause} field can hold; both {@code null} and {@code this} are
 154.919 +     * valid values for the field.
 154.920 +     */
 154.921 +//    private void readObject(ObjectInputStream s)
 154.922 +//        throws IOException, ClassNotFoundException {
 154.923 +//        s.defaultReadObject();     // read in all fields
 154.924 +//        if (suppressedExceptions != null) {
 154.925 +//            List<Throwable> suppressed = null;
 154.926 +//            if (suppressedExceptions.isEmpty()) {
 154.927 +//                // Use the sentinel for a zero-length list
 154.928 +//                suppressed = SUPPRESSED_SENTINEL;
 154.929 +//            } else { // Copy Throwables to new list
 154.930 +//                suppressed = new ArrayList<Throwable>(1);
 154.931 +//                for (Throwable t : suppressedExceptions) {
 154.932 +//                    // Enforce constraints on suppressed exceptions in
 154.933 +//                    // case of corrupt or malicious stream.
 154.934 +//                    if (t == null)
 154.935 +//                        throw new NullPointerException(NULL_CAUSE_MESSAGE);
 154.936 +//                    if (t == this)
 154.937 +//                        throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
 154.938 +//                    suppressed.add(t);
 154.939 +//                }
 154.940 +//            }
 154.941 +//            suppressedExceptions = suppressed;
 154.942 +//        } // else a null suppressedExceptions field remains null
 154.943 +//
 154.944 +//        /*
 154.945 +//         * For zero-length stack traces, use a clone of
 154.946 +//         * UNASSIGNED_STACK rather than UNASSIGNED_STACK itself to
 154.947 +//         * allow identity comparison against UNASSIGNED_STACK in
 154.948 +//         * getOurStackTrace.  The identity of UNASSIGNED_STACK in
 154.949 +//         * stackTrace indicates to the getOurStackTrace method that
 154.950 +//         * the stackTrace needs to be constructed from the information
 154.951 +//         * in backtrace.
 154.952 +//         */
 154.953 +//        if (stackTrace != null) {
 154.954 +//            if (stackTrace.length == 0) {
 154.955 +//                stackTrace = UNASSIGNED_STACK.clone();
 154.956 +//            }  else if (stackTrace.length == 1 &&
 154.957 +//                        // Check for the marker of an immutable stack trace
 154.958 +//                        SentinelHolder.STACK_TRACE_ELEMENT_SENTINEL.equals(stackTrace[0])) {
 154.959 +//                stackTrace = null;
 154.960 +//            } else { // Verify stack trace elements are non-null.
 154.961 +//                for(StackTraceElement ste : stackTrace) {
 154.962 +//                    if (ste == null)
 154.963 +//                        throw new NullPointerException("null StackTraceElement in serial stream. ");
 154.964 +//                }
 154.965 +//            }
 154.966 +//        } else {
 154.967 +//            // A null stackTrace field in the serial form can result
 154.968 +//            // from an exception serialized without that field in
 154.969 +//            // older JDK releases; treat such exceptions as having
 154.970 +//            // empty stack traces.
 154.971 +//            stackTrace = UNASSIGNED_STACK.clone();
 154.972 +//        }
 154.973 +//    }
 154.974 +
 154.975 +    /**
 154.976 +     * Write a {@code Throwable} object to a stream.
 154.977 +     *
 154.978 +     * A {@code null} stack trace field is represented in the serial
 154.979 +     * form as a one-element array whose element is equal to {@code
 154.980 +     * new StackTraceElement("", "", null, Integer.MIN_VALUE)}.
 154.981 +     */
 154.982 +//    private synchronized void writeObject(ObjectOutputStream s)
 154.983 +//        throws IOException {
 154.984 +//        // Ensure that the stackTrace field is initialized to a
 154.985 +//        // non-null value, if appropriate.  As of JDK 7, a null stack
 154.986 +//        // trace field is a valid value indicating the stack trace
 154.987 +//        // should not be set.
 154.988 +//        getOurStackTrace();
 154.989 +//
 154.990 +//        StackTraceElement[] oldStackTrace = stackTrace;
 154.991 +//        try {
 154.992 +//            if (stackTrace == null)
 154.993 +//                stackTrace = SentinelHolder.STACK_TRACE_SENTINEL;
 154.994 +//            s.defaultWriteObject();
 154.995 +//        } finally {
 154.996 +//            stackTrace = oldStackTrace;
 154.997 +//        }
 154.998 +//    }
 154.999 +
154.1000 +    /**
154.1001 +     * Appends the specified exception to the exceptions that were
154.1002 +     * suppressed in order to deliver this exception. This method is
154.1003 +     * thread-safe and typically called (automatically and implicitly)
154.1004 +     * by the {@code try}-with-resources statement.
154.1005 +     *
154.1006 +     * <p>The suppression behavior is enabled <em>unless</em> disabled
154.1007 +     * {@linkplain #Throwable(String, Throwable, boolean, boolean) via
154.1008 +     * a constructor}.  When suppression is disabled, this method does
154.1009 +     * nothing other than to validate its argument.
154.1010 +     *
154.1011 +     * <p>Note that when one exception {@linkplain
154.1012 +     * #initCause(Throwable) causes} another exception, the first
154.1013 +     * exception is usually caught and then the second exception is
154.1014 +     * thrown in response.  In other words, there is a causal
154.1015 +     * connection between the two exceptions.
154.1016 +     *
154.1017 +     * In contrast, there are situations where two independent
154.1018 +     * exceptions can be thrown in sibling code blocks, in particular
154.1019 +     * in the {@code try} block of a {@code try}-with-resources
154.1020 +     * statement and the compiler-generated {@code finally} block
154.1021 +     * which closes the resource.
154.1022 +     *
154.1023 +     * In these situations, only one of the thrown exceptions can be
154.1024 +     * propagated.  In the {@code try}-with-resources statement, when
154.1025 +     * there are two such exceptions, the exception originating from
154.1026 +     * the {@code try} block is propagated and the exception from the
154.1027 +     * {@code finally} block is added to the list of exceptions
154.1028 +     * suppressed by the exception from the {@code try} block.  As an
154.1029 +     * exception unwinds the stack, it can accumulate multiple
154.1030 +     * suppressed exceptions.
154.1031 +     *
154.1032 +     * <p>An exception may have suppressed exceptions while also being
154.1033 +     * caused by another exception.  Whether or not an exception has a
154.1034 +     * cause is semantically known at the time of its creation, unlike
154.1035 +     * whether or not an exception will suppress other exceptions
154.1036 +     * which is typically only determined after an exception is
154.1037 +     * thrown.
154.1038 +     *
154.1039 +     * <p>Note that programmer written code is also able to take
154.1040 +     * advantage of calling this method in situations where there are
154.1041 +     * multiple sibling exceptions and only one can be propagated.
154.1042 +     *
154.1043 +     * @param exception the exception to be added to the list of
154.1044 +     *        suppressed exceptions
154.1045 +     * @throws IllegalArgumentException if {@code exception} is this
154.1046 +     *         throwable; a throwable cannot suppress itself.
154.1047 +     * @throws NullPointerException if {@code exception} is {@code null}
154.1048 +     * @since 1.7
154.1049 +     */
154.1050 +    public final synchronized void addSuppressed(Throwable exception) {
154.1051 +        if (exception == this)
154.1052 +            throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
154.1053 +
154.1054 +        if (exception == null)
154.1055 +            throw new NullPointerException(NULL_CAUSE_MESSAGE);
154.1056 +
154.1057 +//        if (suppressedExceptions == null) // Suppressed exceptions not recorded
154.1058 +//            return;
154.1059 +//
154.1060 +//        if (suppressedExceptions == SUPPRESSED_SENTINEL)
154.1061 +//            suppressedExceptions = new ArrayList<Throwable>(1);
154.1062 +//
154.1063 +//        suppressedExceptions.add(exception);
154.1064 +    }
154.1065 +
154.1066 +    private static final Throwable[] EMPTY_THROWABLE_ARRAY = new Throwable[0];
154.1067 +
154.1068 +    /**
154.1069 +     * Returns an array containing all of the exceptions that were
154.1070 +     * suppressed, typically by the {@code try}-with-resources
154.1071 +     * statement, in order to deliver this exception.
154.1072 +     *
154.1073 +     * If no exceptions were suppressed or {@linkplain
154.1074 +     * #Throwable(String, Throwable, boolean, boolean) suppression is
154.1075 +     * disabled}, an empty array is returned.  This method is
154.1076 +     * thread-safe.  Writes to the returned array do not affect future
154.1077 +     * calls to this method.
154.1078 +     *
154.1079 +     * @return an array containing all of the exceptions that were
154.1080 +     *         suppressed to deliver this exception.
154.1081 +     * @since 1.7
154.1082 +     */
154.1083 +    public final synchronized Throwable[] getSuppressed() {
154.1084 +        return new Throwable[0];
154.1085 +//        if (suppressedExceptions == SUPPRESSED_SENTINEL ||
154.1086 +//            suppressedExceptions == null)
154.1087 +//            return EMPTY_THROWABLE_ARRAY;
154.1088 +//        else
154.1089 +//            return suppressedExceptions.toArray(EMPTY_THROWABLE_ARRAY);
154.1090 +    }
154.1091 +}
   155.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   155.2 +++ b/emul/mini/src/main/java/java/lang/VirtualMachineError.java	Sun Feb 03 07:48:42 2013 +0100
   155.3 @@ -0,0 +1,54 @@
   155.4 +/*
   155.5 + * Copyright (c) 1995, 1997, 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 + * Thrown to indicate that the Java Virtual Machine is broken or has
  155.33 + * run out of resources necessary for it to continue operating.
  155.34 + *
  155.35 + *
  155.36 + * @author  Frank Yellin
  155.37 + * @since   JDK1.0
  155.38 + */
  155.39 +abstract public
  155.40 +class VirtualMachineError extends Error {
  155.41 +    /**
  155.42 +     * Constructs a <code>VirtualMachineError</code> with no detail message.
  155.43 +     */
  155.44 +    public VirtualMachineError() {
  155.45 +        super();
  155.46 +    }
  155.47 +
  155.48 +    /**
  155.49 +     * Constructs a <code>VirtualMachineError</code> with the specified
  155.50 +     * detail message.
  155.51 +     *
  155.52 +     * @param   s   the detail message.
  155.53 +     */
  155.54 +    public VirtualMachineError(String s) {
  155.55 +        super(s);
  155.56 +    }
  155.57 +}
   156.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   156.2 +++ b/emul/mini/src/main/java/java/lang/Void.java	Sun Feb 03 07:48:42 2013 +0100
   156.3 @@ -0,0 +1,49 @@
   156.4 +/*
   156.5 + * Copyright (c) 1996, 2006, 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 + * The {@code Void} class is an uninstantiable placeholder class to hold a
  156.33 + * reference to the {@code Class} object representing the Java keyword
  156.34 + * void.
  156.35 + *
  156.36 + * @author  unascribed
  156.37 + * @since   JDK1.1
  156.38 + */
  156.39 +public final
  156.40 +class Void {
  156.41 +
  156.42 +    /**
  156.43 +     * The {@code Class} object representing the pseudo-type corresponding to
  156.44 +     * the keyword {@code void}.
  156.45 +     */
  156.46 +    public static final Class<Void> TYPE = Class.getPrimitiveClass("void");
  156.47 +
  156.48 +    /*
  156.49 +     * The Void class cannot be instantiated.
  156.50 +     */
  156.51 +    private Void() {}
  156.52 +}
   157.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   157.2 +++ b/emul/mini/src/main/java/java/lang/annotation/Annotation.java	Sun Feb 03 07:48:42 2013 +0100
   157.3 @@ -0,0 +1,131 @@
   157.4 +/*
   157.5 + * Copyright (c) 2003, 2009, 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.annotation;
  157.30 +
  157.31 +/**
  157.32 + * The common interface extended by all annotation types.  Note that an
  157.33 + * interface that manually extends this one does <i>not</i> define
  157.34 + * an annotation type.  Also note that this interface does not itself
  157.35 + * define an annotation type.
  157.36 + *
  157.37 + * More information about annotation types can be found in section 9.6 of
  157.38 + * <cite>The Java&trade; Language Specification</cite>.
  157.39 + *
  157.40 + * @author  Josh Bloch
  157.41 + * @since   1.5
  157.42 + */
  157.43 +public interface Annotation {
  157.44 +    /**
  157.45 +     * Returns true if the specified object represents an annotation
  157.46 +     * that is logically equivalent to this one.  In other words,
  157.47 +     * returns true if the specified object is an instance of the same
  157.48 +     * annotation type as this instance, all of whose members are equal
  157.49 +     * to the corresponding member of this annotation, as defined below:
  157.50 +     * <ul>
  157.51 +     *    <li>Two corresponding primitive typed members whose values are
  157.52 +     *    <tt>x</tt> and <tt>y</tt> are considered equal if <tt>x == y</tt>,
  157.53 +     *    unless their type is <tt>float</tt> or <tt>double</tt>.
  157.54 +     *
  157.55 +     *    <li>Two corresponding <tt>float</tt> members whose values
  157.56 +     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
  157.57 +     *    <tt>Float.valueOf(x).equals(Float.valueOf(y))</tt>.
  157.58 +     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
  157.59 +     *    to itself, and <tt>0.0f</tt> unequal to <tt>-0.0f</tt>.)
  157.60 +     *
  157.61 +     *    <li>Two corresponding <tt>double</tt> members whose values
  157.62 +     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
  157.63 +     *    <tt>Double.valueOf(x).equals(Double.valueOf(y))</tt>.
  157.64 +     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
  157.65 +     *    to itself, and <tt>0.0</tt> unequal to <tt>-0.0</tt>.)
  157.66 +     *
  157.67 +     *    <li>Two corresponding <tt>String</tt>, <tt>Class</tt>, enum, or
  157.68 +     *    annotation typed members whose values are <tt>x</tt> and <tt>y</tt>
  157.69 +     *    are considered equal if <tt>x.equals(y)</tt>.  (Note that this
  157.70 +     *    definition is recursive for annotation typed members.)
  157.71 +     *
  157.72 +     *    <li>Two corresponding array typed members <tt>x</tt> and <tt>y</tt>
  157.73 +     *    are considered equal if <tt>Arrays.equals(x, y)</tt>, for the
  157.74 +     *    appropriate overloading of {@link java.util.Arrays#equals}.
  157.75 +     * </ul>
  157.76 +     *
  157.77 +     * @return true if the specified object represents an annotation
  157.78 +     *     that is logically equivalent to this one, otherwise false
  157.79 +     */
  157.80 +    boolean equals(Object obj);
  157.81 +
  157.82 +    /**
  157.83 +     * Returns the hash code of this annotation, as defined below:
  157.84 +     *
  157.85 +     * <p>The hash code of an annotation is the sum of the hash codes
  157.86 +     * of its members (including those with default values), as defined
  157.87 +     * below:
  157.88 +     *
  157.89 +     * The hash code of an annotation member is (127 times the hash code
  157.90 +     * of the member-name as computed by {@link String#hashCode()}) XOR
  157.91 +     * the hash code of the member-value, as defined below:
  157.92 +     *
  157.93 +     * <p>The hash code of a member-value depends on its type:
  157.94 +     * <ul>
  157.95 +     * <li>The hash code of a primitive value <tt><i>v</i></tt> is equal to
  157.96 +     *     <tt><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</tt>, where
  157.97 +     *     <tt><i>WrapperType</i></tt> is the wrapper type corresponding
  157.98 +     *     to the primitive type of <tt><i>v</i></tt> ({@link Byte},
  157.99 +     *     {@link Character}, {@link Double}, {@link Float}, {@link Integer},
 157.100 +     *     {@link Long}, {@link Short}, or {@link Boolean}).
 157.101 +     *
 157.102 +     * <li>The hash code of a string, enum, class, or annotation member-value
 157.103 +     I     <tt><i>v</i></tt> is computed as by calling
 157.104 +     *     <tt><i>v</i>.hashCode()</tt>.  (In the case of annotation
 157.105 +     *     member values, this is a recursive definition.)
 157.106 +     *
 157.107 +     * <li>The hash code of an array member-value is computed by calling
 157.108 +     *     the appropriate overloading of
 157.109 +     *     {@link java.util.Arrays#hashCode(long[]) Arrays.hashCode}
 157.110 +     *     on the value.  (There is one overloading for each primitive
 157.111 +     *     type, and one for object reference types.)
 157.112 +     * </ul>
 157.113 +     *
 157.114 +     * @return the hash code of this annotation
 157.115 +     */
 157.116 +    int hashCode();
 157.117 +
 157.118 +    /**
 157.119 +     * Returns a string representation of this annotation.  The details
 157.120 +     * of the representation are implementation-dependent, but the following
 157.121 +     * may be regarded as typical:
 157.122 +     * <pre>
 157.123 +     *   &#064;com.acme.util.Name(first=Alfred, middle=E., last=Neuman)
 157.124 +     * </pre>
 157.125 +     *
 157.126 +     * @return a string representation of this annotation
 157.127 +     */
 157.128 +    String toString();
 157.129 +
 157.130 +    /**
 157.131 +     * Returns the annotation type of this annotation.
 157.132 +     */
 157.133 +    Class<? extends Annotation> annotationType();
 157.134 +}
   158.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   158.2 +++ b/emul/mini/src/main/java/java/lang/annotation/Documented.java	Sun Feb 03 07:48:42 2013 +0100
   158.3 @@ -0,0 +1,43 @@
   158.4 +/*
   158.5 + * Copyright (c) 2003, 2004, 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.annotation;
  158.30 +
  158.31 +/**
  158.32 + * Indicates that annotations with a type are to be documented by javadoc
  158.33 + * and similar tools by default.  This type should be used to annotate the
  158.34 + * declarations of types whose annotations affect the use of annotated
  158.35 + * elements by their clients.  If a type declaration is annotated with
  158.36 + * Documented, its annotations become part of the public API
  158.37 + * of the annotated elements.
  158.38 + *
  158.39 + * @author  Joshua Bloch
  158.40 + * @since 1.5
  158.41 + */
  158.42 +@Documented
  158.43 +@Retention(RetentionPolicy.RUNTIME)
  158.44 +@Target(ElementType.ANNOTATION_TYPE)
  158.45 +public @interface Documented {
  158.46 +}
   159.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   159.2 +++ b/emul/mini/src/main/java/java/lang/annotation/ElementType.java	Sun Feb 03 07:48:42 2013 +0100
   159.3 @@ -0,0 +1,63 @@
   159.4 +/*
   159.5 + * Copyright (c) 2003, 2011, 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.annotation;
  159.30 +
  159.31 +/**
  159.32 + * A program element type.  The constants of this enumerated type
  159.33 + * provide a simple classification of the declared elements in a
  159.34 + * Java program.
  159.35 + *
  159.36 + * <p>These constants are used with the {@link Target} meta-annotation type
  159.37 + * to specify where it is legal to use an annotation type.
  159.38 + *
  159.39 + * @author  Joshua Bloch
  159.40 + * @since 1.5
  159.41 + */
  159.42 +public enum ElementType {
  159.43 +    /** Class, interface (including annotation type), or enum declaration */
  159.44 +    TYPE,
  159.45 +
  159.46 +    /** Field declaration (includes enum constants) */
  159.47 +    FIELD,
  159.48 +
  159.49 +    /** Method declaration */
  159.50 +    METHOD,
  159.51 +
  159.52 +    /** Parameter declaration */
  159.53 +    PARAMETER,
  159.54 +
  159.55 +    /** Constructor declaration */
  159.56 +    CONSTRUCTOR,
  159.57 +
  159.58 +    /** Local variable declaration */
  159.59 +    LOCAL_VARIABLE,
  159.60 +
  159.61 +    /** Annotation type declaration */
  159.62 +    ANNOTATION_TYPE,
  159.63 +
  159.64 +    /** Package declaration */
  159.65 +    PACKAGE
  159.66 +}
   160.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   160.2 +++ b/emul/mini/src/main/java/java/lang/annotation/Retention.java	Sun Feb 03 07:48:42 2013 +0100
   160.3 @@ -0,0 +1,47 @@
   160.4 +/*
   160.5 + * Copyright (c) 2003, 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.annotation;
  160.30 +
  160.31 +/**
  160.32 + * Indicates how long annotations with the annotated type are to
  160.33 + * be retained.  If no Retention annotation is present on
  160.34 + * an annotation type declaration, the retention policy defaults to
  160.35 + * {@code RetentionPolicy.CLASS}.
  160.36 + *
  160.37 + * <p>A Retention meta-annotation has effect only if the
  160.38 + * meta-annotated type is used directly for annotation.  It has no
  160.39 + * effect if the meta-annotated type is used as a member type in
  160.40 + * another annotation type.
  160.41 + *
  160.42 + * @author  Joshua Bloch
  160.43 + * @since 1.5
  160.44 + */
  160.45 +@Documented
  160.46 +@Retention(RetentionPolicy.RUNTIME)
  160.47 +@Target(ElementType.ANNOTATION_TYPE)
  160.48 +public @interface Retention {
  160.49 +    RetentionPolicy value();
  160.50 +}
   161.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   161.2 +++ b/emul/mini/src/main/java/java/lang/annotation/RetentionPolicy.java	Sun Feb 03 07:48:42 2013 +0100
   161.3 @@ -0,0 +1,57 @@
   161.4 +/*
   161.5 + * Copyright (c) 2003, 2004, 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 + * Annotation retention policy.  The constants of this enumerated type
  161.33 + * describe the various policies for retaining annotations.  They are used
  161.34 + * in conjunction with the {@link Retention} meta-annotation type to specify
  161.35 + * how long annotations are to be retained.
  161.36 + *
  161.37 + * @author  Joshua Bloch
  161.38 + * @since 1.5
  161.39 + */
  161.40 +public enum RetentionPolicy {
  161.41 +    /**
  161.42 +     * Annotations are to be discarded by the compiler.
  161.43 +     */
  161.44 +    SOURCE,
  161.45 +
  161.46 +    /**
  161.47 +     * Annotations are to be recorded in the class file by the compiler
  161.48 +     * but need not be retained by the VM at run time.  This is the default
  161.49 +     * behavior.
  161.50 +     */
  161.51 +    CLASS,
  161.52 +
  161.53 +    /**
  161.54 +     * Annotations are to be recorded in the class file by the compiler and
  161.55 +     * retained by the VM at run time, so they may be read reflectively.
  161.56 +     *
  161.57 +     * @see java.lang.reflect.AnnotatedElement
  161.58 +     */
  161.59 +    RUNTIME
  161.60 +}
   162.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   162.2 +++ b/emul/mini/src/main/java/java/lang/annotation/Target.java	Sun Feb 03 07:48:42 2013 +0100
   162.3 @@ -0,0 +1,68 @@
   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 the kinds of program element to which an annotation type
  162.33 + * is applicable.  If a Target meta-annotation is not present on an
  162.34 + * annotation type declaration, the declared type may be used on any
  162.35 + * program element.  If such a meta-annotation is present, the compiler
  162.36 + * will enforce the specified usage restriction.
  162.37 + *
  162.38 + * For example, this meta-annotation indicates that the declared type is
  162.39 + * itself a meta-annotation type.  It can only be used on annotation type
  162.40 + * declarations:
  162.41 + * <pre>
  162.42 + *    &#064;Target(ElementType.ANNOTATION_TYPE)
  162.43 + *    public &#064;interface MetaAnnotationType {
  162.44 + *        ...
  162.45 + *    }
  162.46 + * </pre>
  162.47 + * This meta-annotation indicates that the declared type is intended solely
  162.48 + * for use as a member type in complex annotation type declarations.  It
  162.49 + * cannot be used to annotate anything directly:
  162.50 + * <pre>
  162.51 + *    &#064;Target({})
  162.52 + *    public &#064;interface MemberType {
  162.53 + *        ...
  162.54 + *    }
  162.55 + * </pre>
  162.56 + * It is a compile-time error for a single ElementType constant to
  162.57 + * appear more than once in a Target annotation.  For example, the
  162.58 + * following meta-annotation is illegal:
  162.59 + * <pre>
  162.60 + *    &#064;Target({ElementType.FIELD, ElementType.METHOD, ElementType.FIELD})
  162.61 + *    public &#064;interface Bogus {
  162.62 + *        ...
  162.63 + *    }
  162.64 + * </pre>
  162.65 + */
  162.66 +@Documented
  162.67 +@Retention(RetentionPolicy.RUNTIME)
  162.68 +@Target(ElementType.ANNOTATION_TYPE)
  162.69 +public @interface Target {
  162.70 +    ElementType[] value();
  162.71 +}
   163.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   163.2 +++ b/emul/mini/src/main/java/java/lang/annotation/UnsupportedOperationException.java	Sun Feb 03 07:48:42 2013 +0100
   163.3 @@ -0,0 +1,94 @@
   163.4 +/*
   163.5 + * Copyright (c) 1997, 2006, 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;
  163.30 +
  163.31 +/**
  163.32 + * Thrown to indicate that the requested operation is not supported.<p>
  163.33 + *
  163.34 + * This class is a member of the
  163.35 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  163.36 + * Java Collections Framework</a>.
  163.37 + *
  163.38 + * @author  Josh Bloch
  163.39 + * @since   1.2
  163.40 + */
  163.41 +public class UnsupportedOperationException extends RuntimeException {
  163.42 +    /**
  163.43 +     * Constructs an UnsupportedOperationException with no detail message.
  163.44 +     */
  163.45 +    public UnsupportedOperationException() {
  163.46 +    }
  163.47 +
  163.48 +    /**
  163.49 +     * Constructs an UnsupportedOperationException with the specified
  163.50 +     * detail message.
  163.51 +     *
  163.52 +     * @param message the detail message
  163.53 +     */
  163.54 +    public UnsupportedOperationException(String message) {
  163.55 +        super(message);
  163.56 +    }
  163.57 +
  163.58 +    /**
  163.59 +     * Constructs a new exception with the specified detail message and
  163.60 +     * cause.
  163.61 +     *
  163.62 +     * <p>Note that the detail message associated with <code>cause</code> is
  163.63 +     * <i>not</i> automatically incorporated in this exception's detail
  163.64 +     * message.
  163.65 +     *
  163.66 +     * @param  message the detail message (which is saved for later retrieval
  163.67 +     *         by the {@link Throwable#getMessage()} method).
  163.68 +     * @param  cause the cause (which is saved for later retrieval by the
  163.69 +     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value
  163.70 +     *         is permitted, and indicates that the cause is nonexistent or
  163.71 +     *         unknown.)
  163.72 +     * @since 1.5
  163.73 +     */
  163.74 +    public UnsupportedOperationException(String message, Throwable cause) {
  163.75 +        super(message, cause);
  163.76 +    }
  163.77 +
  163.78 +    /**
  163.79 +     * Constructs a new exception with the specified cause and a detail
  163.80 +     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  163.81 +     * typically contains the class and detail message of <tt>cause</tt>).
  163.82 +     * This constructor is useful for exceptions that are little more than
  163.83 +     * wrappers for other throwables (for example, {@link
  163.84 +     * java.security.PrivilegedActionException}).
  163.85 +     *
  163.86 +     * @param  cause the cause (which is saved for later retrieval by the
  163.87 +     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value is
  163.88 +     *         permitted, and indicates that the cause is nonexistent or
  163.89 +     *         unknown.)
  163.90 +     * @since  1.5
  163.91 +     */
  163.92 +    public UnsupportedOperationException(Throwable cause) {
  163.93 +        super(cause);
  163.94 +    }
  163.95 +
  163.96 +    static final long serialVersionUID = -1242599979055084673L;
  163.97 +}
   164.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   164.2 +++ b/emul/mini/src/main/java/java/lang/reflect/AccessibleObject.java	Sun Feb 03 07:48:42 2013 +0100
   164.3 @@ -0,0 +1,167 @@
   164.4 +/*
   164.5 + * Copyright (c) 1997, 2008, 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.reflect;
  164.30 +
  164.31 +import java.lang.annotation.Annotation;
  164.32 +
  164.33 +/**
  164.34 + * The AccessibleObject class is the base class for Field, Method and
  164.35 + * Constructor objects.  It provides the ability to flag a reflected
  164.36 + * object as suppressing default Java language access control checks
  164.37 + * when it is used.  The access checks--for public, default (package)
  164.38 + * access, protected, and private members--are performed when Fields,
  164.39 + * Methods or Constructors are used to set or get fields, to invoke
  164.40 + * methods, or to create and initialize new instances of classes,
  164.41 + * respectively.
  164.42 + *
  164.43 + * <p>Setting the {@code accessible} flag in a reflected object
  164.44 + * permits sophisticated applications with sufficient privilege, such
  164.45 + * as Java Object Serialization or other persistence mechanisms, to
  164.46 + * manipulate objects in a manner that would normally be prohibited.
  164.47 + *
  164.48 + * <p>By default, a reflected object is <em>not</em> accessible.
  164.49 + *
  164.50 + * @see Field
  164.51 + * @see Method
  164.52 + * @see Constructor
  164.53 + * @see ReflectPermission
  164.54 + *
  164.55 + * @since 1.2
  164.56 + */
  164.57 +public class AccessibleObject implements AnnotatedElement {
  164.58 +
  164.59 +    /**
  164.60 +     * Convenience method to set the {@code accessible} flag for an
  164.61 +     * array of objects with a single security check (for efficiency).
  164.62 +     *
  164.63 +     * <p>First, if there is a security manager, its
  164.64 +     * {@code checkPermission} method is called with a
  164.65 +     * {@code ReflectPermission("suppressAccessChecks")} permission.
  164.66 +     *
  164.67 +     * <p>A {@code SecurityException} is raised if {@code flag} is
  164.68 +     * {@code true} but accessibility of any of the elements of the input
  164.69 +     * {@code array} may not be changed (for example, if the element
  164.70 +     * object is a {@link Constructor} object for the class {@link
  164.71 +     * java.lang.Class}).  In the event of such a SecurityException, the
  164.72 +     * accessibility of objects is set to {@code flag} for array elements
  164.73 +     * upto (and excluding) the element for which the exception occurred; the
  164.74 +     * accessibility of elements beyond (and including) the element for which
  164.75 +     * the exception occurred is unchanged.
  164.76 +     *
  164.77 +     * @param array the array of AccessibleObjects
  164.78 +     * @param flag  the new value for the {@code accessible} flag
  164.79 +     *              in each object
  164.80 +     * @throws SecurityException if the request is denied.
  164.81 +     * @see SecurityManager#checkPermission
  164.82 +     * @see java.lang.RuntimePermission
  164.83 +     */
  164.84 +    public static void setAccessible(AccessibleObject[] array, boolean flag)
  164.85 +        throws SecurityException {
  164.86 +        throw new SecurityException();
  164.87 +    }
  164.88 +
  164.89 +    /**
  164.90 +     * Set the {@code accessible} flag for this object to
  164.91 +     * the indicated boolean value.  A value of {@code true} indicates that
  164.92 +     * the reflected object should suppress Java language access
  164.93 +     * checking when it is used.  A value of {@code false} indicates
  164.94 +     * that the reflected object should enforce Java language access checks.
  164.95 +     *
  164.96 +     * <p>First, if there is a security manager, its
  164.97 +     * {@code checkPermission} method is called with a
  164.98 +     * {@code ReflectPermission("suppressAccessChecks")} permission.
  164.99 +     *
 164.100 +     * <p>A {@code SecurityException} is raised if {@code flag} is
 164.101 +     * {@code true} but accessibility of this object may not be changed
 164.102 +     * (for example, if this element object is a {@link Constructor} object for
 164.103 +     * the class {@link java.lang.Class}).
 164.104 +     *
 164.105 +     * <p>A {@code SecurityException} is raised if this object is a {@link
 164.106 +     * java.lang.reflect.Constructor} object for the class
 164.107 +     * {@code java.lang.Class}, and {@code flag} is true.
 164.108 +     *
 164.109 +     * @param flag the new value for the {@code accessible} flag
 164.110 +     * @throws SecurityException if the request is denied.
 164.111 +     * @see SecurityManager#checkPermission
 164.112 +     * @see java.lang.RuntimePermission
 164.113 +     */
 164.114 +    public void setAccessible(boolean flag) throws SecurityException {
 164.115 +        throw new SecurityException();
 164.116 +    }
 164.117 +
 164.118 +    /**
 164.119 +     * Get the value of the {@code accessible} flag for this object.
 164.120 +     *
 164.121 +     * @return the value of the object's {@code accessible} flag
 164.122 +     */
 164.123 +    public boolean isAccessible() {
 164.124 +        return override;
 164.125 +    }
 164.126 +
 164.127 +    /**
 164.128 +     * Constructor: only used by the Java Virtual Machine.
 164.129 +     */
 164.130 +    protected AccessibleObject() {}
 164.131 +
 164.132 +    // Indicates whether language-level access checks are overridden
 164.133 +    // by this object. Initializes to "false". This field is used by
 164.134 +    // Field, Method, and Constructor.
 164.135 +    //
 164.136 +    // NOTE: for security purposes, this field must not be visible
 164.137 +    // outside this package.
 164.138 +    boolean override;
 164.139 +
 164.140 +    /**
 164.141 +     * @throws NullPointerException {@inheritDoc}
 164.142 +     * @since 1.5
 164.143 +     */
 164.144 +    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 164.145 +        throw new AssertionError("All subclasses should override this method");
 164.146 +    }
 164.147 +
 164.148 +    /**
 164.149 +     * @throws NullPointerException {@inheritDoc}
 164.150 +     * @since 1.5
 164.151 +     */
 164.152 +    public boolean isAnnotationPresent(
 164.153 +        Class<? extends Annotation> annotationClass) {
 164.154 +        return getAnnotation(annotationClass) != null;
 164.155 +    }
 164.156 +
 164.157 +    /**
 164.158 +     * @since 1.5
 164.159 +     */
 164.160 +    public Annotation[] getAnnotations() {
 164.161 +        return getDeclaredAnnotations();
 164.162 +    }
 164.163 +
 164.164 +    /**
 164.165 +     * @since 1.5
 164.166 +     */
 164.167 +    public Annotation[] getDeclaredAnnotations()  {
 164.168 +        throw new AssertionError("All subclasses should override this method");
 164.169 +    }
 164.170 +}
   165.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   165.2 +++ b/emul/mini/src/main/java/java/lang/reflect/AnnotatedElement.java	Sun Feb 03 07:48:42 2013 +0100
   165.3 @@ -0,0 +1,112 @@
   165.4 +/*
   165.5 + * Copyright (c) 2003, 2005, 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.reflect;
  165.30 +
  165.31 +import java.lang.annotation.Annotation;
  165.32 +
  165.33 +/**
  165.34 + * Represents an annotated element of the program currently running in this
  165.35 + * VM.  This interface allows annotations to be read reflectively.  All
  165.36 + * annotations returned by methods in this interface are immutable and
  165.37 + * serializable.  It is permissible for the caller to modify the
  165.38 + * arrays returned by accessors for array-valued enum members; it will
  165.39 + * have no affect on the arrays returned to other callers.
  165.40 + *
  165.41 + * <p>If an annotation returned by a method in this interface contains
  165.42 + * (directly or indirectly) a {@link Class}-valued member referring to
  165.43 + * a class that is not accessible in this VM, attempting to read the class
  165.44 + * by calling the relevant Class-returning method on the returned annotation
  165.45 + * will result in a {@link TypeNotPresentException}.
  165.46 + *
  165.47 + * <p>Similarly, attempting to read an enum-valued member will result in
  165.48 + * a {@link EnumConstantNotPresentException} if the enum constant in the
  165.49 + * annotation is no longer present in the enum type.
  165.50 + *
  165.51 + * <p>Finally, Attempting to read a member whose definition has evolved
  165.52 + * incompatibly will result in a {@link
  165.53 + * java.lang.annotation.AnnotationTypeMismatchException} or an
  165.54 + * {@link java.lang.annotation.IncompleteAnnotationException}.
  165.55 + *
  165.56 + * @see java.lang.EnumConstantNotPresentException
  165.57 + * @see java.lang.TypeNotPresentException
  165.58 + * @see java.lang.annotation.AnnotationFormatError
  165.59 + * @see java.lang.annotation.AnnotationTypeMismatchException
  165.60 + * @see java.lang.annotation.IncompleteAnnotationException
  165.61 + * @since 1.5
  165.62 + * @author Josh Bloch
  165.63 + */
  165.64 +public interface AnnotatedElement {
  165.65 +    /**
  165.66 +     * Returns true if an annotation for the specified type
  165.67 +     * is present on this element, else false.  This method
  165.68 +     * is designed primarily for convenient access to marker annotations.
  165.69 +     *
  165.70 +     * @param annotationClass the Class object corresponding to the
  165.71 +     *        annotation type
  165.72 +     * @return true if an annotation for the specified annotation
  165.73 +     *     type is present on this element, else false
  165.74 +     * @throws NullPointerException if the given annotation class is null
  165.75 +     * @since 1.5
  165.76 +     */
  165.77 +     boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
  165.78 +
  165.79 +   /**
  165.80 +     * Returns this element's annotation for the specified type if
  165.81 +     * such an annotation is present, else null.
  165.82 +     *
  165.83 +     * @param annotationClass the Class object corresponding to the
  165.84 +     *        annotation type
  165.85 +     * @return this element's annotation for the specified annotation type if
  165.86 +     *     present on this element, else null
  165.87 +     * @throws NullPointerException if the given annotation class is null
  165.88 +     * @since 1.5
  165.89 +     */
  165.90 +    <T extends Annotation> T getAnnotation(Class<T> annotationClass);
  165.91 +
  165.92 +    /**
  165.93 +     * Returns all annotations present on this element.  (Returns an array
  165.94 +     * of length zero if this element has no annotations.)  The caller of
  165.95 +     * this method is free to modify the returned array; it will have no
  165.96 +     * effect on the arrays returned to other callers.
  165.97 +     *
  165.98 +     * @return all annotations present on this element
  165.99 +     * @since 1.5
 165.100 +     */
 165.101 +    Annotation[] getAnnotations();
 165.102 +
 165.103 +    /**
 165.104 +     * Returns all annotations that are directly present on this
 165.105 +     * element.  Unlike the other methods in this interface, this method
 165.106 +     * ignores inherited annotations.  (Returns an array of length zero if
 165.107 +     * no annotations are directly present on this element.)  The caller of
 165.108 +     * this method is free to modify the returned array; it will have no
 165.109 +     * effect on the arrays returned to other callers.
 165.110 +     *
 165.111 +     * @return All annotations directly present on this element
 165.112 +     * @since 1.5
 165.113 +     */
 165.114 +    Annotation[] getDeclaredAnnotations();
 165.115 +}
   166.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   166.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Array.java	Sun Feb 03 07:48:42 2013 +0100
   166.3 @@ -0,0 +1,663 @@
   166.4 +/*
   166.5 + * Copyright (c) 1996, 2006, 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.reflect;
  166.30 +
  166.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  166.32 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  166.33 +
  166.34 +/**
  166.35 + * The {@code Array} class provides static methods to dynamically create and
  166.36 + * access Java arrays.
  166.37 + *
  166.38 + * <p>{@code Array} permits widening conversions to occur during a get or set
  166.39 + * operation, but throws an {@code IllegalArgumentException} if a narrowing
  166.40 + * conversion would occur.
  166.41 + *
  166.42 + * @author Nakul Saraiya
  166.43 + */
  166.44 +@JavaScriptPrototype(prototype = "new Array", container = "Array.prototype")
  166.45 +public final
  166.46 +class Array {
  166.47 +
  166.48 +    /**
  166.49 +     * Constructor.  Class Array is not instantiable.
  166.50 +     */
  166.51 +    private Array() {}
  166.52 +
  166.53 +    /**
  166.54 +     * Creates a new array with the specified component type and
  166.55 +     * length.
  166.56 +     * Invoking this method is equivalent to creating an array
  166.57 +     * as follows:
  166.58 +     * <blockquote>
  166.59 +     * <pre>
  166.60 +     * int[] x = {length};
  166.61 +     * Array.newInstance(componentType, x);
  166.62 +     * </pre>
  166.63 +     * </blockquote>
  166.64 +     *
  166.65 +     * @param componentType the {@code Class} object representing the
  166.66 +     * component type of the new array
  166.67 +     * @param length the length of the new array
  166.68 +     * @return the new array
  166.69 +     * @exception NullPointerException if the specified
  166.70 +     * {@code componentType} parameter is null
  166.71 +     * @exception IllegalArgumentException if componentType is {@link Void#TYPE}
  166.72 +     * @exception NegativeArraySizeException if the specified {@code length}
  166.73 +     * is negative
  166.74 +     */
  166.75 +    public static Object newInstance(Class<?> componentType, int length)
  166.76 +    throws NegativeArraySizeException {
  166.77 +        if (length < 0) {
  166.78 +            throw new NegativeArraySizeException();
  166.79 +        }
  166.80 +        String sig = findSignature(componentType);
  166.81 +        return newArray(componentType.isPrimitive(), sig, length);
  166.82 +    }
  166.83 +    
  166.84 +    private static String findSignature(Class<?> type) {
  166.85 +        if (type == Integer.TYPE) {
  166.86 +            return "[I";
  166.87 +        }
  166.88 +        if (type == Long.TYPE) {
  166.89 +            return "[J";
  166.90 +        }
  166.91 +        if (type == Double.TYPE) {
  166.92 +            return "[D";
  166.93 +        }
  166.94 +        if (type == Float.TYPE) {
  166.95 +            return "[F";
  166.96 +        }
  166.97 +        if (type == Byte.TYPE) {
  166.98 +            return "[B";
  166.99 +        }
 166.100 +        if (type == Boolean.TYPE) {
 166.101 +            return "[Z";
 166.102 +        }
 166.103 +        if (type == Short.TYPE) {
 166.104 +            return "[S";
 166.105 +        }
 166.106 +        if (type == Character.TYPE) {
 166.107 +            return "[C";
 166.108 +        }
 166.109 +        if (type.getName().equals("void")) {
 166.110 +            throw new IllegalStateException("Can't create array for " + type);
 166.111 +        }
 166.112 +        return "[L" + type.getName() + ";";
 166.113 +    }
 166.114 +    /**
 166.115 +     * Creates a new array
 166.116 +     * with the specified component type and dimensions.
 166.117 +     * If {@code componentType}
 166.118 +     * represents a non-array class or interface, the new array
 166.119 +     * has {@code dimensions.length} dimensions and
 166.120 +     * {@code componentType} as its component type. If
 166.121 +     * {@code componentType} represents an array class, the
 166.122 +     * number of dimensions of the new array is equal to the sum
 166.123 +     * of {@code dimensions.length} and the number of
 166.124 +     * dimensions of {@code componentType}. In this case, the
 166.125 +     * component type of the new array is the component type of
 166.126 +     * {@code componentType}.
 166.127 +     *
 166.128 +     * <p>The number of dimensions of the new array must not
 166.129 +     * exceed the number of array dimensions supported by the
 166.130 +     * implementation (typically 255).
 166.131 +     *
 166.132 +     * @param componentType the {@code Class} object representing the component
 166.133 +     * type of the new array
 166.134 +     * @param dimensions an array of {@code int} representing the dimensions of
 166.135 +     * the new array
 166.136 +     * @return the new array
 166.137 +     * @exception NullPointerException if the specified
 166.138 +     * {@code componentType} argument is null
 166.139 +     * @exception IllegalArgumentException if the specified {@code dimensions}
 166.140 +     * argument is a zero-dimensional array, or if the number of
 166.141 +     * requested dimensions exceeds the limit on the number of array dimensions
 166.142 +     * supported by the implementation (typically 255), or if componentType
 166.143 +     * is {@link Void#TYPE}.
 166.144 +     * @exception NegativeArraySizeException if any of the components in
 166.145 +     * the specified {@code dimensions} argument is negative.
 166.146 +     */
 166.147 +    public static Object newInstance(Class<?> componentType, int... dimensions)
 166.148 +        throws IllegalArgumentException, NegativeArraySizeException {
 166.149 +        StringBuilder sig = new StringBuilder();
 166.150 +        for (int i = 1; i < dimensions.length; i++) {
 166.151 +            sig.append('[');
 166.152 +        }
 166.153 +        sig.append(findSignature(componentType));
 166.154 +        return multiNewArray(sig.toString(), dimensions, 0);
 166.155 +    }
 166.156 +
 166.157 +    /**
 166.158 +     * Returns the length of the specified array object, as an {@code int}.
 166.159 +     *
 166.160 +     * @param array the array
 166.161 +     * @return the length of the array
 166.162 +     * @exception IllegalArgumentException if the object argument is not
 166.163 +     * an array
 166.164 +     */
 166.165 +    public static int getLength(Object array)
 166.166 +    throws IllegalArgumentException {
 166.167 +        if (!array.getClass().isArray()) {
 166.168 +            throw new IllegalArgumentException("Argument is not an array");
 166.169 +        }
 166.170 +        return length(array);
 166.171 +    }
 166.172 +    
 166.173 +    @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
 166.174 +    private static native int length(Object arr);
 166.175 +
 166.176 +    /**
 166.177 +     * Returns the value of the indexed component in the specified
 166.178 +     * array object.  The value is automatically wrapped in an object
 166.179 +     * if it has a primitive type.
 166.180 +     *
 166.181 +     * @param array the array
 166.182 +     * @param index the index
 166.183 +     * @return the (possibly wrapped) value of the indexed component in
 166.184 +     * the specified array
 166.185 +     * @exception NullPointerException If the specified object is null
 166.186 +     * @exception IllegalArgumentException If the specified object is not
 166.187 +     * an array
 166.188 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.189 +     * argument is negative, or if it is greater than or equal to the
 166.190 +     * length of the specified array
 166.191 +     */
 166.192 +    public static Object get(Object array, int index)
 166.193 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.194 +        final Class<?> t = array.getClass().getComponentType();
 166.195 +        if (t.isPrimitive()) {
 166.196 +            return fromPrimitive(t, array, index);
 166.197 +        } else {
 166.198 +            return ((Object[])array)[index];
 166.199 +        }
 166.200 +    }
 166.201 +
 166.202 +    /**
 166.203 +     * Returns the value of the indexed component in the specified
 166.204 +     * array object, as a {@code boolean}.
 166.205 +     *
 166.206 +     * @param array the array
 166.207 +     * @param index the index
 166.208 +     * @return the value of the indexed component in the specified array
 166.209 +     * @exception NullPointerException If the specified object is null
 166.210 +     * @exception IllegalArgumentException If the specified object is not
 166.211 +     * an array, or if the indexed element cannot be converted to the
 166.212 +     * return type by an identity or widening conversion
 166.213 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.214 +     * argument is negative, or if it is greater than or equal to the
 166.215 +     * length of the specified array
 166.216 +     * @see Array#get
 166.217 +     */
 166.218 +    public static native boolean getBoolean(Object array, int index)
 166.219 +        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
 166.220 +
 166.221 +    /**
 166.222 +     * Returns the value of the indexed component in the specified
 166.223 +     * array object, as a {@code byte}.
 166.224 +     *
 166.225 +     * @param array the array
 166.226 +     * @param index the index
 166.227 +     * @return the value of the indexed component in the specified array
 166.228 +     * @exception NullPointerException If the specified object is null
 166.229 +     * @exception IllegalArgumentException If the specified object is not
 166.230 +     * an array, or if the indexed element cannot be converted to the
 166.231 +     * return type by an identity or widening conversion
 166.232 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.233 +     * argument is negative, or if it is greater than or equal to the
 166.234 +     * length of the specified array
 166.235 +     * @see Array#get
 166.236 +     */
 166.237 +    public static byte getByte(Object array, int index)
 166.238 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.239 +        if (array.getClass().getComponentType() != Byte.TYPE) {
 166.240 +            throw new IllegalArgumentException();
 166.241 +        }
 166.242 +        byte[] arr = (byte[]) array;
 166.243 +        return arr[index];
 166.244 +    }
 166.245 +
 166.246 +    /**
 166.247 +     * Returns the value of the indexed component in the specified
 166.248 +     * array object, as a {@code char}.
 166.249 +     *
 166.250 +     * @param array the array
 166.251 +     * @param index the index
 166.252 +     * @return the value of the indexed component in the specified array
 166.253 +     * @exception NullPointerException If the specified object is null
 166.254 +     * @exception IllegalArgumentException If the specified object is not
 166.255 +     * an array, or if the indexed element cannot be converted to the
 166.256 +     * return type by an identity or widening conversion
 166.257 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.258 +     * argument is negative, or if it is greater than or equal to the
 166.259 +     * length of the specified array
 166.260 +     * @see Array#get
 166.261 +     */
 166.262 +    public static native char getChar(Object array, int index)
 166.263 +        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
 166.264 +
 166.265 +    /**
 166.266 +     * Returns the value of the indexed component in the specified
 166.267 +     * array object, as a {@code short}.
 166.268 +     *
 166.269 +     * @param array the array
 166.270 +     * @param index the index
 166.271 +     * @return the value of the indexed component in the specified array
 166.272 +     * @exception NullPointerException If the specified object is null
 166.273 +     * @exception IllegalArgumentException If the specified object is not
 166.274 +     * an array, or if the indexed element cannot be converted to the
 166.275 +     * return type by an identity or widening conversion
 166.276 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.277 +     * argument is negative, or if it is greater than or equal to the
 166.278 +     * length of the specified array
 166.279 +     * @see Array#get
 166.280 +     */
 166.281 +    public static short getShort(Object array, int index)
 166.282 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.283 +        final Class<?> t = array.getClass().getComponentType();
 166.284 +        if (t == Short.TYPE) {
 166.285 +            short[] arr = (short[]) array;
 166.286 +            return arr[index];
 166.287 +        }
 166.288 +        return getByte(array, index);
 166.289 +    }
 166.290 +
 166.291 +    /**
 166.292 +     * Returns the value of the indexed component in the specified
 166.293 +     * array object, as an {@code int}.
 166.294 +     *
 166.295 +     * @param array the array
 166.296 +     * @param index the index
 166.297 +     * @return the value of the indexed component in the specified array
 166.298 +     * @exception NullPointerException If the specified object is null
 166.299 +     * @exception IllegalArgumentException If the specified object is not
 166.300 +     * an array, or if the indexed element cannot be converted to the
 166.301 +     * return type by an identity or widening conversion
 166.302 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.303 +     * argument is negative, or if it is greater than or equal to the
 166.304 +     * length of the specified array
 166.305 +     * @see Array#get
 166.306 +     */
 166.307 +    public static int getInt(Object array, int index) 
 166.308 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.309 +        final Class<?> t = array.getClass().getComponentType();
 166.310 +        if (t == Integer.TYPE) {
 166.311 +            int[] arr = (int[]) array;
 166.312 +            return arr[index];
 166.313 +        }
 166.314 +        return getShort(array, index);
 166.315 +    }
 166.316 +
 166.317 +    /**
 166.318 +     * Returns the value of the indexed component in the specified
 166.319 +     * array object, as a {@code long}.
 166.320 +     *
 166.321 +     * @param array the array
 166.322 +     * @param index the index
 166.323 +     * @return the value of the indexed component in the specified array
 166.324 +     * @exception NullPointerException If the specified object is null
 166.325 +     * @exception IllegalArgumentException If the specified object is not
 166.326 +     * an array, or if the indexed element cannot be converted to the
 166.327 +     * return type by an identity or widening conversion
 166.328 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.329 +     * argument is negative, or if it is greater than or equal to the
 166.330 +     * length of the specified array
 166.331 +     * @see Array#get
 166.332 +     */
 166.333 +    public static long getLong(Object array, int index)
 166.334 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.335 +        final Class<?> t = array.getClass().getComponentType();
 166.336 +        if (t == Long.TYPE) {
 166.337 +            long[] arr = (long[]) array;
 166.338 +            return arr[index];
 166.339 +        }
 166.340 +        return getInt(array, index);
 166.341 +    }
 166.342 +
 166.343 +    /**
 166.344 +     * Returns the value of the indexed component in the specified
 166.345 +     * array object, as a {@code float}.
 166.346 +     *
 166.347 +     * @param array the array
 166.348 +     * @param index the index
 166.349 +     * @return the value of the indexed component in the specified array
 166.350 +     * @exception NullPointerException If the specified object is null
 166.351 +     * @exception IllegalArgumentException If the specified object is not
 166.352 +     * an array, or if the indexed element cannot be converted to the
 166.353 +     * return type by an identity or widening conversion
 166.354 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.355 +     * argument is negative, or if it is greater than or equal to the
 166.356 +     * length of the specified array
 166.357 +     * @see Array#get
 166.358 +     */
 166.359 +    public static float getFloat(Object array, int index)
 166.360 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.361 +        final Class<?> t = array.getClass().getComponentType();
 166.362 +        if (t == Float.TYPE) {
 166.363 +            float[] arr = (float[]) array;
 166.364 +            return arr[index];
 166.365 +        }
 166.366 +        return getLong(array, index);
 166.367 +    }
 166.368 +
 166.369 +    /**
 166.370 +     * Returns the value of the indexed component in the specified
 166.371 +     * array object, as a {@code double}.
 166.372 +     *
 166.373 +     * @param array the array
 166.374 +     * @param index the index
 166.375 +     * @return the value of the indexed component in the specified array
 166.376 +     * @exception NullPointerException If the specified object is null
 166.377 +     * @exception IllegalArgumentException If the specified object is not
 166.378 +     * an array, or if the indexed element cannot be converted to the
 166.379 +     * return type by an identity or widening conversion
 166.380 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.381 +     * argument is negative, or if it is greater than or equal to the
 166.382 +     * length of the specified array
 166.383 +     * @see Array#get
 166.384 +     */
 166.385 +    public static double getDouble(Object array, int index)
 166.386 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.387 +        final Class<?> t = array.getClass().getComponentType();
 166.388 +        if (t == Double.TYPE) {
 166.389 +            double[] arr = (double[]) array;
 166.390 +            return arr[index];
 166.391 +        }
 166.392 +        return getFloat(array, index);
 166.393 +    }
 166.394 +
 166.395 +    /**
 166.396 +     * Sets the value of the indexed component of the specified array
 166.397 +     * object to the specified new value.  The new value is first
 166.398 +     * automatically unwrapped if the array has a primitive component
 166.399 +     * type.
 166.400 +     * @param array the array
 166.401 +     * @param index the index into the array
 166.402 +     * @param value the new value of the indexed component
 166.403 +     * @exception NullPointerException If the specified object argument
 166.404 +     * is null
 166.405 +     * @exception IllegalArgumentException If the specified object argument
 166.406 +     * is not an array, or if the array component type is primitive and
 166.407 +     * an unwrapping conversion fails
 166.408 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.409 +     * argument is negative, or if it is greater than or equal to
 166.410 +     * the length of the specified array
 166.411 +     */
 166.412 +    public static void set(Object array, int index, Object value)
 166.413 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.414 +        if (array.getClass().getComponentType().isPrimitive()) {
 166.415 +            throw new IllegalArgumentException();
 166.416 +        } else {
 166.417 +            Object[] arr = (Object[])array;
 166.418 +            arr[index] = value;
 166.419 +        }
 166.420 +    }
 166.421 +
 166.422 +    /**
 166.423 +     * Sets the value of the indexed component of the specified array
 166.424 +     * object to the specified {@code boolean} value.
 166.425 +     * @param array the array
 166.426 +     * @param index the index into the array
 166.427 +     * @param z the new value of the indexed component
 166.428 +     * @exception NullPointerException If the specified object argument
 166.429 +     * is null
 166.430 +     * @exception IllegalArgumentException If the specified object argument
 166.431 +     * is not an array, or if the specified value cannot be converted
 166.432 +     * to the underlying array's component type by an identity or a
 166.433 +     * primitive widening conversion
 166.434 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.435 +     * argument is negative, or if it is greater than or equal to
 166.436 +     * the length of the specified array
 166.437 +     * @see Array#set
 166.438 +     */
 166.439 +    public static native void setBoolean(Object array, int index, boolean z)
 166.440 +        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
 166.441 +
 166.442 +    /**
 166.443 +     * Sets the value of the indexed component of the specified array
 166.444 +     * object to the specified {@code byte} value.
 166.445 +     * @param array the array
 166.446 +     * @param index the index into the array
 166.447 +     * @param b the new value of the indexed component
 166.448 +     * @exception NullPointerException If the specified object argument
 166.449 +     * is null
 166.450 +     * @exception IllegalArgumentException If the specified object argument
 166.451 +     * is not an array, or if the specified value cannot be converted
 166.452 +     * to the underlying array's component type by an identity or a
 166.453 +     * primitive widening conversion
 166.454 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.455 +     * argument is negative, or if it is greater than or equal to
 166.456 +     * the length of the specified array
 166.457 +     * @see Array#set
 166.458 +     */
 166.459 +    public static void setByte(Object array, int index, byte b)
 166.460 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.461 +        Class<?> t = array.getClass().getComponentType();
 166.462 +        if (t == Byte.TYPE) {
 166.463 +            byte[] arr = (byte[]) array;
 166.464 +            arr[index] = b;
 166.465 +        } else {
 166.466 +            setShort(array, index, b);
 166.467 +        }
 166.468 +    }
 166.469 +
 166.470 +    /**
 166.471 +     * Sets the value of the indexed component of the specified array
 166.472 +     * object to the specified {@code char} value.
 166.473 +     * @param array the array
 166.474 +     * @param index the index into the array
 166.475 +     * @param c the new value of the indexed component
 166.476 +     * @exception NullPointerException If the specified object argument
 166.477 +     * is null
 166.478 +     * @exception IllegalArgumentException If the specified object argument
 166.479 +     * is not an array, or if the specified value cannot be converted
 166.480 +     * to the underlying array's component type by an identity or a
 166.481 +     * primitive widening conversion
 166.482 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.483 +     * argument is negative, or if it is greater than or equal to
 166.484 +     * the length of the specified array
 166.485 +     * @see Array#set
 166.486 +     */
 166.487 +    public static native void setChar(Object array, int index, char c)
 166.488 +        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
 166.489 +
 166.490 +    /**
 166.491 +     * Sets the value of the indexed component of the specified array
 166.492 +     * object to the specified {@code short} value.
 166.493 +     * @param array the array
 166.494 +     * @param index the index into the array
 166.495 +     * @param s the new value of the indexed component
 166.496 +     * @exception NullPointerException If the specified object argument
 166.497 +     * is null
 166.498 +     * @exception IllegalArgumentException If the specified object argument
 166.499 +     * is not an array, or if the specified value cannot be converted
 166.500 +     * to the underlying array's component type by an identity or a
 166.501 +     * primitive widening conversion
 166.502 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.503 +     * argument is negative, or if it is greater than or equal to
 166.504 +     * the length of the specified array
 166.505 +     * @see Array#set
 166.506 +     */
 166.507 +    public static void setShort(Object array, int index, short s)
 166.508 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.509 +        Class<?> t = array.getClass().getComponentType();
 166.510 +        if (t == Short.TYPE) {
 166.511 +            short[] arr = (short[]) array;
 166.512 +            arr[index] = s;
 166.513 +        } else {
 166.514 +            setInt(array, index, s);
 166.515 +        }
 166.516 +        
 166.517 +    }
 166.518 +    
 166.519 +    /**
 166.520 +     * Sets the value of the indexed component of the specified array
 166.521 +     * object to the specified {@code int} value.
 166.522 +     * @param array the array
 166.523 +     * @param index the index into the array
 166.524 +     * @param i the new value of the indexed component
 166.525 +     * @exception NullPointerException If the specified object argument
 166.526 +     * is null
 166.527 +     * @exception IllegalArgumentException If the specified object argument
 166.528 +     * is not an array, or if the specified value cannot be converted
 166.529 +     * to the underlying array's component type by an identity or a
 166.530 +     * primitive widening conversion
 166.531 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.532 +     * argument is negative, or if it is greater than or equal to
 166.533 +     * the length of the specified array
 166.534 +     * @see Array#set
 166.535 +     */
 166.536 +    public static void setInt(Object array, int index, int i)
 166.537 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.538 +        Class<?> t = array.getClass().getComponentType();
 166.539 +        if (t == Integer.TYPE) {
 166.540 +            int[] arr = (int[]) array;
 166.541 +            arr[index] = i;
 166.542 +        } else {
 166.543 +            setLong(array, index, i);
 166.544 +        }
 166.545 +    }
 166.546 +
 166.547 +    /**
 166.548 +     * Sets the value of the indexed component of the specified array
 166.549 +     * object to the specified {@code long} value.
 166.550 +     * @param array the array
 166.551 +     * @param index the index into the array
 166.552 +     * @param l the new value of the indexed component
 166.553 +     * @exception NullPointerException If the specified object argument
 166.554 +     * is null
 166.555 +     * @exception IllegalArgumentException If the specified object argument
 166.556 +     * is not an array, or if the specified value cannot be converted
 166.557 +     * to the underlying array's component type by an identity or a
 166.558 +     * primitive widening conversion
 166.559 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.560 +     * argument is negative, or if it is greater than or equal to
 166.561 +     * the length of the specified array
 166.562 +     * @see Array#set
 166.563 +     */
 166.564 +    public static void setLong(Object array, int index, long l)
 166.565 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.566 +        Class<?> t = array.getClass().getComponentType();
 166.567 +        if (t == Long.TYPE) {
 166.568 +            long[] arr = (long[]) array;
 166.569 +            arr[index] = l;
 166.570 +        } else {
 166.571 +            setFloat(array, index, l);
 166.572 +        }
 166.573 +    }
 166.574 +
 166.575 +    /**
 166.576 +     * Sets the value of the indexed component of the specified array
 166.577 +     * object to the specified {@code float} value.
 166.578 +     * @param array the array
 166.579 +     * @param index the index into the array
 166.580 +     * @param f the new value of the indexed component
 166.581 +     * @exception NullPointerException If the specified object argument
 166.582 +     * is null
 166.583 +     * @exception IllegalArgumentException If the specified object argument
 166.584 +     * is not an array, or if the specified value cannot be converted
 166.585 +     * to the underlying array's component type by an identity or a
 166.586 +     * primitive widening conversion
 166.587 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.588 +     * argument is negative, or if it is greater than or equal to
 166.589 +     * the length of the specified array
 166.590 +     * @see Array#set
 166.591 +     */
 166.592 +    public static void setFloat(Object array, int index, float f)
 166.593 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.594 +        Class<?> t = array.getClass().getComponentType();
 166.595 +        if (t == Float.TYPE) {
 166.596 +            float[] arr = (float[])array;
 166.597 +            arr[index] = f;
 166.598 +        } else {
 166.599 +            setDouble(array, index, f);
 166.600 +        }
 166.601 +    }
 166.602 +
 166.603 +    /**
 166.604 +     * Sets the value of the indexed component of the specified array
 166.605 +     * object to the specified {@code double} value.
 166.606 +     * @param array the array
 166.607 +     * @param index the index into the array
 166.608 +     * @param d the new value of the indexed component
 166.609 +     * @exception NullPointerException If the specified object argument
 166.610 +     * is null
 166.611 +     * @exception IllegalArgumentException If the specified object argument
 166.612 +     * is not an array, or if the specified value cannot be converted
 166.613 +     * to the underlying array's component type by an identity or a
 166.614 +     * primitive widening conversion
 166.615 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 166.616 +     * argument is negative, or if it is greater than or equal to
 166.617 +     * the length of the specified array
 166.618 +     * @see Array#set
 166.619 +     */
 166.620 +    public static void setDouble(Object array, int index, double d)
 166.621 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 166.622 +        Class<?> t = array.getClass().getComponentType();
 166.623 +        if (t == Double.TYPE) {
 166.624 +            double[] arr = (double[])array;
 166.625 +            arr[index] = d;
 166.626 +        } else {
 166.627 +            throw new IllegalArgumentException("argument type mismatch");
 166.628 +        }
 166.629 +    }
 166.630 +
 166.631 +    /*
 166.632 +     * Private
 166.633 +     */
 166.634 +
 166.635 +    @JavaScriptBody(args = { "primitive", "sig", "length" }, body =
 166.636 +          "var arr = new Array(length);\n"
 166.637 +        + "var value = primitive ? 0 : null;\n"
 166.638 +        + "for(var i = 0; i < length; i++) arr[i] = value;\n"
 166.639 +        + "arr.jvmName = sig;\n"
 166.640 +        + "return arr;"
 166.641 +    )
 166.642 +    private static native Object newArray(boolean primitive, String sig, int length);
 166.643 +
 166.644 +    private static Object multiNewArray(String sig, int[] dims, int index)
 166.645 +    throws IllegalArgumentException, NegativeArraySizeException {
 166.646 +        if (dims.length == index + 1) {
 166.647 +            return newArray(sig.length() == 2, sig, dims[index]);
 166.648 +        }
 166.649 +        Object arr = newArray(false, sig, dims[index]);
 166.650 +        String compsig = sig.substring(1);
 166.651 +        int len = getLength(arr);
 166.652 +        for (int i = 0; i < len; i++) {
 166.653 +            setArray(arr, i, multiNewArray(compsig, dims, index + 1));
 166.654 +        }
 166.655 +        return arr;
 166.656 +    }
 166.657 +    private static Object fromPrimitive(Class<?> t, Object array, int index) {
 166.658 +        return Method.fromPrimitive(t, atArray(array, index));
 166.659 +    }
 166.660 +    
 166.661 +    @JavaScriptBody(args = { "array", "index" }, body = "return array[index];")
 166.662 +    private static native Object atArray(Object array, int index);
 166.663 +
 166.664 +    @JavaScriptBody(args = { "array", "index", "v" }, body = "array[index] = v;")
 166.665 +    private static native Object setArray(Object array, int index, Object v);
 166.666 +}
   167.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   167.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Field.java	Sun Feb 03 07:48:42 2013 +0100
   167.3 @@ -0,0 +1,953 @@
   167.4 +/*
   167.5 + * Copyright (c) 1996, 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.reflect;
  167.30 +
  167.31 +import java.lang.annotation.Annotation;
  167.32 +
  167.33 +
  167.34 +/**
  167.35 + * A {@code Field} provides information about, and dynamic access to, a
  167.36 + * single field of a class or an interface.  The reflected field may
  167.37 + * be a class (static) field or an instance field.
  167.38 + *
  167.39 + * <p>A {@code Field} permits widening conversions to occur during a get or
  167.40 + * set access operation, but throws an {@code IllegalArgumentException} if a
  167.41 + * narrowing conversion would occur.
  167.42 + *
  167.43 + * @see Member
  167.44 + * @see java.lang.Class
  167.45 + * @see java.lang.Class#getFields()
  167.46 + * @see java.lang.Class#getField(String)
  167.47 + * @see java.lang.Class#getDeclaredFields()
  167.48 + * @see java.lang.Class#getDeclaredField(String)
  167.49 + *
  167.50 + * @author Kenneth Russell
  167.51 + * @author Nakul Saraiya
  167.52 + */
  167.53 +public final
  167.54 +class Field extends AccessibleObject implements Member {
  167.55 +
  167.56 +    private Class<?>            clazz;
  167.57 +    private int                 slot;
  167.58 +    // This is guaranteed to be interned by the VM in the 1.4
  167.59 +    // reflection implementation
  167.60 +    private String              name;
  167.61 +    private Class<?>            type;
  167.62 +    private int                 modifiers;
  167.63 +    // Generics and annotations support
  167.64 +    private transient String    signature;
  167.65 +    private byte[]              annotations;
  167.66 +    // For sharing of FieldAccessors. This branching structure is
  167.67 +    // currently only two levels deep (i.e., one root Field and
  167.68 +    // potentially many Field objects pointing to it.)
  167.69 +    private Field               root;
  167.70 +
  167.71 +    // Generics infrastructure
  167.72 +
  167.73 +    private String getGenericSignature() {return signature;}
  167.74 +
  167.75 +
  167.76 +    /**
  167.77 +     * Package-private constructor used by ReflectAccess to enable
  167.78 +     * instantiation of these objects in Java code from the java.lang
  167.79 +     * package via sun.reflect.LangReflectAccess.
  167.80 +     */
  167.81 +    Field(Class<?> declaringClass,
  167.82 +          String name,
  167.83 +          Class<?> type,
  167.84 +          int modifiers,
  167.85 +          int slot,
  167.86 +          String signature,
  167.87 +          byte[] annotations)
  167.88 +    {
  167.89 +        this.clazz = declaringClass;
  167.90 +        this.name = name;
  167.91 +        this.type = type;
  167.92 +        this.modifiers = modifiers;
  167.93 +        this.slot = slot;
  167.94 +        this.signature = signature;
  167.95 +        this.annotations = annotations;
  167.96 +    }
  167.97 +
  167.98 +    /**
  167.99 +     * Package-private routine (exposed to java.lang.Class via
 167.100 +     * ReflectAccess) which returns a copy of this Field. The copy's
 167.101 +     * "root" field points to this Field.
 167.102 +     */
 167.103 +    Field copy() {
 167.104 +        // This routine enables sharing of FieldAccessor objects
 167.105 +        // among Field objects which refer to the same underlying
 167.106 +        // method in the VM. (All of this contortion is only necessary
 167.107 +        // because of the "accessibility" bit in AccessibleObject,
 167.108 +        // which implicitly requires that new java.lang.reflect
 167.109 +        // objects be fabricated for each reflective call on Class
 167.110 +        // objects.)
 167.111 +        Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
 167.112 +        res.root = this;
 167.113 +        return res;
 167.114 +    }
 167.115 +
 167.116 +    /**
 167.117 +     * Returns the {@code Class} object representing the class or interface
 167.118 +     * that declares the field represented by this {@code Field} object.
 167.119 +     */
 167.120 +    public Class<?> getDeclaringClass() {
 167.121 +        return clazz;
 167.122 +    }
 167.123 +
 167.124 +    /**
 167.125 +     * Returns the name of the field represented by this {@code Field} object.
 167.126 +     */
 167.127 +    public String getName() {
 167.128 +        return name;
 167.129 +    }
 167.130 +
 167.131 +    /**
 167.132 +     * Returns the Java language modifiers for the field represented
 167.133 +     * by this {@code Field} object, as an integer. The {@code Modifier} class should
 167.134 +     * be used to decode the modifiers.
 167.135 +     *
 167.136 +     * @see Modifier
 167.137 +     */
 167.138 +    public int getModifiers() {
 167.139 +        return modifiers;
 167.140 +    }
 167.141 +
 167.142 +    /**
 167.143 +     * Returns {@code true} if this field represents an element of
 167.144 +     * an enumerated type; returns {@code false} otherwise.
 167.145 +     *
 167.146 +     * @return {@code true} if and only if this field represents an element of
 167.147 +     * an enumerated type.
 167.148 +     * @since 1.5
 167.149 +     */
 167.150 +    public boolean isEnumConstant() {
 167.151 +        return (getModifiers() & Modifier.ENUM) != 0;
 167.152 +    }
 167.153 +
 167.154 +    /**
 167.155 +     * Returns {@code true} if this field is a synthetic
 167.156 +     * field; returns {@code false} otherwise.
 167.157 +     *
 167.158 +     * @return true if and only if this field is a synthetic
 167.159 +     * field as defined by the Java Language Specification.
 167.160 +     * @since 1.5
 167.161 +     */
 167.162 +    public boolean isSynthetic() {
 167.163 +        return Modifier.isSynthetic(getModifiers());
 167.164 +    }
 167.165 +
 167.166 +    /**
 167.167 +     * Returns a {@code Class} object that identifies the
 167.168 +     * declared type for the field represented by this
 167.169 +     * {@code Field} object.
 167.170 +     *
 167.171 +     * @return a {@code Class} object identifying the declared
 167.172 +     * type of the field represented by this object
 167.173 +     */
 167.174 +    public Class<?> getType() {
 167.175 +        return type;
 167.176 +    }
 167.177 +
 167.178 +    /**
 167.179 +     * Returns a {@code Type} object that represents the declared type for
 167.180 +     * the field represented by this {@code Field} object.
 167.181 +     *
 167.182 +     * <p>If the {@code Type} is a parameterized type, the
 167.183 +     * {@code Type} object returned must accurately reflect the
 167.184 +     * actual type parameters used in the source code.
 167.185 +     *
 167.186 +     * <p>If the type of the underlying field is a type variable or a
 167.187 +     * parameterized type, it is created. Otherwise, it is resolved.
 167.188 +     *
 167.189 +     * @return a {@code Type} object that represents the declared type for
 167.190 +     *     the field represented by this {@code Field} object
 167.191 +     * @throws GenericSignatureFormatError if the generic field
 167.192 +     *     signature does not conform to the format specified in
 167.193 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 167.194 +     * @throws TypeNotPresentException if the generic type
 167.195 +     *     signature of the underlying field refers to a non-existent
 167.196 +     *     type declaration
 167.197 +     * @throws MalformedParameterizedTypeException if the generic
 167.198 +     *     signature of the underlying field refers to a parameterized type
 167.199 +     *     that cannot be instantiated for any reason
 167.200 +     * @since 1.5
 167.201 +     */
 167.202 +    public Type getGenericType() {
 167.203 +        throw new UnsupportedOperationException();
 167.204 +    }
 167.205 +
 167.206 +
 167.207 +    /**
 167.208 +     * Compares this {@code Field} against the specified object.  Returns
 167.209 +     * true if the objects are the same.  Two {@code Field} objects are the same if
 167.210 +     * they were declared by the same class and have the same name
 167.211 +     * and type.
 167.212 +     */
 167.213 +    public boolean equals(Object obj) {
 167.214 +        if (obj != null && obj instanceof Field) {
 167.215 +            Field other = (Field)obj;
 167.216 +            return (getDeclaringClass() == other.getDeclaringClass())
 167.217 +                && (getName() == other.getName())
 167.218 +                && (getType() == other.getType());
 167.219 +        }
 167.220 +        return false;
 167.221 +    }
 167.222 +
 167.223 +    /**
 167.224 +     * Returns a hashcode for this {@code Field}.  This is computed as the
 167.225 +     * exclusive-or of the hashcodes for the underlying field's
 167.226 +     * declaring class name and its name.
 167.227 +     */
 167.228 +    public int hashCode() {
 167.229 +        return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
 167.230 +    }
 167.231 +
 167.232 +    /**
 167.233 +     * Returns a string describing this {@code Field}.  The format is
 167.234 +     * the access modifiers for the field, if any, followed
 167.235 +     * by the field type, followed by a space, followed by
 167.236 +     * the fully-qualified name of the class declaring the field,
 167.237 +     * followed by a period, followed by the name of the field.
 167.238 +     * For example:
 167.239 +     * <pre>
 167.240 +     *    public static final int java.lang.Thread.MIN_PRIORITY
 167.241 +     *    private int java.io.FileDescriptor.fd
 167.242 +     * </pre>
 167.243 +     *
 167.244 +     * <p>The modifiers are placed in canonical order as specified by
 167.245 +     * "The Java Language Specification".  This is {@code public},
 167.246 +     * {@code protected} or {@code private} first, and then other
 167.247 +     * modifiers in the following order: {@code static}, {@code final},
 167.248 +     * {@code transient}, {@code volatile}.
 167.249 +     */
 167.250 +    public String toString() {
 167.251 +        int mod = getModifiers();
 167.252 +        return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
 167.253 +            + getTypeName(getType()) + " "
 167.254 +            + getTypeName(getDeclaringClass()) + "."
 167.255 +            + getName());
 167.256 +    }
 167.257 +
 167.258 +    /**
 167.259 +     * Returns a string describing this {@code Field}, including
 167.260 +     * its generic type.  The format is the access modifiers for the
 167.261 +     * field, if any, followed by the generic field type, followed by
 167.262 +     * a space, followed by the fully-qualified name of the class
 167.263 +     * declaring the field, followed by a period, followed by the name
 167.264 +     * of the field.
 167.265 +     *
 167.266 +     * <p>The modifiers are placed in canonical order as specified by
 167.267 +     * "The Java Language Specification".  This is {@code public},
 167.268 +     * {@code protected} or {@code private} first, and then other
 167.269 +     * modifiers in the following order: {@code static}, {@code final},
 167.270 +     * {@code transient}, {@code volatile}.
 167.271 +     *
 167.272 +     * @return a string describing this {@code Field}, including
 167.273 +     * its generic type
 167.274 +     *
 167.275 +     * @since 1.5
 167.276 +     */
 167.277 +    public String toGenericString() {
 167.278 +        int mod = getModifiers();
 167.279 +        Type fieldType = getGenericType();
 167.280 +        return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
 167.281 +            +  ((fieldType instanceof Class) ?
 167.282 +                getTypeName((Class)fieldType): fieldType.toString())+ " "
 167.283 +            + getTypeName(getDeclaringClass()) + "."
 167.284 +            + getName());
 167.285 +    }
 167.286 +
 167.287 +    /**
 167.288 +     * Returns the value of the field represented by this {@code Field}, on
 167.289 +     * the specified object. The value is automatically wrapped in an
 167.290 +     * object if it has a primitive type.
 167.291 +     *
 167.292 +     * <p>The underlying field's value is obtained as follows:
 167.293 +     *
 167.294 +     * <p>If the underlying field is a static field, the {@code obj} argument
 167.295 +     * is ignored; it may be null.
 167.296 +     *
 167.297 +     * <p>Otherwise, the underlying field is an instance field.  If the
 167.298 +     * specified {@code obj} argument is null, the method throws a
 167.299 +     * {@code NullPointerException}. If the specified object is not an
 167.300 +     * instance of the class or interface declaring the underlying
 167.301 +     * field, the method throws an {@code IllegalArgumentException}.
 167.302 +     *
 167.303 +     * <p>If this {@code Field} object is enforcing Java language access control, and
 167.304 +     * the underlying field is inaccessible, the method throws an
 167.305 +     * {@code IllegalAccessException}.
 167.306 +     * If the underlying field is static, the class that declared the
 167.307 +     * field is initialized if it has not already been initialized.
 167.308 +     *
 167.309 +     * <p>Otherwise, the value is retrieved from the underlying instance
 167.310 +     * or static field.  If the field has a primitive type, the value
 167.311 +     * is wrapped in an object before being returned, otherwise it is
 167.312 +     * returned as is.
 167.313 +     *
 167.314 +     * <p>If the field is hidden in the type of {@code obj},
 167.315 +     * the field's value is obtained according to the preceding rules.
 167.316 +     *
 167.317 +     * @param obj object from which the represented field's value is
 167.318 +     * to be extracted
 167.319 +     * @return the value of the represented field in object
 167.320 +     * {@code obj}; primitive values are wrapped in an appropriate
 167.321 +     * object before being returned
 167.322 +     *
 167.323 +     * @exception IllegalAccessException    if this {@code Field} object
 167.324 +     *              is enforcing Java language access control and the underlying
 167.325 +     *              field is inaccessible.
 167.326 +     * @exception IllegalArgumentException  if the specified object is not an
 167.327 +     *              instance of the class or interface declaring the underlying
 167.328 +     *              field (or a subclass or implementor thereof).
 167.329 +     * @exception NullPointerException      if the specified object is null
 167.330 +     *              and the field is an instance field.
 167.331 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.332 +     *              by this method fails.
 167.333 +     */
 167.334 +    public Object get(Object obj)
 167.335 +        throws IllegalArgumentException, IllegalAccessException
 167.336 +    {
 167.337 +        return getFieldAccessor(obj).get(obj);
 167.338 +    }
 167.339 +
 167.340 +    /**
 167.341 +     * Gets the value of a static or instance {@code boolean} field.
 167.342 +     *
 167.343 +     * @param obj the object to extract the {@code boolean} value
 167.344 +     * from
 167.345 +     * @return the value of the {@code boolean} field
 167.346 +     *
 167.347 +     * @exception IllegalAccessException    if this {@code Field} object
 167.348 +     *              is enforcing Java language access control and the underlying
 167.349 +     *              field is inaccessible.
 167.350 +     * @exception IllegalArgumentException  if the specified object is not
 167.351 +     *              an instance of the class or interface declaring the
 167.352 +     *              underlying field (or a subclass or implementor
 167.353 +     *              thereof), or if the field value cannot be
 167.354 +     *              converted to the type {@code boolean} by a
 167.355 +     *              widening conversion.
 167.356 +     * @exception NullPointerException      if the specified object is null
 167.357 +     *              and the field is an instance field.
 167.358 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.359 +     *              by this method fails.
 167.360 +     * @see       Field#get
 167.361 +     */
 167.362 +    public boolean getBoolean(Object obj)
 167.363 +        throws IllegalArgumentException, IllegalAccessException
 167.364 +    {
 167.365 +        return getFieldAccessor(obj).getBoolean(obj);
 167.366 +    }
 167.367 +
 167.368 +    /**
 167.369 +     * Gets the value of a static or instance {@code byte} field.
 167.370 +     *
 167.371 +     * @param obj the object to extract the {@code byte} value
 167.372 +     * from
 167.373 +     * @return the value of the {@code byte} field
 167.374 +     *
 167.375 +     * @exception IllegalAccessException    if this {@code Field} object
 167.376 +     *              is enforcing Java language access control and the underlying
 167.377 +     *              field is inaccessible.
 167.378 +     * @exception IllegalArgumentException  if the specified object is not
 167.379 +     *              an instance of the class or interface declaring the
 167.380 +     *              underlying field (or a subclass or implementor
 167.381 +     *              thereof), or if the field value cannot be
 167.382 +     *              converted to the type {@code byte} by a
 167.383 +     *              widening conversion.
 167.384 +     * @exception NullPointerException      if the specified object is null
 167.385 +     *              and the field is an instance field.
 167.386 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.387 +     *              by this method fails.
 167.388 +     * @see       Field#get
 167.389 +     */
 167.390 +    public byte getByte(Object obj)
 167.391 +        throws IllegalArgumentException, IllegalAccessException
 167.392 +    {
 167.393 +        return getFieldAccessor(obj).getByte(obj);
 167.394 +    }
 167.395 +
 167.396 +    /**
 167.397 +     * Gets the value of a static or instance field of type
 167.398 +     * {@code char} or of another primitive type convertible to
 167.399 +     * type {@code char} via a widening conversion.
 167.400 +     *
 167.401 +     * @param obj the object to extract the {@code char} value
 167.402 +     * from
 167.403 +     * @return the value of the field converted to type {@code char}
 167.404 +     *
 167.405 +     * @exception IllegalAccessException    if this {@code Field} object
 167.406 +     *              is enforcing Java language access control and the underlying
 167.407 +     *              field is inaccessible.
 167.408 +     * @exception IllegalArgumentException  if the specified object is not
 167.409 +     *              an instance of the class or interface declaring the
 167.410 +     *              underlying field (or a subclass or implementor
 167.411 +     *              thereof), or if the field value cannot be
 167.412 +     *              converted to the type {@code char} by a
 167.413 +     *              widening conversion.
 167.414 +     * @exception NullPointerException      if the specified object is null
 167.415 +     *              and the field is an instance field.
 167.416 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.417 +     *              by this method fails.
 167.418 +     * @see Field#get
 167.419 +     */
 167.420 +    public char getChar(Object obj)
 167.421 +        throws IllegalArgumentException, IllegalAccessException
 167.422 +    {
 167.423 +        return getFieldAccessor(obj).getChar(obj);
 167.424 +    }
 167.425 +
 167.426 +    /**
 167.427 +     * Gets the value of a static or instance field of type
 167.428 +     * {@code short} or of another primitive type convertible to
 167.429 +     * type {@code short} via a widening conversion.
 167.430 +     *
 167.431 +     * @param obj the object to extract the {@code short} value
 167.432 +     * from
 167.433 +     * @return the value of the field converted to type {@code short}
 167.434 +     *
 167.435 +     * @exception IllegalAccessException    if this {@code Field} object
 167.436 +     *              is enforcing Java language access control and the underlying
 167.437 +     *              field is inaccessible.
 167.438 +     * @exception IllegalArgumentException  if the specified object is not
 167.439 +     *              an instance of the class or interface declaring the
 167.440 +     *              underlying field (or a subclass or implementor
 167.441 +     *              thereof), or if the field value cannot be
 167.442 +     *              converted to the type {@code short} by a
 167.443 +     *              widening conversion.
 167.444 +     * @exception NullPointerException      if the specified object is null
 167.445 +     *              and the field is an instance field.
 167.446 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.447 +     *              by this method fails.
 167.448 +     * @see       Field#get
 167.449 +     */
 167.450 +    public short getShort(Object obj)
 167.451 +        throws IllegalArgumentException, IllegalAccessException
 167.452 +    {
 167.453 +        return getFieldAccessor(obj).getShort(obj);
 167.454 +    }
 167.455 +
 167.456 +    /**
 167.457 +     * Gets the value of a static or instance field of type
 167.458 +     * {@code int} or of another primitive type convertible to
 167.459 +     * type {@code int} via a widening conversion.
 167.460 +     *
 167.461 +     * @param obj the object to extract the {@code int} value
 167.462 +     * from
 167.463 +     * @return the value of the field converted to type {@code int}
 167.464 +     *
 167.465 +     * @exception IllegalAccessException    if this {@code Field} object
 167.466 +     *              is enforcing Java language access control and the underlying
 167.467 +     *              field is inaccessible.
 167.468 +     * @exception IllegalArgumentException  if the specified object is not
 167.469 +     *              an instance of the class or interface declaring the
 167.470 +     *              underlying field (or a subclass or implementor
 167.471 +     *              thereof), or if the field value cannot be
 167.472 +     *              converted to the type {@code int} by a
 167.473 +     *              widening conversion.
 167.474 +     * @exception NullPointerException      if the specified object is null
 167.475 +     *              and the field is an instance field.
 167.476 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.477 +     *              by this method fails.
 167.478 +     * @see       Field#get
 167.479 +     */
 167.480 +    public int getInt(Object obj)
 167.481 +        throws IllegalArgumentException, IllegalAccessException
 167.482 +    {
 167.483 +        return getFieldAccessor(obj).getInt(obj);
 167.484 +    }
 167.485 +
 167.486 +    /**
 167.487 +     * Gets the value of a static or instance field of type
 167.488 +     * {@code long} or of another primitive type convertible to
 167.489 +     * type {@code long} via a widening conversion.
 167.490 +     *
 167.491 +     * @param obj the object to extract the {@code long} value
 167.492 +     * from
 167.493 +     * @return the value of the field converted to type {@code long}
 167.494 +     *
 167.495 +     * @exception IllegalAccessException    if this {@code Field} object
 167.496 +     *              is enforcing Java language access control and the underlying
 167.497 +     *              field is inaccessible.
 167.498 +     * @exception IllegalArgumentException  if the specified object is not
 167.499 +     *              an instance of the class or interface declaring the
 167.500 +     *              underlying field (or a subclass or implementor
 167.501 +     *              thereof), or if the field value cannot be
 167.502 +     *              converted to the type {@code long} by a
 167.503 +     *              widening conversion.
 167.504 +     * @exception NullPointerException      if the specified object is null
 167.505 +     *              and the field is an instance field.
 167.506 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.507 +     *              by this method fails.
 167.508 +     * @see       Field#get
 167.509 +     */
 167.510 +    public long getLong(Object obj)
 167.511 +        throws IllegalArgumentException, IllegalAccessException
 167.512 +    {
 167.513 +        return getFieldAccessor(obj).getLong(obj);
 167.514 +    }
 167.515 +
 167.516 +    /**
 167.517 +     * Gets the value of a static or instance field of type
 167.518 +     * {@code float} or of another primitive type convertible to
 167.519 +     * type {@code float} via a widening conversion.
 167.520 +     *
 167.521 +     * @param obj the object to extract the {@code float} value
 167.522 +     * from
 167.523 +     * @return the value of the field converted to type {@code float}
 167.524 +     *
 167.525 +     * @exception IllegalAccessException    if this {@code Field} object
 167.526 +     *              is enforcing Java language access control and the underlying
 167.527 +     *              field is inaccessible.
 167.528 +     * @exception IllegalArgumentException  if the specified object is not
 167.529 +     *              an instance of the class or interface declaring the
 167.530 +     *              underlying field (or a subclass or implementor
 167.531 +     *              thereof), or if the field value cannot be
 167.532 +     *              converted to the type {@code float} by a
 167.533 +     *              widening conversion.
 167.534 +     * @exception NullPointerException      if the specified object is null
 167.535 +     *              and the field is an instance field.
 167.536 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.537 +     *              by this method fails.
 167.538 +     * @see Field#get
 167.539 +     */
 167.540 +    public float getFloat(Object obj)
 167.541 +        throws IllegalArgumentException, IllegalAccessException
 167.542 +    {
 167.543 +        return getFieldAccessor(obj).getFloat(obj);
 167.544 +    }
 167.545 +
 167.546 +    /**
 167.547 +     * Gets the value of a static or instance field of type
 167.548 +     * {@code double} or of another primitive type convertible to
 167.549 +     * type {@code double} via a widening conversion.
 167.550 +     *
 167.551 +     * @param obj the object to extract the {@code double} value
 167.552 +     * from
 167.553 +     * @return the value of the field converted to type {@code double}
 167.554 +     *
 167.555 +     * @exception IllegalAccessException    if this {@code Field} object
 167.556 +     *              is enforcing Java language access control and the underlying
 167.557 +     *              field is inaccessible.
 167.558 +     * @exception IllegalArgumentException  if the specified object is not
 167.559 +     *              an instance of the class or interface declaring the
 167.560 +     *              underlying field (or a subclass or implementor
 167.561 +     *              thereof), or if the field value cannot be
 167.562 +     *              converted to the type {@code double} by a
 167.563 +     *              widening conversion.
 167.564 +     * @exception NullPointerException      if the specified object is null
 167.565 +     *              and the field is an instance field.
 167.566 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.567 +     *              by this method fails.
 167.568 +     * @see       Field#get
 167.569 +     */
 167.570 +    public double getDouble(Object obj)
 167.571 +        throws IllegalArgumentException, IllegalAccessException
 167.572 +    {
 167.573 +        return getFieldAccessor(obj).getDouble(obj);
 167.574 +    }
 167.575 +
 167.576 +    /**
 167.577 +     * Sets the field represented by this {@code Field} object on the
 167.578 +     * specified object argument to the specified new value. The new
 167.579 +     * value is automatically unwrapped if the underlying field has a
 167.580 +     * primitive type.
 167.581 +     *
 167.582 +     * <p>The operation proceeds as follows:
 167.583 +     *
 167.584 +     * <p>If the underlying field is static, the {@code obj} argument is
 167.585 +     * ignored; it may be null.
 167.586 +     *
 167.587 +     * <p>Otherwise the underlying field is an instance field.  If the
 167.588 +     * specified object argument is null, the method throws a
 167.589 +     * {@code NullPointerException}.  If the specified object argument is not
 167.590 +     * an instance of the class or interface declaring the underlying
 167.591 +     * field, the method throws an {@code IllegalArgumentException}.
 167.592 +     *
 167.593 +     * <p>If this {@code Field} object is enforcing Java language access control, and
 167.594 +     * the underlying field is inaccessible, the method throws an
 167.595 +     * {@code IllegalAccessException}.
 167.596 +     *
 167.597 +     * <p>If the underlying field is final, the method throws an
 167.598 +     * {@code IllegalAccessException} unless {@code setAccessible(true)}
 167.599 +     * has succeeded for this {@code Field} object
 167.600 +     * and the field is non-static. Setting a final field in this way
 167.601 +     * is meaningful only during deserialization or reconstruction of
 167.602 +     * instances of classes with blank final fields, before they are
 167.603 +     * made available for access by other parts of a program. Use in
 167.604 +     * any other context may have unpredictable effects, including cases
 167.605 +     * in which other parts of a program continue to use the original
 167.606 +     * value of this field.
 167.607 +     *
 167.608 +     * <p>If the underlying field is of a primitive type, an unwrapping
 167.609 +     * conversion is attempted to convert the new value to a value of
 167.610 +     * a primitive type.  If this attempt fails, the method throws an
 167.611 +     * {@code IllegalArgumentException}.
 167.612 +     *
 167.613 +     * <p>If, after possible unwrapping, the new value cannot be
 167.614 +     * converted to the type of the underlying field by an identity or
 167.615 +     * widening conversion, the method throws an
 167.616 +     * {@code IllegalArgumentException}.
 167.617 +     *
 167.618 +     * <p>If the underlying field is static, the class that declared the
 167.619 +     * field is initialized if it has not already been initialized.
 167.620 +     *
 167.621 +     * <p>The field is set to the possibly unwrapped and widened new value.
 167.622 +     *
 167.623 +     * <p>If the field is hidden in the type of {@code obj},
 167.624 +     * the field's value is set according to the preceding rules.
 167.625 +     *
 167.626 +     * @param obj the object whose field should be modified
 167.627 +     * @param value the new value for the field of {@code obj}
 167.628 +     * being modified
 167.629 +     *
 167.630 +     * @exception IllegalAccessException    if this {@code Field} object
 167.631 +     *              is enforcing Java language access control and the underlying
 167.632 +     *              field is either inaccessible or final.
 167.633 +     * @exception IllegalArgumentException  if the specified object is not an
 167.634 +     *              instance of the class or interface declaring the underlying
 167.635 +     *              field (or a subclass or implementor thereof),
 167.636 +     *              or if an unwrapping conversion fails.
 167.637 +     * @exception NullPointerException      if the specified object is null
 167.638 +     *              and the field is an instance field.
 167.639 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.640 +     *              by this method fails.
 167.641 +     */
 167.642 +    public void set(Object obj, Object value)
 167.643 +        throws IllegalArgumentException, IllegalAccessException
 167.644 +    {
 167.645 +        getFieldAccessor(obj).set(obj, value);
 167.646 +    }
 167.647 +
 167.648 +    /**
 167.649 +     * Sets the value of a field as a {@code boolean} on the specified object.
 167.650 +     * This method is equivalent to
 167.651 +     * {@code set(obj, zObj)},
 167.652 +     * where {@code zObj} is a {@code Boolean} object and
 167.653 +     * {@code zObj.booleanValue() == z}.
 167.654 +     *
 167.655 +     * @param obj the object whose field should be modified
 167.656 +     * @param z   the new value for the field of {@code obj}
 167.657 +     * being modified
 167.658 +     *
 167.659 +     * @exception IllegalAccessException    if this {@code Field} object
 167.660 +     *              is enforcing Java language access control and the underlying
 167.661 +     *              field is either inaccessible or final.
 167.662 +     * @exception IllegalArgumentException  if the specified object is not an
 167.663 +     *              instance of the class or interface declaring the underlying
 167.664 +     *              field (or a subclass or implementor thereof),
 167.665 +     *              or if an unwrapping conversion fails.
 167.666 +     * @exception NullPointerException      if the specified object is null
 167.667 +     *              and the field is an instance field.
 167.668 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.669 +     *              by this method fails.
 167.670 +     * @see       Field#set
 167.671 +     */
 167.672 +    public void setBoolean(Object obj, boolean z)
 167.673 +        throws IllegalArgumentException, IllegalAccessException
 167.674 +    {
 167.675 +        getFieldAccessor(obj).setBoolean(obj, z);
 167.676 +    }
 167.677 +
 167.678 +    /**
 167.679 +     * Sets the value of a field as a {@code byte} on the specified object.
 167.680 +     * This method is equivalent to
 167.681 +     * {@code set(obj, bObj)},
 167.682 +     * where {@code bObj} is a {@code Byte} object and
 167.683 +     * {@code bObj.byteValue() == b}.
 167.684 +     *
 167.685 +     * @param obj the object whose field should be modified
 167.686 +     * @param b   the new value for the field of {@code obj}
 167.687 +     * being modified
 167.688 +     *
 167.689 +     * @exception IllegalAccessException    if this {@code Field} object
 167.690 +     *              is enforcing Java language access control and the underlying
 167.691 +     *              field is either inaccessible or final.
 167.692 +     * @exception IllegalArgumentException  if the specified object is not an
 167.693 +     *              instance of the class or interface declaring the underlying
 167.694 +     *              field (or a subclass or implementor thereof),
 167.695 +     *              or if an unwrapping conversion fails.
 167.696 +     * @exception NullPointerException      if the specified object is null
 167.697 +     *              and the field is an instance field.
 167.698 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.699 +     *              by this method fails.
 167.700 +     * @see       Field#set
 167.701 +     */
 167.702 +    public void setByte(Object obj, byte b)
 167.703 +        throws IllegalArgumentException, IllegalAccessException
 167.704 +    {
 167.705 +        getFieldAccessor(obj).setByte(obj, b);
 167.706 +    }
 167.707 +
 167.708 +    /**
 167.709 +     * Sets the value of a field as a {@code char} on the specified object.
 167.710 +     * This method is equivalent to
 167.711 +     * {@code set(obj, cObj)},
 167.712 +     * where {@code cObj} is a {@code Character} object and
 167.713 +     * {@code cObj.charValue() == c}.
 167.714 +     *
 167.715 +     * @param obj the object whose field should be modified
 167.716 +     * @param c   the new value for the field of {@code obj}
 167.717 +     * being modified
 167.718 +     *
 167.719 +     * @exception IllegalAccessException    if this {@code Field} object
 167.720 +     *              is enforcing Java language access control and the underlying
 167.721 +     *              field is either inaccessible or final.
 167.722 +     * @exception IllegalArgumentException  if the specified object is not an
 167.723 +     *              instance of the class or interface declaring the underlying
 167.724 +     *              field (or a subclass or implementor thereof),
 167.725 +     *              or if an unwrapping conversion fails.
 167.726 +     * @exception NullPointerException      if the specified object is null
 167.727 +     *              and the field is an instance field.
 167.728 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.729 +     *              by this method fails.
 167.730 +     * @see       Field#set
 167.731 +     */
 167.732 +    public void setChar(Object obj, char c)
 167.733 +        throws IllegalArgumentException, IllegalAccessException
 167.734 +    {
 167.735 +        getFieldAccessor(obj).setChar(obj, c);
 167.736 +    }
 167.737 +
 167.738 +    /**
 167.739 +     * Sets the value of a field as a {@code short} on the specified object.
 167.740 +     * This method is equivalent to
 167.741 +     * {@code set(obj, sObj)},
 167.742 +     * where {@code sObj} is a {@code Short} object and
 167.743 +     * {@code sObj.shortValue() == s}.
 167.744 +     *
 167.745 +     * @param obj the object whose field should be modified
 167.746 +     * @param s   the new value for the field of {@code obj}
 167.747 +     * being modified
 167.748 +     *
 167.749 +     * @exception IllegalAccessException    if this {@code Field} object
 167.750 +     *              is enforcing Java language access control and the underlying
 167.751 +     *              field is either inaccessible or final.
 167.752 +     * @exception IllegalArgumentException  if the specified object is not an
 167.753 +     *              instance of the class or interface declaring the underlying
 167.754 +     *              field (or a subclass or implementor thereof),
 167.755 +     *              or if an unwrapping conversion fails.
 167.756 +     * @exception NullPointerException      if the specified object is null
 167.757 +     *              and the field is an instance field.
 167.758 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.759 +     *              by this method fails.
 167.760 +     * @see       Field#set
 167.761 +     */
 167.762 +    public void setShort(Object obj, short s)
 167.763 +        throws IllegalArgumentException, IllegalAccessException
 167.764 +    {
 167.765 +        getFieldAccessor(obj).setShort(obj, s);
 167.766 +    }
 167.767 +
 167.768 +    /**
 167.769 +     * Sets the value of a field as an {@code int} on the specified object.
 167.770 +     * This method is equivalent to
 167.771 +     * {@code set(obj, iObj)},
 167.772 +     * where {@code iObj} is a {@code Integer} object and
 167.773 +     * {@code iObj.intValue() == i}.
 167.774 +     *
 167.775 +     * @param obj the object whose field should be modified
 167.776 +     * @param i   the new value for the field of {@code obj}
 167.777 +     * being modified
 167.778 +     *
 167.779 +     * @exception IllegalAccessException    if this {@code Field} object
 167.780 +     *              is enforcing Java language access control and the underlying
 167.781 +     *              field is either inaccessible or final.
 167.782 +     * @exception IllegalArgumentException  if the specified object is not an
 167.783 +     *              instance of the class or interface declaring the underlying
 167.784 +     *              field (or a subclass or implementor thereof),
 167.785 +     *              or if an unwrapping conversion fails.
 167.786 +     * @exception NullPointerException      if the specified object is null
 167.787 +     *              and the field is an instance field.
 167.788 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.789 +     *              by this method fails.
 167.790 +     * @see       Field#set
 167.791 +     */
 167.792 +    public void setInt(Object obj, int i)
 167.793 +        throws IllegalArgumentException, IllegalAccessException
 167.794 +    {
 167.795 +        getFieldAccessor(obj).setInt(obj, i);
 167.796 +    }
 167.797 +
 167.798 +    /**
 167.799 +     * Sets the value of a field as a {@code long} on the specified object.
 167.800 +     * This method is equivalent to
 167.801 +     * {@code set(obj, lObj)},
 167.802 +     * where {@code lObj} is a {@code Long} object and
 167.803 +     * {@code lObj.longValue() == l}.
 167.804 +     *
 167.805 +     * @param obj the object whose field should be modified
 167.806 +     * @param l   the new value for the field of {@code obj}
 167.807 +     * being modified
 167.808 +     *
 167.809 +     * @exception IllegalAccessException    if this {@code Field} object
 167.810 +     *              is enforcing Java language access control and the underlying
 167.811 +     *              field is either inaccessible or final.
 167.812 +     * @exception IllegalArgumentException  if the specified object is not an
 167.813 +     *              instance of the class or interface declaring the underlying
 167.814 +     *              field (or a subclass or implementor thereof),
 167.815 +     *              or if an unwrapping conversion fails.
 167.816 +     * @exception NullPointerException      if the specified object is null
 167.817 +     *              and the field is an instance field.
 167.818 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.819 +     *              by this method fails.
 167.820 +     * @see       Field#set
 167.821 +     */
 167.822 +    public void setLong(Object obj, long l)
 167.823 +        throws IllegalArgumentException, IllegalAccessException
 167.824 +    {
 167.825 +        getFieldAccessor(obj).setLong(obj, l);
 167.826 +    }
 167.827 +
 167.828 +    /**
 167.829 +     * Sets the value of a field as a {@code float} on the specified object.
 167.830 +     * This method is equivalent to
 167.831 +     * {@code set(obj, fObj)},
 167.832 +     * where {@code fObj} is a {@code Float} object and
 167.833 +     * {@code fObj.floatValue() == f}.
 167.834 +     *
 167.835 +     * @param obj the object whose field should be modified
 167.836 +     * @param f   the new value for the field of {@code obj}
 167.837 +     * being modified
 167.838 +     *
 167.839 +     * @exception IllegalAccessException    if this {@code Field} object
 167.840 +     *              is enforcing Java language access control and the underlying
 167.841 +     *              field is either inaccessible or final.
 167.842 +     * @exception IllegalArgumentException  if the specified object is not an
 167.843 +     *              instance of the class or interface declaring the underlying
 167.844 +     *              field (or a subclass or implementor thereof),
 167.845 +     *              or if an unwrapping conversion fails.
 167.846 +     * @exception NullPointerException      if the specified object is null
 167.847 +     *              and the field is an instance field.
 167.848 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.849 +     *              by this method fails.
 167.850 +     * @see       Field#set
 167.851 +     */
 167.852 +    public void setFloat(Object obj, float f)
 167.853 +        throws IllegalArgumentException, IllegalAccessException
 167.854 +    {
 167.855 +        getFieldAccessor(obj).setFloat(obj, f);
 167.856 +    }
 167.857 +
 167.858 +    /**
 167.859 +     * Sets the value of a field as a {@code double} on the specified object.
 167.860 +     * This method is equivalent to
 167.861 +     * {@code set(obj, dObj)},
 167.862 +     * where {@code dObj} is a {@code Double} object and
 167.863 +     * {@code dObj.doubleValue() == d}.
 167.864 +     *
 167.865 +     * @param obj the object whose field should be modified
 167.866 +     * @param d   the new value for the field of {@code obj}
 167.867 +     * being modified
 167.868 +     *
 167.869 +     * @exception IllegalAccessException    if this {@code Field} object
 167.870 +     *              is enforcing Java language access control and the underlying
 167.871 +     *              field is either inaccessible or final.
 167.872 +     * @exception IllegalArgumentException  if the specified object is not an
 167.873 +     *              instance of the class or interface declaring the underlying
 167.874 +     *              field (or a subclass or implementor thereof),
 167.875 +     *              or if an unwrapping conversion fails.
 167.876 +     * @exception NullPointerException      if the specified object is null
 167.877 +     *              and the field is an instance field.
 167.878 +     * @exception ExceptionInInitializerError if the initialization provoked
 167.879 +     *              by this method fails.
 167.880 +     * @see       Field#set
 167.881 +     */
 167.882 +    public void setDouble(Object obj, double d)
 167.883 +        throws IllegalArgumentException, IllegalAccessException
 167.884 +    {
 167.885 +        getFieldAccessor(obj).setDouble(obj, d);
 167.886 +    }
 167.887 +
 167.888 +    // Convenience routine which performs security checks
 167.889 +    private FieldAccessor getFieldAccessor(Object obj)
 167.890 +        throws IllegalAccessException
 167.891 +    {
 167.892 +        throw new SecurityException();
 167.893 +    }
 167.894 +    
 167.895 +    private static abstract class FieldAccessor {
 167.896 +        abstract void setShort(Object obj, short s);
 167.897 +        abstract void setInt(Object obj, int i);
 167.898 +        abstract void setChar(Object obj, char c);
 167.899 +        abstract void setByte(Object obj, byte b);
 167.900 +        abstract void setBoolean(Object obj, boolean z);
 167.901 +        abstract void set(Object obj, Object value);
 167.902 +        abstract double getDouble(Object obj);
 167.903 +        abstract void setLong(Object obj, long l);
 167.904 +        abstract void setFloat(Object obj, float f);
 167.905 +        abstract void setDouble(Object obj, double d);
 167.906 +        abstract long getLong(Object obj);
 167.907 +        abstract int getInt(Object obj);
 167.908 +        abstract short getShort(Object obj);
 167.909 +        abstract char getChar(Object obj);
 167.910 +        abstract byte getByte(Object obj);
 167.911 +        abstract boolean getBoolean(Object obj);
 167.912 +        abstract Object get(Object obj);
 167.913 +        abstract float getFloat(Object obj);
 167.914 +    }
 167.915 +
 167.916 +    /*
 167.917 +     * Utility routine to paper over array type names
 167.918 +     */
 167.919 +    static String getTypeName(Class<?> type) {
 167.920 +        if (type.isArray()) {
 167.921 +            try {
 167.922 +                Class<?> cl = type;
 167.923 +                int dimensions = 0;
 167.924 +                while (cl.isArray()) {
 167.925 +                    dimensions++;
 167.926 +                    cl = cl.getComponentType();
 167.927 +                }
 167.928 +                StringBuffer sb = new StringBuffer();
 167.929 +                sb.append(cl.getName());
 167.930 +                for (int i = 0; i < dimensions; i++) {
 167.931 +                    sb.append("[]");
 167.932 +                }
 167.933 +                return sb.toString();
 167.934 +            } catch (Throwable e) { /*FALLTHRU*/ }
 167.935 +        }
 167.936 +        return type.getName();
 167.937 +    }
 167.938 +
 167.939 +    /**
 167.940 +     * @throws NullPointerException {@inheritDoc}
 167.941 +     * @since 1.5
 167.942 +     */
 167.943 +    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 167.944 +        if (annotationClass == null)
 167.945 +            throw new NullPointerException();
 167.946 +
 167.947 +        throw new UnsupportedOperationException();
 167.948 +    }
 167.949 +
 167.950 +    /**
 167.951 +     * @since 1.5
 167.952 +     */
 167.953 +    public Annotation[] getDeclaredAnnotations()  {
 167.954 +        throw new UnsupportedOperationException();
 167.955 +    }
 167.956 +}
   168.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   168.2 +++ b/emul/mini/src/main/java/java/lang/reflect/GenericDeclaration.java	Sun Feb 03 07:48:42 2013 +0100
   168.3 @@ -0,0 +1,49 @@
   168.4 +/*
   168.5 + * Copyright (c) 2003, 2004, 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 +/**
  168.32 + * A common interface for all entities that declare type variables.
  168.33 + *
  168.34 + * @since 1.5
  168.35 + */
  168.36 +public interface GenericDeclaration {
  168.37 +    /**
  168.38 +     * Returns an array of {@code TypeVariable} objects that
  168.39 +     * represent the type variables declared by the generic
  168.40 +     * declaration represented by this {@code GenericDeclaration}
  168.41 +     * object, in declaration order.  Returns an array of length 0 if
  168.42 +     * the underlying generic declaration declares no type variables.
  168.43 +     *
  168.44 +     * @return an array of {@code TypeVariable} objects that represent
  168.45 +     *     the type variables declared by this generic declaration
  168.46 +     * @throws GenericSignatureFormatError if the generic
  168.47 +     *     signature of this generic declaration does not conform to
  168.48 +     *     the format specified in
  168.49 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
  168.50 +     */
  168.51 +    public TypeVariable<?>[] getTypeParameters();
  168.52 +}
   169.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   169.2 +++ b/emul/mini/src/main/java/java/lang/reflect/InvocationTargetException.java	Sun Feb 03 07:48:42 2013 +0100
   169.3 @@ -0,0 +1,111 @@
   169.4 +/*
   169.5 + * Copyright (c) 1996, 2004, 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 +/**
  169.32 + * InvocationTargetException is a checked exception that wraps
  169.33 + * an exception thrown by an invoked method or constructor.
  169.34 + *
  169.35 + * <p>As of release 1.4, this exception has been retrofitted to conform to
  169.36 + * the general purpose exception-chaining mechanism.  The "target exception"
  169.37 + * that is provided at construction time and accessed via the
  169.38 + * {@link #getTargetException()} method is now known as the <i>cause</i>,
  169.39 + * and may be accessed via the {@link Throwable#getCause()} method,
  169.40 + * as well as the aforementioned "legacy method."
  169.41 + *
  169.42 + * @see Method
  169.43 + * @see Constructor
  169.44 + */
  169.45 +public class InvocationTargetException extends ReflectiveOperationException {
  169.46 +    /**
  169.47 +     * Use serialVersionUID from JDK 1.1.X for interoperability
  169.48 +     */
  169.49 +    private static final long serialVersionUID = 4085088731926701167L;
  169.50 +
  169.51 +     /**
  169.52 +     * This field holds the target if the
  169.53 +     * InvocationTargetException(Throwable target) constructor was
  169.54 +     * used to instantiate the object
  169.55 +     *
  169.56 +     * @serial
  169.57 +     *
  169.58 +     */
  169.59 +    private Throwable target;
  169.60 +
  169.61 +    /**
  169.62 +     * Constructs an {@code InvocationTargetException} with
  169.63 +     * {@code null} as the target exception.
  169.64 +     */
  169.65 +    protected InvocationTargetException() {
  169.66 +        super((Throwable)null);  // Disallow initCause
  169.67 +    }
  169.68 +
  169.69 +    /**
  169.70 +     * Constructs a InvocationTargetException with a target exception.
  169.71 +     *
  169.72 +     * @param target the target exception
  169.73 +     */
  169.74 +    public InvocationTargetException(Throwable target) {
  169.75 +        super((Throwable)null);  // Disallow initCause
  169.76 +        this.target = target;
  169.77 +    }
  169.78 +
  169.79 +    /**
  169.80 +     * Constructs a InvocationTargetException with a target exception
  169.81 +     * and a detail message.
  169.82 +     *
  169.83 +     * @param target the target exception
  169.84 +     * @param s      the detail message
  169.85 +     */
  169.86 +    public InvocationTargetException(Throwable target, String s) {
  169.87 +        super(s, null);  // Disallow initCause
  169.88 +        this.target = target;
  169.89 +    }
  169.90 +
  169.91 +    /**
  169.92 +     * Get the thrown target exception.
  169.93 +     *
  169.94 +     * <p>This method predates the general-purpose exception chaining facility.
  169.95 +     * The {@link Throwable#getCause()} method is now the preferred means of
  169.96 +     * obtaining this information.
  169.97 +     *
  169.98 +     * @return the thrown target exception (cause of this exception).
  169.99 +     */
 169.100 +    public Throwable getTargetException() {
 169.101 +        return target;
 169.102 +    }
 169.103 +
 169.104 +    /**
 169.105 +     * Returns the cause of this exception (the thrown target exception,
 169.106 +     * which may be {@code null}).
 169.107 +     *
 169.108 +     * @return  the cause of this exception.
 169.109 +     * @since   1.4
 169.110 +     */
 169.111 +    public Throwable getCause() {
 169.112 +        return target;
 169.113 +    }
 169.114 +}
   170.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   170.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Member.java	Sun Feb 03 07:48:42 2013 +0100
   170.3 @@ -0,0 +1,93 @@
   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 +/**
  170.32 + * Member is an interface that reflects identifying information about
  170.33 + * a single member (a field or a method) or a constructor.
  170.34 + *
  170.35 + * @see java.lang.Class
  170.36 + * @see Field
  170.37 + * @see Method
  170.38 + * @see Constructor
  170.39 + *
  170.40 + * @author Nakul Saraiya
  170.41 + */
  170.42 +public
  170.43 +interface Member {
  170.44 +
  170.45 +    /**
  170.46 +     * Identifies the set of all public members of a class or interface,
  170.47 +     * including inherited members.
  170.48 +     * @see java.lang.SecurityManager#checkMemberAccess
  170.49 +     */
  170.50 +    public static final int PUBLIC = 0;
  170.51 +
  170.52 +    /**
  170.53 +     * Identifies the set of declared members of a class or interface.
  170.54 +     * Inherited members are not included.
  170.55 +     * @see java.lang.SecurityManager#checkMemberAccess
  170.56 +     */
  170.57 +    public static final int DECLARED = 1;
  170.58 +
  170.59 +    /**
  170.60 +     * Returns the Class object representing the class or interface
  170.61 +     * that declares the member or constructor represented by this Member.
  170.62 +     *
  170.63 +     * @return an object representing the declaring class of the
  170.64 +     * underlying member
  170.65 +     */
  170.66 +    public Class<?> getDeclaringClass();
  170.67 +
  170.68 +    /**
  170.69 +     * Returns the simple name of the underlying member or constructor
  170.70 +     * represented by this Member.
  170.71 +     *
  170.72 +     * @return the simple name of the underlying member
  170.73 +     */
  170.74 +    public String getName();
  170.75 +
  170.76 +    /**
  170.77 +     * Returns the Java language modifiers for the member or
  170.78 +     * constructor represented by this Member, as an integer.  The
  170.79 +     * Modifier class should be used to decode the modifiers in
  170.80 +     * the integer.
  170.81 +     *
  170.82 +     * @return the Java language modifiers for the underlying member
  170.83 +     * @see Modifier
  170.84 +     */
  170.85 +    public int getModifiers();
  170.86 +
  170.87 +    /**
  170.88 +     * Returns {@code true} if this member was introduced by
  170.89 +     * the compiler; returns {@code false} otherwise.
  170.90 +     *
  170.91 +     * @return true if and only if this member was introduced by
  170.92 +     * the compiler.
  170.93 +     * @since 1.5
  170.94 +     */
  170.95 +    public boolean isSynthetic();
  170.96 +}
   171.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   171.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Method.java	Sun Feb 03 07:48:42 2013 +0100
   171.3 @@ -0,0 +1,721 @@
   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 +import java.util.Enumeration;
  171.33 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  171.34 +import org.apidesign.bck2brwsr.emul.reflect.AnnotationImpl;
  171.35 +import org.apidesign.bck2brwsr.emul.reflect.MethodImpl;
  171.36 +
  171.37 +/**
  171.38 + * A {@code Method} provides information about, and access to, a single method
  171.39 + * on a class or interface.  The reflected method may be a class method
  171.40 + * or an instance method (including an abstract method).
  171.41 + *
  171.42 + * <p>A {@code Method} permits widening conversions to occur when matching the
  171.43 + * actual parameters to invoke with the underlying method's formal
  171.44 + * parameters, but it throws an {@code IllegalArgumentException} if a
  171.45 + * narrowing conversion would occur.
  171.46 + *
  171.47 + * @see Member
  171.48 + * @see java.lang.Class
  171.49 + * @see java.lang.Class#getMethods()
  171.50 + * @see java.lang.Class#getMethod(String, Class[])
  171.51 + * @see java.lang.Class#getDeclaredMethods()
  171.52 + * @see java.lang.Class#getDeclaredMethod(String, Class[])
  171.53 + *
  171.54 + * @author Kenneth Russell
  171.55 + * @author Nakul Saraiya
  171.56 + */
  171.57 +public final
  171.58 +    class Method extends AccessibleObject implements GenericDeclaration,
  171.59 +                                                     Member {
  171.60 +    private final Class<?> clazz;
  171.61 +    private final String name;
  171.62 +    private final Object data;
  171.63 +    private final String sig;
  171.64 +
  171.65 +   // Generics infrastructure
  171.66 +
  171.67 +    private String getGenericSignature() {return null;}
  171.68 +
  171.69 +    /**
  171.70 +     * Package-private constructor used by ReflectAccess to enable
  171.71 +     * instantiation of these objects in Java code from the java.lang
  171.72 +     * package via sun.reflect.LangReflectAccess.
  171.73 +     */
  171.74 +    Method(Class<?> declaringClass, String name, Object data, String sig)
  171.75 +    {
  171.76 +        this.clazz = declaringClass;
  171.77 +        this.name = name;
  171.78 +        this.data = data;
  171.79 +        this.sig = sig;
  171.80 +    }
  171.81 +
  171.82 +    /**
  171.83 +     * Package-private routine (exposed to java.lang.Class via
  171.84 +     * ReflectAccess) which returns a copy of this Method. The copy's
  171.85 +     * "root" field points to this Method.
  171.86 +     */
  171.87 +    Method copy() {
  171.88 +        return this;
  171.89 +    }
  171.90 +
  171.91 +    /**
  171.92 +     * Returns the {@code Class} object representing the class or interface
  171.93 +     * that declares the method represented by this {@code Method} object.
  171.94 +     */
  171.95 +    public Class<?> getDeclaringClass() {
  171.96 +        return clazz;
  171.97 +    }
  171.98 +
  171.99 +    /**
 171.100 +     * Returns the name of the method represented by this {@code Method}
 171.101 +     * object, as a {@code String}.
 171.102 +     */
 171.103 +    public String getName() {
 171.104 +        return name;
 171.105 +    }
 171.106 +
 171.107 +    /**
 171.108 +     * Returns the Java language modifiers for the method represented
 171.109 +     * by this {@code Method} object, as an integer. The {@code Modifier} class should
 171.110 +     * be used to decode the modifiers.
 171.111 +     *
 171.112 +     * @see Modifier
 171.113 +     */
 171.114 +    public int getModifiers() {
 171.115 +        return getAccess(data);
 171.116 +    }
 171.117 +    
 171.118 +    @JavaScriptBody(args = "self", body = "return self.access;")
 171.119 +    private static native int getAccess(Object self);
 171.120 +    
 171.121 +    /**
 171.122 +     * Returns an array of {@code TypeVariable} objects that represent the
 171.123 +     * type variables declared by the generic declaration represented by this
 171.124 +     * {@code GenericDeclaration} object, in declaration order.  Returns an
 171.125 +     * array of length 0 if the underlying generic declaration declares no type
 171.126 +     * variables.
 171.127 +     *
 171.128 +     * @return an array of {@code TypeVariable} objects that represent
 171.129 +     *     the type variables declared by this generic declaration
 171.130 +     * @throws GenericSignatureFormatError if the generic
 171.131 +     *     signature of this generic declaration does not conform to
 171.132 +     *     the format specified in
 171.133 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 171.134 +     * @since 1.5
 171.135 +     */
 171.136 +    public TypeVariable<Method>[] getTypeParameters() {
 171.137 +        throw new UnsupportedOperationException();
 171.138 +    }
 171.139 +
 171.140 +    /**
 171.141 +     * Returns a {@code Class} object that represents the formal return type
 171.142 +     * of the method represented by this {@code Method} object.
 171.143 +     *
 171.144 +     * @return the return type for the method this object represents
 171.145 +     */
 171.146 +    public Class<?> getReturnType() {
 171.147 +        return MethodImpl.signatureParser(sig).nextElement();
 171.148 +    }
 171.149 +
 171.150 +    /**
 171.151 +     * Returns a {@code Type} object that represents the formal return
 171.152 +     * type of the method represented by this {@code Method} object.
 171.153 +     *
 171.154 +     * <p>If the return type is a parameterized type,
 171.155 +     * the {@code Type} object returned must accurately reflect
 171.156 +     * the actual type parameters used in the source code.
 171.157 +     *
 171.158 +     * <p>If the return type is a type variable or a parameterized type, it
 171.159 +     * is created. Otherwise, it is resolved.
 171.160 +     *
 171.161 +     * @return  a {@code Type} object that represents the formal return
 171.162 +     *     type of the underlying  method
 171.163 +     * @throws GenericSignatureFormatError
 171.164 +     *     if the generic method signature does not conform to the format
 171.165 +     *     specified in
 171.166 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 171.167 +     * @throws TypeNotPresentException if the underlying method's
 171.168 +     *     return type refers to a non-existent type declaration
 171.169 +     * @throws MalformedParameterizedTypeException if the
 171.170 +     *     underlying method's return typed refers to a parameterized
 171.171 +     *     type that cannot be instantiated for any reason
 171.172 +     * @since 1.5
 171.173 +     */
 171.174 +    public Type getGenericReturnType() {
 171.175 +        throw new UnsupportedOperationException();
 171.176 +    }
 171.177 +
 171.178 +
 171.179 +    /**
 171.180 +     * Returns an array of {@code Class} objects that represent the formal
 171.181 +     * parameter types, in declaration order, of the method
 171.182 +     * represented by this {@code Method} object.  Returns an array of length
 171.183 +     * 0 if the underlying method takes no parameters.
 171.184 +     *
 171.185 +     * @return the parameter types for the method this object
 171.186 +     * represents
 171.187 +     */
 171.188 +    public Class<?>[] getParameterTypes() {
 171.189 +        Class[] arr = new Class[MethodImpl.signatureElements(sig) - 1];
 171.190 +        Enumeration<Class> en = MethodImpl.signatureParser(sig);
 171.191 +        en.nextElement(); // return type
 171.192 +        for (int i = 0; i < arr.length; i++) {
 171.193 +            arr[i] = en.nextElement();
 171.194 +        }
 171.195 +        return arr;
 171.196 +    }
 171.197 +
 171.198 +    /**
 171.199 +     * Returns an array of {@code Type} objects that represent the formal
 171.200 +     * parameter types, in declaration order, of the method represented by
 171.201 +     * this {@code Method} object. Returns an array of length 0 if the
 171.202 +     * underlying method takes no parameters.
 171.203 +     *
 171.204 +     * <p>If a formal parameter type is a parameterized type,
 171.205 +     * the {@code Type} object returned for it must accurately reflect
 171.206 +     * the actual type parameters used in the source code.
 171.207 +     *
 171.208 +     * <p>If a formal parameter type is a type variable or a parameterized
 171.209 +     * type, it is created. Otherwise, it is resolved.
 171.210 +     *
 171.211 +     * @return an array of Types that represent the formal
 171.212 +     *     parameter types of the underlying method, in declaration order
 171.213 +     * @throws GenericSignatureFormatError
 171.214 +     *     if the generic method signature does not conform to the format
 171.215 +     *     specified in
 171.216 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 171.217 +     * @throws TypeNotPresentException if any of the parameter
 171.218 +     *     types of the underlying method refers to a non-existent type
 171.219 +     *     declaration
 171.220 +     * @throws MalformedParameterizedTypeException if any of
 171.221 +     *     the underlying method's parameter types refer to a parameterized
 171.222 +     *     type that cannot be instantiated for any reason
 171.223 +     * @since 1.5
 171.224 +     */
 171.225 +    public Type[] getGenericParameterTypes() {
 171.226 +        throw new UnsupportedOperationException();
 171.227 +    }
 171.228 +
 171.229 +
 171.230 +    /**
 171.231 +     * Returns an array of {@code Class} objects that represent
 171.232 +     * the types of the exceptions declared to be thrown
 171.233 +     * by the underlying method
 171.234 +     * represented by this {@code Method} object.  Returns an array of length
 171.235 +     * 0 if the method declares no exceptions in its {@code throws} clause.
 171.236 +     *
 171.237 +     * @return the exception types declared as being thrown by the
 171.238 +     * method this object represents
 171.239 +     */
 171.240 +    public Class<?>[] getExceptionTypes() {
 171.241 +        throw new UnsupportedOperationException();
 171.242 +        //return (Class<?>[]) exceptionTypes.clone();
 171.243 +    }
 171.244 +
 171.245 +    /**
 171.246 +     * Returns an array of {@code Type} objects that represent the
 171.247 +     * exceptions declared to be thrown by this {@code Method} object.
 171.248 +     * Returns an array of length 0 if the underlying method declares
 171.249 +     * no exceptions in its {@code throws} clause.
 171.250 +     *
 171.251 +     * <p>If an exception type is a type variable or a parameterized
 171.252 +     * type, it is created. Otherwise, it is resolved.
 171.253 +     *
 171.254 +     * @return an array of Types that represent the exception types
 171.255 +     *     thrown by the underlying method
 171.256 +     * @throws GenericSignatureFormatError
 171.257 +     *     if the generic method signature does not conform to the format
 171.258 +     *     specified in
 171.259 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 171.260 +     * @throws TypeNotPresentException if the underlying method's
 171.261 +     *     {@code throws} clause refers to a non-existent type declaration
 171.262 +     * @throws MalformedParameterizedTypeException if
 171.263 +     *     the underlying method's {@code throws} clause refers to a
 171.264 +     *     parameterized type that cannot be instantiated for any reason
 171.265 +     * @since 1.5
 171.266 +     */
 171.267 +      public Type[] getGenericExceptionTypes() {
 171.268 +        throw new UnsupportedOperationException();
 171.269 +      }
 171.270 +
 171.271 +    /**
 171.272 +     * Compares this {@code Method} against the specified object.  Returns
 171.273 +     * true if the objects are the same.  Two {@code Methods} are the same if
 171.274 +     * they were declared by the same class and have the same name
 171.275 +     * and formal parameter types and return type.
 171.276 +     */
 171.277 +    public boolean equals(Object obj) {
 171.278 +        if (obj != null && obj instanceof Method) {
 171.279 +            Method other = (Method)obj;
 171.280 +            return data == other.data;
 171.281 +        }
 171.282 +        return false;
 171.283 +    }
 171.284 +
 171.285 +    /**
 171.286 +     * Returns a hashcode for this {@code Method}.  The hashcode is computed
 171.287 +     * as the exclusive-or of the hashcodes for the underlying
 171.288 +     * method's declaring class name and the method's name.
 171.289 +     */
 171.290 +    public int hashCode() {
 171.291 +        return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
 171.292 +    }
 171.293 +
 171.294 +    /**
 171.295 +     * Returns a string describing this {@code Method}.  The string is
 171.296 +     * formatted as the method access modifiers, if any, followed by
 171.297 +     * the method return type, followed by a space, followed by the
 171.298 +     * class declaring the method, followed by a period, followed by
 171.299 +     * the method name, followed by a parenthesized, comma-separated
 171.300 +     * list of the method's formal parameter types. If the method
 171.301 +     * throws checked exceptions, the parameter list is followed by a
 171.302 +     * space, followed by the word throws followed by a
 171.303 +     * comma-separated list of the thrown exception types.
 171.304 +     * For example:
 171.305 +     * <pre>
 171.306 +     *    public boolean java.lang.Object.equals(java.lang.Object)
 171.307 +     * </pre>
 171.308 +     *
 171.309 +     * <p>The access modifiers are placed in canonical order as
 171.310 +     * specified by "The Java Language Specification".  This is
 171.311 +     * {@code public}, {@code protected} or {@code private} first,
 171.312 +     * and then other modifiers in the following order:
 171.313 +     * {@code abstract}, {@code static}, {@code final},
 171.314 +     * {@code synchronized}, {@code native}, {@code strictfp}.
 171.315 +     */
 171.316 +    public String toString() {
 171.317 +        try {
 171.318 +            StringBuilder sb = new StringBuilder();
 171.319 +            int mod = getModifiers() & Modifier.methodModifiers();
 171.320 +            if (mod != 0) {
 171.321 +                sb.append(Modifier.toString(mod)).append(' ');
 171.322 +            }
 171.323 +            sb.append(Field.getTypeName(getReturnType())).append(' ');
 171.324 +            sb.append(Field.getTypeName(getDeclaringClass())).append('.');
 171.325 +            sb.append(getName()).append('(');
 171.326 +            Class<?>[] params = getParameterTypes(); // avoid clone
 171.327 +            for (int j = 0; j < params.length; j++) {
 171.328 +                sb.append(Field.getTypeName(params[j]));
 171.329 +                if (j < (params.length - 1))
 171.330 +                    sb.append(',');
 171.331 +            }
 171.332 +            sb.append(')');
 171.333 +            /*
 171.334 +            Class<?>[] exceptions = exceptionTypes; // avoid clone
 171.335 +            if (exceptions.length > 0) {
 171.336 +                sb.append(" throws ");
 171.337 +                for (int k = 0; k < exceptions.length; k++) {
 171.338 +                    sb.append(exceptions[k].getName());
 171.339 +                    if (k < (exceptions.length - 1))
 171.340 +                        sb.append(',');
 171.341 +                }
 171.342 +            }
 171.343 +            */
 171.344 +            return sb.toString();
 171.345 +        } catch (Exception e) {
 171.346 +            return "<" + e + ">";
 171.347 +        }
 171.348 +    }
 171.349 +
 171.350 +    /**
 171.351 +     * Returns a string describing this {@code Method}, including
 171.352 +     * type parameters.  The string is formatted as the method access
 171.353 +     * modifiers, if any, followed by an angle-bracketed
 171.354 +     * comma-separated list of the method's type parameters, if any,
 171.355 +     * followed by the method's generic return type, followed by a
 171.356 +     * space, followed by the class declaring the method, followed by
 171.357 +     * a period, followed by the method name, followed by a
 171.358 +     * parenthesized, comma-separated list of the method's generic
 171.359 +     * formal parameter types.
 171.360 +     *
 171.361 +     * If this method was declared to take a variable number of
 171.362 +     * arguments, instead of denoting the last parameter as
 171.363 +     * "<tt><i>Type</i>[]</tt>", it is denoted as
 171.364 +     * "<tt><i>Type</i>...</tt>".
 171.365 +     *
 171.366 +     * A space is used to separate access modifiers from one another
 171.367 +     * and from the type parameters or return type.  If there are no
 171.368 +     * type parameters, the type parameter list is elided; if the type
 171.369 +     * parameter list is present, a space separates the list from the
 171.370 +     * class name.  If the method is declared to throw exceptions, the
 171.371 +     * parameter list is followed by a space, followed by the word
 171.372 +     * throws followed by a comma-separated list of the generic thrown
 171.373 +     * exception types.  If there are no type parameters, the type
 171.374 +     * parameter list is elided.
 171.375 +     *
 171.376 +     * <p>The access modifiers are placed in canonical order as
 171.377 +     * specified by "The Java Language Specification".  This is
 171.378 +     * {@code public}, {@code protected} or {@code private} first,
 171.379 +     * and then other modifiers in the following order:
 171.380 +     * {@code abstract}, {@code static}, {@code final},
 171.381 +     * {@code synchronized}, {@code native}, {@code strictfp}.
 171.382 +     *
 171.383 +     * @return a string describing this {@code Method},
 171.384 +     * include type parameters
 171.385 +     *
 171.386 +     * @since 1.5
 171.387 +     */
 171.388 +    public String toGenericString() {
 171.389 +        try {
 171.390 +            StringBuilder sb = new StringBuilder();
 171.391 +            int mod = getModifiers() & Modifier.methodModifiers();
 171.392 +            if (mod != 0) {
 171.393 +                sb.append(Modifier.toString(mod)).append(' ');
 171.394 +            }
 171.395 +            TypeVariable<?>[] typeparms = getTypeParameters();
 171.396 +            if (typeparms.length > 0) {
 171.397 +                boolean first = true;
 171.398 +                sb.append('<');
 171.399 +                for(TypeVariable<?> typeparm: typeparms) {
 171.400 +                    if (!first)
 171.401 +                        sb.append(',');
 171.402 +                    // Class objects can't occur here; no need to test
 171.403 +                    // and call Class.getName().
 171.404 +                    sb.append(typeparm.toString());
 171.405 +                    first = false;
 171.406 +                }
 171.407 +                sb.append("> ");
 171.408 +            }
 171.409 +
 171.410 +            Type genRetType = getGenericReturnType();
 171.411 +            sb.append( ((genRetType instanceof Class<?>)?
 171.412 +                        Field.getTypeName((Class<?>)genRetType):genRetType.toString()))
 171.413 +                    .append(' ');
 171.414 +
 171.415 +            sb.append(Field.getTypeName(getDeclaringClass())).append('.');
 171.416 +            sb.append(getName()).append('(');
 171.417 +            Type[] params = getGenericParameterTypes();
 171.418 +            for (int j = 0; j < params.length; j++) {
 171.419 +                String param = (params[j] instanceof Class)?
 171.420 +                    Field.getTypeName((Class)params[j]):
 171.421 +                    (params[j].toString());
 171.422 +                if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
 171.423 +                    param = param.replaceFirst("\\[\\]$", "...");
 171.424 +                sb.append(param);
 171.425 +                if (j < (params.length - 1))
 171.426 +                    sb.append(',');
 171.427 +            }
 171.428 +            sb.append(')');
 171.429 +            Type[] exceptions = getGenericExceptionTypes();
 171.430 +            if (exceptions.length > 0) {
 171.431 +                sb.append(" throws ");
 171.432 +                for (int k = 0; k < exceptions.length; k++) {
 171.433 +                    sb.append((exceptions[k] instanceof Class)?
 171.434 +                              ((Class)exceptions[k]).getName():
 171.435 +                              exceptions[k].toString());
 171.436 +                    if (k < (exceptions.length - 1))
 171.437 +                        sb.append(',');
 171.438 +                }
 171.439 +            }
 171.440 +            return sb.toString();
 171.441 +        } catch (Exception e) {
 171.442 +            return "<" + e + ">";
 171.443 +        }
 171.444 +    }
 171.445 +
 171.446 +    /**
 171.447 +     * Invokes the underlying method represented by this {@code Method}
 171.448 +     * object, on the specified object with the specified parameters.
 171.449 +     * Individual parameters are automatically unwrapped to match
 171.450 +     * primitive formal parameters, and both primitive and reference
 171.451 +     * parameters are subject to method invocation conversions as
 171.452 +     * necessary.
 171.453 +     *
 171.454 +     * <p>If the underlying method is static, then the specified {@code obj}
 171.455 +     * argument is ignored. It may be null.
 171.456 +     *
 171.457 +     * <p>If the number of formal parameters required by the underlying method is
 171.458 +     * 0, the supplied {@code args} array may be of length 0 or null.
 171.459 +     *
 171.460 +     * <p>If the underlying method is an instance method, it is invoked
 171.461 +     * using dynamic method lookup as documented in The Java Language
 171.462 +     * Specification, Second Edition, section 15.12.4.4; in particular,
 171.463 +     * overriding based on the runtime type of the target object will occur.
 171.464 +     *
 171.465 +     * <p>If the underlying method is static, the class that declared
 171.466 +     * the method is initialized if it has not already been initialized.
 171.467 +     *
 171.468 +     * <p>If the method completes normally, the value it returns is
 171.469 +     * returned to the caller of invoke; if the value has a primitive
 171.470 +     * type, it is first appropriately wrapped in an object. However,
 171.471 +     * if the value has the type of an array of a primitive type, the
 171.472 +     * elements of the array are <i>not</i> wrapped in objects; in
 171.473 +     * other words, an array of primitive type is returned.  If the
 171.474 +     * underlying method return type is void, the invocation returns
 171.475 +     * null.
 171.476 +     *
 171.477 +     * @param obj  the object the underlying method is invoked from
 171.478 +     * @param args the arguments used for the method call
 171.479 +     * @return the result of dispatching the method represented by
 171.480 +     * this object on {@code obj} with parameters
 171.481 +     * {@code args}
 171.482 +     *
 171.483 +     * @exception IllegalAccessException    if this {@code Method} object
 171.484 +     *              is enforcing Java language access control and the underlying
 171.485 +     *              method is inaccessible.
 171.486 +     * @exception IllegalArgumentException  if the method is an
 171.487 +     *              instance method and the specified object argument
 171.488 +     *              is not an instance of the class or interface
 171.489 +     *              declaring the underlying method (or of a subclass
 171.490 +     *              or implementor thereof); if the number of actual
 171.491 +     *              and formal parameters differ; if an unwrapping
 171.492 +     *              conversion for primitive arguments fails; or if,
 171.493 +     *              after possible unwrapping, a parameter value
 171.494 +     *              cannot be converted to the corresponding formal
 171.495 +     *              parameter type by a method invocation conversion.
 171.496 +     * @exception InvocationTargetException if the underlying method
 171.497 +     *              throws an exception.
 171.498 +     * @exception NullPointerException      if the specified object is null
 171.499 +     *              and the method is an instance method.
 171.500 +     * @exception ExceptionInInitializerError if the initialization
 171.501 +     * provoked by this method fails.
 171.502 +     */
 171.503 +    public Object invoke(Object obj, Object... args)
 171.504 +        throws IllegalAccessException, IllegalArgumentException,
 171.505 +           InvocationTargetException
 171.506 +    {
 171.507 +        final boolean isStatic = (getModifiers() & Modifier.STATIC) == 0;
 171.508 +        if (isStatic && obj == null) {
 171.509 +            throw new NullPointerException();
 171.510 +        }
 171.511 +        Class[] types = getParameterTypes();
 171.512 +        if (types.length != args.length) {
 171.513 +            throw new IllegalArgumentException("Types len " + types.length + " args: " + args.length);
 171.514 +        } else {
 171.515 +            args = args.clone();
 171.516 +            for (int i = 0; i < types.length; i++) {
 171.517 +                Class c = types[i];
 171.518 +                if (c.isPrimitive()) {
 171.519 +                    args[i] = toPrimitive(c, args[i]);
 171.520 +                }
 171.521 +            }
 171.522 +        }
 171.523 +        Object res = invoke0(isStatic, this, obj, args);
 171.524 +        if (getReturnType().isPrimitive()) {
 171.525 +            res = fromPrimitive(getReturnType(), res);
 171.526 +        }
 171.527 +        return res;
 171.528 +    }
 171.529 +    
 171.530 +    @JavaScriptBody(args = { "st", "method", "self", "args" }, body =
 171.531 +          "var p;\n"
 171.532 +        + "if (st) {\n"
 171.533 +        + "  p = new Array(1);\n"
 171.534 +        + "  p[0] = self;\n"
 171.535 +        + "  p = p.concat(args);\n"
 171.536 +        + "} else {\n"
 171.537 +        + "  p = args;\n"
 171.538 +        + "}\n"
 171.539 +        + "return method._data().apply(self, p);\n"
 171.540 +    )
 171.541 +    private static native Object invoke0(boolean isStatic, Method m, Object self, Object[] args);
 171.542 +
 171.543 +    static Object fromPrimitive(Class<?> type, Object o) {
 171.544 +        if (type == Integer.TYPE) {
 171.545 +            return fromRaw(Integer.class, "valueOf__Ljava_lang_Integer_2I", o);
 171.546 +        }
 171.547 +        if (type == Long.TYPE) {
 171.548 +            return fromRaw(Long.class, "valueOf__Ljava_lang_Long_2J", o);
 171.549 +        }
 171.550 +        if (type == Double.TYPE) {
 171.551 +            return fromRaw(Double.class, "valueOf__Ljava_lang_Double_2D", o);
 171.552 +        }
 171.553 +        if (type == Float.TYPE) {
 171.554 +            return fromRaw(Float.class, "valueOf__Ljava_lang_Float_2F", o);
 171.555 +        }
 171.556 +        if (type == Byte.TYPE) {
 171.557 +            return fromRaw(Byte.class, "valueOf__Ljava_lang_Byte_2B", o);
 171.558 +        }
 171.559 +        if (type == Boolean.TYPE) {
 171.560 +            return fromRaw(Boolean.class, "valueOf__Ljava_lang_Boolean_2Z", o);
 171.561 +        }
 171.562 +        if (type == Short.TYPE) {
 171.563 +            return fromRaw(Short.class, "valueOf__Ljava_lang_Short_2S", o);
 171.564 +        }
 171.565 +        if (type == Character.TYPE) {
 171.566 +            return fromRaw(Character.class, "valueOf__Ljava_lang_Character_2C", o);
 171.567 +        }
 171.568 +        if (type.getName().equals("void")) {
 171.569 +            return null;
 171.570 +        }
 171.571 +        throw new IllegalStateException("Can't convert " + o);
 171.572 +    }
 171.573 +    
 171.574 +    @JavaScriptBody(args = { "cls", "m", "o" }, 
 171.575 +        body = "return cls.cnstr(false)[m](o);"
 171.576 +    )
 171.577 +    private static native Integer fromRaw(Class<?> cls, String m, Object o);
 171.578 +
 171.579 +    private static Object toPrimitive(Class<?> type, Object o) {
 171.580 +        if (type == Integer.TYPE) {
 171.581 +            return toRaw("intValue__I", o);
 171.582 +        }
 171.583 +        if (type == Long.TYPE) {
 171.584 +            return toRaw("longValue__J", o);
 171.585 +        }
 171.586 +        if (type == Double.TYPE) {
 171.587 +            return toRaw("doubleValue__D", o);
 171.588 +        }
 171.589 +        if (type == Float.TYPE) {
 171.590 +            return toRaw("floatValue__F", o);
 171.591 +        }
 171.592 +        if (type == Byte.TYPE) {
 171.593 +            return toRaw("byteValue__B", o);
 171.594 +        }
 171.595 +        if (type == Boolean.TYPE) {
 171.596 +            return toRaw("booleanValue__Z", o);
 171.597 +        }
 171.598 +        if (type == Short.TYPE) {
 171.599 +            return toRaw("shortValue__S", o);
 171.600 +        }
 171.601 +        if (type == Character.TYPE) {
 171.602 +            return toRaw("charValue__C", o);
 171.603 +        }
 171.604 +        if (type.getName().equals("void")) {
 171.605 +            return o;
 171.606 +        }
 171.607 +        throw new IllegalStateException("Can't convert " + o);
 171.608 +    }
 171.609 +    
 171.610 +    @JavaScriptBody(args = { "m", "o" }, 
 171.611 +        body = "return o[m](o);"
 171.612 +    )
 171.613 +    private static native Object toRaw(String m, Object o);
 171.614 +    
 171.615 +    /**
 171.616 +     * Returns {@code true} if this method is a bridge
 171.617 +     * method; returns {@code false} otherwise.
 171.618 +     *
 171.619 +     * @return true if and only if this method is a bridge
 171.620 +     * method as defined by the Java Language Specification.
 171.621 +     * @since 1.5
 171.622 +     */
 171.623 +    public boolean isBridge() {
 171.624 +        return (getModifiers() & Modifier.BRIDGE) != 0;
 171.625 +    }
 171.626 +
 171.627 +    /**
 171.628 +     * Returns {@code true} if this method was declared to take
 171.629 +     * a variable number of arguments; returns {@code false}
 171.630 +     * otherwise.
 171.631 +     *
 171.632 +     * @return {@code true} if an only if this method was declared to
 171.633 +     * take a variable number of arguments.
 171.634 +     * @since 1.5
 171.635 +     */
 171.636 +    public boolean isVarArgs() {
 171.637 +        return (getModifiers() & Modifier.VARARGS) != 0;
 171.638 +    }
 171.639 +
 171.640 +    /**
 171.641 +     * Returns {@code true} if this method is a synthetic
 171.642 +     * method; returns {@code false} otherwise.
 171.643 +     *
 171.644 +     * @return true if and only if this method is a synthetic
 171.645 +     * method as defined by the Java Language Specification.
 171.646 +     * @since 1.5
 171.647 +     */
 171.648 +    public boolean isSynthetic() {
 171.649 +        return Modifier.isSynthetic(getModifiers());
 171.650 +    }
 171.651 +
 171.652 +    @JavaScriptBody(args = { "ac" }, 
 171.653 +        body = 
 171.654 +          "var a = this._data().anno;"
 171.655 +        + "if (a) {"
 171.656 +        + "  return a['L' + ac.jvmName + ';'];"
 171.657 +        + "} else return null;"
 171.658 +    )
 171.659 +    private Object getAnnotationData(Class<?> annotationClass) {
 171.660 +        throw new UnsupportedOperationException();
 171.661 +    }
 171.662 +    
 171.663 +    /**
 171.664 +     * @throws NullPointerException {@inheritDoc}
 171.665 +     * @since 1.5
 171.666 +     */
 171.667 +    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 171.668 +        Object data = getAnnotationData(annotationClass);
 171.669 +        return data == null ? null : AnnotationImpl.create(annotationClass, data);
 171.670 +    }
 171.671 +
 171.672 +    /**
 171.673 +     * @since 1.5
 171.674 +     */
 171.675 +    public Annotation[] getDeclaredAnnotations()  {
 171.676 +        throw new UnsupportedOperationException();
 171.677 +    }
 171.678 +
 171.679 +    /**
 171.680 +     * Returns the default value for the annotation member represented by
 171.681 +     * this {@code Method} instance.  If the member is of a primitive type,
 171.682 +     * an instance of the corresponding wrapper type is returned. Returns
 171.683 +     * null if no default is associated with the member, or if the method
 171.684 +     * instance does not represent a declared member of an annotation type.
 171.685 +     *
 171.686 +     * @return the default value for the annotation member represented
 171.687 +     *     by this {@code Method} instance.
 171.688 +     * @throws TypeNotPresentException if the annotation is of type
 171.689 +     *     {@link Class} and no definition can be found for the
 171.690 +     *     default class value.
 171.691 +     * @since  1.5
 171.692 +     */
 171.693 +    public Object getDefaultValue() {
 171.694 +        throw new UnsupportedOperationException();
 171.695 +    }
 171.696 +
 171.697 +    /**
 171.698 +     * Returns an array of arrays that represent the annotations on the formal
 171.699 +     * parameters, in declaration order, of the method represented by
 171.700 +     * this {@code Method} object. (Returns an array of length zero if the
 171.701 +     * underlying method is parameterless.  If the method has one or more
 171.702 +     * parameters, a nested array of length zero is returned for each parameter
 171.703 +     * with no annotations.) The annotation objects contained in the returned
 171.704 +     * arrays are serializable.  The caller of this method is free to modify
 171.705 +     * the returned arrays; it will have no effect on the arrays returned to
 171.706 +     * other callers.
 171.707 +     *
 171.708 +     * @return an array of arrays that represent the annotations on the formal
 171.709 +     *    parameters, in declaration order, of the method represented by this
 171.710 +     *    Method object
 171.711 +     * @since 1.5
 171.712 +     */
 171.713 +    public Annotation[][] getParameterAnnotations() {
 171.714 +        throw new UnsupportedOperationException();
 171.715 +    }
 171.716 +
 171.717 +    static {
 171.718 +        MethodImpl.INSTANCE = new MethodImpl() {
 171.719 +            protected Method create(Class<?> declaringClass, String name, Object data, String sig) {
 171.720 +                return new Method(declaringClass, name, data, sig);
 171.721 +            }
 171.722 +        };
 171.723 +    }
 171.724 +}
   172.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   172.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Modifier.java	Sun Feb 03 07:48:42 2013 +0100
   172.3 @@ -0,0 +1,437 @@
   172.4 +/*
   172.5 + * Copyright (c) 1996, 2008, 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 + * The Modifier class provides {@code static} methods and
  172.33 + * constants to decode class and member access modifiers.  The sets of
  172.34 + * modifiers are represented as integers with distinct bit positions
  172.35 + * representing different modifiers.  The values for the constants
  172.36 + * representing the modifiers are taken from the tables in sections 4.1, 4.4, 4.5, and 4.7 of
  172.37 + * <cite>The Java&trade; Virtual Machine Specification</cite>.
  172.38 + *
  172.39 + * @see Class#getModifiers()
  172.40 + * @see Member#getModifiers()
  172.41 + *
  172.42 + * @author Nakul Saraiya
  172.43 + * @author Kenneth Russell
  172.44 + */
  172.45 +public
  172.46 +class Modifier {
  172.47 +
  172.48 +    /**
  172.49 +     * Return {@code true} if the integer argument includes the
  172.50 +     * {@code public} modifier, {@code false} otherwise.
  172.51 +     *
  172.52 +     * @param   mod a set of modifiers
  172.53 +     * @return {@code true} if {@code mod} includes the
  172.54 +     * {@code public} modifier; {@code false} otherwise.
  172.55 +     */
  172.56 +    public static boolean isPublic(int mod) {
  172.57 +        return (mod & PUBLIC) != 0;
  172.58 +    }
  172.59 +
  172.60 +    /**
  172.61 +     * Return {@code true} if the integer argument includes the
  172.62 +     * {@code private} modifier, {@code false} otherwise.
  172.63 +     *
  172.64 +     * @param   mod a set of modifiers
  172.65 +     * @return {@code true} if {@code mod} includes the
  172.66 +     * {@code private} modifier; {@code false} otherwise.
  172.67 +     */
  172.68 +    public static boolean isPrivate(int mod) {
  172.69 +        return (mod & PRIVATE) != 0;
  172.70 +    }
  172.71 +
  172.72 +    /**
  172.73 +     * Return {@code true} if the integer argument includes the
  172.74 +     * {@code protected} modifier, {@code false} otherwise.
  172.75 +     *
  172.76 +     * @param   mod a set of modifiers
  172.77 +     * @return {@code true} if {@code mod} includes the
  172.78 +     * {@code protected} modifier; {@code false} otherwise.
  172.79 +     */
  172.80 +    public static boolean isProtected(int mod) {
  172.81 +        return (mod & PROTECTED) != 0;
  172.82 +    }
  172.83 +
  172.84 +    /**
  172.85 +     * Return {@code true} if the integer argument includes the
  172.86 +     * {@code static} modifier, {@code false} otherwise.
  172.87 +     *
  172.88 +     * @param   mod a set of modifiers
  172.89 +     * @return {@code true} if {@code mod} includes the
  172.90 +     * {@code static} modifier; {@code false} otherwise.
  172.91 +     */
  172.92 +    public static boolean isStatic(int mod) {
  172.93 +        return (mod & STATIC) != 0;
  172.94 +    }
  172.95 +
  172.96 +    /**
  172.97 +     * Return {@code true} if the integer argument includes the
  172.98 +     * {@code final} modifier, {@code false} otherwise.
  172.99 +     *
 172.100 +     * @param   mod a set of modifiers
 172.101 +     * @return {@code true} if {@code mod} includes the
 172.102 +     * {@code final} modifier; {@code false} otherwise.
 172.103 +     */
 172.104 +    public static boolean isFinal(int mod) {
 172.105 +        return (mod & FINAL) != 0;
 172.106 +    }
 172.107 +
 172.108 +    /**
 172.109 +     * Return {@code true} if the integer argument includes the
 172.110 +     * {@code synchronized} modifier, {@code false} otherwise.
 172.111 +     *
 172.112 +     * @param   mod a set of modifiers
 172.113 +     * @return {@code true} if {@code mod} includes the
 172.114 +     * {@code synchronized} modifier; {@code false} otherwise.
 172.115 +     */
 172.116 +    public static boolean isSynchronized(int mod) {
 172.117 +        return (mod & SYNCHRONIZED) != 0;
 172.118 +    }
 172.119 +
 172.120 +    /**
 172.121 +     * Return {@code true} if the integer argument includes the
 172.122 +     * {@code volatile} modifier, {@code false} otherwise.
 172.123 +     *
 172.124 +     * @param   mod a set of modifiers
 172.125 +     * @return {@code true} if {@code mod} includes the
 172.126 +     * {@code volatile} modifier; {@code false} otherwise.
 172.127 +     */
 172.128 +    public static boolean isVolatile(int mod) {
 172.129 +        return (mod & VOLATILE) != 0;
 172.130 +    }
 172.131 +
 172.132 +    /**
 172.133 +     * Return {@code true} if the integer argument includes the
 172.134 +     * {@code transient} modifier, {@code false} otherwise.
 172.135 +     *
 172.136 +     * @param   mod a set of modifiers
 172.137 +     * @return {@code true} if {@code mod} includes the
 172.138 +     * {@code transient} modifier; {@code false} otherwise.
 172.139 +     */
 172.140 +    public static boolean isTransient(int mod) {
 172.141 +        return (mod & TRANSIENT) != 0;
 172.142 +    }
 172.143 +
 172.144 +    /**
 172.145 +     * Return {@code true} if the integer argument includes the
 172.146 +     * {@code native} modifier, {@code false} otherwise.
 172.147 +     *
 172.148 +     * @param   mod a set of modifiers
 172.149 +     * @return {@code true} if {@code mod} includes the
 172.150 +     * {@code native} modifier; {@code false} otherwise.
 172.151 +     */
 172.152 +    public static boolean isNative(int mod) {
 172.153 +        return (mod & NATIVE) != 0;
 172.154 +    }
 172.155 +
 172.156 +    /**
 172.157 +     * Return {@code true} if the integer argument includes the
 172.158 +     * {@code interface} modifier, {@code false} otherwise.
 172.159 +     *
 172.160 +     * @param   mod a set of modifiers
 172.161 +     * @return {@code true} if {@code mod} includes the
 172.162 +     * {@code interface} modifier; {@code false} otherwise.
 172.163 +     */
 172.164 +    public static boolean isInterface(int mod) {
 172.165 +        return (mod & INTERFACE) != 0;
 172.166 +    }
 172.167 +
 172.168 +    /**
 172.169 +     * Return {@code true} if the integer argument includes the
 172.170 +     * {@code abstract} modifier, {@code false} otherwise.
 172.171 +     *
 172.172 +     * @param   mod a set of modifiers
 172.173 +     * @return {@code true} if {@code mod} includes the
 172.174 +     * {@code abstract} modifier; {@code false} otherwise.
 172.175 +     */
 172.176 +    public static boolean isAbstract(int mod) {
 172.177 +        return (mod & ABSTRACT) != 0;
 172.178 +    }
 172.179 +
 172.180 +    /**
 172.181 +     * Return {@code true} if the integer argument includes the
 172.182 +     * {@code strictfp} modifier, {@code false} otherwise.
 172.183 +     *
 172.184 +     * @param   mod a set of modifiers
 172.185 +     * @return {@code true} if {@code mod} includes the
 172.186 +     * {@code strictfp} modifier; {@code false} otherwise.
 172.187 +     */
 172.188 +    public static boolean isStrict(int mod) {
 172.189 +        return (mod & STRICT) != 0;
 172.190 +    }
 172.191 +
 172.192 +    /**
 172.193 +     * Return a string describing the access modifier flags in
 172.194 +     * the specified modifier. For example:
 172.195 +     * <blockquote><pre>
 172.196 +     *    public final synchronized strictfp
 172.197 +     * </pre></blockquote>
 172.198 +     * The modifier names are returned in an order consistent with the
 172.199 +     * suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of
 172.200 +     * <cite>The Java&trade; Language Specification</cite>.
 172.201 +     * The full modifier ordering used by this method is:
 172.202 +     * <blockquote> {@code
 172.203 +     * public protected private abstract static final transient
 172.204 +     * volatile synchronized native strictfp
 172.205 +     * interface } </blockquote>
 172.206 +     * The {@code interface} modifier discussed in this class is
 172.207 +     * not a true modifier in the Java language and it appears after
 172.208 +     * all other modifiers listed by this method.  This method may
 172.209 +     * return a string of modifiers that are not valid modifiers of a
 172.210 +     * Java entity; in other words, no checking is done on the
 172.211 +     * possible validity of the combination of modifiers represented
 172.212 +     * by the input.
 172.213 +     *
 172.214 +     * Note that to perform such checking for a known kind of entity,
 172.215 +     * such as a constructor or method, first AND the argument of
 172.216 +     * {@code toString} with the appropriate mask from a method like
 172.217 +     * {@link #constructorModifiers} or {@link #methodModifiers}.
 172.218 +     *
 172.219 +     * @param   mod a set of modifiers
 172.220 +     * @return  a string representation of the set of modifiers
 172.221 +     * represented by {@code mod}
 172.222 +     */
 172.223 +    public static String toString(int mod) {
 172.224 +        StringBuffer sb = new StringBuffer();
 172.225 +        int len;
 172.226 +
 172.227 +        if ((mod & PUBLIC) != 0)        sb.append("public ");
 172.228 +        if ((mod & PROTECTED) != 0)     sb.append("protected ");
 172.229 +        if ((mod & PRIVATE) != 0)       sb.append("private ");
 172.230 +
 172.231 +        /* Canonical order */
 172.232 +        if ((mod & ABSTRACT) != 0)      sb.append("abstract ");
 172.233 +        if ((mod & STATIC) != 0)        sb.append("static ");
 172.234 +        if ((mod & FINAL) != 0)         sb.append("final ");
 172.235 +        if ((mod & TRANSIENT) != 0)     sb.append("transient ");
 172.236 +        if ((mod & VOLATILE) != 0)      sb.append("volatile ");
 172.237 +        if ((mod & SYNCHRONIZED) != 0)  sb.append("synchronized ");
 172.238 +        if ((mod & NATIVE) != 0)        sb.append("native ");
 172.239 +        if ((mod & STRICT) != 0)        sb.append("strictfp ");
 172.240 +        if ((mod & INTERFACE) != 0)     sb.append("interface ");
 172.241 +
 172.242 +        if ((len = sb.length()) > 0)    /* trim trailing space */
 172.243 +            return sb.toString().substring(0, len-1);
 172.244 +        return "";
 172.245 +    }
 172.246 +
 172.247 +    /*
 172.248 +     * Access modifier flag constants from tables 4.1, 4.4, 4.5, and 4.7 of
 172.249 +     * <cite>The Java&trade; Virtual Machine Specification</cite>
 172.250 +     */
 172.251 +
 172.252 +    /**
 172.253 +     * The {@code int} value representing the {@code public}
 172.254 +     * modifier.
 172.255 +     */
 172.256 +    public static final int PUBLIC           = 0x00000001;
 172.257 +
 172.258 +    /**
 172.259 +     * The {@code int} value representing the {@code private}
 172.260 +     * modifier.
 172.261 +     */
 172.262 +    public static final int PRIVATE          = 0x00000002;
 172.263 +
 172.264 +    /**
 172.265 +     * The {@code int} value representing the {@code protected}
 172.266 +     * modifier.
 172.267 +     */
 172.268 +    public static final int PROTECTED        = 0x00000004;
 172.269 +
 172.270 +    /**
 172.271 +     * The {@code int} value representing the {@code static}
 172.272 +     * modifier.
 172.273 +     */
 172.274 +    public static final int STATIC           = 0x00000008;
 172.275 +
 172.276 +    /**
 172.277 +     * The {@code int} value representing the {@code final}
 172.278 +     * modifier.
 172.279 +     */
 172.280 +    public static final int FINAL            = 0x00000010;
 172.281 +
 172.282 +    /**
 172.283 +     * The {@code int} value representing the {@code synchronized}
 172.284 +     * modifier.
 172.285 +     */
 172.286 +    public static final int SYNCHRONIZED     = 0x00000020;
 172.287 +
 172.288 +    /**
 172.289 +     * The {@code int} value representing the {@code volatile}
 172.290 +     * modifier.
 172.291 +     */
 172.292 +    public static final int VOLATILE         = 0x00000040;
 172.293 +
 172.294 +    /**
 172.295 +     * The {@code int} value representing the {@code transient}
 172.296 +     * modifier.
 172.297 +     */
 172.298 +    public static final int TRANSIENT        = 0x00000080;
 172.299 +
 172.300 +    /**
 172.301 +     * The {@code int} value representing the {@code native}
 172.302 +     * modifier.
 172.303 +     */
 172.304 +    public static final int NATIVE           = 0x00000100;
 172.305 +
 172.306 +    /**
 172.307 +     * The {@code int} value representing the {@code interface}
 172.308 +     * modifier.
 172.309 +     */
 172.310 +    public static final int INTERFACE        = 0x00000200;
 172.311 +
 172.312 +    /**
 172.313 +     * The {@code int} value representing the {@code abstract}
 172.314 +     * modifier.
 172.315 +     */
 172.316 +    public static final int ABSTRACT         = 0x00000400;
 172.317 +
 172.318 +    /**
 172.319 +     * The {@code int} value representing the {@code strictfp}
 172.320 +     * modifier.
 172.321 +     */
 172.322 +    public static final int STRICT           = 0x00000800;
 172.323 +
 172.324 +    // Bits not (yet) exposed in the public API either because they
 172.325 +    // have different meanings for fields and methods and there is no
 172.326 +    // way to distinguish between the two in this class, or because
 172.327 +    // they are not Java programming language keywords
 172.328 +    static final int BRIDGE    = 0x00000040;
 172.329 +    static final int VARARGS   = 0x00000080;
 172.330 +    static final int SYNTHETIC = 0x00001000;
 172.331 +    static final int ANNOTATION= 0x00002000;
 172.332 +    static final int ENUM      = 0x00004000;
 172.333 +    static boolean isSynthetic(int mod) {
 172.334 +      return (mod & SYNTHETIC) != 0;
 172.335 +    }
 172.336 +
 172.337 +    /**
 172.338 +     * See JLSv3 section 8.1.1.
 172.339 +     */
 172.340 +    private static final int CLASS_MODIFIERS =
 172.341 +        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 172.342 +        Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.FINAL   |
 172.343 +        Modifier.STRICT;
 172.344 +
 172.345 +    /**
 172.346 +     * See JLSv3 section 9.1.1.
 172.347 +     */
 172.348 +    private static final int INTERFACE_MODIFIERS =
 172.349 +        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 172.350 +        Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.STRICT;
 172.351 +
 172.352 +
 172.353 +    /**
 172.354 +     * See JLSv3 section 8.8.3.
 172.355 +     */
 172.356 +    private static final int CONSTRUCTOR_MODIFIERS =
 172.357 +        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE;
 172.358 +
 172.359 +    /**
 172.360 +     * See JLSv3 section 8.4.3.
 172.361 +     */
 172.362 +    private static final int METHOD_MODIFIERS =
 172.363 +        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 172.364 +        Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.FINAL   |
 172.365 +        Modifier.SYNCHRONIZED   | Modifier.NATIVE       | Modifier.STRICT;
 172.366 +
 172.367 +    /**
 172.368 +     * See JLSv3 section 8.3.1.
 172.369 +     */
 172.370 +    private static final int FIELD_MODIFIERS =
 172.371 +        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 172.372 +        Modifier.STATIC         | Modifier.FINAL        | Modifier.TRANSIENT |
 172.373 +        Modifier.VOLATILE;
 172.374 +
 172.375 +    /**
 172.376 +     * Return an {@code int} value OR-ing together the source language
 172.377 +     * modifiers that can be applied to a class.
 172.378 +     * @return an {@code int} value OR-ing together the source language
 172.379 +     * modifiers that can be applied to a class.
 172.380 +     *
 172.381 +     * @jls 8.1.1 Class Modifiers
 172.382 +     * @since 1.7
 172.383 +     */
 172.384 +    public static int classModifiers() {
 172.385 +        return CLASS_MODIFIERS;
 172.386 +    }
 172.387 +
 172.388 +    /**
 172.389 +     * Return an {@code int} value OR-ing together the source language
 172.390 +     * modifiers that can be applied to an interface.
 172.391 +     * @return an {@code int} value OR-ing together the source language
 172.392 +     * modifiers that can be applied to an inteface.
 172.393 +     *
 172.394 +     * @jls 9.1.1 Interface Modifiers
 172.395 +     * @since 1.7
 172.396 +     */
 172.397 +    public static int interfaceModifiers() {
 172.398 +        return INTERFACE_MODIFIERS;
 172.399 +    }
 172.400 +
 172.401 +    /**
 172.402 +     * Return an {@code int} value OR-ing together the source language
 172.403 +     * modifiers that can be applied to a constructor.
 172.404 +     * @return an {@code int} value OR-ing together the source language
 172.405 +     * modifiers that can be applied to a constructor.
 172.406 +     *
 172.407 +     * @jls 8.8.3 Constructor Modifiers
 172.408 +     * @since 1.7
 172.409 +     */
 172.410 +    public static int constructorModifiers() {
 172.411 +        return CONSTRUCTOR_MODIFIERS;
 172.412 +    }
 172.413 +
 172.414 +    /**
 172.415 +     * Return an {@code int} value OR-ing together the source language
 172.416 +     * modifiers that can be applied to a method.
 172.417 +     * @return an {@code int} value OR-ing together the source language
 172.418 +     * modifiers that can be applied to a method.
 172.419 +     *
 172.420 +     * @jls 8.4.3 Method Modifiers
 172.421 +     * @since 1.7
 172.422 +     */
 172.423 +    public static int methodModifiers() {
 172.424 +        return METHOD_MODIFIERS;
 172.425 +    }
 172.426 +
 172.427 +
 172.428 +    /**
 172.429 +     * Return an {@code int} value OR-ing together the source language
 172.430 +     * modifiers that can be applied to a field.
 172.431 +     * @return an {@code int} value OR-ing together the source language
 172.432 +     * modifiers that can be applied to a field.
 172.433 +     *
 172.434 +     * @jls 8.3.1 Field Modifiers
 172.435 +     * @since 1.7
 172.436 +     */
 172.437 +    public static int fieldModifiers() {
 172.438 +        return FIELD_MODIFIERS;
 172.439 +    }
 172.440 +}
   173.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   173.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Type.java	Sun Feb 03 07:48:42 2013 +0100
   173.3 @@ -0,0 +1,37 @@
   173.4 +/*
   173.5 + * Copyright (c) 2003, 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 + * Type is the common superinterface for all types in the Java
  173.33 + * programming language. These include raw types, parameterized types,
  173.34 + * array types, type variables and primitive types.
  173.35 + *
  173.36 + * @since 1.5
  173.37 + */
  173.38 +
  173.39 +public interface Type {
  173.40 +}
   174.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   174.2 +++ b/emul/mini/src/main/java/java/lang/reflect/TypeVariable.java	Sun Feb 03 07:48:42 2013 +0100
   174.3 @@ -0,0 +1,89 @@
   174.4 +/*
   174.5 + * Copyright (c) 2003, 2005, 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 + * TypeVariable is the common superinterface for type variables of kinds.
  174.33 + * A type variable is created the first time it is needed by a reflective
  174.34 + * method, as specified in this package.  If a type variable t is referenced
  174.35 + * by a type (i.e, class, interface or annotation type) T, and T is declared
  174.36 + * by the nth enclosing class of T (see JLS 8.1.2), then the creation of t
  174.37 + * requires the resolution (see JVMS 5) of the ith enclosing class of T,
  174.38 + * for i = 0 to n, inclusive. Creating a type variable must not cause the
  174.39 + * creation of its bounds. Repeated creation of a type variable has no effect.
  174.40 + *
  174.41 + * <p>Multiple objects may be instantiated at run-time to
  174.42 + * represent a given type variable. Even though a type variable is
  174.43 + * created only once, this does not imply any requirement to cache
  174.44 + * instances representing the type variable. However, all instances
  174.45 + * representing a type variable must be equal() to each other.
  174.46 + * As a consequence, users of type variables must not rely on the identity
  174.47 + * of instances of classes implementing this interface.
  174.48 + *
  174.49 + * @param <D> the type of generic declaration that declared the
  174.50 + * underlying type variable.
  174.51 + *
  174.52 + * @since 1.5
  174.53 + */
  174.54 +public interface TypeVariable<D extends GenericDeclaration> extends Type {
  174.55 +    /**
  174.56 +     * Returns an array of {@code Type} objects representing the
  174.57 +     * upper bound(s) of this type variable.  Note that if no upper bound is
  174.58 +     * explicitly declared, the upper bound is {@code Object}.
  174.59 +     *
  174.60 +     * <p>For each upper bound B: <ul> <li>if B is a parameterized
  174.61 +     * type or a type variable, it is created, (see {@link
  174.62 +     * java.lang.reflect.ParameterizedType ParameterizedType} for the
  174.63 +     * details of the creation process for parameterized types).
  174.64 +     * <li>Otherwise, B is resolved.  </ul>
  174.65 +     *
  174.66 +     * @throws TypeNotPresentException  if any of the
  174.67 +     *     bounds refers to a non-existent type declaration
  174.68 +     * @throws MalformedParameterizedTypeException if any of the
  174.69 +     *     bounds refer to a parameterized type that cannot be instantiated
  174.70 +     *     for any reason
  174.71 +     * @return an array of {@code Type}s representing the upper
  174.72 +     *     bound(s) of this type variable
  174.73 +    */
  174.74 +    Type[] getBounds();
  174.75 +
  174.76 +    /**
  174.77 +     * Returns the {@code GenericDeclaration} object representing the
  174.78 +     * generic declaration declared this type variable.
  174.79 +     *
  174.80 +     * @return the generic declaration declared for this type variable.
  174.81 +     *
  174.82 +     * @since 1.5
  174.83 +     */
  174.84 +    D getGenericDeclaration();
  174.85 +
  174.86 +    /**
  174.87 +     * Returns the name of this type variable, as it occurs in the source code.
  174.88 +     *
  174.89 +     * @return the name of this type variable, as it appears in the source code
  174.90 +     */
  174.91 +    String getName();
  174.92 +}
   175.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   175.2 +++ b/emul/mini/src/main/java/java/lang/reflect/package-info.java	Sun Feb 03 07:48:42 2013 +0100
   175.3 @@ -0,0 +1,49 @@
   175.4 +/*
   175.5 + * Copyright (c) 1998, 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 +/**
  175.30 + * Provides classes and interfaces for obtaining reflective
  175.31 + * information about classes and objects.  Reflection allows
  175.32 + * programmatic access to information about the fields, methods and
  175.33 + * constructors of loaded classes, and the use of reflected fields,
  175.34 + * methods, and constructors to operate on their underlying
  175.35 + * counterparts, within security restrictions.
  175.36 + *
  175.37 + * <p>{@code AccessibleObject} allows suppression of access checks if
  175.38 + * the necessary {@code ReflectPermission} is available.
  175.39 + *
  175.40 + * <p>{@code Array} provides static methods to dynamically create and
  175.41 + * access arrays.
  175.42 + *
  175.43 + * <p>Classes in this package, along with {@code java.lang.Class}
  175.44 + * accommodate applications such as debuggers, interpreters, object
  175.45 + * inspectors, class browsers, and services such as Object
  175.46 + * Serialization and JavaBeans that need access to either the public
  175.47 + * members of a target object (based on its runtime class) or the
  175.48 + * members declared by a given class.
  175.49 + *
  175.50 + * @since JDK1.1
  175.51 + */
  175.52 +package java.lang.reflect;
   176.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   176.2 +++ b/emul/mini/src/main/java/java/net/MalformedURLException.java	Sun Feb 03 07:48:42 2013 +0100
   176.3 @@ -0,0 +1,56 @@
   176.4 +/*
   176.5 + * Copyright (c) 1995, 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.net;
  176.30 +
  176.31 +import java.io.IOException;
  176.32 +
  176.33 +/**
  176.34 + * Thrown to indicate that a malformed URL has occurred. Either no
  176.35 + * legal protocol could be found in a specification string or the
  176.36 + * string could not be parsed.
  176.37 + *
  176.38 + * @author  Arthur van Hoff
  176.39 + * @since   JDK1.0
  176.40 + */
  176.41 +public class MalformedURLException extends IOException {
  176.42 +    private static final long serialVersionUID = -182787522200415866L;
  176.43 +
  176.44 +    /**
  176.45 +     * Constructs a <code>MalformedURLException</code> with no detail message.
  176.46 +     */
  176.47 +    public MalformedURLException() {
  176.48 +    }
  176.49 +
  176.50 +    /**
  176.51 +     * Constructs a <code>MalformedURLException</code> with the
  176.52 +     * specified detail message.
  176.53 +     *
  176.54 +     * @param   msg   the detail message.
  176.55 +     */
  176.56 +    public MalformedURLException(String msg) {
  176.57 +        super(msg);
  176.58 +    }
  176.59 +}
   177.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   177.2 +++ b/emul/mini/src/main/java/java/net/URL.java	Sun Feb 03 07:48:42 2013 +0100
   177.3 @@ -0,0 +1,1047 @@
   177.4 +/*
   177.5 + * Copyright (c) 1995, 2008, 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.net;
  177.30 +
  177.31 +import java.io.IOException;
  177.32 +import java.io.InputStream;
  177.33 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  177.34 +
  177.35 +
  177.36 +/**
  177.37 + * Class <code>URL</code> represents a Uniform Resource
  177.38 + * Locator, a pointer to a "resource" on the World
  177.39 + * Wide Web. A resource can be something as simple as a file or a
  177.40 + * directory, or it can be a reference to a more complicated object,
  177.41 + * such as a query to a database or to a search engine. More
  177.42 + * information on the types of URLs and their formats can be found at:
  177.43 + * <blockquote>
  177.44 + *     <a href="http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html">
  177.45 + *    <i>http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html</i></a>
  177.46 + * </blockquote>
  177.47 + * <p>
  177.48 + * In general, a URL can be broken into several parts. The previous
  177.49 + * example of a URL indicates that the protocol to use is
  177.50 + * <code>http</code> (HyperText Transfer Protocol) and that the
  177.51 + * information resides on a host machine named
  177.52 + * <code>www.socs.uts.edu.au</code>. The information on that host
  177.53 + * machine is named <code>/MosaicDocs-old/url-primer.html</code>. The exact
  177.54 + * meaning of this name on the host machine is both protocol
  177.55 + * dependent and host dependent. The information normally resides in
  177.56 + * a file, but it could be generated on the fly. This component of
  177.57 + * the URL is called the <i>path</i> component.
  177.58 + * <p>
  177.59 + * A URL can optionally specify a "port", which is the
  177.60 + * port number to which the TCP connection is made on the remote host
  177.61 + * machine. If the port is not specified, the default port for
  177.62 + * the protocol is used instead. For example, the default port for
  177.63 + * <code>http</code> is <code>80</code>. An alternative port could be
  177.64 + * specified as:
  177.65 + * <blockquote><pre>
  177.66 + *     http://www.socs.uts.edu.au:80/MosaicDocs-old/url-primer.html
  177.67 + * </pre></blockquote>
  177.68 + * <p>
  177.69 + * The syntax of <code>URL</code> is defined by  <a
  177.70 + * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC&nbsp;2396: Uniform
  177.71 + * Resource Identifiers (URI): Generic Syntax</i></a>, amended by <a
  177.72 + * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC&nbsp;2732: Format for
  177.73 + * Literal IPv6 Addresses in URLs</i></a>. The Literal IPv6 address format
  177.74 + * also supports scope_ids. The syntax and usage of scope_ids is described
  177.75 + * <a href="Inet6Address.html#scoped">here</a>.
  177.76 + * <p>
  177.77 + * A URL may have appended to it a "fragment", also known
  177.78 + * as a "ref" or a "reference". The fragment is indicated by the sharp
  177.79 + * sign character "#" followed by more characters. For example,
  177.80 + * <blockquote><pre>
  177.81 + *     http://java.sun.com/index.html#chapter1
  177.82 + * </pre></blockquote>
  177.83 + * <p>
  177.84 + * This fragment is not technically part of the URL. Rather, it
  177.85 + * indicates that after the specified resource is retrieved, the
  177.86 + * application is specifically interested in that part of the
  177.87 + * document that has the tag <code>chapter1</code> attached to it. The
  177.88 + * meaning of a tag is resource specific.
  177.89 + * <p>
  177.90 + * An application can also specify a "relative URL",
  177.91 + * which contains only enough information to reach the resource
  177.92 + * relative to another URL. Relative URLs are frequently used within
  177.93 + * HTML pages. For example, if the contents of the URL:
  177.94 + * <blockquote><pre>
  177.95 + *     http://java.sun.com/index.html
  177.96 + * </pre></blockquote>
  177.97 + * contained within it the relative URL:
  177.98 + * <blockquote><pre>
  177.99 + *     FAQ.html
 177.100 + * </pre></blockquote>
 177.101 + * it would be a shorthand for:
 177.102 + * <blockquote><pre>
 177.103 + *     http://java.sun.com/FAQ.html
 177.104 + * </pre></blockquote>
 177.105 + * <p>
 177.106 + * The relative URL need not specify all the components of a URL. If
 177.107 + * the protocol, host name, or port number is missing, the value is
 177.108 + * inherited from the fully specified URL. The file component must be
 177.109 + * specified. The optional fragment is not inherited.
 177.110 + * <p>
 177.111 + * The URL class does not itself encode or decode any URL components
 177.112 + * according to the escaping mechanism defined in RFC2396. It is the
 177.113 + * responsibility of the caller to encode any fields, which need to be
 177.114 + * escaped prior to calling URL, and also to decode any escaped fields,
 177.115 + * that are returned from URL. Furthermore, because URL has no knowledge
 177.116 + * of URL escaping, it does not recognise equivalence between the encoded
 177.117 + * or decoded form of the same URL. For example, the two URLs:<br>
 177.118 + * <pre>    http://foo.com/hello world/ and http://foo.com/hello%20world</pre>
 177.119 + * would be considered not equal to each other.
 177.120 + * <p>
 177.121 + * Note, the {@link java.net.URI} class does perform escaping of its
 177.122 + * component fields in certain circumstances. The recommended way
 177.123 + * to manage the encoding and decoding of URLs is to use {@link java.net.URI},
 177.124 + * and to convert between these two classes using {@link #toURI()} and
 177.125 + * {@link URI#toURL()}.
 177.126 + * <p>
 177.127 + * The {@link URLEncoder} and {@link URLDecoder} classes can also be
 177.128 + * used, but only for HTML form encoding, which is not the same
 177.129 + * as the encoding scheme defined in RFC2396.
 177.130 + *
 177.131 + * @author  James Gosling
 177.132 + * @since JDK1.0
 177.133 + */
 177.134 +public final class URL implements java.io.Serializable {
 177.135 +
 177.136 +    static final long serialVersionUID = -7627629688361524110L;
 177.137 +
 177.138 +    /**
 177.139 +     * The property which specifies the package prefix list to be scanned
 177.140 +     * for protocol handlers.  The value of this property (if any) should
 177.141 +     * be a vertical bar delimited list of package names to search through
 177.142 +     * for a protocol handler to load.  The policy of this class is that
 177.143 +     * all protocol handlers will be in a class called <protocolname>.Handler,
 177.144 +     * and each package in the list is examined in turn for a matching
 177.145 +     * handler.  If none are found (or the property is not specified), the
 177.146 +     * default package prefix, sun.net.www.protocol, is used.  The search
 177.147 +     * proceeds from the first package in the list to the last and stops
 177.148 +     * when a match is found.
 177.149 +     */
 177.150 +    private static final String protocolPathProp = "java.protocol.handler.pkgs";
 177.151 +
 177.152 +    /**
 177.153 +     * The protocol to use (ftp, http, nntp, ... etc.) .
 177.154 +     * @serial
 177.155 +     */
 177.156 +    private String protocol;
 177.157 +
 177.158 +    /**
 177.159 +     * The host name to connect to.
 177.160 +     * @serial
 177.161 +     */
 177.162 +    private String host;
 177.163 +
 177.164 +    /**
 177.165 +     * The protocol port to connect to.
 177.166 +     * @serial
 177.167 +     */
 177.168 +    private int port = -1;
 177.169 +
 177.170 +    /**
 177.171 +     * The specified file name on that host. <code>file</code> is
 177.172 +     * defined as <code>path[?query]</code>
 177.173 +     * @serial
 177.174 +     */
 177.175 +    private String file;
 177.176 +
 177.177 +    /**
 177.178 +     * The query part of this URL.
 177.179 +     */
 177.180 +    private transient String query;
 177.181 +
 177.182 +    /**
 177.183 +     * The authority part of this URL.
 177.184 +     * @serial
 177.185 +     */
 177.186 +    private String authority;
 177.187 +
 177.188 +    /**
 177.189 +     * The path part of this URL.
 177.190 +     */
 177.191 +    private transient String path;
 177.192 +
 177.193 +    /**
 177.194 +     * The userinfo part of this URL.
 177.195 +     */
 177.196 +    private transient String userInfo;
 177.197 +
 177.198 +    /**
 177.199 +     * # reference.
 177.200 +     * @serial
 177.201 +     */
 177.202 +    private String ref;
 177.203 +
 177.204 +    /**
 177.205 +     * The host's IP address, used in equals and hashCode.
 177.206 +     * Computed on demand. An uninitialized or unknown hostAddress is null.
 177.207 +     */
 177.208 +    transient Object hostAddress;
 177.209 +
 177.210 +    /**
 177.211 +     * The URLStreamHandler for this URL.
 177.212 +     */
 177.213 +    transient URLStreamHandler handler;
 177.214 +
 177.215 +    /* Our hash code.
 177.216 +     * @serial
 177.217 +     */
 177.218 +    private int hashCode = -1;
 177.219 +    
 177.220 +    /** input stream associated with the URL */
 177.221 +    private InputStream is;
 177.222 +
 177.223 +    /**
 177.224 +     * Creates a <code>URL</code> object from the specified
 177.225 +     * <code>protocol</code>, <code>host</code>, <code>port</code>
 177.226 +     * number, and <code>file</code>.<p>
 177.227 +     *
 177.228 +     * <code>host</code> can be expressed as a host name or a literal
 177.229 +     * IP address. If IPv6 literal address is used, it should be
 177.230 +     * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>), as
 177.231 +     * specified by <a
 177.232 +     * href="http://www.ietf.org/rfc/rfc2732.txt">RFC&nbsp;2732</a>;
 177.233 +     * However, the literal IPv6 address format defined in <a
 177.234 +     * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC&nbsp;2373: IP
 177.235 +     * Version 6 Addressing Architecture</i></a> is also accepted.<p>
 177.236 +     *
 177.237 +     * Specifying a <code>port</code> number of <code>-1</code>
 177.238 +     * indicates that the URL should use the default port for the
 177.239 +     * protocol.<p>
 177.240 +     *
 177.241 +     * If this is the first URL object being created with the specified
 177.242 +     * protocol, a <i>stream protocol handler</i> object, an instance of
 177.243 +     * class <code>URLStreamHandler</code>, is created for that protocol:
 177.244 +     * <ol>
 177.245 +     * <li>If the application has previously set up an instance of
 177.246 +     *     <code>URLStreamHandlerFactory</code> as the stream handler factory,
 177.247 +     *     then the <code>createURLStreamHandler</code> method of that instance
 177.248 +     *     is called with the protocol string as an argument to create the
 177.249 +     *     stream protocol handler.
 177.250 +     * <li>If no <code>URLStreamHandlerFactory</code> has yet been set up,
 177.251 +     *     or if the factory's <code>createURLStreamHandler</code> method
 177.252 +     *     returns <code>null</code>, then the constructor finds the
 177.253 +     *     value of the system property:
 177.254 +     *     <blockquote><pre>
 177.255 +     *         java.protocol.handler.pkgs
 177.256 +     *     </pre></blockquote>
 177.257 +     *     If the value of that system property is not <code>null</code>,
 177.258 +     *     it is interpreted as a list of packages separated by a vertical
 177.259 +     *     slash character '<code>|</code>'. The constructor tries to load
 177.260 +     *     the class named:
 177.261 +     *     <blockquote><pre>
 177.262 +     *         &lt;<i>package</i>&gt;.&lt;<i>protocol</i>&gt;.Handler
 177.263 +     *     </pre></blockquote>
 177.264 +     *     where &lt;<i>package</i>&gt; is replaced by the name of the package
 177.265 +     *     and &lt;<i>protocol</i>&gt; is replaced by the name of the protocol.
 177.266 +     *     If this class does not exist, or if the class exists but it is not
 177.267 +     *     a subclass of <code>URLStreamHandler</code>, then the next package
 177.268 +     *     in the list is tried.
 177.269 +     * <li>If the previous step fails to find a protocol handler, then the
 177.270 +     *     constructor tries to load from a system default package.
 177.271 +     *     <blockquote><pre>
 177.272 +     *         &lt;<i>system default package</i>&gt;.&lt;<i>protocol</i>&gt;.Handler
 177.273 +     *     </pre></blockquote>
 177.274 +     *     If this class does not exist, or if the class exists but it is not a
 177.275 +     *     subclass of <code>URLStreamHandler</code>, then a
 177.276 +     *     <code>MalformedURLException</code> is thrown.
 177.277 +     * </ol>
 177.278 +     *
 177.279 +     * <p>Protocol handlers for the following protocols are guaranteed
 177.280 +     * to exist on the search path :-
 177.281 +     * <blockquote><pre>
 177.282 +     *     http, https, ftp, file, and jar
 177.283 +     * </pre></blockquote>
 177.284 +     * Protocol handlers for additional protocols may also be
 177.285 +     * available.
 177.286 +     *
 177.287 +     * <p>No validation of the inputs is performed by this constructor.
 177.288 +     *
 177.289 +     * @param      protocol   the name of the protocol to use.
 177.290 +     * @param      host       the name of the host.
 177.291 +     * @param      port       the port number on the host.
 177.292 +     * @param      file       the file on the host
 177.293 +     * @exception  MalformedURLException  if an unknown protocol is specified.
 177.294 +     * @see        java.lang.System#getProperty(java.lang.String)
 177.295 +     * @see        java.net.URL#setURLStreamHandlerFactory(
 177.296 +     *                  java.net.URLStreamHandlerFactory)
 177.297 +     * @see        java.net.URLStreamHandler
 177.298 +     * @see        java.net.URLStreamHandlerFactory#createURLStreamHandler(
 177.299 +     *                  java.lang.String)
 177.300 +     */
 177.301 +    public URL(String protocol, String host, int port, String file)
 177.302 +        throws MalformedURLException
 177.303 +    {
 177.304 +        this(protocol, host, port, file, null);
 177.305 +    }
 177.306 +
 177.307 +    /**
 177.308 +     * Creates a URL from the specified <code>protocol</code>
 177.309 +     * name, <code>host</code> name, and <code>file</code> name. The
 177.310 +     * default port for the specified protocol is used.
 177.311 +     * <p>
 177.312 +     * This method is equivalent to calling the four-argument
 177.313 +     * constructor with the arguments being <code>protocol</code>,
 177.314 +     * <code>host</code>, <code>-1</code>, and <code>file</code>.
 177.315 +     *
 177.316 +     * No validation of the inputs is performed by this constructor.
 177.317 +     *
 177.318 +     * @param      protocol   the name of the protocol to use.
 177.319 +     * @param      host       the name of the host.
 177.320 +     * @param      file       the file on the host.
 177.321 +     * @exception  MalformedURLException  if an unknown protocol is specified.
 177.322 +     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 177.323 +     *                  int, java.lang.String)
 177.324 +     */
 177.325 +    public URL(String protocol, String host, String file)
 177.326 +            throws MalformedURLException {
 177.327 +        this(protocol, host, -1, file);
 177.328 +    }
 177.329 +
 177.330 +    /**
 177.331 +     * Creates a <code>URL</code> object from the specified
 177.332 +     * <code>protocol</code>, <code>host</code>, <code>port</code>
 177.333 +     * number, <code>file</code>, and <code>handler</code>. Specifying
 177.334 +     * a <code>port</code> number of <code>-1</code> indicates that
 177.335 +     * the URL should use the default port for the protocol. Specifying
 177.336 +     * a <code>handler</code> of <code>null</code> indicates that the URL
 177.337 +     * should use a default stream handler for the protocol, as outlined
 177.338 +     * for:
 177.339 +     *     java.net.URL#URL(java.lang.String, java.lang.String, int,
 177.340 +     *                      java.lang.String)
 177.341 +     *
 177.342 +     * <p>If the handler is not null and there is a security manager,
 177.343 +     * the security manager's <code>checkPermission</code>
 177.344 +     * method is called with a
 177.345 +     * <code>NetPermission("specifyStreamHandler")</code> permission.
 177.346 +     * This may result in a SecurityException.
 177.347 +     *
 177.348 +     * No validation of the inputs is performed by this constructor.
 177.349 +     *
 177.350 +     * @param      protocol   the name of the protocol to use.
 177.351 +     * @param      host       the name of the host.
 177.352 +     * @param      port       the port number on the host.
 177.353 +     * @param      file       the file on the host
 177.354 +     * @param      handler    the stream handler for the URL.
 177.355 +     * @exception  MalformedURLException  if an unknown protocol is specified.
 177.356 +     * @exception  SecurityException
 177.357 +     *        if a security manager exists and its
 177.358 +     *        <code>checkPermission</code> method doesn't allow
 177.359 +     *        specifying a stream handler explicitly.
 177.360 +     * @see        java.lang.System#getProperty(java.lang.String)
 177.361 +     * @see        java.net.URL#setURLStreamHandlerFactory(
 177.362 +     *                  java.net.URLStreamHandlerFactory)
 177.363 +     * @see        java.net.URLStreamHandler
 177.364 +     * @see        java.net.URLStreamHandlerFactory#createURLStreamHandler(
 177.365 +     *                  java.lang.String)
 177.366 +     * @see        SecurityManager#checkPermission
 177.367 +     * @see        java.net.NetPermission
 177.368 +     */
 177.369 +    public URL(String protocol, String host, int port, String file,
 177.370 +               URLStreamHandler handler) throws MalformedURLException {
 177.371 +        if (handler != null) {
 177.372 +            throw new SecurityException();
 177.373 +        }
 177.374 +
 177.375 +        protocol = protocol.toLowerCase();
 177.376 +        this.protocol = protocol;
 177.377 +        if (host != null) {
 177.378 +
 177.379 +            /**
 177.380 +             * if host is a literal IPv6 address,
 177.381 +             * we will make it conform to RFC 2732
 177.382 +             */
 177.383 +            if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
 177.384 +                host = "["+host+"]";
 177.385 +            }
 177.386 +            this.host = host;
 177.387 +
 177.388 +            if (port < -1) {
 177.389 +                throw new MalformedURLException("Invalid port number :" +
 177.390 +                                                    port);
 177.391 +            }
 177.392 +            this.port = port;
 177.393 +            authority = (port == -1) ? host : host + ":" + port;
 177.394 +        }
 177.395 +
 177.396 +        Parts parts = new Parts(file);
 177.397 +        path = parts.getPath();
 177.398 +        query = parts.getQuery();
 177.399 +
 177.400 +        if (query != null) {
 177.401 +            this.file = path + "?" + query;
 177.402 +        } else {
 177.403 +            this.file = path;
 177.404 +        }
 177.405 +        ref = parts.getRef();
 177.406 +
 177.407 +        // Note: we don't do validation of the URL here. Too risky to change
 177.408 +        // right now, but worth considering for future reference. -br
 177.409 +        if (handler == null &&
 177.410 +            (handler = getURLStreamHandler(protocol)) == null) {
 177.411 +            throw new MalformedURLException("unknown protocol: " + protocol);
 177.412 +        }
 177.413 +        this.handler = handler;
 177.414 +    }
 177.415 +
 177.416 +    /**
 177.417 +     * Creates a <code>URL</code> object from the <code>String</code>
 177.418 +     * representation.
 177.419 +     * <p>
 177.420 +     * This constructor is equivalent to a call to the two-argument
 177.421 +     * constructor with a <code>null</code> first argument.
 177.422 +     *
 177.423 +     * @param      spec   the <code>String</code> to parse as a URL.
 177.424 +     * @exception  MalformedURLException  if no protocol is specified, or an
 177.425 +     *               unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
 177.426 +     * @see        java.net.URL#URL(java.net.URL, java.lang.String)
 177.427 +     */
 177.428 +    public URL(String spec) throws MalformedURLException {
 177.429 +        this(null, spec);
 177.430 +    }
 177.431 +    
 177.432 +    private URL(String spec, InputStream is) throws MalformedURLException {
 177.433 +        this(null, spec);
 177.434 +        this.is = is;
 177.435 +    }
 177.436 +
 177.437 +    /**
 177.438 +     * Creates a URL by parsing the given spec within a specified context.
 177.439 +     *
 177.440 +     * The new URL is created from the given context URL and the spec
 177.441 +     * argument as described in
 177.442 +     * RFC2396 &quot;Uniform Resource Identifiers : Generic * Syntax&quot; :
 177.443 +     * <blockquote><pre>
 177.444 +     *          &lt;scheme&gt;://&lt;authority&gt;&lt;path&gt;?&lt;query&gt;#&lt;fragment&gt;
 177.445 +     * </pre></blockquote>
 177.446 +     * The reference is parsed into the scheme, authority, path, query and
 177.447 +     * fragment parts. If the path component is empty and the scheme,
 177.448 +     * authority, and query components are undefined, then the new URL is a
 177.449 +     * reference to the current document. Otherwise, the fragment and query
 177.450 +     * parts present in the spec are used in the new URL.
 177.451 +     * <p>
 177.452 +     * If the scheme component is defined in the given spec and does not match
 177.453 +     * the scheme of the context, then the new URL is created as an absolute
 177.454 +     * URL based on the spec alone. Otherwise the scheme component is inherited
 177.455 +     * from the context URL.
 177.456 +     * <p>
 177.457 +     * If the authority component is present in the spec then the spec is
 177.458 +     * treated as absolute and the spec authority and path will replace the
 177.459 +     * context authority and path. If the authority component is absent in the
 177.460 +     * spec then the authority of the new URL will be inherited from the
 177.461 +     * context.
 177.462 +     * <p>
 177.463 +     * If the spec's path component begins with a slash character
 177.464 +     * &quot;/&quot; then the
 177.465 +     * path is treated as absolute and the spec path replaces the context path.
 177.466 +     * <p>
 177.467 +     * Otherwise, the path is treated as a relative path and is appended to the
 177.468 +     * context path, as described in RFC2396. Also, in this case,
 177.469 +     * the path is canonicalized through the removal of directory
 177.470 +     * changes made by occurences of &quot;..&quot; and &quot;.&quot;.
 177.471 +     * <p>
 177.472 +     * For a more detailed description of URL parsing, refer to RFC2396.
 177.473 +     *
 177.474 +     * @param      context   the context in which to parse the specification.
 177.475 +     * @param      spec      the <code>String</code> to parse as a URL.
 177.476 +     * @exception  MalformedURLException  if no protocol is specified, or an
 177.477 +     *               unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
 177.478 +     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 177.479 +     *                  int, java.lang.String)
 177.480 +     * @see        java.net.URLStreamHandler
 177.481 +     * @see        java.net.URLStreamHandler#parseURL(java.net.URL,
 177.482 +     *                  java.lang.String, int, int)
 177.483 +     */
 177.484 +    public URL(URL context, String spec) throws MalformedURLException {
 177.485 +        this(context, spec, null);
 177.486 +    }
 177.487 +
 177.488 +    /**
 177.489 +     * Creates a URL by parsing the given spec with the specified handler
 177.490 +     * within a specified context. If the handler is null, the parsing
 177.491 +     * occurs as with the two argument constructor.
 177.492 +     *
 177.493 +     * @param      context   the context in which to parse the specification.
 177.494 +     * @param      spec      the <code>String</code> to parse as a URL.
 177.495 +     * @param      handler   the stream handler for the URL.
 177.496 +     * @exception  MalformedURLException  if no protocol is specified, or an
 177.497 +     *               unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
 177.498 +     * @exception  SecurityException
 177.499 +     *        if a security manager exists and its
 177.500 +     *        <code>checkPermission</code> method doesn't allow
 177.501 +     *        specifying a stream handler.
 177.502 +     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 177.503 +     *                  int, java.lang.String)
 177.504 +     * @see        java.net.URLStreamHandler
 177.505 +     * @see        java.net.URLStreamHandler#parseURL(java.net.URL,
 177.506 +     *                  java.lang.String, int, int)
 177.507 +     */
 177.508 +    public URL(URL context, String spec, URLStreamHandler handler)
 177.509 +        throws MalformedURLException
 177.510 +    {
 177.511 +        String original = spec;
 177.512 +        int i, limit, c;
 177.513 +        int start = 0;
 177.514 +        String newProtocol = null;
 177.515 +        boolean aRef=false;
 177.516 +        boolean isRelative = false;
 177.517 +
 177.518 +        // Check for permission to specify a handler
 177.519 +        if (handler != null) {
 177.520 +            throw new SecurityException();
 177.521 +        }
 177.522 +
 177.523 +        try {
 177.524 +            limit = spec.length();
 177.525 +            while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) {
 177.526 +                limit--;        //eliminate trailing whitespace
 177.527 +            }
 177.528 +            while ((start < limit) && (spec.charAt(start) <= ' ')) {
 177.529 +                start++;        // eliminate leading whitespace
 177.530 +            }
 177.531 +
 177.532 +            if (spec.regionMatches(true, start, "url:", 0, 4)) {
 177.533 +                start += 4;
 177.534 +            }
 177.535 +            if (start < spec.length() && spec.charAt(start) == '#') {
 177.536 +                /* we're assuming this is a ref relative to the context URL.
 177.537 +                 * This means protocols cannot start w/ '#', but we must parse
 177.538 +                 * ref URL's like: "hello:there" w/ a ':' in them.
 177.539 +                 */
 177.540 +                aRef=true;
 177.541 +            }
 177.542 +            for (i = start ; !aRef && (i < limit) &&
 177.543 +                     ((c = spec.charAt(i)) != '/') ; i++) {
 177.544 +                if (c == ':') {
 177.545 +
 177.546 +                    String s = spec.substring(start, i).toLowerCase();
 177.547 +                    if (isValidProtocol(s)) {
 177.548 +                        newProtocol = s;
 177.549 +                        start = i + 1;
 177.550 +                    }
 177.551 +                    break;
 177.552 +                }
 177.553 +            }
 177.554 +
 177.555 +            // Only use our context if the protocols match.
 177.556 +            protocol = newProtocol;
 177.557 +            if ((context != null) && ((newProtocol == null) ||
 177.558 +                            newProtocol.equalsIgnoreCase(context.protocol))) {
 177.559 +                // inherit the protocol handler from the context
 177.560 +                // if not specified to the constructor
 177.561 +                if (handler == null) {
 177.562 +                    handler = context.handler;
 177.563 +                }
 177.564 +
 177.565 +                // If the context is a hierarchical URL scheme and the spec
 177.566 +                // contains a matching scheme then maintain backwards
 177.567 +                // compatibility and treat it as if the spec didn't contain
 177.568 +                // the scheme; see 5.2.3 of RFC2396
 177.569 +                if (context.path != null && context.path.startsWith("/"))
 177.570 +                    newProtocol = null;
 177.571 +
 177.572 +                if (newProtocol == null) {
 177.573 +                    protocol = context.protocol;
 177.574 +                    authority = context.authority;
 177.575 +                    userInfo = context.userInfo;
 177.576 +                    host = context.host;
 177.577 +                    port = context.port;
 177.578 +                    file = context.file;
 177.579 +                    path = context.path;
 177.580 +                    isRelative = true;
 177.581 +                }
 177.582 +            }
 177.583 +
 177.584 +            if (protocol == null) {
 177.585 +                throw new MalformedURLException("no protocol: "+original);
 177.586 +            }
 177.587 +
 177.588 +            // Get the protocol handler if not specified or the protocol
 177.589 +            // of the context could not be used
 177.590 +            if (handler == null &&
 177.591 +                (handler = getURLStreamHandler(protocol)) == null) {
 177.592 +                throw new MalformedURLException("unknown protocol: "+protocol);
 177.593 +            }
 177.594 +            this.handler = handler;
 177.595 +
 177.596 +            i = spec.indexOf('#', start);
 177.597 +            if (i >= 0) {
 177.598 +//thrw(protocol + " hnd: " + handler.getClass().getName() + " i: " + i);
 177.599 +                ref = spec.substring(i + 1, limit);
 177.600 +                limit = i;
 177.601 +            }
 177.602 +
 177.603 +            /*
 177.604 +             * Handle special case inheritance of query and fragment
 177.605 +             * implied by RFC2396 section 5.2.2.
 177.606 +             */
 177.607 +            if (isRelative && start == limit) {
 177.608 +                query = context.query;
 177.609 +                if (ref == null) {
 177.610 +                    ref = context.ref;
 177.611 +                }
 177.612 +            }
 177.613 +
 177.614 +            handler.parseURL(this, spec, start, limit);
 177.615 +
 177.616 +        } catch(MalformedURLException e) {
 177.617 +            throw e;
 177.618 +        } catch(Exception e) {
 177.619 +            MalformedURLException exception = new MalformedURLException(e.getMessage());
 177.620 +            exception.initCause(e);
 177.621 +            throw exception;
 177.622 +        }
 177.623 +    }
 177.624 +    
 177.625 +    /*
 177.626 +     * Returns true if specified string is a valid protocol name.
 177.627 +     */
 177.628 +    private boolean isValidProtocol(String protocol) {
 177.629 +        int len = protocol.length();
 177.630 +        if (len < 1)
 177.631 +            return false;
 177.632 +        char c = protocol.charAt(0);
 177.633 +        if (!Character.isLetter(c))
 177.634 +            return false;
 177.635 +        for (int i = 1; i < len; i++) {
 177.636 +            c = protocol.charAt(i);
 177.637 +            if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' &&
 177.638 +                c != '-') {
 177.639 +                return false;
 177.640 +            }
 177.641 +        }
 177.642 +        return true;
 177.643 +    }
 177.644 +
 177.645 +    /**
 177.646 +     * Sets the fields of the URL. This is not a public method so that
 177.647 +     * only URLStreamHandlers can modify URL fields. URLs are
 177.648 +     * otherwise constant.
 177.649 +     *
 177.650 +     * @param protocol the name of the protocol to use
 177.651 +     * @param host the name of the host
 177.652 +       @param port the port number on the host
 177.653 +     * @param file the file on the host
 177.654 +     * @param ref the internal reference in the URL
 177.655 +     */
 177.656 +    protected void set(String protocol, String host,
 177.657 +                       int port, String file, String ref) {
 177.658 +        synchronized (this) {
 177.659 +            this.protocol = protocol;
 177.660 +            this.host = host;
 177.661 +            authority = port == -1 ? host : host + ":" + port;
 177.662 +            this.port = port;
 177.663 +            this.file = file;
 177.664 +            this.ref = ref;
 177.665 +            /* This is very important. We must recompute this after the
 177.666 +             * URL has been changed. */
 177.667 +            hashCode = -1;
 177.668 +            hostAddress = null;
 177.669 +            int q = file.lastIndexOf('?');
 177.670 +            if (q != -1) {
 177.671 +                query = file.substring(q+1);
 177.672 +                path = file.substring(0, q);
 177.673 +            } else
 177.674 +                path = file;
 177.675 +        }
 177.676 +    }
 177.677 +
 177.678 +    /**
 177.679 +     * Sets the specified 8 fields of the URL. This is not a public method so
 177.680 +     * that only URLStreamHandlers can modify URL fields. URLs are otherwise
 177.681 +     * constant.
 177.682 +     *
 177.683 +     * @param protocol the name of the protocol to use
 177.684 +     * @param host the name of the host
 177.685 +     * @param port the port number on the host
 177.686 +     * @param authority the authority part for the url
 177.687 +     * @param userInfo the username and password
 177.688 +     * @param path the file on the host
 177.689 +     * @param ref the internal reference in the URL
 177.690 +     * @param query the query part of this URL
 177.691 +     * @since 1.3
 177.692 +     */
 177.693 +    protected void set(String protocol, String host, int port,
 177.694 +                       String authority, String userInfo, String path,
 177.695 +                       String query, String ref) {
 177.696 +        synchronized (this) {
 177.697 +            this.protocol = protocol;
 177.698 +            this.host = host;
 177.699 +            this.port = port;
 177.700 +            this.file = query == null ? path : path + "?" + query;
 177.701 +            this.userInfo = userInfo;
 177.702 +            this.path = path;
 177.703 +            this.ref = ref;
 177.704 +            /* This is very important. We must recompute this after the
 177.705 +             * URL has been changed. */
 177.706 +            hashCode = -1;
 177.707 +            hostAddress = null;
 177.708 +            this.query = query;
 177.709 +            this.authority = authority;
 177.710 +        }
 177.711 +    }
 177.712 +
 177.713 +    /**
 177.714 +     * Gets the query part of this <code>URL</code>.
 177.715 +     *
 177.716 +     * @return  the query part of this <code>URL</code>,
 177.717 +     * or <CODE>null</CODE> if one does not exist
 177.718 +     * @since 1.3
 177.719 +     */
 177.720 +    public String getQuery() {
 177.721 +        return query;
 177.722 +    }
 177.723 +
 177.724 +    /**
 177.725 +     * Gets the path part of this <code>URL</code>.
 177.726 +     *
 177.727 +     * @return  the path part of this <code>URL</code>, or an
 177.728 +     * empty string if one does not exist
 177.729 +     * @since 1.3
 177.730 +     */
 177.731 +    public String getPath() {
 177.732 +        return path;
 177.733 +    }
 177.734 +
 177.735 +    /**
 177.736 +     * Gets the userInfo part of this <code>URL</code>.
 177.737 +     *
 177.738 +     * @return  the userInfo part of this <code>URL</code>, or
 177.739 +     * <CODE>null</CODE> if one does not exist
 177.740 +     * @since 1.3
 177.741 +     */
 177.742 +    public String getUserInfo() {
 177.743 +        return userInfo;
 177.744 +    }
 177.745 +
 177.746 +    /**
 177.747 +     * Gets the authority part of this <code>URL</code>.
 177.748 +     *
 177.749 +     * @return  the authority part of this <code>URL</code>
 177.750 +     * @since 1.3
 177.751 +     */
 177.752 +    public String getAuthority() {
 177.753 +        return authority;
 177.754 +    }
 177.755 +
 177.756 +    /**
 177.757 +     * Gets the port number of this <code>URL</code>.
 177.758 +     *
 177.759 +     * @return  the port number, or -1 if the port is not set
 177.760 +     */
 177.761 +    public int getPort() {
 177.762 +        return port;
 177.763 +    }
 177.764 +
 177.765 +    /**
 177.766 +     * Gets the default port number of the protocol associated
 177.767 +     * with this <code>URL</code>. If the URL scheme or the URLStreamHandler
 177.768 +     * for the URL do not define a default port number,
 177.769 +     * then -1 is returned.
 177.770 +     *
 177.771 +     * @return  the port number
 177.772 +     * @since 1.4
 177.773 +     */
 177.774 +    public int getDefaultPort() {
 177.775 +        return handler.getDefaultPort();
 177.776 +    }
 177.777 +
 177.778 +    /**
 177.779 +     * Gets the protocol name of this <code>URL</code>.
 177.780 +     *
 177.781 +     * @return  the protocol of this <code>URL</code>.
 177.782 +     */
 177.783 +    public String getProtocol() {
 177.784 +        return protocol;
 177.785 +    }
 177.786 +
 177.787 +    /**
 177.788 +     * Gets the host name of this <code>URL</code>, if applicable.
 177.789 +     * The format of the host conforms to RFC 2732, i.e. for a
 177.790 +     * literal IPv6 address, this method will return the IPv6 address
 177.791 +     * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>).
 177.792 +     *
 177.793 +     * @return  the host name of this <code>URL</code>.
 177.794 +     */
 177.795 +    public String getHost() {
 177.796 +        return host;
 177.797 +    }
 177.798 +
 177.799 +    /**
 177.800 +     * Gets the file name of this <code>URL</code>.
 177.801 +     * The returned file portion will be
 177.802 +     * the same as <CODE>getPath()</CODE>, plus the concatenation of
 177.803 +     * the value of <CODE>getQuery()</CODE>, if any. If there is
 177.804 +     * no query portion, this method and <CODE>getPath()</CODE> will
 177.805 +     * return identical results.
 177.806 +     *
 177.807 +     * @return  the file name of this <code>URL</code>,
 177.808 +     * or an empty string if one does not exist
 177.809 +     */
 177.810 +    public String getFile() {
 177.811 +        return file;
 177.812 +    }
 177.813 +
 177.814 +    /**
 177.815 +     * Gets the anchor (also known as the "reference") of this
 177.816 +     * <code>URL</code>.
 177.817 +     *
 177.818 +     * @return  the anchor (also known as the "reference") of this
 177.819 +     *          <code>URL</code>, or <CODE>null</CODE> if one does not exist
 177.820 +     */
 177.821 +    public String getRef() {
 177.822 +        return ref;
 177.823 +    }
 177.824 +
 177.825 +    /**
 177.826 +     * Compares this URL for equality with another object.<p>
 177.827 +     *
 177.828 +     * If the given object is not a URL then this method immediately returns
 177.829 +     * <code>false</code>.<p>
 177.830 +     *
 177.831 +     * Two URL objects are equal if they have the same protocol, reference
 177.832 +     * equivalent hosts, have the same port number on the host, and the same
 177.833 +     * file and fragment of the file.<p>
 177.834 +     *
 177.835 +     * Two hosts are considered equivalent if both host names can be resolved
 177.836 +     * into the same IP addresses; else if either host name can't be
 177.837 +     * resolved, the host names must be equal without regard to case; or both
 177.838 +     * host names equal to null.<p>
 177.839 +     *
 177.840 +     * Since hosts comparison requires name resolution, this operation is a
 177.841 +     * blocking operation. <p>
 177.842 +     *
 177.843 +     * Note: The defined behavior for <code>equals</code> is known to
 177.844 +     * be inconsistent with virtual hosting in HTTP.
 177.845 +     *
 177.846 +     * @param   obj   the URL to compare against.
 177.847 +     * @return  <code>true</code> if the objects are the same;
 177.848 +     *          <code>false</code> otherwise.
 177.849 +     */
 177.850 +    public boolean equals(Object obj) {
 177.851 +        if (!(obj instanceof URL))
 177.852 +            return false;
 177.853 +        URL u2 = (URL)obj;
 177.854 +
 177.855 +        return handler.equals(this, u2);
 177.856 +    }
 177.857 +
 177.858 +    /**
 177.859 +     * Creates an integer suitable for hash table indexing.<p>
 177.860 +     *
 177.861 +     * The hash code is based upon all the URL components relevant for URL
 177.862 +     * comparison. As such, this operation is a blocking operation.<p>
 177.863 +     *
 177.864 +     * @return  a hash code for this <code>URL</code>.
 177.865 +     */
 177.866 +    public synchronized int hashCode() {
 177.867 +        if (hashCode != -1)
 177.868 +            return hashCode;
 177.869 +
 177.870 +        hashCode = handler.hashCode(this);
 177.871 +        return hashCode;
 177.872 +    }
 177.873 +
 177.874 +    /**
 177.875 +     * Compares two URLs, excluding the fragment component.<p>
 177.876 +     *
 177.877 +     * Returns <code>true</code> if this <code>URL</code> and the
 177.878 +     * <code>other</code> argument are equal without taking the
 177.879 +     * fragment component into consideration.
 177.880 +     *
 177.881 +     * @param   other   the <code>URL</code> to compare against.
 177.882 +     * @return  <code>true</code> if they reference the same remote object;
 177.883 +     *          <code>false</code> otherwise.
 177.884 +     */
 177.885 +    public boolean sameFile(URL other) {
 177.886 +        return handler.sameFile(this, other);
 177.887 +    }
 177.888 +
 177.889 +    /**
 177.890 +     * Constructs a string representation of this <code>URL</code>. The
 177.891 +     * string is created by calling the <code>toExternalForm</code>
 177.892 +     * method of the stream protocol handler for this object.
 177.893 +     *
 177.894 +     * @return  a string representation of this object.
 177.895 +     * @see     java.net.URL#URL(java.lang.String, java.lang.String, int,
 177.896 +     *                  java.lang.String)
 177.897 +     * @see     java.net.URLStreamHandler#toExternalForm(java.net.URL)
 177.898 +     */
 177.899 +    public String toString() {
 177.900 +        return toExternalForm();
 177.901 +    }
 177.902 +
 177.903 +    /**
 177.904 +     * Constructs a string representation of this <code>URL</code>. The
 177.905 +     * string is created by calling the <code>toExternalForm</code>
 177.906 +     * method of the stream protocol handler for this object.
 177.907 +     *
 177.908 +     * @return  a string representation of this object.
 177.909 +     * @see     java.net.URL#URL(java.lang.String, java.lang.String,
 177.910 +     *                  int, java.lang.String)
 177.911 +     * @see     java.net.URLStreamHandler#toExternalForm(java.net.URL)
 177.912 +     */
 177.913 +    public String toExternalForm() {
 177.914 +        return handler.toExternalForm(this);
 177.915 +    }
 177.916 +
 177.917 +    /**
 177.918 +     * Returns a {@link java.net.URLConnection URLConnection} instance that
 177.919 +     * represents a connection to the remote object referred to by the
 177.920 +     * {@code URL}.
 177.921 +     *
 177.922 +     * <P>A new instance of {@linkplain java.net.URLConnection URLConnection} is
 177.923 +     * created every time when invoking the
 177.924 +     * {@linkplain java.net.URLStreamHandler#openConnection(URL)
 177.925 +     * URLStreamHandler.openConnection(URL)} method of the protocol handler for
 177.926 +     * this URL.</P>
 177.927 +     *
 177.928 +     * <P>It should be noted that a URLConnection instance does not establish
 177.929 +     * the actual network connection on creation. This will happen only when
 177.930 +     * calling {@linkplain java.net.URLConnection#connect() URLConnection.connect()}.</P>
 177.931 +     *
 177.932 +     * <P>If for the URL's protocol (such as HTTP or JAR), there
 177.933 +     * exists a public, specialized URLConnection subclass belonging
 177.934 +     * to one of the following packages or one of their subpackages:
 177.935 +     * java.lang, java.io, java.util, java.net, the connection
 177.936 +     * returned will be of that subclass. For example, for HTTP an
 177.937 +     * HttpURLConnection will be returned, and for JAR a
 177.938 +     * JarURLConnection will be returned.</P>
 177.939 +     *
 177.940 +     * @return     a {@link java.net.URLConnection URLConnection} linking
 177.941 +     *             to the URL.
 177.942 +     * @exception  IOException  if an I/O exception occurs.
 177.943 +     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 177.944 +     *             int, java.lang.String)
 177.945 +     */
 177.946 +//    public URLConnection openConnection() throws java.io.IOException {
 177.947 +//        return handler.openConnection(this);
 177.948 +//    }
 177.949 +
 177.950 +
 177.951 +    /**
 177.952 +     * Opens a connection to this <code>URL</code> and returns an
 177.953 +     * <code>InputStream</code> for reading from that connection. This
 177.954 +     * method is a shorthand for:
 177.955 +     * <blockquote><pre>
 177.956 +     *     openConnection().getInputStream()
 177.957 +     * </pre></blockquote>
 177.958 +     *
 177.959 +     * @return     an input stream for reading from the URL connection.
 177.960 +     * @exception  IOException  if an I/O exception occurs.
 177.961 +     * @see        java.net.URL#openConnection()
 177.962 +     * @see        java.net.URLConnection#getInputStream()
 177.963 +     */
 177.964 +    public final InputStream openStream() throws java.io.IOException {
 177.965 +        if (is != null) {
 177.966 +            return is;
 177.967 +        }
 177.968 +        throw new IOException();
 177.969 +    }
 177.970 +
 177.971 +    /**
 177.972 +     * Gets the contents of this URL. This method is a shorthand for:
 177.973 +     * <blockquote><pre>
 177.974 +     *     openConnection().getContent()
 177.975 +     * </pre></blockquote>
 177.976 +     *
 177.977 +     * @return     the contents of this URL.
 177.978 +     * @exception  IOException  if an I/O exception occurs.
 177.979 +     * @see        java.net.URLConnection#getContent()
 177.980 +     */
 177.981 +    public final Object getContent() throws java.io.IOException {
 177.982 +        return loadText(toExternalForm());
 177.983 +    }
 177.984 +    
 177.985 +    @JavaScriptBody(args = "url", body = ""
 177.986 +        + "var request = new XMLHttpRequest();\n"
 177.987 +        + "request.open('GET', url, false);\n"
 177.988 +        + "request.send();\n"
 177.989 +        + "return request.responseText;\n"
 177.990 +    )
 177.991 +    private static native String loadText(String url) throws IOException;
 177.992 +
 177.993 +    /**
 177.994 +     * Gets the contents of this URL. This method is a shorthand for:
 177.995 +     * <blockquote><pre>
 177.996 +     *     openConnection().getContent(Class[])
 177.997 +     * </pre></blockquote>
 177.998 +     *
 177.999 +     * @param classes an array of Java types
177.1000 +     * @return     the content object of this URL that is the first match of
177.1001 +     *               the types specified in the classes array.
177.1002 +     *               null if none of the requested types are supported.
177.1003 +     * @exception  IOException  if an I/O exception occurs.
177.1004 +     * @see        java.net.URLConnection#getContent(Class[])
177.1005 +     * @since 1.3
177.1006 +     */
177.1007 +    public final Object getContent(Class[] classes)
177.1008 +    throws java.io.IOException {
177.1009 +        for (Class<?> c : classes) {
177.1010 +            if (c == String.class) {
177.1011 +                return getContent();
177.1012 +            }
177.1013 +        }
177.1014 +        return null;
177.1015 +    }
177.1016 +
177.1017 +    static URLStreamHandler getURLStreamHandler(String protocol) {
177.1018 +        URLStreamHandler universal = new URLStreamHandler() {};
177.1019 +        return universal;
177.1020 +    }
177.1021 +
177.1022 +}
177.1023 +class Parts {
177.1024 +    String path, query, ref;
177.1025 +
177.1026 +    Parts(String file) {
177.1027 +        int ind = file.indexOf('#');
177.1028 +        ref = ind < 0 ? null: file.substring(ind + 1);
177.1029 +        file = ind < 0 ? file: file.substring(0, ind);
177.1030 +        int q = file.lastIndexOf('?');
177.1031 +        if (q != -1) {
177.1032 +            query = file.substring(q+1);
177.1033 +            path = file.substring(0, q);
177.1034 +        } else {
177.1035 +            path = file;
177.1036 +        }
177.1037 +    }
177.1038 +
177.1039 +    String getPath() {
177.1040 +        return path;
177.1041 +    }
177.1042 +
177.1043 +    String getQuery() {
177.1044 +        return query;
177.1045 +    }
177.1046 +
177.1047 +    String getRef() {
177.1048 +        return ref;
177.1049 +    }
177.1050 +}
   178.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   178.2 +++ b/emul/mini/src/main/java/java/net/URLStreamHandler.java	Sun Feb 03 07:48:42 2013 +0100
   178.3 @@ -0,0 +1,568 @@
   178.4 +/*
   178.5 + * Copyright (c) 1995, 2006, 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.net;
  178.30 +
  178.31 +
  178.32 +/**
  178.33 + * The abstract class <code>URLStreamHandler</code> is the common
  178.34 + * superclass for all stream protocol handlers. A stream protocol
  178.35 + * handler knows how to make a connection for a particular protocol
  178.36 + * type, such as <code>http</code>, <code>ftp</code>, or
  178.37 + * <code>gopher</code>.
  178.38 + * <p>
  178.39 + * In most cases, an instance of a <code>URLStreamHandler</code>
  178.40 + * subclass is not created directly by an application. Rather, the
  178.41 + * first time a protocol name is encountered when constructing a
  178.42 + * <code>URL</code>, the appropriate stream protocol handler is
  178.43 + * automatically loaded.
  178.44 + *
  178.45 + * @author  James Gosling
  178.46 + * @see     java.net.URL#URL(java.lang.String, java.lang.String, int, java.lang.String)
  178.47 + * @since   JDK1.0
  178.48 + */
  178.49 +public abstract class URLStreamHandler {
  178.50 +    /**
  178.51 +     * Opens a connection to the object referenced by the
  178.52 +     * <code>URL</code> argument.
  178.53 +     * This method should be overridden by a subclass.
  178.54 +     *
  178.55 +     * <p>If for the handler's protocol (such as HTTP or JAR), there
  178.56 +     * exists a public, specialized URLConnection subclass belonging
  178.57 +     * to one of the following packages or one of their subpackages:
  178.58 +     * java.lang, java.io, java.util, java.net, the connection
  178.59 +     * returned will be of that subclass. For example, for HTTP an
  178.60 +     * HttpURLConnection will be returned, and for JAR a
  178.61 +     * JarURLConnection will be returned.
  178.62 +     *
  178.63 +     * @param      u   the URL that this connects to.
  178.64 +     * @return     a <code>URLConnection</code> object for the <code>URL</code>.
  178.65 +     * @exception  IOException  if an I/O error occurs while opening the
  178.66 +     *               connection.
  178.67 +     */
  178.68 +//    abstract protected URLConnection openConnection(URL u) throws IOException;
  178.69 +
  178.70 +    /**
  178.71 +     * Same as openConnection(URL), except that the connection will be
  178.72 +     * made through the specified proxy; Protocol handlers that do not
  178.73 +     * support proxying will ignore the proxy parameter and make a
  178.74 +     * normal connection.
  178.75 +     *
  178.76 +     * Calling this method preempts the system's default ProxySelector
  178.77 +     * settings.
  178.78 +     *
  178.79 +     * @param      u   the URL that this connects to.
  178.80 +     * @param      p   the proxy through which the connection will be made.
  178.81 +     *                 If direct connection is desired, Proxy.NO_PROXY
  178.82 +     *                 should be specified.
  178.83 +     * @return     a <code>URLConnection</code> object for the <code>URL</code>.
  178.84 +     * @exception  IOException  if an I/O error occurs while opening the
  178.85 +     *               connection.
  178.86 +     * @exception  IllegalArgumentException if either u or p is null,
  178.87 +     *               or p has the wrong type.
  178.88 +     * @exception  UnsupportedOperationException if the subclass that
  178.89 +     *               implements the protocol doesn't support this method.
  178.90 +     * @since      1.5
  178.91 +     */
  178.92 +//    protected URLConnection openConnection(URL u, Proxy p) throws IOException {
  178.93 +//        throw new UnsupportedOperationException("Method not implemented.");
  178.94 +//    }
  178.95 +
  178.96 +    /**
  178.97 +     * Parses the string representation of a <code>URL</code> into a
  178.98 +     * <code>URL</code> object.
  178.99 +     * <p>
 178.100 +     * If there is any inherited context, then it has already been
 178.101 +     * copied into the <code>URL</code> argument.
 178.102 +     * <p>
 178.103 +     * The <code>parseURL</code> method of <code>URLStreamHandler</code>
 178.104 +     * parses the string representation as if it were an
 178.105 +     * <code>http</code> specification. Most URL protocol families have a
 178.106 +     * similar parsing. A stream protocol handler for a protocol that has
 178.107 +     * a different syntax must override this routine.
 178.108 +     *
 178.109 +     * @param   u       the <code>URL</code> to receive the result of parsing
 178.110 +     *                  the spec.
 178.111 +     * @param   spec    the <code>String</code> representing the URL that
 178.112 +     *                  must be parsed.
 178.113 +     * @param   start   the character index at which to begin parsing. This is
 178.114 +     *                  just past the '<code>:</code>' (if there is one) that
 178.115 +     *                  specifies the determination of the protocol name.
 178.116 +     * @param   limit   the character position to stop parsing at. This is the
 178.117 +     *                  end of the string or the position of the
 178.118 +     *                  "<code>#</code>" character, if present. All information
 178.119 +     *                  after the sharp sign indicates an anchor.
 178.120 +     */
 178.121 +    protected void parseURL(URL u, String spec, int start, int limit) {
 178.122 +        // These fields may receive context content if this was relative URL
 178.123 +        String protocol = u.getProtocol();
 178.124 +        String authority = u.getAuthority();
 178.125 +        String userInfo = u.getUserInfo();
 178.126 +        String host = u.getHost();
 178.127 +        int port = u.getPort();
 178.128 +        String path = u.getPath();
 178.129 +        String query = u.getQuery();
 178.130 +
 178.131 +        // This field has already been parsed
 178.132 +        String ref = u.getRef();
 178.133 +
 178.134 +        boolean isRelPath = false;
 178.135 +        boolean queryOnly = false;
 178.136 +
 178.137 +// FIX: should not assume query if opaque
 178.138 +        // Strip off the query part
 178.139 +        if (start < limit) {
 178.140 +            int queryStart = spec.indexOf('?');
 178.141 +            queryOnly = queryStart == start;
 178.142 +            if ((queryStart != -1) && (queryStart < limit)) {
 178.143 +                query = spec.substring(queryStart+1, limit);
 178.144 +                if (limit > queryStart)
 178.145 +                    limit = queryStart;
 178.146 +                spec = spec.substring(0, queryStart);
 178.147 +            }
 178.148 +        }
 178.149 +
 178.150 +        int i = 0;
 178.151 +        // Parse the authority part if any
 178.152 +        boolean isUNCName = (start <= limit - 4) &&
 178.153 +                        (spec.charAt(start) == '/') &&
 178.154 +                        (spec.charAt(start + 1) == '/') &&
 178.155 +                        (spec.charAt(start + 2) == '/') &&
 178.156 +                        (spec.charAt(start + 3) == '/');
 178.157 +        if (!isUNCName && (start <= limit - 2) && (spec.charAt(start) == '/') &&
 178.158 +            (spec.charAt(start + 1) == '/')) {
 178.159 +            start += 2;
 178.160 +            i = spec.indexOf('/', start);
 178.161 +            if (i < 0) {
 178.162 +                i = spec.indexOf('?', start);
 178.163 +                if (i < 0)
 178.164 +                    i = limit;
 178.165 +            }
 178.166 +
 178.167 +            host = authority = spec.substring(start, i);
 178.168 +
 178.169 +            int ind = authority.indexOf('@');
 178.170 +            if (ind != -1) {
 178.171 +                userInfo = authority.substring(0, ind);
 178.172 +                host = authority.substring(ind+1);
 178.173 +            } else {
 178.174 +                userInfo = null;
 178.175 +            }
 178.176 +            if (host != null) {
 178.177 +                // If the host is surrounded by [ and ] then its an IPv6
 178.178 +                // literal address as specified in RFC2732
 178.179 +                if (host.length()>0 && (host.charAt(0) == '[')) {
 178.180 +                    if ((ind = host.indexOf(']')) > 2) {
 178.181 +
 178.182 +                        String nhost = host ;
 178.183 +                        host = nhost.substring(0,ind+1);
 178.184 +//                        if (!IPAddressUtil.
 178.185 +//                            isIPv6LiteralAddress(host.substring(1, ind))) {
 178.186 +//                            throw new IllegalArgumentException(
 178.187 +//                                "Invalid host: "+ host);
 178.188 +//                        }
 178.189 +
 178.190 +                        port = -1 ;
 178.191 +                        if (nhost.length() > ind+1) {
 178.192 +                            if (nhost.charAt(ind+1) == ':') {
 178.193 +                                ++ind ;
 178.194 +                                // port can be null according to RFC2396
 178.195 +                                if (nhost.length() > (ind + 1)) {
 178.196 +                                    port = Integer.parseInt(nhost.substring(ind+1));
 178.197 +                                }
 178.198 +                            } else {
 178.199 +                                throw new IllegalArgumentException(
 178.200 +                                    "Invalid authority field: " + authority);
 178.201 +                            }
 178.202 +                        }
 178.203 +                    } else {
 178.204 +                        throw new IllegalArgumentException(
 178.205 +                            "Invalid authority field: " + authority);
 178.206 +                    }
 178.207 +                } else {
 178.208 +                    ind = host.indexOf(':');
 178.209 +                    port = -1;
 178.210 +                    if (ind >= 0) {
 178.211 +                        // port can be null according to RFC2396
 178.212 +                        if (host.length() > (ind + 1)) {
 178.213 +                            port = Integer.parseInt(host.substring(ind + 1));
 178.214 +                        }
 178.215 +                        host = host.substring(0, ind);
 178.216 +                    }
 178.217 +                }
 178.218 +            } else {
 178.219 +                host = "";
 178.220 +            }
 178.221 +            if (port < -1)
 178.222 +                throw new IllegalArgumentException("Invalid port number :" +
 178.223 +                                                   port);
 178.224 +            start = i;
 178.225 +            // If the authority is defined then the path is defined by the
 178.226 +            // spec only; See RFC 2396 Section 5.2.4.
 178.227 +            if (authority != null && authority.length() > 0)
 178.228 +                path = "";
 178.229 +        }
 178.230 +
 178.231 +        if (host == null) {
 178.232 +            host = "";
 178.233 +        }
 178.234 +
 178.235 +        // Parse the file path if any
 178.236 +        if (start < limit) {
 178.237 +            if (spec.charAt(start) == '/') {
 178.238 +                path = spec.substring(start, limit);
 178.239 +            } else if (path != null && path.length() > 0) {
 178.240 +                isRelPath = true;
 178.241 +                int ind = path.lastIndexOf('/');
 178.242 +                String seperator = "";
 178.243 +                if (ind == -1 && authority != null)
 178.244 +                    seperator = "/";
 178.245 +                path = path.substring(0, ind + 1) + seperator +
 178.246 +                         spec.substring(start, limit);
 178.247 +
 178.248 +            } else {
 178.249 +                String seperator = (authority != null) ? "/" : "";
 178.250 +                path = seperator + spec.substring(start, limit);
 178.251 +            }
 178.252 +        } else if (queryOnly && path != null) {
 178.253 +            int ind = path.lastIndexOf('/');
 178.254 +            if (ind < 0)
 178.255 +                ind = 0;
 178.256 +            path = path.substring(0, ind) + "/";
 178.257 +        }
 178.258 +        if (path == null)
 178.259 +            path = "";
 178.260 +
 178.261 +        if (isRelPath) {
 178.262 +            // Remove embedded /./
 178.263 +            while ((i = path.indexOf("/./")) >= 0) {
 178.264 +                path = path.substring(0, i) + path.substring(i + 2);
 178.265 +            }
 178.266 +            // Remove embedded /../ if possible
 178.267 +            i = 0;
 178.268 +            while ((i = path.indexOf("/../", i)) >= 0) {
 178.269 +                /*
 178.270 +                 * A "/../" will cancel the previous segment and itself,
 178.271 +                 * unless that segment is a "/../" itself
 178.272 +                 * i.e. "/a/b/../c" becomes "/a/c"
 178.273 +                 * but "/../../a" should stay unchanged
 178.274 +                 */
 178.275 +                if (i > 0 && (limit = path.lastIndexOf('/', i - 1)) >= 0 &&
 178.276 +                    (path.indexOf("/../", limit) != 0)) {
 178.277 +                    path = path.substring(0, limit) + path.substring(i + 3);
 178.278 +                    i = 0;
 178.279 +                } else {
 178.280 +                    i = i + 3;
 178.281 +                }
 178.282 +            }
 178.283 +            // Remove trailing .. if possible
 178.284 +            while (path.endsWith("/..")) {
 178.285 +                i = path.indexOf("/..");
 178.286 +                if ((limit = path.lastIndexOf('/', i - 1)) >= 0) {
 178.287 +                    path = path.substring(0, limit+1);
 178.288 +                } else {
 178.289 +                    break;
 178.290 +                }
 178.291 +            }
 178.292 +            // Remove starting .
 178.293 +            if (path.startsWith("./") && path.length() > 2)
 178.294 +                path = path.substring(2);
 178.295 +
 178.296 +            // Remove trailing .
 178.297 +            if (path.endsWith("/."))
 178.298 +                path = path.substring(0, path.length() -1);
 178.299 +        }
 178.300 +
 178.301 +        setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
 178.302 +    }
 178.303 +
 178.304 +    /**
 178.305 +     * Returns the default port for a URL parsed by this handler. This method
 178.306 +     * is meant to be overidden by handlers with default port numbers.
 178.307 +     * @return the default port for a <code>URL</code> parsed by this handler.
 178.308 +     * @since 1.3
 178.309 +     */
 178.310 +    protected int getDefaultPort() {
 178.311 +        return -1;
 178.312 +    }
 178.313 +
 178.314 +    /**
 178.315 +     * Provides the default equals calculation. May be overidden by handlers
 178.316 +     * for other protocols that have different requirements for equals().
 178.317 +     * This method requires that none of its arguments is null. This is
 178.318 +     * guaranteed by the fact that it is only called by java.net.URL class.
 178.319 +     * @param u1 a URL object
 178.320 +     * @param u2 a URL object
 178.321 +     * @return <tt>true</tt> if the two urls are
 178.322 +     * considered equal, ie. they refer to the same
 178.323 +     * fragment in the same file.
 178.324 +     * @since 1.3
 178.325 +     */
 178.326 +    protected boolean equals(URL u1, URL u2) {
 178.327 +        String ref1 = u1.getRef();
 178.328 +        String ref2 = u2.getRef();
 178.329 +        return (ref1 == ref2 || (ref1 != null && ref1.equals(ref2))) &&
 178.330 +               sameFile(u1, u2);
 178.331 +    }
 178.332 +
 178.333 +    /**
 178.334 +     * Provides the default hash calculation. May be overidden by handlers for
 178.335 +     * other protocols that have different requirements for hashCode
 178.336 +     * calculation.
 178.337 +     * @param u a URL object
 178.338 +     * @return an <tt>int</tt> suitable for hash table indexing
 178.339 +     * @since 1.3
 178.340 +     */
 178.341 +    protected int hashCode(URL u) {
 178.342 +        int h = 0;
 178.343 +
 178.344 +        // Generate the protocol part.
 178.345 +        String protocol = u.getProtocol();
 178.346 +        if (protocol != null)
 178.347 +            h += protocol.hashCode();
 178.348 +
 178.349 +        // Generate the host part.
 178.350 +        Object addr = getHostAddress(u);
 178.351 +        if (addr != null) {
 178.352 +            h += addr.hashCode();
 178.353 +        } else {
 178.354 +            String host = u.getHost();
 178.355 +            if (host != null)
 178.356 +                h += host.toLowerCase().hashCode();
 178.357 +        }
 178.358 +
 178.359 +        // Generate the file part.
 178.360 +        String file = u.getFile();
 178.361 +        if (file != null)
 178.362 +            h += file.hashCode();
 178.363 +
 178.364 +        // Generate the port part.
 178.365 +        if (u.getPort() == -1)
 178.366 +            h += getDefaultPort();
 178.367 +        else
 178.368 +            h += u.getPort();
 178.369 +
 178.370 +        // Generate the ref part.
 178.371 +        String ref = u.getRef();
 178.372 +        if (ref != null)
 178.373 +            h += ref.hashCode();
 178.374 +
 178.375 +        return h;
 178.376 +    }
 178.377 +
 178.378 +    /**
 178.379 +     * Compare two urls to see whether they refer to the same file,
 178.380 +     * i.e., having the same protocol, host, port, and path.
 178.381 +     * This method requires that none of its arguments is null. This is
 178.382 +     * guaranteed by the fact that it is only called indirectly
 178.383 +     * by java.net.URL class.
 178.384 +     * @param u1 a URL object
 178.385 +     * @param u2 a URL object
 178.386 +     * @return true if u1 and u2 refer to the same file
 178.387 +     * @since 1.3
 178.388 +     */
 178.389 +    protected boolean sameFile(URL u1, URL u2) {
 178.390 +        // Compare the protocols.
 178.391 +        if (!((u1.getProtocol() == u2.getProtocol()) ||
 178.392 +              (u1.getProtocol() != null &&
 178.393 +               u1.getProtocol().equalsIgnoreCase(u2.getProtocol()))))
 178.394 +            return false;
 178.395 +
 178.396 +        // Compare the files.
 178.397 +        if (!(u1.getFile() == u2.getFile() ||
 178.398 +              (u1.getFile() != null && u1.getFile().equals(u2.getFile()))))
 178.399 +            return false;
 178.400 +
 178.401 +        // Compare the ports.
 178.402 +        int port1, port2;
 178.403 +        port1 = (u1.getPort() != -1) ? u1.getPort() : u1.handler.getDefaultPort();
 178.404 +        port2 = (u2.getPort() != -1) ? u2.getPort() : u2.handler.getDefaultPort();
 178.405 +        if (port1 != port2)
 178.406 +            return false;
 178.407 +
 178.408 +        // Compare the hosts.
 178.409 +        if (!hostsEqual(u1, u2))
 178.410 +            return false;
 178.411 +
 178.412 +        return true;
 178.413 +    }
 178.414 +
 178.415 +    /**
 178.416 +     * Get the IP address of our host. An empty host field or a DNS failure
 178.417 +     * will result in a null return.
 178.418 +     *
 178.419 +     * @param u a URL object
 178.420 +     * @return an <code>InetAddress</code> representing the host
 178.421 +     * IP address.
 178.422 +     * @since 1.3
 178.423 +     */
 178.424 +    private synchronized Object getHostAddress(URL u) {
 178.425 +        return u.hostAddress;
 178.426 +    }
 178.427 +
 178.428 +    /**
 178.429 +     * Compares the host components of two URLs.
 178.430 +     * @param u1 the URL of the first host to compare
 178.431 +     * @param u2 the URL of the second host to compare
 178.432 +     * @return  <tt>true</tt> if and only if they
 178.433 +     * are equal, <tt>false</tt> otherwise.
 178.434 +     * @since 1.3
 178.435 +     */
 178.436 +    protected boolean hostsEqual(URL u1, URL u2) {
 178.437 +        Object a1 = getHostAddress(u1);
 178.438 +        Object a2 = getHostAddress(u2);
 178.439 +        // if we have internet address for both, compare them
 178.440 +        if (a1 != null && a2 != null) {
 178.441 +            return a1.equals(a2);
 178.442 +        // else, if both have host names, compare them
 178.443 +        } else if (u1.getHost() != null && u2.getHost() != null)
 178.444 +            return u1.getHost().equalsIgnoreCase(u2.getHost());
 178.445 +         else
 178.446 +            return u1.getHost() == null && u2.getHost() == null;
 178.447 +    }
 178.448 +
 178.449 +    /**
 178.450 +     * Converts a <code>URL</code> of a specific protocol to a
 178.451 +     * <code>String</code>.
 178.452 +     *
 178.453 +     * @param   u   the URL.
 178.454 +     * @return  a string representation of the <code>URL</code> argument.
 178.455 +     */
 178.456 +    protected String toExternalForm(URL u) {
 178.457 +
 178.458 +        // pre-compute length of StringBuffer
 178.459 +        int len = u.getProtocol().length() + 1;
 178.460 +        if (u.getAuthority() != null && u.getAuthority().length() > 0)
 178.461 +            len += 2 + u.getAuthority().length();
 178.462 +        if (u.getPath() != null) {
 178.463 +            len += u.getPath().length();
 178.464 +        }
 178.465 +        if (u.getQuery() != null) {
 178.466 +            len += 1 + u.getQuery().length();
 178.467 +        }
 178.468 +        if (u.getRef() != null)
 178.469 +            len += 1 + u.getRef().length();
 178.470 +
 178.471 +        StringBuffer result = new StringBuffer(len);
 178.472 +        result.append(u.getProtocol());
 178.473 +        result.append(":");
 178.474 +        if (u.getAuthority() != null && u.getAuthority().length() > 0) {
 178.475 +            result.append("//");
 178.476 +            result.append(u.getAuthority());
 178.477 +        }
 178.478 +        if (u.getPath() != null) {
 178.479 +            result.append(u.getPath());
 178.480 +        }
 178.481 +        if (u.getQuery() != null) {
 178.482 +            result.append('?');
 178.483 +            result.append(u.getQuery());
 178.484 +        }
 178.485 +        if (u.getRef() != null) {
 178.486 +            result.append("#");
 178.487 +            result.append(u.getRef());
 178.488 +        }
 178.489 +        return result.toString();
 178.490 +    }
 178.491 +
 178.492 +    /**
 178.493 +     * Sets the fields of the <code>URL</code> argument to the indicated values.
 178.494 +     * Only classes derived from URLStreamHandler are supposed to be able
 178.495 +     * to call the set method on a URL.
 178.496 +     *
 178.497 +     * @param   u         the URL to modify.
 178.498 +     * @param   protocol  the protocol name.
 178.499 +     * @param   host      the remote host value for the URL.
 178.500 +     * @param   port      the port on the remote machine.
 178.501 +     * @param   authority the authority part for the URL.
 178.502 +     * @param   userInfo the userInfo part of the URL.
 178.503 +     * @param   path      the path component of the URL.
 178.504 +     * @param   query     the query part for the URL.
 178.505 +     * @param   ref       the reference.
 178.506 +     * @exception       SecurityException       if the protocol handler of the URL is
 178.507 +     *                                  different from this one
 178.508 +     * @see     java.net.URL#set(java.lang.String, java.lang.String, int, java.lang.String, java.lang.String)
 178.509 +     * @since 1.3
 178.510 +     */
 178.511 +       protected void setURL(URL u, String protocol, String host, int port,
 178.512 +                             String authority, String userInfo, String path,
 178.513 +                             String query, String ref) {
 178.514 +        if (this != u.handler) {
 178.515 +            throw new SecurityException("handler for url different from " +
 178.516 +                                        "this handler");
 178.517 +        }
 178.518 +        // ensure that no one can reset the protocol on a given URL.
 178.519 +        u.set(u.getProtocol(), host, port, authority, userInfo, path, query, ref);
 178.520 +    }
 178.521 +
 178.522 +    /**
 178.523 +     * Sets the fields of the <code>URL</code> argument to the indicated values.
 178.524 +     * Only classes derived from URLStreamHandler are supposed to be able
 178.525 +     * to call the set method on a URL.
 178.526 +     *
 178.527 +     * @param   u         the URL to modify.
 178.528 +     * @param   protocol  the protocol name. This value is ignored since 1.2.
 178.529 +     * @param   host      the remote host value for the URL.
 178.530 +     * @param   port      the port on the remote machine.
 178.531 +     * @param   file      the file.
 178.532 +     * @param   ref       the reference.
 178.533 +     * @exception       SecurityException       if the protocol handler of the URL is
 178.534 +     *                                  different from this one
 178.535 +     * @deprecated Use setURL(URL, String, String, int, String, String, String,
 178.536 +     *             String);
 178.537 +     */
 178.538 +    @Deprecated
 178.539 +    protected void setURL(URL u, String protocol, String host, int port,
 178.540 +                          String file, String ref) {
 178.541 +        /*
 178.542 +         * Only old URL handlers call this, so assume that the host
 178.543 +         * field might contain "user:passwd@host". Fix as necessary.
 178.544 +         */
 178.545 +        String authority = null;
 178.546 +        String userInfo = null;
 178.547 +        if (host != null && host.length() != 0) {
 178.548 +            authority = (port == -1) ? host : host + ":" + port;
 178.549 +            int at = host.lastIndexOf('@');
 178.550 +            if (at != -1) {
 178.551 +                userInfo = host.substring(0, at);
 178.552 +                host = host.substring(at+1);
 178.553 +            }
 178.554 +        }
 178.555 +
 178.556 +        /*
 178.557 +         * Assume file might contain query part. Fix as necessary.
 178.558 +         */
 178.559 +        String path = null;
 178.560 +        String query = null;
 178.561 +        if (file != null) {
 178.562 +            int q = file.lastIndexOf('?');
 178.563 +            if (q != -1) {
 178.564 +                query = file.substring(q+1);
 178.565 +                path = file.substring(0, q);
 178.566 +            } else
 178.567 +                path = file;
 178.568 +        }
 178.569 +        setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
 178.570 +    }
 178.571 +}
   179.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   179.2 +++ b/emul/mini/src/main/java/java/util/Comparator.java	Sun Feb 03 07:48:42 2013 +0100
   179.3 @@ -0,0 +1,168 @@
   179.4 +/*
   179.5 + * Copyright (c) 1997, 2007, 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 +package java.util;
  179.30 +
  179.31 +/**
  179.32 + * A comparison function, which imposes a <i>total ordering</i> on some
  179.33 + * collection of objects.  Comparators can be passed to a sort method (such
  179.34 + * as {@link Collections#sort(List,Comparator) Collections.sort} or {@link
  179.35 + * Arrays#sort(Object[],Comparator) Arrays.sort}) to allow precise control
  179.36 + * over the sort order.  Comparators can also be used to control the order of
  179.37 + * certain data structures (such as {@link SortedSet sorted sets} or {@link
  179.38 + * SortedMap sorted maps}), or to provide an ordering for collections of
  179.39 + * objects that don't have a {@link Comparable natural ordering}.<p>
  179.40 + *
  179.41 + * The ordering imposed by a comparator <tt>c</tt> on a set of elements
  179.42 + * <tt>S</tt> is said to be <i>consistent with equals</i> if and only if
  179.43 + * <tt>c.compare(e1, e2)==0</tt> has the same boolean value as
  179.44 + * <tt>e1.equals(e2)</tt> for every <tt>e1</tt> and <tt>e2</tt> in
  179.45 + * <tt>S</tt>.<p>
  179.46 + *
  179.47 + * Caution should be exercised when using a comparator capable of imposing an
  179.48 + * ordering inconsistent with equals to order a sorted set (or sorted map).
  179.49 + * Suppose a sorted set (or sorted map) with an explicit comparator <tt>c</tt>
  179.50 + * is used with elements (or keys) drawn from a set <tt>S</tt>.  If the
  179.51 + * ordering imposed by <tt>c</tt> on <tt>S</tt> is inconsistent with equals,
  179.52 + * the sorted set (or sorted map) will behave "strangely."  In particular the
  179.53 + * sorted set (or sorted map) will violate the general contract for set (or
  179.54 + * map), which is defined in terms of <tt>equals</tt>.<p>
  179.55 + *
  179.56 + * For example, suppose one adds two elements {@code a} and {@code b} such that
  179.57 + * {@code (a.equals(b) && c.compare(a, b) != 0)}
  179.58 + * to an empty {@code TreeSet} with comparator {@code c}.
  179.59 + * The second {@code add} operation will return
  179.60 + * true (and the size of the tree set will increase) because {@code a} and
  179.61 + * {@code b} are not equivalent from the tree set's perspective, even though
  179.62 + * this is contrary to the specification of the
  179.63 + * {@link Set#add Set.add} method.<p>
  179.64 + *
  179.65 + * Note: It is generally a good idea for comparators to also implement
  179.66 + * <tt>java.io.Serializable</tt>, as they may be used as ordering methods in
  179.67 + * serializable data structures (like {@link TreeSet}, {@link TreeMap}).  In
  179.68 + * order for the data structure to serialize successfully, the comparator (if
  179.69 + * provided) must implement <tt>Serializable</tt>.<p>
  179.70 + *
  179.71 + * For the mathematically inclined, the <i>relation</i> that defines the
  179.72 + * <i>imposed ordering</i> that a given comparator <tt>c</tt> imposes on a
  179.73 + * given set of objects <tt>S</tt> is:<pre>
  179.74 + *       {(x, y) such that c.compare(x, y) &lt;= 0}.
  179.75 + * </pre> The <i>quotient</i> for this total order is:<pre>
  179.76 + *       {(x, y) such that c.compare(x, y) == 0}.
  179.77 + * </pre>
  179.78 + *
  179.79 + * It follows immediately from the contract for <tt>compare</tt> that the
  179.80 + * quotient is an <i>equivalence relation</i> on <tt>S</tt>, and that the
  179.81 + * imposed ordering is a <i>total order</i> on <tt>S</tt>.  When we say that
  179.82 + * the ordering imposed by <tt>c</tt> on <tt>S</tt> is <i>consistent with
  179.83 + * equals</i>, we mean that the quotient for the ordering is the equivalence
  179.84 + * relation defined by the objects' {@link Object#equals(Object)
  179.85 + * equals(Object)} method(s):<pre>
  179.86 + *     {(x, y) such that x.equals(y)}. </pre>
  179.87 + *
  179.88 + * <p>Unlike {@code Comparable}, a comparator may optionally permit
  179.89 + * comparison of null arguments, while maintaining the requirements for
  179.90 + * an equivalence relation.
  179.91 + *
  179.92 + * <p>This interface is a member of the
  179.93 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  179.94 + * Java Collections Framework</a>.
  179.95 + *
  179.96 + * @param <T> the type of objects that may be compared by this comparator
  179.97 + *
  179.98 + * @author  Josh Bloch
  179.99 + * @author  Neal Gafter
 179.100 + * @see Comparable
 179.101 + * @see java.io.Serializable
 179.102 + * @since 1.2
 179.103 + */
 179.104 +
 179.105 +public interface Comparator<T> {
 179.106 +    /**
 179.107 +     * Compares its two arguments for order.  Returns a negative integer,
 179.108 +     * zero, or a positive integer as the first argument is less than, equal
 179.109 +     * to, or greater than the second.<p>
 179.110 +     *
 179.111 +     * In the foregoing description, the notation
 179.112 +     * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
 179.113 +     * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
 179.114 +     * <tt>0</tt>, or <tt>1</tt> according to whether the value of
 179.115 +     * <i>expression</i> is negative, zero or positive.<p>
 179.116 +     *
 179.117 +     * The implementor must ensure that <tt>sgn(compare(x, y)) ==
 179.118 +     * -sgn(compare(y, x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
 179.119 +     * implies that <tt>compare(x, y)</tt> must throw an exception if and only
 179.120 +     * if <tt>compare(y, x)</tt> throws an exception.)<p>
 179.121 +     *
 179.122 +     * The implementor must also ensure that the relation is transitive:
 179.123 +     * <tt>((compare(x, y)&gt;0) &amp;&amp; (compare(y, z)&gt;0))</tt> implies
 179.124 +     * <tt>compare(x, z)&gt;0</tt>.<p>
 179.125 +     *
 179.126 +     * Finally, the implementor must ensure that <tt>compare(x, y)==0</tt>
 179.127 +     * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all
 179.128 +     * <tt>z</tt>.<p>
 179.129 +     *
 179.130 +     * It is generally the case, but <i>not</i> strictly required that
 179.131 +     * <tt>(compare(x, y)==0) == (x.equals(y))</tt>.  Generally speaking,
 179.132 +     * any comparator that violates this condition should clearly indicate
 179.133 +     * this fact.  The recommended language is "Note: this comparator
 179.134 +     * imposes orderings that are inconsistent with equals."
 179.135 +     *
 179.136 +     * @param o1 the first object to be compared.
 179.137 +     * @param o2 the second object to be compared.
 179.138 +     * @return a negative integer, zero, or a positive integer as the
 179.139 +     *         first argument is less than, equal to, or greater than the
 179.140 +     *         second.
 179.141 +     * @throws NullPointerException if an argument is null and this
 179.142 +     *         comparator does not permit null arguments
 179.143 +     * @throws ClassCastException if the arguments' types prevent them from
 179.144 +     *         being compared by this comparator.
 179.145 +     */
 179.146 +    int compare(T o1, T o2);
 179.147 +
 179.148 +    /**
 179.149 +     * Indicates whether some other object is &quot;equal to&quot; this
 179.150 +     * comparator.  This method must obey the general contract of
 179.151 +     * {@link Object#equals(Object)}.  Additionally, this method can return
 179.152 +     * <tt>true</tt> <i>only</i> if the specified object is also a comparator
 179.153 +     * and it imposes the same ordering as this comparator.  Thus,
 179.154 +     * <code>comp1.equals(comp2)</code> implies that <tt>sgn(comp1.compare(o1,
 179.155 +     * o2))==sgn(comp2.compare(o1, o2))</tt> for every object reference
 179.156 +     * <tt>o1</tt> and <tt>o2</tt>.<p>
 179.157 +     *
 179.158 +     * Note that it is <i>always</i> safe <i>not</i> to override
 179.159 +     * <tt>Object.equals(Object)</tt>.  However, overriding this method may,
 179.160 +     * in some cases, improve performance by allowing programs to determine
 179.161 +     * that two distinct comparators impose the same order.
 179.162 +     *
 179.163 +     * @param   obj   the reference object with which to compare.
 179.164 +     * @return  <code>true</code> only if the specified object is also
 179.165 +     *          a comparator and it imposes the same ordering as this
 179.166 +     *          comparator.
 179.167 +     * @see Object#equals(Object)
 179.168 +     * @see Object#hashCode()
 179.169 +     */
 179.170 +    boolean equals(Object obj);
 179.171 +}
   180.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   180.2 +++ b/emul/mini/src/main/java/java/util/Enumeration.java	Sun Feb 03 07:48:42 2013 +0100
   180.3 @@ -0,0 +1,79 @@
   180.4 +/*
   180.5 + * Copyright (c) 1994, 2005, 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.util;
  180.30 +
  180.31 +/**
  180.32 + * An object that implements the Enumeration interface generates a
  180.33 + * series of elements, one at a time. Successive calls to the
  180.34 + * <code>nextElement</code> method return successive elements of the
  180.35 + * series.
  180.36 + * <p>
  180.37 + * For example, to print all elements of a <tt>Vector&lt;E&gt;</tt> <i>v</i>:
  180.38 + * <pre>
  180.39 + *   for (Enumeration&lt;E&gt; e = v.elements(); e.hasMoreElements();)
  180.40 + *       System.out.println(e.nextElement());</pre>
  180.41 + * <p>
  180.42 + * Methods are provided to enumerate through the elements of a
  180.43 + * vector, the keys of a hashtable, and the values in a hashtable.
  180.44 + * Enumerations are also used to specify the input streams to a
  180.45 + * <code>SequenceInputStream</code>.
  180.46 + * <p>
  180.47 + * NOTE: The functionality of this interface is duplicated by the Iterator
  180.48 + * interface.  In addition, Iterator adds an optional remove operation, and
  180.49 + * has shorter method names.  New implementations should consider using
  180.50 + * Iterator in preference to Enumeration.
  180.51 + *
  180.52 + * @see     java.util.Iterator
  180.53 + * @see     java.io.SequenceInputStream
  180.54 + * @see     java.util.Enumeration#nextElement()
  180.55 + * @see     java.util.Hashtable
  180.56 + * @see     java.util.Hashtable#elements()
  180.57 + * @see     java.util.Hashtable#keys()
  180.58 + * @see     java.util.Vector
  180.59 + * @see     java.util.Vector#elements()
  180.60 + *
  180.61 + * @author  Lee Boynton
  180.62 + * @since   JDK1.0
  180.63 + */
  180.64 +public interface Enumeration<E> {
  180.65 +    /**
  180.66 +     * Tests if this enumeration contains more elements.
  180.67 +     *
  180.68 +     * @return  <code>true</code> if and only if this enumeration object
  180.69 +     *           contains at least one more element to provide;
  180.70 +     *          <code>false</code> otherwise.
  180.71 +     */
  180.72 +    boolean hasMoreElements();
  180.73 +
  180.74 +    /**
  180.75 +     * Returns the next element of this enumeration if this enumeration
  180.76 +     * object has at least one more element to provide.
  180.77 +     *
  180.78 +     * @return     the next element of this enumeration.
  180.79 +     * @exception  NoSuchElementException  if no more elements exist.
  180.80 +     */
  180.81 +    E nextElement();
  180.82 +}
   181.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   181.2 +++ b/emul/mini/src/main/java/java/util/NoSuchElementException.java	Sun Feb 03 07:48:42 2013 +0100
   181.3 @@ -0,0 +1,60 @@
   181.4 +/*
   181.5 + * Copyright (c) 1994, 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.util;
  181.30 +
  181.31 +/**
  181.32 + * Thrown by the <code>nextElement</code> method of an
  181.33 + * <code>Enumeration</code> to indicate that there are no more
  181.34 + * elements in the enumeration.
  181.35 + *
  181.36 + * @author  unascribed
  181.37 + * @see     java.util.Enumeration
  181.38 + * @see     java.util.Enumeration#nextElement()
  181.39 + * @since   JDK1.0
  181.40 + */
  181.41 +public
  181.42 +class NoSuchElementException extends RuntimeException {
  181.43 +    private static final long serialVersionUID = 6769829250639411880L;
  181.44 +
  181.45 +    /**
  181.46 +     * Constructs a <code>NoSuchElementException</code> with <tt>null</tt>
  181.47 +     * as its error message string.
  181.48 +     */
  181.49 +    public NoSuchElementException() {
  181.50 +        super();
  181.51 +    }
  181.52 +
  181.53 +    /**
  181.54 +     * Constructs a <code>NoSuchElementException</code>, saving a reference
  181.55 +     * to the error message string <tt>s</tt> for later retrieval by the
  181.56 +     * <tt>getMessage</tt> method.
  181.57 +     *
  181.58 +     * @param   s   the detail message.
  181.59 +     */
  181.60 +    public NoSuchElementException(String s) {
  181.61 +        super(s);
  181.62 +    }
  181.63 +}
   182.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   182.2 +++ b/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java	Sun Feb 03 07:48:42 2013 +0100
   182.3 @@ -0,0 +1,54 @@
   182.4 +/**
   182.5 + * Back 2 Browser Bytecode Translator
   182.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   182.7 + *
   182.8 + * This program is free software: you can redistribute it and/or modify
   182.9 + * it under the terms of the GNU General Public License as published by
  182.10 + * the Free Software Foundation, version 2 of the License.
  182.11 + *
  182.12 + * This program is distributed in the hope that it will be useful,
  182.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  182.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  182.15 + * GNU General Public License for more details.
  182.16 + *
  182.17 + * You should have received a copy of the GNU General Public License
  182.18 + * along with this program. Look for COPYING file in the top folder.
  182.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  182.20 + */
  182.21 +package org.apidesign.bck2brwsr.emul.lang;
  182.22 +
  182.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  182.24 +
  182.25 +/**
  182.26 + *
  182.27 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  182.28 + */
  182.29 +public class System {
  182.30 +    private System() {
  182.31 +    }
  182.32 +
  182.33 +    @JavaScriptBody(args = { "value", "srcBegin", "dst", "dstBegin", "count" }, body = 
  182.34 +        "if (srcBegin < dstBegin) {\n" +
  182.35 +        "    while (count-- > 0) {\n" +
  182.36 +        "        dst[dstBegin + count] = value[srcBegin + count];\n" +
  182.37 +        "    }\n" +
  182.38 +        "} else {\n" +
  182.39 +        "    while (count-- > 0) {\n" +
  182.40 +        "        dst[dstBegin++] = value[srcBegin++];\n" +
  182.41 +        "    }\n" +
  182.42 +        "}"
  182.43 +    )
  182.44 +    public static native void arraycopy(Object value, int srcBegin, Object dst, int dstBegin, int count);
  182.45 +
  182.46 +    @JavaScriptBody(args = { "arr", "expectedSize" }, body = 
  182.47 +        "while (expectedSize-- > arr.length) { arr.push(0); }; return arr;"
  182.48 +    )
  182.49 +    public static native byte[] expandArray(byte[] arr, int expectedSize);
  182.50 +
  182.51 +    @JavaScriptBody(args = {}, body = "new Date().getMilliseconds();")
  182.52 +    public static native long currentTimeMillis();
  182.53 +    
  182.54 +    public static long nanoTime() {
  182.55 +        return 1000L * currentTimeMillis();
  182.56 +    }
  182.57 +}
   183.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   183.2 +++ b/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/reflect/AnnotationImpl.java	Sun Feb 03 07:48:42 2013 +0100
   183.3 @@ -0,0 +1,81 @@
   183.4 +/**
   183.5 + * Back 2 Browser Bytecode Translator
   183.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   183.7 + *
   183.8 + * This program is free software: you can redistribute it and/or modify
   183.9 + * it under the terms of the GNU General Public License as published by
  183.10 + * the Free Software Foundation, version 2 of the License.
  183.11 + *
  183.12 + * This program is distributed in the hope that it will be useful,
  183.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  183.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  183.15 + * GNU General Public License for more details.
  183.16 + *
  183.17 + * You should have received a copy of the GNU General Public License
  183.18 + * along with this program. Look for COPYING file in the top folder.
  183.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  183.20 + */
  183.21 +package org.apidesign.bck2brwsr.emul.reflect;
  183.22 +
  183.23 +import java.lang.annotation.Annotation;
  183.24 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  183.25 +
  183.26 +/**
  183.27 + *
  183.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  183.29 + */
  183.30 +public final class AnnotationImpl implements Annotation {
  183.31 +    public Class<? extends Annotation> annotationType() {
  183.32 +        return getClass();
  183.33 +    }
  183.34 +
  183.35 +    @JavaScriptBody(args = { "a", "n", "values" }, body = ""
  183.36 +        + "function f(v, p) {\n"
  183.37 +        + "  var val = v;\n"
  183.38 +        + "  var prop = p;\n"
  183.39 +        + "  return function() {\n"
  183.40 +        + "    return val[prop];\n"
  183.41 +        + "  };\n"
  183.42 +        + "}\n"
  183.43 +        + "var props = Object.getOwnPropertyNames(values);\n"
  183.44 +        + "for (var i = 0; i < props.length; i++) {\n"
  183.45 +        + "  var p = props[i];\n"
  183.46 +        + "  a[p] = new f(values, p);\n"
  183.47 +        + "}\n"
  183.48 +        + "a['$instOf_' + n] = true;\n"
  183.49 +        + "return a;"
  183.50 +    )
  183.51 +    private static <T extends Annotation> T create(AnnotationImpl a, String n, Object values) {
  183.52 +        return null;
  183.53 +    }
  183.54 +    public static <T extends Annotation> T create(Class<T> annoClass, Object values) {
  183.55 +        return create(new AnnotationImpl(), annoClass.getName().replace('.', '_'), values);
  183.56 +    }
  183.57 +
  183.58 +    public static Annotation[] create(Object anno) {
  183.59 +        String[] names = findNames(anno);
  183.60 +        Annotation[] ret = new Annotation[names.length];
  183.61 +        for (int i = 0; i < names.length; i++) {
  183.62 +            String n = names[i].substring(1, names[i].length() - 1).replace('/', '_');
  183.63 +            ret[i] = create(new AnnotationImpl(), n, findData(anno, names[i]));
  183.64 +        }
  183.65 +        return ret;
  183.66 +    }
  183.67 +    @JavaScriptBody(args = "anno", body =
  183.68 +          "var arr = new Array();"
  183.69 +        + "var props = Object.getOwnPropertyNames(anno);\n"
  183.70 +        + "for (var i = 0; i < props.length; i++) {\n"
  183.71 +        + "  var p = props[i];\n"
  183.72 +        + "  arr.push(p);"
  183.73 +        + "}"
  183.74 +        + "return arr;"
  183.75 +    )
  183.76 +    private static String[] findNames(Object anno) {
  183.77 +        throw new UnsupportedOperationException();
  183.78 +    }
  183.79 +
  183.80 +    @JavaScriptBody(args={ "anno", "p"}, body="return anno[p];")
  183.81 +    private static Object findData(Object anno, String p) {
  183.82 +        throw new UnsupportedOperationException();
  183.83 +    }
  183.84 +}
   184.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   184.2 +++ b/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/reflect/MethodImpl.java	Sun Feb 03 07:48:42 2013 +0100
   184.3 @@ -0,0 +1,164 @@
   184.4 +/*
   184.5 + * Copyright (c) 1996, 2006, 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 +package org.apidesign.bck2brwsr.emul.reflect;
  184.29 +
  184.30 +import java.lang.reflect.Method;
  184.31 +import java.util.Enumeration;
  184.32 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  184.33 +
  184.34 +/** Utilities to work on methods.
  184.35 + *
  184.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  184.37 + */
  184.38 +public abstract class MethodImpl {
  184.39 +    public static MethodImpl INSTANCE;
  184.40 +    static {
  184.41 +        try {
  184.42 +            Class.forName(Method.class.getName());
  184.43 +        } catch (ClassNotFoundException ex) {
  184.44 +            throw new IllegalStateException(ex);
  184.45 +        }
  184.46 +    }
  184.47 +    
  184.48 +    protected abstract Method create(Class<?> declaringClass, String name, Object data, String sig);
  184.49 +    
  184.50 +    
  184.51 +    //
  184.52 +    // bck2brwsr implementation
  184.53 +    //
  184.54 +
  184.55 +    @JavaScriptBody(args = {"clazz", "prefix"},
  184.56 +        body = ""
  184.57 +        + "var c = clazz.cnstr.prototype;"
  184.58 +        + "var arr = new Array();\n"
  184.59 +        + "for (m in c) {\n"
  184.60 +        + "  if (m.indexOf(prefix) === 0) {\n"
  184.61 +        + "     arr.push(m);\n"
  184.62 +        + "     arr.push(c[m]);\n"
  184.63 +        + "  }"
  184.64 +        + "}\n"
  184.65 +        + "return arr;")
  184.66 +    private static native Object[] findMethodData(
  184.67 +        Class<?> clazz, String prefix);
  184.68 +
  184.69 +    public static Method findMethod(
  184.70 +        Class<?> clazz, String name, Class<?>... parameterTypes) {
  184.71 +        Object[] data = findMethodData(clazz, name + "__");
  184.72 +        BIG: for (int i = 0; i < data.length; i += 2) {
  184.73 +            String sig = ((String) data[0]).substring(name.length() + 2);
  184.74 +            Method tmp = INSTANCE.create(clazz, name, data[1], sig);
  184.75 +            Class<?>[] tmpParms = tmp.getParameterTypes();
  184.76 +            if (parameterTypes.length != tmpParms.length) {
  184.77 +                continue;
  184.78 +            }
  184.79 +            for (int j = 0; j < tmpParms.length; j++) {
  184.80 +                if (!parameterTypes[j].equals(tmpParms[j])) {
  184.81 +                    continue BIG;
  184.82 +                }
  184.83 +            }
  184.84 +            return tmp;
  184.85 +        }
  184.86 +        return null;
  184.87 +    }
  184.88 +
  184.89 +    public static Method[] findMethods(Class<?> clazz, int mask) {
  184.90 +        Object[] namesAndData = findMethodData(clazz, "");
  184.91 +        int cnt = 0;
  184.92 +        for (int i = 0; i < namesAndData.length; i += 2) {
  184.93 +            String sig = (String) namesAndData[i];
  184.94 +            Object data = namesAndData[i + 1];
  184.95 +            int middle = sig.indexOf("__");
  184.96 +            if (middle == -1) {
  184.97 +                continue;
  184.98 +            }
  184.99 +            String name = sig.substring(0, middle);
 184.100 +            sig = sig.substring(middle + 2);
 184.101 +            final Method m = INSTANCE.create(clazz, name, data, sig);
 184.102 +            if ((m.getModifiers() & mask) == 0) {
 184.103 +                continue;
 184.104 +            }
 184.105 +            namesAndData[cnt++] = m;
 184.106 +        }
 184.107 +        Method[] arr = new Method[cnt];
 184.108 +        for (int i = 0; i < cnt; i++) {
 184.109 +            arr[i] = (Method) namesAndData[i];
 184.110 +        }
 184.111 +        return arr;
 184.112 +    }
 184.113 +
 184.114 +    public static int signatureElements(String sig) {
 184.115 +        Enumeration<Class> en = signatureParser(sig);
 184.116 +        int cnt = 0;
 184.117 +        while (en.hasMoreElements()) {
 184.118 +            en.nextElement();
 184.119 +            cnt++;
 184.120 +        }
 184.121 +        return cnt;
 184.122 +    }
 184.123 +    
 184.124 +    public static Enumeration<Class> signatureParser(final String sig) {
 184.125 +        class E implements Enumeration<Class> {
 184.126 +            int pos;
 184.127 +            
 184.128 +            public boolean hasMoreElements() {
 184.129 +                return pos < sig.length();
 184.130 +            }
 184.131 +
 184.132 +            public Class nextElement() {
 184.133 +                switch (sig.charAt(pos++)) {
 184.134 +                    case 'I':
 184.135 +                        return Integer.TYPE;
 184.136 +                    case 'J':
 184.137 +                        return Long.TYPE;
 184.138 +                    case 'D':
 184.139 +                        return Double.TYPE;
 184.140 +                    case 'F':
 184.141 +                        return Float.TYPE;
 184.142 +                    case 'B':
 184.143 +                        return Byte.TYPE;
 184.144 +                    case 'Z':
 184.145 +                        return Boolean.TYPE;
 184.146 +                    case 'S':
 184.147 +                        return Short.TYPE;
 184.148 +                    case 'V':
 184.149 +                        return Void.TYPE;
 184.150 +                    case 'C':
 184.151 +                        return Character.TYPE;
 184.152 +                    case 'L':
 184.153 +                        try {
 184.154 +                            int up = sig.indexOf("_2");
 184.155 +                            String type = sig.substring(1, up);
 184.156 +                            pos = up + 2;
 184.157 +                            return Class.forName(type);
 184.158 +                        } catch (ClassNotFoundException ex) {
 184.159 +                            // should not happen
 184.160 +                        }
 184.161 +                }
 184.162 +                throw new UnsupportedOperationException(sig + " at " + pos);
 184.163 +            }
 184.164 +        }
 184.165 +        return new E();
 184.166 +    }
 184.167 +}
   185.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   185.2 +++ b/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js	Sun Feb 03 07:48:42 2013 +0100
   185.3 @@ -0,0 +1,9 @@
   185.4 +// empty line needed here
   185.5 +Number.prototype.add32 = function(x) { return (this + x) | 0; };
   185.6 +Number.prototype.sub32 = function(x) { return (this - x) | 0; };
   185.7 +Number.prototype.mul32 = function(x) { 
   185.8 +    return (((this * (x >> 16)) << 16) + this * (x & 0xFFFF)) | 0;
   185.9 +};
  185.10 +
  185.11 +Number.prototype.toInt8 = function()  { return (this << 24) >> 24; };
  185.12 +Number.prototype.toInt16 = function() { return (this << 16) >> 16; };
  185.13 \ No newline at end of file
   186.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   186.2 +++ b/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_String.js	Sun Feb 03 07:48:42 2013 +0100
   186.3 @@ -0,0 +1,27 @@
   186.4 +// initialize methods on arrays and String constants
   186.5 +vm.java_lang_reflect_Array(false);
   186.6 +vm.java_lang_String(false);
   186.7 +
   186.8 +Array.prototype.at = function(indx, value) {
   186.9 +  if (indx < 0 || indx > this.length) {
  186.10 +      var e = vm.java_lang_ArrayIndexOutOfBoundsException(true);
  186.11 +      e.constructor.cons__VLjava_lang_String_2.call(e, indx.toString());
  186.12 +      throw e;
  186.13 +  }
  186.14 +  if (arguments.length === 2) {
  186.15 +      this[indx] = value;
  186.16 +  }
  186.17 +  return this[indx];
  186.18 +};
  186.19 +Array.prototype.getClass__Ljava_lang_Class_2 = function() {
  186.20 +  return vm.java_lang_Class(false).defineArray__Ljava_lang_Class_2Ljava_lang_String_2(this.jvmName);
  186.21 +};
  186.22 +Array.prototype.clone__Ljava_lang_Object_2 = function() {
  186.23 +  var s = this.length;
  186.24 +  var ret = new Array(s);
  186.25 +  for (var i = 0; i < s; i++) {
  186.26 +      ret[i] = this[i];
  186.27 +  }
  186.28 +  ret.jvmName = this.jvmName;
  186.29 +  return ret;
  186.30 +};
   187.1 --- a/emul/pom.xml	Wed Dec 05 10:03:58 2012 +0100
   187.2 +++ b/emul/pom.xml	Sun Feb 03 07:48:42 2013 +0100
   187.3 @@ -1,42 +1,18 @@
   187.4 -<?xml version="1.0"?>
   187.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"
   187.6 -    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   187.7 +<?xml version="1.0" encoding="UTF-8"?>
   187.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">
   187.9    <modelVersion>4.0.0</modelVersion>
  187.10    <parent>
  187.11 +    <artifactId>bck2brwsr</artifactId>
  187.12      <groupId>org.apidesign</groupId>
  187.13 -    <artifactId>bck2brwsr</artifactId>
  187.14      <version>0.3-SNAPSHOT</version>
  187.15    </parent>
  187.16    <groupId>org.apidesign.bck2brwsr</groupId>
  187.17 -  <artifactId>emul</artifactId>
  187.18 +  <artifactId>emul.pom</artifactId>
  187.19    <version>0.3-SNAPSHOT</version>
  187.20 -  <name>Java API Emulation</name>
  187.21 -  <url>http://maven.apache.org</url>
  187.22 -  <properties>
  187.23 -    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  187.24 -  </properties>
  187.25 -  <dependencies>
  187.26 -    <dependency>
  187.27 -      <groupId>org.apidesign.bck2brwsr</groupId>
  187.28 -      <artifactId>core</artifactId>
  187.29 -      <version>0.3-SNAPSHOT</version>
  187.30 -      <type>jar</type>
  187.31 -    </dependency>
  187.32 -  </dependencies>
  187.33 -  <build>
  187.34 -      <plugins>
  187.35 -          <plugin>
  187.36 -              <groupId>org.apache.maven.plugins</groupId>
  187.37 -              <artifactId>maven-compiler-plugin</artifactId>
  187.38 -              <version>2.5.1</version>
  187.39 -              <configuration>
  187.40 -                  <compilerArguments>
  187.41 -                      <bootclasspath>non-existing</bootclasspath>
  187.42 -                  </compilerArguments>
  187.43 -                 <source>1.7</source>
  187.44 -                 <target>1.7</target>
  187.45 -              </configuration>
  187.46 -          </plugin>
  187.47 -      </plugins>
  187.48 -  </build>
  187.49 +  <packaging>pom</packaging>
  187.50 +  <name>Emulation of Core Libraries</name>
  187.51 +  <modules>
  187.52 +    <module>mini</module>
  187.53 +    <module>compact</module>
  187.54 +  </modules>
  187.55  </project>
   188.1 --- a/emul/src/main/java/java/io/ByteArrayInputStream.java	Wed Dec 05 10:03:58 2012 +0100
   188.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   188.3 @@ -1,283 +0,0 @@
   188.4 -/*
   188.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   188.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   188.7 - *
   188.8 - * This code is free software; you can redistribute it and/or modify it
   188.9 - * under the terms of the GNU General Public License version 2 only, as
  188.10 - * published by the Free Software Foundation.  Oracle designates this
  188.11 - * particular file as subject to the "Classpath" exception as provided
  188.12 - * by Oracle in the LICENSE file that accompanied this code.
  188.13 - *
  188.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  188.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  188.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  188.17 - * version 2 for more details (a copy is included in the LICENSE file that
  188.18 - * accompanied this code).
  188.19 - *
  188.20 - * You should have received a copy of the GNU General Public License version
  188.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  188.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  188.23 - *
  188.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  188.25 - * or visit www.oracle.com if you need additional information or have any
  188.26 - * questions.
  188.27 - */
  188.28 -
  188.29 -package java.io;
  188.30 -
  188.31 -/**
  188.32 - * A <code>ByteArrayInputStream</code> contains
  188.33 - * an internal buffer that contains bytes that
  188.34 - * may be read from the stream. An internal
  188.35 - * counter keeps track of the next byte to
  188.36 - * be supplied by the <code>read</code> method.
  188.37 - * <p>
  188.38 - * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
  188.39 - * this class can be called after the stream has been closed without
  188.40 - * generating an <tt>IOException</tt>.
  188.41 - *
  188.42 - * @author  Arthur van Hoff
  188.43 - * @see     java.io.StringBufferInputStream
  188.44 - * @since   JDK1.0
  188.45 - */
  188.46 -public
  188.47 -class ByteArrayInputStream extends InputStream {
  188.48 -
  188.49 -    /**
  188.50 -     * An array of bytes that was provided
  188.51 -     * by the creator of the stream. Elements <code>buf[0]</code>
  188.52 -     * through <code>buf[count-1]</code> are the
  188.53 -     * only bytes that can ever be read from the
  188.54 -     * stream;  element <code>buf[pos]</code> is
  188.55 -     * the next byte to be read.
  188.56 -     */
  188.57 -    protected byte buf[];
  188.58 -
  188.59 -    /**
  188.60 -     * The index of the next character to read from the input stream buffer.
  188.61 -     * This value should always be nonnegative
  188.62 -     * and not larger than the value of <code>count</code>.
  188.63 -     * The next byte to be read from the input stream buffer
  188.64 -     * will be <code>buf[pos]</code>.
  188.65 -     */
  188.66 -    protected int pos;
  188.67 -
  188.68 -    /**
  188.69 -     * The currently marked position in the stream.
  188.70 -     * ByteArrayInputStream objects are marked at position zero by
  188.71 -     * default when constructed.  They may be marked at another
  188.72 -     * position within the buffer by the <code>mark()</code> method.
  188.73 -     * The current buffer position is set to this point by the
  188.74 -     * <code>reset()</code> method.
  188.75 -     * <p>
  188.76 -     * If no mark has been set, then the value of mark is the offset
  188.77 -     * passed to the constructor (or 0 if the offset was not supplied).
  188.78 -     *
  188.79 -     * @since   JDK1.1
  188.80 -     */
  188.81 -    protected int mark = 0;
  188.82 -
  188.83 -    /**
  188.84 -     * The index one greater than the last valid character in the input
  188.85 -     * stream buffer.
  188.86 -     * This value should always be nonnegative
  188.87 -     * and not larger than the length of <code>buf</code>.
  188.88 -     * It  is one greater than the position of
  188.89 -     * the last byte within <code>buf</code> that
  188.90 -     * can ever be read  from the input stream buffer.
  188.91 -     */
  188.92 -    protected int count;
  188.93 -
  188.94 -    /**
  188.95 -     * Creates a <code>ByteArrayInputStream</code>
  188.96 -     * so that it  uses <code>buf</code> as its
  188.97 -     * buffer array.
  188.98 -     * The buffer array is not copied.
  188.99 -     * The initial value of <code>pos</code>
 188.100 -     * is <code>0</code> and the initial value
 188.101 -     * of  <code>count</code> is the length of
 188.102 -     * <code>buf</code>.
 188.103 -     *
 188.104 -     * @param   buf   the input buffer.
 188.105 -     */
 188.106 -    public ByteArrayInputStream(byte buf[]) {
 188.107 -        this.buf = buf;
 188.108 -        this.pos = 0;
 188.109 -        this.count = buf.length;
 188.110 -    }
 188.111 -
 188.112 -    /**
 188.113 -     * Creates <code>ByteArrayInputStream</code>
 188.114 -     * that uses <code>buf</code> as its
 188.115 -     * buffer array. The initial value of <code>pos</code>
 188.116 -     * is <code>offset</code> and the initial value
 188.117 -     * of <code>count</code> is the minimum of <code>offset+length</code>
 188.118 -     * and <code>buf.length</code>.
 188.119 -     * The buffer array is not copied. The buffer's mark is
 188.120 -     * set to the specified offset.
 188.121 -     *
 188.122 -     * @param   buf      the input buffer.
 188.123 -     * @param   offset   the offset in the buffer of the first byte to read.
 188.124 -     * @param   length   the maximum number of bytes to read from the buffer.
 188.125 -     */
 188.126 -    public ByteArrayInputStream(byte buf[], int offset, int length) {
 188.127 -        this.buf = buf;
 188.128 -        this.pos = offset;
 188.129 -        this.count = Math.min(offset + length, buf.length);
 188.130 -        this.mark = offset;
 188.131 -    }
 188.132 -
 188.133 -    /**
 188.134 -     * Reads the next byte of data from this input stream. The value
 188.135 -     * byte is returned as an <code>int</code> in the range
 188.136 -     * <code>0</code> to <code>255</code>. If no byte is available
 188.137 -     * because the end of the stream has been reached, the value
 188.138 -     * <code>-1</code> is returned.
 188.139 -     * <p>
 188.140 -     * This <code>read</code> method
 188.141 -     * cannot block.
 188.142 -     *
 188.143 -     * @return  the next byte of data, or <code>-1</code> if the end of the
 188.144 -     *          stream has been reached.
 188.145 -     */
 188.146 -    public synchronized int read() {
 188.147 -        return (pos < count) ? (buf[pos++] & 0xff) : -1;
 188.148 -    }
 188.149 -
 188.150 -    /**
 188.151 -     * Reads up to <code>len</code> bytes of data into an array of bytes
 188.152 -     * from this input stream.
 188.153 -     * If <code>pos</code> equals <code>count</code>,
 188.154 -     * then <code>-1</code> is returned to indicate
 188.155 -     * end of file. Otherwise, the  number <code>k</code>
 188.156 -     * of bytes read is equal to the smaller of
 188.157 -     * <code>len</code> and <code>count-pos</code>.
 188.158 -     * If <code>k</code> is positive, then bytes
 188.159 -     * <code>buf[pos]</code> through <code>buf[pos+k-1]</code>
 188.160 -     * are copied into <code>b[off]</code>  through
 188.161 -     * <code>b[off+k-1]</code> in the manner performed
 188.162 -     * by <code>System.arraycopy</code>. The
 188.163 -     * value <code>k</code> is added into <code>pos</code>
 188.164 -     * and <code>k</code> is returned.
 188.165 -     * <p>
 188.166 -     * This <code>read</code> method cannot block.
 188.167 -     *
 188.168 -     * @param   b     the buffer into which the data is read.
 188.169 -     * @param   off   the start offset in the destination array <code>b</code>
 188.170 -     * @param   len   the maximum number of bytes read.
 188.171 -     * @return  the total number of bytes read into the buffer, or
 188.172 -     *          <code>-1</code> if there is no more data because the end of
 188.173 -     *          the stream has been reached.
 188.174 -     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 188.175 -     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 188.176 -     * <code>len</code> is negative, or <code>len</code> is greater than
 188.177 -     * <code>b.length - off</code>
 188.178 -     */
 188.179 -    public synchronized int read(byte b[], int off, int len) {
 188.180 -        if (b == null) {
 188.181 -            throw new NullPointerException();
 188.182 -        } else if (off < 0 || len < 0 || len > b.length - off) {
 188.183 -            throw new IndexOutOfBoundsException();
 188.184 -        }
 188.185 -
 188.186 -        if (pos >= count) {
 188.187 -            return -1;
 188.188 -        }
 188.189 -
 188.190 -        int avail = count - pos;
 188.191 -        if (len > avail) {
 188.192 -            len = avail;
 188.193 -        }
 188.194 -        if (len <= 0) {
 188.195 -            return 0;
 188.196 -        }
 188.197 -        PushbackInputStream.arraycopy(buf, pos, b, off, len);
 188.198 -        pos += len;
 188.199 -        return len;
 188.200 -    }
 188.201 -
 188.202 -    /**
 188.203 -     * Skips <code>n</code> bytes of input from this input stream. Fewer
 188.204 -     * bytes might be skipped if the end of the input stream is reached.
 188.205 -     * The actual number <code>k</code>
 188.206 -     * of bytes to be skipped is equal to the smaller
 188.207 -     * of <code>n</code> and  <code>count-pos</code>.
 188.208 -     * The value <code>k</code> is added into <code>pos</code>
 188.209 -     * and <code>k</code> is returned.
 188.210 -     *
 188.211 -     * @param   n   the number of bytes to be skipped.
 188.212 -     * @return  the actual number of bytes skipped.
 188.213 -     */
 188.214 -    public synchronized long skip(long n) {
 188.215 -        long k = count - pos;
 188.216 -        if (n < k) {
 188.217 -            k = n < 0 ? 0 : n;
 188.218 -        }
 188.219 -
 188.220 -        pos += k;
 188.221 -        return k;
 188.222 -    }
 188.223 -
 188.224 -    /**
 188.225 -     * Returns the number of remaining bytes that can be read (or skipped over)
 188.226 -     * from this input stream.
 188.227 -     * <p>
 188.228 -     * The value returned is <code>count&nbsp;- pos</code>,
 188.229 -     * which is the number of bytes remaining to be read from the input buffer.
 188.230 -     *
 188.231 -     * @return  the number of remaining bytes that can be read (or skipped
 188.232 -     *          over) from this input stream without blocking.
 188.233 -     */
 188.234 -    public synchronized int available() {
 188.235 -        return count - pos;
 188.236 -    }
 188.237 -
 188.238 -    /**
 188.239 -     * Tests if this <code>InputStream</code> supports mark/reset. The
 188.240 -     * <code>markSupported</code> method of <code>ByteArrayInputStream</code>
 188.241 -     * always returns <code>true</code>.
 188.242 -     *
 188.243 -     * @since   JDK1.1
 188.244 -     */
 188.245 -    public boolean markSupported() {
 188.246 -        return true;
 188.247 -    }
 188.248 -
 188.249 -    /**
 188.250 -     * Set the current marked position in the stream.
 188.251 -     * ByteArrayInputStream objects are marked at position zero by
 188.252 -     * default when constructed.  They may be marked at another
 188.253 -     * position within the buffer by this method.
 188.254 -     * <p>
 188.255 -     * If no mark has been set, then the value of the mark is the
 188.256 -     * offset passed to the constructor (or 0 if the offset was not
 188.257 -     * supplied).
 188.258 -     *
 188.259 -     * <p> Note: The <code>readAheadLimit</code> for this class
 188.260 -     *  has no meaning.
 188.261 -     *
 188.262 -     * @since   JDK1.1
 188.263 -     */
 188.264 -    public void mark(int readAheadLimit) {
 188.265 -        mark = pos;
 188.266 -    }
 188.267 -
 188.268 -    /**
 188.269 -     * Resets the buffer to the marked position.  The marked position
 188.270 -     * is 0 unless another position was marked or an offset was specified
 188.271 -     * in the constructor.
 188.272 -     */
 188.273 -    public synchronized void reset() {
 188.274 -        pos = mark;
 188.275 -    }
 188.276 -
 188.277 -    /**
 188.278 -     * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
 188.279 -     * this class can be called after the stream has been closed without
 188.280 -     * generating an <tt>IOException</tt>.
 188.281 -     * <p>
 188.282 -     */
 188.283 -    public void close() throws IOException {
 188.284 -    }
 188.285 -
 188.286 -}
   189.1 --- a/emul/src/main/java/java/io/Closeable.java	Wed Dec 05 10:03:58 2012 +0100
   189.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   189.3 @@ -1,48 +0,0 @@
   189.4 -/*
   189.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   189.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   189.7 - *
   189.8 - * This code is free software; you can redistribute it and/or modify it
   189.9 - * under the terms of the GNU General Public License version 2 only, as
  189.10 - * published by the Free Software Foundation.  Oracle designates this
  189.11 - * particular file as subject to the "Classpath" exception as provided
  189.12 - * by Oracle in the LICENSE file that accompanied this code.
  189.13 - *
  189.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  189.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  189.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  189.17 - * version 2 for more details (a copy is included in the LICENSE file that
  189.18 - * accompanied this code).
  189.19 - *
  189.20 - * You should have received a copy of the GNU General Public License version
  189.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  189.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  189.23 - *
  189.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  189.25 - * or visit www.oracle.com if you need additional information or have any
  189.26 - * questions.
  189.27 - */
  189.28 -
  189.29 -package java.io;
  189.30 -
  189.31 -import java.io.IOException;
  189.32 -
  189.33 -/**
  189.34 - * A {@code Closeable} is a source or destination of data that can be closed.
  189.35 - * The close method is invoked to release resources that the object is
  189.36 - * holding (such as open files).
  189.37 - *
  189.38 - * @since 1.5
  189.39 - */
  189.40 -
  189.41 -public interface Closeable extends AutoCloseable {
  189.42 -
  189.43 -    /**
  189.44 -     * Closes this stream and releases any system resources associated
  189.45 -     * with it. If the stream is already closed then invoking this
  189.46 -     * method has no effect.
  189.47 -     *
  189.48 -     * @throws IOException if an I/O error occurs
  189.49 -     */
  189.50 -    public void close() throws IOException;
  189.51 -}
   190.1 --- a/emul/src/main/java/java/io/DataInput.java	Wed Dec 05 10:03:58 2012 +0100
   190.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   190.3 @@ -1,635 +0,0 @@
   190.4 -/*
   190.5 - * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
   190.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   190.7 - *
   190.8 - * This code is free software; you can redistribute it and/or modify it
   190.9 - * under the terms of the GNU General Public License version 2 only, as
  190.10 - * published by the Free Software Foundation.  Oracle designates this
  190.11 - * particular file as subject to the "Classpath" exception as provided
  190.12 - * by Oracle in the LICENSE file that accompanied this code.
  190.13 - *
  190.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  190.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  190.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  190.17 - * version 2 for more details (a copy is included in the LICENSE file that
  190.18 - * accompanied this code).
  190.19 - *
  190.20 - * You should have received a copy of the GNU General Public License version
  190.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  190.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  190.23 - *
  190.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  190.25 - * or visit www.oracle.com if you need additional information or have any
  190.26 - * questions.
  190.27 - */
  190.28 -
  190.29 -package java.io;
  190.30 -
  190.31 -/**
  190.32 - * The <code>DataInput</code> interface provides
  190.33 - * for reading bytes from a binary stream and
  190.34 - * reconstructing from them data in any of
  190.35 - * the Java primitive types. There is also
  190.36 - * a
  190.37 - * facility for reconstructing a <code>String</code>
  190.38 - * from data in
  190.39 - * <a href="#modified-utf-8">modified UTF-8</a>
  190.40 - * format.
  190.41 - * <p>
  190.42 - * It is generally true of all the reading
  190.43 - * routines in this interface that if end of
  190.44 - * file is reached before the desired number
  190.45 - * of bytes has been read, an <code>EOFException</code>
  190.46 - * (which is a kind of <code>IOException</code>)
  190.47 - * is thrown. If any byte cannot be read for
  190.48 - * any reason other than end of file, an <code>IOException</code>
  190.49 - * other than <code>EOFException</code> is
  190.50 - * thrown. In particular, an <code>IOException</code>
  190.51 - * may be thrown if the input stream has been
  190.52 - * closed.
  190.53 - *
  190.54 - * <h4><a name="modified-utf-8">Modified UTF-8</a></h4>
  190.55 - * <p>
  190.56 - * Implementations of the DataInput and DataOutput interfaces represent
  190.57 - * Unicode strings in a format that is a slight modification of UTF-8.
  190.58 - * (For information regarding the standard UTF-8 format, see section
  190.59 - * <i>3.9 Unicode Encoding Forms</i> of <i>The Unicode Standard, Version
  190.60 - * 4.0</i>).
  190.61 - * Note that in the following tables, the most significant bit appears in the
  190.62 - * far left-hand column.
  190.63 - * <p>
  190.64 - * All characters in the range <code>'&#92;u0001'</code> to
  190.65 - * <code>'&#92;u007F'</code> are represented by a single byte:
  190.66 - *
  190.67 - * <blockquote>
  190.68 - *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
  190.69 - *          summary="Bit values and bytes">
  190.70 - *     <tr>
  190.71 - *       <td></td>
  190.72 - *       <th id="bit">Bit Values</th>
  190.73 - *     </tr>
  190.74 - *     <tr>
  190.75 - *       <th id="byte1">Byte 1</th>
  190.76 - *       <td>
  190.77 - *         <table border="1" cellspacing="0" width="100%">
  190.78 - *           <tr>
  190.79 - *             <td width="12%"><center>0</center>
  190.80 - *             <td colspan="7"><center>bits 6-0</center>
  190.81 - *           </tr>
  190.82 - *         </table>
  190.83 - *       </td>
  190.84 - *     </tr>
  190.85 - *   </table>
  190.86 - * </blockquote>
  190.87 - *
  190.88 - * <p>
  190.89 - * The null character <code>'&#92;u0000'</code> and characters in the
  190.90 - * range <code>'&#92;u0080'</code> to <code>'&#92;u07FF'</code> are
  190.91 - * represented by a pair of bytes:
  190.92 - *
  190.93 - * <blockquote>
  190.94 - *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
  190.95 - *          summary="Bit values and bytes">
  190.96 - *     <tr>
  190.97 - *       <td></td>
  190.98 - *       <th id="bit">Bit Values</th>
  190.99 - *     </tr>
 190.100 - *     <tr>
 190.101 - *       <th id="byte1">Byte 1</th>
 190.102 - *       <td>
 190.103 - *         <table border="1" cellspacing="0" width="100%">
 190.104 - *           <tr>
 190.105 - *             <td width="12%"><center>1</center>
 190.106 - *             <td width="13%"><center>1</center>
 190.107 - *             <td width="12%"><center>0</center>
 190.108 - *             <td colspan="5"><center>bits 10-6</center>
 190.109 - *           </tr>
 190.110 - *         </table>
 190.111 - *       </td>
 190.112 - *     </tr>
 190.113 - *     <tr>
 190.114 - *       <th id="byte2">Byte 2</th>
 190.115 - *       <td>
 190.116 - *         <table border="1" cellspacing="0" width="100%">
 190.117 - *           <tr>
 190.118 - *             <td width="12%"><center>1</center>
 190.119 - *             <td width="13%"><center>0</center>
 190.120 - *             <td colspan="6"><center>bits 5-0</center>
 190.121 - *           </tr>
 190.122 - *         </table>
 190.123 - *       </td>
 190.124 - *     </tr>
 190.125 - *   </table>
 190.126 - *  </blockquote>
 190.127 - *
 190.128 - * <br>
 190.129 - * <code>char</code> values in the range <code>'&#92;u0800'</code> to
 190.130 - * <code>'&#92;uFFFF'</code> are represented by three bytes:
 190.131 - *
 190.132 - * <blockquote>
 190.133 - *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
 190.134 - *          summary="Bit values and bytes">
 190.135 - *     <tr>
 190.136 - *       <td></td>
 190.137 - *       <th id="bit">Bit Values</th>
 190.138 - *     </tr>
 190.139 - *     <tr>
 190.140 - *       <th id="byte1">Byte 1</th>
 190.141 - *       <td>
 190.142 - *         <table border="1" cellspacing="0" width="100%">
 190.143 - *           <tr>
 190.144 - *             <td width="12%"><center>1</center>
 190.145 - *             <td width="13%"><center>1</center>
 190.146 - *             <td width="12%"><center>1</center>
 190.147 - *             <td width="13%"><center>0</center>
 190.148 - *             <td colspan="4"><center>bits 15-12</center>
 190.149 - *           </tr>
 190.150 - *         </table>
 190.151 - *       </td>
 190.152 - *     </tr>
 190.153 - *     <tr>
 190.154 - *       <th id="byte2">Byte 2</th>
 190.155 - *       <td>
 190.156 - *         <table border="1" cellspacing="0" width="100%">
 190.157 - *           <tr>
 190.158 - *             <td width="12%"><center>1</center>
 190.159 - *             <td width="13%"><center>0</center>
 190.160 - *             <td colspan="6"><center>bits 11-6</center>
 190.161 - *           </tr>
 190.162 - *         </table>
 190.163 - *       </td>
 190.164 - *     </tr>
 190.165 - *     <tr>
 190.166 - *       <th id="byte3">Byte 3</th>
 190.167 - *       <td>
 190.168 - *         <table border="1" cellspacing="0" width="100%">
 190.169 - *           <tr>
 190.170 - *             <td width="12%"><center>1</center>
 190.171 - *             <td width="13%"><center>0</center>
 190.172 - *             <td colspan="6"><center>bits 5-0</center>
 190.173 - *           </tr>
 190.174 - *         </table>
 190.175 - *       </td>
 190.176 - *     </tr>
 190.177 - *   </table>
 190.178 - *  </blockquote>
 190.179 - *
 190.180 - * <p>
 190.181 - * The differences between this format and the
 190.182 - * standard UTF-8 format are the following:
 190.183 - * <ul>
 190.184 - * <li>The null byte <code>'&#92;u0000'</code> is encoded in 2-byte format
 190.185 - *     rather than 1-byte, so that the encoded strings never have
 190.186 - *     embedded nulls.
 190.187 - * <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
 190.188 - * <li><a href="../lang/Character.html#unicode">Supplementary characters</a>
 190.189 - *     are represented in the form of surrogate pairs.
 190.190 - * </ul>
 190.191 - * @author  Frank Yellin
 190.192 - * @see     java.io.DataInputStream
 190.193 - * @see     java.io.DataOutput
 190.194 - * @since   JDK1.0
 190.195 - */
 190.196 -public
 190.197 -interface DataInput {
 190.198 -    /**
 190.199 -     * Reads some bytes from an input
 190.200 -     * stream and stores them into the buffer
 190.201 -     * array <code>b</code>. The number of bytes
 190.202 -     * read is equal
 190.203 -     * to the length of <code>b</code>.
 190.204 -     * <p>
 190.205 -     * This method blocks until one of the
 190.206 -     * following conditions occurs:<p>
 190.207 -     * <ul>
 190.208 -     * <li><code>b.length</code>
 190.209 -     * bytes of input data are available, in which
 190.210 -     * case a normal return is made.
 190.211 -     *
 190.212 -     * <li>End of
 190.213 -     * file is detected, in which case an <code>EOFException</code>
 190.214 -     * is thrown.
 190.215 -     *
 190.216 -     * <li>An I/O error occurs, in
 190.217 -     * which case an <code>IOException</code> other
 190.218 -     * than <code>EOFException</code> is thrown.
 190.219 -     * </ul>
 190.220 -     * <p>
 190.221 -     * If <code>b</code> is <code>null</code>,
 190.222 -     * a <code>NullPointerException</code> is thrown.
 190.223 -     * If <code>b.length</code> is zero, then
 190.224 -     * no bytes are read. Otherwise, the first
 190.225 -     * byte read is stored into element <code>b[0]</code>,
 190.226 -     * the next one into <code>b[1]</code>, and
 190.227 -     * so on.
 190.228 -     * If an exception is thrown from
 190.229 -     * this method, then it may be that some but
 190.230 -     * not all bytes of <code>b</code> have been
 190.231 -     * updated with data from the input stream.
 190.232 -     *
 190.233 -     * @param     b   the buffer into which the data is read.
 190.234 -     * @exception  EOFException  if this stream reaches the end before reading
 190.235 -     *               all the bytes.
 190.236 -     * @exception  IOException   if an I/O error occurs.
 190.237 -     */
 190.238 -    void readFully(byte b[]) throws IOException;
 190.239 -
 190.240 -    /**
 190.241 -     *
 190.242 -     * Reads <code>len</code>
 190.243 -     * bytes from
 190.244 -     * an input stream.
 190.245 -     * <p>
 190.246 -     * This method
 190.247 -     * blocks until one of the following conditions
 190.248 -     * occurs:<p>
 190.249 -     * <ul>
 190.250 -     * <li><code>len</code> bytes
 190.251 -     * of input data are available, in which case
 190.252 -     * a normal return is made.
 190.253 -     *
 190.254 -     * <li>End of file
 190.255 -     * is detected, in which case an <code>EOFException</code>
 190.256 -     * is thrown.
 190.257 -     *
 190.258 -     * <li>An I/O error occurs, in
 190.259 -     * which case an <code>IOException</code> other
 190.260 -     * than <code>EOFException</code> is thrown.
 190.261 -     * </ul>
 190.262 -     * <p>
 190.263 -     * If <code>b</code> is <code>null</code>,
 190.264 -     * a <code>NullPointerException</code> is thrown.
 190.265 -     * If <code>off</code> is negative, or <code>len</code>
 190.266 -     * is negative, or <code>off+len</code> is
 190.267 -     * greater than the length of the array <code>b</code>,
 190.268 -     * then an <code>IndexOutOfBoundsException</code>
 190.269 -     * is thrown.
 190.270 -     * If <code>len</code> is zero,
 190.271 -     * then no bytes are read. Otherwise, the first
 190.272 -     * byte read is stored into element <code>b[off]</code>,
 190.273 -     * the next one into <code>b[off+1]</code>,
 190.274 -     * and so on. The number of bytes read is,
 190.275 -     * at most, equal to <code>len</code>.
 190.276 -     *
 190.277 -     * @param     b   the buffer into which the data is read.
 190.278 -     * @param off  an int specifying the offset into the data.
 190.279 -     * @param len  an int specifying the number of bytes to read.
 190.280 -     * @exception  EOFException  if this stream reaches the end before reading
 190.281 -     *               all the bytes.
 190.282 -     * @exception  IOException   if an I/O error occurs.
 190.283 -     */
 190.284 -    void readFully(byte b[], int off, int len) throws IOException;
 190.285 -
 190.286 -    /**
 190.287 -     * Makes an attempt to skip over
 190.288 -     * <code>n</code> bytes
 190.289 -     * of data from the input
 190.290 -     * stream, discarding the skipped bytes. However,
 190.291 -     * it may skip
 190.292 -     * over some smaller number of
 190.293 -     * bytes, possibly zero. This may result from
 190.294 -     * any of a
 190.295 -     * number of conditions; reaching
 190.296 -     * end of file before <code>n</code> bytes
 190.297 -     * have been skipped is
 190.298 -     * only one possibility.
 190.299 -     * This method never throws an <code>EOFException</code>.
 190.300 -     * The actual
 190.301 -     * number of bytes skipped is returned.
 190.302 -     *
 190.303 -     * @param      n   the number of bytes to be skipped.
 190.304 -     * @return     the number of bytes actually skipped.
 190.305 -     * @exception  IOException   if an I/O error occurs.
 190.306 -     */
 190.307 -    int skipBytes(int n) throws IOException;
 190.308 -
 190.309 -    /**
 190.310 -     * Reads one input byte and returns
 190.311 -     * <code>true</code> if that byte is nonzero,
 190.312 -     * <code>false</code> if that byte is zero.
 190.313 -     * This method is suitable for reading
 190.314 -     * the byte written by the <code>writeBoolean</code>
 190.315 -     * method of interface <code>DataOutput</code>.
 190.316 -     *
 190.317 -     * @return     the <code>boolean</code> value read.
 190.318 -     * @exception  EOFException  if this stream reaches the end before reading
 190.319 -     *               all the bytes.
 190.320 -     * @exception  IOException   if an I/O error occurs.
 190.321 -     */
 190.322 -    boolean readBoolean() throws IOException;
 190.323 -
 190.324 -    /**
 190.325 -     * Reads and returns one input byte.
 190.326 -     * The byte is treated as a signed value in
 190.327 -     * the range <code>-128</code> through <code>127</code>,
 190.328 -     * inclusive.
 190.329 -     * This method is suitable for
 190.330 -     * reading the byte written by the <code>writeByte</code>
 190.331 -     * method of interface <code>DataOutput</code>.
 190.332 -     *
 190.333 -     * @return     the 8-bit value read.
 190.334 -     * @exception  EOFException  if this stream reaches the end before reading
 190.335 -     *               all the bytes.
 190.336 -     * @exception  IOException   if an I/O error occurs.
 190.337 -     */
 190.338 -    byte readByte() throws IOException;
 190.339 -
 190.340 -    /**
 190.341 -     * Reads one input byte, zero-extends
 190.342 -     * it to type <code>int</code>, and returns
 190.343 -     * the result, which is therefore in the range
 190.344 -     * <code>0</code>
 190.345 -     * through <code>255</code>.
 190.346 -     * This method is suitable for reading
 190.347 -     * the byte written by the <code>writeByte</code>
 190.348 -     * method of interface <code>DataOutput</code>
 190.349 -     * if the argument to <code>writeByte</code>
 190.350 -     * was intended to be a value in the range
 190.351 -     * <code>0</code> through <code>255</code>.
 190.352 -     *
 190.353 -     * @return     the unsigned 8-bit value read.
 190.354 -     * @exception  EOFException  if this stream reaches the end before reading
 190.355 -     *               all the bytes.
 190.356 -     * @exception  IOException   if an I/O error occurs.
 190.357 -     */
 190.358 -    int readUnsignedByte() throws IOException;
 190.359 -
 190.360 -    /**
 190.361 -     * Reads two input bytes and returns
 190.362 -     * a <code>short</code> value. Let <code>a</code>
 190.363 -     * be the first byte read and <code>b</code>
 190.364 -     * be the second byte. The value
 190.365 -     * returned
 190.366 -     * is:
 190.367 -     * <p><pre><code>(short)((a &lt;&lt; 8) | (b &amp; 0xff))
 190.368 -     * </code></pre>
 190.369 -     * This method
 190.370 -     * is suitable for reading the bytes written
 190.371 -     * by the <code>writeShort</code> method of
 190.372 -     * interface <code>DataOutput</code>.
 190.373 -     *
 190.374 -     * @return     the 16-bit value read.
 190.375 -     * @exception  EOFException  if this stream reaches the end before reading
 190.376 -     *               all the bytes.
 190.377 -     * @exception  IOException   if an I/O error occurs.
 190.378 -     */
 190.379 -    short readShort() throws IOException;
 190.380 -
 190.381 -    /**
 190.382 -     * Reads two input bytes and returns
 190.383 -     * an <code>int</code> value in the range <code>0</code>
 190.384 -     * through <code>65535</code>. Let <code>a</code>
 190.385 -     * be the first byte read and
 190.386 -     * <code>b</code>
 190.387 -     * be the second byte. The value returned is:
 190.388 -     * <p><pre><code>(((a &amp; 0xff) &lt;&lt; 8) | (b &amp; 0xff))
 190.389 -     * </code></pre>
 190.390 -     * This method is suitable for reading the bytes
 190.391 -     * written by the <code>writeShort</code> method
 190.392 -     * of interface <code>DataOutput</code>  if
 190.393 -     * the argument to <code>writeShort</code>
 190.394 -     * was intended to be a value in the range
 190.395 -     * <code>0</code> through <code>65535</code>.
 190.396 -     *
 190.397 -     * @return     the unsigned 16-bit value read.
 190.398 -     * @exception  EOFException  if this stream reaches the end before reading
 190.399 -     *               all the bytes.
 190.400 -     * @exception  IOException   if an I/O error occurs.
 190.401 -     */
 190.402 -    int readUnsignedShort() throws IOException;
 190.403 -
 190.404 -    /**
 190.405 -     * Reads two input bytes and returns a <code>char</code> value.
 190.406 -     * Let <code>a</code>
 190.407 -     * be the first byte read and <code>b</code>
 190.408 -     * be the second byte. The value
 190.409 -     * returned is:
 190.410 -     * <p><pre><code>(char)((a &lt;&lt; 8) | (b &amp; 0xff))
 190.411 -     * </code></pre>
 190.412 -     * This method
 190.413 -     * is suitable for reading bytes written by
 190.414 -     * the <code>writeChar</code> method of interface
 190.415 -     * <code>DataOutput</code>.
 190.416 -     *
 190.417 -     * @return     the <code>char</code> value read.
 190.418 -     * @exception  EOFException  if this stream reaches the end before reading
 190.419 -     *               all the bytes.
 190.420 -     * @exception  IOException   if an I/O error occurs.
 190.421 -     */
 190.422 -    char readChar() throws IOException;
 190.423 -
 190.424 -    /**
 190.425 -     * Reads four input bytes and returns an
 190.426 -     * <code>int</code> value. Let <code>a-d</code>
 190.427 -     * be the first through fourth bytes read. The value returned is:
 190.428 -     * <p><pre>
 190.429 -     * <code>
 190.430 -     * (((a &amp; 0xff) &lt;&lt; 24) | ((b &amp; 0xff) &lt;&lt; 16) |
 190.431 -     * &#32;((c &amp; 0xff) &lt;&lt; 8) | (d &amp; 0xff))
 190.432 -     * </code></pre>
 190.433 -     * This method is suitable
 190.434 -     * for reading bytes written by the <code>writeInt</code>
 190.435 -     * method of interface <code>DataOutput</code>.
 190.436 -     *
 190.437 -     * @return     the <code>int</code> value read.
 190.438 -     * @exception  EOFException  if this stream reaches the end before reading
 190.439 -     *               all the bytes.
 190.440 -     * @exception  IOException   if an I/O error occurs.
 190.441 -     */
 190.442 -    int readInt() throws IOException;
 190.443 -
 190.444 -    /**
 190.445 -     * Reads eight input bytes and returns
 190.446 -     * a <code>long</code> value. Let <code>a-h</code>
 190.447 -     * be the first through eighth bytes read.
 190.448 -     * The value returned is:
 190.449 -     * <p><pre> <code>
 190.450 -     * (((long)(a &amp; 0xff) &lt;&lt; 56) |
 190.451 -     *  ((long)(b &amp; 0xff) &lt;&lt; 48) |
 190.452 -     *  ((long)(c &amp; 0xff) &lt;&lt; 40) |
 190.453 -     *  ((long)(d &amp; 0xff) &lt;&lt; 32) |
 190.454 -     *  ((long)(e &amp; 0xff) &lt;&lt; 24) |
 190.455 -     *  ((long)(f &amp; 0xff) &lt;&lt; 16) |
 190.456 -     *  ((long)(g &amp; 0xff) &lt;&lt;  8) |
 190.457 -     *  ((long)(h &amp; 0xff)))
 190.458 -     * </code></pre>
 190.459 -     * <p>
 190.460 -     * This method is suitable
 190.461 -     * for reading bytes written by the <code>writeLong</code>
 190.462 -     * method of interface <code>DataOutput</code>.
 190.463 -     *
 190.464 -     * @return     the <code>long</code> value read.
 190.465 -     * @exception  EOFException  if this stream reaches the end before reading
 190.466 -     *               all the bytes.
 190.467 -     * @exception  IOException   if an I/O error occurs.
 190.468 -     */
 190.469 -    long readLong() throws IOException;
 190.470 -
 190.471 -    /**
 190.472 -     * Reads four input bytes and returns
 190.473 -     * a <code>float</code> value. It does this
 190.474 -     * by first constructing an <code>int</code>
 190.475 -     * value in exactly the manner
 190.476 -     * of the <code>readInt</code>
 190.477 -     * method, then converting this <code>int</code>
 190.478 -     * value to a <code>float</code> in
 190.479 -     * exactly the manner of the method <code>Float.intBitsToFloat</code>.
 190.480 -     * This method is suitable for reading
 190.481 -     * bytes written by the <code>writeFloat</code>
 190.482 -     * method of interface <code>DataOutput</code>.
 190.483 -     *
 190.484 -     * @return     the <code>float</code> value read.
 190.485 -     * @exception  EOFException  if this stream reaches the end before reading
 190.486 -     *               all the bytes.
 190.487 -     * @exception  IOException   if an I/O error occurs.
 190.488 -     */
 190.489 -    float readFloat() throws IOException;
 190.490 -
 190.491 -    /**
 190.492 -     * Reads eight input bytes and returns
 190.493 -     * a <code>double</code> value. It does this
 190.494 -     * by first constructing a <code>long</code>
 190.495 -     * value in exactly the manner
 190.496 -     * of the <code>readlong</code>
 190.497 -     * method, then converting this <code>long</code>
 190.498 -     * value to a <code>double</code> in exactly
 190.499 -     * the manner of the method <code>Double.longBitsToDouble</code>.
 190.500 -     * This method is suitable for reading
 190.501 -     * bytes written by the <code>writeDouble</code>
 190.502 -     * method of interface <code>DataOutput</code>.
 190.503 -     *
 190.504 -     * @return     the <code>double</code> value read.
 190.505 -     * @exception  EOFException  if this stream reaches the end before reading
 190.506 -     *               all the bytes.
 190.507 -     * @exception  IOException   if an I/O error occurs.
 190.508 -     */
 190.509 -    double readDouble() throws IOException;
 190.510 -
 190.511 -    /**
 190.512 -     * Reads the next line of text from the input stream.
 190.513 -     * It reads successive bytes, converting
 190.514 -     * each byte separately into a character,
 190.515 -     * until it encounters a line terminator or
 190.516 -     * end of
 190.517 -     * file; the characters read are then
 190.518 -     * returned as a <code>String</code>. Note
 190.519 -     * that because this
 190.520 -     * method processes bytes,
 190.521 -     * it does not support input of the full Unicode
 190.522 -     * character set.
 190.523 -     * <p>
 190.524 -     * If end of file is encountered
 190.525 -     * before even one byte can be read, then <code>null</code>
 190.526 -     * is returned. Otherwise, each byte that is
 190.527 -     * read is converted to type <code>char</code>
 190.528 -     * by zero-extension. If the character <code>'\n'</code>
 190.529 -     * is encountered, it is discarded and reading
 190.530 -     * ceases. If the character <code>'\r'</code>
 190.531 -     * is encountered, it is discarded and, if
 190.532 -     * the following byte converts &#32;to the
 190.533 -     * character <code>'\n'</code>, then that is
 190.534 -     * discarded also; reading then ceases. If
 190.535 -     * end of file is encountered before either
 190.536 -     * of the characters <code>'\n'</code> and
 190.537 -     * <code>'\r'</code> is encountered, reading
 190.538 -     * ceases. Once reading has ceased, a <code>String</code>
 190.539 -     * is returned that contains all the characters
 190.540 -     * read and not discarded, taken in order.
 190.541 -     * Note that every character in this string
 190.542 -     * will have a value less than <code>&#92;u0100</code>,
 190.543 -     * that is, <code>(char)256</code>.
 190.544 -     *
 190.545 -     * @return the next line of text from the input stream,
 190.546 -     *         or <CODE>null</CODE> if the end of file is
 190.547 -     *         encountered before a byte can be read.
 190.548 -     * @exception  IOException  if an I/O error occurs.
 190.549 -     */
 190.550 -    String readLine() throws IOException;
 190.551 -
 190.552 -    /**
 190.553 -     * Reads in a string that has been encoded using a
 190.554 -     * <a href="#modified-utf-8">modified UTF-8</a>
 190.555 -     * format.
 190.556 -     * The general contract of <code>readUTF</code>
 190.557 -     * is that it reads a representation of a Unicode
 190.558 -     * character string encoded in modified
 190.559 -     * UTF-8 format; this string of characters
 190.560 -     * is then returned as a <code>String</code>.
 190.561 -     * <p>
 190.562 -     * First, two bytes are read and used to
 190.563 -     * construct an unsigned 16-bit integer in
 190.564 -     * exactly the manner of the <code>readUnsignedShort</code>
 190.565 -     * method . This integer value is called the
 190.566 -     * <i>UTF length</i> and specifies the number
 190.567 -     * of additional bytes to be read. These bytes
 190.568 -     * are then converted to characters by considering
 190.569 -     * them in groups. The length of each group
 190.570 -     * is computed from the value of the first
 190.571 -     * byte of the group. The byte following a
 190.572 -     * group, if any, is the first byte of the
 190.573 -     * next group.
 190.574 -     * <p>
 190.575 -     * If the first byte of a group
 190.576 -     * matches the bit pattern <code>0xxxxxxx</code>
 190.577 -     * (where <code>x</code> means "may be <code>0</code>
 190.578 -     * or <code>1</code>"), then the group consists
 190.579 -     * of just that byte. The byte is zero-extended
 190.580 -     * to form a character.
 190.581 -     * <p>
 190.582 -     * If the first byte
 190.583 -     * of a group matches the bit pattern <code>110xxxxx</code>,
 190.584 -     * then the group consists of that byte <code>a</code>
 190.585 -     * and a second byte <code>b</code>. If there
 190.586 -     * is no byte <code>b</code> (because byte
 190.587 -     * <code>a</code> was the last of the bytes
 190.588 -     * to be read), or if byte <code>b</code> does
 190.589 -     * not match the bit pattern <code>10xxxxxx</code>,
 190.590 -     * then a <code>UTFDataFormatException</code>
 190.591 -     * is thrown. Otherwise, the group is converted
 190.592 -     * to the character:<p>
 190.593 -     * <pre><code>(char)(((a&amp; 0x1F) &lt;&lt; 6) | (b &amp; 0x3F))
 190.594 -     * </code></pre>
 190.595 -     * If the first byte of a group
 190.596 -     * matches the bit pattern <code>1110xxxx</code>,
 190.597 -     * then the group consists of that byte <code>a</code>
 190.598 -     * and two more bytes <code>b</code> and <code>c</code>.
 190.599 -     * If there is no byte <code>c</code> (because
 190.600 -     * byte <code>a</code> was one of the last
 190.601 -     * two of the bytes to be read), or either
 190.602 -     * byte <code>b</code> or byte <code>c</code>
 190.603 -     * does not match the bit pattern <code>10xxxxxx</code>,
 190.604 -     * then a <code>UTFDataFormatException</code>
 190.605 -     * is thrown. Otherwise, the group is converted
 190.606 -     * to the character:<p>
 190.607 -     * <pre><code>
 190.608 -     * (char)(((a &amp; 0x0F) &lt;&lt; 12) | ((b &amp; 0x3F) &lt;&lt; 6) | (c &amp; 0x3F))
 190.609 -     * </code></pre>
 190.610 -     * If the first byte of a group matches the
 190.611 -     * pattern <code>1111xxxx</code> or the pattern
 190.612 -     * <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code>
 190.613 -     * is thrown.
 190.614 -     * <p>
 190.615 -     * If end of file is encountered
 190.616 -     * at any time during this entire process,
 190.617 -     * then an <code>EOFException</code> is thrown.
 190.618 -     * <p>
 190.619 -     * After every group has been converted to
 190.620 -     * a character by this process, the characters
 190.621 -     * are gathered, in the same order in which
 190.622 -     * their corresponding groups were read from
 190.623 -     * the input stream, to form a <code>String</code>,
 190.624 -     * which is returned.
 190.625 -     * <p>
 190.626 -     * The <code>writeUTF</code>
 190.627 -     * method of interface <code>DataOutput</code>
 190.628 -     * may be used to write data that is suitable
 190.629 -     * for reading by this method.
 190.630 -     * @return     a Unicode string.
 190.631 -     * @exception  EOFException            if this stream reaches the end
 190.632 -     *               before reading all the bytes.
 190.633 -     * @exception  IOException             if an I/O error occurs.
 190.634 -     * @exception  UTFDataFormatException  if the bytes do not represent a
 190.635 -     *               valid modified UTF-8 encoding of a string.
 190.636 -     */
 190.637 -    String readUTF() throws IOException;
 190.638 -}
   191.1 --- a/emul/src/main/java/java/io/DataInputStream.java	Wed Dec 05 10:03:58 2012 +0100
   191.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   191.3 @@ -1,704 +0,0 @@
   191.4 -/*
   191.5 - * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
   191.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   191.7 - *
   191.8 - * This code is free software; you can redistribute it and/or modify it
   191.9 - * under the terms of the GNU General Public License version 2 only, as
  191.10 - * published by the Free Software Foundation.  Oracle designates this
  191.11 - * particular file as subject to the "Classpath" exception as provided
  191.12 - * by Oracle in the LICENSE file that accompanied this code.
  191.13 - *
  191.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  191.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  191.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  191.17 - * version 2 for more details (a copy is included in the LICENSE file that
  191.18 - * accompanied this code).
  191.19 - *
  191.20 - * You should have received a copy of the GNU General Public License version
  191.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  191.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  191.23 - *
  191.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  191.25 - * or visit www.oracle.com if you need additional information or have any
  191.26 - * questions.
  191.27 - */
  191.28 -
  191.29 -package java.io;
  191.30 -
  191.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  191.32 -
  191.33 -/**
  191.34 - * A data input stream lets an application read primitive Java data
  191.35 - * types from an underlying input stream in a machine-independent
  191.36 - * way. An application uses a data output stream to write data that
  191.37 - * can later be read by a data input stream.
  191.38 - * <p>
  191.39 - * DataInputStream is not necessarily safe for multithreaded access.
  191.40 - * Thread safety is optional and is the responsibility of users of
  191.41 - * methods in this class.
  191.42 - *
  191.43 - * @author  Arthur van Hoff
  191.44 - * @see     java.io.DataOutputStream
  191.45 - * @since   JDK1.0
  191.46 - */
  191.47 -public
  191.48 -class DataInputStream extends FilterInputStream implements DataInput {
  191.49 -
  191.50 -    /**
  191.51 -     * Creates a DataInputStream that uses the specified
  191.52 -     * underlying InputStream.
  191.53 -     *
  191.54 -     * @param  in   the specified input stream
  191.55 -     */
  191.56 -    public DataInputStream(InputStream in) {
  191.57 -        super(in);
  191.58 -    }
  191.59 -
  191.60 -    /**
  191.61 -     * working arrays initialized on demand by readUTF
  191.62 -     */
  191.63 -    private byte bytearr[] = new byte[80];
  191.64 -    private char chararr[] = new char[80];
  191.65 -
  191.66 -    /**
  191.67 -     * Reads some number of bytes from the contained input stream and
  191.68 -     * stores them into the buffer array <code>b</code>. The number of
  191.69 -     * bytes actually read is returned as an integer. This method blocks
  191.70 -     * until input data is available, end of file is detected, or an
  191.71 -     * exception is thrown.
  191.72 -     *
  191.73 -     * <p>If <code>b</code> is null, a <code>NullPointerException</code> is
  191.74 -     * thrown. If the length of <code>b</code> is zero, then no bytes are
  191.75 -     * read and <code>0</code> is returned; otherwise, there is an attempt
  191.76 -     * to read at least one byte. If no byte is available because the
  191.77 -     * stream is at end of file, the value <code>-1</code> is returned;
  191.78 -     * otherwise, at least one byte is read and stored into <code>b</code>.
  191.79 -     *
  191.80 -     * <p>The first byte read is stored into element <code>b[0]</code>, the
  191.81 -     * next one into <code>b[1]</code>, and so on. The number of bytes read
  191.82 -     * is, at most, equal to the length of <code>b</code>. Let <code>k</code>
  191.83 -     * be the number of bytes actually read; these bytes will be stored in
  191.84 -     * elements <code>b[0]</code> through <code>b[k-1]</code>, leaving
  191.85 -     * elements <code>b[k]</code> through <code>b[b.length-1]</code>
  191.86 -     * unaffected.
  191.87 -     *
  191.88 -     * <p>The <code>read(b)</code> method has the same effect as:
  191.89 -     * <blockquote><pre>
  191.90 -     * read(b, 0, b.length)
  191.91 -     * </pre></blockquote>
  191.92 -     *
  191.93 -     * @param      b   the buffer into which the data is read.
  191.94 -     * @return     the total number of bytes read into the buffer, or
  191.95 -     *             <code>-1</code> if there is no more data because the end
  191.96 -     *             of the stream has been reached.
  191.97 -     * @exception  IOException if the first byte cannot be read for any reason
  191.98 -     * other than end of file, the stream has been closed and the underlying
  191.99 -     * input stream does not support reading after close, or another I/O
 191.100 -     * error occurs.
 191.101 -     * @see        java.io.FilterInputStream#in
 191.102 -     * @see        java.io.InputStream#read(byte[], int, int)
 191.103 -     */
 191.104 -    public final int read(byte b[]) throws IOException {
 191.105 -        return in.read(b, 0, b.length);
 191.106 -    }
 191.107 -
 191.108 -    /**
 191.109 -     * Reads up to <code>len</code> bytes of data from the contained
 191.110 -     * input stream into an array of bytes.  An attempt is made to read
 191.111 -     * as many as <code>len</code> bytes, but a smaller number may be read,
 191.112 -     * possibly zero. The number of bytes actually read is returned as an
 191.113 -     * integer.
 191.114 -     *
 191.115 -     * <p> This method blocks until input data is available, end of file is
 191.116 -     * detected, or an exception is thrown.
 191.117 -     *
 191.118 -     * <p> If <code>len</code> is zero, then no bytes are read and
 191.119 -     * <code>0</code> is returned; otherwise, there is an attempt to read at
 191.120 -     * least one byte. If no byte is available because the stream is at end of
 191.121 -     * file, the value <code>-1</code> is returned; otherwise, at least one
 191.122 -     * byte is read and stored into <code>b</code>.
 191.123 -     *
 191.124 -     * <p> The first byte read is stored into element <code>b[off]</code>, the
 191.125 -     * next one into <code>b[off+1]</code>, and so on. The number of bytes read
 191.126 -     * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
 191.127 -     * bytes actually read; these bytes will be stored in elements
 191.128 -     * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
 191.129 -     * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
 191.130 -     * <code>b[off+len-1]</code> unaffected.
 191.131 -     *
 191.132 -     * <p> In every case, elements <code>b[0]</code> through
 191.133 -     * <code>b[off]</code> and elements <code>b[off+len]</code> through
 191.134 -     * <code>b[b.length-1]</code> are unaffected.
 191.135 -     *
 191.136 -     * @param      b     the buffer into which the data is read.
 191.137 -     * @param off the start offset in the destination array <code>b</code>
 191.138 -     * @param      len   the maximum number of bytes read.
 191.139 -     * @return     the total number of bytes read into the buffer, or
 191.140 -     *             <code>-1</code> if there is no more data because the end
 191.141 -     *             of the stream has been reached.
 191.142 -     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 191.143 -     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 191.144 -     * <code>len</code> is negative, or <code>len</code> is greater than
 191.145 -     * <code>b.length - off</code>
 191.146 -     * @exception  IOException if the first byte cannot be read for any reason
 191.147 -     * other than end of file, the stream has been closed and the underlying
 191.148 -     * input stream does not support reading after close, or another I/O
 191.149 -     * error occurs.
 191.150 -     * @see        java.io.FilterInputStream#in
 191.151 -     * @see        java.io.InputStream#read(byte[], int, int)
 191.152 -     */
 191.153 -    public final int read(byte b[], int off, int len) throws IOException {
 191.154 -        return in.read(b, off, len);
 191.155 -    }
 191.156 -
 191.157 -    /**
 191.158 -     * See the general contract of the <code>readFully</code>
 191.159 -     * method of <code>DataInput</code>.
 191.160 -     * <p>
 191.161 -     * Bytes
 191.162 -     * for this operation are read from the contained
 191.163 -     * input stream.
 191.164 -     *
 191.165 -     * @param      b   the buffer into which the data is read.
 191.166 -     * @exception  EOFException  if this input stream reaches the end before
 191.167 -     *             reading all the bytes.
 191.168 -     * @exception  IOException   the stream has been closed and the contained
 191.169 -     *             input stream does not support reading after close, or
 191.170 -     *             another I/O error occurs.
 191.171 -     * @see        java.io.FilterInputStream#in
 191.172 -     */
 191.173 -    public final void readFully(byte b[]) throws IOException {
 191.174 -        readFully(b, 0, b.length);
 191.175 -    }
 191.176 -
 191.177 -    /**
 191.178 -     * See the general contract of the <code>readFully</code>
 191.179 -     * method of <code>DataInput</code>.
 191.180 -     * <p>
 191.181 -     * Bytes
 191.182 -     * for this operation are read from the contained
 191.183 -     * input stream.
 191.184 -     *
 191.185 -     * @param      b     the buffer into which the data is read.
 191.186 -     * @param      off   the start offset of the data.
 191.187 -     * @param      len   the number of bytes to read.
 191.188 -     * @exception  EOFException  if this input stream reaches the end before
 191.189 -     *               reading all the bytes.
 191.190 -     * @exception  IOException   the stream has been closed and the contained
 191.191 -     *             input stream does not support reading after close, or
 191.192 -     *             another I/O error occurs.
 191.193 -     * @see        java.io.FilterInputStream#in
 191.194 -     */
 191.195 -    public final void readFully(byte b[], int off, int len) throws IOException {
 191.196 -        if (len < 0)
 191.197 -            throw new IndexOutOfBoundsException();
 191.198 -        int n = 0;
 191.199 -        while (n < len) {
 191.200 -            int count = in.read(b, off + n, len - n);
 191.201 -            if (count < 0)
 191.202 -                throw new EOFException();
 191.203 -            n += count;
 191.204 -        }
 191.205 -    }
 191.206 -
 191.207 -    /**
 191.208 -     * See the general contract of the <code>skipBytes</code>
 191.209 -     * method of <code>DataInput</code>.
 191.210 -     * <p>
 191.211 -     * Bytes for this operation are read from the contained
 191.212 -     * input stream.
 191.213 -     *
 191.214 -     * @param      n   the number of bytes to be skipped.
 191.215 -     * @return     the actual number of bytes skipped.
 191.216 -     * @exception  IOException  if the contained input stream does not support
 191.217 -     *             seek, or the stream has been closed and
 191.218 -     *             the contained input stream does not support
 191.219 -     *             reading after close, or another I/O error occurs.
 191.220 -     */
 191.221 -    public final int skipBytes(int n) throws IOException {
 191.222 -        int total = 0;
 191.223 -        int cur = 0;
 191.224 -
 191.225 -        while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
 191.226 -            total += cur;
 191.227 -        }
 191.228 -
 191.229 -        return total;
 191.230 -    }
 191.231 -
 191.232 -    /**
 191.233 -     * See the general contract of the <code>readBoolean</code>
 191.234 -     * method of <code>DataInput</code>.
 191.235 -     * <p>
 191.236 -     * Bytes for this operation are read from the contained
 191.237 -     * input stream.
 191.238 -     *
 191.239 -     * @return     the <code>boolean</code> value read.
 191.240 -     * @exception  EOFException  if this input stream has reached the end.
 191.241 -     * @exception  IOException   the stream has been closed and the contained
 191.242 -     *             input stream does not support reading after close, or
 191.243 -     *             another I/O error occurs.
 191.244 -     * @see        java.io.FilterInputStream#in
 191.245 -     */
 191.246 -    public final boolean readBoolean() throws IOException {
 191.247 -        int ch = in.read();
 191.248 -        if (ch < 0)
 191.249 -            throw new EOFException();
 191.250 -        return (ch != 0);
 191.251 -    }
 191.252 -
 191.253 -    /**
 191.254 -     * See the general contract of the <code>readByte</code>
 191.255 -     * method of <code>DataInput</code>.
 191.256 -     * <p>
 191.257 -     * Bytes
 191.258 -     * for this operation are read from the contained
 191.259 -     * input stream.
 191.260 -     *
 191.261 -     * @return     the next byte of this input stream as a signed 8-bit
 191.262 -     *             <code>byte</code>.
 191.263 -     * @exception  EOFException  if this input stream has reached the end.
 191.264 -     * @exception  IOException   the stream has been closed and the contained
 191.265 -     *             input stream does not support reading after close, or
 191.266 -     *             another I/O error occurs.
 191.267 -     * @see        java.io.FilterInputStream#in
 191.268 -     */
 191.269 -    public final byte readByte() throws IOException {
 191.270 -        int ch = in.read();
 191.271 -        if (ch < 0)
 191.272 -            throw new EOFException();
 191.273 -        return (byte)(ch);
 191.274 -    }
 191.275 -
 191.276 -    /**
 191.277 -     * See the general contract of the <code>readUnsignedByte</code>
 191.278 -     * method of <code>DataInput</code>.
 191.279 -     * <p>
 191.280 -     * Bytes
 191.281 -     * for this operation are read from the contained
 191.282 -     * input stream.
 191.283 -     *
 191.284 -     * @return     the next byte of this input stream, interpreted as an
 191.285 -     *             unsigned 8-bit number.
 191.286 -     * @exception  EOFException  if this input stream has reached the end.
 191.287 -     * @exception  IOException   the stream has been closed and the contained
 191.288 -     *             input stream does not support reading after close, or
 191.289 -     *             another I/O error occurs.
 191.290 -     * @see         java.io.FilterInputStream#in
 191.291 -     */
 191.292 -    public final int readUnsignedByte() throws IOException {
 191.293 -        int ch = in.read();
 191.294 -        if (ch < 0)
 191.295 -            throw new EOFException();
 191.296 -        return ch;
 191.297 -    }
 191.298 -
 191.299 -    /**
 191.300 -     * See the general contract of the <code>readShort</code>
 191.301 -     * method of <code>DataInput</code>.
 191.302 -     * <p>
 191.303 -     * Bytes
 191.304 -     * for this operation are read from the contained
 191.305 -     * input stream.
 191.306 -     *
 191.307 -     * @return     the next two bytes of this input stream, interpreted as a
 191.308 -     *             signed 16-bit number.
 191.309 -     * @exception  EOFException  if this input stream reaches the end before
 191.310 -     *               reading two bytes.
 191.311 -     * @exception  IOException   the stream has been closed and the contained
 191.312 -     *             input stream does not support reading after close, or
 191.313 -     *             another I/O error occurs.
 191.314 -     * @see        java.io.FilterInputStream#in
 191.315 -     */
 191.316 -    public final short readShort() throws IOException {
 191.317 -        int ch1 = in.read();
 191.318 -        int ch2 = in.read();
 191.319 -        if ((ch1 | ch2) < 0)
 191.320 -            throw new EOFException();
 191.321 -        return (short)((ch1 << 8) + (ch2 << 0));
 191.322 -    }
 191.323 -
 191.324 -    /**
 191.325 -     * See the general contract of the <code>readUnsignedShort</code>
 191.326 -     * method of <code>DataInput</code>.
 191.327 -     * <p>
 191.328 -     * Bytes
 191.329 -     * for this operation are read from the contained
 191.330 -     * input stream.
 191.331 -     *
 191.332 -     * @return     the next two bytes of this input stream, interpreted as an
 191.333 -     *             unsigned 16-bit integer.
 191.334 -     * @exception  EOFException  if this input stream reaches the end before
 191.335 -     *             reading two bytes.
 191.336 -     * @exception  IOException   the stream has been closed and the contained
 191.337 -     *             input stream does not support reading after close, or
 191.338 -     *             another I/O error occurs.
 191.339 -     * @see        java.io.FilterInputStream#in
 191.340 -     */
 191.341 -    public final int readUnsignedShort() throws IOException {
 191.342 -        int ch1 = in.read();
 191.343 -        int ch2 = in.read();
 191.344 -        if ((ch1 | ch2) < 0)
 191.345 -            throw new EOFException();
 191.346 -        return (ch1 << 8) + (ch2 << 0);
 191.347 -    }
 191.348 -
 191.349 -    /**
 191.350 -     * See the general contract of the <code>readChar</code>
 191.351 -     * method of <code>DataInput</code>.
 191.352 -     * <p>
 191.353 -     * Bytes
 191.354 -     * for this operation are read from the contained
 191.355 -     * input stream.
 191.356 -     *
 191.357 -     * @return     the next two bytes of this input stream, interpreted as a
 191.358 -     *             <code>char</code>.
 191.359 -     * @exception  EOFException  if this input stream reaches the end before
 191.360 -     *               reading two bytes.
 191.361 -     * @exception  IOException   the stream has been closed and the contained
 191.362 -     *             input stream does not support reading after close, or
 191.363 -     *             another I/O error occurs.
 191.364 -     * @see        java.io.FilterInputStream#in
 191.365 -     */
 191.366 -    public final char readChar() throws IOException {
 191.367 -        int ch1 = in.read();
 191.368 -        int ch2 = in.read();
 191.369 -        if ((ch1 | ch2) < 0)
 191.370 -            throw new EOFException();
 191.371 -        return (char)((ch1 << 8) + (ch2 << 0));
 191.372 -    }
 191.373 -
 191.374 -    /**
 191.375 -     * See the general contract of the <code>readInt</code>
 191.376 -     * method of <code>DataInput</code>.
 191.377 -     * <p>
 191.378 -     * Bytes
 191.379 -     * for this operation are read from the contained
 191.380 -     * input stream.
 191.381 -     *
 191.382 -     * @return     the next four bytes of this input stream, interpreted as an
 191.383 -     *             <code>int</code>.
 191.384 -     * @exception  EOFException  if this input stream reaches the end before
 191.385 -     *               reading four bytes.
 191.386 -     * @exception  IOException   the stream has been closed and the contained
 191.387 -     *             input stream does not support reading after close, or
 191.388 -     *             another I/O error occurs.
 191.389 -     * @see        java.io.FilterInputStream#in
 191.390 -     */
 191.391 -    public final int readInt() throws IOException {
 191.392 -        int ch1 = in.read();
 191.393 -        int ch2 = in.read();
 191.394 -        int ch3 = in.read();
 191.395 -        int ch4 = in.read();
 191.396 -        if ((ch1 | ch2 | ch3 | ch4) < 0)
 191.397 -            throw new EOFException();
 191.398 -        return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
 191.399 -    }
 191.400 -
 191.401 -    private byte readBuffer[] = new byte[8];
 191.402 -
 191.403 -    /**
 191.404 -     * See the general contract of the <code>readLong</code>
 191.405 -     * method of <code>DataInput</code>.
 191.406 -     * <p>
 191.407 -     * Bytes
 191.408 -     * for this operation are read from the contained
 191.409 -     * input stream.
 191.410 -     *
 191.411 -     * @return     the next eight bytes of this input stream, interpreted as a
 191.412 -     *             <code>long</code>.
 191.413 -     * @exception  EOFException  if this input stream reaches the end before
 191.414 -     *               reading eight bytes.
 191.415 -     * @exception  IOException   the stream has been closed and the contained
 191.416 -     *             input stream does not support reading after close, or
 191.417 -     *             another I/O error occurs.
 191.418 -     * @see        java.io.FilterInputStream#in
 191.419 -     */
 191.420 -    public final long readLong() throws IOException {
 191.421 -        readFully(readBuffer, 0, 8);
 191.422 -        return (((long)readBuffer[0] << 56) +
 191.423 -                ((long)(readBuffer[1] & 255) << 48) +
 191.424 -                ((long)(readBuffer[2] & 255) << 40) +
 191.425 -                ((long)(readBuffer[3] & 255) << 32) +
 191.426 -                ((long)(readBuffer[4] & 255) << 24) +
 191.427 -                ((readBuffer[5] & 255) << 16) +
 191.428 -                ((readBuffer[6] & 255) <<  8) +
 191.429 -                ((readBuffer[7] & 255) <<  0));
 191.430 -    }
 191.431 -
 191.432 -    /**
 191.433 -     * See the general contract of the <code>readFloat</code>
 191.434 -     * method of <code>DataInput</code>.
 191.435 -     * <p>
 191.436 -     * Bytes
 191.437 -     * for this operation are read from the contained
 191.438 -     * input stream.
 191.439 -     *
 191.440 -     * @return     the next four bytes of this input stream, interpreted as a
 191.441 -     *             <code>float</code>.
 191.442 -     * @exception  EOFException  if this input stream reaches the end before
 191.443 -     *               reading four bytes.
 191.444 -     * @exception  IOException   the stream has been closed and the contained
 191.445 -     *             input stream does not support reading after close, or
 191.446 -     *             another I/O error occurs.
 191.447 -     * @see        java.io.DataInputStream#readInt()
 191.448 -     * @see        java.lang.Float#intBitsToFloat(int)
 191.449 -     */
 191.450 -    public final float readFloat() throws IOException {
 191.451 -        return Float.intBitsToFloat(readInt());
 191.452 -    }
 191.453 -
 191.454 -    /**
 191.455 -     * See the general contract of the <code>readDouble</code>
 191.456 -     * method of <code>DataInput</code>.
 191.457 -     * <p>
 191.458 -     * Bytes
 191.459 -     * for this operation are read from the contained
 191.460 -     * input stream.
 191.461 -     *
 191.462 -     * @return     the next eight bytes of this input stream, interpreted as a
 191.463 -     *             <code>double</code>.
 191.464 -     * @exception  EOFException  if this input stream reaches the end before
 191.465 -     *               reading eight bytes.
 191.466 -     * @exception  IOException   the stream has been closed and the contained
 191.467 -     *             input stream does not support reading after close, or
 191.468 -     *             another I/O error occurs.
 191.469 -     * @see        java.io.DataInputStream#readLong()
 191.470 -     * @see        java.lang.Double#longBitsToDouble(long)
 191.471 -     */
 191.472 -    public final double readDouble() throws IOException {
 191.473 -        int hi = readInt();
 191.474 -        int low = readInt();
 191.475 -        return toDouble(hi, low);
 191.476 -    }
 191.477 -    
 191.478 -    @JavaScriptBody(args={ "hi", "low" },
 191.479 -        body=
 191.480 -          "if (low == 0) {\n"
 191.481 -        + "  if (hi === 0x7ff00000) return Number.POSITIVE_INFINITY;\n"
 191.482 -        + "  if (hi === 0xfff00000) return Number.NEGATIVE_INFINITY;\n"
 191.483 -        + "}\n"
 191.484 -        + "if (hi >= 0x7ff00000 && hi <= 0x7fffffff) return Number.NaN;\n"
 191.485 -        + "if (hi >= 0xfff00000 && hi <= 0xffffffff) return Number.NaN;\n"
 191.486 -        + "var s = (hi & 0x80000000) === 0 ? 1 : -1;\n"
 191.487 -        + "var e = (hi >> 20) & 0x7ff;\n"
 191.488 -        + "var to32 = low >> 0;\n"
 191.489 -        + "if (e === 0) {\n"
 191.490 -        + "  if (to32 & 0x80000000) {\n"
 191.491 -        + "    hi = hi << 1 + 1; low = low << 1;\n"
 191.492 -        + "  } else {\n"
 191.493 -        + "    hi = hi << 1; low = low << 1;\n"
 191.494 -        + "  }\n" 
 191.495 -        + "} else {\n"
 191.496 -        + "    hi = (hi & 0xfffff) | 0x100000;\n"
 191.497 -        + "}\n"
 191.498 -        + "to32 = low >> 0;\n"
 191.499 -        + "var m = Math.pow(2.0, 32) * hi + to32;\n"
 191.500 -        + "var r = s * m * Math.pow(2.0, e - 1075);\n"
 191.501 -        + "//throw 'exp: ' + e + ' sign: ' + s + ' hi:' + hi + ' low: ' + low + ' m: ' + m + ' r: ' + r;\n"
 191.502 -        + "return r;\n"
 191.503 -    )
 191.504 -    private static double toDouble(int hi, int low) {
 191.505 -        long both = hi;
 191.506 -        both = (both << 32) & low;
 191.507 -        return Double.doubleToLongBits(both);
 191.508 -    }
 191.509 -
 191.510 -    private char lineBuffer[];
 191.511 -
 191.512 -    /**
 191.513 -     * See the general contract of the <code>readLine</code>
 191.514 -     * method of <code>DataInput</code>.
 191.515 -     * <p>
 191.516 -     * Bytes
 191.517 -     * for this operation are read from the contained
 191.518 -     * input stream.
 191.519 -     *
 191.520 -     * @deprecated This method does not properly convert bytes to characters.
 191.521 -     * As of JDK&nbsp;1.1, the preferred way to read lines of text is via the
 191.522 -     * <code>BufferedReader.readLine()</code> method.  Programs that use the
 191.523 -     * <code>DataInputStream</code> class to read lines can be converted to use
 191.524 -     * the <code>BufferedReader</code> class by replacing code of the form:
 191.525 -     * <blockquote><pre>
 191.526 -     *     DataInputStream d =&nbsp;new&nbsp;DataInputStream(in);
 191.527 -     * </pre></blockquote>
 191.528 -     * with:
 191.529 -     * <blockquote><pre>
 191.530 -     *     BufferedReader d
 191.531 -     *          =&nbsp;new&nbsp;BufferedReader(new&nbsp;InputStreamReader(in));
 191.532 -     * </pre></blockquote>
 191.533 -     *
 191.534 -     * @return     the next line of text from this input stream.
 191.535 -     * @exception  IOException  if an I/O error occurs.
 191.536 -     * @see        java.io.BufferedReader#readLine()
 191.537 -     * @see        java.io.FilterInputStream#in
 191.538 -     */
 191.539 -    @Deprecated
 191.540 -    public final String readLine() throws IOException {
 191.541 -        char buf[] = lineBuffer;
 191.542 -
 191.543 -        if (buf == null) {
 191.544 -            buf = lineBuffer = new char[128];
 191.545 -        }
 191.546 -
 191.547 -        int room = buf.length;
 191.548 -        int offset = 0;
 191.549 -        int c;
 191.550 -
 191.551 -loop:   while (true) {
 191.552 -            switch (c = in.read()) {
 191.553 -              case -1:
 191.554 -              case '\n':
 191.555 -                break loop;
 191.556 -
 191.557 -              case '\r':
 191.558 -                int c2 = in.read();
 191.559 -                if ((c2 != '\n') && (c2 != -1)) {
 191.560 -                    if (!(in instanceof PushbackInputStream)) {
 191.561 -                        this.in = new PushbackInputStream(in);
 191.562 -                    }
 191.563 -                    ((PushbackInputStream)in).unread(c2);
 191.564 -                }
 191.565 -                break loop;
 191.566 -
 191.567 -              default:
 191.568 -                if (--room < 0) {
 191.569 -                    buf = new char[offset + 128];
 191.570 -                    room = buf.length - offset - 1;
 191.571 -                    arraycopy(lineBuffer, 0, buf, 0, offset);
 191.572 -                    lineBuffer = buf;
 191.573 -                }
 191.574 -                buf[offset++] = (char) c;
 191.575 -                break;
 191.576 -            }
 191.577 -        }
 191.578 -        if ((c == -1) && (offset == 0)) {
 191.579 -            return null;
 191.580 -        }
 191.581 -        return String.copyValueOf(buf, 0, offset);
 191.582 -    }
 191.583 -
 191.584 -    /**
 191.585 -     * See the general contract of the <code>readUTF</code>
 191.586 -     * method of <code>DataInput</code>.
 191.587 -     * <p>
 191.588 -     * Bytes
 191.589 -     * for this operation are read from the contained
 191.590 -     * input stream.
 191.591 -     *
 191.592 -     * @return     a Unicode string.
 191.593 -     * @exception  EOFException  if this input stream reaches the end before
 191.594 -     *               reading all the bytes.
 191.595 -     * @exception  IOException   the stream has been closed and the contained
 191.596 -     *             input stream does not support reading after close, or
 191.597 -     *             another I/O error occurs.
 191.598 -     * @exception  UTFDataFormatException if the bytes do not represent a valid
 191.599 -     *             modified UTF-8 encoding of a string.
 191.600 -     * @see        java.io.DataInputStream#readUTF(java.io.DataInput)
 191.601 -     */
 191.602 -    public final String readUTF() throws IOException {
 191.603 -        return readUTF(this);
 191.604 -    }
 191.605 -
 191.606 -    /**
 191.607 -     * Reads from the
 191.608 -     * stream <code>in</code> a representation
 191.609 -     * of a Unicode  character string encoded in
 191.610 -     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
 191.611 -     * this string of characters is then returned as a <code>String</code>.
 191.612 -     * The details of the modified UTF-8 representation
 191.613 -     * are  exactly the same as for the <code>readUTF</code>
 191.614 -     * method of <code>DataInput</code>.
 191.615 -     *
 191.616 -     * @param      in   a data input stream.
 191.617 -     * @return     a Unicode string.
 191.618 -     * @exception  EOFException            if the input stream reaches the end
 191.619 -     *               before all the bytes.
 191.620 -     * @exception  IOException   the stream has been closed and the contained
 191.621 -     *             input stream does not support reading after close, or
 191.622 -     *             another I/O error occurs.
 191.623 -     * @exception  UTFDataFormatException  if the bytes do not represent a
 191.624 -     *               valid modified UTF-8 encoding of a Unicode string.
 191.625 -     * @see        java.io.DataInputStream#readUnsignedShort()
 191.626 -     */
 191.627 -    public final static String readUTF(DataInput in) throws IOException {
 191.628 -        int utflen = in.readUnsignedShort();
 191.629 -        byte[] bytearr = null;
 191.630 -        char[] chararr = null;
 191.631 -        if (in instanceof DataInputStream) {
 191.632 -            DataInputStream dis = (DataInputStream)in;
 191.633 -            if (dis.bytearr.length < utflen){
 191.634 -                dis.bytearr = new byte[utflen*2];
 191.635 -                dis.chararr = new char[utflen*2];
 191.636 -            }
 191.637 -            chararr = dis.chararr;
 191.638 -            bytearr = dis.bytearr;
 191.639 -        } else {
 191.640 -            bytearr = new byte[utflen];
 191.641 -            chararr = new char[utflen];
 191.642 -        }
 191.643 -
 191.644 -        int c, char2, char3;
 191.645 -        int count = 0;
 191.646 -        int chararr_count=0;
 191.647 -
 191.648 -        in.readFully(bytearr, 0, utflen);
 191.649 -
 191.650 -        while (count < utflen) {
 191.651 -            c = (int) bytearr[count] & 0xff;
 191.652 -            if (c > 127) break;
 191.653 -            count++;
 191.654 -            chararr[chararr_count++]=(char)c;
 191.655 -        }
 191.656 -
 191.657 -        while (count < utflen) {
 191.658 -            c = (int) bytearr[count] & 0xff;
 191.659 -            switch (c >> 4) {
 191.660 -                case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
 191.661 -                    /* 0xxxxxxx*/
 191.662 -                    count++;
 191.663 -                    chararr[chararr_count++]=(char)c;
 191.664 -                    break;
 191.665 -                case 12: case 13:
 191.666 -                    /* 110x xxxx   10xx xxxx*/
 191.667 -                    count += 2;
 191.668 -                    if (count > utflen)
 191.669 -                        throw new UTFDataFormatException(
 191.670 -                            "malformed input: partial character at end");
 191.671 -                    char2 = (int) bytearr[count-1];
 191.672 -                    if ((char2 & 0xC0) != 0x80)
 191.673 -                        throw new UTFDataFormatException(
 191.674 -                            "malformed input around byte " + count);
 191.675 -                    chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
 191.676 -                                                    (char2 & 0x3F));
 191.677 -                    break;
 191.678 -                case 14:
 191.679 -                    /* 1110 xxxx  10xx xxxx  10xx xxxx */
 191.680 -                    count += 3;
 191.681 -                    if (count > utflen)
 191.682 -                        throw new UTFDataFormatException(
 191.683 -                            "malformed input: partial character at end");
 191.684 -                    char2 = (int) bytearr[count-2];
 191.685 -                    char3 = (int) bytearr[count-1];
 191.686 -                    if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
 191.687 -                        throw new UTFDataFormatException(
 191.688 -                            "malformed input around byte " + (count-1));
 191.689 -                    chararr[chararr_count++]=(char)(((c     & 0x0F) << 12) |
 191.690 -                                                    ((char2 & 0x3F) << 6)  |
 191.691 -                                                    ((char3 & 0x3F) << 0));
 191.692 -                    break;
 191.693 -                default:
 191.694 -                    /* 10xx xxxx,  1111 xxxx */
 191.695 -                    throw new UTFDataFormatException(
 191.696 -                        "malformed input around byte " + count);
 191.697 -            }
 191.698 -        }
 191.699 -        // The number of chars produced may be less than utflen
 191.700 -        return new String(chararr, 0, chararr_count);
 191.701 -    }
 191.702 -    static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
 191.703 -        while (count-- > 0) {
 191.704 -            dst[dstBegin++] = value[srcBegin++];
 191.705 -        }
 191.706 -    }
 191.707 -}
   192.1 --- a/emul/src/main/java/java/io/EOFException.java	Wed Dec 05 10:03:58 2012 +0100
   192.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   192.3 @@ -1,65 +0,0 @@
   192.4 -/*
   192.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   192.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   192.7 - *
   192.8 - * This code is free software; you can redistribute it and/or modify it
   192.9 - * under the terms of the GNU General Public License version 2 only, as
  192.10 - * published by the Free Software Foundation.  Oracle designates this
  192.11 - * particular file as subject to the "Classpath" exception as provided
  192.12 - * by Oracle in the LICENSE file that accompanied this code.
  192.13 - *
  192.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  192.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  192.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  192.17 - * version 2 for more details (a copy is included in the LICENSE file that
  192.18 - * accompanied this code).
  192.19 - *
  192.20 - * You should have received a copy of the GNU General Public License version
  192.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  192.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  192.23 - *
  192.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  192.25 - * or visit www.oracle.com if you need additional information or have any
  192.26 - * questions.
  192.27 - */
  192.28 -
  192.29 -package java.io;
  192.30 -
  192.31 -/**
  192.32 - * Signals that an end of file or end of stream has been reached
  192.33 - * unexpectedly during input.
  192.34 - * <p>
  192.35 - * This exception is mainly used by data input streams to signal end of
  192.36 - * stream. Note that many other input operations return a special value on
  192.37 - * end of stream rather than throwing an exception.
  192.38 - * <p>
  192.39 - *
  192.40 - * @author  Frank Yellin
  192.41 - * @see     java.io.DataInputStream
  192.42 - * @see     java.io.IOException
  192.43 - * @since   JDK1.0
  192.44 - */
  192.45 -public
  192.46 -class EOFException extends IOException {
  192.47 -    private static final long serialVersionUID = 6433858223774886977L;
  192.48 -
  192.49 -    /**
  192.50 -     * Constructs an <code>EOFException</code> with <code>null</code>
  192.51 -     * as its error detail message.
  192.52 -     */
  192.53 -    public EOFException() {
  192.54 -        super();
  192.55 -    }
  192.56 -
  192.57 -    /**
  192.58 -     * Constructs an <code>EOFException</code> with the specified detail
  192.59 -     * message. The string <code>s</code> may later be retrieved by the
  192.60 -     * <code>{@link java.lang.Throwable#getMessage}</code> method of class
  192.61 -     * <code>java.lang.Throwable</code>.
  192.62 -     *
  192.63 -     * @param   s   the detail message.
  192.64 -     */
  192.65 -    public EOFException(String s) {
  192.66 -        super(s);
  192.67 -    }
  192.68 -}
   193.1 --- a/emul/src/main/java/java/io/FilterInputStream.java	Wed Dec 05 10:03:58 2012 +0100
   193.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   193.3 @@ -1,245 +0,0 @@
   193.4 -/*
   193.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   193.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   193.7 - *
   193.8 - * This code is free software; you can redistribute it and/or modify it
   193.9 - * under the terms of the GNU General Public License version 2 only, as
  193.10 - * published by the Free Software Foundation.  Oracle designates this
  193.11 - * particular file as subject to the "Classpath" exception as provided
  193.12 - * by Oracle in the LICENSE file that accompanied this code.
  193.13 - *
  193.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  193.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  193.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  193.17 - * version 2 for more details (a copy is included in the LICENSE file that
  193.18 - * accompanied this code).
  193.19 - *
  193.20 - * You should have received a copy of the GNU General Public License version
  193.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  193.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  193.23 - *
  193.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  193.25 - * or visit www.oracle.com if you need additional information or have any
  193.26 - * questions.
  193.27 - */
  193.28 -
  193.29 -package java.io;
  193.30 -
  193.31 -/**
  193.32 - * A <code>FilterInputStream</code> contains
  193.33 - * some other input stream, which it uses as
  193.34 - * its  basic source of data, possibly transforming
  193.35 - * the data along the way or providing  additional
  193.36 - * functionality. The class <code>FilterInputStream</code>
  193.37 - * itself simply overrides all  methods of
  193.38 - * <code>InputStream</code> with versions that
  193.39 - * pass all requests to the contained  input
  193.40 - * stream. Subclasses of <code>FilterInputStream</code>
  193.41 - * may further override some of  these methods
  193.42 - * and may also provide additional methods
  193.43 - * and fields.
  193.44 - *
  193.45 - * @author  Jonathan Payne
  193.46 - * @since   JDK1.0
  193.47 - */
  193.48 -public
  193.49 -class FilterInputStream extends InputStream {
  193.50 -    /**
  193.51 -     * The input stream to be filtered.
  193.52 -     */
  193.53 -    protected volatile InputStream in;
  193.54 -
  193.55 -    /**
  193.56 -     * Creates a <code>FilterInputStream</code>
  193.57 -     * by assigning the  argument <code>in</code>
  193.58 -     * to the field <code>this.in</code> so as
  193.59 -     * to remember it for later use.
  193.60 -     *
  193.61 -     * @param   in   the underlying input stream, or <code>null</code> if
  193.62 -     *          this instance is to be created without an underlying stream.
  193.63 -     */
  193.64 -    protected FilterInputStream(InputStream in) {
  193.65 -        this.in = in;
  193.66 -    }
  193.67 -
  193.68 -    /**
  193.69 -     * Reads the next byte of data from this input stream. The value
  193.70 -     * byte is returned as an <code>int</code> in the range
  193.71 -     * <code>0</code> to <code>255</code>. If no byte is available
  193.72 -     * because the end of the stream has been reached, the value
  193.73 -     * <code>-1</code> is returned. This method blocks until input data
  193.74 -     * is available, the end of the stream is detected, or an exception
  193.75 -     * is thrown.
  193.76 -     * <p>
  193.77 -     * This method
  193.78 -     * simply performs <code>in.read()</code> and returns the result.
  193.79 -     *
  193.80 -     * @return     the next byte of data, or <code>-1</code> if the end of the
  193.81 -     *             stream is reached.
  193.82 -     * @exception  IOException  if an I/O error occurs.
  193.83 -     * @see        java.io.FilterInputStream#in
  193.84 -     */
  193.85 -    public int read() throws IOException {
  193.86 -        return in.read();
  193.87 -    }
  193.88 -
  193.89 -    /**
  193.90 -     * Reads up to <code>byte.length</code> bytes of data from this
  193.91 -     * input stream into an array of bytes. This method blocks until some
  193.92 -     * input is available.
  193.93 -     * <p>
  193.94 -     * This method simply performs the call
  193.95 -     * <code>read(b, 0, b.length)</code> and returns
  193.96 -     * the  result. It is important that it does
  193.97 -     * <i>not</i> do <code>in.read(b)</code> instead;
  193.98 -     * certain subclasses of  <code>FilterInputStream</code>
  193.99 -     * depend on the implementation strategy actually
 193.100 -     * used.
 193.101 -     *
 193.102 -     * @param      b   the buffer into which the data is read.
 193.103 -     * @return     the total number of bytes read into the buffer, or
 193.104 -     *             <code>-1</code> if there is no more data because the end of
 193.105 -     *             the stream has been reached.
 193.106 -     * @exception  IOException  if an I/O error occurs.
 193.107 -     * @see        java.io.FilterInputStream#read(byte[], int, int)
 193.108 -     */
 193.109 -    public int read(byte b[]) throws IOException {
 193.110 -        return read(b, 0, b.length);
 193.111 -    }
 193.112 -
 193.113 -    /**
 193.114 -     * Reads up to <code>len</code> bytes of data from this input stream
 193.115 -     * into an array of bytes. If <code>len</code> is not zero, the method
 193.116 -     * blocks until some input is available; otherwise, no
 193.117 -     * bytes are read and <code>0</code> is returned.
 193.118 -     * <p>
 193.119 -     * This method simply performs <code>in.read(b, off, len)</code>
 193.120 -     * and returns the result.
 193.121 -     *
 193.122 -     * @param      b     the buffer into which the data is read.
 193.123 -     * @param      off   the start offset in the destination array <code>b</code>
 193.124 -     * @param      len   the maximum number of bytes read.
 193.125 -     * @return     the total number of bytes read into the buffer, or
 193.126 -     *             <code>-1</code> if there is no more data because the end of
 193.127 -     *             the stream has been reached.
 193.128 -     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 193.129 -     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 193.130 -     * <code>len</code> is negative, or <code>len</code> is greater than
 193.131 -     * <code>b.length - off</code>
 193.132 -     * @exception  IOException  if an I/O error occurs.
 193.133 -     * @see        java.io.FilterInputStream#in
 193.134 -     */
 193.135 -    public int read(byte b[], int off, int len) throws IOException {
 193.136 -        return in.read(b, off, len);
 193.137 -    }
 193.138 -
 193.139 -    /**
 193.140 -     * Skips over and discards <code>n</code> bytes of data from the
 193.141 -     * input stream. The <code>skip</code> method may, for a variety of
 193.142 -     * reasons, end up skipping over some smaller number of bytes,
 193.143 -     * possibly <code>0</code>. The actual number of bytes skipped is
 193.144 -     * returned.
 193.145 -     * <p>
 193.146 -     * This method simply performs <code>in.skip(n)</code>.
 193.147 -     *
 193.148 -     * @param      n   the number of bytes to be skipped.
 193.149 -     * @return     the actual number of bytes skipped.
 193.150 -     * @exception  IOException  if the stream does not support seek,
 193.151 -     *                          or if some other I/O error occurs.
 193.152 -     */
 193.153 -    public long skip(long n) throws IOException {
 193.154 -        return in.skip(n);
 193.155 -    }
 193.156 -
 193.157 -    /**
 193.158 -     * Returns an estimate of the number of bytes that can be read (or
 193.159 -     * skipped over) from this input stream without blocking by the next
 193.160 -     * caller of a method for this input stream. The next caller might be
 193.161 -     * the same thread or another thread.  A single read or skip of this
 193.162 -     * many bytes will not block, but may read or skip fewer bytes.
 193.163 -     * <p>
 193.164 -     * This method returns the result of {@link #in in}.available().
 193.165 -     *
 193.166 -     * @return     an estimate of the number of bytes that can be read (or skipped
 193.167 -     *             over) from this input stream without blocking.
 193.168 -     * @exception  IOException  if an I/O error occurs.
 193.169 -     */
 193.170 -    public int available() throws IOException {
 193.171 -        return in.available();
 193.172 -    }
 193.173 -
 193.174 -    /**
 193.175 -     * Closes this input stream and releases any system resources
 193.176 -     * associated with the stream.
 193.177 -     * This
 193.178 -     * method simply performs <code>in.close()</code>.
 193.179 -     *
 193.180 -     * @exception  IOException  if an I/O error occurs.
 193.181 -     * @see        java.io.FilterInputStream#in
 193.182 -     */
 193.183 -    public void close() throws IOException {
 193.184 -        in.close();
 193.185 -    }
 193.186 -
 193.187 -    /**
 193.188 -     * Marks the current position in this input stream. A subsequent
 193.189 -     * call to the <code>reset</code> method repositions this stream at
 193.190 -     * the last marked position so that subsequent reads re-read the same bytes.
 193.191 -     * <p>
 193.192 -     * The <code>readlimit</code> argument tells this input stream to
 193.193 -     * allow that many bytes to be read before the mark position gets
 193.194 -     * invalidated.
 193.195 -     * <p>
 193.196 -     * This method simply performs <code>in.mark(readlimit)</code>.
 193.197 -     *
 193.198 -     * @param   readlimit   the maximum limit of bytes that can be read before
 193.199 -     *                      the mark position becomes invalid.
 193.200 -     * @see     java.io.FilterInputStream#in
 193.201 -     * @see     java.io.FilterInputStream#reset()
 193.202 -     */
 193.203 -    public synchronized void mark(int readlimit) {
 193.204 -        in.mark(readlimit);
 193.205 -    }
 193.206 -
 193.207 -    /**
 193.208 -     * Repositions this stream to the position at the time the
 193.209 -     * <code>mark</code> method was last called on this input stream.
 193.210 -     * <p>
 193.211 -     * This method
 193.212 -     * simply performs <code>in.reset()</code>.
 193.213 -     * <p>
 193.214 -     * Stream marks are intended to be used in
 193.215 -     * situations where you need to read ahead a little to see what's in
 193.216 -     * the stream. Often this is most easily done by invoking some
 193.217 -     * general parser. If the stream is of the type handled by the
 193.218 -     * parse, it just chugs along happily. If the stream is not of
 193.219 -     * that type, the parser should toss an exception when it fails.
 193.220 -     * If this happens within readlimit bytes, it allows the outer
 193.221 -     * code to reset the stream and try another parser.
 193.222 -     *
 193.223 -     * @exception  IOException  if the stream has not been marked or if the
 193.224 -     *               mark has been invalidated.
 193.225 -     * @see        java.io.FilterInputStream#in
 193.226 -     * @see        java.io.FilterInputStream#mark(int)
 193.227 -     */
 193.228 -    public synchronized void reset() throws IOException {
 193.229 -        in.reset();
 193.230 -    }
 193.231 -
 193.232 -    /**
 193.233 -     * Tests if this input stream supports the <code>mark</code>
 193.234 -     * and <code>reset</code> methods.
 193.235 -     * This method
 193.236 -     * simply performs <code>in.markSupported()</code>.
 193.237 -     *
 193.238 -     * @return  <code>true</code> if this stream type supports the
 193.239 -     *          <code>mark</code> and <code>reset</code> method;
 193.240 -     *          <code>false</code> otherwise.
 193.241 -     * @see     java.io.FilterInputStream#in
 193.242 -     * @see     java.io.InputStream#mark(int)
 193.243 -     * @see     java.io.InputStream#reset()
 193.244 -     */
 193.245 -    public boolean markSupported() {
 193.246 -        return in.markSupported();
 193.247 -    }
 193.248 -}
   194.1 --- a/emul/src/main/java/java/io/IOException.java	Wed Dec 05 10:03:58 2012 +0100
   194.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   194.3 @@ -1,101 +0,0 @@
   194.4 -/*
   194.5 - * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
   194.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   194.7 - *
   194.8 - * This code is free software; you can redistribute it and/or modify it
   194.9 - * under the terms of the GNU General Public License version 2 only, as
  194.10 - * published by the Free Software Foundation.  Oracle designates this
  194.11 - * particular file as subject to the "Classpath" exception as provided
  194.12 - * by Oracle in the LICENSE file that accompanied this code.
  194.13 - *
  194.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  194.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  194.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  194.17 - * version 2 for more details (a copy is included in the LICENSE file that
  194.18 - * accompanied this code).
  194.19 - *
  194.20 - * You should have received a copy of the GNU General Public License version
  194.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  194.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  194.23 - *
  194.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  194.25 - * or visit www.oracle.com if you need additional information or have any
  194.26 - * questions.
  194.27 - */
  194.28 -
  194.29 -package java.io;
  194.30 -
  194.31 -/**
  194.32 - * Signals that an I/O exception of some sort has occurred. This
  194.33 - * class is the general class of exceptions produced by failed or
  194.34 - * interrupted I/O operations.
  194.35 - *
  194.36 - * @author  unascribed
  194.37 - * @see     java.io.InputStream
  194.38 - * @see     java.io.OutputStream
  194.39 - * @since   JDK1.0
  194.40 - */
  194.41 -public
  194.42 -class IOException extends Exception {
  194.43 -    static final long serialVersionUID = 7818375828146090155L;
  194.44 -
  194.45 -    /**
  194.46 -     * Constructs an {@code IOException} with {@code null}
  194.47 -     * as its error detail message.
  194.48 -     */
  194.49 -    public IOException() {
  194.50 -        super();
  194.51 -    }
  194.52 -
  194.53 -    /**
  194.54 -     * Constructs an {@code IOException} with the specified detail message.
  194.55 -     *
  194.56 -     * @param message
  194.57 -     *        The detail message (which is saved for later retrieval
  194.58 -     *        by the {@link #getMessage()} method)
  194.59 -     */
  194.60 -    public IOException(String message) {
  194.61 -        super(message);
  194.62 -    }
  194.63 -
  194.64 -    /**
  194.65 -     * Constructs an {@code IOException} with the specified detail message
  194.66 -     * and cause.
  194.67 -     *
  194.68 -     * <p> Note that the detail message associated with {@code cause} is
  194.69 -     * <i>not</i> automatically incorporated into this exception's detail
  194.70 -     * message.
  194.71 -     *
  194.72 -     * @param message
  194.73 -     *        The detail message (which is saved for later retrieval
  194.74 -     *        by the {@link #getMessage()} method)
  194.75 -     *
  194.76 -     * @param cause
  194.77 -     *        The cause (which is saved for later retrieval by the
  194.78 -     *        {@link #getCause()} method).  (A null value is permitted,
  194.79 -     *        and indicates that the cause is nonexistent or unknown.)
  194.80 -     *
  194.81 -     * @since 1.6
  194.82 -     */
  194.83 -    public IOException(String message, Throwable cause) {
  194.84 -        super(message, cause);
  194.85 -    }
  194.86 -
  194.87 -    /**
  194.88 -     * Constructs an {@code IOException} with the specified cause and a
  194.89 -     * detail message of {@code (cause==null ? null : cause.toString())}
  194.90 -     * (which typically contains the class and detail message of {@code cause}).
  194.91 -     * This constructor is useful for IO exceptions that are little more
  194.92 -     * than wrappers for other throwables.
  194.93 -     *
  194.94 -     * @param cause
  194.95 -     *        The cause (which is saved for later retrieval by the
  194.96 -     *        {@link #getCause()} method).  (A null value is permitted,
  194.97 -     *        and indicates that the cause is nonexistent or unknown.)
  194.98 -     *
  194.99 -     * @since 1.6
 194.100 -     */
 194.101 -    public IOException(Throwable cause) {
 194.102 -        super(cause);
 194.103 -    }
 194.104 -}
   195.1 --- a/emul/src/main/java/java/io/InputStream.java	Wed Dec 05 10:03:58 2012 +0100
   195.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   195.3 @@ -1,370 +0,0 @@
   195.4 -/*
   195.5 - * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
   195.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   195.7 - *
   195.8 - * This code is free software; you can redistribute it and/or modify it
   195.9 - * under the terms of the GNU General Public License version 2 only, as
  195.10 - * published by the Free Software Foundation.  Oracle designates this
  195.11 - * particular file as subject to the "Classpath" exception as provided
  195.12 - * by Oracle in the LICENSE file that accompanied this code.
  195.13 - *
  195.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  195.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  195.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  195.17 - * version 2 for more details (a copy is included in the LICENSE file that
  195.18 - * accompanied this code).
  195.19 - *
  195.20 - * You should have received a copy of the GNU General Public License version
  195.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  195.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  195.23 - *
  195.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  195.25 - * or visit www.oracle.com if you need additional information or have any
  195.26 - * questions.
  195.27 - */
  195.28 -
  195.29 -package java.io;
  195.30 -
  195.31 -/**
  195.32 - * This abstract class is the superclass of all classes representing
  195.33 - * an input stream of bytes.
  195.34 - *
  195.35 - * <p> Applications that need to define a subclass of <code>InputStream</code>
  195.36 - * must always provide a method that returns the next byte of input.
  195.37 - *
  195.38 - * @author  Arthur van Hoff
  195.39 - * @see     java.io.BufferedInputStream
  195.40 - * @see     java.io.ByteArrayInputStream
  195.41 - * @see     java.io.DataInputStream
  195.42 - * @see     java.io.FilterInputStream
  195.43 - * @see     java.io.InputStream#read()
  195.44 - * @see     java.io.OutputStream
  195.45 - * @see     java.io.PushbackInputStream
  195.46 - * @since   JDK1.0
  195.47 - */
  195.48 -public abstract class InputStream implements Closeable {
  195.49 -
  195.50 -    // SKIP_BUFFER_SIZE is used to determine the size of skipBuffer
  195.51 -    private static final int SKIP_BUFFER_SIZE = 2048;
  195.52 -    // skipBuffer is initialized in skip(long), if needed.
  195.53 -    private static byte[] skipBuffer;
  195.54 -
  195.55 -    /**
  195.56 -     * Reads the next byte of data from the input stream. The value byte is
  195.57 -     * returned as an <code>int</code> in the range <code>0</code> to
  195.58 -     * <code>255</code>. If no byte is available because the end of the stream
  195.59 -     * has been reached, the value <code>-1</code> is returned. This method
  195.60 -     * blocks until input data is available, the end of the stream is detected,
  195.61 -     * or an exception is thrown.
  195.62 -     *
  195.63 -     * <p> A subclass must provide an implementation of this method.
  195.64 -     *
  195.65 -     * @return     the next byte of data, or <code>-1</code> if the end of the
  195.66 -     *             stream is reached.
  195.67 -     * @exception  IOException  if an I/O error occurs.
  195.68 -     */
  195.69 -    public abstract int read() throws IOException;
  195.70 -
  195.71 -    /**
  195.72 -     * Reads some number of bytes from the input stream and stores them into
  195.73 -     * the buffer array <code>b</code>. The number of bytes actually read is
  195.74 -     * returned as an integer.  This method blocks until input data is
  195.75 -     * available, end of file is detected, or an exception is thrown.
  195.76 -     *
  195.77 -     * <p> If the length of <code>b</code> is zero, then no bytes are read and
  195.78 -     * <code>0</code> is returned; otherwise, there is an attempt to read at
  195.79 -     * least one byte. If no byte is available because the stream is at the
  195.80 -     * end of the file, the value <code>-1</code> is returned; otherwise, at
  195.81 -     * least one byte is read and stored into <code>b</code>.
  195.82 -     *
  195.83 -     * <p> The first byte read is stored into element <code>b[0]</code>, the
  195.84 -     * next one into <code>b[1]</code>, and so on. The number of bytes read is,
  195.85 -     * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
  195.86 -     * number of bytes actually read; these bytes will be stored in elements
  195.87 -     * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
  195.88 -     * leaving elements <code>b[</code><i>k</i><code>]</code> through
  195.89 -     * <code>b[b.length-1]</code> unaffected.
  195.90 -     *
  195.91 -     * <p> The <code>read(b)</code> method for class <code>InputStream</code>
  195.92 -     * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
  195.93 -     *
  195.94 -     * @param      b   the buffer into which the data is read.
  195.95 -     * @return     the total number of bytes read into the buffer, or
  195.96 -     *             <code>-1</code> if there is no more data because the end of
  195.97 -     *             the stream has been reached.
  195.98 -     * @exception  IOException  If the first byte cannot be read for any reason
  195.99 -     * other than the end of the file, if the input stream has been closed, or
 195.100 -     * if some other I/O error occurs.
 195.101 -     * @exception  NullPointerException  if <code>b</code> is <code>null</code>.
 195.102 -     * @see        java.io.InputStream#read(byte[], int, int)
 195.103 -     */
 195.104 -    public int read(byte b[]) throws IOException {
 195.105 -        return read(b, 0, b.length);
 195.106 -    }
 195.107 -
 195.108 -    /**
 195.109 -     * Reads up to <code>len</code> bytes of data from the input stream into
 195.110 -     * an array of bytes.  An attempt is made to read as many as
 195.111 -     * <code>len</code> bytes, but a smaller number may be read.
 195.112 -     * The number of bytes actually read is returned as an integer.
 195.113 -     *
 195.114 -     * <p> This method blocks until input data is available, end of file is
 195.115 -     * detected, or an exception is thrown.
 195.116 -     *
 195.117 -     * <p> If <code>len</code> is zero, then no bytes are read and
 195.118 -     * <code>0</code> is returned; otherwise, there is an attempt to read at
 195.119 -     * least one byte. If no byte is available because the stream is at end of
 195.120 -     * file, the value <code>-1</code> is returned; otherwise, at least one
 195.121 -     * byte is read and stored into <code>b</code>.
 195.122 -     *
 195.123 -     * <p> The first byte read is stored into element <code>b[off]</code>, the
 195.124 -     * next one into <code>b[off+1]</code>, and so on. The number of bytes read
 195.125 -     * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
 195.126 -     * bytes actually read; these bytes will be stored in elements
 195.127 -     * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
 195.128 -     * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
 195.129 -     * <code>b[off+len-1]</code> unaffected.
 195.130 -     *
 195.131 -     * <p> In every case, elements <code>b[0]</code> through
 195.132 -     * <code>b[off]</code> and elements <code>b[off+len]</code> through
 195.133 -     * <code>b[b.length-1]</code> are unaffected.
 195.134 -     *
 195.135 -     * <p> The <code>read(b,</code> <code>off,</code> <code>len)</code> method
 195.136 -     * for class <code>InputStream</code> simply calls the method
 195.137 -     * <code>read()</code> repeatedly. If the first such call results in an
 195.138 -     * <code>IOException</code>, that exception is returned from the call to
 195.139 -     * the <code>read(b,</code> <code>off,</code> <code>len)</code> method.  If
 195.140 -     * any subsequent call to <code>read()</code> results in a
 195.141 -     * <code>IOException</code>, the exception is caught and treated as if it
 195.142 -     * were end of file; the bytes read up to that point are stored into
 195.143 -     * <code>b</code> and the number of bytes read before the exception
 195.144 -     * occurred is returned. The default implementation of this method blocks
 195.145 -     * until the requested amount of input data <code>len</code> has been read,
 195.146 -     * end of file is detected, or an exception is thrown. Subclasses are encouraged
 195.147 -     * to provide a more efficient implementation of this method.
 195.148 -     *
 195.149 -     * @param      b     the buffer into which the data is read.
 195.150 -     * @param      off   the start offset in array <code>b</code>
 195.151 -     *                   at which the data is written.
 195.152 -     * @param      len   the maximum number of bytes to read.
 195.153 -     * @return     the total number of bytes read into the buffer, or
 195.154 -     *             <code>-1</code> if there is no more data because the end of
 195.155 -     *             the stream has been reached.
 195.156 -     * @exception  IOException If the first byte cannot be read for any reason
 195.157 -     * other than end of file, or if the input stream has been closed, or if
 195.158 -     * some other I/O error occurs.
 195.159 -     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 195.160 -     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 195.161 -     * <code>len</code> is negative, or <code>len</code> is greater than
 195.162 -     * <code>b.length - off</code>
 195.163 -     * @see        java.io.InputStream#read()
 195.164 -     */
 195.165 -    public int read(byte b[], int off, int len) throws IOException {
 195.166 -        if (b == null) {
 195.167 -            throw new NullPointerException();
 195.168 -        } else if (off < 0 || len < 0 || len > b.length - off) {
 195.169 -            throw new IndexOutOfBoundsException();
 195.170 -        } else if (len == 0) {
 195.171 -            return 0;
 195.172 -        }
 195.173 -
 195.174 -        int c = read();
 195.175 -        if (c == -1) {
 195.176 -            return -1;
 195.177 -        }
 195.178 -        b[off] = (byte)c;
 195.179 -
 195.180 -        int i = 1;
 195.181 -        try {
 195.182 -            for (; i < len ; i++) {
 195.183 -                c = read();
 195.184 -                if (c == -1) {
 195.185 -                    break;
 195.186 -                }
 195.187 -                b[off + i] = (byte)c;
 195.188 -            }
 195.189 -        } catch (IOException ee) {
 195.190 -        }
 195.191 -        return i;
 195.192 -    }
 195.193 -
 195.194 -    /**
 195.195 -     * Skips over and discards <code>n</code> bytes of data from this input
 195.196 -     * stream. The <code>skip</code> method may, for a variety of reasons, end
 195.197 -     * up skipping over some smaller number of bytes, possibly <code>0</code>.
 195.198 -     * This may result from any of a number of conditions; reaching end of file
 195.199 -     * before <code>n</code> bytes have been skipped is only one possibility.
 195.200 -     * The actual number of bytes skipped is returned.  If <code>n</code> is
 195.201 -     * negative, no bytes are skipped.
 195.202 -     *
 195.203 -     * <p> The <code>skip</code> method of this class creates a
 195.204 -     * byte array and then repeatedly reads into it until <code>n</code> bytes
 195.205 -     * have been read or the end of the stream has been reached. Subclasses are
 195.206 -     * encouraged to provide a more efficient implementation of this method.
 195.207 -     * For instance, the implementation may depend on the ability to seek.
 195.208 -     *
 195.209 -     * @param      n   the number of bytes to be skipped.
 195.210 -     * @return     the actual number of bytes skipped.
 195.211 -     * @exception  IOException  if the stream does not support seek,
 195.212 -     *                          or if some other I/O error occurs.
 195.213 -     */
 195.214 -    public long skip(long n) throws IOException {
 195.215 -
 195.216 -        long remaining = n;
 195.217 -        int nr;
 195.218 -        if (skipBuffer == null)
 195.219 -            skipBuffer = new byte[SKIP_BUFFER_SIZE];
 195.220 -
 195.221 -        byte[] localSkipBuffer = skipBuffer;
 195.222 -
 195.223 -        if (n <= 0) {
 195.224 -            return 0;
 195.225 -        }
 195.226 -
 195.227 -        while (remaining > 0) {
 195.228 -            nr = read(localSkipBuffer, 0,
 195.229 -                      (int) Math.min(SKIP_BUFFER_SIZE, remaining));
 195.230 -            if (nr < 0) {
 195.231 -                break;
 195.232 -            }
 195.233 -            remaining -= nr;
 195.234 -        }
 195.235 -
 195.236 -        return n - remaining;
 195.237 -    }
 195.238 -
 195.239 -    /**
 195.240 -     * Returns an estimate of the number of bytes that can be read (or
 195.241 -     * skipped over) from this input stream without blocking by the next
 195.242 -     * invocation of a method for this input stream. The next invocation
 195.243 -     * might be the same thread or another thread.  A single read or skip of this
 195.244 -     * many bytes will not block, but may read or skip fewer bytes.
 195.245 -     *
 195.246 -     * <p> Note that while some implementations of {@code InputStream} will return
 195.247 -     * the total number of bytes in the stream, many will not.  It is
 195.248 -     * never correct to use the return value of this method to allocate
 195.249 -     * a buffer intended to hold all data in this stream.
 195.250 -     *
 195.251 -     * <p> A subclass' implementation of this method may choose to throw an
 195.252 -     * {@link IOException} if this input stream has been closed by
 195.253 -     * invoking the {@link #close()} method.
 195.254 -     *
 195.255 -     * <p> The {@code available} method for class {@code InputStream} always
 195.256 -     * returns {@code 0}.
 195.257 -     *
 195.258 -     * <p> This method should be overridden by subclasses.
 195.259 -     *
 195.260 -     * @return     an estimate of the number of bytes that can be read (or skipped
 195.261 -     *             over) from this input stream without blocking or {@code 0} when
 195.262 -     *             it reaches the end of the input stream.
 195.263 -     * @exception  IOException if an I/O error occurs.
 195.264 -     */
 195.265 -    public int available() throws IOException {
 195.266 -        return 0;
 195.267 -    }
 195.268 -
 195.269 -    /**
 195.270 -     * Closes this input stream and releases any system resources associated
 195.271 -     * with the stream.
 195.272 -     *
 195.273 -     * <p> The <code>close</code> method of <code>InputStream</code> does
 195.274 -     * nothing.
 195.275 -     *
 195.276 -     * @exception  IOException  if an I/O error occurs.
 195.277 -     */
 195.278 -    public void close() throws IOException {}
 195.279 -
 195.280 -    /**
 195.281 -     * Marks the current position in this input stream. A subsequent call to
 195.282 -     * the <code>reset</code> method repositions this stream at the last marked
 195.283 -     * position so that subsequent reads re-read the same bytes.
 195.284 -     *
 195.285 -     * <p> The <code>readlimit</code> arguments tells this input stream to
 195.286 -     * allow that many bytes to be read before the mark position gets
 195.287 -     * invalidated.
 195.288 -     *
 195.289 -     * <p> The general contract of <code>mark</code> is that, if the method
 195.290 -     * <code>markSupported</code> returns <code>true</code>, the stream somehow
 195.291 -     * remembers all the bytes read after the call to <code>mark</code> and
 195.292 -     * stands ready to supply those same bytes again if and whenever the method
 195.293 -     * <code>reset</code> is called.  However, the stream is not required to
 195.294 -     * remember any data at all if more than <code>readlimit</code> bytes are
 195.295 -     * read from the stream before <code>reset</code> is called.
 195.296 -     *
 195.297 -     * <p> Marking a closed stream should not have any effect on the stream.
 195.298 -     *
 195.299 -     * <p> The <code>mark</code> method of <code>InputStream</code> does
 195.300 -     * nothing.
 195.301 -     *
 195.302 -     * @param   readlimit   the maximum limit of bytes that can be read before
 195.303 -     *                      the mark position becomes invalid.
 195.304 -     * @see     java.io.InputStream#reset()
 195.305 -     */
 195.306 -    public synchronized void mark(int readlimit) {}
 195.307 -
 195.308 -    /**
 195.309 -     * Repositions this stream to the position at the time the
 195.310 -     * <code>mark</code> method was last called on this input stream.
 195.311 -     *
 195.312 -     * <p> The general contract of <code>reset</code> is:
 195.313 -     *
 195.314 -     * <p><ul>
 195.315 -     *
 195.316 -     * <li> If the method <code>markSupported</code> returns
 195.317 -     * <code>true</code>, then:
 195.318 -     *
 195.319 -     *     <ul><li> If the method <code>mark</code> has not been called since
 195.320 -     *     the stream was created, or the number of bytes read from the stream
 195.321 -     *     since <code>mark</code> was last called is larger than the argument
 195.322 -     *     to <code>mark</code> at that last call, then an
 195.323 -     *     <code>IOException</code> might be thrown.
 195.324 -     *
 195.325 -     *     <li> If such an <code>IOException</code> is not thrown, then the
 195.326 -     *     stream is reset to a state such that all the bytes read since the
 195.327 -     *     most recent call to <code>mark</code> (or since the start of the
 195.328 -     *     file, if <code>mark</code> has not been called) will be resupplied
 195.329 -     *     to subsequent callers of the <code>read</code> method, followed by
 195.330 -     *     any bytes that otherwise would have been the next input data as of
 195.331 -     *     the time of the call to <code>reset</code>. </ul>
 195.332 -     *
 195.333 -     * <li> If the method <code>markSupported</code> returns
 195.334 -     * <code>false</code>, then:
 195.335 -     *
 195.336 -     *     <ul><li> The call to <code>reset</code> may throw an
 195.337 -     *     <code>IOException</code>.
 195.338 -     *
 195.339 -     *     <li> If an <code>IOException</code> is not thrown, then the stream
 195.340 -     *     is reset to a fixed state that depends on the particular type of the
 195.341 -     *     input stream and how it was created. The bytes that will be supplied
 195.342 -     *     to subsequent callers of the <code>read</code> method depend on the
 195.343 -     *     particular type of the input stream. </ul></ul>
 195.344 -     *
 195.345 -     * <p>The method <code>reset</code> for class <code>InputStream</code>
 195.346 -     * does nothing except throw an <code>IOException</code>.
 195.347 -     *
 195.348 -     * @exception  IOException  if this stream has not been marked or if the
 195.349 -     *               mark has been invalidated.
 195.350 -     * @see     java.io.InputStream#mark(int)
 195.351 -     * @see     java.io.IOException
 195.352 -     */
 195.353 -    public synchronized void reset() throws IOException {
 195.354 -        throw new IOException("mark/reset not supported");
 195.355 -    }
 195.356 -
 195.357 -    /**
 195.358 -     * Tests if this input stream supports the <code>mark</code> and
 195.359 -     * <code>reset</code> methods. Whether or not <code>mark</code> and
 195.360 -     * <code>reset</code> are supported is an invariant property of a
 195.361 -     * particular input stream instance. The <code>markSupported</code> method
 195.362 -     * of <code>InputStream</code> returns <code>false</code>.
 195.363 -     *
 195.364 -     * @return  <code>true</code> if this stream instance supports the mark
 195.365 -     *          and reset methods; <code>false</code> otherwise.
 195.366 -     * @see     java.io.InputStream#mark(int)
 195.367 -     * @see     java.io.InputStream#reset()
 195.368 -     */
 195.369 -    public boolean markSupported() {
 195.370 -        return false;
 195.371 -    }
 195.372 -
 195.373 -}
   196.1 --- a/emul/src/main/java/java/io/PushbackInputStream.java	Wed Dec 05 10:03:58 2012 +0100
   196.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   196.3 @@ -1,388 +0,0 @@
   196.4 -/*
   196.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   196.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   196.7 - *
   196.8 - * This code is free software; you can redistribute it and/or modify it
   196.9 - * under the terms of the GNU General Public License version 2 only, as
  196.10 - * published by the Free Software Foundation.  Oracle designates this
  196.11 - * particular file as subject to the "Classpath" exception as provided
  196.12 - * by Oracle in the LICENSE file that accompanied this code.
  196.13 - *
  196.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  196.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  196.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  196.17 - * version 2 for more details (a copy is included in the LICENSE file that
  196.18 - * accompanied this code).
  196.19 - *
  196.20 - * You should have received a copy of the GNU General Public License version
  196.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  196.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  196.23 - *
  196.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  196.25 - * or visit www.oracle.com if you need additional information or have any
  196.26 - * questions.
  196.27 - */
  196.28 -
  196.29 -package java.io;
  196.30 -
  196.31 -/**
  196.32 - * A <code>PushbackInputStream</code> adds
  196.33 - * functionality to another input stream, namely
  196.34 - * the  ability to "push back" or "unread"
  196.35 - * one byte. This is useful in situations where
  196.36 - * it is  convenient for a fragment of code
  196.37 - * to read an indefinite number of data bytes
  196.38 - * that  are delimited by a particular byte
  196.39 - * value; after reading the terminating byte,
  196.40 - * the  code fragment can "unread" it, so that
  196.41 - * the next read operation on the input stream
  196.42 - * will reread the byte that was pushed back.
  196.43 - * For example, bytes representing the  characters
  196.44 - * constituting an identifier might be terminated
  196.45 - * by a byte representing an  operator character;
  196.46 - * a method whose job is to read just an identifier
  196.47 - * can read until it  sees the operator and
  196.48 - * then push the operator back to be re-read.
  196.49 - *
  196.50 - * @author  David Connelly
  196.51 - * @author  Jonathan Payne
  196.52 - * @since   JDK1.0
  196.53 - */
  196.54 -public
  196.55 -class PushbackInputStream extends FilterInputStream {
  196.56 -    /**
  196.57 -     * The pushback buffer.
  196.58 -     * @since   JDK1.1
  196.59 -     */
  196.60 -    protected byte[] buf;
  196.61 -
  196.62 -    /**
  196.63 -     * The position within the pushback buffer from which the next byte will
  196.64 -     * be read.  When the buffer is empty, <code>pos</code> is equal to
  196.65 -     * <code>buf.length</code>; when the buffer is full, <code>pos</code> is
  196.66 -     * equal to zero.
  196.67 -     *
  196.68 -     * @since   JDK1.1
  196.69 -     */
  196.70 -    protected int pos;
  196.71 -
  196.72 -    /**
  196.73 -     * Check to make sure that this stream has not been closed
  196.74 -     */
  196.75 -    private void ensureOpen() throws IOException {
  196.76 -        if (in == null)
  196.77 -            throw new IOException("Stream closed");
  196.78 -    }
  196.79 -
  196.80 -    /**
  196.81 -     * Creates a <code>PushbackInputStream</code>
  196.82 -     * with a pushback buffer of the specified <code>size</code>,
  196.83 -     * and saves its  argument, the input stream
  196.84 -     * <code>in</code>, for later use. Initially,
  196.85 -     * there is no pushed-back byte  (the field
  196.86 -     * <code>pushBack</code> is initialized to
  196.87 -     * <code>-1</code>).
  196.88 -     *
  196.89 -     * @param  in    the input stream from which bytes will be read.
  196.90 -     * @param  size  the size of the pushback buffer.
  196.91 -     * @exception IllegalArgumentException if size is <= 0
  196.92 -     * @since  JDK1.1
  196.93 -     */
  196.94 -    public PushbackInputStream(InputStream in, int size) {
  196.95 -        super(in);
  196.96 -        if (size <= 0) {
  196.97 -            throw new IllegalArgumentException("size <= 0");
  196.98 -        }
  196.99 -        this.buf = new byte[size];
 196.100 -        this.pos = size;
 196.101 -    }
 196.102 -
 196.103 -    /**
 196.104 -     * Creates a <code>PushbackInputStream</code>
 196.105 -     * and saves its  argument, the input stream
 196.106 -     * <code>in</code>, for later use. Initially,
 196.107 -     * there is no pushed-back byte  (the field
 196.108 -     * <code>pushBack</code> is initialized to
 196.109 -     * <code>-1</code>).
 196.110 -     *
 196.111 -     * @param   in   the input stream from which bytes will be read.
 196.112 -     */
 196.113 -    public PushbackInputStream(InputStream in) {
 196.114 -        this(in, 1);
 196.115 -    }
 196.116 -
 196.117 -    /**
 196.118 -     * Reads the next byte of data from this input stream. The value
 196.119 -     * byte is returned as an <code>int</code> in the range
 196.120 -     * <code>0</code> to <code>255</code>. If no byte is available
 196.121 -     * because the end of the stream has been reached, the value
 196.122 -     * <code>-1</code> is returned. This method blocks until input data
 196.123 -     * is available, the end of the stream is detected, or an exception
 196.124 -     * is thrown.
 196.125 -     *
 196.126 -     * <p> This method returns the most recently pushed-back byte, if there is
 196.127 -     * one, and otherwise calls the <code>read</code> method of its underlying
 196.128 -     * input stream and returns whatever value that method returns.
 196.129 -     *
 196.130 -     * @return     the next byte of data, or <code>-1</code> if the end of the
 196.131 -     *             stream has been reached.
 196.132 -     * @exception  IOException  if this input stream has been closed by
 196.133 -     *             invoking its {@link #close()} method,
 196.134 -     *             or an I/O error occurs.
 196.135 -     * @see        java.io.InputStream#read()
 196.136 -     */
 196.137 -    public int read() throws IOException {
 196.138 -        ensureOpen();
 196.139 -        if (pos < buf.length) {
 196.140 -            return buf[pos++] & 0xff;
 196.141 -        }
 196.142 -        return super.read();
 196.143 -    }
 196.144 -
 196.145 -    /**
 196.146 -     * Reads up to <code>len</code> bytes of data from this input stream into
 196.147 -     * an array of bytes.  This method first reads any pushed-back bytes; after
 196.148 -     * that, if fewer than <code>len</code> bytes have been read then it
 196.149 -     * reads from the underlying input stream. If <code>len</code> is not zero, the method
 196.150 -     * blocks until at least 1 byte of input is available; otherwise, no
 196.151 -     * bytes are read and <code>0</code> is returned.
 196.152 -     *
 196.153 -     * @param      b     the buffer into which the data is read.
 196.154 -     * @param      off   the start offset in the destination array <code>b</code>
 196.155 -     * @param      len   the maximum number of bytes read.
 196.156 -     * @return     the total number of bytes read into the buffer, or
 196.157 -     *             <code>-1</code> if there is no more data because the end of
 196.158 -     *             the stream has been reached.
 196.159 -     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 196.160 -     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 196.161 -     * <code>len</code> is negative, or <code>len</code> is greater than
 196.162 -     * <code>b.length - off</code>
 196.163 -     * @exception  IOException  if this input stream has been closed by
 196.164 -     *             invoking its {@link #close()} method,
 196.165 -     *             or an I/O error occurs.
 196.166 -     * @see        java.io.InputStream#read(byte[], int, int)
 196.167 -     */
 196.168 -    public int read(byte[] b, int off, int len) throws IOException {
 196.169 -        ensureOpen();
 196.170 -        if (b == null) {
 196.171 -            throw new NullPointerException();
 196.172 -        } else if (off < 0 || len < 0 || len > b.length - off) {
 196.173 -            throw new IndexOutOfBoundsException();
 196.174 -        } else if (len == 0) {
 196.175 -            return 0;
 196.176 -        }
 196.177 -
 196.178 -        int avail = buf.length - pos;
 196.179 -        if (avail > 0) {
 196.180 -            if (len < avail) {
 196.181 -                avail = len;
 196.182 -            }
 196.183 -            arraycopy(buf, pos, b, off, avail);
 196.184 -            pos += avail;
 196.185 -            off += avail;
 196.186 -            len -= avail;
 196.187 -        }
 196.188 -        if (len > 0) {
 196.189 -            len = super.read(b, off, len);
 196.190 -            if (len == -1) {
 196.191 -                return avail == 0 ? -1 : avail;
 196.192 -            }
 196.193 -            return avail + len;
 196.194 -        }
 196.195 -        return avail;
 196.196 -    }
 196.197 -
 196.198 -    /**
 196.199 -     * Pushes back a byte by copying it to the front of the pushback buffer.
 196.200 -     * After this method returns, the next byte to be read will have the value
 196.201 -     * <code>(byte)b</code>.
 196.202 -     *
 196.203 -     * @param      b   the <code>int</code> value whose low-order
 196.204 -     *                  byte is to be pushed back.
 196.205 -     * @exception IOException If there is not enough room in the pushback
 196.206 -     *            buffer for the byte, or this input stream has been closed by
 196.207 -     *            invoking its {@link #close()} method.
 196.208 -     */
 196.209 -    public void unread(int b) throws IOException {
 196.210 -        ensureOpen();
 196.211 -        if (pos == 0) {
 196.212 -            throw new IOException("Push back buffer is full");
 196.213 -        }
 196.214 -        buf[--pos] = (byte)b;
 196.215 -    }
 196.216 -
 196.217 -    /**
 196.218 -     * Pushes back a portion of an array of bytes by copying it to the front
 196.219 -     * of the pushback buffer.  After this method returns, the next byte to be
 196.220 -     * read will have the value <code>b[off]</code>, the byte after that will
 196.221 -     * have the value <code>b[off+1]</code>, and so forth.
 196.222 -     *
 196.223 -     * @param b the byte array to push back.
 196.224 -     * @param off the start offset of the data.
 196.225 -     * @param len the number of bytes to push back.
 196.226 -     * @exception IOException If there is not enough room in the pushback
 196.227 -     *            buffer for the specified number of bytes,
 196.228 -     *            or this input stream has been closed by
 196.229 -     *            invoking its {@link #close()} method.
 196.230 -     * @since     JDK1.1
 196.231 -     */
 196.232 -    public void unread(byte[] b, int off, int len) throws IOException {
 196.233 -        ensureOpen();
 196.234 -        if (len > pos) {
 196.235 -            throw new IOException("Push back buffer is full");
 196.236 -        }
 196.237 -        pos -= len;
 196.238 -        arraycopy(b, off, buf, pos, len);
 196.239 -    }
 196.240 -
 196.241 -    /**
 196.242 -     * Pushes back an array of bytes by copying it to the front of the
 196.243 -     * pushback buffer.  After this method returns, the next byte to be read
 196.244 -     * will have the value <code>b[0]</code>, the byte after that will have the
 196.245 -     * value <code>b[1]</code>, and so forth.
 196.246 -     *
 196.247 -     * @param b the byte array to push back
 196.248 -     * @exception IOException If there is not enough room in the pushback
 196.249 -     *            buffer for the specified number of bytes,
 196.250 -     *            or this input stream has been closed by
 196.251 -     *            invoking its {@link #close()} method.
 196.252 -     * @since     JDK1.1
 196.253 -     */
 196.254 -    public void unread(byte[] b) throws IOException {
 196.255 -        unread(b, 0, b.length);
 196.256 -    }
 196.257 -
 196.258 -    /**
 196.259 -     * Returns an estimate of the number of bytes that can be read (or
 196.260 -     * skipped over) from this input stream without blocking by the next
 196.261 -     * invocation of a method for this input stream. The next invocation might be
 196.262 -     * the same thread or another thread.  A single read or skip of this
 196.263 -     * many bytes will not block, but may read or skip fewer bytes.
 196.264 -     *
 196.265 -     * <p> The method returns the sum of the number of bytes that have been
 196.266 -     * pushed back and the value returned by {@link
 196.267 -     * java.io.FilterInputStream#available available}.
 196.268 -     *
 196.269 -     * @return     the number of bytes that can be read (or skipped over) from
 196.270 -     *             the input stream without blocking.
 196.271 -     * @exception  IOException  if this input stream has been closed by
 196.272 -     *             invoking its {@link #close()} method,
 196.273 -     *             or an I/O error occurs.
 196.274 -     * @see        java.io.FilterInputStream#in
 196.275 -     * @see        java.io.InputStream#available()
 196.276 -     */
 196.277 -    public int available() throws IOException {
 196.278 -        ensureOpen();
 196.279 -        int n = buf.length - pos;
 196.280 -        int avail = super.available();
 196.281 -        return n > (Integer.MAX_VALUE - avail)
 196.282 -                    ? Integer.MAX_VALUE
 196.283 -                    : n + avail;
 196.284 -    }
 196.285 -
 196.286 -    /**
 196.287 -     * Skips over and discards <code>n</code> bytes of data from this
 196.288 -     * input stream. The <code>skip</code> method may, for a variety of
 196.289 -     * reasons, end up skipping over some smaller number of bytes,
 196.290 -     * possibly zero.  If <code>n</code> is negative, no bytes are skipped.
 196.291 -     *
 196.292 -     * <p> The <code>skip</code> method of <code>PushbackInputStream</code>
 196.293 -     * first skips over the bytes in the pushback buffer, if any.  It then
 196.294 -     * calls the <code>skip</code> method of the underlying input stream if
 196.295 -     * more bytes need to be skipped.  The actual number of bytes skipped
 196.296 -     * is returned.
 196.297 -     *
 196.298 -     * @param      n  {@inheritDoc}
 196.299 -     * @return     {@inheritDoc}
 196.300 -     * @exception  IOException  if the stream does not support seek,
 196.301 -     *            or the stream has been closed by
 196.302 -     *            invoking its {@link #close()} method,
 196.303 -     *            or an I/O error occurs.
 196.304 -     * @see        java.io.FilterInputStream#in
 196.305 -     * @see        java.io.InputStream#skip(long n)
 196.306 -     * @since      1.2
 196.307 -     */
 196.308 -    public long skip(long n) throws IOException {
 196.309 -        ensureOpen();
 196.310 -        if (n <= 0) {
 196.311 -            return 0;
 196.312 -        }
 196.313 -
 196.314 -        long pskip = buf.length - pos;
 196.315 -        if (pskip > 0) {
 196.316 -            if (n < pskip) {
 196.317 -                pskip = n;
 196.318 -            }
 196.319 -            pos += pskip;
 196.320 -            n -= pskip;
 196.321 -        }
 196.322 -        if (n > 0) {
 196.323 -            pskip += super.skip(n);
 196.324 -        }
 196.325 -        return pskip;
 196.326 -    }
 196.327 -
 196.328 -    /**
 196.329 -     * Tests if this input stream supports the <code>mark</code> and
 196.330 -     * <code>reset</code> methods, which it does not.
 196.331 -     *
 196.332 -     * @return   <code>false</code>, since this class does not support the
 196.333 -     *           <code>mark</code> and <code>reset</code> methods.
 196.334 -     * @see     java.io.InputStream#mark(int)
 196.335 -     * @see     java.io.InputStream#reset()
 196.336 -     */
 196.337 -    public boolean markSupported() {
 196.338 -        return false;
 196.339 -    }
 196.340 -
 196.341 -    /**
 196.342 -     * Marks the current position in this input stream.
 196.343 -     *
 196.344 -     * <p> The <code>mark</code> method of <code>PushbackInputStream</code>
 196.345 -     * does nothing.
 196.346 -     *
 196.347 -     * @param   readlimit   the maximum limit of bytes that can be read before
 196.348 -     *                      the mark position becomes invalid.
 196.349 -     * @see     java.io.InputStream#reset()
 196.350 -     */
 196.351 -    public synchronized void mark(int readlimit) {
 196.352 -    }
 196.353 -
 196.354 -    /**
 196.355 -     * Repositions this stream to the position at the time the
 196.356 -     * <code>mark</code> method was last called on this input stream.
 196.357 -     *
 196.358 -     * <p> The method <code>reset</code> for class
 196.359 -     * <code>PushbackInputStream</code> does nothing except throw an
 196.360 -     * <code>IOException</code>.
 196.361 -     *
 196.362 -     * @exception  IOException  if this method is invoked.
 196.363 -     * @see     java.io.InputStream#mark(int)
 196.364 -     * @see     java.io.IOException
 196.365 -     */
 196.366 -    public synchronized void reset() throws IOException {
 196.367 -        throw new IOException("mark/reset not supported");
 196.368 -    }
 196.369 -
 196.370 -    /**
 196.371 -     * Closes this input stream and releases any system resources
 196.372 -     * associated with the stream.
 196.373 -     * Once the stream has been closed, further read(), unread(),
 196.374 -     * available(), reset(), or skip() invocations will throw an IOException.
 196.375 -     * Closing a previously closed stream has no effect.
 196.376 -     *
 196.377 -     * @exception  IOException  if an I/O error occurs.
 196.378 -     */
 196.379 -    public synchronized void close() throws IOException {
 196.380 -        if (in == null)
 196.381 -            return;
 196.382 -        in.close();
 196.383 -        in = null;
 196.384 -        buf = null;
 196.385 -    }
 196.386 -    static void arraycopy(byte[] value, int srcBegin, byte[] dst, int dstBegin, int count) {
 196.387 -        while (count-- > 0) {
 196.388 -            dst[dstBegin++] = value[srcBegin++];
 196.389 -        }
 196.390 -    }
 196.391 -}
   197.1 --- a/emul/src/main/java/java/io/Serializable.java	Wed Dec 05 10:03:58 2012 +0100
   197.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   197.3 @@ -1,170 +0,0 @@
   197.4 -/*
   197.5 - * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
   197.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   197.7 - *
   197.8 - * This code is free software; you can redistribute it and/or modify it
   197.9 - * under the terms of the GNU General Public License version 2 only, as
  197.10 - * published by the Free Software Foundation.  Oracle designates this
  197.11 - * particular file as subject to the "Classpath" exception as provided
  197.12 - * by Oracle in the LICENSE file that accompanied this code.
  197.13 - *
  197.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  197.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  197.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  197.17 - * version 2 for more details (a copy is included in the LICENSE file that
  197.18 - * accompanied this code).
  197.19 - *
  197.20 - * You should have received a copy of the GNU General Public License version
  197.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  197.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  197.23 - *
  197.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  197.25 - * or visit www.oracle.com if you need additional information or have any
  197.26 - * questions.
  197.27 - */
  197.28 -
  197.29 -package java.io;
  197.30 -
  197.31 -/**
  197.32 - * Serializability of a class is enabled by the class implementing the
  197.33 - * java.io.Serializable interface. Classes that do not implement this
  197.34 - * interface will not have any of their state serialized or
  197.35 - * deserialized.  All subtypes of a serializable class are themselves
  197.36 - * serializable.  The serialization interface has no methods or fields
  197.37 - * and serves only to identify the semantics of being serializable. <p>
  197.38 - *
  197.39 - * To allow subtypes of non-serializable classes to be serialized, the
  197.40 - * subtype may assume responsibility for saving and restoring the
  197.41 - * state of the supertype's public, protected, and (if accessible)
  197.42 - * package fields.  The subtype may assume this responsibility only if
  197.43 - * the class it extends has an accessible no-arg constructor to
  197.44 - * initialize the class's state.  It is an error to declare a class
  197.45 - * Serializable if this is not the case.  The error will be detected at
  197.46 - * runtime. <p>
  197.47 - *
  197.48 - * During deserialization, the fields of non-serializable classes will
  197.49 - * be initialized using the public or protected no-arg constructor of
  197.50 - * the class.  A no-arg constructor must be accessible to the subclass
  197.51 - * that is serializable.  The fields of serializable subclasses will
  197.52 - * be restored from the stream. <p>
  197.53 - *
  197.54 - * When traversing a graph, an object may be encountered that does not
  197.55 - * support the Serializable interface. In this case the
  197.56 - * NotSerializableException will be thrown and will identify the class
  197.57 - * of the non-serializable object. <p>
  197.58 - *
  197.59 - * Classes that require special handling during the serialization and
  197.60 - * deserialization process must implement special methods with these exact
  197.61 - * signatures: <p>
  197.62 - *
  197.63 - * <PRE>
  197.64 - * private void writeObject(java.io.ObjectOutputStream out)
  197.65 - *     throws IOException
  197.66 - * private void readObject(java.io.ObjectInputStream in)
  197.67 - *     throws IOException, ClassNotFoundException;
  197.68 - * private void readObjectNoData()
  197.69 - *     throws ObjectStreamException;
  197.70 - * </PRE>
  197.71 - *
  197.72 - * <p>The writeObject method is responsible for writing the state of the
  197.73 - * object for its particular class so that the corresponding
  197.74 - * readObject method can restore it.  The default mechanism for saving
  197.75 - * the Object's fields can be invoked by calling
  197.76 - * out.defaultWriteObject. The method does not need to concern
  197.77 - * itself with the state belonging to its superclasses or subclasses.
  197.78 - * State is saved by writing the individual fields to the
  197.79 - * ObjectOutputStream using the writeObject method or by using the
  197.80 - * methods for primitive data types supported by DataOutput.
  197.81 - *
  197.82 - * <p>The readObject method is responsible for reading from the stream and
  197.83 - * restoring the classes fields. It may call in.defaultReadObject to invoke
  197.84 - * the default mechanism for restoring the object's non-static and
  197.85 - * non-transient fields.  The defaultReadObject method uses information in
  197.86 - * the stream to assign the fields of the object saved in the stream with the
  197.87 - * correspondingly named fields in the current object.  This handles the case
  197.88 - * when the class has evolved to add new fields. The method does not need to
  197.89 - * concern itself with the state belonging to its superclasses or subclasses.
  197.90 - * State is saved by writing the individual fields to the
  197.91 - * ObjectOutputStream using the writeObject method or by using the
  197.92 - * methods for primitive data types supported by DataOutput.
  197.93 - *
  197.94 - * <p>The readObjectNoData method is responsible for initializing the state of
  197.95 - * the object for its particular class in the event that the serialization
  197.96 - * stream does not list the given class as a superclass of the object being
  197.97 - * deserialized.  This may occur in cases where the receiving party uses a
  197.98 - * different version of the deserialized instance's class than the sending
  197.99 - * party, and the receiver's version extends classes that are not extended by
 197.100 - * the sender's version.  This may also occur if the serialization stream has
 197.101 - * been tampered; hence, readObjectNoData is useful for initializing
 197.102 - * deserialized objects properly despite a "hostile" or incomplete source
 197.103 - * stream.
 197.104 - *
 197.105 - * <p>Serializable classes that need to designate an alternative object to be
 197.106 - * used when writing an object to the stream should implement this
 197.107 - * special method with the exact signature: <p>
 197.108 - *
 197.109 - * <PRE>
 197.110 - * ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
 197.111 - * </PRE><p>
 197.112 - *
 197.113 - * This writeReplace method is invoked by serialization if the method
 197.114 - * exists and it would be accessible from a method defined within the
 197.115 - * class of the object being serialized. Thus, the method can have private,
 197.116 - * protected and package-private access. Subclass access to this method
 197.117 - * follows java accessibility rules. <p>
 197.118 - *
 197.119 - * Classes that need to designate a replacement when an instance of it
 197.120 - * is read from the stream should implement this special method with the
 197.121 - * exact signature.<p>
 197.122 - *
 197.123 - * <PRE>
 197.124 - * ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
 197.125 - * </PRE><p>
 197.126 - *
 197.127 - * This readResolve method follows the same invocation rules and
 197.128 - * accessibility rules as writeReplace.<p>
 197.129 - *
 197.130 - * The serialization runtime associates with each serializable class a version
 197.131 - * number, called a serialVersionUID, which is used during deserialization to
 197.132 - * verify that the sender and receiver of a serialized object have loaded
 197.133 - * classes for that object that are compatible with respect to serialization.
 197.134 - * If the receiver has loaded a class for the object that has a different
 197.135 - * serialVersionUID than that of the corresponding sender's class, then
 197.136 - * deserialization will result in an {@link InvalidClassException}.  A
 197.137 - * serializable class can declare its own serialVersionUID explicitly by
 197.138 - * declaring a field named <code>"serialVersionUID"</code> that must be static,
 197.139 - * final, and of type <code>long</code>:<p>
 197.140 - *
 197.141 - * <PRE>
 197.142 - * ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
 197.143 - * </PRE>
 197.144 - *
 197.145 - * If a serializable class does not explicitly declare a serialVersionUID, then
 197.146 - * the serialization runtime will calculate a default serialVersionUID value
 197.147 - * for that class based on various aspects of the class, as described in the
 197.148 - * Java(TM) Object Serialization Specification.  However, it is <em>strongly
 197.149 - * recommended</em> that all serializable classes explicitly declare
 197.150 - * serialVersionUID values, since the default serialVersionUID computation is
 197.151 - * highly sensitive to class details that may vary depending on compiler
 197.152 - * implementations, and can thus result in unexpected
 197.153 - * <code>InvalidClassException</code>s during deserialization.  Therefore, to
 197.154 - * guarantee a consistent serialVersionUID value across different java compiler
 197.155 - * implementations, a serializable class must declare an explicit
 197.156 - * serialVersionUID value.  It is also strongly advised that explicit
 197.157 - * serialVersionUID declarations use the <code>private</code> modifier where
 197.158 - * possible, since such declarations apply only to the immediately declaring
 197.159 - * class--serialVersionUID fields are not useful as inherited members. Array
 197.160 - * classes cannot declare an explicit serialVersionUID, so they always have
 197.161 - * the default computed value, but the requirement for matching
 197.162 - * serialVersionUID values is waived for array classes.
 197.163 - *
 197.164 - * @author  unascribed
 197.165 - * @see java.io.ObjectOutputStream
 197.166 - * @see java.io.ObjectInputStream
 197.167 - * @see java.io.ObjectOutput
 197.168 - * @see java.io.ObjectInput
 197.169 - * @see java.io.Externalizable
 197.170 - * @since   JDK1.1
 197.171 - */
 197.172 -public interface Serializable {
 197.173 -}
   198.1 --- a/emul/src/main/java/java/io/UTFDataFormatException.java	Wed Dec 05 10:03:58 2012 +0100
   198.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   198.3 @@ -1,69 +0,0 @@
   198.4 -/*
   198.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   198.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   198.7 - *
   198.8 - * This code is free software; you can redistribute it and/or modify it
   198.9 - * under the terms of the GNU General Public License version 2 only, as
  198.10 - * published by the Free Software Foundation.  Oracle designates this
  198.11 - * particular file as subject to the "Classpath" exception as provided
  198.12 - * by Oracle in the LICENSE file that accompanied this code.
  198.13 - *
  198.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  198.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  198.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  198.17 - * version 2 for more details (a copy is included in the LICENSE file that
  198.18 - * accompanied this code).
  198.19 - *
  198.20 - * You should have received a copy of the GNU General Public License version
  198.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  198.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  198.23 - *
  198.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  198.25 - * or visit www.oracle.com if you need additional information or have any
  198.26 - * questions.
  198.27 - */
  198.28 -
  198.29 -package java.io;
  198.30 -
  198.31 -/**
  198.32 - * Signals that a malformed string in
  198.33 - * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
  198.34 - * format has been read in a data
  198.35 - * input stream or by any class that implements the data input
  198.36 - * interface.
  198.37 - * See the
  198.38 - * <a href="DataInput.html#modified-utf-8"><code>DataInput</code></a>
  198.39 - * class description for the format in
  198.40 - * which modified UTF-8 strings are read and written.
  198.41 - *
  198.42 - * @author  Frank Yellin
  198.43 - * @see     java.io.DataInput
  198.44 - * @see     java.io.DataInputStream#readUTF(java.io.DataInput)
  198.45 - * @see     java.io.IOException
  198.46 - * @since   JDK1.0
  198.47 - */
  198.48 -public
  198.49 -class UTFDataFormatException extends IOException {
  198.50 -    private static final long serialVersionUID = 420743449228280612L;
  198.51 -
  198.52 -    /**
  198.53 -     * Constructs a <code>UTFDataFormatException</code> with
  198.54 -     * <code>null</code> as its error detail message.
  198.55 -     */
  198.56 -    public UTFDataFormatException() {
  198.57 -        super();
  198.58 -    }
  198.59 -
  198.60 -    /**
  198.61 -     * Constructs a <code>UTFDataFormatException</code> with the
  198.62 -     * specified detail message. The string <code>s</code> can be
  198.63 -     * retrieved later by the
  198.64 -     * <code>{@link java.lang.Throwable#getMessage}</code>
  198.65 -     * method of class <code>java.lang.Throwable</code>.
  198.66 -     *
  198.67 -     * @param   s   the detail message.
  198.68 -     */
  198.69 -    public UTFDataFormatException(String s) {
  198.70 -        super(s);
  198.71 -    }
  198.72 -}
   199.1 --- a/emul/src/main/java/java/io/UnsupportedEncodingException.java	Wed Dec 05 10:03:58 2012 +0100
   199.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   199.3 @@ -1,52 +0,0 @@
   199.4 -/*
   199.5 - * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
   199.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   199.7 - *
   199.8 - * This code is free software; you can redistribute it and/or modify it
   199.9 - * under the terms of the GNU General Public License version 2 only, as
  199.10 - * published by the Free Software Foundation.  Oracle designates this
  199.11 - * particular file as subject to the "Classpath" exception as provided
  199.12 - * by Oracle in the LICENSE file that accompanied this code.
  199.13 - *
  199.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  199.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  199.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  199.17 - * version 2 for more details (a copy is included in the LICENSE file that
  199.18 - * accompanied this code).
  199.19 - *
  199.20 - * You should have received a copy of the GNU General Public License version
  199.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  199.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  199.23 - *
  199.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  199.25 - * or visit www.oracle.com if you need additional information or have any
  199.26 - * questions.
  199.27 - */
  199.28 -package java.io;
  199.29 -
  199.30 -/**
  199.31 - * The Character Encoding is not supported.
  199.32 - *
  199.33 - * @author  Asmus Freytag
  199.34 - * @since   JDK1.1
  199.35 - */
  199.36 -public class UnsupportedEncodingException
  199.37 -    extends IOException
  199.38 -{
  199.39 -    private static final long serialVersionUID = -4274276298326136670L;
  199.40 -
  199.41 -    /**
  199.42 -     * Constructs an UnsupportedEncodingException without a detail message.
  199.43 -     */
  199.44 -    public UnsupportedEncodingException() {
  199.45 -        super();
  199.46 -    }
  199.47 -
  199.48 -    /**
  199.49 -     * Constructs an UnsupportedEncodingException with a detail message.
  199.50 -     * @param s Describes the reason for the exception.
  199.51 -     */
  199.52 -    public UnsupportedEncodingException(String s) {
  199.53 -        super(s);
  199.54 -    }
  199.55 -}
   200.1 --- a/emul/src/main/java/java/lang/AbstractStringBuilder.java	Wed Dec 05 10:03:58 2012 +0100
   200.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   200.3 @@ -1,1425 +0,0 @@
   200.4 -/*
   200.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   200.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   200.7 - *
   200.8 - * This code is free software; you can redistribute it and/or modify it
   200.9 - * under the terms of the GNU General Public License version 2 only, as
  200.10 - * published by the Free Software Foundation.  Oracle designates this
  200.11 - * particular file as subject to the "Classpath" exception as provided
  200.12 - * by Oracle in the LICENSE file that accompanied this code.
  200.13 - *
  200.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  200.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  200.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  200.17 - * version 2 for more details (a copy is included in the LICENSE file that
  200.18 - * accompanied this code).
  200.19 - *
  200.20 - * You should have received a copy of the GNU General Public License version
  200.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  200.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  200.23 - *
  200.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  200.25 - * or visit www.oracle.com if you need additional information or have any
  200.26 - * questions.
  200.27 - */
  200.28 -
  200.29 -package java.lang;
  200.30 -
  200.31 -/**
  200.32 - * A mutable sequence of characters.
  200.33 - * <p>
  200.34 - * Implements a modifiable string. At any point in time it contains some
  200.35 - * particular sequence of characters, but the length and content of the
  200.36 - * sequence can be changed through certain method calls.
  200.37 - *
  200.38 - * @author      Michael McCloskey
  200.39 - * @author      Martin Buchholz
  200.40 - * @author      Ulf Zibis
  200.41 - * @since       1.5
  200.42 - */
  200.43 -abstract class AbstractStringBuilder implements Appendable, CharSequence {
  200.44 -    /**
  200.45 -     * The value is used for character storage.
  200.46 -     */
  200.47 -    char[] value;
  200.48 -
  200.49 -    /**
  200.50 -     * The count is the number of characters used.
  200.51 -     */
  200.52 -    int count;
  200.53 -
  200.54 -    /**
  200.55 -     * This no-arg constructor is necessary for serialization of subclasses.
  200.56 -     */
  200.57 -    AbstractStringBuilder() {
  200.58 -    }
  200.59 -
  200.60 -    /**
  200.61 -     * Creates an AbstractStringBuilder of the specified capacity.
  200.62 -     */
  200.63 -    AbstractStringBuilder(int capacity) {
  200.64 -        value = new char[capacity];
  200.65 -    }
  200.66 -
  200.67 -    /**
  200.68 -     * Returns the length (character count).
  200.69 -     *
  200.70 -     * @return  the length of the sequence of characters currently
  200.71 -     *          represented by this object
  200.72 -     */
  200.73 -    public int length() {
  200.74 -        return count;
  200.75 -    }
  200.76 -
  200.77 -    /**
  200.78 -     * Returns the current capacity. The capacity is the amount of storage
  200.79 -     * available for newly inserted characters, beyond which an allocation
  200.80 -     * will occur.
  200.81 -     *
  200.82 -     * @return  the current capacity
  200.83 -     */
  200.84 -    public int capacity() {
  200.85 -        return value.length;
  200.86 -    }
  200.87 -
  200.88 -    /**
  200.89 -     * Ensures that the capacity is at least equal to the specified minimum.
  200.90 -     * If the current capacity is less than the argument, then a new internal
  200.91 -     * array is allocated with greater capacity. The new capacity is the
  200.92 -     * larger of:
  200.93 -     * <ul>
  200.94 -     * <li>The <code>minimumCapacity</code> argument.
  200.95 -     * <li>Twice the old capacity, plus <code>2</code>.
  200.96 -     * </ul>
  200.97 -     * If the <code>minimumCapacity</code> argument is nonpositive, this
  200.98 -     * method takes no action and simply returns.
  200.99 -     *
 200.100 -     * @param   minimumCapacity   the minimum desired capacity.
 200.101 -     */
 200.102 -    public void ensureCapacity(int minimumCapacity) {
 200.103 -        if (minimumCapacity > 0)
 200.104 -            ensureCapacityInternal(minimumCapacity);
 200.105 -    }
 200.106 -
 200.107 -    /**
 200.108 -     * This method has the same contract as ensureCapacity, but is
 200.109 -     * never synchronized.
 200.110 -     */
 200.111 -    private void ensureCapacityInternal(int minimumCapacity) {
 200.112 -        // overflow-conscious code
 200.113 -        if (minimumCapacity - value.length > 0)
 200.114 -            expandCapacity(minimumCapacity);
 200.115 -    }
 200.116 -
 200.117 -    /**
 200.118 -     * This implements the expansion semantics of ensureCapacity with no
 200.119 -     * size check or synchronization.
 200.120 -     */
 200.121 -    void expandCapacity(int minimumCapacity) {
 200.122 -        int newCapacity = value.length * 2 + 2;
 200.123 -        if (newCapacity - minimumCapacity < 0)
 200.124 -            newCapacity = minimumCapacity;
 200.125 -        if (newCapacity < 0) {
 200.126 -            if (minimumCapacity < 0) // overflow
 200.127 -                throw new OutOfMemoryError();
 200.128 -            newCapacity = Integer.MAX_VALUE;
 200.129 -        }
 200.130 -        value = copyOf(value, newCapacity);
 200.131 -    }
 200.132 -
 200.133 -    /**
 200.134 -     * Attempts to reduce storage used for the character sequence.
 200.135 -     * If the buffer is larger than necessary to hold its current sequence of
 200.136 -     * characters, then it may be resized to become more space efficient.
 200.137 -     * Calling this method may, but is not required to, affect the value
 200.138 -     * returned by a subsequent call to the {@link #capacity()} method.
 200.139 -     */
 200.140 -    public void trimToSize() {
 200.141 -        if (count < value.length) {
 200.142 -            value = copyOf(value, count);
 200.143 -        }
 200.144 -    }
 200.145 -
 200.146 -    /**
 200.147 -     * Sets the length of the character sequence.
 200.148 -     * The sequence is changed to a new character sequence
 200.149 -     * whose length is specified by the argument. For every nonnegative
 200.150 -     * index <i>k</i> less than <code>newLength</code>, the character at
 200.151 -     * index <i>k</i> in the new character sequence is the same as the
 200.152 -     * character at index <i>k</i> in the old sequence if <i>k</i> is less
 200.153 -     * than the length of the old character sequence; otherwise, it is the
 200.154 -     * null character <code>'&#92;u0000'</code>.
 200.155 -     *
 200.156 -     * In other words, if the <code>newLength</code> argument is less than
 200.157 -     * the current length, the length is changed to the specified length.
 200.158 -     * <p>
 200.159 -     * If the <code>newLength</code> argument is greater than or equal
 200.160 -     * to the current length, sufficient null characters
 200.161 -     * (<code>'&#92;u0000'</code>) are appended so that
 200.162 -     * length becomes the <code>newLength</code> argument.
 200.163 -     * <p>
 200.164 -     * The <code>newLength</code> argument must be greater than or equal
 200.165 -     * to <code>0</code>.
 200.166 -     *
 200.167 -     * @param      newLength   the new length
 200.168 -     * @throws     IndexOutOfBoundsException  if the
 200.169 -     *               <code>newLength</code> argument is negative.
 200.170 -     */
 200.171 -    public void setLength(int newLength) {
 200.172 -        if (newLength < 0)
 200.173 -            throw new StringIndexOutOfBoundsException(newLength);
 200.174 -        ensureCapacityInternal(newLength);
 200.175 -
 200.176 -        if (count < newLength) {
 200.177 -            for (; count < newLength; count++)
 200.178 -                value[count] = '\0';
 200.179 -        } else {
 200.180 -            count = newLength;
 200.181 -        }
 200.182 -    }
 200.183 -
 200.184 -    /**
 200.185 -     * Returns the <code>char</code> value in this sequence at the specified index.
 200.186 -     * The first <code>char</code> value is at index <code>0</code>, the next at index
 200.187 -     * <code>1</code>, and so on, as in array indexing.
 200.188 -     * <p>
 200.189 -     * The index argument must be greater than or equal to
 200.190 -     * <code>0</code>, and less than the length of this sequence.
 200.191 -     *
 200.192 -     * <p>If the <code>char</code> value specified by the index is a
 200.193 -     * <a href="Character.html#unicode">surrogate</a>, the surrogate
 200.194 -     * value is returned.
 200.195 -     *
 200.196 -     * @param      index   the index of the desired <code>char</code> value.
 200.197 -     * @return     the <code>char</code> value at the specified index.
 200.198 -     * @throws     IndexOutOfBoundsException  if <code>index</code> is
 200.199 -     *             negative or greater than or equal to <code>length()</code>.
 200.200 -     */
 200.201 -    public char charAt(int index) {
 200.202 -        if ((index < 0) || (index >= count))
 200.203 -            throw new StringIndexOutOfBoundsException(index);
 200.204 -        return value[index];
 200.205 -    }
 200.206 -
 200.207 -    /**
 200.208 -     * Returns the character (Unicode code point) at the specified
 200.209 -     * index. The index refers to <code>char</code> values
 200.210 -     * (Unicode code units) and ranges from <code>0</code> to
 200.211 -     * {@link #length()}<code> - 1</code>.
 200.212 -     *
 200.213 -     * <p> If the <code>char</code> value specified at the given index
 200.214 -     * is in the high-surrogate range, the following index is less
 200.215 -     * than the length of this sequence, and the
 200.216 -     * <code>char</code> value at the following index is in the
 200.217 -     * low-surrogate range, then the supplementary code point
 200.218 -     * corresponding to this surrogate pair is returned. Otherwise,
 200.219 -     * the <code>char</code> value at the given index is returned.
 200.220 -     *
 200.221 -     * @param      index the index to the <code>char</code> values
 200.222 -     * @return     the code point value of the character at the
 200.223 -     *             <code>index</code>
 200.224 -     * @exception  IndexOutOfBoundsException  if the <code>index</code>
 200.225 -     *             argument is negative or not less than the length of this
 200.226 -     *             sequence.
 200.227 -     */
 200.228 -    public int codePointAt(int index) {
 200.229 -        if ((index < 0) || (index >= count)) {
 200.230 -            throw new StringIndexOutOfBoundsException(index);
 200.231 -        }
 200.232 -        return Character.codePointAt(value, index);
 200.233 -    }
 200.234 -
 200.235 -    /**
 200.236 -     * Returns the character (Unicode code point) before the specified
 200.237 -     * index. The index refers to <code>char</code> values
 200.238 -     * (Unicode code units) and ranges from <code>1</code> to {@link
 200.239 -     * #length()}.
 200.240 -     *
 200.241 -     * <p> If the <code>char</code> value at <code>(index - 1)</code>
 200.242 -     * is in the low-surrogate range, <code>(index - 2)</code> is not
 200.243 -     * negative, and the <code>char</code> value at <code>(index -
 200.244 -     * 2)</code> is in the high-surrogate range, then the
 200.245 -     * supplementary code point value of the surrogate pair is
 200.246 -     * returned. If the <code>char</code> value at <code>index -
 200.247 -     * 1</code> is an unpaired low-surrogate or a high-surrogate, the
 200.248 -     * surrogate value is returned.
 200.249 -     *
 200.250 -     * @param     index the index following the code point that should be returned
 200.251 -     * @return    the Unicode code point value before the given index.
 200.252 -     * @exception IndexOutOfBoundsException if the <code>index</code>
 200.253 -     *            argument is less than 1 or greater than the length
 200.254 -     *            of this sequence.
 200.255 -     */
 200.256 -    public int codePointBefore(int index) {
 200.257 -        int i = index - 1;
 200.258 -        if ((i < 0) || (i >= count)) {
 200.259 -            throw new StringIndexOutOfBoundsException(index);
 200.260 -        }
 200.261 -        return Character.codePointBefore(value, index);
 200.262 -    }
 200.263 -
 200.264 -    /**
 200.265 -     * Returns the number of Unicode code points in the specified text
 200.266 -     * range of this sequence. The text range begins at the specified
 200.267 -     * <code>beginIndex</code> and extends to the <code>char</code> at
 200.268 -     * index <code>endIndex - 1</code>. Thus the length (in
 200.269 -     * <code>char</code>s) of the text range is
 200.270 -     * <code>endIndex-beginIndex</code>. Unpaired surrogates within
 200.271 -     * this sequence count as one code point each.
 200.272 -     *
 200.273 -     * @param beginIndex the index to the first <code>char</code> of
 200.274 -     * the text range.
 200.275 -     * @param endIndex the index after the last <code>char</code> of
 200.276 -     * the text range.
 200.277 -     * @return the number of Unicode code points in the specified text
 200.278 -     * range
 200.279 -     * @exception IndexOutOfBoundsException if the
 200.280 -     * <code>beginIndex</code> is negative, or <code>endIndex</code>
 200.281 -     * is larger than the length of this sequence, or
 200.282 -     * <code>beginIndex</code> is larger than <code>endIndex</code>.
 200.283 -     */
 200.284 -    public int codePointCount(int beginIndex, int endIndex) {
 200.285 -        if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
 200.286 -            throw new IndexOutOfBoundsException();
 200.287 -        }
 200.288 -        return Character.codePointCountImpl(value, beginIndex, endIndex-beginIndex);
 200.289 -    }
 200.290 -
 200.291 -    /**
 200.292 -     * Returns the index within this sequence that is offset from the
 200.293 -     * given <code>index</code> by <code>codePointOffset</code> code
 200.294 -     * points. Unpaired surrogates within the text range given by
 200.295 -     * <code>index</code> and <code>codePointOffset</code> count as
 200.296 -     * one code point each.
 200.297 -     *
 200.298 -     * @param index the index to be offset
 200.299 -     * @param codePointOffset the offset in code points
 200.300 -     * @return the index within this sequence
 200.301 -     * @exception IndexOutOfBoundsException if <code>index</code>
 200.302 -     *   is negative or larger then the length of this sequence,
 200.303 -     *   or if <code>codePointOffset</code> is positive and the subsequence
 200.304 -     *   starting with <code>index</code> has fewer than
 200.305 -     *   <code>codePointOffset</code> code points,
 200.306 -     *   or if <code>codePointOffset</code> is negative and the subsequence
 200.307 -     *   before <code>index</code> has fewer than the absolute value of
 200.308 -     *   <code>codePointOffset</code> code points.
 200.309 -     */
 200.310 -    public int offsetByCodePoints(int index, int codePointOffset) {
 200.311 -        if (index < 0 || index > count) {
 200.312 -            throw new IndexOutOfBoundsException();
 200.313 -        }
 200.314 -        return Character.offsetByCodePointsImpl(value, 0, count,
 200.315 -                                                index, codePointOffset);
 200.316 -    }
 200.317 -
 200.318 -    /**
 200.319 -     * Characters are copied from this sequence into the
 200.320 -     * destination character array <code>dst</code>. The first character to
 200.321 -     * be copied is at index <code>srcBegin</code>; the last character to
 200.322 -     * be copied is at index <code>srcEnd-1</code>. The total number of
 200.323 -     * characters to be copied is <code>srcEnd-srcBegin</code>. The
 200.324 -     * characters are copied into the subarray of <code>dst</code> starting
 200.325 -     * at index <code>dstBegin</code> and ending at index:
 200.326 -     * <p><blockquote><pre>
 200.327 -     * dstbegin + (srcEnd-srcBegin) - 1
 200.328 -     * </pre></blockquote>
 200.329 -     *
 200.330 -     * @param      srcBegin   start copying at this offset.
 200.331 -     * @param      srcEnd     stop copying at this offset.
 200.332 -     * @param      dst        the array to copy the data into.
 200.333 -     * @param      dstBegin   offset into <code>dst</code>.
 200.334 -     * @throws     NullPointerException if <code>dst</code> is
 200.335 -     *             <code>null</code>.
 200.336 -     * @throws     IndexOutOfBoundsException  if any of the following is true:
 200.337 -     *             <ul>
 200.338 -     *             <li><code>srcBegin</code> is negative
 200.339 -     *             <li><code>dstBegin</code> is negative
 200.340 -     *             <li>the <code>srcBegin</code> argument is greater than
 200.341 -     *             the <code>srcEnd</code> argument.
 200.342 -     *             <li><code>srcEnd</code> is greater than
 200.343 -     *             <code>this.length()</code>.
 200.344 -     *             <li><code>dstBegin+srcEnd-srcBegin</code> is greater than
 200.345 -     *             <code>dst.length</code>
 200.346 -     *             </ul>
 200.347 -     */
 200.348 -    public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
 200.349 -    {
 200.350 -        if (srcBegin < 0)
 200.351 -            throw new StringIndexOutOfBoundsException(srcBegin);
 200.352 -        if ((srcEnd < 0) || (srcEnd > count))
 200.353 -            throw new StringIndexOutOfBoundsException(srcEnd);
 200.354 -        if (srcBegin > srcEnd)
 200.355 -            throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
 200.356 -        arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
 200.357 -    }
 200.358 -
 200.359 -    /**
 200.360 -     * The character at the specified index is set to <code>ch</code>. This
 200.361 -     * sequence is altered to represent a new character sequence that is
 200.362 -     * identical to the old character sequence, except that it contains the
 200.363 -     * character <code>ch</code> at position <code>index</code>.
 200.364 -     * <p>
 200.365 -     * The index argument must be greater than or equal to
 200.366 -     * <code>0</code>, and less than the length of this sequence.
 200.367 -     *
 200.368 -     * @param      index   the index of the character to modify.
 200.369 -     * @param      ch      the new character.
 200.370 -     * @throws     IndexOutOfBoundsException  if <code>index</code> is
 200.371 -     *             negative or greater than or equal to <code>length()</code>.
 200.372 -     */
 200.373 -    public void setCharAt(int index, char ch) {
 200.374 -        if ((index < 0) || (index >= count))
 200.375 -            throw new StringIndexOutOfBoundsException(index);
 200.376 -        value[index] = ch;
 200.377 -    }
 200.378 -
 200.379 -    /**
 200.380 -     * Appends the string representation of the {@code Object} argument.
 200.381 -     * <p>
 200.382 -     * The overall effect is exactly as if the argument were converted
 200.383 -     * to a string by the method {@link String#valueOf(Object)},
 200.384 -     * and the characters of that string were then
 200.385 -     * {@link #append(String) appended} to this character sequence.
 200.386 -     *
 200.387 -     * @param   obj   an {@code Object}.
 200.388 -     * @return  a reference to this object.
 200.389 -     */
 200.390 -    public AbstractStringBuilder append(Object obj) {
 200.391 -        return append(String.valueOf(obj));
 200.392 -    }
 200.393 -
 200.394 -    /**
 200.395 -     * Appends the specified string to this character sequence.
 200.396 -     * <p>
 200.397 -     * The characters of the {@code String} argument are appended, in
 200.398 -     * order, increasing the length of this sequence by the length of the
 200.399 -     * argument. If {@code str} is {@code null}, then the four
 200.400 -     * characters {@code "null"} are appended.
 200.401 -     * <p>
 200.402 -     * Let <i>n</i> be the length of this character sequence just prior to
 200.403 -     * execution of the {@code append} method. Then the character at
 200.404 -     * index <i>k</i> in the new character sequence is equal to the character
 200.405 -     * at index <i>k</i> in the old character sequence, if <i>k</i> is less
 200.406 -     * than <i>n</i>; otherwise, it is equal to the character at index
 200.407 -     * <i>k-n</i> in the argument {@code str}.
 200.408 -     *
 200.409 -     * @param   str   a string.
 200.410 -     * @return  a reference to this object.
 200.411 -     */
 200.412 -    public AbstractStringBuilder append(String str) {
 200.413 -        if (str == null) str = "null";
 200.414 -        int len = str.length();
 200.415 -        ensureCapacityInternal(count + len);
 200.416 -        str.getChars(0, len, value, count);
 200.417 -        count += len;
 200.418 -        return this;
 200.419 -    }
 200.420 -
 200.421 -    // Documentation in subclasses because of synchro difference
 200.422 -    public AbstractStringBuilder append(StringBuffer sb) {
 200.423 -        if (sb == null)
 200.424 -            return append("null");
 200.425 -        int len = sb.length();
 200.426 -        ensureCapacityInternal(count + len);
 200.427 -        sb.getChars(0, len, value, count);
 200.428 -        count += len;
 200.429 -        return this;
 200.430 -    }
 200.431 -
 200.432 -    // Documentation in subclasses because of synchro difference
 200.433 -    public AbstractStringBuilder append(CharSequence s) {
 200.434 -        if (s == null)
 200.435 -            s = "null";
 200.436 -        if (s instanceof String)
 200.437 -            return this.append((String)s);
 200.438 -        if (s instanceof StringBuffer)
 200.439 -            return this.append((StringBuffer)s);
 200.440 -        return this.append(s, 0, s.length());
 200.441 -    }
 200.442 -
 200.443 -    /**
 200.444 -     * Appends a subsequence of the specified {@code CharSequence} to this
 200.445 -     * sequence.
 200.446 -     * <p>
 200.447 -     * Characters of the argument {@code s}, starting at
 200.448 -     * index {@code start}, are appended, in order, to the contents of
 200.449 -     * this sequence up to the (exclusive) index {@code end}. The length
 200.450 -     * of this sequence is increased by the value of {@code end - start}.
 200.451 -     * <p>
 200.452 -     * Let <i>n</i> be the length of this character sequence just prior to
 200.453 -     * execution of the {@code append} method. Then the character at
 200.454 -     * index <i>k</i> in this character sequence becomes equal to the
 200.455 -     * character at index <i>k</i> in this sequence, if <i>k</i> is less than
 200.456 -     * <i>n</i>; otherwise, it is equal to the character at index
 200.457 -     * <i>k+start-n</i> in the argument {@code s}.
 200.458 -     * <p>
 200.459 -     * If {@code s} is {@code null}, then this method appends
 200.460 -     * characters as if the s parameter was a sequence containing the four
 200.461 -     * characters {@code "null"}.
 200.462 -     *
 200.463 -     * @param   s the sequence to append.
 200.464 -     * @param   start   the starting index of the subsequence to be appended.
 200.465 -     * @param   end     the end index of the subsequence to be appended.
 200.466 -     * @return  a reference to this object.
 200.467 -     * @throws     IndexOutOfBoundsException if
 200.468 -     *             {@code start} is negative, or
 200.469 -     *             {@code start} is greater than {@code end} or
 200.470 -     *             {@code end} is greater than {@code s.length()}
 200.471 -     */
 200.472 -    public AbstractStringBuilder append(CharSequence s, int start, int end) {
 200.473 -        if (s == null)
 200.474 -            s = "null";
 200.475 -        if ((start < 0) || (start > end) || (end > s.length()))
 200.476 -            throw new IndexOutOfBoundsException(
 200.477 -                "start " + start + ", end " + end + ", s.length() "
 200.478 -                + s.length());
 200.479 -        int len = end - start;
 200.480 -        ensureCapacityInternal(count + len);
 200.481 -        for (int i = start, j = count; i < end; i++, j++)
 200.482 -            value[j] = s.charAt(i);
 200.483 -        count += len;
 200.484 -        return this;
 200.485 -    }
 200.486 -
 200.487 -    /**
 200.488 -     * Appends the string representation of the {@code char} array
 200.489 -     * argument to this sequence.
 200.490 -     * <p>
 200.491 -     * The characters of the array argument are appended, in order, to
 200.492 -     * the contents of this sequence. The length of this sequence
 200.493 -     * increases by the length of the argument.
 200.494 -     * <p>
 200.495 -     * The overall effect is exactly as if the argument were converted
 200.496 -     * to a string by the method {@link String#valueOf(char[])},
 200.497 -     * and the characters of that string were then
 200.498 -     * {@link #append(String) appended} to this character sequence.
 200.499 -     *
 200.500 -     * @param   str   the characters to be appended.
 200.501 -     * @return  a reference to this object.
 200.502 -     */
 200.503 -    public AbstractStringBuilder append(char[] str) {
 200.504 -        int len = str.length;
 200.505 -        ensureCapacityInternal(count + len);
 200.506 -        arraycopy(str, 0, value, count, len);
 200.507 -        count += len;
 200.508 -        return this;
 200.509 -    }
 200.510 -
 200.511 -    /**
 200.512 -     * Appends the string representation of a subarray of the
 200.513 -     * {@code char} array argument to this sequence.
 200.514 -     * <p>
 200.515 -     * Characters of the {@code char} array {@code str}, starting at
 200.516 -     * index {@code offset}, are appended, in order, to the contents
 200.517 -     * of this sequence. The length of this sequence increases
 200.518 -     * by the value of {@code len}.
 200.519 -     * <p>
 200.520 -     * The overall effect is exactly as if the arguments were converted
 200.521 -     * to a string by the method {@link String#valueOf(char[],int,int)},
 200.522 -     * and the characters of that string were then
 200.523 -     * {@link #append(String) appended} to this character sequence.
 200.524 -     *
 200.525 -     * @param   str      the characters to be appended.
 200.526 -     * @param   offset   the index of the first {@code char} to append.
 200.527 -     * @param   len      the number of {@code char}s to append.
 200.528 -     * @return  a reference to this object.
 200.529 -     * @throws IndexOutOfBoundsException
 200.530 -     *         if {@code offset < 0} or {@code len < 0}
 200.531 -     *         or {@code offset+len > str.length}
 200.532 -     */
 200.533 -    public AbstractStringBuilder append(char str[], int offset, int len) {
 200.534 -        if (len > 0)                // let arraycopy report AIOOBE for len < 0
 200.535 -            ensureCapacityInternal(count + len);
 200.536 -        arraycopy(str, offset, value, count, len);
 200.537 -        count += len;
 200.538 -        return this;
 200.539 -    }
 200.540 -
 200.541 -    /**
 200.542 -     * Appends the string representation of the {@code boolean}
 200.543 -     * argument to the sequence.
 200.544 -     * <p>
 200.545 -     * The overall effect is exactly as if the argument were converted
 200.546 -     * to a string by the method {@link String#valueOf(boolean)},
 200.547 -     * and the characters of that string were then
 200.548 -     * {@link #append(String) appended} to this character sequence.
 200.549 -     *
 200.550 -     * @param   b   a {@code boolean}.
 200.551 -     * @return  a reference to this object.
 200.552 -     */
 200.553 -    public AbstractStringBuilder append(boolean b) {
 200.554 -        if (b) {
 200.555 -            ensureCapacityInternal(count + 4);
 200.556 -            value[count++] = 't';
 200.557 -            value[count++] = 'r';
 200.558 -            value[count++] = 'u';
 200.559 -            value[count++] = 'e';
 200.560 -        } else {
 200.561 -            ensureCapacityInternal(count + 5);
 200.562 -            value[count++] = 'f';
 200.563 -            value[count++] = 'a';
 200.564 -            value[count++] = 'l';
 200.565 -            value[count++] = 's';
 200.566 -            value[count++] = 'e';
 200.567 -        }
 200.568 -        return this;
 200.569 -    }
 200.570 -
 200.571 -    /**
 200.572 -     * Appends the string representation of the {@code char}
 200.573 -     * argument to this sequence.
 200.574 -     * <p>
 200.575 -     * The argument is appended to the contents of this sequence.
 200.576 -     * The length of this sequence increases by {@code 1}.
 200.577 -     * <p>
 200.578 -     * The overall effect is exactly as if the argument were converted
 200.579 -     * to a string by the method {@link String#valueOf(char)},
 200.580 -     * and the character in that string were then
 200.581 -     * {@link #append(String) appended} to this character sequence.
 200.582 -     *
 200.583 -     * @param   c   a {@code char}.
 200.584 -     * @return  a reference to this object.
 200.585 -     */
 200.586 -    public AbstractStringBuilder append(char c) {
 200.587 -        ensureCapacityInternal(count + 1);
 200.588 -        value[count++] = c;
 200.589 -        return this;
 200.590 -    }
 200.591 -
 200.592 -    /**
 200.593 -     * Appends the string representation of the {@code int}
 200.594 -     * argument to this sequence.
 200.595 -     * <p>
 200.596 -     * The overall effect is exactly as if the argument were converted
 200.597 -     * to a string by the method {@link String#valueOf(int)},
 200.598 -     * and the characters of that string were then
 200.599 -     * {@link #append(String) appended} to this character sequence.
 200.600 -     *
 200.601 -     * @param   i   an {@code int}.
 200.602 -     * @return  a reference to this object.
 200.603 -     */
 200.604 -    public AbstractStringBuilder append(int i) {
 200.605 -        return append(Integer.toString(i));
 200.606 -    }
 200.607 -
 200.608 -    /**
 200.609 -     * Appends the string representation of the {@code long}
 200.610 -     * argument to this sequence.
 200.611 -     * <p>
 200.612 -     * The overall effect is exactly as if the argument were converted
 200.613 -     * to a string by the method {@link String#valueOf(long)},
 200.614 -     * and the characters of that string were then
 200.615 -     * {@link #append(String) appended} to this character sequence.
 200.616 -     *
 200.617 -     * @param   l   a {@code long}.
 200.618 -     * @return  a reference to this object.
 200.619 -     */
 200.620 -    public AbstractStringBuilder append(long l) {
 200.621 -        if (l == Long.MIN_VALUE) {
 200.622 -            append("-9223372036854775808");
 200.623 -            return this;
 200.624 -        }
 200.625 -        int appendedLength = (l < 0) ? Long.stringSize(-l) + 1
 200.626 -                                     : Long.stringSize(l);
 200.627 -        int spaceNeeded = count + appendedLength;
 200.628 -        ensureCapacityInternal(spaceNeeded);
 200.629 -        Long.getChars(l, spaceNeeded, value);
 200.630 -        count = spaceNeeded;
 200.631 -        return this;
 200.632 -    }
 200.633 -
 200.634 -    /**
 200.635 -     * Appends the string representation of the {@code float}
 200.636 -     * argument to this sequence.
 200.637 -     * <p>
 200.638 -     * The overall effect is exactly as if the argument were converted
 200.639 -     * to a string by the method {@link String#valueOf(float)},
 200.640 -     * and the characters of that string were then
 200.641 -     * {@link #append(String) appended} to this character sequence.
 200.642 -     *
 200.643 -     * @param   f   a {@code float}.
 200.644 -     * @return  a reference to this object.
 200.645 -     */
 200.646 -    public AbstractStringBuilder append(float f) {
 200.647 -        return append(Float.toString(f));
 200.648 -    }
 200.649 -
 200.650 -    /**
 200.651 -     * Appends the string representation of the {@code double}
 200.652 -     * argument to this sequence.
 200.653 -     * <p>
 200.654 -     * The overall effect is exactly as if the argument were converted
 200.655 -     * to a string by the method {@link String#valueOf(double)},
 200.656 -     * and the characters of that string were then
 200.657 -     * {@link #append(String) appended} to this character sequence.
 200.658 -     *
 200.659 -     * @param   d   a {@code double}.
 200.660 -     * @return  a reference to this object.
 200.661 -     */
 200.662 -    public AbstractStringBuilder append(double d) {
 200.663 -        return append(Double.toString(d));
 200.664 -    }
 200.665 -
 200.666 -    /**
 200.667 -     * Removes the characters in a substring of this sequence.
 200.668 -     * The substring begins at the specified {@code start} and extends to
 200.669 -     * the character at index {@code end - 1} or to the end of the
 200.670 -     * sequence if no such character exists. If
 200.671 -     * {@code start} is equal to {@code end}, no changes are made.
 200.672 -     *
 200.673 -     * @param      start  The beginning index, inclusive.
 200.674 -     * @param      end    The ending index, exclusive.
 200.675 -     * @return     This object.
 200.676 -     * @throws     StringIndexOutOfBoundsException  if {@code start}
 200.677 -     *             is negative, greater than {@code length()}, or
 200.678 -     *             greater than {@code end}.
 200.679 -     */
 200.680 -    public AbstractStringBuilder delete(int start, int end) {
 200.681 -        if (start < 0)
 200.682 -            throw new StringIndexOutOfBoundsException(start);
 200.683 -        if (end > count)
 200.684 -            end = count;
 200.685 -        if (start > end)
 200.686 -            throw new StringIndexOutOfBoundsException();
 200.687 -        int len = end - start;
 200.688 -        if (len > 0) {
 200.689 -            arraycopy(value, start+len, value, start, count-end);
 200.690 -            count -= len;
 200.691 -        }
 200.692 -        return this;
 200.693 -    }
 200.694 -
 200.695 -    /**
 200.696 -     * Appends the string representation of the {@code codePoint}
 200.697 -     * argument to this sequence.
 200.698 -     *
 200.699 -     * <p> The argument is appended to the contents of this sequence.
 200.700 -     * The length of this sequence increases by
 200.701 -     * {@link Character#charCount(int) Character.charCount(codePoint)}.
 200.702 -     *
 200.703 -     * <p> The overall effect is exactly as if the argument were
 200.704 -     * converted to a {@code char} array by the method
 200.705 -     * {@link Character#toChars(int)} and the character in that array
 200.706 -     * were then {@link #append(char[]) appended} to this character
 200.707 -     * sequence.
 200.708 -     *
 200.709 -     * @param   codePoint   a Unicode code point
 200.710 -     * @return  a reference to this object.
 200.711 -     * @exception IllegalArgumentException if the specified
 200.712 -     * {@code codePoint} isn't a valid Unicode code point
 200.713 -     */
 200.714 -    public AbstractStringBuilder appendCodePoint(int codePoint) {
 200.715 -        final int count = this.count;
 200.716 -
 200.717 -        if (Character.isBmpCodePoint(codePoint)) {
 200.718 -            ensureCapacityInternal(count + 1);
 200.719 -            value[count] = (char) codePoint;
 200.720 -            this.count = count + 1;
 200.721 -        } else if (Character.isValidCodePoint(codePoint)) {
 200.722 -            ensureCapacityInternal(count + 2);
 200.723 -            Character.toSurrogates(codePoint, value, count);
 200.724 -            this.count = count + 2;
 200.725 -        } else {
 200.726 -            throw new IllegalArgumentException();
 200.727 -        }
 200.728 -        return this;
 200.729 -    }
 200.730 -
 200.731 -    /**
 200.732 -     * Removes the <code>char</code> at the specified position in this
 200.733 -     * sequence. This sequence is shortened by one <code>char</code>.
 200.734 -     *
 200.735 -     * <p>Note: If the character at the given index is a supplementary
 200.736 -     * character, this method does not remove the entire character. If
 200.737 -     * correct handling of supplementary characters is required,
 200.738 -     * determine the number of <code>char</code>s to remove by calling
 200.739 -     * <code>Character.charCount(thisSequence.codePointAt(index))</code>,
 200.740 -     * where <code>thisSequence</code> is this sequence.
 200.741 -     *
 200.742 -     * @param       index  Index of <code>char</code> to remove
 200.743 -     * @return      This object.
 200.744 -     * @throws      StringIndexOutOfBoundsException  if the <code>index</code>
 200.745 -     *              is negative or greater than or equal to
 200.746 -     *              <code>length()</code>.
 200.747 -     */
 200.748 -    public AbstractStringBuilder deleteCharAt(int index) {
 200.749 -        if ((index < 0) || (index >= count))
 200.750 -            throw new StringIndexOutOfBoundsException(index);
 200.751 -        arraycopy(value, index+1, value, index, count-index-1);
 200.752 -        count--;
 200.753 -        return this;
 200.754 -    }
 200.755 -
 200.756 -    /**
 200.757 -     * Replaces the characters in a substring of this sequence
 200.758 -     * with characters in the specified <code>String</code>. The substring
 200.759 -     * begins at the specified <code>start</code> and extends to the character
 200.760 -     * at index <code>end - 1</code> or to the end of the
 200.761 -     * sequence if no such character exists. First the
 200.762 -     * characters in the substring are removed and then the specified
 200.763 -     * <code>String</code> is inserted at <code>start</code>. (This
 200.764 -     * sequence will be lengthened to accommodate the
 200.765 -     * specified String if necessary.)
 200.766 -     *
 200.767 -     * @param      start    The beginning index, inclusive.
 200.768 -     * @param      end      The ending index, exclusive.
 200.769 -     * @param      str   String that will replace previous contents.
 200.770 -     * @return     This object.
 200.771 -     * @throws     StringIndexOutOfBoundsException  if <code>start</code>
 200.772 -     *             is negative, greater than <code>length()</code>, or
 200.773 -     *             greater than <code>end</code>.
 200.774 -     */
 200.775 -    public AbstractStringBuilder replace(int start, int end, String str) {
 200.776 -        if (start < 0)
 200.777 -            throw new StringIndexOutOfBoundsException(start);
 200.778 -        if (start > count)
 200.779 -            throw new StringIndexOutOfBoundsException("start > length()");
 200.780 -        if (start > end)
 200.781 -            throw new StringIndexOutOfBoundsException("start > end");
 200.782 -
 200.783 -        if (end > count)
 200.784 -            end = count;
 200.785 -        int len = str.length();
 200.786 -        int newCount = count + len - (end - start);
 200.787 -        ensureCapacityInternal(newCount);
 200.788 -
 200.789 -        arraycopy(value, end, value, start + len, count - end);
 200.790 -        str.getChars(value, start);
 200.791 -        count = newCount;
 200.792 -        return this;
 200.793 -    }
 200.794 -
 200.795 -    /**
 200.796 -     * Returns a new <code>String</code> that contains a subsequence of
 200.797 -     * characters currently contained in this character sequence. The
 200.798 -     * substring begins at the specified index and extends to the end of
 200.799 -     * this sequence.
 200.800 -     *
 200.801 -     * @param      start    The beginning index, inclusive.
 200.802 -     * @return     The new string.
 200.803 -     * @throws     StringIndexOutOfBoundsException  if <code>start</code> is
 200.804 -     *             less than zero, or greater than the length of this object.
 200.805 -     */
 200.806 -    public String substring(int start) {
 200.807 -        return substring(start, count);
 200.808 -    }
 200.809 -
 200.810 -    /**
 200.811 -     * Returns a new character sequence that is a subsequence of this sequence.
 200.812 -     *
 200.813 -     * <p> An invocation of this method of the form
 200.814 -     *
 200.815 -     * <blockquote><pre>
 200.816 -     * sb.subSequence(begin,&nbsp;end)</pre></blockquote>
 200.817 -     *
 200.818 -     * behaves in exactly the same way as the invocation
 200.819 -     *
 200.820 -     * <blockquote><pre>
 200.821 -     * sb.substring(begin,&nbsp;end)</pre></blockquote>
 200.822 -     *
 200.823 -     * This method is provided so that this class can
 200.824 -     * implement the {@link CharSequence} interface. </p>
 200.825 -     *
 200.826 -     * @param      start   the start index, inclusive.
 200.827 -     * @param      end     the end index, exclusive.
 200.828 -     * @return     the specified subsequence.
 200.829 -     *
 200.830 -     * @throws  IndexOutOfBoundsException
 200.831 -     *          if <tt>start</tt> or <tt>end</tt> are negative,
 200.832 -     *          if <tt>end</tt> is greater than <tt>length()</tt>,
 200.833 -     *          or if <tt>start</tt> is greater than <tt>end</tt>
 200.834 -     * @spec JSR-51
 200.835 -     */
 200.836 -    public CharSequence subSequence(int start, int end) {
 200.837 -        return substring(start, end);
 200.838 -    }
 200.839 -
 200.840 -    /**
 200.841 -     * Returns a new <code>String</code> that contains a subsequence of
 200.842 -     * characters currently contained in this sequence. The
 200.843 -     * substring begins at the specified <code>start</code> and
 200.844 -     * extends to the character at index <code>end - 1</code>.
 200.845 -     *
 200.846 -     * @param      start    The beginning index, inclusive.
 200.847 -     * @param      end      The ending index, exclusive.
 200.848 -     * @return     The new string.
 200.849 -     * @throws     StringIndexOutOfBoundsException  if <code>start</code>
 200.850 -     *             or <code>end</code> are negative or greater than
 200.851 -     *             <code>length()</code>, or <code>start</code> is
 200.852 -     *             greater than <code>end</code>.
 200.853 -     */
 200.854 -    public String substring(int start, int end) {
 200.855 -        if (start < 0)
 200.856 -            throw new StringIndexOutOfBoundsException(start);
 200.857 -        if (end > count)
 200.858 -            throw new StringIndexOutOfBoundsException(end);
 200.859 -        if (start > end)
 200.860 -            throw new StringIndexOutOfBoundsException(end - start);
 200.861 -        return new String(value, start, end - start);
 200.862 -    }
 200.863 -
 200.864 -    /**
 200.865 -     * Inserts the string representation of a subarray of the {@code str}
 200.866 -     * array argument into this sequence. The subarray begins at the
 200.867 -     * specified {@code offset} and extends {@code len} {@code char}s.
 200.868 -     * The characters of the subarray are inserted into this sequence at
 200.869 -     * the position indicated by {@code index}. The length of this
 200.870 -     * sequence increases by {@code len} {@code char}s.
 200.871 -     *
 200.872 -     * @param      index    position at which to insert subarray.
 200.873 -     * @param      str       A {@code char} array.
 200.874 -     * @param      offset   the index of the first {@code char} in subarray to
 200.875 -     *             be inserted.
 200.876 -     * @param      len      the number of {@code char}s in the subarray to
 200.877 -     *             be inserted.
 200.878 -     * @return     This object
 200.879 -     * @throws     StringIndexOutOfBoundsException  if {@code index}
 200.880 -     *             is negative or greater than {@code length()}, or
 200.881 -     *             {@code offset} or {@code len} are negative, or
 200.882 -     *             {@code (offset+len)} is greater than
 200.883 -     *             {@code str.length}.
 200.884 -     */
 200.885 -    public AbstractStringBuilder insert(int index, char[] str, int offset,
 200.886 -                                        int len)
 200.887 -    {
 200.888 -        if ((index < 0) || (index > length()))
 200.889 -            throw new StringIndexOutOfBoundsException(index);
 200.890 -        if ((offset < 0) || (len < 0) || (offset > str.length - len))
 200.891 -            throw new StringIndexOutOfBoundsException(
 200.892 -                "offset " + offset + ", len " + len + ", str.length "
 200.893 -                + str.length);
 200.894 -        ensureCapacityInternal(count + len);
 200.895 -        arraycopy(value, index, value, index + len, count - index);
 200.896 -        arraycopy(str, offset, value, index, len);
 200.897 -        count += len;
 200.898 -        return this;
 200.899 -    }
 200.900 -
 200.901 -    /**
 200.902 -     * Inserts the string representation of the {@code Object}
 200.903 -     * argument into this character sequence.
 200.904 -     * <p>
 200.905 -     * The overall effect is exactly as if the second argument were
 200.906 -     * converted to a string by the method {@link String#valueOf(Object)},
 200.907 -     * and the characters of that string were then
 200.908 -     * {@link #insert(int,String) inserted} into this character
 200.909 -     * sequence at the indicated offset.
 200.910 -     * <p>
 200.911 -     * The {@code offset} argument must be greater than or equal to
 200.912 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
 200.913 -     * of this sequence.
 200.914 -     *
 200.915 -     * @param      offset   the offset.
 200.916 -     * @param      obj      an {@code Object}.
 200.917 -     * @return     a reference to this object.
 200.918 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
 200.919 -     */
 200.920 -    public AbstractStringBuilder insert(int offset, Object obj) {
 200.921 -        return insert(offset, String.valueOf(obj));
 200.922 -    }
 200.923 -
 200.924 -    /**
 200.925 -     * Inserts the string into this character sequence.
 200.926 -     * <p>
 200.927 -     * The characters of the {@code String} argument are inserted, in
 200.928 -     * order, into this sequence at the indicated offset, moving up any
 200.929 -     * characters originally above that position and increasing the length
 200.930 -     * of this sequence by the length of the argument. If
 200.931 -     * {@code str} is {@code null}, then the four characters
 200.932 -     * {@code "null"} are inserted into this sequence.
 200.933 -     * <p>
 200.934 -     * The character at index <i>k</i> in the new character sequence is
 200.935 -     * equal to:
 200.936 -     * <ul>
 200.937 -     * <li>the character at index <i>k</i> in the old character sequence, if
 200.938 -     * <i>k</i> is less than {@code offset}
 200.939 -     * <li>the character at index <i>k</i>{@code -offset} in the
 200.940 -     * argument {@code str}, if <i>k</i> is not less than
 200.941 -     * {@code offset} but is less than {@code offset+str.length()}
 200.942 -     * <li>the character at index <i>k</i>{@code -str.length()} in the
 200.943 -     * old character sequence, if <i>k</i> is not less than
 200.944 -     * {@code offset+str.length()}
 200.945 -     * </ul><p>
 200.946 -     * The {@code offset} argument must be greater than or equal to
 200.947 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
 200.948 -     * of this sequence.
 200.949 -     *
 200.950 -     * @param      offset   the offset.
 200.951 -     * @param      str      a string.
 200.952 -     * @return     a reference to this object.
 200.953 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
 200.954 -     */
 200.955 -    public AbstractStringBuilder insert(int offset, String str) {
 200.956 -        if ((offset < 0) || (offset > length()))
 200.957 -            throw new StringIndexOutOfBoundsException(offset);
 200.958 -        if (str == null)
 200.959 -            str = "null";
 200.960 -        int len = str.length();
 200.961 -        ensureCapacityInternal(count + len);
 200.962 -        arraycopy(value, offset, value, offset + len, count - offset);
 200.963 -        str.getChars(value, offset);
 200.964 -        count += len;
 200.965 -        return this;
 200.966 -    }
 200.967 -
 200.968 -    /**
 200.969 -     * Inserts the string representation of the {@code char} array
 200.970 -     * argument into this sequence.
 200.971 -     * <p>
 200.972 -     * The characters of the array argument are inserted into the
 200.973 -     * contents of this sequence at the position indicated by
 200.974 -     * {@code offset}. The length of this sequence increases by
 200.975 -     * the length of the argument.
 200.976 -     * <p>
 200.977 -     * The overall effect is exactly as if the second argument were
 200.978 -     * converted to a string by the method {@link String#valueOf(char[])},
 200.979 -     * and the characters of that string were then
 200.980 -     * {@link #insert(int,String) inserted} into this character
 200.981 -     * sequence at the indicated offset.
 200.982 -     * <p>
 200.983 -     * The {@code offset} argument must be greater than or equal to
 200.984 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
 200.985 -     * of this sequence.
 200.986 -     *
 200.987 -     * @param      offset   the offset.
 200.988 -     * @param      str      a character array.
 200.989 -     * @return     a reference to this object.
 200.990 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
 200.991 -     */
 200.992 -    public AbstractStringBuilder insert(int offset, char[] str) {
 200.993 -        if ((offset < 0) || (offset > length()))
 200.994 -            throw new StringIndexOutOfBoundsException(offset);
 200.995 -        int len = str.length;
 200.996 -        ensureCapacityInternal(count + len);
 200.997 -        arraycopy(value, offset, value, offset + len, count - offset);
 200.998 -        arraycopy(str, 0, value, offset, len);
 200.999 -        count += len;
200.1000 -        return this;
200.1001 -    }
200.1002 -
200.1003 -    /**
200.1004 -     * Inserts the specified {@code CharSequence} into this sequence.
200.1005 -     * <p>
200.1006 -     * The characters of the {@code CharSequence} argument are inserted,
200.1007 -     * in order, into this sequence at the indicated offset, moving up
200.1008 -     * any characters originally above that position and increasing the length
200.1009 -     * of this sequence by the length of the argument s.
200.1010 -     * <p>
200.1011 -     * The result of this method is exactly the same as if it were an
200.1012 -     * invocation of this object's
200.1013 -     * {@link #insert(int,CharSequence,int,int) insert}(dstOffset, s, 0, s.length())
200.1014 -     * method.
200.1015 -     *
200.1016 -     * <p>If {@code s} is {@code null}, then the four characters
200.1017 -     * {@code "null"} are inserted into this sequence.
200.1018 -     *
200.1019 -     * @param      dstOffset   the offset.
200.1020 -     * @param      s the sequence to be inserted
200.1021 -     * @return     a reference to this object.
200.1022 -     * @throws     IndexOutOfBoundsException  if the offset is invalid.
200.1023 -     */
200.1024 -    public AbstractStringBuilder insert(int dstOffset, CharSequence s) {
200.1025 -        if (s == null)
200.1026 -            s = "null";
200.1027 -        if (s instanceof String)
200.1028 -            return this.insert(dstOffset, (String)s);
200.1029 -        return this.insert(dstOffset, s, 0, s.length());
200.1030 -    }
200.1031 -
200.1032 -    /**
200.1033 -     * Inserts a subsequence of the specified {@code CharSequence} into
200.1034 -     * this sequence.
200.1035 -     * <p>
200.1036 -     * The subsequence of the argument {@code s} specified by
200.1037 -     * {@code start} and {@code end} are inserted,
200.1038 -     * in order, into this sequence at the specified destination offset, moving
200.1039 -     * up any characters originally above that position. The length of this
200.1040 -     * sequence is increased by {@code end - start}.
200.1041 -     * <p>
200.1042 -     * The character at index <i>k</i> in this sequence becomes equal to:
200.1043 -     * <ul>
200.1044 -     * <li>the character at index <i>k</i> in this sequence, if
200.1045 -     * <i>k</i> is less than {@code dstOffset}
200.1046 -     * <li>the character at index <i>k</i>{@code +start-dstOffset} in
200.1047 -     * the argument {@code s}, if <i>k</i> is greater than or equal to
200.1048 -     * {@code dstOffset} but is less than {@code dstOffset+end-start}
200.1049 -     * <li>the character at index <i>k</i>{@code -(end-start)} in this
200.1050 -     * sequence, if <i>k</i> is greater than or equal to
200.1051 -     * {@code dstOffset+end-start}
200.1052 -     * </ul><p>
200.1053 -     * The {@code dstOffset} argument must be greater than or equal to
200.1054 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
200.1055 -     * of this sequence.
200.1056 -     * <p>The start argument must be nonnegative, and not greater than
200.1057 -     * {@code end}.
200.1058 -     * <p>The end argument must be greater than or equal to
200.1059 -     * {@code start}, and less than or equal to the length of s.
200.1060 -     *
200.1061 -     * <p>If {@code s} is {@code null}, then this method inserts
200.1062 -     * characters as if the s parameter was a sequence containing the four
200.1063 -     * characters {@code "null"}.
200.1064 -     *
200.1065 -     * @param      dstOffset   the offset in this sequence.
200.1066 -     * @param      s       the sequence to be inserted.
200.1067 -     * @param      start   the starting index of the subsequence to be inserted.
200.1068 -     * @param      end     the end index of the subsequence to be inserted.
200.1069 -     * @return     a reference to this object.
200.1070 -     * @throws     IndexOutOfBoundsException  if {@code dstOffset}
200.1071 -     *             is negative or greater than {@code this.length()}, or
200.1072 -     *              {@code start} or {@code end} are negative, or
200.1073 -     *              {@code start} is greater than {@code end} or
200.1074 -     *              {@code end} is greater than {@code s.length()}
200.1075 -     */
200.1076 -     public AbstractStringBuilder insert(int dstOffset, CharSequence s,
200.1077 -                                         int start, int end) {
200.1078 -        if (s == null)
200.1079 -            s = "null";
200.1080 -        if ((dstOffset < 0) || (dstOffset > this.length()))
200.1081 -            throw new IndexOutOfBoundsException("dstOffset "+dstOffset);
200.1082 -        if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
200.1083 -            throw new IndexOutOfBoundsException(
200.1084 -                "start " + start + ", end " + end + ", s.length() "
200.1085 -                + s.length());
200.1086 -        int len = end - start;
200.1087 -        ensureCapacityInternal(count + len);
200.1088 -        arraycopy(value, dstOffset, value, dstOffset + len,
200.1089 -                         count - dstOffset);
200.1090 -        for (int i=start; i<end; i++)
200.1091 -            value[dstOffset++] = s.charAt(i);
200.1092 -        count += len;
200.1093 -        return this;
200.1094 -    }
200.1095 -
200.1096 -    /**
200.1097 -     * Inserts the string representation of the {@code boolean}
200.1098 -     * argument into this sequence.
200.1099 -     * <p>
200.1100 -     * The overall effect is exactly as if the second argument were
200.1101 -     * converted to a string by the method {@link String#valueOf(boolean)},
200.1102 -     * and the characters of that string were then
200.1103 -     * {@link #insert(int,String) inserted} into this character
200.1104 -     * sequence at the indicated offset.
200.1105 -     * <p>
200.1106 -     * The {@code offset} argument must be greater than or equal to
200.1107 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
200.1108 -     * of this sequence.
200.1109 -     *
200.1110 -     * @param      offset   the offset.
200.1111 -     * @param      b        a {@code boolean}.
200.1112 -     * @return     a reference to this object.
200.1113 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
200.1114 -     */
200.1115 -    public AbstractStringBuilder insert(int offset, boolean b) {
200.1116 -        return insert(offset, String.valueOf(b));
200.1117 -    }
200.1118 -
200.1119 -    /**
200.1120 -     * Inserts the string representation of the {@code char}
200.1121 -     * argument into this sequence.
200.1122 -     * <p>
200.1123 -     * The overall effect is exactly as if the second argument were
200.1124 -     * converted to a string by the method {@link String#valueOf(char)},
200.1125 -     * and the character in that string were then
200.1126 -     * {@link #insert(int,String) inserted} into this character
200.1127 -     * sequence at the indicated offset.
200.1128 -     * <p>
200.1129 -     * The {@code offset} argument must be greater than or equal to
200.1130 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
200.1131 -     * of this sequence.
200.1132 -     *
200.1133 -     * @param      offset   the offset.
200.1134 -     * @param      c        a {@code char}.
200.1135 -     * @return     a reference to this object.
200.1136 -     * @throws     IndexOutOfBoundsException  if the offset is invalid.
200.1137 -     */
200.1138 -    public AbstractStringBuilder insert(int offset, char c) {
200.1139 -        ensureCapacityInternal(count + 1);
200.1140 -        arraycopy(value, offset, value, offset + 1, count - offset);
200.1141 -        value[offset] = c;
200.1142 -        count += 1;
200.1143 -        return this;
200.1144 -    }
200.1145 -
200.1146 -    /**
200.1147 -     * Inserts the string representation of the second {@code int}
200.1148 -     * argument into this sequence.
200.1149 -     * <p>
200.1150 -     * The overall effect is exactly as if the second argument were
200.1151 -     * converted to a string by the method {@link String#valueOf(int)},
200.1152 -     * and the characters of that string were then
200.1153 -     * {@link #insert(int,String) inserted} into this character
200.1154 -     * sequence at the indicated offset.
200.1155 -     * <p>
200.1156 -     * The {@code offset} argument must be greater than or equal to
200.1157 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
200.1158 -     * of this sequence.
200.1159 -     *
200.1160 -     * @param      offset   the offset.
200.1161 -     * @param      i        an {@code int}.
200.1162 -     * @return     a reference to this object.
200.1163 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
200.1164 -     */
200.1165 -    public AbstractStringBuilder insert(int offset, int i) {
200.1166 -        return insert(offset, String.valueOf(i));
200.1167 -    }
200.1168 -
200.1169 -    /**
200.1170 -     * Inserts the string representation of the {@code long}
200.1171 -     * argument into this sequence.
200.1172 -     * <p>
200.1173 -     * The overall effect is exactly as if the second argument were
200.1174 -     * converted to a string by the method {@link String#valueOf(long)},
200.1175 -     * and the characters of that string were then
200.1176 -     * {@link #insert(int,String) inserted} into this character
200.1177 -     * sequence at the indicated offset.
200.1178 -     * <p>
200.1179 -     * The {@code offset} argument must be greater than or equal to
200.1180 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
200.1181 -     * of this sequence.
200.1182 -     *
200.1183 -     * @param      offset   the offset.
200.1184 -     * @param      l        a {@code long}.
200.1185 -     * @return     a reference to this object.
200.1186 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
200.1187 -     */
200.1188 -    public AbstractStringBuilder insert(int offset, long l) {
200.1189 -        return insert(offset, String.valueOf(l));
200.1190 -    }
200.1191 -
200.1192 -    /**
200.1193 -     * Inserts the string representation of the {@code float}
200.1194 -     * argument into this sequence.
200.1195 -     * <p>
200.1196 -     * The overall effect is exactly as if the second argument were
200.1197 -     * converted to a string by the method {@link String#valueOf(float)},
200.1198 -     * and the characters of that string were then
200.1199 -     * {@link #insert(int,String) inserted} into this character
200.1200 -     * sequence at the indicated offset.
200.1201 -     * <p>
200.1202 -     * The {@code offset} argument must be greater than or equal to
200.1203 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
200.1204 -     * of this sequence.
200.1205 -     *
200.1206 -     * @param      offset   the offset.
200.1207 -     * @param      f        a {@code float}.
200.1208 -     * @return     a reference to this object.
200.1209 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
200.1210 -     */
200.1211 -    public AbstractStringBuilder insert(int offset, float f) {
200.1212 -        return insert(offset, String.valueOf(f));
200.1213 -    }
200.1214 -
200.1215 -    /**
200.1216 -     * Inserts the string representation of the {@code double}
200.1217 -     * argument into this sequence.
200.1218 -     * <p>
200.1219 -     * The overall effect is exactly as if the second argument were
200.1220 -     * converted to a string by the method {@link String#valueOf(double)},
200.1221 -     * and the characters of that string were then
200.1222 -     * {@link #insert(int,String) inserted} into this character
200.1223 -     * sequence at the indicated offset.
200.1224 -     * <p>
200.1225 -     * The {@code offset} argument must be greater than or equal to
200.1226 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
200.1227 -     * of this sequence.
200.1228 -     *
200.1229 -     * @param      offset   the offset.
200.1230 -     * @param      d        a {@code double}.
200.1231 -     * @return     a reference to this object.
200.1232 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
200.1233 -     */
200.1234 -    public AbstractStringBuilder insert(int offset, double d) {
200.1235 -        return insert(offset, String.valueOf(d));
200.1236 -    }
200.1237 -
200.1238 -    /**
200.1239 -     * Returns the index within this string of the first occurrence of the
200.1240 -     * specified substring. The integer returned is the smallest value
200.1241 -     * <i>k</i> such that:
200.1242 -     * <blockquote><pre>
200.1243 -     * this.toString().startsWith(str, <i>k</i>)
200.1244 -     * </pre></blockquote>
200.1245 -     * is <code>true</code>.
200.1246 -     *
200.1247 -     * @param   str   any string.
200.1248 -     * @return  if the string argument occurs as a substring within this
200.1249 -     *          object, then the index of the first character of the first
200.1250 -     *          such substring is returned; if it does not occur as a
200.1251 -     *          substring, <code>-1</code> is returned.
200.1252 -     * @throws  java.lang.NullPointerException if <code>str</code> is
200.1253 -     *          <code>null</code>.
200.1254 -     */
200.1255 -    public int indexOf(String str) {
200.1256 -        return indexOf(str, 0);
200.1257 -    }
200.1258 -
200.1259 -    /**
200.1260 -     * Returns the index within this string of the first occurrence of the
200.1261 -     * specified substring, starting at the specified index.  The integer
200.1262 -     * returned is the smallest value <tt>k</tt> for which:
200.1263 -     * <blockquote><pre>
200.1264 -     *     k >= Math.min(fromIndex, str.length()) &&
200.1265 -     *                   this.toString().startsWith(str, k)
200.1266 -     * </pre></blockquote>
200.1267 -     * If no such value of <i>k</i> exists, then -1 is returned.
200.1268 -     *
200.1269 -     * @param   str         the substring for which to search.
200.1270 -     * @param   fromIndex   the index from which to start the search.
200.1271 -     * @return  the index within this string of the first occurrence of the
200.1272 -     *          specified substring, starting at the specified index.
200.1273 -     * @throws  java.lang.NullPointerException if <code>str</code> is
200.1274 -     *            <code>null</code>.
200.1275 -     */
200.1276 -    public int indexOf(String str, int fromIndex) {
200.1277 -        return String.indexOf(value, 0, count,
200.1278 -                              str.toCharArray(), 0, str.length(), fromIndex);
200.1279 -    }
200.1280 -
200.1281 -    /**
200.1282 -     * Returns the index within this string of the rightmost occurrence
200.1283 -     * of the specified substring.  The rightmost empty string "" is
200.1284 -     * considered to occur at the index value <code>this.length()</code>.
200.1285 -     * The returned index is the largest value <i>k</i> such that
200.1286 -     * <blockquote><pre>
200.1287 -     * this.toString().startsWith(str, k)
200.1288 -     * </pre></blockquote>
200.1289 -     * is true.
200.1290 -     *
200.1291 -     * @param   str   the substring to search for.
200.1292 -     * @return  if the string argument occurs one or more times as a substring
200.1293 -     *          within this object, then the index of the first character of
200.1294 -     *          the last such substring is returned. If it does not occur as
200.1295 -     *          a substring, <code>-1</code> is returned.
200.1296 -     * @throws  java.lang.NullPointerException  if <code>str</code> is
200.1297 -     *          <code>null</code>.
200.1298 -     */
200.1299 -    public int lastIndexOf(String str) {
200.1300 -        return lastIndexOf(str, count);
200.1301 -    }
200.1302 -
200.1303 -    /**
200.1304 -     * Returns the index within this string of the last occurrence of the
200.1305 -     * specified substring. The integer returned is the largest value <i>k</i>
200.1306 -     * such that:
200.1307 -     * <blockquote><pre>
200.1308 -     *     k <= Math.min(fromIndex, str.length()) &&
200.1309 -     *                   this.toString().startsWith(str, k)
200.1310 -     * </pre></blockquote>
200.1311 -     * If no such value of <i>k</i> exists, then -1 is returned.
200.1312 -     *
200.1313 -     * @param   str         the substring to search for.
200.1314 -     * @param   fromIndex   the index to start the search from.
200.1315 -     * @return  the index within this sequence of the last occurrence of the
200.1316 -     *          specified substring.
200.1317 -     * @throws  java.lang.NullPointerException if <code>str</code> is
200.1318 -     *          <code>null</code>.
200.1319 -     */
200.1320 -    public int lastIndexOf(String str, int fromIndex) {
200.1321 -        return String.lastIndexOf(value, 0, count,
200.1322 -                              str.toCharArray(), 0, str.length(), fromIndex);
200.1323 -    }
200.1324 -
200.1325 -    /**
200.1326 -     * Causes this character sequence to be replaced by the reverse of
200.1327 -     * the sequence. If there are any surrogate pairs included in the
200.1328 -     * sequence, these are treated as single characters for the
200.1329 -     * reverse operation. Thus, the order of the high-low surrogates
200.1330 -     * is never reversed.
200.1331 -     *
200.1332 -     * Let <i>n</i> be the character length of this character sequence
200.1333 -     * (not the length in <code>char</code> values) just prior to
200.1334 -     * execution of the <code>reverse</code> method. Then the
200.1335 -     * character at index <i>k</i> in the new character sequence is
200.1336 -     * equal to the character at index <i>n-k-1</i> in the old
200.1337 -     * character sequence.
200.1338 -     *
200.1339 -     * <p>Note that the reverse operation may result in producing
200.1340 -     * surrogate pairs that were unpaired low-surrogates and
200.1341 -     * high-surrogates before the operation. For example, reversing
200.1342 -     * "&#92;uDC00&#92;uD800" produces "&#92;uD800&#92;uDC00" which is
200.1343 -     * a valid surrogate pair.
200.1344 -     *
200.1345 -     * @return  a reference to this object.
200.1346 -     */
200.1347 -    public AbstractStringBuilder reverse() {
200.1348 -        boolean hasSurrogate = false;
200.1349 -        int n = count - 1;
200.1350 -        for (int j = (n-1) >> 1; j >= 0; --j) {
200.1351 -            char temp = value[j];
200.1352 -            char temp2 = value[n - j];
200.1353 -            if (!hasSurrogate) {
200.1354 -                hasSurrogate = (temp >= Character.MIN_SURROGATE && temp <= Character.MAX_SURROGATE)
200.1355 -                    || (temp2 >= Character.MIN_SURROGATE && temp2 <= Character.MAX_SURROGATE);
200.1356 -            }
200.1357 -            value[j] = temp2;
200.1358 -            value[n - j] = temp;
200.1359 -        }
200.1360 -        if (hasSurrogate) {
200.1361 -            // Reverse back all valid surrogate pairs
200.1362 -            for (int i = 0; i < count - 1; i++) {
200.1363 -                char c2 = value[i];
200.1364 -                if (Character.isLowSurrogate(c2)) {
200.1365 -                    char c1 = value[i + 1];
200.1366 -                    if (Character.isHighSurrogate(c1)) {
200.1367 -                        value[i++] = c1;
200.1368 -                        value[i] = c2;
200.1369 -                    }
200.1370 -                }
200.1371 -            }
200.1372 -        }
200.1373 -        return this;
200.1374 -    }
200.1375 -
200.1376 -    /**
200.1377 -     * Returns a string representing the data in this sequence.
200.1378 -     * A new <code>String</code> object is allocated and initialized to
200.1379 -     * contain the character sequence currently represented by this
200.1380 -     * object. This <code>String</code> is then returned. Subsequent
200.1381 -     * changes to this sequence do not affect the contents of the
200.1382 -     * <code>String</code>.
200.1383 -     *
200.1384 -     * @return  a string representation of this sequence of characters.
200.1385 -     */
200.1386 -    public abstract String toString();
200.1387 -
200.1388 -    /**
200.1389 -     * Needed by <tt>String</tt> for the contentEquals method.
200.1390 -     */
200.1391 -    final char[] getValue() {
200.1392 -        return value;
200.1393 -    }
200.1394 -
200.1395 -    static char[] copyOfRange(char[] original, int from, int to) {
200.1396 -        int newLength = to - from;
200.1397 -        if (newLength < 0) {
200.1398 -            throw new IllegalArgumentException(from + " > " + to);
200.1399 -        }
200.1400 -        char[] copy = new char[newLength];
200.1401 -        arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
200.1402 -        return copy;
200.1403 -    }
200.1404 -
200.1405 -    static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
200.1406 -        if (srcBegin < dstBegin) {
200.1407 -            while (count-- > 0) {
200.1408 -                dst[dstBegin + count] = value[srcBegin + count];
200.1409 -            }
200.1410 -        } else {
200.1411 -            while (count-- > 0) {
200.1412 -                dst[dstBegin++] = value[srcBegin++];
200.1413 -            }
200.1414 -        }
200.1415 -    }
200.1416 -
200.1417 -    // access system property
200.1418 -    static String getProperty(String nm) {
200.1419 -        return null;
200.1420 -    }
200.1421 -
200.1422 -    static char[] copyOf(char[] original, int newLength) {
200.1423 -        char[] copy = new char[newLength];
200.1424 -        arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
200.1425 -        return copy;
200.1426 -    }
200.1427 -    
200.1428 -}
   201.1 --- a/emul/src/main/java/java/lang/Appendable.java	Wed Dec 05 10:03:58 2012 +0100
   201.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   201.3 @@ -1,121 +0,0 @@
   201.4 -/*
   201.5 - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
   201.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   201.7 - *
   201.8 - * This code is free software; you can redistribute it and/or modify it
   201.9 - * under the terms of the GNU General Public License version 2 only, as
  201.10 - * published by the Free Software Foundation.  Oracle designates this
  201.11 - * particular file as subject to the "Classpath" exception as provided
  201.12 - * by Oracle in the LICENSE file that accompanied this code.
  201.13 - *
  201.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  201.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  201.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  201.17 - * version 2 for more details (a copy is included in the LICENSE file that
  201.18 - * accompanied this code).
  201.19 - *
  201.20 - * You should have received a copy of the GNU General Public License version
  201.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  201.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  201.23 - *
  201.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  201.25 - * or visit www.oracle.com if you need additional information or have any
  201.26 - * questions.
  201.27 - */
  201.28 -
  201.29 -package java.lang;
  201.30 -
  201.31 -import java.io.IOException;
  201.32 -
  201.33 -/**
  201.34 - * An object to which <tt>char</tt> sequences and values can be appended.  The
  201.35 - * <tt>Appendable</tt> interface must be implemented by any class whose
  201.36 - * instances are intended to receive formatted output from a {@link
  201.37 - * java.util.Formatter}.
  201.38 - *
  201.39 - * <p> The characters to be appended should be valid Unicode characters as
  201.40 - * described in <a href="Character.html#unicode">Unicode Character
  201.41 - * Representation</a>.  Note that supplementary characters may be composed of
  201.42 - * multiple 16-bit <tt>char</tt> values.
  201.43 - *
  201.44 - * <p> Appendables are not necessarily safe for multithreaded access.  Thread
  201.45 - * safety is the responsibility of classes that extend and implement this
  201.46 - * interface.
  201.47 - *
  201.48 - * <p> Since this interface may be implemented by existing classes
  201.49 - * with different styles of error handling there is no guarantee that
  201.50 - * errors will be propagated to the invoker.
  201.51 - *
  201.52 - * @since 1.5
  201.53 - */
  201.54 -public interface Appendable {
  201.55 -
  201.56 -    /**
  201.57 -     * Appends the specified character sequence to this <tt>Appendable</tt>.
  201.58 -     *
  201.59 -     * <p> Depending on which class implements the character sequence
  201.60 -     * <tt>csq</tt>, the entire sequence may not be appended.  For
  201.61 -     * instance, if <tt>csq</tt> is a {@link java.nio.CharBuffer} then
  201.62 -     * the subsequence to append is defined by the buffer's position and limit.
  201.63 -     *
  201.64 -     * @param  csq
  201.65 -     *         The character sequence to append.  If <tt>csq</tt> is
  201.66 -     *         <tt>null</tt>, then the four characters <tt>"null"</tt> are
  201.67 -     *         appended to this Appendable.
  201.68 -     *
  201.69 -     * @return  A reference to this <tt>Appendable</tt>
  201.70 -     *
  201.71 -     * @throws  IOException
  201.72 -     *          If an I/O error occurs
  201.73 -     */
  201.74 -    Appendable append(CharSequence csq) throws IOException;
  201.75 -
  201.76 -    /**
  201.77 -     * Appends a subsequence of the specified character sequence to this
  201.78 -     * <tt>Appendable</tt>.
  201.79 -     *
  201.80 -     * <p> An invocation of this method of the form <tt>out.append(csq, start,
  201.81 -     * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
  201.82 -     * exactly the same way as the invocation
  201.83 -     *
  201.84 -     * <pre>
  201.85 -     *     out.append(csq.subSequence(start, end)) </pre>
  201.86 -     *
  201.87 -     * @param  csq
  201.88 -     *         The character sequence from which a subsequence will be
  201.89 -     *         appended.  If <tt>csq</tt> is <tt>null</tt>, then characters
  201.90 -     *         will be appended as if <tt>csq</tt> contained the four
  201.91 -     *         characters <tt>"null"</tt>.
  201.92 -     *
  201.93 -     * @param  start
  201.94 -     *         The index of the first character in the subsequence
  201.95 -     *
  201.96 -     * @param  end
  201.97 -     *         The index of the character following the last character in the
  201.98 -     *         subsequence
  201.99 -     *
 201.100 -     * @return  A reference to this <tt>Appendable</tt>
 201.101 -     *
 201.102 -     * @throws  IndexOutOfBoundsException
 201.103 -     *          If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
 201.104 -     *          is greater than <tt>end</tt>, or <tt>end</tt> is greater than
 201.105 -     *          <tt>csq.length()</tt>
 201.106 -     *
 201.107 -     * @throws  IOException
 201.108 -     *          If an I/O error occurs
 201.109 -     */
 201.110 -    Appendable append(CharSequence csq, int start, int end) throws IOException;
 201.111 -
 201.112 -    /**
 201.113 -     * Appends the specified character to this <tt>Appendable</tt>.
 201.114 -     *
 201.115 -     * @param  c
 201.116 -     *         The character to append
 201.117 -     *
 201.118 -     * @return  A reference to this <tt>Appendable</tt>
 201.119 -     *
 201.120 -     * @throws  IOException
 201.121 -     *          If an I/O error occurs
 201.122 -     */
 201.123 -    Appendable append(char c) throws IOException;
 201.124 -}
   202.1 --- a/emul/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java	Wed Dec 05 10:03:58 2012 +0100
   202.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   202.3 @@ -1,67 +0,0 @@
   202.4 -/*
   202.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   202.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   202.7 - *
   202.8 - * This code is free software; you can redistribute it and/or modify it
   202.9 - * under the terms of the GNU General Public License version 2 only, as
  202.10 - * published by the Free Software Foundation.  Oracle designates this
  202.11 - * particular file as subject to the "Classpath" exception as provided
  202.12 - * by Oracle in the LICENSE file that accompanied this code.
  202.13 - *
  202.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  202.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  202.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  202.17 - * version 2 for more details (a copy is included in the LICENSE file that
  202.18 - * accompanied this code).
  202.19 - *
  202.20 - * You should have received a copy of the GNU General Public License version
  202.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  202.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  202.23 - *
  202.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  202.25 - * or visit www.oracle.com if you need additional information or have any
  202.26 - * questions.
  202.27 - */
  202.28 -
  202.29 -package java.lang;
  202.30 -
  202.31 -/**
  202.32 - * Thrown to indicate that an array has been accessed with an
  202.33 - * illegal index. The index is either negative or greater than or
  202.34 - * equal to the size of the array.
  202.35 - *
  202.36 - * @author  unascribed
  202.37 - * @since   JDK1.0
  202.38 - */
  202.39 -public
  202.40 -class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException {
  202.41 -    private static final long serialVersionUID = -5116101128118950844L;
  202.42 -
  202.43 -    /**
  202.44 -     * Constructs an <code>ArrayIndexOutOfBoundsException</code> with no
  202.45 -     * detail message.
  202.46 -     */
  202.47 -    public ArrayIndexOutOfBoundsException() {
  202.48 -        super();
  202.49 -    }
  202.50 -
  202.51 -    /**
  202.52 -     * Constructs a new <code>ArrayIndexOutOfBoundsException</code>
  202.53 -     * class with an argument indicating the illegal index.
  202.54 -     *
  202.55 -     * @param   index   the illegal index.
  202.56 -     */
  202.57 -    public ArrayIndexOutOfBoundsException(int index) {
  202.58 -        super("Array index out of range: " + index);
  202.59 -    }
  202.60 -
  202.61 -    /**
  202.62 -     * Constructs an <code>ArrayIndexOutOfBoundsException</code> class
  202.63 -     * with the specified detail message.
  202.64 -     *
  202.65 -     * @param   s   the detail message.
  202.66 -     */
  202.67 -    public ArrayIndexOutOfBoundsException(String s) {
  202.68 -        super(s);
  202.69 -    }
  202.70 -}
   203.1 --- a/emul/src/main/java/java/lang/AssertionError.java	Wed Dec 05 10:03:58 2012 +0100
   203.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   203.3 @@ -1,167 +0,0 @@
   203.4 -/*
   203.5 - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
   203.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   203.7 - *
   203.8 - * This code is free software; you can redistribute it and/or modify it
   203.9 - * under the terms of the GNU General Public License version 2 only, as
  203.10 - * published by the Free Software Foundation.  Oracle designates this
  203.11 - * particular file as subject to the "Classpath" exception as provided
  203.12 - * by Oracle in the LICENSE file that accompanied this code.
  203.13 - *
  203.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  203.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  203.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  203.17 - * version 2 for more details (a copy is included in the LICENSE file that
  203.18 - * accompanied this code).
  203.19 - *
  203.20 - * You should have received a copy of the GNU General Public License version
  203.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  203.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  203.23 - *
  203.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  203.25 - * or visit www.oracle.com if you need additional information or have any
  203.26 - * questions.
  203.27 - */
  203.28 -
  203.29 -package java.lang;
  203.30 -
  203.31 -/**
  203.32 - * Thrown to indicate that an assertion has failed.
  203.33 - *
  203.34 - * <p>The seven one-argument public constructors provided by this
  203.35 - * class ensure that the assertion error returned by the invocation:
  203.36 - * <pre>
  203.37 - *     new AssertionError(<i>expression</i>)
  203.38 - * </pre>
  203.39 - * has as its detail message the <i>string conversion</i> of
  203.40 - * <i>expression</i> (as defined in section 15.18.1.1 of
  203.41 - * <cite>The Java&trade; Language Specification</cite>),
  203.42 - * regardless of the type of <i>expression</i>.
  203.43 - *
  203.44 - * @since   1.4
  203.45 - */
  203.46 -public class AssertionError extends Error {
  203.47 -    private static final long serialVersionUID = -5013299493970297370L;
  203.48 -
  203.49 -    /**
  203.50 -     * Constructs an AssertionError with no detail message.
  203.51 -     */
  203.52 -    public AssertionError() {
  203.53 -    }
  203.54 -
  203.55 -    /**
  203.56 -     * This internal constructor does no processing on its string argument,
  203.57 -     * even if it is a null reference.  The public constructors will
  203.58 -     * never call this constructor with a null argument.
  203.59 -     */
  203.60 -    private AssertionError(String detailMessage) {
  203.61 -        super(detailMessage);
  203.62 -    }
  203.63 -
  203.64 -    /**
  203.65 -     * Constructs an AssertionError with its detail message derived
  203.66 -     * from the specified object, which is converted to a string as
  203.67 -     * defined in section 15.18.1.1 of
  203.68 -     * <cite>The Java&trade; Language Specification</cite>.
  203.69 -     *<p>
  203.70 -     * If the specified object is an instance of {@code Throwable}, it
  203.71 -     * becomes the <i>cause</i> of the newly constructed assertion error.
  203.72 -     *
  203.73 -     * @param detailMessage value to be used in constructing detail message
  203.74 -     * @see   Throwable#getCause()
  203.75 -     */
  203.76 -    public AssertionError(Object detailMessage) {
  203.77 -        this("" +  detailMessage);
  203.78 -        if (detailMessage instanceof Throwable)
  203.79 -            initCause((Throwable) detailMessage);
  203.80 -    }
  203.81 -
  203.82 -    /**
  203.83 -     * Constructs an AssertionError with its detail message derived
  203.84 -     * from the specified <code>boolean</code>, which is converted to
  203.85 -     * a string as defined in section 15.18.1.1 of
  203.86 -     * <cite>The Java&trade; Language Specification</cite>.
  203.87 -     *
  203.88 -     * @param detailMessage value to be used in constructing detail message
  203.89 -     */
  203.90 -    public AssertionError(boolean detailMessage) {
  203.91 -        this("" +  detailMessage);
  203.92 -    }
  203.93 -
  203.94 -    /**
  203.95 -     * Constructs an AssertionError with its detail message derived
  203.96 -     * from the specified <code>char</code>, which is converted to a
  203.97 -     * string as defined in section 15.18.1.1 of
  203.98 -     * <cite>The Java&trade; Language Specification</cite>.
  203.99 -     *
 203.100 -     * @param detailMessage value to be used in constructing detail message
 203.101 -     */
 203.102 -    public AssertionError(char detailMessage) {
 203.103 -        this("" +  detailMessage);
 203.104 -    }
 203.105 -
 203.106 -    /**
 203.107 -     * Constructs an AssertionError with its detail message derived
 203.108 -     * from the specified <code>int</code>, which is converted to a
 203.109 -     * string as defined in section 15.18.1.1 of
 203.110 -     * <cite>The Java&trade; Language Specification</cite>.
 203.111 -     *
 203.112 -     * @param detailMessage value to be used in constructing detail message
 203.113 -     */
 203.114 -    public AssertionError(int detailMessage) {
 203.115 -        this("" +  detailMessage);
 203.116 -    }
 203.117 -
 203.118 -    /**
 203.119 -     * Constructs an AssertionError with its detail message derived
 203.120 -     * from the specified <code>long</code>, which is converted to a
 203.121 -     * string as defined in section 15.18.1.1 of
 203.122 -     * <cite>The Java&trade; Language Specification</cite>.
 203.123 -     *
 203.124 -     * @param detailMessage value to be used in constructing detail message
 203.125 -     */
 203.126 -    public AssertionError(long detailMessage) {
 203.127 -        this("" +  detailMessage);
 203.128 -    }
 203.129 -
 203.130 -    /**
 203.131 -     * Constructs an AssertionError with its detail message derived
 203.132 -     * from the specified <code>float</code>, which is converted to a
 203.133 -     * string as defined in section 15.18.1.1 of
 203.134 -     * <cite>The Java&trade; Language Specification</cite>.
 203.135 -     *
 203.136 -     * @param detailMessage value to be used in constructing detail message
 203.137 -     */
 203.138 -    public AssertionError(float detailMessage) {
 203.139 -        this("" +  detailMessage);
 203.140 -    }
 203.141 -
 203.142 -    /**
 203.143 -     * Constructs an AssertionError with its detail message derived
 203.144 -     * from the specified <code>double</code>, which is converted to a
 203.145 -     * string as defined in section 15.18.1.1 of
 203.146 -     * <cite>The Java&trade; Language Specification</cite>.
 203.147 -     *
 203.148 -     * @param detailMessage value to be used in constructing detail message
 203.149 -     */
 203.150 -    public AssertionError(double detailMessage) {
 203.151 -        this("" +  detailMessage);
 203.152 -    }
 203.153 -
 203.154 -    /**
 203.155 -     * Constructs a new {@code AssertionError} with the specified
 203.156 -     * detail message and cause.
 203.157 -     *
 203.158 -     * <p>Note that the detail message associated with
 203.159 -     * {@code cause} is <i>not</i> automatically incorporated in
 203.160 -     * this error's detail message.
 203.161 -     *
 203.162 -     * @param  message the detail message, may be {@code null}
 203.163 -     * @param  cause the cause, may be {@code null}
 203.164 -     *
 203.165 -     * @since 1.7
 203.166 -     */
 203.167 -    public AssertionError(String message, Throwable cause) {
 203.168 -        super(message, cause);
 203.169 -    }
 203.170 -}
   204.1 --- a/emul/src/main/java/java/lang/AutoCloseable.java	Wed Dec 05 10:03:58 2012 +0100
   204.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   204.3 @@ -1,72 +0,0 @@
   204.4 -/*
   204.5 - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
   204.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   204.7 - *
   204.8 - * This code is free software; you can redistribute it and/or modify it
   204.9 - * under the terms of the GNU General Public License version 2 only, as
  204.10 - * published by the Free Software Foundation.  Oracle designates this
  204.11 - * particular file as subject to the "Classpath" exception as provided
  204.12 - * by Oracle in the LICENSE file that accompanied this code.
  204.13 - *
  204.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  204.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  204.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  204.17 - * version 2 for more details (a copy is included in the LICENSE file that
  204.18 - * accompanied this code).
  204.19 - *
  204.20 - * You should have received a copy of the GNU General Public License version
  204.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  204.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  204.23 - *
  204.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  204.25 - * or visit www.oracle.com if you need additional information or have any
  204.26 - * questions.
  204.27 - */
  204.28 -
  204.29 -package java.lang;
  204.30 -
  204.31 -/**
  204.32 - * A resource that must be closed when it is no longer needed.
  204.33 - *
  204.34 - * @author Josh Bloch
  204.35 - * @since 1.7
  204.36 - */
  204.37 -public interface AutoCloseable {
  204.38 -    /**
  204.39 -     * Closes this resource, relinquishing any underlying resources.
  204.40 -     * This method is invoked automatically on objects managed by the
  204.41 -     * {@code try}-with-resources statement.
  204.42 -     *
  204.43 -     * <p>While this interface method is declared to throw {@code
  204.44 -     * Exception}, implementers are <em>strongly</em> encouraged to
  204.45 -     * declare concrete implementations of the {@code close} method to
  204.46 -     * throw more specific exceptions, or to throw no exception at all
  204.47 -     * if the close operation cannot fail.
  204.48 -     *
  204.49 -     * <p><em>Implementers of this interface are also strongly advised
  204.50 -     * to not have the {@code close} method throw {@link
  204.51 -     * InterruptedException}.</em>
  204.52 -     *
  204.53 -     * This exception interacts with a thread's interrupted status,
  204.54 -     * and runtime misbehavior is likely to occur if an {@code
  204.55 -     * InterruptedException} is {@linkplain Throwable#addSuppressed
  204.56 -     * suppressed}.
  204.57 -     *
  204.58 -     * More generally, if it would cause problems for an
  204.59 -     * exception to be suppressed, the {@code AutoCloseable.close}
  204.60 -     * method should not throw it.
  204.61 -     *
  204.62 -     * <p>Note that unlike the {@link java.io.Closeable#close close}
  204.63 -     * method of {@link java.io.Closeable}, this {@code close} method
  204.64 -     * is <em>not</em> required to be idempotent.  In other words,
  204.65 -     * calling this {@code close} method more than once may have some
  204.66 -     * visible side effect, unlike {@code Closeable.close} which is
  204.67 -     * required to have no effect if called more than once.
  204.68 -     *
  204.69 -     * However, implementers of this interface are strongly encouraged
  204.70 -     * to make their {@code close} methods idempotent.
  204.71 -     *
  204.72 -     * @throws Exception if this resource cannot be closed
  204.73 -     */
  204.74 -    void close() throws Exception;
  204.75 -}
   205.1 --- a/emul/src/main/java/java/lang/Boolean.java	Wed Dec 05 10:03:58 2012 +0100
   205.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   205.3 @@ -1,282 +0,0 @@
   205.4 -/*
   205.5 - * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
   205.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   205.7 - *
   205.8 - * This code is free software; you can redistribute it and/or modify it
   205.9 - * under the terms of the GNU General Public License version 2 only, as
  205.10 - * published by the Free Software Foundation.  Oracle designates this
  205.11 - * particular file as subject to the "Classpath" exception as provided
  205.12 - * by Oracle in the LICENSE file that accompanied this code.
  205.13 - *
  205.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  205.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  205.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  205.17 - * version 2 for more details (a copy is included in the LICENSE file that
  205.18 - * accompanied this code).
  205.19 - *
  205.20 - * You should have received a copy of the GNU General Public License version
  205.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  205.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  205.23 - *
  205.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  205.25 - * or visit www.oracle.com if you need additional information or have any
  205.26 - * questions.
  205.27 - */
  205.28 -
  205.29 -package java.lang;
  205.30 -
  205.31 -/**
  205.32 - * The Boolean class wraps a value of the primitive type
  205.33 - * {@code boolean} in an object. An object of type
  205.34 - * {@code Boolean} contains a single field whose type is
  205.35 - * {@code boolean}.
  205.36 - * <p>
  205.37 - * In addition, this class provides many methods for
  205.38 - * converting a {@code boolean} to a {@code String} and a
  205.39 - * {@code String} to a {@code boolean}, as well as other
  205.40 - * constants and methods useful when dealing with a
  205.41 - * {@code boolean}.
  205.42 - *
  205.43 - * @author  Arthur van Hoff
  205.44 - * @since   JDK1.0
  205.45 - */
  205.46 -public final class Boolean implements java.io.Serializable,
  205.47 -                                      Comparable<Boolean>
  205.48 -{
  205.49 -    /**
  205.50 -     * The {@code Boolean} object corresponding to the primitive
  205.51 -     * value {@code true}.
  205.52 -     */
  205.53 -    public static final Boolean TRUE = new Boolean(true);
  205.54 -
  205.55 -    /**
  205.56 -     * The {@code Boolean} object corresponding to the primitive
  205.57 -     * value {@code false}.
  205.58 -     */
  205.59 -    public static final Boolean FALSE = new Boolean(false);
  205.60 -
  205.61 -    /**
  205.62 -     * The Class object representing the primitive type boolean.
  205.63 -     *
  205.64 -     * @since   JDK1.1
  205.65 -     */
  205.66 -    public static final Class<Boolean> TYPE = Class.getPrimitiveClass("boolean");
  205.67 -
  205.68 -    /**
  205.69 -     * The value of the Boolean.
  205.70 -     *
  205.71 -     * @serial
  205.72 -     */
  205.73 -    private final boolean value;
  205.74 -
  205.75 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
  205.76 -    private static final long serialVersionUID = -3665804199014368530L;
  205.77 -
  205.78 -    /**
  205.79 -     * Allocates a {@code Boolean} object representing the
  205.80 -     * {@code value} argument.
  205.81 -     *
  205.82 -     * <p><b>Note: It is rarely appropriate to use this constructor.
  205.83 -     * Unless a <i>new</i> instance is required, the static factory
  205.84 -     * {@link #valueOf(boolean)} is generally a better choice. It is
  205.85 -     * likely to yield significantly better space and time performance.</b>
  205.86 -     *
  205.87 -     * @param   value   the value of the {@code Boolean}.
  205.88 -     */
  205.89 -    public Boolean(boolean value) {
  205.90 -        this.value = value;
  205.91 -    }
  205.92 -
  205.93 -    /**
  205.94 -     * Allocates a {@code Boolean} object representing the value
  205.95 -     * {@code true} if the string argument is not {@code null}
  205.96 -     * and is equal, ignoring case, to the string {@code "true"}.
  205.97 -     * Otherwise, allocate a {@code Boolean} object representing the
  205.98 -     * value {@code false}. Examples:<p>
  205.99 -     * {@code new Boolean("True")} produces a {@code Boolean} object
 205.100 -     * that represents {@code true}.<br>
 205.101 -     * {@code new Boolean("yes")} produces a {@code Boolean} object
 205.102 -     * that represents {@code false}.
 205.103 -     *
 205.104 -     * @param   s   the string to be converted to a {@code Boolean}.
 205.105 -     */
 205.106 -    public Boolean(String s) {
 205.107 -        this(toBoolean(s));
 205.108 -    }
 205.109 -
 205.110 -    /**
 205.111 -     * Parses the string argument as a boolean.  The {@code boolean}
 205.112 -     * returned represents the value {@code true} if the string argument
 205.113 -     * is not {@code null} and is equal, ignoring case, to the string
 205.114 -     * {@code "true"}. <p>
 205.115 -     * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
 205.116 -     * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
 205.117 -     *
 205.118 -     * @param      s   the {@code String} containing the boolean
 205.119 -     *                 representation to be parsed
 205.120 -     * @return     the boolean represented by the string argument
 205.121 -     * @since 1.5
 205.122 -     */
 205.123 -    public static boolean parseBoolean(String s) {
 205.124 -        return toBoolean(s);
 205.125 -    }
 205.126 -
 205.127 -    /**
 205.128 -     * Returns the value of this {@code Boolean} object as a boolean
 205.129 -     * primitive.
 205.130 -     *
 205.131 -     * @return  the primitive {@code boolean} value of this object.
 205.132 -     */
 205.133 -    public boolean booleanValue() {
 205.134 -        return value;
 205.135 -    }
 205.136 -
 205.137 -    /**
 205.138 -     * Returns a {@code Boolean} instance representing the specified
 205.139 -     * {@code boolean} value.  If the specified {@code boolean} value
 205.140 -     * is {@code true}, this method returns {@code Boolean.TRUE};
 205.141 -     * if it is {@code false}, this method returns {@code Boolean.FALSE}.
 205.142 -     * If a new {@code Boolean} instance is not required, this method
 205.143 -     * should generally be used in preference to the constructor
 205.144 -     * {@link #Boolean(boolean)}, as this method is likely to yield
 205.145 -     * significantly better space and time performance.
 205.146 -     *
 205.147 -     * @param  b a boolean value.
 205.148 -     * @return a {@code Boolean} instance representing {@code b}.
 205.149 -     * @since  1.4
 205.150 -     */
 205.151 -    public static Boolean valueOf(boolean b) {
 205.152 -        return (b ? TRUE : FALSE);
 205.153 -    }
 205.154 -
 205.155 -    /**
 205.156 -     * Returns a {@code Boolean} with a value represented by the
 205.157 -     * specified string.  The {@code Boolean} returned represents a
 205.158 -     * true value if the string argument is not {@code null}
 205.159 -     * and is equal, ignoring case, to the string {@code "true"}.
 205.160 -     *
 205.161 -     * @param   s   a string.
 205.162 -     * @return  the {@code Boolean} value represented by the string.
 205.163 -     */
 205.164 -    public static Boolean valueOf(String s) {
 205.165 -        return toBoolean(s) ? TRUE : FALSE;
 205.166 -    }
 205.167 -
 205.168 -    /**
 205.169 -     * Returns a {@code String} object representing the specified
 205.170 -     * boolean.  If the specified boolean is {@code true}, then
 205.171 -     * the string {@code "true"} will be returned, otherwise the
 205.172 -     * string {@code "false"} will be returned.
 205.173 -     *
 205.174 -     * @param b the boolean to be converted
 205.175 -     * @return the string representation of the specified {@code boolean}
 205.176 -     * @since 1.4
 205.177 -     */
 205.178 -    public static String toString(boolean b) {
 205.179 -        return b ? "true" : "false";
 205.180 -    }
 205.181 -
 205.182 -    /**
 205.183 -     * Returns a {@code String} object representing this Boolean's
 205.184 -     * value.  If this object represents the value {@code true},
 205.185 -     * a string equal to {@code "true"} is returned. Otherwise, a
 205.186 -     * string equal to {@code "false"} is returned.
 205.187 -     *
 205.188 -     * @return  a string representation of this object.
 205.189 -     */
 205.190 -    public String toString() {
 205.191 -        return value ? "true" : "false";
 205.192 -    }
 205.193 -
 205.194 -    /**
 205.195 -     * Returns a hash code for this {@code Boolean} object.
 205.196 -     *
 205.197 -     * @return  the integer {@code 1231} if this object represents
 205.198 -     * {@code true}; returns the integer {@code 1237} if this
 205.199 -     * object represents {@code false}.
 205.200 -     */
 205.201 -    public int hashCode() {
 205.202 -        return value ? 1231 : 1237;
 205.203 -    }
 205.204 -
 205.205 -    /**
 205.206 -     * Returns {@code true} if and only if the argument is not
 205.207 -     * {@code null} and is a {@code Boolean} object that
 205.208 -     * represents the same {@code boolean} value as this object.
 205.209 -     *
 205.210 -     * @param   obj   the object to compare with.
 205.211 -     * @return  {@code true} if the Boolean objects represent the
 205.212 -     *          same value; {@code false} otherwise.
 205.213 -     */
 205.214 -    public boolean equals(Object obj) {
 205.215 -        if (obj instanceof Boolean) {
 205.216 -            return value == ((Boolean)obj).booleanValue();
 205.217 -        }
 205.218 -        return false;
 205.219 -    }
 205.220 -
 205.221 -    /**
 205.222 -     * Returns {@code true} if and only if the system property
 205.223 -     * named by the argument exists and is equal to the string
 205.224 -     * {@code "true"}. (Beginning with version 1.0.2 of the
 205.225 -     * Java<small><sup>TM</sup></small> platform, the test of
 205.226 -     * this string is case insensitive.) A system property is accessible
 205.227 -     * through {@code getProperty}, a method defined by the
 205.228 -     * {@code System} class.
 205.229 -     * <p>
 205.230 -     * If there is no property with the specified name, or if the specified
 205.231 -     * name is empty or null, then {@code false} is returned.
 205.232 -     *
 205.233 -     * @param   name   the system property name.
 205.234 -     * @return  the {@code boolean} value of the system property.
 205.235 -     * @see     java.lang.System#getProperty(java.lang.String)
 205.236 -     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 205.237 -     */
 205.238 -    public static boolean getBoolean(String name) {
 205.239 -        boolean result = false;
 205.240 -        try {
 205.241 -            result = toBoolean(AbstractStringBuilder.getProperty(name));
 205.242 -        } catch (IllegalArgumentException e) {
 205.243 -        } catch (NullPointerException e) {
 205.244 -        }
 205.245 -        return result;
 205.246 -    }
 205.247 -
 205.248 -    /**
 205.249 -     * Compares this {@code Boolean} instance with another.
 205.250 -     *
 205.251 -     * @param   b the {@code Boolean} instance to be compared
 205.252 -     * @return  zero if this object represents the same boolean value as the
 205.253 -     *          argument; a positive value if this object represents true
 205.254 -     *          and the argument represents false; and a negative value if
 205.255 -     *          this object represents false and the argument represents true
 205.256 -     * @throws  NullPointerException if the argument is {@code null}
 205.257 -     * @see     Comparable
 205.258 -     * @since  1.5
 205.259 -     */
 205.260 -    public int compareTo(Boolean b) {
 205.261 -        return compare(this.value, b.value);
 205.262 -    }
 205.263 -
 205.264 -    /**
 205.265 -     * Compares two {@code boolean} values.
 205.266 -     * The value returned is identical to what would be returned by:
 205.267 -     * <pre>
 205.268 -     *    Boolean.valueOf(x).compareTo(Boolean.valueOf(y))
 205.269 -     * </pre>
 205.270 -     *
 205.271 -     * @param  x the first {@code boolean} to compare
 205.272 -     * @param  y the second {@code boolean} to compare
 205.273 -     * @return the value {@code 0} if {@code x == y};
 205.274 -     *         a value less than {@code 0} if {@code !x && y}; and
 205.275 -     *         a value greater than {@code 0} if {@code x && !y}
 205.276 -     * @since 1.7
 205.277 -     */
 205.278 -    public static int compare(boolean x, boolean y) {
 205.279 -        return (x == y) ? 0 : (x ? 1 : -1);
 205.280 -    }
 205.281 -
 205.282 -    private static boolean toBoolean(String name) {
 205.283 -        return ((name != null) && name.equalsIgnoreCase("true"));
 205.284 -    }
 205.285 -}
   206.1 --- a/emul/src/main/java/java/lang/Byte.java	Wed Dec 05 10:03:58 2012 +0100
   206.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   206.3 @@ -1,452 +0,0 @@
   206.4 -/*
   206.5 - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
   206.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   206.7 - *
   206.8 - * This code is free software; you can redistribute it and/or modify it
   206.9 - * under the terms of the GNU General Public License version 2 only, as
  206.10 - * published by the Free Software Foundation.  Oracle designates this
  206.11 - * particular file as subject to the "Classpath" exception as provided
  206.12 - * by Oracle in the LICENSE file that accompanied this code.
  206.13 - *
  206.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  206.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  206.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  206.17 - * version 2 for more details (a copy is included in the LICENSE file that
  206.18 - * accompanied this code).
  206.19 - *
  206.20 - * You should have received a copy of the GNU General Public License version
  206.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  206.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  206.23 - *
  206.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  206.25 - * or visit www.oracle.com if you need additional information or have any
  206.26 - * questions.
  206.27 - */
  206.28 -
  206.29 -package java.lang;
  206.30 -
  206.31 -/**
  206.32 - *
  206.33 - * The {@code Byte} class wraps a value of primitive type {@code byte}
  206.34 - * in an object.  An object of type {@code Byte} contains a single
  206.35 - * field whose type is {@code byte}.
  206.36 - *
  206.37 - * <p>In addition, this class provides several methods for converting
  206.38 - * a {@code byte} to a {@code String} and a {@code String} to a {@code
  206.39 - * byte}, as well as other constants and methods useful when dealing
  206.40 - * with a {@code byte}.
  206.41 - *
  206.42 - * @author  Nakul Saraiya
  206.43 - * @author  Joseph D. Darcy
  206.44 - * @see     java.lang.Number
  206.45 - * @since   JDK1.1
  206.46 - */
  206.47 -public final class Byte extends Number implements Comparable<Byte> {
  206.48 -
  206.49 -    /**
  206.50 -     * A constant holding the minimum value a {@code byte} can
  206.51 -     * have, -2<sup>7</sup>.
  206.52 -     */
  206.53 -    public static final byte   MIN_VALUE = -128;
  206.54 -
  206.55 -    /**
  206.56 -     * A constant holding the maximum value a {@code byte} can
  206.57 -     * have, 2<sup>7</sup>-1.
  206.58 -     */
  206.59 -    public static final byte   MAX_VALUE = 127;
  206.60 -
  206.61 -    /**
  206.62 -     * The {@code Class} instance representing the primitive type
  206.63 -     * {@code byte}.
  206.64 -     */
  206.65 -    public static final Class<Byte>     TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");
  206.66 -
  206.67 -    /**
  206.68 -     * Returns a new {@code String} object representing the
  206.69 -     * specified {@code byte}. The radix is assumed to be 10.
  206.70 -     *
  206.71 -     * @param b the {@code byte} to be converted
  206.72 -     * @return the string representation of the specified {@code byte}
  206.73 -     * @see java.lang.Integer#toString(int)
  206.74 -     */
  206.75 -    public static String toString(byte b) {
  206.76 -        return Integer.toString((int)b, 10);
  206.77 -    }
  206.78 -
  206.79 -    private static class ByteCache {
  206.80 -        private ByteCache(){}
  206.81 -
  206.82 -        static final Byte cache[] = new Byte[-(-128) + 127 + 1];
  206.83 -
  206.84 -        static {
  206.85 -            for(int i = 0; i < cache.length; i++)
  206.86 -                cache[i] = new Byte((byte)(i - 128));
  206.87 -        }
  206.88 -    }
  206.89 -
  206.90 -    /**
  206.91 -     * Returns a {@code Byte} instance representing the specified
  206.92 -     * {@code byte} value.
  206.93 -     * If a new {@code Byte} instance is not required, this method
  206.94 -     * should generally be used in preference to the constructor
  206.95 -     * {@link #Byte(byte)}, as this method is likely to yield
  206.96 -     * significantly better space and time performance since
  206.97 -     * all byte values are cached.
  206.98 -     *
  206.99 -     * @param  b a byte value.
 206.100 -     * @return a {@code Byte} instance representing {@code b}.
 206.101 -     * @since  1.5
 206.102 -     */
 206.103 -    public static Byte valueOf(byte b) {
 206.104 -        final int offset = 128;
 206.105 -        return ByteCache.cache[(int)b + offset];
 206.106 -    }
 206.107 -
 206.108 -    /**
 206.109 -     * Parses the string argument as a signed {@code byte} in the
 206.110 -     * radix specified by the second argument. The characters in the
 206.111 -     * string must all be digits, of the specified radix (as
 206.112 -     * determined by whether {@link java.lang.Character#digit(char,
 206.113 -     * int)} returns a nonnegative value) except that the first
 206.114 -     * character may be an ASCII minus sign {@code '-'}
 206.115 -     * (<code>'&#92;u002D'</code>) to indicate a negative value or an
 206.116 -     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
 206.117 -     * indicate a positive value.  The resulting {@code byte} value is
 206.118 -     * returned.
 206.119 -     *
 206.120 -     * <p>An exception of type {@code NumberFormatException} is
 206.121 -     * thrown if any of the following situations occurs:
 206.122 -     * <ul>
 206.123 -     * <li> The first argument is {@code null} or is a string of
 206.124 -     * length zero.
 206.125 -     *
 206.126 -     * <li> The radix is either smaller than {@link
 206.127 -     * java.lang.Character#MIN_RADIX} or larger than {@link
 206.128 -     * java.lang.Character#MAX_RADIX}.
 206.129 -     *
 206.130 -     * <li> Any character of the string is not a digit of the
 206.131 -     * specified radix, except that the first character may be a minus
 206.132 -     * sign {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
 206.133 -     * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
 206.134 -     * string is longer than length 1.
 206.135 -     *
 206.136 -     * <li> The value represented by the string is not a value of type
 206.137 -     * {@code byte}.
 206.138 -     * </ul>
 206.139 -     *
 206.140 -     * @param s         the {@code String} containing the
 206.141 -     *                  {@code byte}
 206.142 -     *                  representation to be parsed
 206.143 -     * @param radix     the radix to be used while parsing {@code s}
 206.144 -     * @return          the {@code byte} value represented by the string
 206.145 -     *                   argument in the specified radix
 206.146 -     * @throws          NumberFormatException If the string does
 206.147 -     *                  not contain a parsable {@code byte}.
 206.148 -     */
 206.149 -    public static byte parseByte(String s, int radix)
 206.150 -        throws NumberFormatException {
 206.151 -        int i = Integer.parseInt(s, radix);
 206.152 -        if (i < MIN_VALUE || i > MAX_VALUE)
 206.153 -            throw new NumberFormatException(
 206.154 -                "Value out of range. Value:\"" + s + "\" Radix:" + radix);
 206.155 -        return (byte)i;
 206.156 -    }
 206.157 -
 206.158 -    /**
 206.159 -     * Parses the string argument as a signed decimal {@code
 206.160 -     * byte}. The characters in the string must all be decimal digits,
 206.161 -     * except that the first character may be an ASCII minus sign
 206.162 -     * {@code '-'} (<code>'&#92;u002D'</code>) to indicate a negative
 206.163 -     * value or an ASCII plus sign {@code '+'}
 206.164 -     * (<code>'&#92;u002B'</code>) to indicate a positive value. The
 206.165 -     * resulting {@code byte} value is returned, exactly as if the
 206.166 -     * argument and the radix 10 were given as arguments to the {@link
 206.167 -     * #parseByte(java.lang.String, int)} method.
 206.168 -     *
 206.169 -     * @param s         a {@code String} containing the
 206.170 -     *                  {@code byte} representation to be parsed
 206.171 -     * @return          the {@code byte} value represented by the
 206.172 -     *                  argument in decimal
 206.173 -     * @throws          NumberFormatException if the string does not
 206.174 -     *                  contain a parsable {@code byte}.
 206.175 -     */
 206.176 -    public static byte parseByte(String s) throws NumberFormatException {
 206.177 -        return parseByte(s, 10);
 206.178 -    }
 206.179 -
 206.180 -    /**
 206.181 -     * Returns a {@code Byte} object holding the value
 206.182 -     * extracted from the specified {@code String} when parsed
 206.183 -     * with the radix given by the second argument. The first argument
 206.184 -     * is interpreted as representing a signed {@code byte} in
 206.185 -     * the radix specified by the second argument, exactly as if the
 206.186 -     * argument were given to the {@link #parseByte(java.lang.String,
 206.187 -     * int)} method. The result is a {@code Byte} object that
 206.188 -     * represents the {@code byte} value specified by the string.
 206.189 -     *
 206.190 -     * <p> In other words, this method returns a {@code Byte} object
 206.191 -     * equal to the value of:
 206.192 -     *
 206.193 -     * <blockquote>
 206.194 -     * {@code new Byte(Byte.parseByte(s, radix))}
 206.195 -     * </blockquote>
 206.196 -     *
 206.197 -     * @param s         the string to be parsed
 206.198 -     * @param radix     the radix to be used in interpreting {@code s}
 206.199 -     * @return          a {@code Byte} object holding the value
 206.200 -     *                  represented by the string argument in the
 206.201 -     *                  specified radix.
 206.202 -     * @throws          NumberFormatException If the {@code String} does
 206.203 -     *                  not contain a parsable {@code byte}.
 206.204 -     */
 206.205 -    public static Byte valueOf(String s, int radix)
 206.206 -        throws NumberFormatException {
 206.207 -        return valueOf(parseByte(s, radix));
 206.208 -    }
 206.209 -
 206.210 -    /**
 206.211 -     * Returns a {@code Byte} object holding the value
 206.212 -     * given by the specified {@code String}. The argument is
 206.213 -     * interpreted as representing a signed decimal {@code byte},
 206.214 -     * exactly as if the argument were given to the {@link
 206.215 -     * #parseByte(java.lang.String)} method. The result is a
 206.216 -     * {@code Byte} object that represents the {@code byte}
 206.217 -     * value specified by the string.
 206.218 -     *
 206.219 -     * <p> In other words, this method returns a {@code Byte} object
 206.220 -     * equal to the value of:
 206.221 -     *
 206.222 -     * <blockquote>
 206.223 -     * {@code new Byte(Byte.parseByte(s))}
 206.224 -     * </blockquote>
 206.225 -     *
 206.226 -     * @param s         the string to be parsed
 206.227 -     * @return          a {@code Byte} object holding the value
 206.228 -     *                  represented by the string argument
 206.229 -     * @throws          NumberFormatException If the {@code String} does
 206.230 -     *                  not contain a parsable {@code byte}.
 206.231 -     */
 206.232 -    public static Byte valueOf(String s) throws NumberFormatException {
 206.233 -        return valueOf(s, 10);
 206.234 -    }
 206.235 -
 206.236 -    /**
 206.237 -     * Decodes a {@code String} into a {@code Byte}.
 206.238 -     * Accepts decimal, hexadecimal, and octal numbers given by
 206.239 -     * the following grammar:
 206.240 -     *
 206.241 -     * <blockquote>
 206.242 -     * <dl>
 206.243 -     * <dt><i>DecodableString:</i>
 206.244 -     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 206.245 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 206.246 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 206.247 -     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 206.248 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 206.249 -     * <p>
 206.250 -     * <dt><i>Sign:</i>
 206.251 -     * <dd>{@code -}
 206.252 -     * <dd>{@code +}
 206.253 -     * </dl>
 206.254 -     * </blockquote>
 206.255 -     *
 206.256 -     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 206.257 -     * are as defined in section 3.10.1 of
 206.258 -     * <cite>The Java&trade; Language Specification</cite>,
 206.259 -     * except that underscores are not accepted between digits.
 206.260 -     *
 206.261 -     * <p>The sequence of characters following an optional
 206.262 -     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 206.263 -     * "{@code #}", or leading zero) is parsed as by the {@code
 206.264 -     * Byte.parseByte} method with the indicated radix (10, 16, or 8).
 206.265 -     * This sequence of characters must represent a positive value or
 206.266 -     * a {@link NumberFormatException} will be thrown.  The result is
 206.267 -     * negated if first character of the specified {@code String} is
 206.268 -     * the minus sign.  No whitespace characters are permitted in the
 206.269 -     * {@code String}.
 206.270 -     *
 206.271 -     * @param     nm the {@code String} to decode.
 206.272 -     * @return   a {@code Byte} object holding the {@code byte}
 206.273 -     *          value represented by {@code nm}
 206.274 -     * @throws  NumberFormatException  if the {@code String} does not
 206.275 -     *            contain a parsable {@code byte}.
 206.276 -     * @see java.lang.Byte#parseByte(java.lang.String, int)
 206.277 -     */
 206.278 -    public static Byte decode(String nm) throws NumberFormatException {
 206.279 -        int i = Integer.decode(nm);
 206.280 -        if (i < MIN_VALUE || i > MAX_VALUE)
 206.281 -            throw new NumberFormatException(
 206.282 -                    "Value " + i + " out of range from input " + nm);
 206.283 -        return valueOf((byte)i);
 206.284 -    }
 206.285 -
 206.286 -    /**
 206.287 -     * The value of the {@code Byte}.
 206.288 -     *
 206.289 -     * @serial
 206.290 -     */
 206.291 -    private final byte value;
 206.292 -
 206.293 -    /**
 206.294 -     * Constructs a newly allocated {@code Byte} object that
 206.295 -     * represents the specified {@code byte} value.
 206.296 -     *
 206.297 -     * @param value     the value to be represented by the
 206.298 -     *                  {@code Byte}.
 206.299 -     */
 206.300 -    public Byte(byte value) {
 206.301 -        this.value = value;
 206.302 -    }
 206.303 -
 206.304 -    /**
 206.305 -     * Constructs a newly allocated {@code Byte} object that
 206.306 -     * represents the {@code byte} value indicated by the
 206.307 -     * {@code String} parameter. The string is converted to a
 206.308 -     * {@code byte} value in exactly the manner used by the
 206.309 -     * {@code parseByte} method for radix 10.
 206.310 -     *
 206.311 -     * @param s         the {@code String} to be converted to a
 206.312 -     *                  {@code Byte}
 206.313 -     * @throws           NumberFormatException If the {@code String}
 206.314 -     *                  does not contain a parsable {@code byte}.
 206.315 -     * @see        java.lang.Byte#parseByte(java.lang.String, int)
 206.316 -     */
 206.317 -    public Byte(String s) throws NumberFormatException {
 206.318 -        this.value = parseByte(s, 10);
 206.319 -    }
 206.320 -
 206.321 -    /**
 206.322 -     * Returns the value of this {@code Byte} as a
 206.323 -     * {@code byte}.
 206.324 -     */
 206.325 -    public byte byteValue() {
 206.326 -        return value;
 206.327 -    }
 206.328 -
 206.329 -    /**
 206.330 -     * Returns the value of this {@code Byte} as a
 206.331 -     * {@code short}.
 206.332 -     */
 206.333 -    public short shortValue() {
 206.334 -        return (short)value;
 206.335 -    }
 206.336 -
 206.337 -    /**
 206.338 -     * Returns the value of this {@code Byte} as an
 206.339 -     * {@code int}.
 206.340 -     */
 206.341 -    public int intValue() {
 206.342 -        return (int)value;
 206.343 -    }
 206.344 -
 206.345 -    /**
 206.346 -     * Returns the value of this {@code Byte} as a
 206.347 -     * {@code long}.
 206.348 -     */
 206.349 -    public long longValue() {
 206.350 -        return (long)value;
 206.351 -    }
 206.352 -
 206.353 -    /**
 206.354 -     * Returns the value of this {@code Byte} as a
 206.355 -     * {@code float}.
 206.356 -     */
 206.357 -    public float floatValue() {
 206.358 -        return (float)value;
 206.359 -    }
 206.360 -
 206.361 -    /**
 206.362 -     * Returns the value of this {@code Byte} as a
 206.363 -     * {@code double}.
 206.364 -     */
 206.365 -    public double doubleValue() {
 206.366 -        return (double)value;
 206.367 -    }
 206.368 -
 206.369 -    /**
 206.370 -     * Returns a {@code String} object representing this
 206.371 -     * {@code Byte}'s value.  The value is converted to signed
 206.372 -     * decimal representation and returned as a string, exactly as if
 206.373 -     * the {@code byte} value were given as an argument to the
 206.374 -     * {@link java.lang.Byte#toString(byte)} method.
 206.375 -     *
 206.376 -     * @return  a string representation of the value of this object in
 206.377 -     *          base&nbsp;10.
 206.378 -     */
 206.379 -    public String toString() {
 206.380 -        return Integer.toString((int)value);
 206.381 -    }
 206.382 -
 206.383 -    /**
 206.384 -     * Returns a hash code for this {@code Byte}; equal to the result
 206.385 -     * of invoking {@code intValue()}.
 206.386 -     *
 206.387 -     * @return a hash code value for this {@code Byte}
 206.388 -     */
 206.389 -    public int hashCode() {
 206.390 -        return (int)value;
 206.391 -    }
 206.392 -
 206.393 -    /**
 206.394 -     * Compares this object to the specified object.  The result is
 206.395 -     * {@code true} if and only if the argument is not
 206.396 -     * {@code null} and is a {@code Byte} object that
 206.397 -     * contains the same {@code byte} value as this object.
 206.398 -     *
 206.399 -     * @param obj       the object to compare with
 206.400 -     * @return          {@code true} if the objects are the same;
 206.401 -     *                  {@code false} otherwise.
 206.402 -     */
 206.403 -    public boolean equals(Object obj) {
 206.404 -        if (obj instanceof Byte) {
 206.405 -            return value == ((Byte)obj).byteValue();
 206.406 -        }
 206.407 -        return false;
 206.408 -    }
 206.409 -
 206.410 -    /**
 206.411 -     * Compares two {@code Byte} objects numerically.
 206.412 -     *
 206.413 -     * @param   anotherByte   the {@code Byte} to be compared.
 206.414 -     * @return  the value {@code 0} if this {@code Byte} is
 206.415 -     *          equal to the argument {@code Byte}; a value less than
 206.416 -     *          {@code 0} if this {@code Byte} is numerically less
 206.417 -     *          than the argument {@code Byte}; and a value greater than
 206.418 -     *           {@code 0} if this {@code Byte} is numerically
 206.419 -     *           greater than the argument {@code Byte} (signed
 206.420 -     *           comparison).
 206.421 -     * @since   1.2
 206.422 -     */
 206.423 -    public int compareTo(Byte anotherByte) {
 206.424 -        return compare(this.value, anotherByte.value);
 206.425 -    }
 206.426 -
 206.427 -    /**
 206.428 -     * Compares two {@code byte} values numerically.
 206.429 -     * The value returned is identical to what would be returned by:
 206.430 -     * <pre>
 206.431 -     *    Byte.valueOf(x).compareTo(Byte.valueOf(y))
 206.432 -     * </pre>
 206.433 -     *
 206.434 -     * @param  x the first {@code byte} to compare
 206.435 -     * @param  y the second {@code byte} to compare
 206.436 -     * @return the value {@code 0} if {@code x == y};
 206.437 -     *         a value less than {@code 0} if {@code x < y}; and
 206.438 -     *         a value greater than {@code 0} if {@code x > y}
 206.439 -     * @since 1.7
 206.440 -     */
 206.441 -    public static int compare(byte x, byte y) {
 206.442 -        return x - y;
 206.443 -    }
 206.444 -
 206.445 -    /**
 206.446 -     * The number of bits used to represent a {@code byte} value in two's
 206.447 -     * complement binary form.
 206.448 -     *
 206.449 -     * @since 1.5
 206.450 -     */
 206.451 -    public static final int SIZE = 8;
 206.452 -
 206.453 -    /** use serialVersionUID from JDK 1.1. for interoperability */
 206.454 -    private static final long serialVersionUID = -7183698231559129828L;
 206.455 -}
   207.1 --- a/emul/src/main/java/java/lang/CharSequence.java	Wed Dec 05 10:03:58 2012 +0100
   207.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   207.3 @@ -1,111 +0,0 @@
   207.4 -/*
   207.5 - * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
   207.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   207.7 - *
   207.8 - * This code is free software; you can redistribute it and/or modify it
   207.9 - * under the terms of the GNU General Public License version 2 only, as
  207.10 - * published by the Free Software Foundation.  Oracle designates this
  207.11 - * particular file as subject to the "Classpath" exception as provided
  207.12 - * by Oracle in the LICENSE file that accompanied this code.
  207.13 - *
  207.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  207.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  207.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  207.17 - * version 2 for more details (a copy is included in the LICENSE file that
  207.18 - * accompanied this code).
  207.19 - *
  207.20 - * You should have received a copy of the GNU General Public License version
  207.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  207.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  207.23 - *
  207.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  207.25 - * or visit www.oracle.com if you need additional information or have any
  207.26 - * questions.
  207.27 - */
  207.28 -
  207.29 -package java.lang;
  207.30 -
  207.31 -
  207.32 -/**
  207.33 - * A <tt>CharSequence</tt> is a readable sequence of <code>char</code> values. This
  207.34 - * interface provides uniform, read-only access to many different kinds of
  207.35 - * <code>char</code> sequences.
  207.36 - * A <code>char</code> value represents a character in the <i>Basic
  207.37 - * Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
  207.38 - * href="Character.html#unicode">Unicode Character Representation</a> for details.
  207.39 - *
  207.40 - * <p> This interface does not refine the general contracts of the {@link
  207.41 - * java.lang.Object#equals(java.lang.Object) equals} and {@link
  207.42 - * java.lang.Object#hashCode() hashCode} methods.  The result of comparing two
  207.43 - * objects that implement <tt>CharSequence</tt> is therefore, in general,
  207.44 - * undefined.  Each object may be implemented by a different class, and there
  207.45 - * is no guarantee that each class will be capable of testing its instances
  207.46 - * for equality with those of the other.  It is therefore inappropriate to use
  207.47 - * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in
  207.48 - * a map. </p>
  207.49 - *
  207.50 - * @author Mike McCloskey
  207.51 - * @since 1.4
  207.52 - * @spec JSR-51
  207.53 - */
  207.54 -
  207.55 -public interface CharSequence {
  207.56 -
  207.57 -    /**
  207.58 -     * Returns the length of this character sequence.  The length is the number
  207.59 -     * of 16-bit <code>char</code>s in the sequence.</p>
  207.60 -     *
  207.61 -     * @return  the number of <code>char</code>s in this sequence
  207.62 -     */
  207.63 -    int length();
  207.64 -
  207.65 -    /**
  207.66 -     * Returns the <code>char</code> value at the specified index.  An index ranges from zero
  207.67 -     * to <tt>length() - 1</tt>.  The first <code>char</code> value of the sequence is at
  207.68 -     * index zero, the next at index one, and so on, as for array
  207.69 -     * indexing. </p>
  207.70 -     *
  207.71 -     * <p>If the <code>char</code> value specified by the index is a
  207.72 -     * <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
  207.73 -     * value is returned.
  207.74 -     *
  207.75 -     * @param   index   the index of the <code>char</code> value to be returned
  207.76 -     *
  207.77 -     * @return  the specified <code>char</code> value
  207.78 -     *
  207.79 -     * @throws  IndexOutOfBoundsException
  207.80 -     *          if the <tt>index</tt> argument is negative or not less than
  207.81 -     *          <tt>length()</tt>
  207.82 -     */
  207.83 -    char charAt(int index);
  207.84 -
  207.85 -    /**
  207.86 -     * Returns a new <code>CharSequence</code> that is a subsequence of this sequence.
  207.87 -     * The subsequence starts with the <code>char</code> value at the specified index and
  207.88 -     * ends with the <code>char</code> value at index <tt>end - 1</tt>.  The length
  207.89 -     * (in <code>char</code>s) of the
  207.90 -     * returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
  207.91 -     * then an empty sequence is returned. </p>
  207.92 -     *
  207.93 -     * @param   start   the start index, inclusive
  207.94 -     * @param   end     the end index, exclusive
  207.95 -     *
  207.96 -     * @return  the specified subsequence
  207.97 -     *
  207.98 -     * @throws  IndexOutOfBoundsException
  207.99 -     *          if <tt>start</tt> or <tt>end</tt> are negative,
 207.100 -     *          if <tt>end</tt> is greater than <tt>length()</tt>,
 207.101 -     *          or if <tt>start</tt> is greater than <tt>end</tt>
 207.102 -     */
 207.103 -    CharSequence subSequence(int start, int end);
 207.104 -
 207.105 -    /**
 207.106 -     * Returns a string containing the characters in this sequence in the same
 207.107 -     * order as this sequence.  The length of the string will be the length of
 207.108 -     * this sequence. </p>
 207.109 -     *
 207.110 -     * @return  a string consisting of exactly this sequence of characters
 207.111 -     */
 207.112 -    public String toString();
 207.113 -
 207.114 -}
   208.1 --- a/emul/src/main/java/java/lang/Character.java	Wed Dec 05 10:03:58 2012 +0100
   208.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   208.3 @@ -1,2388 +0,0 @@
   208.4 -/*
   208.5 - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
   208.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   208.7 - *
   208.8 - * This code is free software; you can redistribute it and/or modify it
   208.9 - * under the terms of the GNU General Public License version 2 only, as
  208.10 - * published by the Free Software Foundation.  Oracle designates this
  208.11 - * particular file as subject to the "Classpath" exception as provided
  208.12 - * by Oracle in the LICENSE file that accompanied this code.
  208.13 - *
  208.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  208.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  208.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  208.17 - * version 2 for more details (a copy is included in the LICENSE file that
  208.18 - * accompanied this code).
  208.19 - *
  208.20 - * You should have received a copy of the GNU General Public License version
  208.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  208.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  208.23 - *
  208.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  208.25 - * or visit www.oracle.com if you need additional information or have any
  208.26 - * questions.
  208.27 - */
  208.28 -
  208.29 -package java.lang;
  208.30 -
  208.31 -/**
  208.32 - * The {@code Character} class wraps a value of the primitive
  208.33 - * type {@code char} in an object. An object of type
  208.34 - * {@code Character} contains a single field whose type is
  208.35 - * {@code char}.
  208.36 - * <p>
  208.37 - * In addition, this class provides several methods for determining
  208.38 - * a character's category (lowercase letter, digit, etc.) and for converting
  208.39 - * characters from uppercase to lowercase and vice versa.
  208.40 - * <p>
  208.41 - * Character information is based on the Unicode Standard, version 6.0.0.
  208.42 - * <p>
  208.43 - * The methods and data of class {@code Character} are defined by
  208.44 - * the information in the <i>UnicodeData</i> file that is part of the
  208.45 - * Unicode Character Database maintained by the Unicode
  208.46 - * Consortium. This file specifies various properties including name
  208.47 - * and general category for every defined Unicode code point or
  208.48 - * character range.
  208.49 - * <p>
  208.50 - * The file and its description are available from the Unicode Consortium at:
  208.51 - * <ul>
  208.52 - * <li><a href="http://www.unicode.org">http://www.unicode.org</a>
  208.53 - * </ul>
  208.54 - *
  208.55 - * <h4><a name="unicode">Unicode Character Representations</a></h4>
  208.56 - *
  208.57 - * <p>The {@code char} data type (and therefore the value that a
  208.58 - * {@code Character} object encapsulates) are based on the
  208.59 - * original Unicode specification, which defined characters as
  208.60 - * fixed-width 16-bit entities. The Unicode Standard has since been
  208.61 - * changed to allow for characters whose representation requires more
  208.62 - * than 16 bits.  The range of legal <em>code point</em>s is now
  208.63 - * U+0000 to U+10FFFF, known as <em>Unicode scalar value</em>.
  208.64 - * (Refer to the <a
  208.65 - * href="http://www.unicode.org/reports/tr27/#notation"><i>
  208.66 - * definition</i></a> of the U+<i>n</i> notation in the Unicode
  208.67 - * Standard.)
  208.68 - *
  208.69 - * <p><a name="BMP">The set of characters from U+0000 to U+FFFF is
  208.70 - * sometimes referred to as the <em>Basic Multilingual Plane (BMP)</em>.
  208.71 - * <a name="supplementary">Characters</a> whose code points are greater
  208.72 - * than U+FFFF are called <em>supplementary character</em>s.  The Java
  208.73 - * platform uses the UTF-16 representation in {@code char} arrays and
  208.74 - * in the {@code String} and {@code StringBuffer} classes. In
  208.75 - * this representation, supplementary characters are represented as a pair
  208.76 - * of {@code char} values, the first from the <em>high-surrogates</em>
  208.77 - * range, (&#92;uD800-&#92;uDBFF), the second from the
  208.78 - * <em>low-surrogates</em> range (&#92;uDC00-&#92;uDFFF).
  208.79 - *
  208.80 - * <p>A {@code char} value, therefore, represents Basic
  208.81 - * Multilingual Plane (BMP) code points, including the surrogate
  208.82 - * code points, or code units of the UTF-16 encoding. An
  208.83 - * {@code int} value represents all Unicode code points,
  208.84 - * including supplementary code points. The lower (least significant)
  208.85 - * 21 bits of {@code int} are used to represent Unicode code
  208.86 - * points and the upper (most significant) 11 bits must be zero.
  208.87 - * Unless otherwise specified, the behavior with respect to
  208.88 - * supplementary characters and surrogate {@code char} values is
  208.89 - * as follows:
  208.90 - *
  208.91 - * <ul>
  208.92 - * <li>The methods that only accept a {@code char} value cannot support
  208.93 - * supplementary characters. They treat {@code char} values from the
  208.94 - * surrogate ranges as undefined characters. For example,
  208.95 - * {@code Character.isLetter('\u005CuD840')} returns {@code false}, even though
  208.96 - * this specific value if followed by any low-surrogate value in a string
  208.97 - * would represent a letter.
  208.98 - *
  208.99 - * <li>The methods that accept an {@code int} value support all
 208.100 - * Unicode characters, including supplementary characters. For
 208.101 - * example, {@code Character.isLetter(0x2F81A)} returns
 208.102 - * {@code true} because the code point value represents a letter
 208.103 - * (a CJK ideograph).
 208.104 - * </ul>
 208.105 - *
 208.106 - * <p>In the Java SE API documentation, <em>Unicode code point</em> is
 208.107 - * used for character values in the range between U+0000 and U+10FFFF,
 208.108 - * and <em>Unicode code unit</em> is used for 16-bit
 208.109 - * {@code char} values that are code units of the <em>UTF-16</em>
 208.110 - * encoding. For more information on Unicode terminology, refer to the
 208.111 - * <a href="http://www.unicode.org/glossary/">Unicode Glossary</a>.
 208.112 - *
 208.113 - * @author  Lee Boynton
 208.114 - * @author  Guy Steele
 208.115 - * @author  Akira Tanaka
 208.116 - * @author  Martin Buchholz
 208.117 - * @author  Ulf Zibis
 208.118 - * @since   1.0
 208.119 - */
 208.120 -public final
 208.121 -class Character implements java.io.Serializable, Comparable<Character> {
 208.122 -    /**
 208.123 -     * The minimum radix available for conversion to and from strings.
 208.124 -     * The constant value of this field is the smallest value permitted
 208.125 -     * for the radix argument in radix-conversion methods such as the
 208.126 -     * {@code digit} method, the {@code forDigit} method, and the
 208.127 -     * {@code toString} method of class {@code Integer}.
 208.128 -     *
 208.129 -     * @see     Character#digit(char, int)
 208.130 -     * @see     Character#forDigit(int, int)
 208.131 -     * @see     Integer#toString(int, int)
 208.132 -     * @see     Integer#valueOf(String)
 208.133 -     */
 208.134 -    public static final int MIN_RADIX = 2;
 208.135 -
 208.136 -    /**
 208.137 -     * The maximum radix available for conversion to and from strings.
 208.138 -     * The constant value of this field is the largest value permitted
 208.139 -     * for the radix argument in radix-conversion methods such as the
 208.140 -     * {@code digit} method, the {@code forDigit} method, and the
 208.141 -     * {@code toString} method of class {@code Integer}.
 208.142 -     *
 208.143 -     * @see     Character#digit(char, int)
 208.144 -     * @see     Character#forDigit(int, int)
 208.145 -     * @see     Integer#toString(int, int)
 208.146 -     * @see     Integer#valueOf(String)
 208.147 -     */
 208.148 -    public static final int MAX_RADIX = 36;
 208.149 -
 208.150 -    /**
 208.151 -     * The constant value of this field is the smallest value of type
 208.152 -     * {@code char}, {@code '\u005Cu0000'}.
 208.153 -     *
 208.154 -     * @since   1.0.2
 208.155 -     */
 208.156 -    public static final char MIN_VALUE = '\u0000';
 208.157 -
 208.158 -    /**
 208.159 -     * The constant value of this field is the largest value of type
 208.160 -     * {@code char}, {@code '\u005CuFFFF'}.
 208.161 -     *
 208.162 -     * @since   1.0.2
 208.163 -     */
 208.164 -    public static final char MAX_VALUE = '\uFFFF';
 208.165 -
 208.166 -    /**
 208.167 -     * The {@code Class} instance representing the primitive type
 208.168 -     * {@code char}.
 208.169 -     *
 208.170 -     * @since   1.1
 208.171 -     */
 208.172 -    public static final Class<Character> TYPE = Class.getPrimitiveClass("char");
 208.173 -
 208.174 -    /*
 208.175 -     * Normative general types
 208.176 -     */
 208.177 -
 208.178 -    /*
 208.179 -     * General character types
 208.180 -     */
 208.181 -
 208.182 -    /**
 208.183 -     * General category "Cn" in the Unicode specification.
 208.184 -     * @since   1.1
 208.185 -     */
 208.186 -    public static final byte UNASSIGNED = 0;
 208.187 -
 208.188 -    /**
 208.189 -     * General category "Lu" in the Unicode specification.
 208.190 -     * @since   1.1
 208.191 -     */
 208.192 -    public static final byte UPPERCASE_LETTER = 1;
 208.193 -
 208.194 -    /**
 208.195 -     * General category "Ll" in the Unicode specification.
 208.196 -     * @since   1.1
 208.197 -     */
 208.198 -    public static final byte LOWERCASE_LETTER = 2;
 208.199 -
 208.200 -    /**
 208.201 -     * General category "Lt" in the Unicode specification.
 208.202 -     * @since   1.1
 208.203 -     */
 208.204 -    public static final byte TITLECASE_LETTER = 3;
 208.205 -
 208.206 -    /**
 208.207 -     * General category "Lm" in the Unicode specification.
 208.208 -     * @since   1.1
 208.209 -     */
 208.210 -    public static final byte MODIFIER_LETTER = 4;
 208.211 -
 208.212 -    /**
 208.213 -     * General category "Lo" in the Unicode specification.
 208.214 -     * @since   1.1
 208.215 -     */
 208.216 -    public static final byte OTHER_LETTER = 5;
 208.217 -
 208.218 -    /**
 208.219 -     * General category "Mn" in the Unicode specification.
 208.220 -     * @since   1.1
 208.221 -     */
 208.222 -    public static final byte NON_SPACING_MARK = 6;
 208.223 -
 208.224 -    /**
 208.225 -     * General category "Me" in the Unicode specification.
 208.226 -     * @since   1.1
 208.227 -     */
 208.228 -    public static final byte ENCLOSING_MARK = 7;
 208.229 -
 208.230 -    /**
 208.231 -     * General category "Mc" in the Unicode specification.
 208.232 -     * @since   1.1
 208.233 -     */
 208.234 -    public static final byte COMBINING_SPACING_MARK = 8;
 208.235 -
 208.236 -    /**
 208.237 -     * General category "Nd" in the Unicode specification.
 208.238 -     * @since   1.1
 208.239 -     */
 208.240 -    public static final byte DECIMAL_DIGIT_NUMBER        = 9;
 208.241 -
 208.242 -    /**
 208.243 -     * General category "Nl" in the Unicode specification.
 208.244 -     * @since   1.1
 208.245 -     */
 208.246 -    public static final byte LETTER_NUMBER = 10;
 208.247 -
 208.248 -    /**
 208.249 -     * General category "No" in the Unicode specification.
 208.250 -     * @since   1.1
 208.251 -     */
 208.252 -    public static final byte OTHER_NUMBER = 11;
 208.253 -
 208.254 -    /**
 208.255 -     * General category "Zs" in the Unicode specification.
 208.256 -     * @since   1.1
 208.257 -     */
 208.258 -    public static final byte SPACE_SEPARATOR = 12;
 208.259 -
 208.260 -    /**
 208.261 -     * General category "Zl" in the Unicode specification.
 208.262 -     * @since   1.1
 208.263 -     */
 208.264 -    public static final byte LINE_SEPARATOR = 13;
 208.265 -
 208.266 -    /**
 208.267 -     * General category "Zp" in the Unicode specification.
 208.268 -     * @since   1.1
 208.269 -     */
 208.270 -    public static final byte PARAGRAPH_SEPARATOR = 14;
 208.271 -
 208.272 -    /**
 208.273 -     * General category "Cc" in the Unicode specification.
 208.274 -     * @since   1.1
 208.275 -     */
 208.276 -    public static final byte CONTROL = 15;
 208.277 -
 208.278 -    /**
 208.279 -     * General category "Cf" in the Unicode specification.
 208.280 -     * @since   1.1
 208.281 -     */
 208.282 -    public static final byte FORMAT = 16;
 208.283 -
 208.284 -    /**
 208.285 -     * General category "Co" in the Unicode specification.
 208.286 -     * @since   1.1
 208.287 -     */
 208.288 -    public static final byte PRIVATE_USE = 18;
 208.289 -
 208.290 -    /**
 208.291 -     * General category "Cs" in the Unicode specification.
 208.292 -     * @since   1.1
 208.293 -     */
 208.294 -    public static final byte SURROGATE = 19;
 208.295 -
 208.296 -    /**
 208.297 -     * General category "Pd" in the Unicode specification.
 208.298 -     * @since   1.1
 208.299 -     */
 208.300 -    public static final byte DASH_PUNCTUATION = 20;
 208.301 -
 208.302 -    /**
 208.303 -     * General category "Ps" in the Unicode specification.
 208.304 -     * @since   1.1
 208.305 -     */
 208.306 -    public static final byte START_PUNCTUATION = 21;
 208.307 -
 208.308 -    /**
 208.309 -     * General category "Pe" in the Unicode specification.
 208.310 -     * @since   1.1
 208.311 -     */
 208.312 -    public static final byte END_PUNCTUATION = 22;
 208.313 -
 208.314 -    /**
 208.315 -     * General category "Pc" in the Unicode specification.
 208.316 -     * @since   1.1
 208.317 -     */
 208.318 -    public static final byte CONNECTOR_PUNCTUATION = 23;
 208.319 -
 208.320 -    /**
 208.321 -     * General category "Po" in the Unicode specification.
 208.322 -     * @since   1.1
 208.323 -     */
 208.324 -    public static final byte OTHER_PUNCTUATION = 24;
 208.325 -
 208.326 -    /**
 208.327 -     * General category "Sm" in the Unicode specification.
 208.328 -     * @since   1.1
 208.329 -     */
 208.330 -    public static final byte MATH_SYMBOL = 25;
 208.331 -
 208.332 -    /**
 208.333 -     * General category "Sc" in the Unicode specification.
 208.334 -     * @since   1.1
 208.335 -     */
 208.336 -    public static final byte CURRENCY_SYMBOL = 26;
 208.337 -
 208.338 -    /**
 208.339 -     * General category "Sk" in the Unicode specification.
 208.340 -     * @since   1.1
 208.341 -     */
 208.342 -    public static final byte MODIFIER_SYMBOL = 27;
 208.343 -
 208.344 -    /**
 208.345 -     * General category "So" in the Unicode specification.
 208.346 -     * @since   1.1
 208.347 -     */
 208.348 -    public static final byte OTHER_SYMBOL = 28;
 208.349 -
 208.350 -    /**
 208.351 -     * General category "Pi" in the Unicode specification.
 208.352 -     * @since   1.4
 208.353 -     */
 208.354 -    public static final byte INITIAL_QUOTE_PUNCTUATION = 29;
 208.355 -
 208.356 -    /**
 208.357 -     * General category "Pf" in the Unicode specification.
 208.358 -     * @since   1.4
 208.359 -     */
 208.360 -    public static final byte FINAL_QUOTE_PUNCTUATION = 30;
 208.361 -
 208.362 -    /**
 208.363 -     * Error flag. Use int (code point) to avoid confusion with U+FFFF.
 208.364 -     */
 208.365 -    static final int ERROR = 0xFFFFFFFF;
 208.366 -
 208.367 -
 208.368 -    /**
 208.369 -     * Undefined bidirectional character type. Undefined {@code char}
 208.370 -     * values have undefined directionality in the Unicode specification.
 208.371 -     * @since 1.4
 208.372 -     */
 208.373 -    public static final byte DIRECTIONALITY_UNDEFINED = -1;
 208.374 -
 208.375 -    /**
 208.376 -     * Strong bidirectional character type "L" in the Unicode specification.
 208.377 -     * @since 1.4
 208.378 -     */
 208.379 -    public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = 0;
 208.380 -
 208.381 -    /**
 208.382 -     * Strong bidirectional character type "R" in the Unicode specification.
 208.383 -     * @since 1.4
 208.384 -     */
 208.385 -    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = 1;
 208.386 -
 208.387 -    /**
 208.388 -    * Strong bidirectional character type "AL" in the Unicode specification.
 208.389 -     * @since 1.4
 208.390 -     */
 208.391 -    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = 2;
 208.392 -
 208.393 -    /**
 208.394 -     * Weak bidirectional character type "EN" in the Unicode specification.
 208.395 -     * @since 1.4
 208.396 -     */
 208.397 -    public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = 3;
 208.398 -
 208.399 -    /**
 208.400 -     * Weak bidirectional character type "ES" in the Unicode specification.
 208.401 -     * @since 1.4
 208.402 -     */
 208.403 -    public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = 4;
 208.404 -
 208.405 -    /**
 208.406 -     * Weak bidirectional character type "ET" in the Unicode specification.
 208.407 -     * @since 1.4
 208.408 -     */
 208.409 -    public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = 5;
 208.410 -
 208.411 -    /**
 208.412 -     * Weak bidirectional character type "AN" in the Unicode specification.
 208.413 -     * @since 1.4
 208.414 -     */
 208.415 -    public static final byte DIRECTIONALITY_ARABIC_NUMBER = 6;
 208.416 -
 208.417 -    /**
 208.418 -     * Weak bidirectional character type "CS" in the Unicode specification.
 208.419 -     * @since 1.4
 208.420 -     */
 208.421 -    public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = 7;
 208.422 -
 208.423 -    /**
 208.424 -     * Weak bidirectional character type "NSM" in the Unicode specification.
 208.425 -     * @since 1.4
 208.426 -     */
 208.427 -    public static final byte DIRECTIONALITY_NONSPACING_MARK = 8;
 208.428 -
 208.429 -    /**
 208.430 -     * Weak bidirectional character type "BN" in the Unicode specification.
 208.431 -     * @since 1.4
 208.432 -     */
 208.433 -    public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = 9;
 208.434 -
 208.435 -    /**
 208.436 -     * Neutral bidirectional character type "B" in the Unicode specification.
 208.437 -     * @since 1.4
 208.438 -     */
 208.439 -    public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = 10;
 208.440 -
 208.441 -    /**
 208.442 -     * Neutral bidirectional character type "S" in the Unicode specification.
 208.443 -     * @since 1.4
 208.444 -     */
 208.445 -    public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = 11;
 208.446 -
 208.447 -    /**
 208.448 -     * Neutral bidirectional character type "WS" in the Unicode specification.
 208.449 -     * @since 1.4
 208.450 -     */
 208.451 -    public static final byte DIRECTIONALITY_WHITESPACE = 12;
 208.452 -
 208.453 -    /**
 208.454 -     * Neutral bidirectional character type "ON" in the Unicode specification.
 208.455 -     * @since 1.4
 208.456 -     */
 208.457 -    public static final byte DIRECTIONALITY_OTHER_NEUTRALS = 13;
 208.458 -
 208.459 -    /**
 208.460 -     * Strong bidirectional character type "LRE" in the Unicode specification.
 208.461 -     * @since 1.4
 208.462 -     */
 208.463 -    public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = 14;
 208.464 -
 208.465 -    /**
 208.466 -     * Strong bidirectional character type "LRO" in the Unicode specification.
 208.467 -     * @since 1.4
 208.468 -     */
 208.469 -    public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = 15;
 208.470 -
 208.471 -    /**
 208.472 -     * Strong bidirectional character type "RLE" in the Unicode specification.
 208.473 -     * @since 1.4
 208.474 -     */
 208.475 -    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = 16;
 208.476 -
 208.477 -    /**
 208.478 -     * Strong bidirectional character type "RLO" in the Unicode specification.
 208.479 -     * @since 1.4
 208.480 -     */
 208.481 -    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = 17;
 208.482 -
 208.483 -    /**
 208.484 -     * Weak bidirectional character type "PDF" in the Unicode specification.
 208.485 -     * @since 1.4
 208.486 -     */
 208.487 -    public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18;
 208.488 -
 208.489 -    /**
 208.490 -     * The minimum value of a
 208.491 -     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 208.492 -     * Unicode high-surrogate code unit</a>
 208.493 -     * in the UTF-16 encoding, constant {@code '\u005CuD800'}.
 208.494 -     * A high-surrogate is also known as a <i>leading-surrogate</i>.
 208.495 -     *
 208.496 -     * @since 1.5
 208.497 -     */
 208.498 -    public static final char MIN_HIGH_SURROGATE = '\uD800';
 208.499 -
 208.500 -    /**
 208.501 -     * The maximum value of a
 208.502 -     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 208.503 -     * Unicode high-surrogate code unit</a>
 208.504 -     * in the UTF-16 encoding, constant {@code '\u005CuDBFF'}.
 208.505 -     * A high-surrogate is also known as a <i>leading-surrogate</i>.
 208.506 -     *
 208.507 -     * @since 1.5
 208.508 -     */
 208.509 -    public static final char MAX_HIGH_SURROGATE = '\uDBFF';
 208.510 -
 208.511 -    /**
 208.512 -     * The minimum value of a
 208.513 -     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
 208.514 -     * Unicode low-surrogate code unit</a>
 208.515 -     * in the UTF-16 encoding, constant {@code '\u005CuDC00'}.
 208.516 -     * A low-surrogate is also known as a <i>trailing-surrogate</i>.
 208.517 -     *
 208.518 -     * @since 1.5
 208.519 -     */
 208.520 -    public static final char MIN_LOW_SURROGATE  = '\uDC00';
 208.521 -
 208.522 -    /**
 208.523 -     * The maximum value of a
 208.524 -     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
 208.525 -     * Unicode low-surrogate code unit</a>
 208.526 -     * in the UTF-16 encoding, constant {@code '\u005CuDFFF'}.
 208.527 -     * A low-surrogate is also known as a <i>trailing-surrogate</i>.
 208.528 -     *
 208.529 -     * @since 1.5
 208.530 -     */
 208.531 -    public static final char MAX_LOW_SURROGATE  = '\uDFFF';
 208.532 -
 208.533 -    /**
 208.534 -     * The minimum value of a Unicode surrogate code unit in the
 208.535 -     * UTF-16 encoding, constant {@code '\u005CuD800'}.
 208.536 -     *
 208.537 -     * @since 1.5
 208.538 -     */
 208.539 -    public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE;
 208.540 -
 208.541 -    /**
 208.542 -     * The maximum value of a Unicode surrogate code unit in the
 208.543 -     * UTF-16 encoding, constant {@code '\u005CuDFFF'}.
 208.544 -     *
 208.545 -     * @since 1.5
 208.546 -     */
 208.547 -    public static final char MAX_SURROGATE = MAX_LOW_SURROGATE;
 208.548 -
 208.549 -    /**
 208.550 -     * The minimum value of a
 208.551 -     * <a href="http://www.unicode.org/glossary/#supplementary_code_point">
 208.552 -     * Unicode supplementary code point</a>, constant {@code U+10000}.
 208.553 -     *
 208.554 -     * @since 1.5
 208.555 -     */
 208.556 -    public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000;
 208.557 -
 208.558 -    /**
 208.559 -     * The minimum value of a
 208.560 -     * <a href="http://www.unicode.org/glossary/#code_point">
 208.561 -     * Unicode code point</a>, constant {@code U+0000}.
 208.562 -     *
 208.563 -     * @since 1.5
 208.564 -     */
 208.565 -    public static final int MIN_CODE_POINT = 0x000000;
 208.566 -
 208.567 -    /**
 208.568 -     * The maximum value of a
 208.569 -     * <a href="http://www.unicode.org/glossary/#code_point">
 208.570 -     * Unicode code point</a>, constant {@code U+10FFFF}.
 208.571 -     *
 208.572 -     * @since 1.5
 208.573 -     */
 208.574 -    public static final int MAX_CODE_POINT = 0X10FFFF;
 208.575 -
 208.576 -
 208.577 -    /**
 208.578 -     * Instances of this class represent particular subsets of the Unicode
 208.579 -     * character set.  The only family of subsets defined in the
 208.580 -     * {@code Character} class is {@link Character.UnicodeBlock}.
 208.581 -     * Other portions of the Java API may define other subsets for their
 208.582 -     * own purposes.
 208.583 -     *
 208.584 -     * @since 1.2
 208.585 -     */
 208.586 -    public static class Subset  {
 208.587 -
 208.588 -        private String name;
 208.589 -
 208.590 -        /**
 208.591 -         * Constructs a new {@code Subset} instance.
 208.592 -         *
 208.593 -         * @param  name  The name of this subset
 208.594 -         * @exception NullPointerException if name is {@code null}
 208.595 -         */
 208.596 -        protected Subset(String name) {
 208.597 -            if (name == null) {
 208.598 -                throw new NullPointerException("name");
 208.599 -            }
 208.600 -            this.name = name;
 208.601 -        }
 208.602 -
 208.603 -        /**
 208.604 -         * Compares two {@code Subset} objects for equality.
 208.605 -         * This method returns {@code true} if and only if
 208.606 -         * {@code this} and the argument refer to the same
 208.607 -         * object; since this method is {@code final}, this
 208.608 -         * guarantee holds for all subclasses.
 208.609 -         */
 208.610 -        public final boolean equals(Object obj) {
 208.611 -            return (this == obj);
 208.612 -        }
 208.613 -
 208.614 -        /**
 208.615 -         * Returns the standard hash code as defined by the
 208.616 -         * {@link Object#hashCode} method.  This method
 208.617 -         * is {@code final} in order to ensure that the
 208.618 -         * {@code equals} and {@code hashCode} methods will
 208.619 -         * be consistent in all subclasses.
 208.620 -         */
 208.621 -        public final int hashCode() {
 208.622 -            return super.hashCode();
 208.623 -        }
 208.624 -
 208.625 -        /**
 208.626 -         * Returns the name of this subset.
 208.627 -         */
 208.628 -        public final String toString() {
 208.629 -            return name;
 208.630 -        }
 208.631 -    }
 208.632 -
 208.633 -    // See http://www.unicode.org/Public/UNIDATA/Blocks.txt
 208.634 -    // for the latest specification of Unicode Blocks.
 208.635 -
 208.636 -
 208.637 -    /**
 208.638 -     * The value of the {@code Character}.
 208.639 -     *
 208.640 -     * @serial
 208.641 -     */
 208.642 -    private final char value;
 208.643 -
 208.644 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 208.645 -    private static final long serialVersionUID = 3786198910865385080L;
 208.646 -
 208.647 -    /**
 208.648 -     * Constructs a newly allocated {@code Character} object that
 208.649 -     * represents the specified {@code char} value.
 208.650 -     *
 208.651 -     * @param  value   the value to be represented by the
 208.652 -     *                  {@code Character} object.
 208.653 -     */
 208.654 -    public Character(char value) {
 208.655 -        this.value = value;
 208.656 -    }
 208.657 -
 208.658 -    private static class CharacterCache {
 208.659 -        private CharacterCache(){}
 208.660 -
 208.661 -        static final Character cache[] = new Character[127 + 1];
 208.662 -
 208.663 -        static {
 208.664 -            for (int i = 0; i < cache.length; i++)
 208.665 -                cache[i] = new Character((char)i);
 208.666 -        }
 208.667 -    }
 208.668 -
 208.669 -    /**
 208.670 -     * Returns a <tt>Character</tt> instance representing the specified
 208.671 -     * <tt>char</tt> value.
 208.672 -     * If a new <tt>Character</tt> instance is not required, this method
 208.673 -     * should generally be used in preference to the constructor
 208.674 -     * {@link #Character(char)}, as this method is likely to yield
 208.675 -     * significantly better space and time performance by caching
 208.676 -     * frequently requested values.
 208.677 -     *
 208.678 -     * This method will always cache values in the range {@code
 208.679 -     * '\u005Cu0000'} to {@code '\u005Cu007F'}, inclusive, and may
 208.680 -     * cache other values outside of this range.
 208.681 -     *
 208.682 -     * @param  c a char value.
 208.683 -     * @return a <tt>Character</tt> instance representing <tt>c</tt>.
 208.684 -     * @since  1.5
 208.685 -     */
 208.686 -    public static Character valueOf(char c) {
 208.687 -        if (c <= 127) { // must cache
 208.688 -            return CharacterCache.cache[(int)c];
 208.689 -        }
 208.690 -        return new Character(c);
 208.691 -    }
 208.692 -
 208.693 -    /**
 208.694 -     * Returns the value of this {@code Character} object.
 208.695 -     * @return  the primitive {@code char} value represented by
 208.696 -     *          this object.
 208.697 -     */
 208.698 -    public char charValue() {
 208.699 -        return value;
 208.700 -    }
 208.701 -
 208.702 -    /**
 208.703 -     * Returns a hash code for this {@code Character}; equal to the result
 208.704 -     * of invoking {@code charValue()}.
 208.705 -     *
 208.706 -     * @return a hash code value for this {@code Character}
 208.707 -     */
 208.708 -    public int hashCode() {
 208.709 -        return (int)value;
 208.710 -    }
 208.711 -
 208.712 -    /**
 208.713 -     * Compares this object against the specified object.
 208.714 -     * The result is {@code true} if and only if the argument is not
 208.715 -     * {@code null} and is a {@code Character} object that
 208.716 -     * represents the same {@code char} value as this object.
 208.717 -     *
 208.718 -     * @param   obj   the object to compare with.
 208.719 -     * @return  {@code true} if the objects are the same;
 208.720 -     *          {@code false} otherwise.
 208.721 -     */
 208.722 -    public boolean equals(Object obj) {
 208.723 -        if (obj instanceof Character) {
 208.724 -            return value == ((Character)obj).charValue();
 208.725 -        }
 208.726 -        return false;
 208.727 -    }
 208.728 -
 208.729 -    /**
 208.730 -     * Returns a {@code String} object representing this
 208.731 -     * {@code Character}'s value.  The result is a string of
 208.732 -     * length 1 whose sole component is the primitive
 208.733 -     * {@code char} value represented by this
 208.734 -     * {@code Character} object.
 208.735 -     *
 208.736 -     * @return  a string representation of this object.
 208.737 -     */
 208.738 -    public String toString() {
 208.739 -        char buf[] = {value};
 208.740 -        return String.valueOf(buf);
 208.741 -    }
 208.742 -
 208.743 -    /**
 208.744 -     * Returns a {@code String} object representing the
 208.745 -     * specified {@code char}.  The result is a string of length
 208.746 -     * 1 consisting solely of the specified {@code char}.
 208.747 -     *
 208.748 -     * @param c the {@code char} to be converted
 208.749 -     * @return the string representation of the specified {@code char}
 208.750 -     * @since 1.4
 208.751 -     */
 208.752 -    public static String toString(char c) {
 208.753 -        return String.valueOf(c);
 208.754 -    }
 208.755 -
 208.756 -    /**
 208.757 -     * Determines whether the specified code point is a valid
 208.758 -     * <a href="http://www.unicode.org/glossary/#code_point">
 208.759 -     * Unicode code point value</a>.
 208.760 -     *
 208.761 -     * @param  codePoint the Unicode code point to be tested
 208.762 -     * @return {@code true} if the specified code point value is between
 208.763 -     *         {@link #MIN_CODE_POINT} and
 208.764 -     *         {@link #MAX_CODE_POINT} inclusive;
 208.765 -     *         {@code false} otherwise.
 208.766 -     * @since  1.5
 208.767 -     */
 208.768 -    public static boolean isValidCodePoint(int codePoint) {
 208.769 -        // Optimized form of:
 208.770 -        //     codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT
 208.771 -        int plane = codePoint >>> 16;
 208.772 -        return plane < ((MAX_CODE_POINT + 1) >>> 16);
 208.773 -    }
 208.774 -
 208.775 -    /**
 208.776 -     * Determines whether the specified character (Unicode code point)
 208.777 -     * is in the <a href="#BMP">Basic Multilingual Plane (BMP)</a>.
 208.778 -     * Such code points can be represented using a single {@code char}.
 208.779 -     *
 208.780 -     * @param  codePoint the character (Unicode code point) to be tested
 208.781 -     * @return {@code true} if the specified code point is between
 208.782 -     *         {@link #MIN_VALUE} and {@link #MAX_VALUE} inclusive;
 208.783 -     *         {@code false} otherwise.
 208.784 -     * @since  1.7
 208.785 -     */
 208.786 -    public static boolean isBmpCodePoint(int codePoint) {
 208.787 -        return codePoint >>> 16 == 0;
 208.788 -        // Optimized form of:
 208.789 -        //     codePoint >= MIN_VALUE && codePoint <= MAX_VALUE
 208.790 -        // We consistently use logical shift (>>>) to facilitate
 208.791 -        // additional runtime optimizations.
 208.792 -    }
 208.793 -
 208.794 -    /**
 208.795 -     * Determines whether the specified character (Unicode code point)
 208.796 -     * is in the <a href="#supplementary">supplementary character</a> range.
 208.797 -     *
 208.798 -     * @param  codePoint the character (Unicode code point) to be tested
 208.799 -     * @return {@code true} if the specified code point is between
 208.800 -     *         {@link #MIN_SUPPLEMENTARY_CODE_POINT} and
 208.801 -     *         {@link #MAX_CODE_POINT} inclusive;
 208.802 -     *         {@code false} otherwise.
 208.803 -     * @since  1.5
 208.804 -     */
 208.805 -    public static boolean isSupplementaryCodePoint(int codePoint) {
 208.806 -        return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT
 208.807 -            && codePoint <  MAX_CODE_POINT + 1;
 208.808 -    }
 208.809 -
 208.810 -    /**
 208.811 -     * Determines if the given {@code char} value is a
 208.812 -     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 208.813 -     * Unicode high-surrogate code unit</a>
 208.814 -     * (also known as <i>leading-surrogate code unit</i>).
 208.815 -     *
 208.816 -     * <p>Such values do not represent characters by themselves,
 208.817 -     * but are used in the representation of
 208.818 -     * <a href="#supplementary">supplementary characters</a>
 208.819 -     * in the UTF-16 encoding.
 208.820 -     *
 208.821 -     * @param  ch the {@code char} value to be tested.
 208.822 -     * @return {@code true} if the {@code char} value is between
 208.823 -     *         {@link #MIN_HIGH_SURROGATE} and
 208.824 -     *         {@link #MAX_HIGH_SURROGATE} inclusive;
 208.825 -     *         {@code false} otherwise.
 208.826 -     * @see    Character#isLowSurrogate(char)
 208.827 -     * @see    Character.UnicodeBlock#of(int)
 208.828 -     * @since  1.5
 208.829 -     */
 208.830 -    public static boolean isHighSurrogate(char ch) {
 208.831 -        // Help VM constant-fold; MAX_HIGH_SURROGATE + 1 == MIN_LOW_SURROGATE
 208.832 -        return ch >= MIN_HIGH_SURROGATE && ch < (MAX_HIGH_SURROGATE + 1);
 208.833 -    }
 208.834 -
 208.835 -    /**
 208.836 -     * Determines if the given {@code char} value is a
 208.837 -     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
 208.838 -     * Unicode low-surrogate code unit</a>
 208.839 -     * (also known as <i>trailing-surrogate code unit</i>).
 208.840 -     *
 208.841 -     * <p>Such values do not represent characters by themselves,
 208.842 -     * but are used in the representation of
 208.843 -     * <a href="#supplementary">supplementary characters</a>
 208.844 -     * in the UTF-16 encoding.
 208.845 -     *
 208.846 -     * @param  ch the {@code char} value to be tested.
 208.847 -     * @return {@code true} if the {@code char} value is between
 208.848 -     *         {@link #MIN_LOW_SURROGATE} and
 208.849 -     *         {@link #MAX_LOW_SURROGATE} inclusive;
 208.850 -     *         {@code false} otherwise.
 208.851 -     * @see    Character#isHighSurrogate(char)
 208.852 -     * @since  1.5
 208.853 -     */
 208.854 -    public static boolean isLowSurrogate(char ch) {
 208.855 -        return ch >= MIN_LOW_SURROGATE && ch < (MAX_LOW_SURROGATE + 1);
 208.856 -    }
 208.857 -
 208.858 -    /**
 208.859 -     * Determines if the given {@code char} value is a Unicode
 208.860 -     * <i>surrogate code unit</i>.
 208.861 -     *
 208.862 -     * <p>Such values do not represent characters by themselves,
 208.863 -     * but are used in the representation of
 208.864 -     * <a href="#supplementary">supplementary characters</a>
 208.865 -     * in the UTF-16 encoding.
 208.866 -     *
 208.867 -     * <p>A char value is a surrogate code unit if and only if it is either
 208.868 -     * a {@linkplain #isLowSurrogate(char) low-surrogate code unit} or
 208.869 -     * a {@linkplain #isHighSurrogate(char) high-surrogate code unit}.
 208.870 -     *
 208.871 -     * @param  ch the {@code char} value to be tested.
 208.872 -     * @return {@code true} if the {@code char} value is between
 208.873 -     *         {@link #MIN_SURROGATE} and
 208.874 -     *         {@link #MAX_SURROGATE} inclusive;
 208.875 -     *         {@code false} otherwise.
 208.876 -     * @since  1.7
 208.877 -     */
 208.878 -    public static boolean isSurrogate(char ch) {
 208.879 -        return ch >= MIN_SURROGATE && ch < (MAX_SURROGATE + 1);
 208.880 -    }
 208.881 -
 208.882 -    /**
 208.883 -     * Determines whether the specified pair of {@code char}
 208.884 -     * values is a valid
 208.885 -     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
 208.886 -     * Unicode surrogate pair</a>.
 208.887 -
 208.888 -     * <p>This method is equivalent to the expression:
 208.889 -     * <blockquote><pre>
 208.890 -     * isHighSurrogate(high) && isLowSurrogate(low)
 208.891 -     * </pre></blockquote>
 208.892 -     *
 208.893 -     * @param  high the high-surrogate code value to be tested
 208.894 -     * @param  low the low-surrogate code value to be tested
 208.895 -     * @return {@code true} if the specified high and
 208.896 -     * low-surrogate code values represent a valid surrogate pair;
 208.897 -     * {@code false} otherwise.
 208.898 -     * @since  1.5
 208.899 -     */
 208.900 -    public static boolean isSurrogatePair(char high, char low) {
 208.901 -        return isHighSurrogate(high) && isLowSurrogate(low);
 208.902 -    }
 208.903 -
 208.904 -    /**
 208.905 -     * Determines the number of {@code char} values needed to
 208.906 -     * represent the specified character (Unicode code point). If the
 208.907 -     * specified character is equal to or greater than 0x10000, then
 208.908 -     * the method returns 2. Otherwise, the method returns 1.
 208.909 -     *
 208.910 -     * <p>This method doesn't validate the specified character to be a
 208.911 -     * valid Unicode code point. The caller must validate the
 208.912 -     * character value using {@link #isValidCodePoint(int) isValidCodePoint}
 208.913 -     * if necessary.
 208.914 -     *
 208.915 -     * @param   codePoint the character (Unicode code point) to be tested.
 208.916 -     * @return  2 if the character is a valid supplementary character; 1 otherwise.
 208.917 -     * @see     Character#isSupplementaryCodePoint(int)
 208.918 -     * @since   1.5
 208.919 -     */
 208.920 -    public static int charCount(int codePoint) {
 208.921 -        return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT ? 2 : 1;
 208.922 -    }
 208.923 -
 208.924 -    /**
 208.925 -     * Converts the specified surrogate pair to its supplementary code
 208.926 -     * point value. This method does not validate the specified
 208.927 -     * surrogate pair. The caller must validate it using {@link
 208.928 -     * #isSurrogatePair(char, char) isSurrogatePair} if necessary.
 208.929 -     *
 208.930 -     * @param  high the high-surrogate code unit
 208.931 -     * @param  low the low-surrogate code unit
 208.932 -     * @return the supplementary code point composed from the
 208.933 -     *         specified surrogate pair.
 208.934 -     * @since  1.5
 208.935 -     */
 208.936 -    public static int toCodePoint(char high, char low) {
 208.937 -        // Optimized form of:
 208.938 -        // return ((high - MIN_HIGH_SURROGATE) << 10)
 208.939 -        //         + (low - MIN_LOW_SURROGATE)
 208.940 -        //         + MIN_SUPPLEMENTARY_CODE_POINT;
 208.941 -        return ((high << 10) + low) + (MIN_SUPPLEMENTARY_CODE_POINT
 208.942 -                                       - (MIN_HIGH_SURROGATE << 10)
 208.943 -                                       - MIN_LOW_SURROGATE);
 208.944 -    }
 208.945 -
 208.946 -    /**
 208.947 -     * Returns the code point at the given index of the
 208.948 -     * {@code CharSequence}. If the {@code char} value at
 208.949 -     * the given index in the {@code CharSequence} is in the
 208.950 -     * high-surrogate range, the following index is less than the
 208.951 -     * length of the {@code CharSequence}, and the
 208.952 -     * {@code char} value at the following index is in the
 208.953 -     * low-surrogate range, then the supplementary code point
 208.954 -     * corresponding to this surrogate pair is returned. Otherwise,
 208.955 -     * the {@code char} value at the given index is returned.
 208.956 -     *
 208.957 -     * @param seq a sequence of {@code char} values (Unicode code
 208.958 -     * units)
 208.959 -     * @param index the index to the {@code char} values (Unicode
 208.960 -     * code units) in {@code seq} to be converted
 208.961 -     * @return the Unicode code point at the given index
 208.962 -     * @exception NullPointerException if {@code seq} is null.
 208.963 -     * @exception IndexOutOfBoundsException if the value
 208.964 -     * {@code index} is negative or not less than
 208.965 -     * {@link CharSequence#length() seq.length()}.
 208.966 -     * @since  1.5
 208.967 -     */
 208.968 -    public static int codePointAt(CharSequence seq, int index) {
 208.969 -        char c1 = seq.charAt(index++);
 208.970 -        if (isHighSurrogate(c1)) {
 208.971 -            if (index < seq.length()) {
 208.972 -                char c2 = seq.charAt(index);
 208.973 -                if (isLowSurrogate(c2)) {
 208.974 -                    return toCodePoint(c1, c2);
 208.975 -                }
 208.976 -            }
 208.977 -        }
 208.978 -        return c1;
 208.979 -    }
 208.980 -
 208.981 -    /**
 208.982 -     * Returns the code point at the given index of the
 208.983 -     * {@code char} array. If the {@code char} value at
 208.984 -     * the given index in the {@code char} array is in the
 208.985 -     * high-surrogate range, the following index is less than the
 208.986 -     * length of the {@code char} array, and the
 208.987 -     * {@code char} value at the following index is in the
 208.988 -     * low-surrogate range, then the supplementary code point
 208.989 -     * corresponding to this surrogate pair is returned. Otherwise,
 208.990 -     * the {@code char} value at the given index is returned.
 208.991 -     *
 208.992 -     * @param a the {@code char} array
 208.993 -     * @param index the index to the {@code char} values (Unicode
 208.994 -     * code units) in the {@code char} array to be converted
 208.995 -     * @return the Unicode code point at the given index
 208.996 -     * @exception NullPointerException if {@code a} is null.
 208.997 -     * @exception IndexOutOfBoundsException if the value
 208.998 -     * {@code index} is negative or not less than
 208.999 -     * the length of the {@code char} array.
208.1000 -     * @since  1.5
208.1001 -     */
208.1002 -    public static int codePointAt(char[] a, int index) {
208.1003 -        return codePointAtImpl(a, index, a.length);
208.1004 -    }
208.1005 -
208.1006 -    /**
208.1007 -     * Returns the code point at the given index of the
208.1008 -     * {@code char} array, where only array elements with
208.1009 -     * {@code index} less than {@code limit} can be used. If
208.1010 -     * the {@code char} value at the given index in the
208.1011 -     * {@code char} array is in the high-surrogate range, the
208.1012 -     * following index is less than the {@code limit}, and the
208.1013 -     * {@code char} value at the following index is in the
208.1014 -     * low-surrogate range, then the supplementary code point
208.1015 -     * corresponding to this surrogate pair is returned. Otherwise,
208.1016 -     * the {@code char} value at the given index is returned.
208.1017 -     *
208.1018 -     * @param a the {@code char} array
208.1019 -     * @param index the index to the {@code char} values (Unicode
208.1020 -     * code units) in the {@code char} array to be converted
208.1021 -     * @param limit the index after the last array element that
208.1022 -     * can be used in the {@code char} array
208.1023 -     * @return the Unicode code point at the given index
208.1024 -     * @exception NullPointerException if {@code a} is null.
208.1025 -     * @exception IndexOutOfBoundsException if the {@code index}
208.1026 -     * argument is negative or not less than the {@code limit}
208.1027 -     * argument, or if the {@code limit} argument is negative or
208.1028 -     * greater than the length of the {@code char} array.
208.1029 -     * @since  1.5
208.1030 -     */
208.1031 -    public static int codePointAt(char[] a, int index, int limit) {
208.1032 -        if (index >= limit || limit < 0 || limit > a.length) {
208.1033 -            throw new IndexOutOfBoundsException();
208.1034 -        }
208.1035 -        return codePointAtImpl(a, index, limit);
208.1036 -    }
208.1037 -
208.1038 -    // throws ArrayIndexOutofBoundsException if index out of bounds
208.1039 -    static int codePointAtImpl(char[] a, int index, int limit) {
208.1040 -        char c1 = a[index++];
208.1041 -        if (isHighSurrogate(c1)) {
208.1042 -            if (index < limit) {
208.1043 -                char c2 = a[index];
208.1044 -                if (isLowSurrogate(c2)) {
208.1045 -                    return toCodePoint(c1, c2);
208.1046 -                }
208.1047 -            }
208.1048 -        }
208.1049 -        return c1;
208.1050 -    }
208.1051 -
208.1052 -    /**
208.1053 -     * Returns the code point preceding the given index of the
208.1054 -     * {@code CharSequence}. If the {@code char} value at
208.1055 -     * {@code (index - 1)} in the {@code CharSequence} is in
208.1056 -     * the low-surrogate range, {@code (index - 2)} is not
208.1057 -     * negative, and the {@code char} value at {@code (index - 2)}
208.1058 -     * in the {@code CharSequence} is in the
208.1059 -     * high-surrogate range, then the supplementary code point
208.1060 -     * corresponding to this surrogate pair is returned. Otherwise,
208.1061 -     * the {@code char} value at {@code (index - 1)} is
208.1062 -     * returned.
208.1063 -     *
208.1064 -     * @param seq the {@code CharSequence} instance
208.1065 -     * @param index the index following the code point that should be returned
208.1066 -     * @return the Unicode code point value before the given index.
208.1067 -     * @exception NullPointerException if {@code seq} is null.
208.1068 -     * @exception IndexOutOfBoundsException if the {@code index}
208.1069 -     * argument is less than 1 or greater than {@link
208.1070 -     * CharSequence#length() seq.length()}.
208.1071 -     * @since  1.5
208.1072 -     */
208.1073 -    public static int codePointBefore(CharSequence seq, int index) {
208.1074 -        char c2 = seq.charAt(--index);
208.1075 -        if (isLowSurrogate(c2)) {
208.1076 -            if (index > 0) {
208.1077 -                char c1 = seq.charAt(--index);
208.1078 -                if (isHighSurrogate(c1)) {
208.1079 -                    return toCodePoint(c1, c2);
208.1080 -                }
208.1081 -            }
208.1082 -        }
208.1083 -        return c2;
208.1084 -    }
208.1085 -
208.1086 -    /**
208.1087 -     * Returns the code point preceding the given index of the
208.1088 -     * {@code char} array. If the {@code char} value at
208.1089 -     * {@code (index - 1)} in the {@code char} array is in
208.1090 -     * the low-surrogate range, {@code (index - 2)} is not
208.1091 -     * negative, and the {@code char} value at {@code (index - 2)}
208.1092 -     * in the {@code char} array is in the
208.1093 -     * high-surrogate range, then the supplementary code point
208.1094 -     * corresponding to this surrogate pair is returned. Otherwise,
208.1095 -     * the {@code char} value at {@code (index - 1)} is
208.1096 -     * returned.
208.1097 -     *
208.1098 -     * @param a the {@code char} array
208.1099 -     * @param index the index following the code point that should be returned
208.1100 -     * @return the Unicode code point value before the given index.
208.1101 -     * @exception NullPointerException if {@code a} is null.
208.1102 -     * @exception IndexOutOfBoundsException if the {@code index}
208.1103 -     * argument is less than 1 or greater than the length of the
208.1104 -     * {@code char} array
208.1105 -     * @since  1.5
208.1106 -     */
208.1107 -    public static int codePointBefore(char[] a, int index) {
208.1108 -        return codePointBeforeImpl(a, index, 0);
208.1109 -    }
208.1110 -
208.1111 -    /**
208.1112 -     * Returns the code point preceding the given index of the
208.1113 -     * {@code char} array, where only array elements with
208.1114 -     * {@code index} greater than or equal to {@code start}
208.1115 -     * can be used. If the {@code char} value at {@code (index - 1)}
208.1116 -     * in the {@code char} array is in the
208.1117 -     * low-surrogate range, {@code (index - 2)} is not less than
208.1118 -     * {@code start}, and the {@code char} value at
208.1119 -     * {@code (index - 2)} in the {@code char} array is in
208.1120 -     * the high-surrogate range, then the supplementary code point
208.1121 -     * corresponding to this surrogate pair is returned. Otherwise,
208.1122 -     * the {@code char} value at {@code (index - 1)} is
208.1123 -     * returned.
208.1124 -     *
208.1125 -     * @param a the {@code char} array
208.1126 -     * @param index the index following the code point that should be returned
208.1127 -     * @param start the index of the first array element in the
208.1128 -     * {@code char} array
208.1129 -     * @return the Unicode code point value before the given index.
208.1130 -     * @exception NullPointerException if {@code a} is null.
208.1131 -     * @exception IndexOutOfBoundsException if the {@code index}
208.1132 -     * argument is not greater than the {@code start} argument or
208.1133 -     * is greater than the length of the {@code char} array, or
208.1134 -     * if the {@code start} argument is negative or not less than
208.1135 -     * the length of the {@code char} array.
208.1136 -     * @since  1.5
208.1137 -     */
208.1138 -    public static int codePointBefore(char[] a, int index, int start) {
208.1139 -        if (index <= start || start < 0 || start >= a.length) {
208.1140 -            throw new IndexOutOfBoundsException();
208.1141 -        }
208.1142 -        return codePointBeforeImpl(a, index, start);
208.1143 -    }
208.1144 -
208.1145 -    // throws ArrayIndexOutofBoundsException if index-1 out of bounds
208.1146 -    static int codePointBeforeImpl(char[] a, int index, int start) {
208.1147 -        char c2 = a[--index];
208.1148 -        if (isLowSurrogate(c2)) {
208.1149 -            if (index > start) {
208.1150 -                char c1 = a[--index];
208.1151 -                if (isHighSurrogate(c1)) {
208.1152 -                    return toCodePoint(c1, c2);
208.1153 -                }
208.1154 -            }
208.1155 -        }
208.1156 -        return c2;
208.1157 -    }
208.1158 -
208.1159 -    /**
208.1160 -     * Returns the leading surrogate (a
208.1161 -     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
208.1162 -     * high surrogate code unit</a>) of the
208.1163 -     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
208.1164 -     * surrogate pair</a>
208.1165 -     * representing the specified supplementary character (Unicode
208.1166 -     * code point) in the UTF-16 encoding.  If the specified character
208.1167 -     * is not a
208.1168 -     * <a href="Character.html#supplementary">supplementary character</a>,
208.1169 -     * an unspecified {@code char} is returned.
208.1170 -     *
208.1171 -     * <p>If
208.1172 -     * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
208.1173 -     * is {@code true}, then
208.1174 -     * {@link #isHighSurrogate isHighSurrogate}{@code (highSurrogate(x))} and
208.1175 -     * {@link #toCodePoint toCodePoint}{@code (highSurrogate(x), }{@link #lowSurrogate lowSurrogate}{@code (x)) == x}
208.1176 -     * are also always {@code true}.
208.1177 -     *
208.1178 -     * @param   codePoint a supplementary character (Unicode code point)
208.1179 -     * @return  the leading surrogate code unit used to represent the
208.1180 -     *          character in the UTF-16 encoding
208.1181 -     * @since   1.7
208.1182 -     */
208.1183 -    public static char highSurrogate(int codePoint) {
208.1184 -        return (char) ((codePoint >>> 10)
208.1185 -            + (MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT >>> 10)));
208.1186 -    }
208.1187 -
208.1188 -    /**
208.1189 -     * Returns the trailing surrogate (a
208.1190 -     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
208.1191 -     * low surrogate code unit</a>) of the
208.1192 -     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
208.1193 -     * surrogate pair</a>
208.1194 -     * representing the specified supplementary character (Unicode
208.1195 -     * code point) in the UTF-16 encoding.  If the specified character
208.1196 -     * is not a
208.1197 -     * <a href="Character.html#supplementary">supplementary character</a>,
208.1198 -     * an unspecified {@code char} is returned.
208.1199 -     *
208.1200 -     * <p>If
208.1201 -     * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
208.1202 -     * is {@code true}, then
208.1203 -     * {@link #isLowSurrogate isLowSurrogate}{@code (lowSurrogate(x))} and
208.1204 -     * {@link #toCodePoint toCodePoint}{@code (}{@link #highSurrogate highSurrogate}{@code (x), lowSurrogate(x)) == x}
208.1205 -     * are also always {@code true}.
208.1206 -     *
208.1207 -     * @param   codePoint a supplementary character (Unicode code point)
208.1208 -     * @return  the trailing surrogate code unit used to represent the
208.1209 -     *          character in the UTF-16 encoding
208.1210 -     * @since   1.7
208.1211 -     */
208.1212 -    public static char lowSurrogate(int codePoint) {
208.1213 -        return (char) ((codePoint & 0x3ff) + MIN_LOW_SURROGATE);
208.1214 -    }
208.1215 -
208.1216 -    /**
208.1217 -     * Converts the specified character (Unicode code point) to its
208.1218 -     * UTF-16 representation. If the specified code point is a BMP
208.1219 -     * (Basic Multilingual Plane or Plane 0) value, the same value is
208.1220 -     * stored in {@code dst[dstIndex]}, and 1 is returned. If the
208.1221 -     * specified code point is a supplementary character, its
208.1222 -     * surrogate values are stored in {@code dst[dstIndex]}
208.1223 -     * (high-surrogate) and {@code dst[dstIndex+1]}
208.1224 -     * (low-surrogate), and 2 is returned.
208.1225 -     *
208.1226 -     * @param  codePoint the character (Unicode code point) to be converted.
208.1227 -     * @param  dst an array of {@code char} in which the
208.1228 -     * {@code codePoint}'s UTF-16 value is stored.
208.1229 -     * @param dstIndex the start index into the {@code dst}
208.1230 -     * array where the converted value is stored.
208.1231 -     * @return 1 if the code point is a BMP code point, 2 if the
208.1232 -     * code point is a supplementary code point.
208.1233 -     * @exception IllegalArgumentException if the specified
208.1234 -     * {@code codePoint} is not a valid Unicode code point.
208.1235 -     * @exception NullPointerException if the specified {@code dst} is null.
208.1236 -     * @exception IndexOutOfBoundsException if {@code dstIndex}
208.1237 -     * is negative or not less than {@code dst.length}, or if
208.1238 -     * {@code dst} at {@code dstIndex} doesn't have enough
208.1239 -     * array element(s) to store the resulting {@code char}
208.1240 -     * value(s). (If {@code dstIndex} is equal to
208.1241 -     * {@code dst.length-1} and the specified
208.1242 -     * {@code codePoint} is a supplementary character, the
208.1243 -     * high-surrogate value is not stored in
208.1244 -     * {@code dst[dstIndex]}.)
208.1245 -     * @since  1.5
208.1246 -     */
208.1247 -    public static int toChars(int codePoint, char[] dst, int dstIndex) {
208.1248 -        if (isBmpCodePoint(codePoint)) {
208.1249 -            dst[dstIndex] = (char) codePoint;
208.1250 -            return 1;
208.1251 -        } else if (isValidCodePoint(codePoint)) {
208.1252 -            toSurrogates(codePoint, dst, dstIndex);
208.1253 -            return 2;
208.1254 -        } else {
208.1255 -            throw new IllegalArgumentException();
208.1256 -        }
208.1257 -    }
208.1258 -
208.1259 -    /**
208.1260 -     * Converts the specified character (Unicode code point) to its
208.1261 -     * UTF-16 representation stored in a {@code char} array. If
208.1262 -     * the specified code point is a BMP (Basic Multilingual Plane or
208.1263 -     * Plane 0) value, the resulting {@code char} array has
208.1264 -     * the same value as {@code codePoint}. If the specified code
208.1265 -     * point is a supplementary code point, the resulting
208.1266 -     * {@code char} array has the corresponding surrogate pair.
208.1267 -     *
208.1268 -     * @param  codePoint a Unicode code point
208.1269 -     * @return a {@code char} array having
208.1270 -     *         {@code codePoint}'s UTF-16 representation.
208.1271 -     * @exception IllegalArgumentException if the specified
208.1272 -     * {@code codePoint} is not a valid Unicode code point.
208.1273 -     * @since  1.5
208.1274 -     */
208.1275 -    public static char[] toChars(int codePoint) {
208.1276 -        if (isBmpCodePoint(codePoint)) {
208.1277 -            return new char[] { (char) codePoint };
208.1278 -        } else if (isValidCodePoint(codePoint)) {
208.1279 -            char[] result = new char[2];
208.1280 -            toSurrogates(codePoint, result, 0);
208.1281 -            return result;
208.1282 -        } else {
208.1283 -            throw new IllegalArgumentException();
208.1284 -        }
208.1285 -    }
208.1286 -
208.1287 -    static void toSurrogates(int codePoint, char[] dst, int index) {
208.1288 -        // We write elements "backwards" to guarantee all-or-nothing
208.1289 -        dst[index+1] = lowSurrogate(codePoint);
208.1290 -        dst[index] = highSurrogate(codePoint);
208.1291 -    }
208.1292 -
208.1293 -    /**
208.1294 -     * Returns the number of Unicode code points in the text range of
208.1295 -     * the specified char sequence. The text range begins at the
208.1296 -     * specified {@code beginIndex} and extends to the
208.1297 -     * {@code char} at index {@code endIndex - 1}. Thus the
208.1298 -     * length (in {@code char}s) of the text range is
208.1299 -     * {@code endIndex-beginIndex}. Unpaired surrogates within
208.1300 -     * the text range count as one code point each.
208.1301 -     *
208.1302 -     * @param seq the char sequence
208.1303 -     * @param beginIndex the index to the first {@code char} of
208.1304 -     * the text range.
208.1305 -     * @param endIndex the index after the last {@code char} of
208.1306 -     * the text range.
208.1307 -     * @return the number of Unicode code points in the specified text
208.1308 -     * range
208.1309 -     * @exception NullPointerException if {@code seq} is null.
208.1310 -     * @exception IndexOutOfBoundsException if the
208.1311 -     * {@code beginIndex} is negative, or {@code endIndex}
208.1312 -     * is larger than the length of the given sequence, or
208.1313 -     * {@code beginIndex} is larger than {@code endIndex}.
208.1314 -     * @since  1.5
208.1315 -     */
208.1316 -    public static int codePointCount(CharSequence seq, int beginIndex, int endIndex) {
208.1317 -        int length = seq.length();
208.1318 -        if (beginIndex < 0 || endIndex > length || beginIndex > endIndex) {
208.1319 -            throw new IndexOutOfBoundsException();
208.1320 -        }
208.1321 -        int n = endIndex - beginIndex;
208.1322 -        for (int i = beginIndex; i < endIndex; ) {
208.1323 -            if (isHighSurrogate(seq.charAt(i++)) && i < endIndex &&
208.1324 -                isLowSurrogate(seq.charAt(i))) {
208.1325 -                n--;
208.1326 -                i++;
208.1327 -            }
208.1328 -        }
208.1329 -        return n;
208.1330 -    }
208.1331 -
208.1332 -    /**
208.1333 -     * Returns the number of Unicode code points in a subarray of the
208.1334 -     * {@code char} array argument. The {@code offset}
208.1335 -     * argument is the index of the first {@code char} of the
208.1336 -     * subarray and the {@code count} argument specifies the
208.1337 -     * length of the subarray in {@code char}s. Unpaired
208.1338 -     * surrogates within the subarray count as one code point each.
208.1339 -     *
208.1340 -     * @param a the {@code char} array
208.1341 -     * @param offset the index of the first {@code char} in the
208.1342 -     * given {@code char} array
208.1343 -     * @param count the length of the subarray in {@code char}s
208.1344 -     * @return the number of Unicode code points in the specified subarray
208.1345 -     * @exception NullPointerException if {@code a} is null.
208.1346 -     * @exception IndexOutOfBoundsException if {@code offset} or
208.1347 -     * {@code count} is negative, or if {@code offset +
208.1348 -     * count} is larger than the length of the given array.
208.1349 -     * @since  1.5
208.1350 -     */
208.1351 -    public static int codePointCount(char[] a, int offset, int count) {
208.1352 -        if (count > a.length - offset || offset < 0 || count < 0) {
208.1353 -            throw new IndexOutOfBoundsException();
208.1354 -        }
208.1355 -        return codePointCountImpl(a, offset, count);
208.1356 -    }
208.1357 -
208.1358 -    static int codePointCountImpl(char[] a, int offset, int count) {
208.1359 -        int endIndex = offset + count;
208.1360 -        int n = count;
208.1361 -        for (int i = offset; i < endIndex; ) {
208.1362 -            if (isHighSurrogate(a[i++]) && i < endIndex &&
208.1363 -                isLowSurrogate(a[i])) {
208.1364 -                n--;
208.1365 -                i++;
208.1366 -            }
208.1367 -        }
208.1368 -        return n;
208.1369 -    }
208.1370 -
208.1371 -    /**
208.1372 -     * Returns the index within the given char sequence that is offset
208.1373 -     * from the given {@code index} by {@code codePointOffset}
208.1374 -     * code points. Unpaired surrogates within the text range given by
208.1375 -     * {@code index} and {@code codePointOffset} count as
208.1376 -     * one code point each.
208.1377 -     *
208.1378 -     * @param seq the char sequence
208.1379 -     * @param index the index to be offset
208.1380 -     * @param codePointOffset the offset in code points
208.1381 -     * @return the index within the char sequence
208.1382 -     * @exception NullPointerException if {@code seq} is null.
208.1383 -     * @exception IndexOutOfBoundsException if {@code index}
208.1384 -     *   is negative or larger then the length of the char sequence,
208.1385 -     *   or if {@code codePointOffset} is positive and the
208.1386 -     *   subsequence starting with {@code index} has fewer than
208.1387 -     *   {@code codePointOffset} code points, or if
208.1388 -     *   {@code codePointOffset} is negative and the subsequence
208.1389 -     *   before {@code index} has fewer than the absolute value
208.1390 -     *   of {@code codePointOffset} code points.
208.1391 -     * @since 1.5
208.1392 -     */
208.1393 -    public static int offsetByCodePoints(CharSequence seq, int index,
208.1394 -                                         int codePointOffset) {
208.1395 -        int length = seq.length();
208.1396 -        if (index < 0 || index > length) {
208.1397 -            throw new IndexOutOfBoundsException();
208.1398 -        }
208.1399 -
208.1400 -        int x = index;
208.1401 -        if (codePointOffset >= 0) {
208.1402 -            int i;
208.1403 -            for (i = 0; x < length && i < codePointOffset; i++) {
208.1404 -                if (isHighSurrogate(seq.charAt(x++)) && x < length &&
208.1405 -                    isLowSurrogate(seq.charAt(x))) {
208.1406 -                    x++;
208.1407 -                }
208.1408 -            }
208.1409 -            if (i < codePointOffset) {
208.1410 -                throw new IndexOutOfBoundsException();
208.1411 -            }
208.1412 -        } else {
208.1413 -            int i;
208.1414 -            for (i = codePointOffset; x > 0 && i < 0; i++) {
208.1415 -                if (isLowSurrogate(seq.charAt(--x)) && x > 0 &&
208.1416 -                    isHighSurrogate(seq.charAt(x-1))) {
208.1417 -                    x--;
208.1418 -                }
208.1419 -            }
208.1420 -            if (i < 0) {
208.1421 -                throw new IndexOutOfBoundsException();
208.1422 -            }
208.1423 -        }
208.1424 -        return x;
208.1425 -    }
208.1426 -
208.1427 -    /**
208.1428 -     * Returns the index within the given {@code char} subarray
208.1429 -     * that is offset from the given {@code index} by
208.1430 -     * {@code codePointOffset} code points. The
208.1431 -     * {@code start} and {@code count} arguments specify a
208.1432 -     * subarray of the {@code char} array. Unpaired surrogates
208.1433 -     * within the text range given by {@code index} and
208.1434 -     * {@code codePointOffset} count as one code point each.
208.1435 -     *
208.1436 -     * @param a the {@code char} array
208.1437 -     * @param start the index of the first {@code char} of the
208.1438 -     * subarray
208.1439 -     * @param count the length of the subarray in {@code char}s
208.1440 -     * @param index the index to be offset
208.1441 -     * @param codePointOffset the offset in code points
208.1442 -     * @return the index within the subarray
208.1443 -     * @exception NullPointerException if {@code a} is null.
208.1444 -     * @exception IndexOutOfBoundsException
208.1445 -     *   if {@code start} or {@code count} is negative,
208.1446 -     *   or if {@code start + count} is larger than the length of
208.1447 -     *   the given array,
208.1448 -     *   or if {@code index} is less than {@code start} or
208.1449 -     *   larger then {@code start + count},
208.1450 -     *   or if {@code codePointOffset} is positive and the text range
208.1451 -     *   starting with {@code index} and ending with {@code start + count - 1}
208.1452 -     *   has fewer than {@code codePointOffset} code
208.1453 -     *   points,
208.1454 -     *   or if {@code codePointOffset} is negative and the text range
208.1455 -     *   starting with {@code start} and ending with {@code index - 1}
208.1456 -     *   has fewer than the absolute value of
208.1457 -     *   {@code codePointOffset} code points.
208.1458 -     * @since 1.5
208.1459 -     */
208.1460 -    public static int offsetByCodePoints(char[] a, int start, int count,
208.1461 -                                         int index, int codePointOffset) {
208.1462 -        if (count > a.length-start || start < 0 || count < 0
208.1463 -            || index < start || index > start+count) {
208.1464 -            throw new IndexOutOfBoundsException();
208.1465 -        }
208.1466 -        return offsetByCodePointsImpl(a, start, count, index, codePointOffset);
208.1467 -    }
208.1468 -
208.1469 -    static int offsetByCodePointsImpl(char[]a, int start, int count,
208.1470 -                                      int index, int codePointOffset) {
208.1471 -        int x = index;
208.1472 -        if (codePointOffset >= 0) {
208.1473 -            int limit = start + count;
208.1474 -            int i;
208.1475 -            for (i = 0; x < limit && i < codePointOffset; i++) {
208.1476 -                if (isHighSurrogate(a[x++]) && x < limit &&
208.1477 -                    isLowSurrogate(a[x])) {
208.1478 -                    x++;
208.1479 -                }
208.1480 -            }
208.1481 -            if (i < codePointOffset) {
208.1482 -                throw new IndexOutOfBoundsException();
208.1483 -            }
208.1484 -        } else {
208.1485 -            int i;
208.1486 -            for (i = codePointOffset; x > start && i < 0; i++) {
208.1487 -                if (isLowSurrogate(a[--x]) && x > start &&
208.1488 -                    isHighSurrogate(a[x-1])) {
208.1489 -                    x--;
208.1490 -                }
208.1491 -            }
208.1492 -            if (i < 0) {
208.1493 -                throw new IndexOutOfBoundsException();
208.1494 -            }
208.1495 -        }
208.1496 -        return x;
208.1497 -    }
208.1498 -
208.1499 -    /**
208.1500 -     * Determines if the specified character is a lowercase character.
208.1501 -     * <p>
208.1502 -     * A character is lowercase if its general category type, provided
208.1503 -     * by {@code Character.getType(ch)}, is
208.1504 -     * {@code LOWERCASE_LETTER}, or it has contributory property
208.1505 -     * Other_Lowercase as defined by the Unicode Standard.
208.1506 -     * <p>
208.1507 -     * The following are examples of lowercase characters:
208.1508 -     * <p><blockquote><pre>
208.1509 -     * 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
208.1510 -     * '&#92;u00DF' '&#92;u00E0' '&#92;u00E1' '&#92;u00E2' '&#92;u00E3' '&#92;u00E4' '&#92;u00E5' '&#92;u00E6'
208.1511 -     * '&#92;u00E7' '&#92;u00E8' '&#92;u00E9' '&#92;u00EA' '&#92;u00EB' '&#92;u00EC' '&#92;u00ED' '&#92;u00EE'
208.1512 -     * '&#92;u00EF' '&#92;u00F0' '&#92;u00F1' '&#92;u00F2' '&#92;u00F3' '&#92;u00F4' '&#92;u00F5' '&#92;u00F6'
208.1513 -     * '&#92;u00F8' '&#92;u00F9' '&#92;u00FA' '&#92;u00FB' '&#92;u00FC' '&#92;u00FD' '&#92;u00FE' '&#92;u00FF'
208.1514 -     * </pre></blockquote>
208.1515 -     * <p> Many other Unicode characters are lowercase too.
208.1516 -     *
208.1517 -     * <p><b>Note:</b> This method cannot handle <a
208.1518 -     * href="#supplementary"> supplementary characters</a>. To support
208.1519 -     * all Unicode characters, including supplementary characters, use
208.1520 -     * the {@link #isLowerCase(int)} method.
208.1521 -     *
208.1522 -     * @param   ch   the character to be tested.
208.1523 -     * @return  {@code true} if the character is lowercase;
208.1524 -     *          {@code false} otherwise.
208.1525 -     * @see     Character#isLowerCase(char)
208.1526 -     * @see     Character#isTitleCase(char)
208.1527 -     * @see     Character#toLowerCase(char)
208.1528 -     * @see     Character#getType(char)
208.1529 -     */
208.1530 -    public static boolean isLowerCase(char ch) {
208.1531 -        throw new UnsupportedOperationException();
208.1532 -    }
208.1533 -
208.1534 -    /**
208.1535 -     * Determines if the specified character is an uppercase character.
208.1536 -     * <p>
208.1537 -     * A character is uppercase if its general category type, provided by
208.1538 -     * {@code Character.getType(ch)}, is {@code UPPERCASE_LETTER}.
208.1539 -     * or it has contributory property Other_Uppercase as defined by the Unicode Standard.
208.1540 -     * <p>
208.1541 -     * The following are examples of uppercase characters:
208.1542 -     * <p><blockquote><pre>
208.1543 -     * 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
208.1544 -     * '&#92;u00C0' '&#92;u00C1' '&#92;u00C2' '&#92;u00C3' '&#92;u00C4' '&#92;u00C5' '&#92;u00C6' '&#92;u00C7'
208.1545 -     * '&#92;u00C8' '&#92;u00C9' '&#92;u00CA' '&#92;u00CB' '&#92;u00CC' '&#92;u00CD' '&#92;u00CE' '&#92;u00CF'
208.1546 -     * '&#92;u00D0' '&#92;u00D1' '&#92;u00D2' '&#92;u00D3' '&#92;u00D4' '&#92;u00D5' '&#92;u00D6' '&#92;u00D8'
208.1547 -     * '&#92;u00D9' '&#92;u00DA' '&#92;u00DB' '&#92;u00DC' '&#92;u00DD' '&#92;u00DE'
208.1548 -     * </pre></blockquote>
208.1549 -     * <p> Many other Unicode characters are uppercase too.<p>
208.1550 -     *
208.1551 -     * <p><b>Note:</b> This method cannot handle <a
208.1552 -     * href="#supplementary"> supplementary characters</a>. To support
208.1553 -     * all Unicode characters, including supplementary characters, use
208.1554 -     * the {@link #isUpperCase(int)} method.
208.1555 -     *
208.1556 -     * @param   ch   the character to be tested.
208.1557 -     * @return  {@code true} if the character is uppercase;
208.1558 -     *          {@code false} otherwise.
208.1559 -     * @see     Character#isLowerCase(char)
208.1560 -     * @see     Character#isTitleCase(char)
208.1561 -     * @see     Character#toUpperCase(char)
208.1562 -     * @see     Character#getType(char)
208.1563 -     * @since   1.0
208.1564 -     */
208.1565 -    public static boolean isUpperCase(char ch) {
208.1566 -        throw new UnsupportedOperationException();
208.1567 -    }
208.1568 -
208.1569 -    /**
208.1570 -     * Determines if the specified character is a titlecase character.
208.1571 -     * <p>
208.1572 -     * A character is a titlecase character if its general
208.1573 -     * category type, provided by {@code Character.getType(ch)},
208.1574 -     * is {@code TITLECASE_LETTER}.
208.1575 -     * <p>
208.1576 -     * Some characters look like pairs of Latin letters. For example, there
208.1577 -     * is an uppercase letter that looks like "LJ" and has a corresponding
208.1578 -     * lowercase letter that looks like "lj". A third form, which looks like "Lj",
208.1579 -     * is the appropriate form to use when rendering a word in lowercase
208.1580 -     * with initial capitals, as for a book title.
208.1581 -     * <p>
208.1582 -     * These are some of the Unicode characters for which this method returns
208.1583 -     * {@code true}:
208.1584 -     * <ul>
208.1585 -     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON}
208.1586 -     * <li>{@code LATIN CAPITAL LETTER L WITH SMALL LETTER J}
208.1587 -     * <li>{@code LATIN CAPITAL LETTER N WITH SMALL LETTER J}
208.1588 -     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z}
208.1589 -     * </ul>
208.1590 -     * <p> Many other Unicode characters are titlecase too.<p>
208.1591 -     *
208.1592 -     * <p><b>Note:</b> This method cannot handle <a
208.1593 -     * href="#supplementary"> supplementary characters</a>. To support
208.1594 -     * all Unicode characters, including supplementary characters, use
208.1595 -     * the {@link #isTitleCase(int)} method.
208.1596 -     *
208.1597 -     * @param   ch   the character to be tested.
208.1598 -     * @return  {@code true} if the character is titlecase;
208.1599 -     *          {@code false} otherwise.
208.1600 -     * @see     Character#isLowerCase(char)
208.1601 -     * @see     Character#isUpperCase(char)
208.1602 -     * @see     Character#toTitleCase(char)
208.1603 -     * @see     Character#getType(char)
208.1604 -     * @since   1.0.2
208.1605 -     */
208.1606 -    public static boolean isTitleCase(char ch) {
208.1607 -        return isTitleCase((int)ch);
208.1608 -    }
208.1609 -
208.1610 -    /**
208.1611 -     * Determines if the specified character (Unicode code point) is a titlecase character.
208.1612 -     * <p>
208.1613 -     * A character is a titlecase character if its general
208.1614 -     * category type, provided by {@link Character#getType(int) getType(codePoint)},
208.1615 -     * is {@code TITLECASE_LETTER}.
208.1616 -     * <p>
208.1617 -     * Some characters look like pairs of Latin letters. For example, there
208.1618 -     * is an uppercase letter that looks like "LJ" and has a corresponding
208.1619 -     * lowercase letter that looks like "lj". A third form, which looks like "Lj",
208.1620 -     * is the appropriate form to use when rendering a word in lowercase
208.1621 -     * with initial capitals, as for a book title.
208.1622 -     * <p>
208.1623 -     * These are some of the Unicode characters for which this method returns
208.1624 -     * {@code true}:
208.1625 -     * <ul>
208.1626 -     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON}
208.1627 -     * <li>{@code LATIN CAPITAL LETTER L WITH SMALL LETTER J}
208.1628 -     * <li>{@code LATIN CAPITAL LETTER N WITH SMALL LETTER J}
208.1629 -     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z}
208.1630 -     * </ul>
208.1631 -     * <p> Many other Unicode characters are titlecase too.<p>
208.1632 -     *
208.1633 -     * @param   codePoint the character (Unicode code point) to be tested.
208.1634 -     * @return  {@code true} if the character is titlecase;
208.1635 -     *          {@code false} otherwise.
208.1636 -     * @see     Character#isLowerCase(int)
208.1637 -     * @see     Character#isUpperCase(int)
208.1638 -     * @see     Character#toTitleCase(int)
208.1639 -     * @see     Character#getType(int)
208.1640 -     * @since   1.5
208.1641 -     */
208.1642 -    public static boolean isTitleCase(int codePoint) {
208.1643 -        return getType(codePoint) == Character.TITLECASE_LETTER;
208.1644 -    }
208.1645 -
208.1646 -    /**
208.1647 -     * Determines if the specified character is a digit.
208.1648 -     * <p>
208.1649 -     * A character is a digit if its general category type, provided
208.1650 -     * by {@code Character.getType(ch)}, is
208.1651 -     * {@code DECIMAL_DIGIT_NUMBER}.
208.1652 -     * <p>
208.1653 -     * Some Unicode character ranges that contain digits:
208.1654 -     * <ul>
208.1655 -     * <li>{@code '\u005Cu0030'} through {@code '\u005Cu0039'},
208.1656 -     *     ISO-LATIN-1 digits ({@code '0'} through {@code '9'})
208.1657 -     * <li>{@code '\u005Cu0660'} through {@code '\u005Cu0669'},
208.1658 -     *     Arabic-Indic digits
208.1659 -     * <li>{@code '\u005Cu06F0'} through {@code '\u005Cu06F9'},
208.1660 -     *     Extended Arabic-Indic digits
208.1661 -     * <li>{@code '\u005Cu0966'} through {@code '\u005Cu096F'},
208.1662 -     *     Devanagari digits
208.1663 -     * <li>{@code '\u005CuFF10'} through {@code '\u005CuFF19'},
208.1664 -     *     Fullwidth digits
208.1665 -     * </ul>
208.1666 -     *
208.1667 -     * Many other character ranges contain digits as well.
208.1668 -     *
208.1669 -     * <p><b>Note:</b> This method cannot handle <a
208.1670 -     * href="#supplementary"> supplementary characters</a>. To support
208.1671 -     * all Unicode characters, including supplementary characters, use
208.1672 -     * the {@link #isDigit(int)} method.
208.1673 -     *
208.1674 -     * @param   ch   the character to be tested.
208.1675 -     * @return  {@code true} if the character is a digit;
208.1676 -     *          {@code false} otherwise.
208.1677 -     * @see     Character#digit(char, int)
208.1678 -     * @see     Character#forDigit(int, int)
208.1679 -     * @see     Character#getType(char)
208.1680 -     */
208.1681 -    public static boolean isDigit(char ch) {
208.1682 -        return isDigit((int)ch);
208.1683 -    }
208.1684 -
208.1685 -    /**
208.1686 -     * Determines if the specified character (Unicode code point) is a digit.
208.1687 -     * <p>
208.1688 -     * A character is a digit if its general category type, provided
208.1689 -     * by {@link Character#getType(int) getType(codePoint)}, is
208.1690 -     * {@code DECIMAL_DIGIT_NUMBER}.
208.1691 -     * <p>
208.1692 -     * Some Unicode character ranges that contain digits:
208.1693 -     * <ul>
208.1694 -     * <li>{@code '\u005Cu0030'} through {@code '\u005Cu0039'},
208.1695 -     *     ISO-LATIN-1 digits ({@code '0'} through {@code '9'})
208.1696 -     * <li>{@code '\u005Cu0660'} through {@code '\u005Cu0669'},
208.1697 -     *     Arabic-Indic digits
208.1698 -     * <li>{@code '\u005Cu06F0'} through {@code '\u005Cu06F9'},
208.1699 -     *     Extended Arabic-Indic digits
208.1700 -     * <li>{@code '\u005Cu0966'} through {@code '\u005Cu096F'},
208.1701 -     *     Devanagari digits
208.1702 -     * <li>{@code '\u005CuFF10'} through {@code '\u005CuFF19'},
208.1703 -     *     Fullwidth digits
208.1704 -     * </ul>
208.1705 -     *
208.1706 -     * Many other character ranges contain digits as well.
208.1707 -     *
208.1708 -     * @param   codePoint the character (Unicode code point) to be tested.
208.1709 -     * @return  {@code true} if the character is a digit;
208.1710 -     *          {@code false} otherwise.
208.1711 -     * @see     Character#forDigit(int, int)
208.1712 -     * @see     Character#getType(int)
208.1713 -     * @since   1.5
208.1714 -     */
208.1715 -    public static boolean isDigit(int codePoint) {
208.1716 -        return getType(codePoint) == Character.DECIMAL_DIGIT_NUMBER;
208.1717 -    }
208.1718 -
208.1719 -    /**
208.1720 -     * Determines if a character is defined in Unicode.
208.1721 -     * <p>
208.1722 -     * A character is defined if at least one of the following is true:
208.1723 -     * <ul>
208.1724 -     * <li>It has an entry in the UnicodeData file.
208.1725 -     * <li>It has a value in a range defined by the UnicodeData file.
208.1726 -     * </ul>
208.1727 -     *
208.1728 -     * <p><b>Note:</b> This method cannot handle <a
208.1729 -     * href="#supplementary"> supplementary characters</a>. To support
208.1730 -     * all Unicode characters, including supplementary characters, use
208.1731 -     * the {@link #isDefined(int)} method.
208.1732 -     *
208.1733 -     * @param   ch   the character to be tested
208.1734 -     * @return  {@code true} if the character has a defined meaning
208.1735 -     *          in Unicode; {@code false} otherwise.
208.1736 -     * @see     Character#isDigit(char)
208.1737 -     * @see     Character#isLetter(char)
208.1738 -     * @see     Character#isLetterOrDigit(char)
208.1739 -     * @see     Character#isLowerCase(char)
208.1740 -     * @see     Character#isTitleCase(char)
208.1741 -     * @see     Character#isUpperCase(char)
208.1742 -     * @since   1.0.2
208.1743 -     */
208.1744 -    public static boolean isDefined(char ch) {
208.1745 -        return isDefined((int)ch);
208.1746 -    }
208.1747 -
208.1748 -    /**
208.1749 -     * Determines if a character (Unicode code point) is defined in Unicode.
208.1750 -     * <p>
208.1751 -     * A character is defined if at least one of the following is true:
208.1752 -     * <ul>
208.1753 -     * <li>It has an entry in the UnicodeData file.
208.1754 -     * <li>It has a value in a range defined by the UnicodeData file.
208.1755 -     * </ul>
208.1756 -     *
208.1757 -     * @param   codePoint the character (Unicode code point) to be tested.
208.1758 -     * @return  {@code true} if the character has a defined meaning
208.1759 -     *          in Unicode; {@code false} otherwise.
208.1760 -     * @see     Character#isDigit(int)
208.1761 -     * @see     Character#isLetter(int)
208.1762 -     * @see     Character#isLetterOrDigit(int)
208.1763 -     * @see     Character#isLowerCase(int)
208.1764 -     * @see     Character#isTitleCase(int)
208.1765 -     * @see     Character#isUpperCase(int)
208.1766 -     * @since   1.5
208.1767 -     */
208.1768 -    public static boolean isDefined(int codePoint) {
208.1769 -        return getType(codePoint) != Character.UNASSIGNED;
208.1770 -    }
208.1771 -
208.1772 -    /**
208.1773 -     * Determines if the specified character is a letter.
208.1774 -     * <p>
208.1775 -     * A character is considered to be a letter if its general
208.1776 -     * category type, provided by {@code Character.getType(ch)},
208.1777 -     * is any of the following:
208.1778 -     * <ul>
208.1779 -     * <li> {@code UPPERCASE_LETTER}
208.1780 -     * <li> {@code LOWERCASE_LETTER}
208.1781 -     * <li> {@code TITLECASE_LETTER}
208.1782 -     * <li> {@code MODIFIER_LETTER}
208.1783 -     * <li> {@code OTHER_LETTER}
208.1784 -     * </ul>
208.1785 -     *
208.1786 -     * Not all letters have case. Many characters are
208.1787 -     * letters but are neither uppercase nor lowercase nor titlecase.
208.1788 -     *
208.1789 -     * <p><b>Note:</b> This method cannot handle <a
208.1790 -     * href="#supplementary"> supplementary characters</a>. To support
208.1791 -     * all Unicode characters, including supplementary characters, use
208.1792 -     * the {@link #isLetter(int)} method.
208.1793 -     *
208.1794 -     * @param   ch   the character to be tested.
208.1795 -     * @return  {@code true} if the character is a letter;
208.1796 -     *          {@code false} otherwise.
208.1797 -     * @see     Character#isDigit(char)
208.1798 -     * @see     Character#isJavaIdentifierStart(char)
208.1799 -     * @see     Character#isJavaLetter(char)
208.1800 -     * @see     Character#isJavaLetterOrDigit(char)
208.1801 -     * @see     Character#isLetterOrDigit(char)
208.1802 -     * @see     Character#isLowerCase(char)
208.1803 -     * @see     Character#isTitleCase(char)
208.1804 -     * @see     Character#isUnicodeIdentifierStart(char)
208.1805 -     * @see     Character#isUpperCase(char)
208.1806 -     */
208.1807 -    public static boolean isLetter(char ch) {
208.1808 -        return isLetter((int)ch);
208.1809 -    }
208.1810 -
208.1811 -    /**
208.1812 -     * Determines if the specified character (Unicode code point) is a letter.
208.1813 -     * <p>
208.1814 -     * A character is considered to be a letter if its general
208.1815 -     * category type, provided by {@link Character#getType(int) getType(codePoint)},
208.1816 -     * is any of the following:
208.1817 -     * <ul>
208.1818 -     * <li> {@code UPPERCASE_LETTER}
208.1819 -     * <li> {@code LOWERCASE_LETTER}
208.1820 -     * <li> {@code TITLECASE_LETTER}
208.1821 -     * <li> {@code MODIFIER_LETTER}
208.1822 -     * <li> {@code OTHER_LETTER}
208.1823 -     * </ul>
208.1824 -     *
208.1825 -     * Not all letters have case. Many characters are
208.1826 -     * letters but are neither uppercase nor lowercase nor titlecase.
208.1827 -     *
208.1828 -     * @param   codePoint the character (Unicode code point) to be tested.
208.1829 -     * @return  {@code true} if the character is a letter;
208.1830 -     *          {@code false} otherwise.
208.1831 -     * @see     Character#isDigit(int)
208.1832 -     * @see     Character#isJavaIdentifierStart(int)
208.1833 -     * @see     Character#isLetterOrDigit(int)
208.1834 -     * @see     Character#isLowerCase(int)
208.1835 -     * @see     Character#isTitleCase(int)
208.1836 -     * @see     Character#isUnicodeIdentifierStart(int)
208.1837 -     * @see     Character#isUpperCase(int)
208.1838 -     * @since   1.5
208.1839 -     */
208.1840 -    public static boolean isLetter(int codePoint) {
208.1841 -        return ((((1 << Character.UPPERCASE_LETTER) |
208.1842 -            (1 << Character.LOWERCASE_LETTER) |
208.1843 -            (1 << Character.TITLECASE_LETTER) |
208.1844 -            (1 << Character.MODIFIER_LETTER) |
208.1845 -            (1 << Character.OTHER_LETTER)) >> getType(codePoint)) & 1)
208.1846 -            != 0;
208.1847 -    }
208.1848 -
208.1849 -    /**
208.1850 -     * Determines if the specified character is a letter or digit.
208.1851 -     * <p>
208.1852 -     * A character is considered to be a letter or digit if either
208.1853 -     * {@code Character.isLetter(char ch)} or
208.1854 -     * {@code Character.isDigit(char ch)} returns
208.1855 -     * {@code true} for the character.
208.1856 -     *
208.1857 -     * <p><b>Note:</b> This method cannot handle <a
208.1858 -     * href="#supplementary"> supplementary characters</a>. To support
208.1859 -     * all Unicode characters, including supplementary characters, use
208.1860 -     * the {@link #isLetterOrDigit(int)} method.
208.1861 -     *
208.1862 -     * @param   ch   the character to be tested.
208.1863 -     * @return  {@code true} if the character is a letter or digit;
208.1864 -     *          {@code false} otherwise.
208.1865 -     * @see     Character#isDigit(char)
208.1866 -     * @see     Character#isJavaIdentifierPart(char)
208.1867 -     * @see     Character#isJavaLetter(char)
208.1868 -     * @see     Character#isJavaLetterOrDigit(char)
208.1869 -     * @see     Character#isLetter(char)
208.1870 -     * @see     Character#isUnicodeIdentifierPart(char)
208.1871 -     * @since   1.0.2
208.1872 -     */
208.1873 -    public static boolean isLetterOrDigit(char ch) {
208.1874 -        return isLetterOrDigit((int)ch);
208.1875 -    }
208.1876 -
208.1877 -    /**
208.1878 -     * Determines if the specified character (Unicode code point) is a letter or digit.
208.1879 -     * <p>
208.1880 -     * A character is considered to be a letter or digit if either
208.1881 -     * {@link #isLetter(int) isLetter(codePoint)} or
208.1882 -     * {@link #isDigit(int) isDigit(codePoint)} returns
208.1883 -     * {@code true} for the character.
208.1884 -     *
208.1885 -     * @param   codePoint the character (Unicode code point) to be tested.
208.1886 -     * @return  {@code true} if the character is a letter or digit;
208.1887 -     *          {@code false} otherwise.
208.1888 -     * @see     Character#isDigit(int)
208.1889 -     * @see     Character#isJavaIdentifierPart(int)
208.1890 -     * @see     Character#isLetter(int)
208.1891 -     * @see     Character#isUnicodeIdentifierPart(int)
208.1892 -     * @since   1.5
208.1893 -     */
208.1894 -    public static boolean isLetterOrDigit(int codePoint) {
208.1895 -        return ((((1 << Character.UPPERCASE_LETTER) |
208.1896 -            (1 << Character.LOWERCASE_LETTER) |
208.1897 -            (1 << Character.TITLECASE_LETTER) |
208.1898 -            (1 << Character.MODIFIER_LETTER) |
208.1899 -            (1 << Character.OTHER_LETTER) |
208.1900 -            (1 << Character.DECIMAL_DIGIT_NUMBER)) >> getType(codePoint)) & 1)
208.1901 -            != 0;
208.1902 -    }
208.1903 -    
208.1904 -    static int getType(int x) {
208.1905 -        throw new UnsupportedOperationException();
208.1906 -    }
208.1907 -    
208.1908 -    /**
208.1909 -     * Converts the character argument to lowercase using case
208.1910 -     * mapping information from the UnicodeData file.
208.1911 -     * <p>
208.1912 -     * Note that
208.1913 -     * {@code Character.isLowerCase(Character.toLowerCase(ch))}
208.1914 -     * does not always return {@code true} for some ranges of
208.1915 -     * characters, particularly those that are symbols or ideographs.
208.1916 -     *
208.1917 -     * <p>In general, {@link String#toLowerCase()} should be used to map
208.1918 -     * characters to lowercase. {@code String} case mapping methods
208.1919 -     * have several benefits over {@code Character} case mapping methods.
208.1920 -     * {@code String} case mapping methods can perform locale-sensitive
208.1921 -     * mappings, context-sensitive mappings, and 1:M character mappings, whereas
208.1922 -     * the {@code Character} case mapping methods cannot.
208.1923 -     *
208.1924 -     * <p><b>Note:</b> This method cannot handle <a
208.1925 -     * href="#supplementary"> supplementary characters</a>. To support
208.1926 -     * all Unicode characters, including supplementary characters, use
208.1927 -     * the {@link #toLowerCase(int)} method.
208.1928 -     *
208.1929 -     * @param   ch   the character to be converted.
208.1930 -     * @return  the lowercase equivalent of the character, if any;
208.1931 -     *          otherwise, the character itself.
208.1932 -     * @see     Character#isLowerCase(char)
208.1933 -     * @see     String#toLowerCase()
208.1934 -     */
208.1935 -    public static char toLowerCase(char ch) {
208.1936 -        throw new UnsupportedOperationException();
208.1937 -    }
208.1938 -
208.1939 -    /**
208.1940 -     * Converts the character argument to uppercase using case mapping
208.1941 -     * information from the UnicodeData file.
208.1942 -     * <p>
208.1943 -     * Note that
208.1944 -     * {@code Character.isUpperCase(Character.toUpperCase(ch))}
208.1945 -     * does not always return {@code true} for some ranges of
208.1946 -     * characters, particularly those that are symbols or ideographs.
208.1947 -     *
208.1948 -     * <p>In general, {@link String#toUpperCase()} should be used to map
208.1949 -     * characters to uppercase. {@code String} case mapping methods
208.1950 -     * have several benefits over {@code Character} case mapping methods.
208.1951 -     * {@code String} case mapping methods can perform locale-sensitive
208.1952 -     * mappings, context-sensitive mappings, and 1:M character mappings, whereas
208.1953 -     * the {@code Character} case mapping methods cannot.
208.1954 -     *
208.1955 -     * <p><b>Note:</b> This method cannot handle <a
208.1956 -     * href="#supplementary"> supplementary characters</a>. To support
208.1957 -     * all Unicode characters, including supplementary characters, use
208.1958 -     * the {@link #toUpperCase(int)} method.
208.1959 -     *
208.1960 -     * @param   ch   the character to be converted.
208.1961 -     * @return  the uppercase equivalent of the character, if any;
208.1962 -     *          otherwise, the character itself.
208.1963 -     * @see     Character#isUpperCase(char)
208.1964 -     * @see     String#toUpperCase()
208.1965 -     */
208.1966 -    public static char toUpperCase(char ch) {
208.1967 -        throw new UnsupportedOperationException();
208.1968 -    }
208.1969 -
208.1970 -    /**
208.1971 -     * Returns the numeric value of the character {@code ch} in the
208.1972 -     * specified radix.
208.1973 -     * <p>
208.1974 -     * If the radix is not in the range {@code MIN_RADIX} &le;
208.1975 -     * {@code radix} &le; {@code MAX_RADIX} or if the
208.1976 -     * value of {@code ch} is not a valid digit in the specified
208.1977 -     * radix, {@code -1} is returned. A character is a valid digit
208.1978 -     * if at least one of the following is true:
208.1979 -     * <ul>
208.1980 -     * <li>The method {@code isDigit} is {@code true} of the character
208.1981 -     *     and the Unicode decimal digit value of the character (or its
208.1982 -     *     single-character decomposition) is less than the specified radix.
208.1983 -     *     In this case the decimal digit value is returned.
208.1984 -     * <li>The character is one of the uppercase Latin letters
208.1985 -     *     {@code 'A'} through {@code 'Z'} and its code is less than
208.1986 -     *     {@code radix + 'A' - 10}.
208.1987 -     *     In this case, {@code ch - 'A' + 10}
208.1988 -     *     is returned.
208.1989 -     * <li>The character is one of the lowercase Latin letters
208.1990 -     *     {@code 'a'} through {@code 'z'} and its code is less than
208.1991 -     *     {@code radix + 'a' - 10}.
208.1992 -     *     In this case, {@code ch - 'a' + 10}
208.1993 -     *     is returned.
208.1994 -     * <li>The character is one of the fullwidth uppercase Latin letters A
208.1995 -     *     ({@code '\u005CuFF21'}) through Z ({@code '\u005CuFF3A'})
208.1996 -     *     and its code is less than
208.1997 -     *     {@code radix + '\u005CuFF21' - 10}.
208.1998 -     *     In this case, {@code ch - '\u005CuFF21' + 10}
208.1999 -     *     is returned.
208.2000 -     * <li>The character is one of the fullwidth lowercase Latin letters a
208.2001 -     *     ({@code '\u005CuFF41'}) through z ({@code '\u005CuFF5A'})
208.2002 -     *     and its code is less than
208.2003 -     *     {@code radix + '\u005CuFF41' - 10}.
208.2004 -     *     In this case, {@code ch - '\u005CuFF41' + 10}
208.2005 -     *     is returned.
208.2006 -     * </ul>
208.2007 -     *
208.2008 -     * <p><b>Note:</b> This method cannot handle <a
208.2009 -     * href="#supplementary"> supplementary characters</a>. To support
208.2010 -     * all Unicode characters, including supplementary characters, use
208.2011 -     * the {@link #digit(int, int)} method.
208.2012 -     *
208.2013 -     * @param   ch      the character to be converted.
208.2014 -     * @param   radix   the radix.
208.2015 -     * @return  the numeric value represented by the character in the
208.2016 -     *          specified radix.
208.2017 -     * @see     Character#forDigit(int, int)
208.2018 -     * @see     Character#isDigit(char)
208.2019 -     */
208.2020 -    public static int digit(char ch, int radix) {
208.2021 -        return digit((int)ch, radix);
208.2022 -    }
208.2023 -
208.2024 -    /**
208.2025 -     * Returns the numeric value of the specified character (Unicode
208.2026 -     * code point) in the specified radix.
208.2027 -     *
208.2028 -     * <p>If the radix is not in the range {@code MIN_RADIX} &le;
208.2029 -     * {@code radix} &le; {@code MAX_RADIX} or if the
208.2030 -     * character is not a valid digit in the specified
208.2031 -     * radix, {@code -1} is returned. A character is a valid digit
208.2032 -     * if at least one of the following is true:
208.2033 -     * <ul>
208.2034 -     * <li>The method {@link #isDigit(int) isDigit(codePoint)} is {@code true} of the character
208.2035 -     *     and the Unicode decimal digit value of the character (or its
208.2036 -     *     single-character decomposition) is less than the specified radix.
208.2037 -     *     In this case the decimal digit value is returned.
208.2038 -     * <li>The character is one of the uppercase Latin letters
208.2039 -     *     {@code 'A'} through {@code 'Z'} and its code is less than
208.2040 -     *     {@code radix + 'A' - 10}.
208.2041 -     *     In this case, {@code codePoint - 'A' + 10}
208.2042 -     *     is returned.
208.2043 -     * <li>The character is one of the lowercase Latin letters
208.2044 -     *     {@code 'a'} through {@code 'z'} and its code is less than
208.2045 -     *     {@code radix + 'a' - 10}.
208.2046 -     *     In this case, {@code codePoint - 'a' + 10}
208.2047 -     *     is returned.
208.2048 -     * <li>The character is one of the fullwidth uppercase Latin letters A
208.2049 -     *     ({@code '\u005CuFF21'}) through Z ({@code '\u005CuFF3A'})
208.2050 -     *     and its code is less than
208.2051 -     *     {@code radix + '\u005CuFF21' - 10}.
208.2052 -     *     In this case,
208.2053 -     *     {@code codePoint - '\u005CuFF21' + 10}
208.2054 -     *     is returned.
208.2055 -     * <li>The character is one of the fullwidth lowercase Latin letters a
208.2056 -     *     ({@code '\u005CuFF41'}) through z ({@code '\u005CuFF5A'})
208.2057 -     *     and its code is less than
208.2058 -     *     {@code radix + '\u005CuFF41'- 10}.
208.2059 -     *     In this case,
208.2060 -     *     {@code codePoint - '\u005CuFF41' + 10}
208.2061 -     *     is returned.
208.2062 -     * </ul>
208.2063 -     *
208.2064 -     * @param   codePoint the character (Unicode code point) to be converted.
208.2065 -     * @param   radix   the radix.
208.2066 -     * @return  the numeric value represented by the character in the
208.2067 -     *          specified radix.
208.2068 -     * @see     Character#forDigit(int, int)
208.2069 -     * @see     Character#isDigit(int)
208.2070 -     * @since   1.5
208.2071 -     */
208.2072 -    public static int digit(int codePoint, int radix) {
208.2073 -        throw new UnsupportedOperationException();
208.2074 -    }
208.2075 -
208.2076 -    /**
208.2077 -     * Returns the {@code int} value that the specified Unicode
208.2078 -     * character represents. For example, the character
208.2079 -     * {@code '\u005Cu216C'} (the roman numeral fifty) will return
208.2080 -     * an int with a value of 50.
208.2081 -     * <p>
208.2082 -     * The letters A-Z in their uppercase ({@code '\u005Cu0041'} through
208.2083 -     * {@code '\u005Cu005A'}), lowercase
208.2084 -     * ({@code '\u005Cu0061'} through {@code '\u005Cu007A'}), and
208.2085 -     * full width variant ({@code '\u005CuFF21'} through
208.2086 -     * {@code '\u005CuFF3A'} and {@code '\u005CuFF41'} through
208.2087 -     * {@code '\u005CuFF5A'}) forms have numeric values from 10
208.2088 -     * through 35. This is independent of the Unicode specification,
208.2089 -     * which does not assign numeric values to these {@code char}
208.2090 -     * values.
208.2091 -     * <p>
208.2092 -     * If the character does not have a numeric value, then -1 is returned.
208.2093 -     * If the character has a numeric value that cannot be represented as a
208.2094 -     * nonnegative integer (for example, a fractional value), then -2
208.2095 -     * is returned.
208.2096 -     *
208.2097 -     * <p><b>Note:</b> This method cannot handle <a
208.2098 -     * href="#supplementary"> supplementary characters</a>. To support
208.2099 -     * all Unicode characters, including supplementary characters, use
208.2100 -     * the {@link #getNumericValue(int)} method.
208.2101 -     *
208.2102 -     * @param   ch      the character to be converted.
208.2103 -     * @return  the numeric value of the character, as a nonnegative {@code int}
208.2104 -     *           value; -2 if the character has a numeric value that is not a
208.2105 -     *          nonnegative integer; -1 if the character has no numeric value.
208.2106 -     * @see     Character#forDigit(int, int)
208.2107 -     * @see     Character#isDigit(char)
208.2108 -     * @since   1.1
208.2109 -     */
208.2110 -    public static int getNumericValue(char ch) {
208.2111 -        return getNumericValue((int)ch);
208.2112 -    }
208.2113 -
208.2114 -    /**
208.2115 -     * Returns the {@code int} value that the specified
208.2116 -     * character (Unicode code point) represents. For example, the character
208.2117 -     * {@code '\u005Cu216C'} (the Roman numeral fifty) will return
208.2118 -     * an {@code int} with a value of 50.
208.2119 -     * <p>
208.2120 -     * The letters A-Z in their uppercase ({@code '\u005Cu0041'} through
208.2121 -     * {@code '\u005Cu005A'}), lowercase
208.2122 -     * ({@code '\u005Cu0061'} through {@code '\u005Cu007A'}), and
208.2123 -     * full width variant ({@code '\u005CuFF21'} through
208.2124 -     * {@code '\u005CuFF3A'} and {@code '\u005CuFF41'} through
208.2125 -     * {@code '\u005CuFF5A'}) forms have numeric values from 10
208.2126 -     * through 35. This is independent of the Unicode specification,
208.2127 -     * which does not assign numeric values to these {@code char}
208.2128 -     * values.
208.2129 -     * <p>
208.2130 -     * If the character does not have a numeric value, then -1 is returned.
208.2131 -     * If the character has a numeric value that cannot be represented as a
208.2132 -     * nonnegative integer (for example, a fractional value), then -2
208.2133 -     * is returned.
208.2134 -     *
208.2135 -     * @param   codePoint the character (Unicode code point) to be converted.
208.2136 -     * @return  the numeric value of the character, as a nonnegative {@code int}
208.2137 -     *          value; -2 if the character has a numeric value that is not a
208.2138 -     *          nonnegative integer; -1 if the character has no numeric value.
208.2139 -     * @see     Character#forDigit(int, int)
208.2140 -     * @see     Character#isDigit(int)
208.2141 -     * @since   1.5
208.2142 -     */
208.2143 -    public static int getNumericValue(int codePoint) {
208.2144 -        throw new UnsupportedOperationException();
208.2145 -    }
208.2146 -
208.2147 -    /**
208.2148 -     * Determines if the specified character is ISO-LATIN-1 white space.
208.2149 -     * This method returns {@code true} for the following five
208.2150 -     * characters only:
208.2151 -     * <table>
208.2152 -     * <tr><td>{@code '\t'}</td>            <td>{@code U+0009}</td>
208.2153 -     *     <td>{@code HORIZONTAL TABULATION}</td></tr>
208.2154 -     * <tr><td>{@code '\n'}</td>            <td>{@code U+000A}</td>
208.2155 -     *     <td>{@code NEW LINE}</td></tr>
208.2156 -     * <tr><td>{@code '\f'}</td>            <td>{@code U+000C}</td>
208.2157 -     *     <td>{@code FORM FEED}</td></tr>
208.2158 -     * <tr><td>{@code '\r'}</td>            <td>{@code U+000D}</td>
208.2159 -     *     <td>{@code CARRIAGE RETURN}</td></tr>
208.2160 -     * <tr><td>{@code '&nbsp;'}</td>  <td>{@code U+0020}</td>
208.2161 -     *     <td>{@code SPACE}</td></tr>
208.2162 -     * </table>
208.2163 -     *
208.2164 -     * @param      ch   the character to be tested.
208.2165 -     * @return     {@code true} if the character is ISO-LATIN-1 white
208.2166 -     *             space; {@code false} otherwise.
208.2167 -     * @see        Character#isSpaceChar(char)
208.2168 -     * @see        Character#isWhitespace(char)
208.2169 -     * @deprecated Replaced by isWhitespace(char).
208.2170 -     */
208.2171 -    @Deprecated
208.2172 -    public static boolean isSpace(char ch) {
208.2173 -        return (ch <= 0x0020) &&
208.2174 -            (((((1L << 0x0009) |
208.2175 -            (1L << 0x000A) |
208.2176 -            (1L << 0x000C) |
208.2177 -            (1L << 0x000D) |
208.2178 -            (1L << 0x0020)) >> ch) & 1L) != 0);
208.2179 -    }
208.2180 -
208.2181 -
208.2182 -
208.2183 -    /**
208.2184 -     * Determines if the specified character is white space according to Java.
208.2185 -     * A character is a Java whitespace character if and only if it satisfies
208.2186 -     * one of the following criteria:
208.2187 -     * <ul>
208.2188 -     * <li> It is a Unicode space character ({@code SPACE_SEPARATOR},
208.2189 -     *      {@code LINE_SEPARATOR}, or {@code PARAGRAPH_SEPARATOR})
208.2190 -     *      but is not also a non-breaking space ({@code '\u005Cu00A0'},
208.2191 -     *      {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).
208.2192 -     * <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.
208.2193 -     * <li> It is {@code '\u005Cn'}, U+000A LINE FEED.
208.2194 -     * <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.
208.2195 -     * <li> It is {@code '\u005Cf'}, U+000C FORM FEED.
208.2196 -     * <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.
208.2197 -     * <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.
208.2198 -     * <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.
208.2199 -     * <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.
208.2200 -     * <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.
208.2201 -     * </ul>
208.2202 -     *
208.2203 -     * <p><b>Note:</b> This method cannot handle <a
208.2204 -     * href="#supplementary"> supplementary characters</a>. To support
208.2205 -     * all Unicode characters, including supplementary characters, use
208.2206 -     * the {@link #isWhitespace(int)} method.
208.2207 -     *
208.2208 -     * @param   ch the character to be tested.
208.2209 -     * @return  {@code true} if the character is a Java whitespace
208.2210 -     *          character; {@code false} otherwise.
208.2211 -     * @see     Character#isSpaceChar(char)
208.2212 -     * @since   1.1
208.2213 -     */
208.2214 -    public static boolean isWhitespace(char ch) {
208.2215 -        return isWhitespace((int)ch);
208.2216 -    }
208.2217 -
208.2218 -    /**
208.2219 -     * Determines if the specified character (Unicode code point) is
208.2220 -     * white space according to Java.  A character is a Java
208.2221 -     * whitespace character if and only if it satisfies one of the
208.2222 -     * following criteria:
208.2223 -     * <ul>
208.2224 -     * <li> It is a Unicode space character ({@link #SPACE_SEPARATOR},
208.2225 -     *      {@link #LINE_SEPARATOR}, or {@link #PARAGRAPH_SEPARATOR})
208.2226 -     *      but is not also a non-breaking space ({@code '\u005Cu00A0'},
208.2227 -     *      {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).
208.2228 -     * <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.
208.2229 -     * <li> It is {@code '\u005Cn'}, U+000A LINE FEED.
208.2230 -     * <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.
208.2231 -     * <li> It is {@code '\u005Cf'}, U+000C FORM FEED.
208.2232 -     * <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.
208.2233 -     * <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.
208.2234 -     * <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.
208.2235 -     * <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.
208.2236 -     * <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.
208.2237 -     * </ul>
208.2238 -     * <p>
208.2239 -     *
208.2240 -     * @param   codePoint the character (Unicode code point) to be tested.
208.2241 -     * @return  {@code true} if the character is a Java whitespace
208.2242 -     *          character; {@code false} otherwise.
208.2243 -     * @see     Character#isSpaceChar(int)
208.2244 -     * @since   1.5
208.2245 -     */
208.2246 -    public static boolean isWhitespace(int codePoint) {
208.2247 -        throw new UnsupportedOperationException();
208.2248 -    }
208.2249 -
208.2250 -    /**
208.2251 -     * Determines if the specified character is an ISO control
208.2252 -     * character.  A character is considered to be an ISO control
208.2253 -     * character if its code is in the range {@code '\u005Cu0000'}
208.2254 -     * through {@code '\u005Cu001F'} or in the range
208.2255 -     * {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.
208.2256 -     *
208.2257 -     * <p><b>Note:</b> This method cannot handle <a
208.2258 -     * href="#supplementary"> supplementary characters</a>. To support
208.2259 -     * all Unicode characters, including supplementary characters, use
208.2260 -     * the {@link #isISOControl(int)} method.
208.2261 -     *
208.2262 -     * @param   ch      the character to be tested.
208.2263 -     * @return  {@code true} if the character is an ISO control character;
208.2264 -     *          {@code false} otherwise.
208.2265 -     *
208.2266 -     * @see     Character#isSpaceChar(char)
208.2267 -     * @see     Character#isWhitespace(char)
208.2268 -     * @since   1.1
208.2269 -     */
208.2270 -    public static boolean isISOControl(char ch) {
208.2271 -        return isISOControl((int)ch);
208.2272 -    }
208.2273 -
208.2274 -    /**
208.2275 -     * Determines if the referenced character (Unicode code point) is an ISO control
208.2276 -     * character.  A character is considered to be an ISO control
208.2277 -     * character if its code is in the range {@code '\u005Cu0000'}
208.2278 -     * through {@code '\u005Cu001F'} or in the range
208.2279 -     * {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.
208.2280 -     *
208.2281 -     * @param   codePoint the character (Unicode code point) to be tested.
208.2282 -     * @return  {@code true} if the character is an ISO control character;
208.2283 -     *          {@code false} otherwise.
208.2284 -     * @see     Character#isSpaceChar(int)
208.2285 -     * @see     Character#isWhitespace(int)
208.2286 -     * @since   1.5
208.2287 -     */
208.2288 -    public static boolean isISOControl(int codePoint) {
208.2289 -        // Optimized form of:
208.2290 -        //     (codePoint >= 0x00 && codePoint <= 0x1F) ||
208.2291 -        //     (codePoint >= 0x7F && codePoint <= 0x9F);
208.2292 -        return codePoint <= 0x9F &&
208.2293 -            (codePoint >= 0x7F || (codePoint >>> 5 == 0));
208.2294 -    }
208.2295 -
208.2296 -    /**
208.2297 -     * Determines the character representation for a specific digit in
208.2298 -     * the specified radix. If the value of {@code radix} is not a
208.2299 -     * valid radix, or the value of {@code digit} is not a valid
208.2300 -     * digit in the specified radix, the null character
208.2301 -     * ({@code '\u005Cu0000'}) is returned.
208.2302 -     * <p>
208.2303 -     * The {@code radix} argument is valid if it is greater than or
208.2304 -     * equal to {@code MIN_RADIX} and less than or equal to
208.2305 -     * {@code MAX_RADIX}. The {@code digit} argument is valid if
208.2306 -     * {@code 0 <= digit < radix}.
208.2307 -     * <p>
208.2308 -     * If the digit is less than 10, then
208.2309 -     * {@code '0' + digit} is returned. Otherwise, the value
208.2310 -     * {@code 'a' + digit - 10} is returned.
208.2311 -     *
208.2312 -     * @param   digit   the number to convert to a character.
208.2313 -     * @param   radix   the radix.
208.2314 -     * @return  the {@code char} representation of the specified digit
208.2315 -     *          in the specified radix.
208.2316 -     * @see     Character#MIN_RADIX
208.2317 -     * @see     Character#MAX_RADIX
208.2318 -     * @see     Character#digit(char, int)
208.2319 -     */
208.2320 -    public static char forDigit(int digit, int radix) {
208.2321 -        if ((digit >= radix) || (digit < 0)) {
208.2322 -            return '\0';
208.2323 -        }
208.2324 -        if ((radix < Character.MIN_RADIX) || (radix > Character.MAX_RADIX)) {
208.2325 -            return '\0';
208.2326 -        }
208.2327 -        if (digit < 10) {
208.2328 -            return (char)('0' + digit);
208.2329 -        }
208.2330 -        return (char)('a' - 10 + digit);
208.2331 -    }
208.2332 -
208.2333 -    /**
208.2334 -     * Compares two {@code Character} objects numerically.
208.2335 -     *
208.2336 -     * @param   anotherCharacter   the {@code Character} to be compared.
208.2337 -
208.2338 -     * @return  the value {@code 0} if the argument {@code Character}
208.2339 -     *          is equal to this {@code Character}; a value less than
208.2340 -     *          {@code 0} if this {@code Character} is numerically less
208.2341 -     *          than the {@code Character} argument; and a value greater than
208.2342 -     *          {@code 0} if this {@code Character} is numerically greater
208.2343 -     *          than the {@code Character} argument (unsigned comparison).
208.2344 -     *          Note that this is strictly a numerical comparison; it is not
208.2345 -     *          locale-dependent.
208.2346 -     * @since   1.2
208.2347 -     */
208.2348 -    public int compareTo(Character anotherCharacter) {
208.2349 -        return compare(this.value, anotherCharacter.value);
208.2350 -    }
208.2351 -
208.2352 -    /**
208.2353 -     * Compares two {@code char} values numerically.
208.2354 -     * The value returned is identical to what would be returned by:
208.2355 -     * <pre>
208.2356 -     *    Character.valueOf(x).compareTo(Character.valueOf(y))
208.2357 -     * </pre>
208.2358 -     *
208.2359 -     * @param  x the first {@code char} to compare
208.2360 -     * @param  y the second {@code char} to compare
208.2361 -     * @return the value {@code 0} if {@code x == y};
208.2362 -     *         a value less than {@code 0} if {@code x < y}; and
208.2363 -     *         a value greater than {@code 0} if {@code x > y}
208.2364 -     * @since 1.7
208.2365 -     */
208.2366 -    public static int compare(char x, char y) {
208.2367 -        return x - y;
208.2368 -    }
208.2369 -
208.2370 -
208.2371 -    /**
208.2372 -     * The number of bits used to represent a <tt>char</tt> value in unsigned
208.2373 -     * binary form, constant {@code 16}.
208.2374 -     *
208.2375 -     * @since 1.5
208.2376 -     */
208.2377 -    public static final int SIZE = 16;
208.2378 -
208.2379 -    /**
208.2380 -     * Returns the value obtained by reversing the order of the bytes in the
208.2381 -     * specified <tt>char</tt> value.
208.2382 -     *
208.2383 -     * @return the value obtained by reversing (or, equivalently, swapping)
208.2384 -     *     the bytes in the specified <tt>char</tt> value.
208.2385 -     * @since 1.5
208.2386 -     */
208.2387 -    public static char reverseBytes(char ch) {
208.2388 -        return (char) (((ch & 0xFF00) >> 8) | (ch << 8));
208.2389 -    }
208.2390 -
208.2391 -}
   209.1 --- a/emul/src/main/java/java/lang/Class.java	Wed Dec 05 10:03:58 2012 +0100
   209.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   209.3 @@ -1,1087 +0,0 @@
   209.4 -/*
   209.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   209.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   209.7 - *
   209.8 - * This code is free software; you can redistribute it and/or modify it
   209.9 - * under the terms of the GNU General Public License version 2 only, as
  209.10 - * published by the Free Software Foundation.  Oracle designates this
  209.11 - * particular file as subject to the "Classpath" exception as provided
  209.12 - * by Oracle in the LICENSE file that accompanied this code.
  209.13 - *
  209.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  209.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  209.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  209.17 - * version 2 for more details (a copy is included in the LICENSE file that
  209.18 - * accompanied this code).
  209.19 - *
  209.20 - * You should have received a copy of the GNU General Public License version
  209.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  209.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  209.23 - *
  209.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  209.25 - * or visit www.oracle.com if you need additional information or have any
  209.26 - * questions.
  209.27 - */
  209.28 -
  209.29 -package java.lang;
  209.30 -
  209.31 -import org.apidesign.bck2brwsr.emul.AnnotationImpl;
  209.32 -import java.io.InputStream;
  209.33 -import java.lang.annotation.Annotation;
  209.34 -import java.lang.reflect.Field;
  209.35 -import java.lang.reflect.Method;
  209.36 -import java.lang.reflect.TypeVariable;
  209.37 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  209.38 -
  209.39 -/**
  209.40 - * Instances of the class {@code Class} represent classes and
  209.41 - * interfaces in a running Java application.  An enum is a kind of
  209.42 - * class and an annotation is a kind of interface.  Every array also
  209.43 - * belongs to a class that is reflected as a {@code Class} object
  209.44 - * that is shared by all arrays with the same element type and number
  209.45 - * of dimensions.  The primitive Java types ({@code boolean},
  209.46 - * {@code byte}, {@code char}, {@code short},
  209.47 - * {@code int}, {@code long}, {@code float}, and
  209.48 - * {@code double}), and the keyword {@code void} are also
  209.49 - * represented as {@code Class} objects.
  209.50 - *
  209.51 - * <p> {@code Class} has no public constructor. Instead {@code Class}
  209.52 - * objects are constructed automatically by the Java Virtual Machine as classes
  209.53 - * are loaded and by calls to the {@code defineClass} method in the class
  209.54 - * loader.
  209.55 - *
  209.56 - * <p> The following example uses a {@code Class} object to print the
  209.57 - * class name of an object:
  209.58 - *
  209.59 - * <p> <blockquote><pre>
  209.60 - *     void printClassName(Object obj) {
  209.61 - *         System.out.println("The class of " + obj +
  209.62 - *                            " is " + obj.getClass().getName());
  209.63 - *     }
  209.64 - * </pre></blockquote>
  209.65 - *
  209.66 - * <p> It is also possible to get the {@code Class} object for a named
  209.67 - * type (or for void) using a class literal.  See Section 15.8.2 of
  209.68 - * <cite>The Java&trade; Language Specification</cite>.
  209.69 - * For example:
  209.70 - *
  209.71 - * <p> <blockquote>
  209.72 - *     {@code System.out.println("The name of class Foo is: "+Foo.class.getName());}
  209.73 - * </blockquote>
  209.74 - *
  209.75 - * @param <T> the type of the class modeled by this {@code Class}
  209.76 - * object.  For example, the type of {@code String.class} is {@code
  209.77 - * Class<String>}.  Use {@code Class<?>} if the class being modeled is
  209.78 - * unknown.
  209.79 - *
  209.80 - * @author  unascribed
  209.81 - * @see     java.lang.ClassLoader#defineClass(byte[], int, int)
  209.82 - * @since   JDK1.0
  209.83 - */
  209.84 -public final
  209.85 -    class Class<T> implements java.io.Serializable,
  209.86 -                              java.lang.reflect.GenericDeclaration,
  209.87 -                              java.lang.reflect.Type,
  209.88 -                              java.lang.reflect.AnnotatedElement {
  209.89 -    private static final int ANNOTATION= 0x00002000;
  209.90 -    private static final int ENUM      = 0x00004000;
  209.91 -    private static final int SYNTHETIC = 0x00001000;
  209.92 -
  209.93 -    /*
  209.94 -     * Constructor. Only the Java Virtual Machine creates Class
  209.95 -     * objects.
  209.96 -     */
  209.97 -    private Class() {}
  209.98 -
  209.99 -
 209.100 -    /**
 209.101 -     * Converts the object to a string. The string representation is the
 209.102 -     * string "class" or "interface", followed by a space, and then by the
 209.103 -     * fully qualified name of the class in the format returned by
 209.104 -     * {@code getName}.  If this {@code Class} object represents a
 209.105 -     * primitive type, this method returns the name of the primitive type.  If
 209.106 -     * this {@code Class} object represents void this method returns
 209.107 -     * "void".
 209.108 -     *
 209.109 -     * @return a string representation of this class object.
 209.110 -     */
 209.111 -    public String toString() {
 209.112 -        return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
 209.113 -            + getName();
 209.114 -    }
 209.115 -
 209.116 -
 209.117 -    /**
 209.118 -     * Returns the {@code Class} object associated with the class or
 209.119 -     * interface with the given string name.  Invoking this method is
 209.120 -     * equivalent to:
 209.121 -     *
 209.122 -     * <blockquote>
 209.123 -     *  {@code Class.forName(className, true, currentLoader)}
 209.124 -     * </blockquote>
 209.125 -     *
 209.126 -     * where {@code currentLoader} denotes the defining class loader of
 209.127 -     * the current class.
 209.128 -     *
 209.129 -     * <p> For example, the following code fragment returns the
 209.130 -     * runtime {@code Class} descriptor for the class named
 209.131 -     * {@code java.lang.Thread}:
 209.132 -     *
 209.133 -     * <blockquote>
 209.134 -     *   {@code Class t = Class.forName("java.lang.Thread")}
 209.135 -     * </blockquote>
 209.136 -     * <p>
 209.137 -     * A call to {@code forName("X")} causes the class named
 209.138 -     * {@code X} to be initialized.
 209.139 -     *
 209.140 -     * @param      className   the fully qualified name of the desired class.
 209.141 -     * @return     the {@code Class} object for the class with the
 209.142 -     *             specified name.
 209.143 -     * @exception LinkageError if the linkage fails
 209.144 -     * @exception ExceptionInInitializerError if the initialization provoked
 209.145 -     *            by this method fails
 209.146 -     * @exception ClassNotFoundException if the class cannot be located
 209.147 -     */
 209.148 -    public static Class<?> forName(String className)
 209.149 -                throws ClassNotFoundException {
 209.150 -        throw new UnsupportedOperationException();
 209.151 -    }
 209.152 -
 209.153 -
 209.154 -    /**
 209.155 -     * Creates a new instance of the class represented by this {@code Class}
 209.156 -     * object.  The class is instantiated as if by a {@code new}
 209.157 -     * expression with an empty argument list.  The class is initialized if it
 209.158 -     * has not already been initialized.
 209.159 -     *
 209.160 -     * <p>Note that this method propagates any exception thrown by the
 209.161 -     * nullary constructor, including a checked exception.  Use of
 209.162 -     * this method effectively bypasses the compile-time exception
 209.163 -     * checking that would otherwise be performed by the compiler.
 209.164 -     * The {@link
 209.165 -     * java.lang.reflect.Constructor#newInstance(java.lang.Object...)
 209.166 -     * Constructor.newInstance} method avoids this problem by wrapping
 209.167 -     * any exception thrown by the constructor in a (checked) {@link
 209.168 -     * java.lang.reflect.InvocationTargetException}.
 209.169 -     *
 209.170 -     * @return     a newly allocated instance of the class represented by this
 209.171 -     *             object.
 209.172 -     * @exception  IllegalAccessException  if the class or its nullary
 209.173 -     *               constructor is not accessible.
 209.174 -     * @exception  InstantiationException
 209.175 -     *               if this {@code Class} represents an abstract class,
 209.176 -     *               an interface, an array class, a primitive type, or void;
 209.177 -     *               or if the class has no nullary constructor;
 209.178 -     *               or if the instantiation fails for some other reason.
 209.179 -     * @exception  ExceptionInInitializerError if the initialization
 209.180 -     *               provoked by this method fails.
 209.181 -     * @exception  SecurityException
 209.182 -     *             If a security manager, <i>s</i>, is present and any of the
 209.183 -     *             following conditions is met:
 209.184 -     *
 209.185 -     *             <ul>
 209.186 -     *
 209.187 -     *             <li> invocation of
 209.188 -     *             {@link SecurityManager#checkMemberAccess
 209.189 -     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 209.190 -     *             creation of new instances of this class
 209.191 -     *
 209.192 -     *             <li> the caller's class loader is not the same as or an
 209.193 -     *             ancestor of the class loader for the current class and
 209.194 -     *             invocation of {@link SecurityManager#checkPackageAccess
 209.195 -     *             s.checkPackageAccess()} denies access to the package
 209.196 -     *             of this class
 209.197 -     *
 209.198 -     *             </ul>
 209.199 -     *
 209.200 -     */
 209.201 -    @JavaScriptBody(args = "self", body =
 209.202 -          "var inst = self.cnstr();"
 209.203 -        + "inst.cons__V(inst);"
 209.204 -        + "return inst;"
 209.205 -    )
 209.206 -    public T newInstance()
 209.207 -        throws InstantiationException, IllegalAccessException
 209.208 -    {
 209.209 -        throw new UnsupportedOperationException();
 209.210 -    }
 209.211 -
 209.212 -    /**
 209.213 -     * Determines if the specified {@code Object} is assignment-compatible
 209.214 -     * with the object represented by this {@code Class}.  This method is
 209.215 -     * the dynamic equivalent of the Java language {@code instanceof}
 209.216 -     * operator. The method returns {@code true} if the specified
 209.217 -     * {@code Object} argument is non-null and can be cast to the
 209.218 -     * reference type represented by this {@code Class} object without
 209.219 -     * raising a {@code ClassCastException.} It returns {@code false}
 209.220 -     * otherwise.
 209.221 -     *
 209.222 -     * <p> Specifically, if this {@code Class} object represents a
 209.223 -     * declared class, this method returns {@code true} if the specified
 209.224 -     * {@code Object} argument is an instance of the represented class (or
 209.225 -     * of any of its subclasses); it returns {@code false} otherwise. If
 209.226 -     * this {@code Class} object represents an array class, this method
 209.227 -     * returns {@code true} if the specified {@code Object} argument
 209.228 -     * can be converted to an object of the array class by an identity
 209.229 -     * conversion or by a widening reference conversion; it returns
 209.230 -     * {@code false} otherwise. If this {@code Class} object
 209.231 -     * represents an interface, this method returns {@code true} if the
 209.232 -     * class or any superclass of the specified {@code Object} argument
 209.233 -     * implements this interface; it returns {@code false} otherwise. If
 209.234 -     * this {@code Class} object represents a primitive type, this method
 209.235 -     * returns {@code false}.
 209.236 -     *
 209.237 -     * @param   obj the object to check
 209.238 -     * @return  true if {@code obj} is an instance of this class
 209.239 -     *
 209.240 -     * @since JDK1.1
 209.241 -     */
 209.242 -    public native boolean isInstance(Object obj);
 209.243 -
 209.244 -
 209.245 -    /**
 209.246 -     * Determines if the class or interface represented by this
 209.247 -     * {@code Class} object is either the same as, or is a superclass or
 209.248 -     * superinterface of, the class or interface represented by the specified
 209.249 -     * {@code Class} parameter. It returns {@code true} if so;
 209.250 -     * otherwise it returns {@code false}. If this {@code Class}
 209.251 -     * object represents a primitive type, this method returns
 209.252 -     * {@code true} if the specified {@code Class} parameter is
 209.253 -     * exactly this {@code Class} object; otherwise it returns
 209.254 -     * {@code false}.
 209.255 -     *
 209.256 -     * <p> Specifically, this method tests whether the type represented by the
 209.257 -     * specified {@code Class} parameter can be converted to the type
 209.258 -     * represented by this {@code Class} object via an identity conversion
 209.259 -     * or via a widening reference conversion. See <em>The Java Language
 209.260 -     * Specification</em>, sections 5.1.1 and 5.1.4 , for details.
 209.261 -     *
 209.262 -     * @param cls the {@code Class} object to be checked
 209.263 -     * @return the {@code boolean} value indicating whether objects of the
 209.264 -     * type {@code cls} can be assigned to objects of this class
 209.265 -     * @exception NullPointerException if the specified Class parameter is
 209.266 -     *            null.
 209.267 -     * @since JDK1.1
 209.268 -     */
 209.269 -    public native boolean isAssignableFrom(Class<?> cls);
 209.270 -
 209.271 -
 209.272 -    /**
 209.273 -     * Determines if the specified {@code Class} object represents an
 209.274 -     * interface type.
 209.275 -     *
 209.276 -     * @return  {@code true} if this object represents an interface;
 209.277 -     *          {@code false} otherwise.
 209.278 -     */
 209.279 -    public native boolean isInterface();
 209.280 -
 209.281 -
 209.282 -    /**
 209.283 -     * Determines if this {@code Class} object represents an array class.
 209.284 -     *
 209.285 -     * @return  {@code true} if this object represents an array class;
 209.286 -     *          {@code false} otherwise.
 209.287 -     * @since   JDK1.1
 209.288 -     */
 209.289 -    public boolean isArray() {
 209.290 -        return false;
 209.291 -    }
 209.292 -
 209.293 -
 209.294 -    /**
 209.295 -     * Determines if the specified {@code Class} object represents a
 209.296 -     * primitive type.
 209.297 -     *
 209.298 -     * <p> There are nine predefined {@code Class} objects to represent
 209.299 -     * the eight primitive types and void.  These are created by the Java
 209.300 -     * Virtual Machine, and have the same names as the primitive types that
 209.301 -     * they represent, namely {@code boolean}, {@code byte},
 209.302 -     * {@code char}, {@code short}, {@code int},
 209.303 -     * {@code long}, {@code float}, and {@code double}.
 209.304 -     *
 209.305 -     * <p> These objects may only be accessed via the following public static
 209.306 -     * final variables, and are the only {@code Class} objects for which
 209.307 -     * this method returns {@code true}.
 209.308 -     *
 209.309 -     * @return true if and only if this class represents a primitive type
 209.310 -     *
 209.311 -     * @see     java.lang.Boolean#TYPE
 209.312 -     * @see     java.lang.Character#TYPE
 209.313 -     * @see     java.lang.Byte#TYPE
 209.314 -     * @see     java.lang.Short#TYPE
 209.315 -     * @see     java.lang.Integer#TYPE
 209.316 -     * @see     java.lang.Long#TYPE
 209.317 -     * @see     java.lang.Float#TYPE
 209.318 -     * @see     java.lang.Double#TYPE
 209.319 -     * @see     java.lang.Void#TYPE
 209.320 -     * @since JDK1.1
 209.321 -     */
 209.322 -    public native boolean isPrimitive();
 209.323 -
 209.324 -    /**
 209.325 -     * Returns true if this {@code Class} object represents an annotation
 209.326 -     * type.  Note that if this method returns true, {@link #isInterface()}
 209.327 -     * would also return true, as all annotation types are also interfaces.
 209.328 -     *
 209.329 -     * @return {@code true} if this class object represents an annotation
 209.330 -     *      type; {@code false} otherwise
 209.331 -     * @since 1.5
 209.332 -     */
 209.333 -    public boolean isAnnotation() {
 209.334 -        return (getModifiers() & ANNOTATION) != 0;
 209.335 -    }
 209.336 -
 209.337 -    /**
 209.338 -     * Returns {@code true} if this class is a synthetic class;
 209.339 -     * returns {@code false} otherwise.
 209.340 -     * @return {@code true} if and only if this class is a synthetic class as
 209.341 -     *         defined by the Java Language Specification.
 209.342 -     * @since 1.5
 209.343 -     */
 209.344 -    public boolean isSynthetic() {
 209.345 -        return (getModifiers() & SYNTHETIC) != 0;
 209.346 -    }
 209.347 -
 209.348 -    /**
 209.349 -     * Returns the  name of the entity (class, interface, array class,
 209.350 -     * primitive type, or void) represented by this {@code Class} object,
 209.351 -     * as a {@code String}.
 209.352 -     *
 209.353 -     * <p> If this class object represents a reference type that is not an
 209.354 -     * array type then the binary name of the class is returned, as specified
 209.355 -     * by
 209.356 -     * <cite>The Java&trade; Language Specification</cite>.
 209.357 -     *
 209.358 -     * <p> If this class object represents a primitive type or void, then the
 209.359 -     * name returned is a {@code String} equal to the Java language
 209.360 -     * keyword corresponding to the primitive type or void.
 209.361 -     *
 209.362 -     * <p> If this class object represents a class of arrays, then the internal
 209.363 -     * form of the name consists of the name of the element type preceded by
 209.364 -     * one or more '{@code [}' characters representing the depth of the array
 209.365 -     * nesting.  The encoding of element type names is as follows:
 209.366 -     *
 209.367 -     * <blockquote><table summary="Element types and encodings">
 209.368 -     * <tr><th> Element Type <th> &nbsp;&nbsp;&nbsp; <th> Encoding
 209.369 -     * <tr><td> boolean      <td> &nbsp;&nbsp;&nbsp; <td align=center> Z
 209.370 -     * <tr><td> byte         <td> &nbsp;&nbsp;&nbsp; <td align=center> B
 209.371 -     * <tr><td> char         <td> &nbsp;&nbsp;&nbsp; <td align=center> C
 209.372 -     * <tr><td> class or interface
 209.373 -     *                       <td> &nbsp;&nbsp;&nbsp; <td align=center> L<i>classname</i>;
 209.374 -     * <tr><td> double       <td> &nbsp;&nbsp;&nbsp; <td align=center> D
 209.375 -     * <tr><td> float        <td> &nbsp;&nbsp;&nbsp; <td align=center> F
 209.376 -     * <tr><td> int          <td> &nbsp;&nbsp;&nbsp; <td align=center> I
 209.377 -     * <tr><td> long         <td> &nbsp;&nbsp;&nbsp; <td align=center> J
 209.378 -     * <tr><td> short        <td> &nbsp;&nbsp;&nbsp; <td align=center> S
 209.379 -     * </table></blockquote>
 209.380 -     *
 209.381 -     * <p> The class or interface name <i>classname</i> is the binary name of
 209.382 -     * the class specified above.
 209.383 -     *
 209.384 -     * <p> Examples:
 209.385 -     * <blockquote><pre>
 209.386 -     * String.class.getName()
 209.387 -     *     returns "java.lang.String"
 209.388 -     * byte.class.getName()
 209.389 -     *     returns "byte"
 209.390 -     * (new Object[3]).getClass().getName()
 209.391 -     *     returns "[Ljava.lang.Object;"
 209.392 -     * (new int[3][4][5][6][7][8][9]).getClass().getName()
 209.393 -     *     returns "[[[[[[[I"
 209.394 -     * </pre></blockquote>
 209.395 -     *
 209.396 -     * @return  the name of the class or interface
 209.397 -     *          represented by this object.
 209.398 -     */
 209.399 -    public String getName() {
 209.400 -        return jvmName().replace('/', '.');
 209.401 -    }
 209.402 -
 209.403 -    @JavaScriptBody(args = "self", body = "return self.jvmName;")
 209.404 -    private native String jvmName();
 209.405 -
 209.406 -    
 209.407 -    /**
 209.408 -     * Returns an array of {@code TypeVariable} objects that represent the
 209.409 -     * type variables declared by the generic declaration represented by this
 209.410 -     * {@code GenericDeclaration} object, in declaration order.  Returns an
 209.411 -     * array of length 0 if the underlying generic declaration declares no type
 209.412 -     * variables.
 209.413 -     *
 209.414 -     * @return an array of {@code TypeVariable} objects that represent
 209.415 -     *     the type variables declared by this generic declaration
 209.416 -     * @throws java.lang.reflect.GenericSignatureFormatError if the generic
 209.417 -     *     signature of this generic declaration does not conform to
 209.418 -     *     the format specified in
 209.419 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 209.420 -     * @since 1.5
 209.421 -     */
 209.422 -    public TypeVariable<Class<T>>[] getTypeParameters() {
 209.423 -        throw new UnsupportedOperationException();
 209.424 -    }
 209.425 - 
 209.426 -    /**
 209.427 -     * Returns the {@code Class} representing the superclass of the entity
 209.428 -     * (class, interface, primitive type or void) represented by this
 209.429 -     * {@code Class}.  If this {@code Class} represents either the
 209.430 -     * {@code Object} class, an interface, a primitive type, or void, then
 209.431 -     * null is returned.  If this object represents an array class then the
 209.432 -     * {@code Class} object representing the {@code Object} class is
 209.433 -     * returned.
 209.434 -     *
 209.435 -     * @return the superclass of the class represented by this object.
 209.436 -     */
 209.437 -    @JavaScriptBody(args = "self", body = "return self.superclass;")
 209.438 -    public native Class<? super T> getSuperclass();
 209.439 -
 209.440 -    /**
 209.441 -     * Returns the Java language modifiers for this class or interface, encoded
 209.442 -     * in an integer. The modifiers consist of the Java Virtual Machine's
 209.443 -     * constants for {@code public}, {@code protected},
 209.444 -     * {@code private}, {@code final}, {@code static},
 209.445 -     * {@code abstract} and {@code interface}; they should be decoded
 209.446 -     * using the methods of class {@code Modifier}.
 209.447 -     *
 209.448 -     * <p> If the underlying class is an array class, then its
 209.449 -     * {@code public}, {@code private} and {@code protected}
 209.450 -     * modifiers are the same as those of its component type.  If this
 209.451 -     * {@code Class} represents a primitive type or void, its
 209.452 -     * {@code public} modifier is always {@code true}, and its
 209.453 -     * {@code protected} and {@code private} modifiers are always
 209.454 -     * {@code false}. If this object represents an array class, a
 209.455 -     * primitive type or void, then its {@code final} modifier is always
 209.456 -     * {@code true} and its interface modifier is always
 209.457 -     * {@code false}. The values of its other modifiers are not determined
 209.458 -     * by this specification.
 209.459 -     *
 209.460 -     * <p> The modifier encodings are defined in <em>The Java Virtual Machine
 209.461 -     * Specification</em>, table 4.1.
 209.462 -     *
 209.463 -     * @return the {@code int} representing the modifiers for this class
 209.464 -     * @see     java.lang.reflect.Modifier
 209.465 -     * @since JDK1.1
 209.466 -     */
 209.467 -    public native int getModifiers();
 209.468 -
 209.469 -
 209.470 -    /**
 209.471 -     * Returns the simple name of the underlying class as given in the
 209.472 -     * source code. Returns an empty string if the underlying class is
 209.473 -     * anonymous.
 209.474 -     *
 209.475 -     * <p>The simple name of an array is the simple name of the
 209.476 -     * component type with "[]" appended.  In particular the simple
 209.477 -     * name of an array whose component type is anonymous is "[]".
 209.478 -     *
 209.479 -     * @return the simple name of the underlying class
 209.480 -     * @since 1.5
 209.481 -     */
 209.482 -    public String getSimpleName() {
 209.483 -        if (isArray())
 209.484 -            return getComponentType().getSimpleName()+"[]";
 209.485 -
 209.486 -        String simpleName = getSimpleBinaryName();
 209.487 -        if (simpleName == null) { // top level class
 209.488 -            simpleName = getName();
 209.489 -            return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
 209.490 -        }
 209.491 -        // According to JLS3 "Binary Compatibility" (13.1) the binary
 209.492 -        // name of non-package classes (not top level) is the binary
 209.493 -        // name of the immediately enclosing class followed by a '$' followed by:
 209.494 -        // (for nested and inner classes): the simple name.
 209.495 -        // (for local classes): 1 or more digits followed by the simple name.
 209.496 -        // (for anonymous classes): 1 or more digits.
 209.497 -
 209.498 -        // Since getSimpleBinaryName() will strip the binary name of
 209.499 -        // the immediatly enclosing class, we are now looking at a
 209.500 -        // string that matches the regular expression "\$[0-9]*"
 209.501 -        // followed by a simple name (considering the simple of an
 209.502 -        // anonymous class to be the empty string).
 209.503 -
 209.504 -        // Remove leading "\$[0-9]*" from the name
 209.505 -        int length = simpleName.length();
 209.506 -        if (length < 1 || simpleName.charAt(0) != '$')
 209.507 -            throw new IllegalStateException("Malformed class name");
 209.508 -        int index = 1;
 209.509 -        while (index < length && isAsciiDigit(simpleName.charAt(index)))
 209.510 -            index++;
 209.511 -        // Eventually, this is the empty string iff this is an anonymous class
 209.512 -        return simpleName.substring(index);
 209.513 -    }
 209.514 -
 209.515 -    /**
 209.516 -     * Returns the "simple binary name" of the underlying class, i.e.,
 209.517 -     * the binary name without the leading enclosing class name.
 209.518 -     * Returns {@code null} if the underlying class is a top level
 209.519 -     * class.
 209.520 -     */
 209.521 -    private String getSimpleBinaryName() {
 209.522 -        Class<?> enclosingClass = null; // XXX getEnclosingClass();
 209.523 -        if (enclosingClass == null) // top level class
 209.524 -            return null;
 209.525 -        // Otherwise, strip the enclosing class' name
 209.526 -        try {
 209.527 -            return getName().substring(enclosingClass.getName().length());
 209.528 -        } catch (IndexOutOfBoundsException ex) {
 209.529 -            throw new IllegalStateException("Malformed class name");
 209.530 -        }
 209.531 -    }
 209.532 -
 209.533 -    /**
 209.534 -     * Returns an array containing {@code Field} objects reflecting all
 209.535 -     * the accessible public fields of the class or interface represented by
 209.536 -     * this {@code Class} object.  The elements in the array returned are
 209.537 -     * not sorted and are not in any particular order.  This method returns an
 209.538 -     * array of length 0 if the class or interface has no accessible public
 209.539 -     * fields, or if it represents an array class, a primitive type, or void.
 209.540 -     *
 209.541 -     * <p> Specifically, if this {@code Class} object represents a class,
 209.542 -     * this method returns the public fields of this class and of all its
 209.543 -     * superclasses.  If this {@code Class} object represents an
 209.544 -     * interface, this method returns the fields of this interface and of all
 209.545 -     * its superinterfaces.
 209.546 -     *
 209.547 -     * <p> The implicit length field for array class is not reflected by this
 209.548 -     * method. User code should use the methods of class {@code Array} to
 209.549 -     * manipulate arrays.
 209.550 -     *
 209.551 -     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
 209.552 -     *
 209.553 -     * @return the array of {@code Field} objects representing the
 209.554 -     * public fields
 209.555 -     * @exception  SecurityException
 209.556 -     *             If a security manager, <i>s</i>, is present and any of the
 209.557 -     *             following conditions is met:
 209.558 -     *
 209.559 -     *             <ul>
 209.560 -     *
 209.561 -     *             <li> invocation of
 209.562 -     *             {@link SecurityManager#checkMemberAccess
 209.563 -     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 209.564 -     *             access to the fields within this class
 209.565 -     *
 209.566 -     *             <li> the caller's class loader is not the same as or an
 209.567 -     *             ancestor of the class loader for the current class and
 209.568 -     *             invocation of {@link SecurityManager#checkPackageAccess
 209.569 -     *             s.checkPackageAccess()} denies access to the package
 209.570 -     *             of this class
 209.571 -     *
 209.572 -     *             </ul>
 209.573 -     *
 209.574 -     * @since JDK1.1
 209.575 -     */
 209.576 -    public Field[] getFields() throws SecurityException {
 209.577 -        throw new SecurityException();
 209.578 -    }
 209.579 -
 209.580 -    /**
 209.581 -     * Returns an array containing {@code Method} objects reflecting all
 209.582 -     * the public <em>member</em> methods of the class or interface represented
 209.583 -     * by this {@code Class} object, including those declared by the class
 209.584 -     * or interface and those inherited from superclasses and
 209.585 -     * superinterfaces.  Array classes return all the (public) member methods
 209.586 -     * inherited from the {@code Object} class.  The elements in the array
 209.587 -     * returned are not sorted and are not in any particular order.  This
 209.588 -     * method returns an array of length 0 if this {@code Class} object
 209.589 -     * represents a class or interface that has no public member methods, or if
 209.590 -     * this {@code Class} object represents a primitive type or void.
 209.591 -     *
 209.592 -     * <p> The class initialization method {@code <clinit>} is not
 209.593 -     * included in the returned array. If the class declares multiple public
 209.594 -     * member methods with the same parameter types, they are all included in
 209.595 -     * the returned array.
 209.596 -     *
 209.597 -     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
 209.598 -     *
 209.599 -     * @return the array of {@code Method} objects representing the
 209.600 -     * public methods of this class
 209.601 -     * @exception  SecurityException
 209.602 -     *             If a security manager, <i>s</i>, is present and any of the
 209.603 -     *             following conditions is met:
 209.604 -     *
 209.605 -     *             <ul>
 209.606 -     *
 209.607 -     *             <li> invocation of
 209.608 -     *             {@link SecurityManager#checkMemberAccess
 209.609 -     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 209.610 -     *             access to the methods within this class
 209.611 -     *
 209.612 -     *             <li> the caller's class loader is not the same as or an
 209.613 -     *             ancestor of the class loader for the current class and
 209.614 -     *             invocation of {@link SecurityManager#checkPackageAccess
 209.615 -     *             s.checkPackageAccess()} denies access to the package
 209.616 -     *             of this class
 209.617 -     *
 209.618 -     *             </ul>
 209.619 -     *
 209.620 -     * @since JDK1.1
 209.621 -     */
 209.622 -    public Method[] getMethods() throws SecurityException {
 209.623 -        return Method.findMethods(this);
 209.624 -    }
 209.625 -
 209.626 -    /**
 209.627 -     * Returns a {@code Field} object that reflects the specified public
 209.628 -     * member field of the class or interface represented by this
 209.629 -     * {@code Class} object. The {@code name} parameter is a
 209.630 -     * {@code String} specifying the simple name of the desired field.
 209.631 -     *
 209.632 -     * <p> The field to be reflected is determined by the algorithm that
 209.633 -     * follows.  Let C be the class represented by this object:
 209.634 -     * <OL>
 209.635 -     * <LI> If C declares a public field with the name specified, that is the
 209.636 -     *      field to be reflected.</LI>
 209.637 -     * <LI> If no field was found in step 1 above, this algorithm is applied
 209.638 -     *      recursively to each direct superinterface of C. The direct
 209.639 -     *      superinterfaces are searched in the order they were declared.</LI>
 209.640 -     * <LI> If no field was found in steps 1 and 2 above, and C has a
 209.641 -     *      superclass S, then this algorithm is invoked recursively upon S.
 209.642 -     *      If C has no superclass, then a {@code NoSuchFieldException}
 209.643 -     *      is thrown.</LI>
 209.644 -     * </OL>
 209.645 -     *
 209.646 -     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
 209.647 -     *
 209.648 -     * @param name the field name
 209.649 -     * @return  the {@code Field} object of this class specified by
 209.650 -     * {@code name}
 209.651 -     * @exception NoSuchFieldException if a field with the specified name is
 209.652 -     *              not found.
 209.653 -     * @exception NullPointerException if {@code name} is {@code null}
 209.654 -     * @exception  SecurityException
 209.655 -     *             If a security manager, <i>s</i>, is present and any of the
 209.656 -     *             following conditions is met:
 209.657 -     *
 209.658 -     *             <ul>
 209.659 -     *
 209.660 -     *             <li> invocation of
 209.661 -     *             {@link SecurityManager#checkMemberAccess
 209.662 -     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 209.663 -     *             access to the field
 209.664 -     *
 209.665 -     *             <li> the caller's class loader is not the same as or an
 209.666 -     *             ancestor of the class loader for the current class and
 209.667 -     *             invocation of {@link SecurityManager#checkPackageAccess
 209.668 -     *             s.checkPackageAccess()} denies access to the package
 209.669 -     *             of this class
 209.670 -     *
 209.671 -     *             </ul>
 209.672 -     *
 209.673 -     * @since JDK1.1
 209.674 -     */
 209.675 -    public Field getField(String name)
 209.676 -        throws SecurityException {
 209.677 -        throw new SecurityException();
 209.678 -    }
 209.679 -    
 209.680 -    
 209.681 -    /**
 209.682 -     * Returns a {@code Method} object that reflects the specified public
 209.683 -     * member method of the class or interface represented by this
 209.684 -     * {@code Class} object. The {@code name} parameter is a
 209.685 -     * {@code String} specifying the simple name of the desired method. The
 209.686 -     * {@code parameterTypes} parameter is an array of {@code Class}
 209.687 -     * objects that identify the method's formal parameter types, in declared
 209.688 -     * order. If {@code parameterTypes} is {@code null}, it is
 209.689 -     * treated as if it were an empty array.
 209.690 -     *
 209.691 -     * <p> If the {@code name} is "{@code <init>};"or "{@code <clinit>}" a
 209.692 -     * {@code NoSuchMethodException} is raised. Otherwise, the method to
 209.693 -     * be reflected is determined by the algorithm that follows.  Let C be the
 209.694 -     * class represented by this object:
 209.695 -     * <OL>
 209.696 -     * <LI> C is searched for any <I>matching methods</I>. If no matching
 209.697 -     *      method is found, the algorithm of step 1 is invoked recursively on
 209.698 -     *      the superclass of C.</LI>
 209.699 -     * <LI> If no method was found in step 1 above, the superinterfaces of C
 209.700 -     *      are searched for a matching method. If any such method is found, it
 209.701 -     *      is reflected.</LI>
 209.702 -     * </OL>
 209.703 -     *
 209.704 -     * To find a matching method in a class C:&nbsp; If C declares exactly one
 209.705 -     * public method with the specified name and exactly the same formal
 209.706 -     * parameter types, that is the method reflected. If more than one such
 209.707 -     * method is found in C, and one of these methods has a return type that is
 209.708 -     * more specific than any of the others, that method is reflected;
 209.709 -     * otherwise one of the methods is chosen arbitrarily.
 209.710 -     *
 209.711 -     * <p>Note that there may be more than one matching method in a
 209.712 -     * class because while the Java language forbids a class to
 209.713 -     * declare multiple methods with the same signature but different
 209.714 -     * return types, the Java virtual machine does not.  This
 209.715 -     * increased flexibility in the virtual machine can be used to
 209.716 -     * implement various language features.  For example, covariant
 209.717 -     * returns can be implemented with {@linkplain
 209.718 -     * java.lang.reflect.Method#isBridge bridge methods}; the bridge
 209.719 -     * method and the method being overridden would have the same
 209.720 -     * signature but different return types.
 209.721 -     *
 209.722 -     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
 209.723 -     *
 209.724 -     * @param name the name of the method
 209.725 -     * @param parameterTypes the list of parameters
 209.726 -     * @return the {@code Method} object that matches the specified
 209.727 -     * {@code name} and {@code parameterTypes}
 209.728 -     * @exception NoSuchMethodException if a matching method is not found
 209.729 -     *            or if the name is "&lt;init&gt;"or "&lt;clinit&gt;".
 209.730 -     * @exception NullPointerException if {@code name} is {@code null}
 209.731 -     * @exception  SecurityException
 209.732 -     *             If a security manager, <i>s</i>, is present and any of the
 209.733 -     *             following conditions is met:
 209.734 -     *
 209.735 -     *             <ul>
 209.736 -     *
 209.737 -     *             <li> invocation of
 209.738 -     *             {@link SecurityManager#checkMemberAccess
 209.739 -     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 209.740 -     *             access to the method
 209.741 -     *
 209.742 -     *             <li> the caller's class loader is not the same as or an
 209.743 -     *             ancestor of the class loader for the current class and
 209.744 -     *             invocation of {@link SecurityManager#checkPackageAccess
 209.745 -     *             s.checkPackageAccess()} denies access to the package
 209.746 -     *             of this class
 209.747 -     *
 209.748 -     *             </ul>
 209.749 -     *
 209.750 -     * @since JDK1.1
 209.751 -     */
 209.752 -    public Method getMethod(String name, Class<?>... parameterTypes)
 209.753 -        throws SecurityException {
 209.754 -        Method m = Method.findMethod(this, name, parameterTypes);
 209.755 -        if (m == null) {
 209.756 -            throw new SecurityException(); // XXX: NoSuchMethodException
 209.757 -        }
 209.758 -        return m;
 209.759 -    }
 209.760 -
 209.761 -    /**
 209.762 -     * Character.isDigit answers {@code true} to some non-ascii
 209.763 -     * digits.  This one does not.
 209.764 -     */
 209.765 -    private static boolean isAsciiDigit(char c) {
 209.766 -        return '0' <= c && c <= '9';
 209.767 -    }
 209.768 -
 209.769 -    /**
 209.770 -     * Returns the canonical name of the underlying class as
 209.771 -     * defined by the Java Language Specification.  Returns null if
 209.772 -     * the underlying class does not have a canonical name (i.e., if
 209.773 -     * it is a local or anonymous class or an array whose component
 209.774 -     * type does not have a canonical name).
 209.775 -     * @return the canonical name of the underlying class if it exists, and
 209.776 -     * {@code null} otherwise.
 209.777 -     * @since 1.5
 209.778 -     */
 209.779 -    public String getCanonicalName() {
 209.780 -        if (isArray()) {
 209.781 -            String canonicalName = getComponentType().getCanonicalName();
 209.782 -            if (canonicalName != null)
 209.783 -                return canonicalName + "[]";
 209.784 -            else
 209.785 -                return null;
 209.786 -        }
 209.787 -//        if (isLocalOrAnonymousClass())
 209.788 -//            return null;
 209.789 -//        Class<?> enclosingClass = getEnclosingClass();
 209.790 -        Class<?> enclosingClass = null;
 209.791 -        if (enclosingClass == null) { // top level class
 209.792 -            return getName();
 209.793 -        } else {
 209.794 -            String enclosingName = enclosingClass.getCanonicalName();
 209.795 -            if (enclosingName == null)
 209.796 -                return null;
 209.797 -            return enclosingName + "." + getSimpleName();
 209.798 -        }
 209.799 -    }
 209.800 -
 209.801 -    /**
 209.802 -     * Finds a resource with a given name.  The rules for searching resources
 209.803 -     * associated with a given class are implemented by the defining
 209.804 -     * {@linkplain ClassLoader class loader} of the class.  This method
 209.805 -     * delegates to this object's class loader.  If this object was loaded by
 209.806 -     * the bootstrap class loader, the method delegates to {@link
 209.807 -     * ClassLoader#getSystemResourceAsStream}.
 209.808 -     *
 209.809 -     * <p> Before delegation, an absolute resource name is constructed from the
 209.810 -     * given resource name using this algorithm:
 209.811 -     *
 209.812 -     * <ul>
 209.813 -     *
 209.814 -     * <li> If the {@code name} begins with a {@code '/'}
 209.815 -     * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
 209.816 -     * portion of the {@code name} following the {@code '/'}.
 209.817 -     *
 209.818 -     * <li> Otherwise, the absolute name is of the following form:
 209.819 -     *
 209.820 -     * <blockquote>
 209.821 -     *   {@code modified_package_name/name}
 209.822 -     * </blockquote>
 209.823 -     *
 209.824 -     * <p> Where the {@code modified_package_name} is the package name of this
 209.825 -     * object with {@code '/'} substituted for {@code '.'}
 209.826 -     * (<tt>'&#92;u002e'</tt>).
 209.827 -     *
 209.828 -     * </ul>
 209.829 -     *
 209.830 -     * @param  name name of the desired resource
 209.831 -     * @return      A {@link java.io.InputStream} object or {@code null} if
 209.832 -     *              no resource with this name is found
 209.833 -     * @throws  NullPointerException If {@code name} is {@code null}
 209.834 -     * @since  JDK1.1
 209.835 -     */
 209.836 -     public InputStream getResourceAsStream(String name) {
 209.837 -        name = resolveName(name);
 209.838 -        ClassLoader cl = getClassLoader0();
 209.839 -        if (cl==null) {
 209.840 -            // A system class.
 209.841 -            return ClassLoader.getSystemResourceAsStream(name);
 209.842 -        }
 209.843 -        return cl.getResourceAsStream(name);
 209.844 -    }
 209.845 -
 209.846 -    /**
 209.847 -     * Finds a resource with a given name.  The rules for searching resources
 209.848 -     * associated with a given class are implemented by the defining
 209.849 -     * {@linkplain ClassLoader class loader} of the class.  This method
 209.850 -     * delegates to this object's class loader.  If this object was loaded by
 209.851 -     * the bootstrap class loader, the method delegates to {@link
 209.852 -     * ClassLoader#getSystemResource}.
 209.853 -     *
 209.854 -     * <p> Before delegation, an absolute resource name is constructed from the
 209.855 -     * given resource name using this algorithm:
 209.856 -     *
 209.857 -     * <ul>
 209.858 -     *
 209.859 -     * <li> If the {@code name} begins with a {@code '/'}
 209.860 -     * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
 209.861 -     * portion of the {@code name} following the {@code '/'}.
 209.862 -     *
 209.863 -     * <li> Otherwise, the absolute name is of the following form:
 209.864 -     *
 209.865 -     * <blockquote>
 209.866 -     *   {@code modified_package_name/name}
 209.867 -     * </blockquote>
 209.868 -     *
 209.869 -     * <p> Where the {@code modified_package_name} is the package name of this
 209.870 -     * object with {@code '/'} substituted for {@code '.'}
 209.871 -     * (<tt>'&#92;u002e'</tt>).
 209.872 -     *
 209.873 -     * </ul>
 209.874 -     *
 209.875 -     * @param  name name of the desired resource
 209.876 -     * @return      A  {@link java.net.URL} object or {@code null} if no
 209.877 -     *              resource with this name is found
 209.878 -     * @since  JDK1.1
 209.879 -     */
 209.880 -    public java.net.URL getResource(String name) {
 209.881 -        name = resolveName(name);
 209.882 -        ClassLoader cl = getClassLoader0();
 209.883 -        if (cl==null) {
 209.884 -            // A system class.
 209.885 -            return ClassLoader.getSystemResource(name);
 209.886 -        }
 209.887 -        return cl.getResource(name);
 209.888 -    }
 209.889 -
 209.890 -
 209.891 -   /**
 209.892 -     * Add a package name prefix if the name is not absolute Remove leading "/"
 209.893 -     * if name is absolute
 209.894 -     */
 209.895 -    private String resolveName(String name) {
 209.896 -        if (name == null) {
 209.897 -            return name;
 209.898 -        }
 209.899 -        if (!name.startsWith("/")) {
 209.900 -            Class<?> c = this;
 209.901 -            while (c.isArray()) {
 209.902 -                c = c.getComponentType();
 209.903 -            }
 209.904 -            String baseName = c.getName();
 209.905 -            int index = baseName.lastIndexOf('.');
 209.906 -            if (index != -1) {
 209.907 -                name = baseName.substring(0, index).replace('.', '/')
 209.908 -                    +"/"+name;
 209.909 -            }
 209.910 -        } else {
 209.911 -            name = name.substring(1);
 209.912 -        }
 209.913 -        return name;
 209.914 -    }
 209.915 -    
 209.916 -    /**
 209.917 -     * Returns the class loader for the class.  Some implementations may use
 209.918 -     * null to represent the bootstrap class loader. This method will return
 209.919 -     * null in such implementations if this class was loaded by the bootstrap
 209.920 -     * class loader.
 209.921 -     *
 209.922 -     * <p> If a security manager is present, and the caller's class loader is
 209.923 -     * not null and the caller's class loader is not the same as or an ancestor of
 209.924 -     * the class loader for the class whose class loader is requested, then
 209.925 -     * this method calls the security manager's {@code checkPermission}
 209.926 -     * method with a {@code RuntimePermission("getClassLoader")}
 209.927 -     * permission to ensure it's ok to access the class loader for the class.
 209.928 -     *
 209.929 -     * <p>If this object
 209.930 -     * represents a primitive type or void, null is returned.
 209.931 -     *
 209.932 -     * @return  the class loader that loaded the class or interface
 209.933 -     *          represented by this object.
 209.934 -     * @throws SecurityException
 209.935 -     *    if a security manager exists and its
 209.936 -     *    {@code checkPermission} method denies
 209.937 -     *    access to the class loader for the class.
 209.938 -     * @see java.lang.ClassLoader
 209.939 -     * @see SecurityManager#checkPermission
 209.940 -     * @see java.lang.RuntimePermission
 209.941 -     */
 209.942 -    public ClassLoader getClassLoader() {
 209.943 -        throw new SecurityException();
 209.944 -    }
 209.945 -    
 209.946 -    // Package-private to allow ClassLoader access
 209.947 -    native ClassLoader getClassLoader0();    
 209.948 -
 209.949 -    /**
 209.950 -     * Returns the {@code Class} representing the component type of an
 209.951 -     * array.  If this class does not represent an array class this method
 209.952 -     * returns null.
 209.953 -     *
 209.954 -     * @return the {@code Class} representing the component type of this
 209.955 -     * class if this class is an array
 209.956 -     * @see     java.lang.reflect.Array
 209.957 -     * @since JDK1.1
 209.958 -     */
 209.959 -    public Class<?> getComponentType() {
 209.960 -        return null;
 209.961 -    }
 209.962 -
 209.963 -    /**
 209.964 -     * Returns true if and only if this class was declared as an enum in the
 209.965 -     * source code.
 209.966 -     *
 209.967 -     * @return true if and only if this class was declared as an enum in the
 209.968 -     *     source code
 209.969 -     * @since 1.5
 209.970 -     */
 209.971 -    public boolean isEnum() {
 209.972 -        // An enum must both directly extend java.lang.Enum and have
 209.973 -        // the ENUM bit set; classes for specialized enum constants
 209.974 -        // don't do the former.
 209.975 -        return (this.getModifiers() & ENUM) != 0 &&
 209.976 -        this.getSuperclass() == java.lang.Enum.class;
 209.977 -    }
 209.978 -
 209.979 -    /**
 209.980 -     * Casts an object to the class or interface represented
 209.981 -     * by this {@code Class} object.
 209.982 -     *
 209.983 -     * @param obj the object to be cast
 209.984 -     * @return the object after casting, or null if obj is null
 209.985 -     *
 209.986 -     * @throws ClassCastException if the object is not
 209.987 -     * null and is not assignable to the type T.
 209.988 -     *
 209.989 -     * @since 1.5
 209.990 -     */
 209.991 -    public T cast(Object obj) {
 209.992 -        if (obj != null && !isInstance(obj))
 209.993 -            throw new ClassCastException(cannotCastMsg(obj));
 209.994 -        return (T) obj;
 209.995 -    }
 209.996 -
 209.997 -    private String cannotCastMsg(Object obj) {
 209.998 -        return "Cannot cast " + obj.getClass().getName() + " to " + getName();
 209.999 -    }
209.1000 -
209.1001 -    /**
209.1002 -     * Casts this {@code Class} object to represent a subclass of the class
209.1003 -     * represented by the specified class object.  Checks that that the cast
209.1004 -     * is valid, and throws a {@code ClassCastException} if it is not.  If
209.1005 -     * this method succeeds, it always returns a reference to this class object.
209.1006 -     *
209.1007 -     * <p>This method is useful when a client needs to "narrow" the type of
209.1008 -     * a {@code Class} object to pass it to an API that restricts the
209.1009 -     * {@code Class} objects that it is willing to accept.  A cast would
209.1010 -     * generate a compile-time warning, as the correctness of the cast
209.1011 -     * could not be checked at runtime (because generic types are implemented
209.1012 -     * by erasure).
209.1013 -     *
209.1014 -     * @return this {@code Class} object, cast to represent a subclass of
209.1015 -     *    the specified class object.
209.1016 -     * @throws ClassCastException if this {@code Class} object does not
209.1017 -     *    represent a subclass of the specified class (here "subclass" includes
209.1018 -     *    the class itself).
209.1019 -     * @since 1.5
209.1020 -     */
209.1021 -    public <U> Class<? extends U> asSubclass(Class<U> clazz) {
209.1022 -        if (clazz.isAssignableFrom(this))
209.1023 -            return (Class<? extends U>) this;
209.1024 -        else
209.1025 -            throw new ClassCastException(this.toString());
209.1026 -    }
209.1027 -
209.1028 -    @JavaScriptBody(args = { "self", "ac" }, 
209.1029 -        body = 
209.1030 -          "if (self.anno) {"
209.1031 -        + "  return self.anno['L' + ac.jvmName + ';'];"
209.1032 -        + "} else return null;"
209.1033 -    )
209.1034 -    private Object getAnnotationData(Class<?> annotationClass) {
209.1035 -        throw new UnsupportedOperationException();
209.1036 -    }
209.1037 -    /**
209.1038 -     * @throws NullPointerException {@inheritDoc}
209.1039 -     * @since 1.5
209.1040 -     */
209.1041 -    public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
209.1042 -        Object data = getAnnotationData(annotationClass);
209.1043 -        return data == null ? null : AnnotationImpl.create(annotationClass, data);
209.1044 -    }
209.1045 -
209.1046 -    /**
209.1047 -     * @throws NullPointerException {@inheritDoc}
209.1048 -     * @since 1.5
209.1049 -     */
209.1050 -    @JavaScriptBody(args = { "self", "ac" }, 
209.1051 -        body = "if (self.anno && self.anno['L' + ac.jvmName + ';']) { return true; }"
209.1052 -        + "else return false;"
209.1053 -    )
209.1054 -    public boolean isAnnotationPresent(
209.1055 -        Class<? extends Annotation> annotationClass) {
209.1056 -        if (annotationClass == null)
209.1057 -            throw new NullPointerException();
209.1058 -
209.1059 -        return getAnnotation(annotationClass) != null;
209.1060 -    }
209.1061 -
209.1062 -    @JavaScriptBody(args = "self", body = "return self.anno;")
209.1063 -    private Object getAnnotationData() {
209.1064 -        throw new UnsupportedOperationException();
209.1065 -    }
209.1066 -
209.1067 -    /**
209.1068 -     * @since 1.5
209.1069 -     */
209.1070 -    public Annotation[] getAnnotations() {
209.1071 -        Object data = getAnnotationData();
209.1072 -        return data == null ? new Annotation[0] : AnnotationImpl.create(data);
209.1073 -    }
209.1074 -
209.1075 -    /**
209.1076 -     * @since 1.5
209.1077 -     */
209.1078 -    public Annotation[] getDeclaredAnnotations()  {
209.1079 -        throw new UnsupportedOperationException();
209.1080 -    }
209.1081 -
209.1082 -    static Class getPrimitiveClass(String type) {
209.1083 -        // XXX
209.1084 -        return Object.class;
209.1085 -    }
209.1086 -
209.1087 -    public boolean desiredAssertionStatus() {
209.1088 -        return false;
209.1089 -    }
209.1090 -}
   210.1 --- a/emul/src/main/java/java/lang/ClassCastException.java	Wed Dec 05 10:03:58 2012 +0100
   210.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   210.3 @@ -1,60 +0,0 @@
   210.4 -/*
   210.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   210.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   210.7 - *
   210.8 - * This code is free software; you can redistribute it and/or modify it
   210.9 - * under the terms of the GNU General Public License version 2 only, as
  210.10 - * published by the Free Software Foundation.  Oracle designates this
  210.11 - * particular file as subject to the "Classpath" exception as provided
  210.12 - * by Oracle in the LICENSE file that accompanied this code.
  210.13 - *
  210.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  210.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  210.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  210.17 - * version 2 for more details (a copy is included in the LICENSE file that
  210.18 - * accompanied this code).
  210.19 - *
  210.20 - * You should have received a copy of the GNU General Public License version
  210.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  210.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  210.23 - *
  210.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  210.25 - * or visit www.oracle.com if you need additional information or have any
  210.26 - * questions.
  210.27 - */
  210.28 -
  210.29 -package java.lang;
  210.30 -
  210.31 -/**
  210.32 - * Thrown to indicate that the code has attempted to cast an object
  210.33 - * to a subclass of which it is not an instance. For example, the
  210.34 - * following code generates a <code>ClassCastException</code>:
  210.35 - * <p><blockquote><pre>
  210.36 - *     Object x = new Integer(0);
  210.37 - *     System.out.println((String)x);
  210.38 - * </pre></blockquote>
  210.39 - *
  210.40 - * @author  unascribed
  210.41 - * @since   JDK1.0
  210.42 - */
  210.43 -public
  210.44 -class ClassCastException extends RuntimeException {
  210.45 -    private static final long serialVersionUID = -9223365651070458532L;
  210.46 -
  210.47 -    /**
  210.48 -     * Constructs a <code>ClassCastException</code> with no detail message.
  210.49 -     */
  210.50 -    public ClassCastException() {
  210.51 -        super();
  210.52 -    }
  210.53 -
  210.54 -    /**
  210.55 -     * Constructs a <code>ClassCastException</code> with the specified
  210.56 -     * detail message.
  210.57 -     *
  210.58 -     * @param   s   the detail message.
  210.59 -     */
  210.60 -    public ClassCastException(String s) {
  210.61 -        super(s);
  210.62 -    }
  210.63 -}
   211.1 --- a/emul/src/main/java/java/lang/ClassFormatError.java	Wed Dec 05 10:03:58 2012 +0100
   211.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   211.3 @@ -1,56 +0,0 @@
   211.4 -/*
   211.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   211.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   211.7 - *
   211.8 - * This code is free software; you can redistribute it and/or modify it
   211.9 - * under the terms of the GNU General Public License version 2 only, as
  211.10 - * published by the Free Software Foundation.  Oracle designates this
  211.11 - * particular file as subject to the "Classpath" exception as provided
  211.12 - * by Oracle in the LICENSE file that accompanied this code.
  211.13 - *
  211.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  211.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  211.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  211.17 - * version 2 for more details (a copy is included in the LICENSE file that
  211.18 - * accompanied this code).
  211.19 - *
  211.20 - * You should have received a copy of the GNU General Public License version
  211.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  211.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  211.23 - *
  211.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  211.25 - * or visit www.oracle.com if you need additional information or have any
  211.26 - * questions.
  211.27 - */
  211.28 -
  211.29 -package java.lang;
  211.30 -
  211.31 -/**
  211.32 - * Thrown when the Java Virtual Machine attempts to read a class
  211.33 - * file and determines that the file is malformed or otherwise cannot
  211.34 - * be interpreted as a class file.
  211.35 - *
  211.36 - * @author  unascribed
  211.37 - * @since   JDK1.0
  211.38 - */
  211.39 -public
  211.40 -class ClassFormatError extends LinkageError {
  211.41 -    private static final long serialVersionUID = -8420114879011949195L;
  211.42 -
  211.43 -    /**
  211.44 -     * Constructs a <code>ClassFormatError</code> with no detail message.
  211.45 -     */
  211.46 -    public ClassFormatError() {
  211.47 -        super();
  211.48 -    }
  211.49 -
  211.50 -    /**
  211.51 -     * Constructs a <code>ClassFormatError</code> with the specified
  211.52 -     * detail message.
  211.53 -     *
  211.54 -     * @param   s   the detail message.
  211.55 -     */
  211.56 -    public ClassFormatError(String s) {
  211.57 -        super(s);
  211.58 -    }
  211.59 -}
   212.1 --- a/emul/src/main/java/java/lang/ClassLoader.java	Wed Dec 05 10:03:58 2012 +0100
   212.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   212.3 @@ -1,914 +0,0 @@
   212.4 -/*
   212.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   212.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   212.7 - *
   212.8 - * This code is free software; you can redistribute it and/or modify it
   212.9 - * under the terms of the GNU General Public License version 2 only, as
  212.10 - * published by the Free Software Foundation.  Oracle designates this
  212.11 - * particular file as subject to the "Classpath" exception as provided
  212.12 - * by Oracle in the LICENSE file that accompanied this code.
  212.13 - *
  212.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  212.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  212.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  212.17 - * version 2 for more details (a copy is included in the LICENSE file that
  212.18 - * accompanied this code).
  212.19 - *
  212.20 - * You should have received a copy of the GNU General Public License version
  212.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  212.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  212.23 - *
  212.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  212.25 - * or visit www.oracle.com if you need additional information or have any
  212.26 - * questions.
  212.27 - */
  212.28 -package java.lang;
  212.29 -
  212.30 -import java.io.InputStream;
  212.31 -import java.io.IOException;
  212.32 -import java.net.URL;
  212.33 -import java.util.Enumeration;
  212.34 -import java.util.NoSuchElementException;
  212.35 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  212.36 -
  212.37 -/**
  212.38 - * A class loader is an object that is responsible for loading classes. The
  212.39 - * class <tt>ClassLoader</tt> is an abstract class.  Given the <a
  212.40 - * href="#name">binary name</a> of a class, a class loader should attempt to
  212.41 - * locate or generate data that constitutes a definition for the class.  A
  212.42 - * typical strategy is to transform the name into a file name and then read a
  212.43 - * "class file" of that name from a file system.
  212.44 - *
  212.45 - * <p> Every {@link Class <tt>Class</tt>} object contains a {@link
  212.46 - * Class#getClassLoader() reference} to the <tt>ClassLoader</tt> that defined
  212.47 - * it.
  212.48 - *
  212.49 - * <p> <tt>Class</tt> objects for array classes are not created by class
  212.50 - * loaders, but are created automatically as required by the Java runtime.
  212.51 - * The class loader for an array class, as returned by {@link
  212.52 - * Class#getClassLoader()} is the same as the class loader for its element
  212.53 - * type; if the element type is a primitive type, then the array class has no
  212.54 - * class loader.
  212.55 - *
  212.56 - * <p> Applications implement subclasses of <tt>ClassLoader</tt> in order to
  212.57 - * extend the manner in which the Java virtual machine dynamically loads
  212.58 - * classes.
  212.59 - *
  212.60 - * <p> Class loaders may typically be used by security managers to indicate
  212.61 - * security domains.
  212.62 - *
  212.63 - * <p> The <tt>ClassLoader</tt> class uses a delegation model to search for
  212.64 - * classes and resources.  Each instance of <tt>ClassLoader</tt> has an
  212.65 - * associated parent class loader.  When requested to find a class or
  212.66 - * resource, a <tt>ClassLoader</tt> instance will delegate the search for the
  212.67 - * class or resource to its parent class loader before attempting to find the
  212.68 - * class or resource itself.  The virtual machine's built-in class loader,
  212.69 - * called the "bootstrap class loader", does not itself have a parent but may
  212.70 - * serve as the parent of a <tt>ClassLoader</tt> instance.
  212.71 - *
  212.72 - * <p> Class loaders that support concurrent loading of classes are known as
  212.73 - * <em>parallel capable</em> class loaders and are required to register
  212.74 - * themselves at their class initialization time by invoking the
  212.75 - * {@link
  212.76 - * #registerAsParallelCapable <tt>ClassLoader.registerAsParallelCapable</tt>}
  212.77 - * method. Note that the <tt>ClassLoader</tt> class is registered as parallel
  212.78 - * capable by default. However, its subclasses still need to register themselves
  212.79 - * if they are parallel capable. <br>
  212.80 - * In environments in which the delegation model is not strictly
  212.81 - * hierarchical, class loaders need to be parallel capable, otherwise class
  212.82 - * loading can lead to deadlocks because the loader lock is held for the
  212.83 - * duration of the class loading process (see {@link #loadClass
  212.84 - * <tt>loadClass</tt>} methods).
  212.85 - *
  212.86 - * <p> Normally, the Java virtual machine loads classes from the local file
  212.87 - * system in a platform-dependent manner.  For example, on UNIX systems, the
  212.88 - * virtual machine loads classes from the directory defined by the
  212.89 - * <tt>CLASSPATH</tt> environment variable.
  212.90 - *
  212.91 - * <p> However, some classes may not originate from a file; they may originate
  212.92 - * from other sources, such as the network, or they could be constructed by an
  212.93 - * application.  The method {@link #defineClass(String, byte[], int, int)
  212.94 - * <tt>defineClass</tt>} converts an array of bytes into an instance of class
  212.95 - * <tt>Class</tt>. Instances of this newly defined class can be created using
  212.96 - * {@link Class#newInstance <tt>Class.newInstance</tt>}.
  212.97 - *
  212.98 - * <p> The methods and constructors of objects created by a class loader may
  212.99 - * reference other classes.  To determine the class(es) referred to, the Java
 212.100 - * virtual machine invokes the {@link #loadClass <tt>loadClass</tt>} method of
 212.101 - * the class loader that originally created the class.
 212.102 - *
 212.103 - * <p> For example, an application could create a network class loader to
 212.104 - * download class files from a server.  Sample code might look like:
 212.105 - *
 212.106 - * <blockquote><pre>
 212.107 - *   ClassLoader loader&nbsp;= new NetworkClassLoader(host,&nbsp;port);
 212.108 - *   Object main&nbsp;= loader.loadClass("Main", true).newInstance();
 212.109 - *       &nbsp;.&nbsp;.&nbsp;.
 212.110 - * </pre></blockquote>
 212.111 - *
 212.112 - * <p> The network class loader subclass must define the methods {@link
 212.113 - * #findClass <tt>findClass</tt>} and <tt>loadClassData</tt> to load a class
 212.114 - * from the network.  Once it has downloaded the bytes that make up the class,
 212.115 - * it should use the method {@link #defineClass <tt>defineClass</tt>} to
 212.116 - * create a class instance.  A sample implementation is:
 212.117 - *
 212.118 - * <blockquote><pre>
 212.119 - *     class NetworkClassLoader extends ClassLoader {
 212.120 - *         String host;
 212.121 - *         int port;
 212.122 - *
 212.123 - *         public Class findClass(String name) {
 212.124 - *             byte[] b = loadClassData(name);
 212.125 - *             return defineClass(name, b, 0, b.length);
 212.126 - *         }
 212.127 - *
 212.128 - *         private byte[] loadClassData(String name) {
 212.129 - *             // load the class data from the connection
 212.130 - *             &nbsp;.&nbsp;.&nbsp;.
 212.131 - *         }
 212.132 - *     }
 212.133 - * </pre></blockquote>
 212.134 - *
 212.135 - * <h4> <a name="name">Binary names</a> </h4>
 212.136 - *
 212.137 - * <p> Any class name provided as a {@link String} parameter to methods in
 212.138 - * <tt>ClassLoader</tt> must be a binary name as defined by
 212.139 - * <cite>The Java&trade; Language Specification</cite>.
 212.140 - *
 212.141 - * <p> Examples of valid class names include:
 212.142 - * <blockquote><pre>
 212.143 - *   "java.lang.String"
 212.144 - *   "javax.swing.JSpinner$DefaultEditor"
 212.145 - *   "java.security.KeyStore$Builder$FileBuilder$1"
 212.146 - *   "java.net.URLClassLoader$3$1"
 212.147 - * </pre></blockquote>
 212.148 - *
 212.149 - * @see      #resolveClass(Class)
 212.150 - * @since 1.0
 212.151 - */
 212.152 -public abstract class ClassLoader {
 212.153 -
 212.154 -    @JavaScriptBody(args = {}, body = "")
 212.155 -    private static native void registerNatives();
 212.156 -    static {
 212.157 -        registerNatives();
 212.158 -    }
 212.159 -
 212.160 -    // The parent class loader for delegation
 212.161 -    // Note: VM hardcoded the offset of this field, thus all new fields
 212.162 -    // must be added *after* it.
 212.163 -    private final ClassLoader parent;
 212.164 -
 212.165 -
 212.166 -    /**
 212.167 -     * Creates a new class loader using the specified parent class loader for
 212.168 -     * delegation.
 212.169 -     *
 212.170 -     * <p> If there is a security manager, its {@link
 212.171 -     * SecurityManager#checkCreateClassLoader()
 212.172 -     * <tt>checkCreateClassLoader</tt>} method is invoked.  This may result in
 212.173 -     * a security exception.  </p>
 212.174 -     *
 212.175 -     * @param  parent
 212.176 -     *         The parent class loader
 212.177 -     *
 212.178 -     * @throws  SecurityException
 212.179 -     *          If a security manager exists and its
 212.180 -     *          <tt>checkCreateClassLoader</tt> method doesn't allow creation
 212.181 -     *          of a new class loader.
 212.182 -     *
 212.183 -     * @since  1.2
 212.184 -     */
 212.185 -    protected ClassLoader(ClassLoader parent) {
 212.186 -        throw new SecurityException();
 212.187 -    }
 212.188 -
 212.189 -    /**
 212.190 -     * Creates a new class loader using the <tt>ClassLoader</tt> returned by
 212.191 -     * the method {@link #getSystemClassLoader()
 212.192 -     * <tt>getSystemClassLoader()</tt>} as the parent class loader.
 212.193 -     *
 212.194 -     * <p> If there is a security manager, its {@link
 212.195 -     * SecurityManager#checkCreateClassLoader()
 212.196 -     * <tt>checkCreateClassLoader</tt>} method is invoked.  This may result in
 212.197 -     * a security exception.  </p>
 212.198 -     *
 212.199 -     * @throws  SecurityException
 212.200 -     *          If a security manager exists and its
 212.201 -     *          <tt>checkCreateClassLoader</tt> method doesn't allow creation
 212.202 -     *          of a new class loader.
 212.203 -     */
 212.204 -    protected ClassLoader() {
 212.205 -        throw new SecurityException();
 212.206 -    }
 212.207 -
 212.208 -    // -- Class --
 212.209 -
 212.210 -    /**
 212.211 -     * Loads the class with the specified <a href="#name">binary name</a>.
 212.212 -     * This method searches for classes in the same manner as the {@link
 212.213 -     * #loadClass(String, boolean)} method.  It is invoked by the Java virtual
 212.214 -     * machine to resolve class references.  Invoking this method is equivalent
 212.215 -     * to invoking {@link #loadClass(String, boolean) <tt>loadClass(name,
 212.216 -     * false)</tt>}.  </p>
 212.217 -     *
 212.218 -     * @param  name
 212.219 -     *         The <a href="#name">binary name</a> of the class
 212.220 -     *
 212.221 -     * @return  The resulting <tt>Class</tt> object
 212.222 -     *
 212.223 -     * @throws  ClassNotFoundException
 212.224 -     *          If the class was not found
 212.225 -     */
 212.226 -    public Class<?> loadClass(String name) throws ClassNotFoundException {
 212.227 -        return loadClass(name, false);
 212.228 -    }
 212.229 -
 212.230 -    /**
 212.231 -     * Loads the class with the specified <a href="#name">binary name</a>.  The
 212.232 -     * default implementation of this method searches for classes in the
 212.233 -     * following order:
 212.234 -     *
 212.235 -     * <p><ol>
 212.236 -     *
 212.237 -     *   <li><p> Invoke {@link #findLoadedClass(String)} to check if the class
 212.238 -     *   has already been loaded.  </p></li>
 212.239 -     *
 212.240 -     *   <li><p> Invoke the {@link #loadClass(String) <tt>loadClass</tt>} method
 212.241 -     *   on the parent class loader.  If the parent is <tt>null</tt> the class
 212.242 -     *   loader built-in to the virtual machine is used, instead.  </p></li>
 212.243 -     *
 212.244 -     *   <li><p> Invoke the {@link #findClass(String)} method to find the
 212.245 -     *   class.  </p></li>
 212.246 -     *
 212.247 -     * </ol>
 212.248 -     *
 212.249 -     * <p> If the class was found using the above steps, and the
 212.250 -     * <tt>resolve</tt> flag is true, this method will then invoke the {@link
 212.251 -     * #resolveClass(Class)} method on the resulting <tt>Class</tt> object.
 212.252 -     *
 212.253 -     * <p> Subclasses of <tt>ClassLoader</tt> are encouraged to override {@link
 212.254 -     * #findClass(String)}, rather than this method.  </p>
 212.255 -     *
 212.256 -     * <p> Unless overridden, this method synchronizes on the result of
 212.257 -     * {@link #getClassLoadingLock <tt>getClassLoadingLock</tt>} method
 212.258 -     * during the entire class loading process.
 212.259 -     *
 212.260 -     * @param  name
 212.261 -     *         The <a href="#name">binary name</a> of the class
 212.262 -     *
 212.263 -     * @param  resolve
 212.264 -     *         If <tt>true</tt> then resolve the class
 212.265 -     *
 212.266 -     * @return  The resulting <tt>Class</tt> object
 212.267 -     *
 212.268 -     * @throws  ClassNotFoundException
 212.269 -     *          If the class could not be found
 212.270 -     */
 212.271 -    protected Class<?> loadClass(String name, boolean resolve)
 212.272 -        throws ClassNotFoundException
 212.273 -    {
 212.274 -        synchronized (getClassLoadingLock(name)) {
 212.275 -            // First, check if the class has already been loaded
 212.276 -            Class c = findLoadedClass(name);
 212.277 -            if (c == null) {
 212.278 -                try {
 212.279 -                    if (parent != null) {
 212.280 -                        c = parent.loadClass(name, false);
 212.281 -                    } else {
 212.282 -                        c = findBootstrapClassOrNull(name);
 212.283 -                    }
 212.284 -                } catch (ClassNotFoundException e) {
 212.285 -                    // ClassNotFoundException thrown if class not found
 212.286 -                    // from the non-null parent class loader
 212.287 -                }
 212.288 -
 212.289 -                if (c == null) {
 212.290 -                    // If still not found, then invoke findClass in order
 212.291 -                    // to find the class.
 212.292 -                    c = findClass(name);
 212.293 -
 212.294 -//                    // this is the defining class loader; record the stats
 212.295 -//                    sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
 212.296 -//                    sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
 212.297 -//                    sun.misc.PerfCounter.getFindClasses().increment();
 212.298 -                }
 212.299 -            }
 212.300 -            if (resolve) {
 212.301 -                resolveClass(c);
 212.302 -            }
 212.303 -            return c;
 212.304 -        }
 212.305 -    }
 212.306 -
 212.307 -    /**
 212.308 -     * Returns the lock object for class loading operations.
 212.309 -     * For backward compatibility, the default implementation of this method
 212.310 -     * behaves as follows. If this ClassLoader object is registered as
 212.311 -     * parallel capable, the method returns a dedicated object associated
 212.312 -     * with the specified class name. Otherwise, the method returns this
 212.313 -     * ClassLoader object. </p>
 212.314 -     *
 212.315 -     * @param  className
 212.316 -     *         The name of the to-be-loaded class
 212.317 -     *
 212.318 -     * @return the lock for class loading operations
 212.319 -     *
 212.320 -     * @throws NullPointerException
 212.321 -     *         If registered as parallel capable and <tt>className</tt> is null
 212.322 -     *
 212.323 -     * @see #loadClass(String, boolean)
 212.324 -     *
 212.325 -     * @since  1.7
 212.326 -     */
 212.327 -    protected Object getClassLoadingLock(String className) {
 212.328 -        Object lock = this;
 212.329 -        return lock;
 212.330 -    }
 212.331 -
 212.332 -    /**
 212.333 -     * Finds the class with the specified <a href="#name">binary name</a>.
 212.334 -     * This method should be overridden by class loader implementations that
 212.335 -     * follow the delegation model for loading classes, and will be invoked by
 212.336 -     * the {@link #loadClass <tt>loadClass</tt>} method after checking the
 212.337 -     * parent class loader for the requested class.  The default implementation
 212.338 -     * throws a <tt>ClassNotFoundException</tt>.  </p>
 212.339 -     *
 212.340 -     * @param  name
 212.341 -     *         The <a href="#name">binary name</a> of the class
 212.342 -     *
 212.343 -     * @return  The resulting <tt>Class</tt> object
 212.344 -     *
 212.345 -     * @throws  ClassNotFoundException
 212.346 -     *          If the class could not be found
 212.347 -     *
 212.348 -     * @since  1.2
 212.349 -     */
 212.350 -    protected Class<?> findClass(String name) throws ClassNotFoundException {
 212.351 -        throw new ClassNotFoundException(name);
 212.352 -    }
 212.353 -
 212.354 -    /**
 212.355 -     * Converts an array of bytes into an instance of class <tt>Class</tt>.
 212.356 -     * Before the <tt>Class</tt> can be used it must be resolved.  This method
 212.357 -     * is deprecated in favor of the version that takes a <a
 212.358 -     * href="#name">binary name</a> as its first argument, and is more secure.
 212.359 -     *
 212.360 -     * @param  b
 212.361 -     *         The bytes that make up the class data.  The bytes in positions
 212.362 -     *         <tt>off</tt> through <tt>off+len-1</tt> should have the format
 212.363 -     *         of a valid class file as defined by
 212.364 -     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
 212.365 -     *
 212.366 -     * @param  off
 212.367 -     *         The start offset in <tt>b</tt> of the class data
 212.368 -     *
 212.369 -     * @param  len
 212.370 -     *         The length of the class data
 212.371 -     *
 212.372 -     * @return  The <tt>Class</tt> object that was created from the specified
 212.373 -     *          class data
 212.374 -     *
 212.375 -     * @throws  ClassFormatError
 212.376 -     *          If the data did not contain a valid class
 212.377 -     *
 212.378 -     * @throws  IndexOutOfBoundsException
 212.379 -     *          If either <tt>off</tt> or <tt>len</tt> is negative, or if
 212.380 -     *          <tt>off+len</tt> is greater than <tt>b.length</tt>.
 212.381 -     *
 212.382 -     * @throws  SecurityException
 212.383 -     *          If an attempt is made to add this class to a package that
 212.384 -     *          contains classes that were signed by a different set of
 212.385 -     *          certificates than this class, or if an attempt is made
 212.386 -     *          to define a class in a package with a fully-qualified name
 212.387 -     *          that starts with "{@code java.}".
 212.388 -     *
 212.389 -     * @see  #loadClass(String, boolean)
 212.390 -     * @see  #resolveClass(Class)
 212.391 -     *
 212.392 -     * @deprecated  Replaced by {@link #defineClass(String, byte[], int, int)
 212.393 -     * defineClass(String, byte[], int, int)}
 212.394 -     */
 212.395 -    @Deprecated
 212.396 -    protected final Class<?> defineClass(byte[] b, int off, int len)
 212.397 -        throws ClassFormatError
 212.398 -    {
 212.399 -        throw new SecurityException();
 212.400 -    }
 212.401 -
 212.402 -    /**
 212.403 -     * Converts an array of bytes into an instance of class <tt>Class</tt>.
 212.404 -     * Before the <tt>Class</tt> can be used it must be resolved.
 212.405 -     *
 212.406 -     * <p> This method assigns a default {@link java.security.ProtectionDomain
 212.407 -     * <tt>ProtectionDomain</tt>} to the newly defined class.  The
 212.408 -     * <tt>ProtectionDomain</tt> is effectively granted the same set of
 212.409 -     * permissions returned when {@link
 212.410 -     * java.security.Policy#getPermissions(java.security.CodeSource)
 212.411 -     * <tt>Policy.getPolicy().getPermissions(new CodeSource(null, null))</tt>}
 212.412 -     * is invoked.  The default domain is created on the first invocation of
 212.413 -     * {@link #defineClass(String, byte[], int, int) <tt>defineClass</tt>},
 212.414 -     * and re-used on subsequent invocations.
 212.415 -     *
 212.416 -     * <p> To assign a specific <tt>ProtectionDomain</tt> to the class, use
 212.417 -     * the {@link #defineClass(String, byte[], int, int,
 212.418 -     * java.security.ProtectionDomain) <tt>defineClass</tt>} method that takes a
 212.419 -     * <tt>ProtectionDomain</tt> as one of its arguments.  </p>
 212.420 -     *
 212.421 -     * @param  name
 212.422 -     *         The expected <a href="#name">binary name</a> of the class, or
 212.423 -     *         <tt>null</tt> if not known
 212.424 -     *
 212.425 -     * @param  b
 212.426 -     *         The bytes that make up the class data.  The bytes in positions
 212.427 -     *         <tt>off</tt> through <tt>off+len-1</tt> should have the format
 212.428 -     *         of a valid class file as defined by
 212.429 -     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
 212.430 -     *
 212.431 -     * @param  off
 212.432 -     *         The start offset in <tt>b</tt> of the class data
 212.433 -     *
 212.434 -     * @param  len
 212.435 -     *         The length of the class data
 212.436 -     *
 212.437 -     * @return  The <tt>Class</tt> object that was created from the specified
 212.438 -     *          class data.
 212.439 -     *
 212.440 -     * @throws  ClassFormatError
 212.441 -     *          If the data did not contain a valid class
 212.442 -     *
 212.443 -     * @throws  IndexOutOfBoundsException
 212.444 -     *          If either <tt>off</tt> or <tt>len</tt> is negative, or if
 212.445 -     *          <tt>off+len</tt> is greater than <tt>b.length</tt>.
 212.446 -     *
 212.447 -     * @throws  SecurityException
 212.448 -     *          If an attempt is made to add this class to a package that
 212.449 -     *          contains classes that were signed by a different set of
 212.450 -     *          certificates than this class (which is unsigned), or if
 212.451 -     *          <tt>name</tt> begins with "<tt>java.</tt>".
 212.452 -     *
 212.453 -     * @see  #loadClass(String, boolean)
 212.454 -     * @see  #resolveClass(Class)
 212.455 -     * @see  java.security.CodeSource
 212.456 -     * @see  java.security.SecureClassLoader
 212.457 -     *
 212.458 -     * @since  1.1
 212.459 -     */
 212.460 -    protected final Class<?> defineClass(String name, byte[] b, int off, int len)
 212.461 -        throws ClassFormatError
 212.462 -    {
 212.463 -        throw new SecurityException();
 212.464 -    }
 212.465 -
 212.466 -    /**
 212.467 -     * Links the specified class.  This (misleadingly named) method may be
 212.468 -     * used by a class loader to link a class.  If the class <tt>c</tt> has
 212.469 -     * already been linked, then this method simply returns. Otherwise, the
 212.470 -     * class is linked as described in the "Execution" chapter of
 212.471 -     * <cite>The Java&trade; Language Specification</cite>.
 212.472 -     * </p>
 212.473 -     *
 212.474 -     * @param  c
 212.475 -     *         The class to link
 212.476 -     *
 212.477 -     * @throws  NullPointerException
 212.478 -     *          If <tt>c</tt> is <tt>null</tt>.
 212.479 -     *
 212.480 -     * @see  #defineClass(String, byte[], int, int)
 212.481 -     */
 212.482 -    protected final void resolveClass(Class<?> c) {
 212.483 -        resolveClass0(c);
 212.484 -    }
 212.485 -
 212.486 -    private native void resolveClass0(Class c);
 212.487 -
 212.488 -
 212.489 -    /**
 212.490 -     * Returns the class with the given <a href="#name">binary name</a> if this
 212.491 -     * loader has been recorded by the Java virtual machine as an initiating
 212.492 -     * loader of a class with that <a href="#name">binary name</a>.  Otherwise
 212.493 -     * <tt>null</tt> is returned.  </p>
 212.494 -     *
 212.495 -     * @param  name
 212.496 -     *         The <a href="#name">binary name</a> of the class
 212.497 -     *
 212.498 -     * @return  The <tt>Class</tt> object, or <tt>null</tt> if the class has
 212.499 -     *          not been loaded
 212.500 -     *
 212.501 -     * @since  1.1
 212.502 -     */
 212.503 -    protected final Class<?> findLoadedClass(String name) {
 212.504 -        if (!checkName(name))
 212.505 -            return null;
 212.506 -        return findLoadedClass0(name);
 212.507 -    }
 212.508 -
 212.509 -    private native final Class findLoadedClass0(String name);
 212.510 -
 212.511 -    /**
 212.512 -     * Sets the signers of a class.  This should be invoked after defining a
 212.513 -     * class.  </p>
 212.514 -     *
 212.515 -     * @param  c
 212.516 -     *         The <tt>Class</tt> object
 212.517 -     *
 212.518 -     * @param  signers
 212.519 -     *         The signers for the class
 212.520 -     *
 212.521 -     * @since  1.1
 212.522 -     */
 212.523 -    protected final void setSigners(Class<?> c, Object[] signers) {
 212.524 -        //c.setSigners(signers);
 212.525 -        throw new UnsupportedOperationException();
 212.526 -    }
 212.527 -
 212.528 -
 212.529 -    // -- Resource --
 212.530 -
 212.531 -    /**
 212.532 -     * Finds the resource with the given name.  A resource is some data
 212.533 -     * (images, audio, text, etc) that can be accessed by class code in a way
 212.534 -     * that is independent of the location of the code.
 212.535 -     *
 212.536 -     * <p> The name of a resource is a '<tt>/</tt>'-separated path name that
 212.537 -     * identifies the resource.
 212.538 -     *
 212.539 -     * <p> This method will first search the parent class loader for the
 212.540 -     * resource; if the parent is <tt>null</tt> the path of the class loader
 212.541 -     * built-in to the virtual machine is searched.  That failing, this method
 212.542 -     * will invoke {@link #findResource(String)} to find the resource.  </p>
 212.543 -     *
 212.544 -     * @param  name
 212.545 -     *         The resource name
 212.546 -     *
 212.547 -     * @return  A <tt>URL</tt> object for reading the resource, or
 212.548 -     *          <tt>null</tt> if the resource could not be found or the invoker
 212.549 -     *          doesn't have adequate  privileges to get the resource.
 212.550 -     *
 212.551 -     * @since  1.1
 212.552 -     */
 212.553 -    public URL getResource(String name) {
 212.554 -        URL url;
 212.555 -        if (parent != null) {
 212.556 -            url = parent.getResource(name);
 212.557 -        } else {
 212.558 -            url = getBootstrapResource(name);
 212.559 -        }
 212.560 -        if (url == null) {
 212.561 -            url = findResource(name);
 212.562 -        }
 212.563 -        return url;
 212.564 -    }
 212.565 -
 212.566 -    /**
 212.567 -     * Finds all the resources with the given name. A resource is some data
 212.568 -     * (images, audio, text, etc) that can be accessed by class code in a way
 212.569 -     * that is independent of the location of the code.
 212.570 -     *
 212.571 -     * <p>The name of a resource is a <tt>/</tt>-separated path name that
 212.572 -     * identifies the resource.
 212.573 -     *
 212.574 -     * <p> The search order is described in the documentation for {@link
 212.575 -     * #getResource(String)}.  </p>
 212.576 -     *
 212.577 -     * @param  name
 212.578 -     *         The resource name
 212.579 -     *
 212.580 -     * @return  An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
 212.581 -     *          the resource.  If no resources could  be found, the enumeration
 212.582 -     *          will be empty.  Resources that the class loader doesn't have
 212.583 -     *          access to will not be in the enumeration.
 212.584 -     *
 212.585 -     * @throws  IOException
 212.586 -     *          If I/O errors occur
 212.587 -     *
 212.588 -     * @see  #findResources(String)
 212.589 -     *
 212.590 -     * @since  1.2
 212.591 -     */
 212.592 -    public Enumeration<URL> getResources(String name) throws IOException {
 212.593 -        Enumeration[] tmp = new Enumeration[2];
 212.594 -        if (parent != null) {
 212.595 -            tmp[0] = parent.getResources(name);
 212.596 -        } else {
 212.597 -            tmp[0] = getBootstrapResources(name);
 212.598 -        }
 212.599 -        tmp[1] = findResources(name);
 212.600 -
 212.601 -        return new CompoundEnumeration(tmp);
 212.602 -    }
 212.603 -
 212.604 -    /**
 212.605 -     * Finds the resource with the given name. Class loader implementations
 212.606 -     * should override this method to specify where to find resources.  </p>
 212.607 -     *
 212.608 -     * @param  name
 212.609 -     *         The resource name
 212.610 -     *
 212.611 -     * @return  A <tt>URL</tt> object for reading the resource, or
 212.612 -     *          <tt>null</tt> if the resource could not be found
 212.613 -     *
 212.614 -     * @since  1.2
 212.615 -     */
 212.616 -    protected URL findResource(String name) {
 212.617 -        return null;
 212.618 -    }
 212.619 -
 212.620 -    /**
 212.621 -     * Returns an enumeration of {@link java.net.URL <tt>URL</tt>} objects
 212.622 -     * representing all the resources with the given name. Class loader
 212.623 -     * implementations should override this method to specify where to load
 212.624 -     * resources from.  </p>
 212.625 -     *
 212.626 -     * @param  name
 212.627 -     *         The resource name
 212.628 -     *
 212.629 -     * @return  An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
 212.630 -     *          the resources
 212.631 -     *
 212.632 -     * @throws  IOException
 212.633 -     *          If I/O errors occur
 212.634 -     *
 212.635 -     * @since  1.2
 212.636 -     */
 212.637 -    protected Enumeration<URL> findResources(String name) throws IOException {
 212.638 -        return new CompoundEnumeration(new Enumeration[0]);
 212.639 -    }
 212.640 -
 212.641 -    // index 0: java.lang.ClassLoader.class
 212.642 -    // index 1: the immediate caller of index 0.
 212.643 -    // index 2: the immediate caller of index 1.
 212.644 -    private static native Class<? extends ClassLoader> getCaller(int index);
 212.645 -
 212.646 -    /**
 212.647 -     * Registers the caller as parallel capable.</p>
 212.648 -     * The registration succeeds if and only if all of the following
 212.649 -     * conditions are met: <br>
 212.650 -     * 1. no instance of the caller has been created</p>
 212.651 -     * 2. all of the super classes (except class Object) of the caller are
 212.652 -     * registered as parallel capable</p>
 212.653 -     * Note that once a class loader is registered as parallel capable, there
 212.654 -     * is no way to change it back. </p>
 212.655 -     *
 212.656 -     * @return  true if the caller is successfully registered as
 212.657 -     *          parallel capable and false if otherwise.
 212.658 -     *
 212.659 -     * @since   1.7
 212.660 -     */
 212.661 -//    protected static boolean registerAsParallelCapable() {
 212.662 -//        return false;
 212.663 -//    }
 212.664 -
 212.665 -    /**
 212.666 -     * Find a resource of the specified name from the search path used to load
 212.667 -     * classes.  This method locates the resource through the system class
 212.668 -     * loader (see {@link #getSystemClassLoader()}).  </p>
 212.669 -     *
 212.670 -     * @param  name
 212.671 -     *         The resource name
 212.672 -     *
 212.673 -     * @return  A {@link java.net.URL <tt>URL</tt>} object for reading the
 212.674 -     *          resource, or <tt>null</tt> if the resource could not be found
 212.675 -     *
 212.676 -     * @since  1.1
 212.677 -     */
 212.678 -    public static URL getSystemResource(String name) {
 212.679 -        ClassLoader system = getSystemClassLoader();
 212.680 -        if (system == null) {
 212.681 -            return getBootstrapResource(name);
 212.682 -        }
 212.683 -        return system.getResource(name);
 212.684 -    }
 212.685 -
 212.686 -    /**
 212.687 -     * Finds all resources of the specified name from the search path used to
 212.688 -     * load classes.  The resources thus found are returned as an
 212.689 -     * {@link java.util.Enumeration <tt>Enumeration</tt>} of {@link
 212.690 -     * java.net.URL <tt>URL</tt>} objects.
 212.691 -     *
 212.692 -     * <p> The search order is described in the documentation for {@link
 212.693 -     * #getSystemResource(String)}.  </p>
 212.694 -     *
 212.695 -     * @param  name
 212.696 -     *         The resource name
 212.697 -     *
 212.698 -     * @return  An enumeration of resource {@link java.net.URL <tt>URL</tt>}
 212.699 -     *          objects
 212.700 -     *
 212.701 -     * @throws  IOException
 212.702 -     *          If I/O errors occur
 212.703 -
 212.704 -     * @since  1.2
 212.705 -     */
 212.706 -    public static Enumeration<URL> getSystemResources(String name)
 212.707 -        throws IOException
 212.708 -    {
 212.709 -        ClassLoader system = getSystemClassLoader();
 212.710 -        if (system == null) {
 212.711 -            return getBootstrapResources(name);
 212.712 -        }
 212.713 -        return system.getResources(name);
 212.714 -    }
 212.715 -
 212.716 -
 212.717 -
 212.718 -    /**
 212.719 -     * Returns an input stream for reading the specified resource.
 212.720 -     *
 212.721 -     * <p> The search order is described in the documentation for {@link
 212.722 -     * #getResource(String)}.  </p>
 212.723 -     *
 212.724 -     * @param  name
 212.725 -     *         The resource name
 212.726 -     *
 212.727 -     * @return  An input stream for reading the resource, or <tt>null</tt>
 212.728 -     *          if the resource could not be found
 212.729 -     *
 212.730 -     * @since  1.1
 212.731 -     */
 212.732 -    public InputStream getResourceAsStream(String name) {
 212.733 -        URL url = getResource(name);
 212.734 -        try {
 212.735 -            return url != null ? url.openStream() : null;
 212.736 -        } catch (IOException e) {
 212.737 -            return null;
 212.738 -        }
 212.739 -    }
 212.740 -
 212.741 -    /**
 212.742 -     * Open for reading, a resource of the specified name from the search path
 212.743 -     * used to load classes.  This method locates the resource through the
 212.744 -     * system class loader (see {@link #getSystemClassLoader()}).  </p>
 212.745 -     *
 212.746 -     * @param  name
 212.747 -     *         The resource name
 212.748 -     *
 212.749 -     * @return  An input stream for reading the resource, or <tt>null</tt>
 212.750 -     *          if the resource could not be found
 212.751 -     *
 212.752 -     * @since  1.1
 212.753 -     */
 212.754 -    public static InputStream getSystemResourceAsStream(String name) {
 212.755 -        URL url = getSystemResource(name);
 212.756 -        try {
 212.757 -            return url != null ? url.openStream() : null;
 212.758 -        } catch (IOException e) {
 212.759 -            return null;
 212.760 -        }
 212.761 -    }
 212.762 -
 212.763 -
 212.764 -    // -- Hierarchy --
 212.765 -
 212.766 -    /**
 212.767 -     * Returns the parent class loader for delegation. Some implementations may
 212.768 -     * use <tt>null</tt> to represent the bootstrap class loader. This method
 212.769 -     * will return <tt>null</tt> in such implementations if this class loader's
 212.770 -     * parent is the bootstrap class loader.
 212.771 -     *
 212.772 -     * <p> If a security manager is present, and the invoker's class loader is
 212.773 -     * not <tt>null</tt> and is not an ancestor of this class loader, then this
 212.774 -     * method invokes the security manager's {@link
 212.775 -     * SecurityManager#checkPermission(java.security.Permission)
 212.776 -     * <tt>checkPermission</tt>} method with a {@link
 212.777 -     * RuntimePermission#RuntimePermission(String)
 212.778 -     * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
 212.779 -     * access to the parent class loader is permitted.  If not, a
 212.780 -     * <tt>SecurityException</tt> will be thrown.  </p>
 212.781 -     *
 212.782 -     * @return  The parent <tt>ClassLoader</tt>
 212.783 -     *
 212.784 -     * @throws  SecurityException
 212.785 -     *          If a security manager exists and its <tt>checkPermission</tt>
 212.786 -     *          method doesn't allow access to this class loader's parent class
 212.787 -     *          loader.
 212.788 -     *
 212.789 -     * @since  1.2
 212.790 -     */
 212.791 -    public final ClassLoader getParent() {
 212.792 -        throw new SecurityException();
 212.793 -    }
 212.794 -
 212.795 -    /**
 212.796 -     * Returns the system class loader for delegation.  This is the default
 212.797 -     * delegation parent for new <tt>ClassLoader</tt> instances, and is
 212.798 -     * typically the class loader used to start the application.
 212.799 -     *
 212.800 -     * <p> This method is first invoked early in the runtime's startup
 212.801 -     * sequence, at which point it creates the system class loader and sets it
 212.802 -     * as the context class loader of the invoking <tt>Thread</tt>.
 212.803 -     *
 212.804 -     * <p> The default system class loader is an implementation-dependent
 212.805 -     * instance of this class.
 212.806 -     *
 212.807 -     * <p> If the system property "<tt>java.system.class.loader</tt>" is defined
 212.808 -     * when this method is first invoked then the value of that property is
 212.809 -     * taken to be the name of a class that will be returned as the system
 212.810 -     * class loader.  The class is loaded using the default system class loader
 212.811 -     * and must define a public constructor that takes a single parameter of
 212.812 -     * type <tt>ClassLoader</tt> which is used as the delegation parent.  An
 212.813 -     * instance is then created using this constructor with the default system
 212.814 -     * class loader as the parameter.  The resulting class loader is defined
 212.815 -     * to be the system class loader.
 212.816 -     *
 212.817 -     * <p> If a security manager is present, and the invoker's class loader is
 212.818 -     * not <tt>null</tt> and the invoker's class loader is not the same as or
 212.819 -     * an ancestor of the system class loader, then this method invokes the
 212.820 -     * security manager's {@link
 212.821 -     * SecurityManager#checkPermission(java.security.Permission)
 212.822 -     * <tt>checkPermission</tt>} method with a {@link
 212.823 -     * RuntimePermission#RuntimePermission(String)
 212.824 -     * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
 212.825 -     * access to the system class loader.  If not, a
 212.826 -     * <tt>SecurityException</tt> will be thrown.  </p>
 212.827 -     *
 212.828 -     * @return  The system <tt>ClassLoader</tt> for delegation, or
 212.829 -     *          <tt>null</tt> if none
 212.830 -     *
 212.831 -     * @throws  SecurityException
 212.832 -     *          If a security manager exists and its <tt>checkPermission</tt>
 212.833 -     *          method doesn't allow access to the system class loader.
 212.834 -     *
 212.835 -     * @throws  IllegalStateException
 212.836 -     *          If invoked recursively during the construction of the class
 212.837 -     *          loader specified by the "<tt>java.system.class.loader</tt>"
 212.838 -     *          property.
 212.839 -     *
 212.840 -     * @throws  Error
 212.841 -     *          If the system property "<tt>java.system.class.loader</tt>"
 212.842 -     *          is defined but the named class could not be loaded, the
 212.843 -     *          provider class does not define the required constructor, or an
 212.844 -     *          exception is thrown by that constructor when it is invoked. The
 212.845 -     *          underlying cause of the error can be retrieved via the
 212.846 -     *          {@link Throwable#getCause()} method.
 212.847 -     *
 212.848 -     * @revised  1.4
 212.849 -     */
 212.850 -    public static ClassLoader getSystemClassLoader() {
 212.851 -        throw new SecurityException();
 212.852 -    }
 212.853 -
 212.854 -    // Returns true if the specified class loader can be found in this class
 212.855 -    // loader's delegation chain.
 212.856 -    boolean isAncestor(ClassLoader cl) {
 212.857 -        ClassLoader acl = this;
 212.858 -        do {
 212.859 -            acl = acl.parent;
 212.860 -            if (cl == acl) {
 212.861 -                return true;
 212.862 -            }
 212.863 -        } while (acl != null);
 212.864 -        return false;
 212.865 -    }
 212.866 -
 212.867 -    private boolean checkName(String name) {
 212.868 -        throw new UnsupportedOperationException(); 
 212.869 -    }
 212.870 -
 212.871 -    private Class findBootstrapClassOrNull(String name) {
 212.872 -        throw new UnsupportedOperationException();
 212.873 -    }
 212.874 -
 212.875 -    private static URL getBootstrapResource(String name) {
 212.876 -        throw new UnsupportedOperationException();
 212.877 -    }
 212.878 -
 212.879 -    private static Enumeration<URL> getBootstrapResources(String name) {
 212.880 -        throw new UnsupportedOperationException();
 212.881 -    }
 212.882 -
 212.883 -    private static class CompoundEnumeration implements Enumeration<URL> {
 212.884 -        private URL next;
 212.885 -        private int index;
 212.886 -        private final Enumeration[] arr;
 212.887 -
 212.888 -        public CompoundEnumeration(Enumeration[] arr) {
 212.889 -            this.arr = arr;
 212.890 -            this.index = 0;
 212.891 -        }
 212.892 -
 212.893 -        public boolean hasMoreElements() {
 212.894 -            if (next == null) {
 212.895 -                if (arr[index].hasMoreElements()) {
 212.896 -                    next = (URL) arr[index].nextElement();
 212.897 -                } else {
 212.898 -                    if (index < arr.length) {
 212.899 -                        index++;
 212.900 -                        return hasMoreElements();
 212.901 -                    }
 212.902 -                }
 212.903 -            }
 212.904 -            return next != null;
 212.905 -        }
 212.906 -
 212.907 -        public URL nextElement() {
 212.908 -            if (!hasMoreElements()) {
 212.909 -                throw new NoSuchElementException();
 212.910 -            }
 212.911 -            URL r = next;
 212.912 -            next = null;
 212.913 -            return r;
 212.914 -        }
 212.915 -        
 212.916 -    }
 212.917 -}
   213.1 --- a/emul/src/main/java/java/lang/ClassNotFoundException.java	Wed Dec 05 10:03:58 2012 +0100
   213.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   213.3 @@ -1,125 +0,0 @@
   213.4 -/*
   213.5 - * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
   213.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   213.7 - *
   213.8 - * This code is free software; you can redistribute it and/or modify it
   213.9 - * under the terms of the GNU General Public License version 2 only, as
  213.10 - * published by the Free Software Foundation.  Oracle designates this
  213.11 - * particular file as subject to the "Classpath" exception as provided
  213.12 - * by Oracle in the LICENSE file that accompanied this code.
  213.13 - *
  213.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  213.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  213.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  213.17 - * version 2 for more details (a copy is included in the LICENSE file that
  213.18 - * accompanied this code).
  213.19 - *
  213.20 - * You should have received a copy of the GNU General Public License version
  213.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  213.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  213.23 - *
  213.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  213.25 - * or visit www.oracle.com if you need additional information or have any
  213.26 - * questions.
  213.27 - */
  213.28 -
  213.29 -package java.lang;
  213.30 -
  213.31 -/**
  213.32 - * Thrown when an application tries to load in a class through its
  213.33 - * string name using:
  213.34 - * <ul>
  213.35 - * <li>The <code>forName</code> method in class <code>Class</code>.
  213.36 - * <li>The <code>findSystemClass</code> method in class
  213.37 - *     <code>ClassLoader</code> .
  213.38 - * <li>The <code>loadClass</code> method in class <code>ClassLoader</code>.
  213.39 - * </ul>
  213.40 - * <p>
  213.41 - * but no definition for the class with the specified name could be found.
  213.42 - *
  213.43 - * <p>As of release 1.4, this exception has been retrofitted to conform to
  213.44 - * the general purpose exception-chaining mechanism.  The "optional exception
  213.45 - * that was raised while loading the class" that may be provided at
  213.46 - * construction time and accessed via the {@link #getException()} method is
  213.47 - * now known as the <i>cause</i>, and may be accessed via the {@link
  213.48 - * Throwable#getCause()} method, as well as the aforementioned "legacy method."
  213.49 - *
  213.50 - * @author  unascribed
  213.51 - * @see     java.lang.Class#forName(java.lang.String)
  213.52 - * @see     java.lang.ClassLoader#findSystemClass(java.lang.String)
  213.53 - * @see     java.lang.ClassLoader#loadClass(java.lang.String, boolean)
  213.54 - * @since   JDK1.0
  213.55 - */
  213.56 -public class ClassNotFoundException extends ReflectiveOperationException {
  213.57 -    /**
  213.58 -     * use serialVersionUID from JDK 1.1.X for interoperability
  213.59 -     */
  213.60 -     private static final long serialVersionUID = 9176873029745254542L;
  213.61 -
  213.62 -    /**
  213.63 -     * This field holds the exception ex if the
  213.64 -     * ClassNotFoundException(String s, Throwable ex) constructor was
  213.65 -     * used to instantiate the object
  213.66 -     * @serial
  213.67 -     * @since 1.2
  213.68 -     */
  213.69 -    private Throwable ex;
  213.70 -
  213.71 -    /**
  213.72 -     * Constructs a <code>ClassNotFoundException</code> with no detail message.
  213.73 -     */
  213.74 -    public ClassNotFoundException() {
  213.75 -        super((Throwable)null);  // Disallow initCause
  213.76 -    }
  213.77 -
  213.78 -    /**
  213.79 -     * Constructs a <code>ClassNotFoundException</code> with the
  213.80 -     * specified detail message.
  213.81 -     *
  213.82 -     * @param   s   the detail message.
  213.83 -     */
  213.84 -    public ClassNotFoundException(String s) {
  213.85 -        super(s, null);  //  Disallow initCause
  213.86 -    }
  213.87 -
  213.88 -    /**
  213.89 -     * Constructs a <code>ClassNotFoundException</code> with the
  213.90 -     * specified detail message and optional exception that was
  213.91 -     * raised while loading the class.
  213.92 -     *
  213.93 -     * @param s the detail message
  213.94 -     * @param ex the exception that was raised while loading the class
  213.95 -     * @since 1.2
  213.96 -     */
  213.97 -    public ClassNotFoundException(String s, Throwable ex) {
  213.98 -        super(s, null);  //  Disallow initCause
  213.99 -        this.ex = ex;
 213.100 -    }
 213.101 -
 213.102 -    /**
 213.103 -     * Returns the exception that was raised if an error occurred while
 213.104 -     * attempting to load the class. Otherwise, returns <tt>null</tt>.
 213.105 -     *
 213.106 -     * <p>This method predates the general-purpose exception chaining facility.
 213.107 -     * The {@link Throwable#getCause()} method is now the preferred means of
 213.108 -     * obtaining this information.
 213.109 -     *
 213.110 -     * @return the <code>Exception</code> that was raised while loading a class
 213.111 -     * @since 1.2
 213.112 -     */
 213.113 -    public Throwable getException() {
 213.114 -        return ex;
 213.115 -    }
 213.116 -
 213.117 -    /**
 213.118 -     * Returns the cause of this exception (the exception that was raised
 213.119 -     * if an error occurred while attempting to load the class; otherwise
 213.120 -     * <tt>null</tt>).
 213.121 -     *
 213.122 -     * @return  the cause of this exception.
 213.123 -     * @since   1.4
 213.124 -     */
 213.125 -    public Throwable getCause() {
 213.126 -        return ex;
 213.127 -    }
 213.128 -}
   214.1 --- a/emul/src/main/java/java/lang/CloneNotSupportedException.java	Wed Dec 05 10:03:58 2012 +0100
   214.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   214.3 @@ -1,65 +0,0 @@
   214.4 -/*
   214.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   214.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   214.7 - *
   214.8 - * This code is free software; you can redistribute it and/or modify it
   214.9 - * under the terms of the GNU General Public License version 2 only, as
  214.10 - * published by the Free Software Foundation.  Oracle designates this
  214.11 - * particular file as subject to the "Classpath" exception as provided
  214.12 - * by Oracle in the LICENSE file that accompanied this code.
  214.13 - *
  214.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  214.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  214.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  214.17 - * version 2 for more details (a copy is included in the LICENSE file that
  214.18 - * accompanied this code).
  214.19 - *
  214.20 - * You should have received a copy of the GNU General Public License version
  214.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  214.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  214.23 - *
  214.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  214.25 - * or visit www.oracle.com if you need additional information or have any
  214.26 - * questions.
  214.27 - */
  214.28 -
  214.29 -package java.lang;
  214.30 -
  214.31 -/**
  214.32 - * Thrown to indicate that the <code>clone</code> method in class
  214.33 - * <code>Object</code> has been called to clone an object, but that
  214.34 - * the object's class does not implement the <code>Cloneable</code>
  214.35 - * interface.
  214.36 - * <p>
  214.37 - * Applications that override the <code>clone</code> method can also
  214.38 - * throw this exception to indicate that an object could not or
  214.39 - * should not be cloned.
  214.40 - *
  214.41 - * @author  unascribed
  214.42 - * @see     java.lang.Cloneable
  214.43 - * @see     java.lang.Object#clone()
  214.44 - * @since   JDK1.0
  214.45 - */
  214.46 -
  214.47 -public
  214.48 -class CloneNotSupportedException extends Exception {
  214.49 -    private static final long serialVersionUID = 5195511250079656443L;
  214.50 -
  214.51 -    /**
  214.52 -     * Constructs a <code>CloneNotSupportedException</code> with no
  214.53 -     * detail message.
  214.54 -     */
  214.55 -    public CloneNotSupportedException() {
  214.56 -        super();
  214.57 -    }
  214.58 -
  214.59 -    /**
  214.60 -     * Constructs a <code>CloneNotSupportedException</code> with the
  214.61 -     * specified detail message.
  214.62 -     *
  214.63 -     * @param   s   the detail message.
  214.64 -     */
  214.65 -    public CloneNotSupportedException(String s) {
  214.66 -        super(s);
  214.67 -    }
  214.68 -}
   215.1 --- a/emul/src/main/java/java/lang/Comparable.java	Wed Dec 05 10:03:58 2012 +0100
   215.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   215.3 @@ -1,137 +0,0 @@
   215.4 -/*
   215.5 - * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
   215.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   215.7 - *
   215.8 - * This code is free software; you can redistribute it and/or modify it
   215.9 - * under the terms of the GNU General Public License version 2 only, as
  215.10 - * published by the Free Software Foundation.  Oracle designates this
  215.11 - * particular file as subject to the "Classpath" exception as provided
  215.12 - * by Oracle in the LICENSE file that accompanied this code.
  215.13 - *
  215.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  215.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  215.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  215.17 - * version 2 for more details (a copy is included in the LICENSE file that
  215.18 - * accompanied this code).
  215.19 - *
  215.20 - * You should have received a copy of the GNU General Public License version
  215.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  215.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  215.23 - *
  215.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  215.25 - * or visit www.oracle.com if you need additional information or have any
  215.26 - * questions.
  215.27 - */
  215.28 -
  215.29 -package java.lang;
  215.30 -
  215.31 -/**
  215.32 - * This interface imposes a total ordering on the objects of each class that
  215.33 - * implements it.  This ordering is referred to as the class's <i>natural
  215.34 - * ordering</i>, and the class's <tt>compareTo</tt> method is referred to as
  215.35 - * its <i>natural comparison method</i>.<p>
  215.36 - *
  215.37 - * Lists (and arrays) of objects that implement this interface can be sorted
  215.38 - * automatically by {@link Collections#sort(List) Collections.sort} (and
  215.39 - * {@link Arrays#sort(Object[]) Arrays.sort}).  Objects that implement this
  215.40 - * interface can be used as keys in a {@linkplain SortedMap sorted map} or as
  215.41 - * elements in a {@linkplain SortedSet sorted set}, without the need to
  215.42 - * specify a {@linkplain Comparator comparator}.<p>
  215.43 - *
  215.44 - * The natural ordering for a class <tt>C</tt> is said to be <i>consistent
  215.45 - * with equals</i> if and only if <tt>e1.compareTo(e2) == 0</tt> has
  215.46 - * the same boolean value as <tt>e1.equals(e2)</tt> for every
  215.47 - * <tt>e1</tt> and <tt>e2</tt> of class <tt>C</tt>.  Note that <tt>null</tt>
  215.48 - * is not an instance of any class, and <tt>e.compareTo(null)</tt> should
  215.49 - * throw a <tt>NullPointerException</tt> even though <tt>e.equals(null)</tt>
  215.50 - * returns <tt>false</tt>.<p>
  215.51 - *
  215.52 - * It is strongly recommended (though not required) that natural orderings be
  215.53 - * consistent with equals.  This is so because sorted sets (and sorted maps)
  215.54 - * without explicit comparators behave "strangely" when they are used with
  215.55 - * elements (or keys) whose natural ordering is inconsistent with equals.  In
  215.56 - * particular, such a sorted set (or sorted map) violates the general contract
  215.57 - * for set (or map), which is defined in terms of the <tt>equals</tt>
  215.58 - * method.<p>
  215.59 - *
  215.60 - * For example, if one adds two keys <tt>a</tt> and <tt>b</tt> such that
  215.61 - * <tt>(!a.equals(b) && a.compareTo(b) == 0)</tt> to a sorted
  215.62 - * set that does not use an explicit comparator, the second <tt>add</tt>
  215.63 - * operation returns false (and the size of the sorted set does not increase)
  215.64 - * because <tt>a</tt> and <tt>b</tt> are equivalent from the sorted set's
  215.65 - * perspective.<p>
  215.66 - *
  215.67 - * Virtually all Java core classes that implement <tt>Comparable</tt> have natural
  215.68 - * orderings that are consistent with equals.  One exception is
  215.69 - * <tt>java.math.BigDecimal</tt>, whose natural ordering equates
  215.70 - * <tt>BigDecimal</tt> objects with equal values and different precisions
  215.71 - * (such as 4.0 and 4.00).<p>
  215.72 - *
  215.73 - * For the mathematically inclined, the <i>relation</i> that defines
  215.74 - * the natural ordering on a given class C is:<pre>
  215.75 - *       {(x, y) such that x.compareTo(y) &lt;= 0}.
  215.76 - * </pre> The <i>quotient</i> for this total order is: <pre>
  215.77 - *       {(x, y) such that x.compareTo(y) == 0}.
  215.78 - * </pre>
  215.79 - *
  215.80 - * It follows immediately from the contract for <tt>compareTo</tt> that the
  215.81 - * quotient is an <i>equivalence relation</i> on <tt>C</tt>, and that the
  215.82 - * natural ordering is a <i>total order</i> on <tt>C</tt>.  When we say that a
  215.83 - * class's natural ordering is <i>consistent with equals</i>, we mean that the
  215.84 - * quotient for the natural ordering is the equivalence relation defined by
  215.85 - * the class's {@link Object#equals(Object) equals(Object)} method:<pre>
  215.86 - *     {(x, y) such that x.equals(y)}. </pre><p>
  215.87 - *
  215.88 - * This interface is a member of the
  215.89 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  215.90 - * Java Collections Framework</a>.
  215.91 - *
  215.92 - * @param <T> the type of objects that this object may be compared to
  215.93 - *
  215.94 - * @author  Josh Bloch
  215.95 - * @see java.util.Comparator
  215.96 - * @since 1.2
  215.97 - */
  215.98 -
  215.99 -public interface Comparable<T> {
 215.100 -    /**
 215.101 -     * Compares this object with the specified object for order.  Returns a
 215.102 -     * negative integer, zero, or a positive integer as this object is less
 215.103 -     * than, equal to, or greater than the specified object.
 215.104 -     *
 215.105 -     * <p>The implementor must ensure <tt>sgn(x.compareTo(y)) ==
 215.106 -     * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
 215.107 -     * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
 215.108 -     * <tt>y.compareTo(x)</tt> throws an exception.)
 215.109 -     *
 215.110 -     * <p>The implementor must also ensure that the relation is transitive:
 215.111 -     * <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
 215.112 -     * <tt>x.compareTo(z)&gt;0</tt>.
 215.113 -     *
 215.114 -     * <p>Finally, the implementor must ensure that <tt>x.compareTo(y)==0</tt>
 215.115 -     * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
 215.116 -     * all <tt>z</tt>.
 215.117 -     *
 215.118 -     * <p>It is strongly recommended, but <i>not</i> strictly required that
 215.119 -     * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>.  Generally speaking, any
 215.120 -     * class that implements the <tt>Comparable</tt> interface and violates
 215.121 -     * this condition should clearly indicate this fact.  The recommended
 215.122 -     * language is "Note: this class has a natural ordering that is
 215.123 -     * inconsistent with equals."
 215.124 -     *
 215.125 -     * <p>In the foregoing description, the notation
 215.126 -     * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
 215.127 -     * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
 215.128 -     * <tt>0</tt>, or <tt>1</tt> according to whether the value of
 215.129 -     * <i>expression</i> is negative, zero or positive.
 215.130 -     *
 215.131 -     * @param   o the object to be compared.
 215.132 -     * @return  a negative integer, zero, or a positive integer as this object
 215.133 -     *          is less than, equal to, or greater than the specified object.
 215.134 -     *
 215.135 -     * @throws NullPointerException if the specified object is null
 215.136 -     * @throws ClassCastException if the specified object's type prevents it
 215.137 -     *         from being compared to this object.
 215.138 -     */
 215.139 -    public int compareTo(T o);
 215.140 -}
   216.1 --- a/emul/src/main/java/java/lang/Deprecated.java	Wed Dec 05 10:03:58 2012 +0100
   216.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   216.3 @@ -1,44 +0,0 @@
   216.4 -/*
   216.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   216.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   216.7 - *
   216.8 - * This code is free software; you can redistribute it and/or modify it
   216.9 - * under the terms of the GNU General Public License version 2 only, as
  216.10 - * published by the Free Software Foundation.  Oracle designates this
  216.11 - * particular file as subject to the "Classpath" exception as provided
  216.12 - * by Oracle in the LICENSE file that accompanied this code.
  216.13 - *
  216.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  216.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  216.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  216.17 - * version 2 for more details (a copy is included in the LICENSE file that
  216.18 - * accompanied this code).
  216.19 - *
  216.20 - * You should have received a copy of the GNU General Public License version
  216.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  216.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  216.23 - *
  216.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  216.25 - * or visit www.oracle.com if you need additional information or have any
  216.26 - * questions.
  216.27 - */
  216.28 -
  216.29 -package java.lang;
  216.30 -
  216.31 -import java.lang.annotation.*;
  216.32 -import static java.lang.annotation.ElementType.*;
  216.33 -
  216.34 -/**
  216.35 - * A program element annotated &#64;Deprecated is one that programmers
  216.36 - * are discouraged from using, typically because it is dangerous,
  216.37 - * or because a better alternative exists.  Compilers warn when a
  216.38 - * deprecated program element is used or overridden in non-deprecated code.
  216.39 - *
  216.40 - * @author  Neal Gafter
  216.41 - * @since 1.5
  216.42 - */
  216.43 -@Documented
  216.44 -@Retention(RetentionPolicy.RUNTIME)
  216.45 -@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
  216.46 -public @interface Deprecated {
  216.47 -}
   217.1 --- a/emul/src/main/java/java/lang/Double.java	Wed Dec 05 10:03:58 2012 +0100
   217.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   217.3 @@ -1,995 +0,0 @@
   217.4 -/*
   217.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   217.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   217.7 - *
   217.8 - * This code is free software; you can redistribute it and/or modify it
   217.9 - * under the terms of the GNU General Public License version 2 only, as
  217.10 - * published by the Free Software Foundation.  Oracle designates this
  217.11 - * particular file as subject to the "Classpath" exception as provided
  217.12 - * by Oracle in the LICENSE file that accompanied this code.
  217.13 - *
  217.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  217.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  217.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  217.17 - * version 2 for more details (a copy is included in the LICENSE file that
  217.18 - * accompanied this code).
  217.19 - *
  217.20 - * You should have received a copy of the GNU General Public License version
  217.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  217.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  217.23 - *
  217.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  217.25 - * or visit www.oracle.com if you need additional information or have any
  217.26 - * questions.
  217.27 - */
  217.28 -
  217.29 -package java.lang;
  217.30 -
  217.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  217.32 -
  217.33 -/**
  217.34 - * The {@code Double} class wraps a value of the primitive type
  217.35 - * {@code double} in an object. An object of type
  217.36 - * {@code Double} contains a single field whose type is
  217.37 - * {@code double}.
  217.38 - *
  217.39 - * <p>In addition, this class provides several methods for converting a
  217.40 - * {@code double} to a {@code String} and a
  217.41 - * {@code String} to a {@code double}, as well as other
  217.42 - * constants and methods useful when dealing with a
  217.43 - * {@code double}.
  217.44 - *
  217.45 - * @author  Lee Boynton
  217.46 - * @author  Arthur van Hoff
  217.47 - * @author  Joseph D. Darcy
  217.48 - * @since JDK1.0
  217.49 - */
  217.50 -public final class Double extends Number implements Comparable<Double> {
  217.51 -    /**
  217.52 -     * A constant holding the positive infinity of type
  217.53 -     * {@code double}. It is equal to the value returned by
  217.54 -     * {@code Double.longBitsToDouble(0x7ff0000000000000L)}.
  217.55 -     */
  217.56 -    public static final double POSITIVE_INFINITY = 1.0 / 0.0;
  217.57 -
  217.58 -    /**
  217.59 -     * A constant holding the negative infinity of type
  217.60 -     * {@code double}. It is equal to the value returned by
  217.61 -     * {@code Double.longBitsToDouble(0xfff0000000000000L)}.
  217.62 -     */
  217.63 -    public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
  217.64 -
  217.65 -    /**
  217.66 -     * A constant holding a Not-a-Number (NaN) value of type
  217.67 -     * {@code double}. It is equivalent to the value returned by
  217.68 -     * {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
  217.69 -     */
  217.70 -    public static final double NaN = 0.0d / 0.0;
  217.71 -
  217.72 -    /**
  217.73 -     * A constant holding the largest positive finite value of type
  217.74 -     * {@code double},
  217.75 -     * (2-2<sup>-52</sup>)&middot;2<sup>1023</sup>.  It is equal to
  217.76 -     * the hexadecimal floating-point literal
  217.77 -     * {@code 0x1.fffffffffffffP+1023} and also equal to
  217.78 -     * {@code Double.longBitsToDouble(0x7fefffffffffffffL)}.
  217.79 -     */
  217.80 -    public static final double MAX_VALUE = 0x1.fffffffffffffP+1023; // 1.7976931348623157e+308
  217.81 -
  217.82 -    /**
  217.83 -     * A constant holding the smallest positive normal value of type
  217.84 -     * {@code double}, 2<sup>-1022</sup>.  It is equal to the
  217.85 -     * hexadecimal floating-point literal {@code 0x1.0p-1022} and also
  217.86 -     * equal to {@code Double.longBitsToDouble(0x0010000000000000L)}.
  217.87 -     *
  217.88 -     * @since 1.6
  217.89 -     */
  217.90 -    public static final double MIN_NORMAL = 0x1.0p-1022; // 2.2250738585072014E-308
  217.91 -
  217.92 -    /**
  217.93 -     * A constant holding the smallest positive nonzero value of type
  217.94 -     * {@code double}, 2<sup>-1074</sup>. It is equal to the
  217.95 -     * hexadecimal floating-point literal
  217.96 -     * {@code 0x0.0000000000001P-1022} and also equal to
  217.97 -     * {@code Double.longBitsToDouble(0x1L)}.
  217.98 -     */
  217.99 -    public static final double MIN_VALUE = 0x0.0000000000001P-1022; // 4.9e-324
 217.100 -
 217.101 -    /**
 217.102 -     * Maximum exponent a finite {@code double} variable may have.
 217.103 -     * It is equal to the value returned by
 217.104 -     * {@code Math.getExponent(Double.MAX_VALUE)}.
 217.105 -     *
 217.106 -     * @since 1.6
 217.107 -     */
 217.108 -    public static final int MAX_EXPONENT = 1023;
 217.109 -
 217.110 -    /**
 217.111 -     * Minimum exponent a normalized {@code double} variable may
 217.112 -     * have.  It is equal to the value returned by
 217.113 -     * {@code Math.getExponent(Double.MIN_NORMAL)}.
 217.114 -     *
 217.115 -     * @since 1.6
 217.116 -     */
 217.117 -    public static final int MIN_EXPONENT = -1022;
 217.118 -
 217.119 -    /**
 217.120 -     * The number of bits used to represent a {@code double} value.
 217.121 -     *
 217.122 -     * @since 1.5
 217.123 -     */
 217.124 -    public static final int SIZE = 64;
 217.125 -
 217.126 -    /**
 217.127 -     * The {@code Class} instance representing the primitive type
 217.128 -     * {@code double}.
 217.129 -     *
 217.130 -     * @since JDK1.1
 217.131 -     */
 217.132 -    public static final Class<Double>   TYPE = (Class<Double>) Class.getPrimitiveClass("double");
 217.133 -
 217.134 -    /**
 217.135 -     * Returns a string representation of the {@code double}
 217.136 -     * argument. All characters mentioned below are ASCII characters.
 217.137 -     * <ul>
 217.138 -     * <li>If the argument is NaN, the result is the string
 217.139 -     *     "{@code NaN}".
 217.140 -     * <li>Otherwise, the result is a string that represents the sign and
 217.141 -     * magnitude (absolute value) of the argument. If the sign is negative,
 217.142 -     * the first character of the result is '{@code -}'
 217.143 -     * (<code>'&#92;u002D'</code>); if the sign is positive, no sign character
 217.144 -     * appears in the result. As for the magnitude <i>m</i>:
 217.145 -     * <ul>
 217.146 -     * <li>If <i>m</i> is infinity, it is represented by the characters
 217.147 -     * {@code "Infinity"}; thus, positive infinity produces the result
 217.148 -     * {@code "Infinity"} and negative infinity produces the result
 217.149 -     * {@code "-Infinity"}.
 217.150 -     *
 217.151 -     * <li>If <i>m</i> is zero, it is represented by the characters
 217.152 -     * {@code "0.0"}; thus, negative zero produces the result
 217.153 -     * {@code "-0.0"} and positive zero produces the result
 217.154 -     * {@code "0.0"}.
 217.155 -     *
 217.156 -     * <li>If <i>m</i> is greater than or equal to 10<sup>-3</sup> but less
 217.157 -     * than 10<sup>7</sup>, then it is represented as the integer part of
 217.158 -     * <i>m</i>, in decimal form with no leading zeroes, followed by
 217.159 -     * '{@code .}' (<code>'&#92;u002E'</code>), followed by one or
 217.160 -     * more decimal digits representing the fractional part of <i>m</i>.
 217.161 -     *
 217.162 -     * <li>If <i>m</i> is less than 10<sup>-3</sup> or greater than or
 217.163 -     * equal to 10<sup>7</sup>, then it is represented in so-called
 217.164 -     * "computerized scientific notation." Let <i>n</i> be the unique
 217.165 -     * integer such that 10<sup><i>n</i></sup> &le; <i>m</i> {@literal <}
 217.166 -     * 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
 217.167 -     * mathematically exact quotient of <i>m</i> and
 217.168 -     * 10<sup><i>n</i></sup> so that 1 &le; <i>a</i> {@literal <} 10. The
 217.169 -     * magnitude is then represented as the integer part of <i>a</i>,
 217.170 -     * as a single decimal digit, followed by '{@code .}'
 217.171 -     * (<code>'&#92;u002E'</code>), followed by decimal digits
 217.172 -     * representing the fractional part of <i>a</i>, followed by the
 217.173 -     * letter '{@code E}' (<code>'&#92;u0045'</code>), followed
 217.174 -     * by a representation of <i>n</i> as a decimal integer, as
 217.175 -     * produced by the method {@link Integer#toString(int)}.
 217.176 -     * </ul>
 217.177 -     * </ul>
 217.178 -     * How many digits must be printed for the fractional part of
 217.179 -     * <i>m</i> or <i>a</i>? There must be at least one digit to represent
 217.180 -     * the fractional part, and beyond that as many, but only as many, more
 217.181 -     * digits as are needed to uniquely distinguish the argument value from
 217.182 -     * adjacent values of type {@code double}. That is, suppose that
 217.183 -     * <i>x</i> is the exact mathematical value represented by the decimal
 217.184 -     * representation produced by this method for a finite nonzero argument
 217.185 -     * <i>d</i>. Then <i>d</i> must be the {@code double} value nearest
 217.186 -     * to <i>x</i>; or if two {@code double} values are equally close
 217.187 -     * to <i>x</i>, then <i>d</i> must be one of them and the least
 217.188 -     * significant bit of the significand of <i>d</i> must be {@code 0}.
 217.189 -     *
 217.190 -     * <p>To create localized string representations of a floating-point
 217.191 -     * value, use subclasses of {@link java.text.NumberFormat}.
 217.192 -     *
 217.193 -     * @param   d   the {@code double} to be converted.
 217.194 -     * @return a string representation of the argument.
 217.195 -     */
 217.196 -    @JavaScriptBody(args="d", body="var r = d.toString();"
 217.197 -        + "if (r.indexOf('.') === -1) r = r + '.0';"
 217.198 -        + "return r;")
 217.199 -    public static String toString(double d) {
 217.200 -        throw new UnsupportedOperationException();
 217.201 -    }
 217.202 -
 217.203 -    /**
 217.204 -     * Returns a hexadecimal string representation of the
 217.205 -     * {@code double} argument. All characters mentioned below
 217.206 -     * are ASCII characters.
 217.207 -     *
 217.208 -     * <ul>
 217.209 -     * <li>If the argument is NaN, the result is the string
 217.210 -     *     "{@code NaN}".
 217.211 -     * <li>Otherwise, the result is a string that represents the sign
 217.212 -     * and magnitude of the argument. If the sign is negative, the
 217.213 -     * first character of the result is '{@code -}'
 217.214 -     * (<code>'&#92;u002D'</code>); if the sign is positive, no sign
 217.215 -     * character appears in the result. As for the magnitude <i>m</i>:
 217.216 -     *
 217.217 -     * <ul>
 217.218 -     * <li>If <i>m</i> is infinity, it is represented by the string
 217.219 -     * {@code "Infinity"}; thus, positive infinity produces the
 217.220 -     * result {@code "Infinity"} and negative infinity produces
 217.221 -     * the result {@code "-Infinity"}.
 217.222 -     *
 217.223 -     * <li>If <i>m</i> is zero, it is represented by the string
 217.224 -     * {@code "0x0.0p0"}; thus, negative zero produces the result
 217.225 -     * {@code "-0x0.0p0"} and positive zero produces the result
 217.226 -     * {@code "0x0.0p0"}.
 217.227 -     *
 217.228 -     * <li>If <i>m</i> is a {@code double} value with a
 217.229 -     * normalized representation, substrings are used to represent the
 217.230 -     * significand and exponent fields.  The significand is
 217.231 -     * represented by the characters {@code "0x1."}
 217.232 -     * followed by a lowercase hexadecimal representation of the rest
 217.233 -     * of the significand as a fraction.  Trailing zeros in the
 217.234 -     * hexadecimal representation are removed unless all the digits
 217.235 -     * are zero, in which case a single zero is used. Next, the
 217.236 -     * exponent is represented by {@code "p"} followed
 217.237 -     * by a decimal string of the unbiased exponent as if produced by
 217.238 -     * a call to {@link Integer#toString(int) Integer.toString} on the
 217.239 -     * exponent value.
 217.240 -     *
 217.241 -     * <li>If <i>m</i> is a {@code double} value with a subnormal
 217.242 -     * representation, the significand is represented by the
 217.243 -     * characters {@code "0x0."} followed by a
 217.244 -     * hexadecimal representation of the rest of the significand as a
 217.245 -     * fraction.  Trailing zeros in the hexadecimal representation are
 217.246 -     * removed. Next, the exponent is represented by
 217.247 -     * {@code "p-1022"}.  Note that there must be at
 217.248 -     * least one nonzero digit in a subnormal significand.
 217.249 -     *
 217.250 -     * </ul>
 217.251 -     *
 217.252 -     * </ul>
 217.253 -     *
 217.254 -     * <table border>
 217.255 -     * <caption><h3>Examples</h3></caption>
 217.256 -     * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
 217.257 -     * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
 217.258 -     * <tr><td>{@code -1.0}</td>        <td>{@code -0x1.0p0}</td>
 217.259 -     * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
 217.260 -     * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
 217.261 -     * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
 217.262 -     * <tr><td>{@code 0.25}</td>        <td>{@code 0x1.0p-2}</td>
 217.263 -     * <tr><td>{@code Double.MAX_VALUE}</td>
 217.264 -     *     <td>{@code 0x1.fffffffffffffp1023}</td>
 217.265 -     * <tr><td>{@code Minimum Normal Value}</td>
 217.266 -     *     <td>{@code 0x1.0p-1022}</td>
 217.267 -     * <tr><td>{@code Maximum Subnormal Value}</td>
 217.268 -     *     <td>{@code 0x0.fffffffffffffp-1022}</td>
 217.269 -     * <tr><td>{@code Double.MIN_VALUE}</td>
 217.270 -     *     <td>{@code 0x0.0000000000001p-1022}</td>
 217.271 -     * </table>
 217.272 -     * @param   d   the {@code double} to be converted.
 217.273 -     * @return a hex string representation of the argument.
 217.274 -     * @since 1.5
 217.275 -     * @author Joseph D. Darcy
 217.276 -     */
 217.277 -    public static String toHexString(double d) {
 217.278 -        throw new UnsupportedOperationException();
 217.279 -//        /*
 217.280 -//         * Modeled after the "a" conversion specifier in C99, section
 217.281 -//         * 7.19.6.1; however, the output of this method is more
 217.282 -//         * tightly specified.
 217.283 -//         */
 217.284 -//        if (!FpUtils.isFinite(d) )
 217.285 -//            // For infinity and NaN, use the decimal output.
 217.286 -//            return Double.toString(d);
 217.287 -//        else {
 217.288 -//            // Initialized to maximum size of output.
 217.289 -//            StringBuffer answer = new StringBuffer(24);
 217.290 -//
 217.291 -//            if (FpUtils.rawCopySign(1.0, d) == -1.0) // value is negative,
 217.292 -//                answer.append("-");                  // so append sign info
 217.293 -//
 217.294 -//            answer.append("0x");
 217.295 -//
 217.296 -//            d = Math.abs(d);
 217.297 -//
 217.298 -//            if(d == 0.0) {
 217.299 -//                answer.append("0.0p0");
 217.300 -//            }
 217.301 -//            else {
 217.302 -//                boolean subnormal = (d < DoubleConsts.MIN_NORMAL);
 217.303 -//
 217.304 -//                // Isolate significand bits and OR in a high-order bit
 217.305 -//                // so that the string representation has a known
 217.306 -//                // length.
 217.307 -//                long signifBits = (Double.doubleToLongBits(d)
 217.308 -//                                   & DoubleConsts.SIGNIF_BIT_MASK) |
 217.309 -//                    0x1000000000000000L;
 217.310 -//
 217.311 -//                // Subnormal values have a 0 implicit bit; normal
 217.312 -//                // values have a 1 implicit bit.
 217.313 -//                answer.append(subnormal ? "0." : "1.");
 217.314 -//
 217.315 -//                // Isolate the low-order 13 digits of the hex
 217.316 -//                // representation.  If all the digits are zero,
 217.317 -//                // replace with a single 0; otherwise, remove all
 217.318 -//                // trailing zeros.
 217.319 -//                String signif = Long.toHexString(signifBits).substring(3,16);
 217.320 -//                answer.append(signif.equals("0000000000000") ? // 13 zeros
 217.321 -//                              "0":
 217.322 -//                              signif.replaceFirst("0{1,12}$", ""));
 217.323 -//
 217.324 -//                // If the value is subnormal, use the E_min exponent
 217.325 -//                // value for double; otherwise, extract and report d's
 217.326 -//                // exponent (the representation of a subnormal uses
 217.327 -//                // E_min -1).
 217.328 -//                answer.append("p" + (subnormal ?
 217.329 -//                               DoubleConsts.MIN_EXPONENT:
 217.330 -//                               FpUtils.getExponent(d) ));
 217.331 -//            }
 217.332 -//            return answer.toString();
 217.333 -//        }
 217.334 -    }
 217.335 -
 217.336 -    /**
 217.337 -     * Returns a {@code Double} object holding the
 217.338 -     * {@code double} value represented by the argument string
 217.339 -     * {@code s}.
 217.340 -     *
 217.341 -     * <p>If {@code s} is {@code null}, then a
 217.342 -     * {@code NullPointerException} is thrown.
 217.343 -     *
 217.344 -     * <p>Leading and trailing whitespace characters in {@code s}
 217.345 -     * are ignored.  Whitespace is removed as if by the {@link
 217.346 -     * String#trim} method; that is, both ASCII space and control
 217.347 -     * characters are removed. The rest of {@code s} should
 217.348 -     * constitute a <i>FloatValue</i> as described by the lexical
 217.349 -     * syntax rules:
 217.350 -     *
 217.351 -     * <blockquote>
 217.352 -     * <dl>
 217.353 -     * <dt><i>FloatValue:</i>
 217.354 -     * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
 217.355 -     * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
 217.356 -     * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
 217.357 -     * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
 217.358 -     * <dd><i>SignedInteger</i>
 217.359 -     * </dl>
 217.360 -     *
 217.361 -     * <p>
 217.362 -     *
 217.363 -     * <dl>
 217.364 -     * <dt><i>HexFloatingPointLiteral</i>:
 217.365 -     * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
 217.366 -     * </dl>
 217.367 -     *
 217.368 -     * <p>
 217.369 -     *
 217.370 -     * <dl>
 217.371 -     * <dt><i>HexSignificand:</i>
 217.372 -     * <dd><i>HexNumeral</i>
 217.373 -     * <dd><i>HexNumeral</i> {@code .}
 217.374 -     * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
 217.375 -     *     </i>{@code .}<i> HexDigits</i>
 217.376 -     * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
 217.377 -     *     </i>{@code .} <i>HexDigits</i>
 217.378 -     * </dl>
 217.379 -     *
 217.380 -     * <p>
 217.381 -     *
 217.382 -     * <dl>
 217.383 -     * <dt><i>BinaryExponent:</i>
 217.384 -     * <dd><i>BinaryExponentIndicator SignedInteger</i>
 217.385 -     * </dl>
 217.386 -     *
 217.387 -     * <p>
 217.388 -     *
 217.389 -     * <dl>
 217.390 -     * <dt><i>BinaryExponentIndicator:</i>
 217.391 -     * <dd>{@code p}
 217.392 -     * <dd>{@code P}
 217.393 -     * </dl>
 217.394 -     *
 217.395 -     * </blockquote>
 217.396 -     *
 217.397 -     * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
 217.398 -     * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
 217.399 -     * <i>FloatTypeSuffix</i> are as defined in the lexical structure
 217.400 -     * sections of
 217.401 -     * <cite>The Java&trade; Language Specification</cite>,
 217.402 -     * except that underscores are not accepted between digits.
 217.403 -     * If {@code s} does not have the form of
 217.404 -     * a <i>FloatValue</i>, then a {@code NumberFormatException}
 217.405 -     * is thrown. Otherwise, {@code s} is regarded as
 217.406 -     * representing an exact decimal value in the usual
 217.407 -     * "computerized scientific notation" or as an exact
 217.408 -     * hexadecimal value; this exact numerical value is then
 217.409 -     * conceptually converted to an "infinitely precise"
 217.410 -     * binary value that is then rounded to type {@code double}
 217.411 -     * by the usual round-to-nearest rule of IEEE 754 floating-point
 217.412 -     * arithmetic, which includes preserving the sign of a zero
 217.413 -     * value.
 217.414 -     *
 217.415 -     * Note that the round-to-nearest rule also implies overflow and
 217.416 -     * underflow behaviour; if the exact value of {@code s} is large
 217.417 -     * enough in magnitude (greater than or equal to ({@link
 217.418 -     * #MAX_VALUE} + {@link Math#ulp(double) ulp(MAX_VALUE)}/2),
 217.419 -     * rounding to {@code double} will result in an infinity and if the
 217.420 -     * exact value of {@code s} is small enough in magnitude (less
 217.421 -     * than or equal to {@link #MIN_VALUE}/2), rounding to float will
 217.422 -     * result in a zero.
 217.423 -     *
 217.424 -     * Finally, after rounding a {@code Double} object representing
 217.425 -     * this {@code double} value is returned.
 217.426 -     *
 217.427 -     * <p> To interpret localized string representations of a
 217.428 -     * floating-point value, use subclasses of {@link
 217.429 -     * java.text.NumberFormat}.
 217.430 -     *
 217.431 -     * <p>Note that trailing format specifiers, specifiers that
 217.432 -     * determine the type of a floating-point literal
 217.433 -     * ({@code 1.0f} is a {@code float} value;
 217.434 -     * {@code 1.0d} is a {@code double} value), do
 217.435 -     * <em>not</em> influence the results of this method.  In other
 217.436 -     * words, the numerical value of the input string is converted
 217.437 -     * directly to the target floating-point type.  The two-step
 217.438 -     * sequence of conversions, string to {@code float} followed
 217.439 -     * by {@code float} to {@code double}, is <em>not</em>
 217.440 -     * equivalent to converting a string directly to
 217.441 -     * {@code double}. For example, the {@code float}
 217.442 -     * literal {@code 0.1f} is equal to the {@code double}
 217.443 -     * value {@code 0.10000000149011612}; the {@code float}
 217.444 -     * literal {@code 0.1f} represents a different numerical
 217.445 -     * value than the {@code double} literal
 217.446 -     * {@code 0.1}. (The numerical value 0.1 cannot be exactly
 217.447 -     * represented in a binary floating-point number.)
 217.448 -     *
 217.449 -     * <p>To avoid calling this method on an invalid string and having
 217.450 -     * a {@code NumberFormatException} be thrown, the regular
 217.451 -     * expression below can be used to screen the input string:
 217.452 -     *
 217.453 -     * <code>
 217.454 -     * <pre>
 217.455 -     *  final String Digits     = "(\\p{Digit}+)";
 217.456 -     *  final String HexDigits  = "(\\p{XDigit}+)";
 217.457 -     *  // an exponent is 'e' or 'E' followed by an optionally
 217.458 -     *  // signed decimal integer.
 217.459 -     *  final String Exp        = "[eE][+-]?"+Digits;
 217.460 -     *  final String fpRegex    =
 217.461 -     *      ("[\\x00-\\x20]*"+  // Optional leading "whitespace"
 217.462 -     *       "[+-]?(" + // Optional sign character
 217.463 -     *       "NaN|" +           // "NaN" string
 217.464 -     *       "Infinity|" +      // "Infinity" string
 217.465 -     *
 217.466 -     *       // A decimal floating-point string representing a finite positive
 217.467 -     *       // number without a leading sign has at most five basic pieces:
 217.468 -     *       // Digits . Digits ExponentPart FloatTypeSuffix
 217.469 -     *       //
 217.470 -     *       // Since this method allows integer-only strings as input
 217.471 -     *       // in addition to strings of floating-point literals, the
 217.472 -     *       // two sub-patterns below are simplifications of the grammar
 217.473 -     *       // productions from section 3.10.2 of
 217.474 -     *       // <cite>The Java&trade; Language Specification</cite>.
 217.475 -     *
 217.476 -     *       // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
 217.477 -     *       "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
 217.478 -     *
 217.479 -     *       // . Digits ExponentPart_opt FloatTypeSuffix_opt
 217.480 -     *       "(\\.("+Digits+")("+Exp+")?)|"+
 217.481 -     *
 217.482 -     *       // Hexadecimal strings
 217.483 -     *       "((" +
 217.484 -     *        // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
 217.485 -     *        "(0[xX]" + HexDigits + "(\\.)?)|" +
 217.486 -     *
 217.487 -     *        // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
 217.488 -     *        "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
 217.489 -     *
 217.490 -     *        ")[pP][+-]?" + Digits + "))" +
 217.491 -     *       "[fFdD]?))" +
 217.492 -     *       "[\\x00-\\x20]*");// Optional trailing "whitespace"
 217.493 -     *
 217.494 -     *  if (Pattern.matches(fpRegex, myString))
 217.495 -     *      Double.valueOf(myString); // Will not throw NumberFormatException
 217.496 -     *  else {
 217.497 -     *      // Perform suitable alternative action
 217.498 -     *  }
 217.499 -     * </pre>
 217.500 -     * </code>
 217.501 -     *
 217.502 -     * @param      s   the string to be parsed.
 217.503 -     * @return     a {@code Double} object holding the value
 217.504 -     *             represented by the {@code String} argument.
 217.505 -     * @throws     NumberFormatException  if the string does not contain a
 217.506 -     *             parsable number.
 217.507 -     */
 217.508 -    @JavaScriptBody(args="s", body="return parseFloat(s);")
 217.509 -    public static Double valueOf(String s) throws NumberFormatException {
 217.510 -        throw new UnsupportedOperationException();
 217.511 -//        return new Double(FloatingDecimal.readJavaFormatString(s).doubleValue());
 217.512 -    }
 217.513 -
 217.514 -    /**
 217.515 -     * Returns a {@code Double} instance representing the specified
 217.516 -     * {@code double} value.
 217.517 -     * If a new {@code Double} instance is not required, this method
 217.518 -     * should generally be used in preference to the constructor
 217.519 -     * {@link #Double(double)}, as this method is likely to yield
 217.520 -     * significantly better space and time performance by caching
 217.521 -     * frequently requested values.
 217.522 -     *
 217.523 -     * @param  d a double value.
 217.524 -     * @return a {@code Double} instance representing {@code d}.
 217.525 -     * @since  1.5
 217.526 -     */
 217.527 -    public static Double valueOf(double d) {
 217.528 -        return new Double(d);
 217.529 -    }
 217.530 -
 217.531 -    /**
 217.532 -     * Returns a new {@code double} initialized to the value
 217.533 -     * represented by the specified {@code String}, as performed
 217.534 -     * by the {@code valueOf} method of class
 217.535 -     * {@code Double}.
 217.536 -     *
 217.537 -     * @param  s   the string to be parsed.
 217.538 -     * @return the {@code double} value represented by the string
 217.539 -     *         argument.
 217.540 -     * @throws NullPointerException  if the string is null
 217.541 -     * @throws NumberFormatException if the string does not contain
 217.542 -     *         a parsable {@code double}.
 217.543 -     * @see    java.lang.Double#valueOf(String)
 217.544 -     * @since 1.2
 217.545 -     */
 217.546 -    @JavaScriptBody(args="s", body="return parseFloat(s);")
 217.547 -    public static double parseDouble(String s) throws NumberFormatException {
 217.548 -        throw new UnsupportedOperationException();
 217.549 -//        return FloatingDecimal.readJavaFormatString(s).doubleValue();
 217.550 -    }
 217.551 -
 217.552 -    /**
 217.553 -     * Returns {@code true} if the specified number is a
 217.554 -     * Not-a-Number (NaN) value, {@code false} otherwise.
 217.555 -     *
 217.556 -     * @param   v   the value to be tested.
 217.557 -     * @return  {@code true} if the value of the argument is NaN;
 217.558 -     *          {@code false} otherwise.
 217.559 -     */
 217.560 -    static public boolean isNaN(double v) {
 217.561 -        return (v != v);
 217.562 -    }
 217.563 -
 217.564 -    /**
 217.565 -     * Returns {@code true} if the specified number is infinitely
 217.566 -     * large in magnitude, {@code false} otherwise.
 217.567 -     *
 217.568 -     * @param   v   the value to be tested.
 217.569 -     * @return  {@code true} if the value of the argument is positive
 217.570 -     *          infinity or negative infinity; {@code false} otherwise.
 217.571 -     */
 217.572 -    static public boolean isInfinite(double v) {
 217.573 -        return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
 217.574 -    }
 217.575 -
 217.576 -    /**
 217.577 -     * The value of the Double.
 217.578 -     *
 217.579 -     * @serial
 217.580 -     */
 217.581 -    private final double value;
 217.582 -
 217.583 -    /**
 217.584 -     * Constructs a newly allocated {@code Double} object that
 217.585 -     * represents the primitive {@code double} argument.
 217.586 -     *
 217.587 -     * @param   value   the value to be represented by the {@code Double}.
 217.588 -     */
 217.589 -    public Double(double value) {
 217.590 -        this.value = value;
 217.591 -    }
 217.592 -
 217.593 -    /**
 217.594 -     * Constructs a newly allocated {@code Double} object that
 217.595 -     * represents the floating-point value of type {@code double}
 217.596 -     * represented by the string. The string is converted to a
 217.597 -     * {@code double} value as if by the {@code valueOf} method.
 217.598 -     *
 217.599 -     * @param  s  a string to be converted to a {@code Double}.
 217.600 -     * @throws    NumberFormatException  if the string does not contain a
 217.601 -     *            parsable number.
 217.602 -     * @see       java.lang.Double#valueOf(java.lang.String)
 217.603 -     */
 217.604 -    public Double(String s) throws NumberFormatException {
 217.605 -        // REMIND: this is inefficient
 217.606 -        this(valueOf(s).doubleValue());
 217.607 -    }
 217.608 -
 217.609 -    /**
 217.610 -     * Returns {@code true} if this {@code Double} value is
 217.611 -     * a Not-a-Number (NaN), {@code false} otherwise.
 217.612 -     *
 217.613 -     * @return  {@code true} if the value represented by this object is
 217.614 -     *          NaN; {@code false} otherwise.
 217.615 -     */
 217.616 -    public boolean isNaN() {
 217.617 -        return isNaN(value);
 217.618 -    }
 217.619 -
 217.620 -    /**
 217.621 -     * Returns {@code true} if this {@code Double} value is
 217.622 -     * infinitely large in magnitude, {@code false} otherwise.
 217.623 -     *
 217.624 -     * @return  {@code true} if the value represented by this object is
 217.625 -     *          positive infinity or negative infinity;
 217.626 -     *          {@code false} otherwise.
 217.627 -     */
 217.628 -    public boolean isInfinite() {
 217.629 -        return isInfinite(value);
 217.630 -    }
 217.631 -
 217.632 -    /**
 217.633 -     * Returns a string representation of this {@code Double} object.
 217.634 -     * The primitive {@code double} value represented by this
 217.635 -     * object is converted to a string exactly as if by the method
 217.636 -     * {@code toString} of one argument.
 217.637 -     *
 217.638 -     * @return  a {@code String} representation of this object.
 217.639 -     * @see java.lang.Double#toString(double)
 217.640 -     */
 217.641 -    public String toString() {
 217.642 -        return toString(value);
 217.643 -    }
 217.644 -
 217.645 -    /**
 217.646 -     * Returns the value of this {@code Double} as a {@code byte} (by
 217.647 -     * casting to a {@code byte}).
 217.648 -     *
 217.649 -     * @return  the {@code double} value represented by this object
 217.650 -     *          converted to type {@code byte}
 217.651 -     * @since JDK1.1
 217.652 -     */
 217.653 -    public byte byteValue() {
 217.654 -        return (byte)value;
 217.655 -    }
 217.656 -
 217.657 -    /**
 217.658 -     * Returns the value of this {@code Double} as a
 217.659 -     * {@code short} (by casting to a {@code short}).
 217.660 -     *
 217.661 -     * @return  the {@code double} value represented by this object
 217.662 -     *          converted to type {@code short}
 217.663 -     * @since JDK1.1
 217.664 -     */
 217.665 -    public short shortValue() {
 217.666 -        return (short)value;
 217.667 -    }
 217.668 -
 217.669 -    /**
 217.670 -     * Returns the value of this {@code Double} as an
 217.671 -     * {@code int} (by casting to type {@code int}).
 217.672 -     *
 217.673 -     * @return  the {@code double} value represented by this object
 217.674 -     *          converted to type {@code int}
 217.675 -     */
 217.676 -    public int intValue() {
 217.677 -        return (int)value;
 217.678 -    }
 217.679 -
 217.680 -    /**
 217.681 -     * Returns the value of this {@code Double} as a
 217.682 -     * {@code long} (by casting to type {@code long}).
 217.683 -     *
 217.684 -     * @return  the {@code double} value represented by this object
 217.685 -     *          converted to type {@code long}
 217.686 -     */
 217.687 -    public long longValue() {
 217.688 -        return (long)value;
 217.689 -    }
 217.690 -
 217.691 -    /**
 217.692 -     * Returns the {@code float} value of this
 217.693 -     * {@code Double} object.
 217.694 -     *
 217.695 -     * @return  the {@code double} value represented by this object
 217.696 -     *          converted to type {@code float}
 217.697 -     * @since JDK1.0
 217.698 -     */
 217.699 -    public float floatValue() {
 217.700 -        return (float)value;
 217.701 -    }
 217.702 -
 217.703 -    /**
 217.704 -     * Returns the {@code double} value of this
 217.705 -     * {@code Double} object.
 217.706 -     *
 217.707 -     * @return the {@code double} value represented by this object
 217.708 -     */
 217.709 -    public double doubleValue() {
 217.710 -        return (double)value;
 217.711 -    }
 217.712 -
 217.713 -    /**
 217.714 -     * Returns a hash code for this {@code Double} object. The
 217.715 -     * result is the exclusive OR of the two halves of the
 217.716 -     * {@code long} integer bit representation, exactly as
 217.717 -     * produced by the method {@link #doubleToLongBits(double)}, of
 217.718 -     * the primitive {@code double} value represented by this
 217.719 -     * {@code Double} object. That is, the hash code is the value
 217.720 -     * of the expression:
 217.721 -     *
 217.722 -     * <blockquote>
 217.723 -     *  {@code (int)(v^(v>>>32))}
 217.724 -     * </blockquote>
 217.725 -     *
 217.726 -     * where {@code v} is defined by:
 217.727 -     *
 217.728 -     * <blockquote>
 217.729 -     *  {@code long v = Double.doubleToLongBits(this.doubleValue());}
 217.730 -     * </blockquote>
 217.731 -     *
 217.732 -     * @return  a {@code hash code} value for this object.
 217.733 -     */
 217.734 -    public int hashCode() {
 217.735 -        long bits = doubleToLongBits(value);
 217.736 -        return (int)(bits ^ (bits >>> 32));
 217.737 -    }
 217.738 -
 217.739 -    /**
 217.740 -     * Compares this object against the specified object.  The result
 217.741 -     * is {@code true} if and only if the argument is not
 217.742 -     * {@code null} and is a {@code Double} object that
 217.743 -     * represents a {@code double} that has the same value as the
 217.744 -     * {@code double} represented by this object. For this
 217.745 -     * purpose, two {@code double} values are considered to be
 217.746 -     * the same if and only if the method {@link
 217.747 -     * #doubleToLongBits(double)} returns the identical
 217.748 -     * {@code long} value when applied to each.
 217.749 -     *
 217.750 -     * <p>Note that in most cases, for two instances of class
 217.751 -     * {@code Double}, {@code d1} and {@code d2}, the
 217.752 -     * value of {@code d1.equals(d2)} is {@code true} if and
 217.753 -     * only if
 217.754 -     *
 217.755 -     * <blockquote>
 217.756 -     *  {@code d1.doubleValue() == d2.doubleValue()}
 217.757 -     * </blockquote>
 217.758 -     *
 217.759 -     * <p>also has the value {@code true}. However, there are two
 217.760 -     * exceptions:
 217.761 -     * <ul>
 217.762 -     * <li>If {@code d1} and {@code d2} both represent
 217.763 -     *     {@code Double.NaN}, then the {@code equals} method
 217.764 -     *     returns {@code true}, even though
 217.765 -     *     {@code Double.NaN==Double.NaN} has the value
 217.766 -     *     {@code false}.
 217.767 -     * <li>If {@code d1} represents {@code +0.0} while
 217.768 -     *     {@code d2} represents {@code -0.0}, or vice versa,
 217.769 -     *     the {@code equal} test has the value {@code false},
 217.770 -     *     even though {@code +0.0==-0.0} has the value {@code true}.
 217.771 -     * </ul>
 217.772 -     * This definition allows hash tables to operate properly.
 217.773 -     * @param   obj   the object to compare with.
 217.774 -     * @return  {@code true} if the objects are the same;
 217.775 -     *          {@code false} otherwise.
 217.776 -     * @see java.lang.Double#doubleToLongBits(double)
 217.777 -     */
 217.778 -    public boolean equals(Object obj) {
 217.779 -        return (obj instanceof Double)
 217.780 -               && (doubleToLongBits(((Double)obj).value) ==
 217.781 -                      doubleToLongBits(value));
 217.782 -    }
 217.783 -
 217.784 -    /**
 217.785 -     * Returns a representation of the specified floating-point value
 217.786 -     * according to the IEEE 754 floating-point "double
 217.787 -     * format" bit layout.
 217.788 -     *
 217.789 -     * <p>Bit 63 (the bit that is selected by the mask
 217.790 -     * {@code 0x8000000000000000L}) represents the sign of the
 217.791 -     * floating-point number. Bits
 217.792 -     * 62-52 (the bits that are selected by the mask
 217.793 -     * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
 217.794 -     * (the bits that are selected by the mask
 217.795 -     * {@code 0x000fffffffffffffL}) represent the significand
 217.796 -     * (sometimes called the mantissa) of the floating-point number.
 217.797 -     *
 217.798 -     * <p>If the argument is positive infinity, the result is
 217.799 -     * {@code 0x7ff0000000000000L}.
 217.800 -     *
 217.801 -     * <p>If the argument is negative infinity, the result is
 217.802 -     * {@code 0xfff0000000000000L}.
 217.803 -     *
 217.804 -     * <p>If the argument is NaN, the result is
 217.805 -     * {@code 0x7ff8000000000000L}.
 217.806 -     *
 217.807 -     * <p>In all cases, the result is a {@code long} integer that, when
 217.808 -     * given to the {@link #longBitsToDouble(long)} method, will produce a
 217.809 -     * floating-point value the same as the argument to
 217.810 -     * {@code doubleToLongBits} (except all NaN values are
 217.811 -     * collapsed to a single "canonical" NaN value).
 217.812 -     *
 217.813 -     * @param   value   a {@code double} precision floating-point number.
 217.814 -     * @return the bits that represent the floating-point number.
 217.815 -     */
 217.816 -    public static long doubleToLongBits(double value) {
 217.817 -        throw new UnsupportedOperationException();
 217.818 -//        long result = doubleToRawLongBits(value);
 217.819 -//        // Check for NaN based on values of bit fields, maximum
 217.820 -//        // exponent and nonzero significand.
 217.821 -//        if ( ((result & DoubleConsts.EXP_BIT_MASK) ==
 217.822 -//              DoubleConsts.EXP_BIT_MASK) &&
 217.823 -//             (result & DoubleConsts.SIGNIF_BIT_MASK) != 0L)
 217.824 -//            result = 0x7ff8000000000000L;
 217.825 -//        return result;
 217.826 -    }
 217.827 -
 217.828 -    /**
 217.829 -     * Returns a representation of the specified floating-point value
 217.830 -     * according to the IEEE 754 floating-point "double
 217.831 -     * format" bit layout, preserving Not-a-Number (NaN) values.
 217.832 -     *
 217.833 -     * <p>Bit 63 (the bit that is selected by the mask
 217.834 -     * {@code 0x8000000000000000L}) represents the sign of the
 217.835 -     * floating-point number. Bits
 217.836 -     * 62-52 (the bits that are selected by the mask
 217.837 -     * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
 217.838 -     * (the bits that are selected by the mask
 217.839 -     * {@code 0x000fffffffffffffL}) represent the significand
 217.840 -     * (sometimes called the mantissa) of the floating-point number.
 217.841 -     *
 217.842 -     * <p>If the argument is positive infinity, the result is
 217.843 -     * {@code 0x7ff0000000000000L}.
 217.844 -     *
 217.845 -     * <p>If the argument is negative infinity, the result is
 217.846 -     * {@code 0xfff0000000000000L}.
 217.847 -     *
 217.848 -     * <p>If the argument is NaN, the result is the {@code long}
 217.849 -     * integer representing the actual NaN value.  Unlike the
 217.850 -     * {@code doubleToLongBits} method,
 217.851 -     * {@code doubleToRawLongBits} does not collapse all the bit
 217.852 -     * patterns encoding a NaN to a single "canonical" NaN
 217.853 -     * value.
 217.854 -     *
 217.855 -     * <p>In all cases, the result is a {@code long} integer that,
 217.856 -     * when given to the {@link #longBitsToDouble(long)} method, will
 217.857 -     * produce a floating-point value the same as the argument to
 217.858 -     * {@code doubleToRawLongBits}.
 217.859 -     *
 217.860 -     * @param   value   a {@code double} precision floating-point number.
 217.861 -     * @return the bits that represent the floating-point number.
 217.862 -     * @since 1.3
 217.863 -     */
 217.864 -    public static native long doubleToRawLongBits(double value);
 217.865 -
 217.866 -    /**
 217.867 -     * Returns the {@code double} value corresponding to a given
 217.868 -     * bit representation.
 217.869 -     * The argument is considered to be a representation of a
 217.870 -     * floating-point value according to the IEEE 754 floating-point
 217.871 -     * "double format" bit layout.
 217.872 -     *
 217.873 -     * <p>If the argument is {@code 0x7ff0000000000000L}, the result
 217.874 -     * is positive infinity.
 217.875 -     *
 217.876 -     * <p>If the argument is {@code 0xfff0000000000000L}, the result
 217.877 -     * is negative infinity.
 217.878 -     *
 217.879 -     * <p>If the argument is any value in the range
 217.880 -     * {@code 0x7ff0000000000001L} through
 217.881 -     * {@code 0x7fffffffffffffffL} or in the range
 217.882 -     * {@code 0xfff0000000000001L} through
 217.883 -     * {@code 0xffffffffffffffffL}, the result is a NaN.  No IEEE
 217.884 -     * 754 floating-point operation provided by Java can distinguish
 217.885 -     * between two NaN values of the same type with different bit
 217.886 -     * patterns.  Distinct values of NaN are only distinguishable by
 217.887 -     * use of the {@code Double.doubleToRawLongBits} method.
 217.888 -     *
 217.889 -     * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
 217.890 -     * values that can be computed from the argument:
 217.891 -     *
 217.892 -     * <blockquote><pre>
 217.893 -     * int s = ((bits &gt;&gt; 63) == 0) ? 1 : -1;
 217.894 -     * int e = (int)((bits &gt;&gt; 52) & 0x7ffL);
 217.895 -     * long m = (e == 0) ?
 217.896 -     *                 (bits & 0xfffffffffffffL) &lt;&lt; 1 :
 217.897 -     *                 (bits & 0xfffffffffffffL) | 0x10000000000000L;
 217.898 -     * </pre></blockquote>
 217.899 -     *
 217.900 -     * Then the floating-point result equals the value of the mathematical
 217.901 -     * expression <i>s</i>&middot;<i>m</i>&middot;2<sup><i>e</i>-1075</sup>.
 217.902 -     *
 217.903 -     * <p>Note that this method may not be able to return a
 217.904 -     * {@code double} NaN with exactly same bit pattern as the
 217.905 -     * {@code long} argument.  IEEE 754 distinguishes between two
 217.906 -     * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>.  The
 217.907 -     * differences between the two kinds of NaN are generally not
 217.908 -     * visible in Java.  Arithmetic operations on signaling NaNs turn
 217.909 -     * them into quiet NaNs with a different, but often similar, bit
 217.910 -     * pattern.  However, on some processors merely copying a
 217.911 -     * signaling NaN also performs that conversion.  In particular,
 217.912 -     * copying a signaling NaN to return it to the calling method
 217.913 -     * may perform this conversion.  So {@code longBitsToDouble}
 217.914 -     * may not be able to return a {@code double} with a
 217.915 -     * signaling NaN bit pattern.  Consequently, for some
 217.916 -     * {@code long} values,
 217.917 -     * {@code doubleToRawLongBits(longBitsToDouble(start))} may
 217.918 -     * <i>not</i> equal {@code start}.  Moreover, which
 217.919 -     * particular bit patterns represent signaling NaNs is platform
 217.920 -     * dependent; although all NaN bit patterns, quiet or signaling,
 217.921 -     * must be in the NaN range identified above.
 217.922 -     *
 217.923 -     * @param   bits   any {@code long} integer.
 217.924 -     * @return  the {@code double} floating-point value with the same
 217.925 -     *          bit pattern.
 217.926 -     */
 217.927 -    public static native double longBitsToDouble(long bits);
 217.928 -
 217.929 -    /**
 217.930 -     * Compares two {@code Double} objects numerically.  There
 217.931 -     * are two ways in which comparisons performed by this method
 217.932 -     * differ from those performed by the Java language numerical
 217.933 -     * comparison operators ({@code <, <=, ==, >=, >})
 217.934 -     * when applied to primitive {@code double} values:
 217.935 -     * <ul><li>
 217.936 -     *          {@code Double.NaN} is considered by this method
 217.937 -     *          to be equal to itself and greater than all other
 217.938 -     *          {@code double} values (including
 217.939 -     *          {@code Double.POSITIVE_INFINITY}).
 217.940 -     * <li>
 217.941 -     *          {@code 0.0d} is considered by this method to be greater
 217.942 -     *          than {@code -0.0d}.
 217.943 -     * </ul>
 217.944 -     * This ensures that the <i>natural ordering</i> of
 217.945 -     * {@code Double} objects imposed by this method is <i>consistent
 217.946 -     * with equals</i>.
 217.947 -     *
 217.948 -     * @param   anotherDouble   the {@code Double} to be compared.
 217.949 -     * @return  the value {@code 0} if {@code anotherDouble} is
 217.950 -     *          numerically equal to this {@code Double}; a value
 217.951 -     *          less than {@code 0} if this {@code Double}
 217.952 -     *          is numerically less than {@code anotherDouble};
 217.953 -     *          and a value greater than {@code 0} if this
 217.954 -     *          {@code Double} is numerically greater than
 217.955 -     *          {@code anotherDouble}.
 217.956 -     *
 217.957 -     * @since   1.2
 217.958 -     */
 217.959 -    public int compareTo(Double anotherDouble) {
 217.960 -        return Double.compare(value, anotherDouble.value);
 217.961 -    }
 217.962 -
 217.963 -    /**
 217.964 -     * Compares the two specified {@code double} values. The sign
 217.965 -     * of the integer value returned is the same as that of the
 217.966 -     * integer that would be returned by the call:
 217.967 -     * <pre>
 217.968 -     *    new Double(d1).compareTo(new Double(d2))
 217.969 -     * </pre>
 217.970 -     *
 217.971 -     * @param   d1        the first {@code double} to compare
 217.972 -     * @param   d2        the second {@code double} to compare
 217.973 -     * @return  the value {@code 0} if {@code d1} is
 217.974 -     *          numerically equal to {@code d2}; a value less than
 217.975 -     *          {@code 0} if {@code d1} is numerically less than
 217.976 -     *          {@code d2}; and a value greater than {@code 0}
 217.977 -     *          if {@code d1} is numerically greater than
 217.978 -     *          {@code d2}.
 217.979 -     * @since 1.4
 217.980 -     */
 217.981 -    public static int compare(double d1, double d2) {
 217.982 -        if (d1 < d2)
 217.983 -            return -1;           // Neither val is NaN, thisVal is smaller
 217.984 -        if (d1 > d2)
 217.985 -            return 1;            // Neither val is NaN, thisVal is larger
 217.986 -
 217.987 -        // Cannot use doubleToRawLongBits because of possibility of NaNs.
 217.988 -        long thisBits    = Double.doubleToLongBits(d1);
 217.989 -        long anotherBits = Double.doubleToLongBits(d2);
 217.990 -
 217.991 -        return (thisBits == anotherBits ?  0 : // Values are equal
 217.992 -                (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
 217.993 -                 1));                          // (0.0, -0.0) or (NaN, !NaN)
 217.994 -    }
 217.995 -
 217.996 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 217.997 -    private static final long serialVersionUID = -9172774392245257468L;
 217.998 -}
   218.1 --- a/emul/src/main/java/java/lang/Enum.java	Wed Dec 05 10:03:58 2012 +0100
   218.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   218.3 @@ -1,254 +0,0 @@
   218.4 -/*
   218.5 - * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
   218.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   218.7 - *
   218.8 - * This code is free software; you can redistribute it and/or modify it
   218.9 - * under the terms of the GNU General Public License version 2 only, as
  218.10 - * published by the Free Software Foundation.  Oracle designates this
  218.11 - * particular file as subject to the "Classpath" exception as provided
  218.12 - * by Oracle in the LICENSE file that accompanied this code.
  218.13 - *
  218.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  218.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  218.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  218.17 - * version 2 for more details (a copy is included in the LICENSE file that
  218.18 - * accompanied this code).
  218.19 - *
  218.20 - * You should have received a copy of the GNU General Public License version
  218.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  218.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  218.23 - *
  218.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  218.25 - * or visit www.oracle.com if you need additional information or have any
  218.26 - * questions.
  218.27 - */
  218.28 -
  218.29 -package java.lang;
  218.30 -
  218.31 -import java.io.Serializable;
  218.32 -import java.io.IOException;
  218.33 -
  218.34 -/**
  218.35 - * This is the common base class of all Java language enumeration types.
  218.36 - *
  218.37 - * More information about enums, including descriptions of the
  218.38 - * implicitly declared methods synthesized by the compiler, can be
  218.39 - * found in section 8.9 of
  218.40 - * <cite>The Java&trade; Language Specification</cite>.
  218.41 - *
  218.42 - * <p> Note that when using an enumeration type as the type of a set
  218.43 - * or as the type of the keys in a map, specialized and efficient
  218.44 - * {@linkplain java.util.EnumSet set} and {@linkplain
  218.45 - * java.util.EnumMap map} implementations are available.
  218.46 - *
  218.47 - * @param <E> The enum type subclass
  218.48 - * @author  Josh Bloch
  218.49 - * @author  Neal Gafter
  218.50 - * @see     Class#getEnumConstants()
  218.51 - * @see     java.util.EnumSet
  218.52 - * @see     java.util.EnumMap
  218.53 - * @since   1.5
  218.54 - */
  218.55 -public abstract class Enum<E extends Enum<E>>
  218.56 -        implements Comparable<E>, Serializable {
  218.57 -    /**
  218.58 -     * The name of this enum constant, as declared in the enum declaration.
  218.59 -     * Most programmers should use the {@link #toString} method rather than
  218.60 -     * accessing this field.
  218.61 -     */
  218.62 -    private final String name;
  218.63 -
  218.64 -    /**
  218.65 -     * Returns the name of this enum constant, exactly as declared in its
  218.66 -     * enum declaration.
  218.67 -     *
  218.68 -     * <b>Most programmers should use the {@link #toString} method in
  218.69 -     * preference to this one, as the toString method may return
  218.70 -     * a more user-friendly name.</b>  This method is designed primarily for
  218.71 -     * use in specialized situations where correctness depends on getting the
  218.72 -     * exact name, which will not vary from release to release.
  218.73 -     *
  218.74 -     * @return the name of this enum constant
  218.75 -     */
  218.76 -    public final String name() {
  218.77 -        return name;
  218.78 -    }
  218.79 -
  218.80 -    /**
  218.81 -     * The ordinal of this enumeration constant (its position
  218.82 -     * in the enum declaration, where the initial constant is assigned
  218.83 -     * an ordinal of zero).
  218.84 -     *
  218.85 -     * Most programmers will have no use for this field.  It is designed
  218.86 -     * for use by sophisticated enum-based data structures, such as
  218.87 -     * {@link java.util.EnumSet} and {@link java.util.EnumMap}.
  218.88 -     */
  218.89 -    private final int ordinal;
  218.90 -
  218.91 -    /**
  218.92 -     * Returns the ordinal of this enumeration constant (its position
  218.93 -     * in its enum declaration, where the initial constant is assigned
  218.94 -     * an ordinal of zero).
  218.95 -     *
  218.96 -     * Most programmers will have no use for this method.  It is
  218.97 -     * designed for use by sophisticated enum-based data structures, such
  218.98 -     * as {@link java.util.EnumSet} and {@link java.util.EnumMap}.
  218.99 -     *
 218.100 -     * @return the ordinal of this enumeration constant
 218.101 -     */
 218.102 -    public final int ordinal() {
 218.103 -        return ordinal;
 218.104 -    }
 218.105 -
 218.106 -    /**
 218.107 -     * Sole constructor.  Programmers cannot invoke this constructor.
 218.108 -     * It is for use by code emitted by the compiler in response to
 218.109 -     * enum type declarations.
 218.110 -     *
 218.111 -     * @param name - The name of this enum constant, which is the identifier
 218.112 -     *               used to declare it.
 218.113 -     * @param ordinal - The ordinal of this enumeration constant (its position
 218.114 -     *         in the enum declaration, where the initial constant is assigned
 218.115 -     *         an ordinal of zero).
 218.116 -     */
 218.117 -    protected Enum(String name, int ordinal) {
 218.118 -        this.name = name;
 218.119 -        this.ordinal = ordinal;
 218.120 -    }
 218.121 -
 218.122 -    /**
 218.123 -     * Returns the name of this enum constant, as contained in the
 218.124 -     * declaration.  This method may be overridden, though it typically
 218.125 -     * isn't necessary or desirable.  An enum type should override this
 218.126 -     * method when a more "programmer-friendly" string form exists.
 218.127 -     *
 218.128 -     * @return the name of this enum constant
 218.129 -     */
 218.130 -    public String toString() {
 218.131 -        return name;
 218.132 -    }
 218.133 -
 218.134 -    /**
 218.135 -     * Returns true if the specified object is equal to this
 218.136 -     * enum constant.
 218.137 -     *
 218.138 -     * @param other the object to be compared for equality with this object.
 218.139 -     * @return  true if the specified object is equal to this
 218.140 -     *          enum constant.
 218.141 -     */
 218.142 -    public final boolean equals(Object other) {
 218.143 -        return this==other;
 218.144 -    }
 218.145 -
 218.146 -    /**
 218.147 -     * Returns a hash code for this enum constant.
 218.148 -     *
 218.149 -     * @return a hash code for this enum constant.
 218.150 -     */
 218.151 -    public final int hashCode() {
 218.152 -        return super.hashCode();
 218.153 -    }
 218.154 -
 218.155 -    /**
 218.156 -     * Throws CloneNotSupportedException.  This guarantees that enums
 218.157 -     * are never cloned, which is necessary to preserve their "singleton"
 218.158 -     * status.
 218.159 -     *
 218.160 -     * @return (never returns)
 218.161 -     */
 218.162 -    protected final Object clone() throws CloneNotSupportedException {
 218.163 -        throw new CloneNotSupportedException();
 218.164 -    }
 218.165 -
 218.166 -    /**
 218.167 -     * Compares this enum with the specified object for order.  Returns a
 218.168 -     * negative integer, zero, or a positive integer as this object is less
 218.169 -     * than, equal to, or greater than the specified object.
 218.170 -     *
 218.171 -     * Enum constants are only comparable to other enum constants of the
 218.172 -     * same enum type.  The natural order implemented by this
 218.173 -     * method is the order in which the constants are declared.
 218.174 -     */
 218.175 -    public final int compareTo(E o) {
 218.176 -        Enum other = (Enum)o;
 218.177 -        Enum self = this;
 218.178 -        if (self.getClass() != other.getClass() && // optimization
 218.179 -            self.getDeclaringClass() != other.getDeclaringClass())
 218.180 -            throw new ClassCastException();
 218.181 -        return self.ordinal - other.ordinal;
 218.182 -    }
 218.183 -
 218.184 -    /**
 218.185 -     * Returns the Class object corresponding to this enum constant's
 218.186 -     * enum type.  Two enum constants e1 and  e2 are of the
 218.187 -     * same enum type if and only if
 218.188 -     *   e1.getDeclaringClass() == e2.getDeclaringClass().
 218.189 -     * (The value returned by this method may differ from the one returned
 218.190 -     * by the {@link Object#getClass} method for enum constants with
 218.191 -     * constant-specific class bodies.)
 218.192 -     *
 218.193 -     * @return the Class object corresponding to this enum constant's
 218.194 -     *     enum type
 218.195 -     */
 218.196 -    public final Class<E> getDeclaringClass() {
 218.197 -        Class clazz = getClass();
 218.198 -        Class zuper = clazz.getSuperclass();
 218.199 -        return (zuper == Enum.class) ? clazz : zuper;
 218.200 -    }
 218.201 -
 218.202 -    /**
 218.203 -     * Returns the enum constant of the specified enum type with the
 218.204 -     * specified name.  The name must match exactly an identifier used
 218.205 -     * to declare an enum constant in this type.  (Extraneous whitespace
 218.206 -     * characters are not permitted.)
 218.207 -     *
 218.208 -     * <p>Note that for a particular enum type {@code T}, the
 218.209 -     * implicitly declared {@code public static T valueOf(String)}
 218.210 -     * method on that enum may be used instead of this method to map
 218.211 -     * from a name to the corresponding enum constant.  All the
 218.212 -     * constants of an enum type can be obtained by calling the
 218.213 -     * implicit {@code public static T[] values()} method of that
 218.214 -     * type.
 218.215 -     *
 218.216 -     * @param <T> The enum type whose constant is to be returned
 218.217 -     * @param enumType the {@code Class} object of the enum type from which
 218.218 -     *      to return a constant
 218.219 -     * @param name the name of the constant to return
 218.220 -     * @return the enum constant of the specified enum type with the
 218.221 -     *      specified name
 218.222 -     * @throws IllegalArgumentException if the specified enum type has
 218.223 -     *         no constant with the specified name, or the specified
 218.224 -     *         class object does not represent an enum type
 218.225 -     * @throws NullPointerException if {@code enumType} or {@code name}
 218.226 -     *         is null
 218.227 -     * @since 1.5
 218.228 -     */
 218.229 -    public static <T extends Enum<T>> T valueOf(Class<T> enumType,
 218.230 -                                                String name) {
 218.231 -        throw new UnsupportedOperationException();
 218.232 -//        T result = enumType.enumConstantDirectory().get(name);
 218.233 -//        if (result != null)
 218.234 -//            return result;
 218.235 -//        if (name == null)
 218.236 -//            throw new NullPointerException("Name is null");
 218.237 -//        throw new IllegalArgumentException(
 218.238 -//            "No enum constant " + enumType.getCanonicalName() + "." + name);
 218.239 -    }
 218.240 -
 218.241 -    /**
 218.242 -     * enum classes cannot have finalize methods.
 218.243 -     */
 218.244 -    protected final void finalize() { }
 218.245 -
 218.246 -    /**
 218.247 -     * prevent default deserialization
 218.248 -     */
 218.249 -//    private void readObject(ObjectInputStream in) throws IOException,
 218.250 -//        ClassNotFoundException {
 218.251 -//        throw new InvalidObjectException("can't deserialize enum");
 218.252 -//    }
 218.253 -//
 218.254 -//    private void readObjectNoData() throws ObjectStreamException {
 218.255 -//        throw new InvalidObjectException("can't deserialize enum");
 218.256 -//    }
 218.257 -}
   219.1 --- a/emul/src/main/java/java/lang/Error.java	Wed Dec 05 10:03:58 2012 +0100
   219.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   219.3 @@ -1,128 +0,0 @@
   219.4 -/*
   219.5 - * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
   219.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   219.7 - *
   219.8 - * This code is free software; you can redistribute it and/or modify it
   219.9 - * under the terms of the GNU General Public License version 2 only, as
  219.10 - * published by the Free Software Foundation.  Oracle designates this
  219.11 - * particular file as subject to the "Classpath" exception as provided
  219.12 - * by Oracle in the LICENSE file that accompanied this code.
  219.13 - *
  219.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  219.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  219.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  219.17 - * version 2 for more details (a copy is included in the LICENSE file that
  219.18 - * accompanied this code).
  219.19 - *
  219.20 - * You should have received a copy of the GNU General Public License version
  219.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  219.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  219.23 - *
  219.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  219.25 - * or visit www.oracle.com if you need additional information or have any
  219.26 - * questions.
  219.27 - */
  219.28 -
  219.29 -package java.lang;
  219.30 -
  219.31 -/**
  219.32 - * An {@code Error} is a subclass of {@code Throwable}
  219.33 - * that indicates serious problems that a reasonable application
  219.34 - * should not try to catch. Most such errors are abnormal conditions.
  219.35 - * The {@code ThreadDeath} error, though a "normal" condition,
  219.36 - * is also a subclass of {@code Error} because most applications
  219.37 - * should not try to catch it.
  219.38 - * <p>
  219.39 - * A method is not required to declare in its {@code throws}
  219.40 - * clause any subclasses of {@code Error} that might be thrown
  219.41 - * during the execution of the method but not caught, since these
  219.42 - * errors are abnormal conditions that should never occur.
  219.43 - *
  219.44 - * That is, {@code Error} and its subclasses are regarded as unchecked
  219.45 - * exceptions for the purposes of compile-time checking of exceptions.
  219.46 - *
  219.47 - * @author  Frank Yellin
  219.48 - * @see     java.lang.ThreadDeath
  219.49 - * @jls 11.2 Compile-Time Checking of Exceptions
  219.50 - * @since   JDK1.0
  219.51 - */
  219.52 -public class Error extends Throwable {
  219.53 -    static final long serialVersionUID = 4980196508277280342L;
  219.54 -
  219.55 -    /**
  219.56 -     * Constructs a new error with {@code null} as its detail message.
  219.57 -     * The cause is not initialized, and may subsequently be initialized by a
  219.58 -     * call to {@link #initCause}.
  219.59 -     */
  219.60 -    public Error() {
  219.61 -        super();
  219.62 -    }
  219.63 -
  219.64 -    /**
  219.65 -     * Constructs a new error with the specified detail message.  The
  219.66 -     * cause is not initialized, and may subsequently be initialized by
  219.67 -     * a call to {@link #initCause}.
  219.68 -     *
  219.69 -     * @param   message   the detail message. The detail message is saved for
  219.70 -     *          later retrieval by the {@link #getMessage()} method.
  219.71 -     */
  219.72 -    public Error(String message) {
  219.73 -        super(message);
  219.74 -    }
  219.75 -
  219.76 -    /**
  219.77 -     * Constructs a new error with the specified detail message and
  219.78 -     * cause.  <p>Note that the detail message associated with
  219.79 -     * {@code cause} is <i>not</i> automatically incorporated in
  219.80 -     * this error's detail message.
  219.81 -     *
  219.82 -     * @param  message the detail message (which is saved for later retrieval
  219.83 -     *         by the {@link #getMessage()} method).
  219.84 -     * @param  cause the cause (which is saved for later retrieval by the
  219.85 -     *         {@link #getCause()} method).  (A {@code null} value is
  219.86 -     *         permitted, and indicates that the cause is nonexistent or
  219.87 -     *         unknown.)
  219.88 -     * @since  1.4
  219.89 -     */
  219.90 -    public Error(String message, Throwable cause) {
  219.91 -        super(message, cause);
  219.92 -    }
  219.93 -
  219.94 -    /**
  219.95 -     * Constructs a new error with the specified cause and a detail
  219.96 -     * message of {@code (cause==null ? null : cause.toString())} (which
  219.97 -     * typically contains the class and detail message of {@code cause}).
  219.98 -     * This constructor is useful for errors that are little more than
  219.99 -     * wrappers for other throwables.
 219.100 -     *
 219.101 -     * @param  cause the cause (which is saved for later retrieval by the
 219.102 -     *         {@link #getCause()} method).  (A {@code null} value is
 219.103 -     *         permitted, and indicates that the cause is nonexistent or
 219.104 -     *         unknown.)
 219.105 -     * @since  1.4
 219.106 -     */
 219.107 -    public Error(Throwable cause) {
 219.108 -        super(cause);
 219.109 -    }
 219.110 -
 219.111 -    /**
 219.112 -     * Constructs a new error with the specified detail message,
 219.113 -     * cause, suppression enabled or disabled, and writable stack
 219.114 -     * trace enabled or disabled.
 219.115 -     *
 219.116 -     * @param  message the detail message.
 219.117 -     * @param cause the cause.  (A {@code null} value is permitted,
 219.118 -     * and indicates that the cause is nonexistent or unknown.)
 219.119 -     * @param enableSuppression whether or not suppression is enabled
 219.120 -     *                          or disabled
 219.121 -     * @param writableStackTrace whether or not the stack trace should
 219.122 -     *                           be writable
 219.123 -     *
 219.124 -     * @since 1.7
 219.125 -     */
 219.126 -    protected Error(String message, Throwable cause,
 219.127 -                    boolean enableSuppression,
 219.128 -                    boolean writableStackTrace) {
 219.129 -        super(message, cause, enableSuppression, writableStackTrace);
 219.130 -    }
 219.131 -}
   220.1 --- a/emul/src/main/java/java/lang/Exception.java	Wed Dec 05 10:03:58 2012 +0100
   220.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   220.3 @@ -1,124 +0,0 @@
   220.4 -/*
   220.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   220.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   220.7 - *
   220.8 - * This code is free software; you can redistribute it and/or modify it
   220.9 - * under the terms of the GNU General Public License version 2 only, as
  220.10 - * published by the Free Software Foundation.  Oracle designates this
  220.11 - * particular file as subject to the "Classpath" exception as provided
  220.12 - * by Oracle in the LICENSE file that accompanied this code.
  220.13 - *
  220.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  220.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  220.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  220.17 - * version 2 for more details (a copy is included in the LICENSE file that
  220.18 - * accompanied this code).
  220.19 - *
  220.20 - * You should have received a copy of the GNU General Public License version
  220.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  220.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  220.23 - *
  220.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  220.25 - * or visit www.oracle.com if you need additional information or have any
  220.26 - * questions.
  220.27 - */
  220.28 -
  220.29 -package java.lang;
  220.30 -
  220.31 -/**
  220.32 - * The class {@code Exception} and its subclasses are a form of
  220.33 - * {@code Throwable} that indicates conditions that a reasonable
  220.34 - * application might want to catch.
  220.35 - *
  220.36 - * <p>The class {@code Exception} and any subclasses that are not also
  220.37 - * subclasses of {@link RuntimeException} are <em>checked
  220.38 - * exceptions</em>.  Checked exceptions need to be declared in a
  220.39 - * method or constructor's {@code throws} clause if they can be thrown
  220.40 - * by the execution of the method or constructor and propagate outside
  220.41 - * the method or constructor boundary.
  220.42 - *
  220.43 - * @author  Frank Yellin
  220.44 - * @see     java.lang.Error
  220.45 - * @jls 11.2 Compile-Time Checking of Exceptions
  220.46 - * @since   JDK1.0
  220.47 - */
  220.48 -public class Exception extends Throwable {
  220.49 -    static final long serialVersionUID = -3387516993124229948L;
  220.50 -
  220.51 -    /**
  220.52 -     * Constructs a new exception with {@code null} as its detail message.
  220.53 -     * The cause is not initialized, and may subsequently be initialized by a
  220.54 -     * call to {@link #initCause}.
  220.55 -     */
  220.56 -    public Exception() {
  220.57 -        super();
  220.58 -    }
  220.59 -
  220.60 -    /**
  220.61 -     * Constructs a new exception with the specified detail message.  The
  220.62 -     * cause is not initialized, and may subsequently be initialized by
  220.63 -     * a call to {@link #initCause}.
  220.64 -     *
  220.65 -     * @param   message   the detail message. The detail message is saved for
  220.66 -     *          later retrieval by the {@link #getMessage()} method.
  220.67 -     */
  220.68 -    public Exception(String message) {
  220.69 -        super(message);
  220.70 -    }
  220.71 -
  220.72 -    /**
  220.73 -     * Constructs a new exception with the specified detail message and
  220.74 -     * cause.  <p>Note that the detail message associated with
  220.75 -     * {@code cause} is <i>not</i> automatically incorporated in
  220.76 -     * this exception's detail message.
  220.77 -     *
  220.78 -     * @param  message the detail message (which is saved for later retrieval
  220.79 -     *         by the {@link #getMessage()} method).
  220.80 -     * @param  cause the cause (which is saved for later retrieval by the
  220.81 -     *         {@link #getCause()} method).  (A <tt>null</tt> value is
  220.82 -     *         permitted, and indicates that the cause is nonexistent or
  220.83 -     *         unknown.)
  220.84 -     * @since  1.4
  220.85 -     */
  220.86 -    public Exception(String message, Throwable cause) {
  220.87 -        super(message, cause);
  220.88 -    }
  220.89 -
  220.90 -    /**
  220.91 -     * Constructs a new exception with the specified cause and a detail
  220.92 -     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  220.93 -     * typically contains the class and detail message of <tt>cause</tt>).
  220.94 -     * This constructor is useful for exceptions that are little more than
  220.95 -     * wrappers for other throwables (for example, {@link
  220.96 -     * java.security.PrivilegedActionException}).
  220.97 -     *
  220.98 -     * @param  cause the cause (which is saved for later retrieval by the
  220.99 -     *         {@link #getCause()} method).  (A <tt>null</tt> value is
 220.100 -     *         permitted, and indicates that the cause is nonexistent or
 220.101 -     *         unknown.)
 220.102 -     * @since  1.4
 220.103 -     */
 220.104 -    public Exception(Throwable cause) {
 220.105 -        super(cause);
 220.106 -    }
 220.107 -
 220.108 -    /**
 220.109 -     * Constructs a new exception with the specified detail message,
 220.110 -     * cause, suppression enabled or disabled, and writable stack
 220.111 -     * trace enabled or disabled.
 220.112 -     *
 220.113 -     * @param  message the detail message.
 220.114 -     * @param cause the cause.  (A {@code null} value is permitted,
 220.115 -     * and indicates that the cause is nonexistent or unknown.)
 220.116 -     * @param enableSuppression whether or not suppression is enabled
 220.117 -     *                          or disabled
 220.118 -     * @param writableStackTrace whether or not the stack trace should
 220.119 -     *                           be writable
 220.120 -     * @since 1.7
 220.121 -     */
 220.122 -    protected Exception(String message, Throwable cause,
 220.123 -                        boolean enableSuppression,
 220.124 -                        boolean writableStackTrace) {
 220.125 -        super(message, cause, enableSuppression, writableStackTrace);
 220.126 -    }
 220.127 -}
   221.1 --- a/emul/src/main/java/java/lang/Float.java	Wed Dec 05 10:03:58 2012 +0100
   221.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   221.3 @@ -1,905 +0,0 @@
   221.4 -/*
   221.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   221.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   221.7 - *
   221.8 - * This code is free software; you can redistribute it and/or modify it
   221.9 - * under the terms of the GNU General Public License version 2 only, as
  221.10 - * published by the Free Software Foundation.  Oracle designates this
  221.11 - * particular file as subject to the "Classpath" exception as provided
  221.12 - * by Oracle in the LICENSE file that accompanied this code.
  221.13 - *
  221.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  221.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  221.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  221.17 - * version 2 for more details (a copy is included in the LICENSE file that
  221.18 - * accompanied this code).
  221.19 - *
  221.20 - * You should have received a copy of the GNU General Public License version
  221.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  221.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  221.23 - *
  221.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  221.25 - * or visit www.oracle.com if you need additional information or have any
  221.26 - * questions.
  221.27 - */
  221.28 -
  221.29 -package java.lang;
  221.30 -
  221.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  221.32 -
  221.33 -/**
  221.34 - * The {@code Float} class wraps a value of primitive type
  221.35 - * {@code float} in an object. An object of type
  221.36 - * {@code Float} contains a single field whose type is
  221.37 - * {@code float}.
  221.38 - *
  221.39 - * <p>In addition, this class provides several methods for converting a
  221.40 - * {@code float} to a {@code String} and a
  221.41 - * {@code String} to a {@code float}, as well as other
  221.42 - * constants and methods useful when dealing with a
  221.43 - * {@code float}.
  221.44 - *
  221.45 - * @author  Lee Boynton
  221.46 - * @author  Arthur van Hoff
  221.47 - * @author  Joseph D. Darcy
  221.48 - * @since JDK1.0
  221.49 - */
  221.50 -public final class Float extends Number implements Comparable<Float> {
  221.51 -    /**
  221.52 -     * A constant holding the positive infinity of type
  221.53 -     * {@code float}. It is equal to the value returned by
  221.54 -     * {@code Float.intBitsToFloat(0x7f800000)}.
  221.55 -     */
  221.56 -    public static final float POSITIVE_INFINITY = 1.0f / 0.0f;
  221.57 -
  221.58 -    /**
  221.59 -     * A constant holding the negative infinity of type
  221.60 -     * {@code float}. It is equal to the value returned by
  221.61 -     * {@code Float.intBitsToFloat(0xff800000)}.
  221.62 -     */
  221.63 -    public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;
  221.64 -
  221.65 -    /**
  221.66 -     * A constant holding a Not-a-Number (NaN) value of type
  221.67 -     * {@code float}.  It is equivalent to the value returned by
  221.68 -     * {@code Float.intBitsToFloat(0x7fc00000)}.
  221.69 -     */
  221.70 -    public static final float NaN = 0.0f / 0.0f;
  221.71 -
  221.72 -    /**
  221.73 -     * A constant holding the largest positive finite value of type
  221.74 -     * {@code float}, (2-2<sup>-23</sup>)&middot;2<sup>127</sup>.
  221.75 -     * It is equal to the hexadecimal floating-point literal
  221.76 -     * {@code 0x1.fffffeP+127f} and also equal to
  221.77 -     * {@code Float.intBitsToFloat(0x7f7fffff)}.
  221.78 -     */
  221.79 -    public static final float MAX_VALUE = 0x1.fffffeP+127f; // 3.4028235e+38f
  221.80 -
  221.81 -    /**
  221.82 -     * A constant holding the smallest positive normal value of type
  221.83 -     * {@code float}, 2<sup>-126</sup>.  It is equal to the
  221.84 -     * hexadecimal floating-point literal {@code 0x1.0p-126f} and also
  221.85 -     * equal to {@code Float.intBitsToFloat(0x00800000)}.
  221.86 -     *
  221.87 -     * @since 1.6
  221.88 -     */
  221.89 -    public static final float MIN_NORMAL = 0x1.0p-126f; // 1.17549435E-38f
  221.90 -
  221.91 -    /**
  221.92 -     * A constant holding the smallest positive nonzero value of type
  221.93 -     * {@code float}, 2<sup>-149</sup>. It is equal to the
  221.94 -     * hexadecimal floating-point literal {@code 0x0.000002P-126f}
  221.95 -     * and also equal to {@code Float.intBitsToFloat(0x1)}.
  221.96 -     */
  221.97 -    public static final float MIN_VALUE = 0x0.000002P-126f; // 1.4e-45f
  221.98 -
  221.99 -    /**
 221.100 -     * Maximum exponent a finite {@code float} variable may have.  It
 221.101 -     * is equal to the value returned by {@code
 221.102 -     * Math.getExponent(Float.MAX_VALUE)}.
 221.103 -     *
 221.104 -     * @since 1.6
 221.105 -     */
 221.106 -    public static final int MAX_EXPONENT = 127;
 221.107 -
 221.108 -    /**
 221.109 -     * Minimum exponent a normalized {@code float} variable may have.
 221.110 -     * It is equal to the value returned by {@code
 221.111 -     * Math.getExponent(Float.MIN_NORMAL)}.
 221.112 -     *
 221.113 -     * @since 1.6
 221.114 -     */
 221.115 -    public static final int MIN_EXPONENT = -126;
 221.116 -
 221.117 -    /**
 221.118 -     * The number of bits used to represent a {@code float} value.
 221.119 -     *
 221.120 -     * @since 1.5
 221.121 -     */
 221.122 -    public static final int SIZE = 32;
 221.123 -
 221.124 -    /**
 221.125 -     * The {@code Class} instance representing the primitive type
 221.126 -     * {@code float}.
 221.127 -     *
 221.128 -     * @since JDK1.1
 221.129 -     */
 221.130 -    public static final Class<Float> TYPE = Class.getPrimitiveClass("float");
 221.131 -
 221.132 -    /**
 221.133 -     * Returns a string representation of the {@code float}
 221.134 -     * argument. All characters mentioned below are ASCII characters.
 221.135 -     * <ul>
 221.136 -     * <li>If the argument is NaN, the result is the string
 221.137 -     * "{@code NaN}".
 221.138 -     * <li>Otherwise, the result is a string that represents the sign and
 221.139 -     *     magnitude (absolute value) of the argument. If the sign is
 221.140 -     *     negative, the first character of the result is
 221.141 -     *     '{@code -}' (<code>'&#92;u002D'</code>); if the sign is
 221.142 -     *     positive, no sign character appears in the result. As for
 221.143 -     *     the magnitude <i>m</i>:
 221.144 -     * <ul>
 221.145 -     * <li>If <i>m</i> is infinity, it is represented by the characters
 221.146 -     *     {@code "Infinity"}; thus, positive infinity produces
 221.147 -     *     the result {@code "Infinity"} and negative infinity
 221.148 -     *     produces the result {@code "-Infinity"}.
 221.149 -     * <li>If <i>m</i> is zero, it is represented by the characters
 221.150 -     *     {@code "0.0"}; thus, negative zero produces the result
 221.151 -     *     {@code "-0.0"} and positive zero produces the result
 221.152 -     *     {@code "0.0"}.
 221.153 -     * <li> If <i>m</i> is greater than or equal to 10<sup>-3</sup> but
 221.154 -     *      less than 10<sup>7</sup>, then it is represented as the
 221.155 -     *      integer part of <i>m</i>, in decimal form with no leading
 221.156 -     *      zeroes, followed by '{@code .}'
 221.157 -     *      (<code>'&#92;u002E'</code>), followed by one or more
 221.158 -     *      decimal digits representing the fractional part of
 221.159 -     *      <i>m</i>.
 221.160 -     * <li> If <i>m</i> is less than 10<sup>-3</sup> or greater than or
 221.161 -     *      equal to 10<sup>7</sup>, then it is represented in
 221.162 -     *      so-called "computerized scientific notation." Let <i>n</i>
 221.163 -     *      be the unique integer such that 10<sup><i>n</i> </sup>&le;
 221.164 -     *      <i>m</i> {@literal <} 10<sup><i>n</i>+1</sup>; then let <i>a</i>
 221.165 -     *      be the mathematically exact quotient of <i>m</i> and
 221.166 -     *      10<sup><i>n</i></sup> so that 1 &le; <i>a</i> {@literal <} 10.
 221.167 -     *      The magnitude is then represented as the integer part of
 221.168 -     *      <i>a</i>, as a single decimal digit, followed by
 221.169 -     *      '{@code .}' (<code>'&#92;u002E'</code>), followed by
 221.170 -     *      decimal digits representing the fractional part of
 221.171 -     *      <i>a</i>, followed by the letter '{@code E}'
 221.172 -     *      (<code>'&#92;u0045'</code>), followed by a representation
 221.173 -     *      of <i>n</i> as a decimal integer, as produced by the
 221.174 -     *      method {@link java.lang.Integer#toString(int)}.
 221.175 -     *
 221.176 -     * </ul>
 221.177 -     * </ul>
 221.178 -     * How many digits must be printed for the fractional part of
 221.179 -     * <i>m</i> or <i>a</i>? There must be at least one digit
 221.180 -     * to represent the fractional part, and beyond that as many, but
 221.181 -     * only as many, more digits as are needed to uniquely distinguish
 221.182 -     * the argument value from adjacent values of type
 221.183 -     * {@code float}. That is, suppose that <i>x</i> is the
 221.184 -     * exact mathematical value represented by the decimal
 221.185 -     * representation produced by this method for a finite nonzero
 221.186 -     * argument <i>f</i>. Then <i>f</i> must be the {@code float}
 221.187 -     * value nearest to <i>x</i>; or, if two {@code float} values are
 221.188 -     * equally close to <i>x</i>, then <i>f</i> must be one of
 221.189 -     * them and the least significant bit of the significand of
 221.190 -     * <i>f</i> must be {@code 0}.
 221.191 -     *
 221.192 -     * <p>To create localized string representations of a floating-point
 221.193 -     * value, use subclasses of {@link java.text.NumberFormat}.
 221.194 -     *
 221.195 -     * @param   f   the float to be converted.
 221.196 -     * @return a string representation of the argument.
 221.197 -     */
 221.198 -    public static String toString(float f) {
 221.199 -        return Double.toString(f);
 221.200 -    }
 221.201 -
 221.202 -    /**
 221.203 -     * Returns a hexadecimal string representation of the
 221.204 -     * {@code float} argument. All characters mentioned below are
 221.205 -     * ASCII characters.
 221.206 -     *
 221.207 -     * <ul>
 221.208 -     * <li>If the argument is NaN, the result is the string
 221.209 -     *     "{@code NaN}".
 221.210 -     * <li>Otherwise, the result is a string that represents the sign and
 221.211 -     * magnitude (absolute value) of the argument. If the sign is negative,
 221.212 -     * the first character of the result is '{@code -}'
 221.213 -     * (<code>'&#92;u002D'</code>); if the sign is positive, no sign character
 221.214 -     * appears in the result. As for the magnitude <i>m</i>:
 221.215 -     *
 221.216 -     * <ul>
 221.217 -     * <li>If <i>m</i> is infinity, it is represented by the string
 221.218 -     * {@code "Infinity"}; thus, positive infinity produces the
 221.219 -     * result {@code "Infinity"} and negative infinity produces
 221.220 -     * the result {@code "-Infinity"}.
 221.221 -     *
 221.222 -     * <li>If <i>m</i> is zero, it is represented by the string
 221.223 -     * {@code "0x0.0p0"}; thus, negative zero produces the result
 221.224 -     * {@code "-0x0.0p0"} and positive zero produces the result
 221.225 -     * {@code "0x0.0p0"}.
 221.226 -     *
 221.227 -     * <li>If <i>m</i> is a {@code float} value with a
 221.228 -     * normalized representation, substrings are used to represent the
 221.229 -     * significand and exponent fields.  The significand is
 221.230 -     * represented by the characters {@code "0x1."}
 221.231 -     * followed by a lowercase hexadecimal representation of the rest
 221.232 -     * of the significand as a fraction.  Trailing zeros in the
 221.233 -     * hexadecimal representation are removed unless all the digits
 221.234 -     * are zero, in which case a single zero is used. Next, the
 221.235 -     * exponent is represented by {@code "p"} followed
 221.236 -     * by a decimal string of the unbiased exponent as if produced by
 221.237 -     * a call to {@link Integer#toString(int) Integer.toString} on the
 221.238 -     * exponent value.
 221.239 -     *
 221.240 -     * <li>If <i>m</i> is a {@code float} value with a subnormal
 221.241 -     * representation, the significand is represented by the
 221.242 -     * characters {@code "0x0."} followed by a
 221.243 -     * hexadecimal representation of the rest of the significand as a
 221.244 -     * fraction.  Trailing zeros in the hexadecimal representation are
 221.245 -     * removed. Next, the exponent is represented by
 221.246 -     * {@code "p-126"}.  Note that there must be at
 221.247 -     * least one nonzero digit in a subnormal significand.
 221.248 -     *
 221.249 -     * </ul>
 221.250 -     *
 221.251 -     * </ul>
 221.252 -     *
 221.253 -     * <table border>
 221.254 -     * <caption><h3>Examples</h3></caption>
 221.255 -     * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
 221.256 -     * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
 221.257 -     * <tr><td>{@code -1.0}</td>        <td>{@code -0x1.0p0}</td>
 221.258 -     * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
 221.259 -     * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
 221.260 -     * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
 221.261 -     * <tr><td>{@code 0.25}</td>        <td>{@code 0x1.0p-2}</td>
 221.262 -     * <tr><td>{@code Float.MAX_VALUE}</td>
 221.263 -     *     <td>{@code 0x1.fffffep127}</td>
 221.264 -     * <tr><td>{@code Minimum Normal Value}</td>
 221.265 -     *     <td>{@code 0x1.0p-126}</td>
 221.266 -     * <tr><td>{@code Maximum Subnormal Value}</td>
 221.267 -     *     <td>{@code 0x0.fffffep-126}</td>
 221.268 -     * <tr><td>{@code Float.MIN_VALUE}</td>
 221.269 -     *     <td>{@code 0x0.000002p-126}</td>
 221.270 -     * </table>
 221.271 -     * @param   f   the {@code float} to be converted.
 221.272 -     * @return a hex string representation of the argument.
 221.273 -     * @since 1.5
 221.274 -     * @author Joseph D. Darcy
 221.275 -     */
 221.276 -    public static String toHexString(float f) {
 221.277 -        throw new UnsupportedOperationException();
 221.278 -//        if (Math.abs(f) < FloatConsts.MIN_NORMAL
 221.279 -//            &&  f != 0.0f ) {// float subnormal
 221.280 -//            // Adjust exponent to create subnormal double, then
 221.281 -//            // replace subnormal double exponent with subnormal float
 221.282 -//            // exponent
 221.283 -//            String s = Double.toHexString(FpUtils.scalb((double)f,
 221.284 -//                                                        /* -1022+126 */
 221.285 -//                                                        DoubleConsts.MIN_EXPONENT-
 221.286 -//                                                        FloatConsts.MIN_EXPONENT));
 221.287 -//            return s.replaceFirst("p-1022$", "p-126");
 221.288 -//        }
 221.289 -//        else // double string will be the same as float string
 221.290 -//            return Double.toHexString(f);
 221.291 -    }
 221.292 -
 221.293 -    /**
 221.294 -     * Returns a {@code Float} object holding the
 221.295 -     * {@code float} value represented by the argument string
 221.296 -     * {@code s}.
 221.297 -     *
 221.298 -     * <p>If {@code s} is {@code null}, then a
 221.299 -     * {@code NullPointerException} is thrown.
 221.300 -     *
 221.301 -     * <p>Leading and trailing whitespace characters in {@code s}
 221.302 -     * are ignored.  Whitespace is removed as if by the {@link
 221.303 -     * String#trim} method; that is, both ASCII space and control
 221.304 -     * characters are removed. The rest of {@code s} should
 221.305 -     * constitute a <i>FloatValue</i> as described by the lexical
 221.306 -     * syntax rules:
 221.307 -     *
 221.308 -     * <blockquote>
 221.309 -     * <dl>
 221.310 -     * <dt><i>FloatValue:</i>
 221.311 -     * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
 221.312 -     * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
 221.313 -     * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
 221.314 -     * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
 221.315 -     * <dd><i>SignedInteger</i>
 221.316 -     * </dl>
 221.317 -     *
 221.318 -     * <p>
 221.319 -     *
 221.320 -     * <dl>
 221.321 -     * <dt><i>HexFloatingPointLiteral</i>:
 221.322 -     * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
 221.323 -     * </dl>
 221.324 -     *
 221.325 -     * <p>
 221.326 -     *
 221.327 -     * <dl>
 221.328 -     * <dt><i>HexSignificand:</i>
 221.329 -     * <dd><i>HexNumeral</i>
 221.330 -     * <dd><i>HexNumeral</i> {@code .}
 221.331 -     * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
 221.332 -     *     </i>{@code .}<i> HexDigits</i>
 221.333 -     * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
 221.334 -     *     </i>{@code .} <i>HexDigits</i>
 221.335 -     * </dl>
 221.336 -     *
 221.337 -     * <p>
 221.338 -     *
 221.339 -     * <dl>
 221.340 -     * <dt><i>BinaryExponent:</i>
 221.341 -     * <dd><i>BinaryExponentIndicator SignedInteger</i>
 221.342 -     * </dl>
 221.343 -     *
 221.344 -     * <p>
 221.345 -     *
 221.346 -     * <dl>
 221.347 -     * <dt><i>BinaryExponentIndicator:</i>
 221.348 -     * <dd>{@code p}
 221.349 -     * <dd>{@code P}
 221.350 -     * </dl>
 221.351 -     *
 221.352 -     * </blockquote>
 221.353 -     *
 221.354 -     * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
 221.355 -     * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
 221.356 -     * <i>FloatTypeSuffix</i> are as defined in the lexical structure
 221.357 -     * sections of
 221.358 -     * <cite>The Java&trade; Language Specification</cite>,
 221.359 -     * except that underscores are not accepted between digits.
 221.360 -     * If {@code s} does not have the form of
 221.361 -     * a <i>FloatValue</i>, then a {@code NumberFormatException}
 221.362 -     * is thrown. Otherwise, {@code s} is regarded as
 221.363 -     * representing an exact decimal value in the usual
 221.364 -     * "computerized scientific notation" or as an exact
 221.365 -     * hexadecimal value; this exact numerical value is then
 221.366 -     * conceptually converted to an "infinitely precise"
 221.367 -     * binary value that is then rounded to type {@code float}
 221.368 -     * by the usual round-to-nearest rule of IEEE 754 floating-point
 221.369 -     * arithmetic, which includes preserving the sign of a zero
 221.370 -     * value.
 221.371 -     *
 221.372 -     * Note that the round-to-nearest rule also implies overflow and
 221.373 -     * underflow behaviour; if the exact value of {@code s} is large
 221.374 -     * enough in magnitude (greater than or equal to ({@link
 221.375 -     * #MAX_VALUE} + {@link Math#ulp(float) ulp(MAX_VALUE)}/2),
 221.376 -     * rounding to {@code float} will result in an infinity and if the
 221.377 -     * exact value of {@code s} is small enough in magnitude (less
 221.378 -     * than or equal to {@link #MIN_VALUE}/2), rounding to float will
 221.379 -     * result in a zero.
 221.380 -     *
 221.381 -     * Finally, after rounding a {@code Float} object representing
 221.382 -     * this {@code float} value is returned.
 221.383 -     *
 221.384 -     * <p>To interpret localized string representations of a
 221.385 -     * floating-point value, use subclasses of {@link
 221.386 -     * java.text.NumberFormat}.
 221.387 -     *
 221.388 -     * <p>Note that trailing format specifiers, specifiers that
 221.389 -     * determine the type of a floating-point literal
 221.390 -     * ({@code 1.0f} is a {@code float} value;
 221.391 -     * {@code 1.0d} is a {@code double} value), do
 221.392 -     * <em>not</em> influence the results of this method.  In other
 221.393 -     * words, the numerical value of the input string is converted
 221.394 -     * directly to the target floating-point type.  In general, the
 221.395 -     * two-step sequence of conversions, string to {@code double}
 221.396 -     * followed by {@code double} to {@code float}, is
 221.397 -     * <em>not</em> equivalent to converting a string directly to
 221.398 -     * {@code float}.  For example, if first converted to an
 221.399 -     * intermediate {@code double} and then to
 221.400 -     * {@code float}, the string<br>
 221.401 -     * {@code "1.00000017881393421514957253748434595763683319091796875001d"}<br>
 221.402 -     * results in the {@code float} value
 221.403 -     * {@code 1.0000002f}; if the string is converted directly to
 221.404 -     * {@code float}, <code>1.000000<b>1</b>f</code> results.
 221.405 -     *
 221.406 -     * <p>To avoid calling this method on an invalid string and having
 221.407 -     * a {@code NumberFormatException} be thrown, the documentation
 221.408 -     * for {@link Double#valueOf Double.valueOf} lists a regular
 221.409 -     * expression which can be used to screen the input.
 221.410 -     *
 221.411 -     * @param   s   the string to be parsed.
 221.412 -     * @return  a {@code Float} object holding the value
 221.413 -     *          represented by the {@code String} argument.
 221.414 -     * @throws  NumberFormatException  if the string does not contain a
 221.415 -     *          parsable number.
 221.416 -     */
 221.417 -    public static Float valueOf(String s) throws NumberFormatException {
 221.418 -        throw new UnsupportedOperationException();
 221.419 -//        return new Float(FloatingDecimal.readJavaFormatString(s).floatValue());
 221.420 -    }
 221.421 -
 221.422 -    /**
 221.423 -     * Returns a {@code Float} instance representing the specified
 221.424 -     * {@code float} value.
 221.425 -     * If a new {@code Float} instance is not required, this method
 221.426 -     * should generally be used in preference to the constructor
 221.427 -     * {@link #Float(float)}, as this method is likely to yield
 221.428 -     * significantly better space and time performance by caching
 221.429 -     * frequently requested values.
 221.430 -     *
 221.431 -     * @param  f a float value.
 221.432 -     * @return a {@code Float} instance representing {@code f}.
 221.433 -     * @since  1.5
 221.434 -     */
 221.435 -    public static Float valueOf(float f) {
 221.436 -        return new Float(f);
 221.437 -    }
 221.438 -
 221.439 -    /**
 221.440 -     * Returns a new {@code float} initialized to the value
 221.441 -     * represented by the specified {@code String}, as performed
 221.442 -     * by the {@code valueOf} method of class {@code Float}.
 221.443 -     *
 221.444 -     * @param  s the string to be parsed.
 221.445 -     * @return the {@code float} value represented by the string
 221.446 -     *         argument.
 221.447 -     * @throws NullPointerException  if the string is null
 221.448 -     * @throws NumberFormatException if the string does not contain a
 221.449 -     *               parsable {@code float}.
 221.450 -     * @see    java.lang.Float#valueOf(String)
 221.451 -     * @since 1.2
 221.452 -     */
 221.453 -    public static float parseFloat(String s) throws NumberFormatException {
 221.454 -        throw new UnsupportedOperationException();
 221.455 -//        return FloatingDecimal.readJavaFormatString(s).floatValue();
 221.456 -    }
 221.457 -
 221.458 -    /**
 221.459 -     * Returns {@code true} if the specified number is a
 221.460 -     * Not-a-Number (NaN) value, {@code false} otherwise.
 221.461 -     *
 221.462 -     * @param   v   the value to be tested.
 221.463 -     * @return  {@code true} if the argument is NaN;
 221.464 -     *          {@code false} otherwise.
 221.465 -     */
 221.466 -    static public boolean isNaN(float v) {
 221.467 -        return (v != v);
 221.468 -    }
 221.469 -
 221.470 -    /**
 221.471 -     * Returns {@code true} if the specified number is infinitely
 221.472 -     * large in magnitude, {@code false} otherwise.
 221.473 -     *
 221.474 -     * @param   v   the value to be tested.
 221.475 -     * @return  {@code true} if the argument is positive infinity or
 221.476 -     *          negative infinity; {@code false} otherwise.
 221.477 -     */
 221.478 -    static public boolean isInfinite(float v) {
 221.479 -        return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
 221.480 -    }
 221.481 -
 221.482 -    /**
 221.483 -     * The value of the Float.
 221.484 -     *
 221.485 -     * @serial
 221.486 -     */
 221.487 -    private final float value;
 221.488 -
 221.489 -    /**
 221.490 -     * Constructs a newly allocated {@code Float} object that
 221.491 -     * represents the primitive {@code float} argument.
 221.492 -     *
 221.493 -     * @param   value   the value to be represented by the {@code Float}.
 221.494 -     */
 221.495 -    public Float(float value) {
 221.496 -        this.value = value;
 221.497 -    }
 221.498 -
 221.499 -    /**
 221.500 -     * Constructs a newly allocated {@code Float} object that
 221.501 -     * represents the argument converted to type {@code float}.
 221.502 -     *
 221.503 -     * @param   value   the value to be represented by the {@code Float}.
 221.504 -     */
 221.505 -    public Float(double value) {
 221.506 -        this.value = (float)value;
 221.507 -    }
 221.508 -
 221.509 -    /**
 221.510 -     * Constructs a newly allocated {@code Float} object that
 221.511 -     * represents the floating-point value of type {@code float}
 221.512 -     * represented by the string. The string is converted to a
 221.513 -     * {@code float} value as if by the {@code valueOf} method.
 221.514 -     *
 221.515 -     * @param      s   a string to be converted to a {@code Float}.
 221.516 -     * @throws  NumberFormatException  if the string does not contain a
 221.517 -     *               parsable number.
 221.518 -     * @see        java.lang.Float#valueOf(java.lang.String)
 221.519 -     */
 221.520 -    public Float(String s) throws NumberFormatException {
 221.521 -        // REMIND: this is inefficient
 221.522 -        this(valueOf(s).floatValue());
 221.523 -    }
 221.524 -
 221.525 -    /**
 221.526 -     * Returns {@code true} if this {@code Float} value is a
 221.527 -     * Not-a-Number (NaN), {@code false} otherwise.
 221.528 -     *
 221.529 -     * @return  {@code true} if the value represented by this object is
 221.530 -     *          NaN; {@code false} otherwise.
 221.531 -     */
 221.532 -    public boolean isNaN() {
 221.533 -        return isNaN(value);
 221.534 -    }
 221.535 -
 221.536 -    /**
 221.537 -     * Returns {@code true} if this {@code Float} value is
 221.538 -     * infinitely large in magnitude, {@code false} otherwise.
 221.539 -     *
 221.540 -     * @return  {@code true} if the value represented by this object is
 221.541 -     *          positive infinity or negative infinity;
 221.542 -     *          {@code false} otherwise.
 221.543 -     */
 221.544 -    public boolean isInfinite() {
 221.545 -        return isInfinite(value);
 221.546 -    }
 221.547 -
 221.548 -    /**
 221.549 -     * Returns a string representation of this {@code Float} object.
 221.550 -     * The primitive {@code float} value represented by this object
 221.551 -     * is converted to a {@code String} exactly as if by the method
 221.552 -     * {@code toString} of one argument.
 221.553 -     *
 221.554 -     * @return  a {@code String} representation of this object.
 221.555 -     * @see java.lang.Float#toString(float)
 221.556 -     */
 221.557 -    public String toString() {
 221.558 -        return Float.toString(value);
 221.559 -    }
 221.560 -
 221.561 -    /**
 221.562 -     * Returns the value of this {@code Float} as a {@code byte} (by
 221.563 -     * casting to a {@code byte}).
 221.564 -     *
 221.565 -     * @return  the {@code float} value represented by this object
 221.566 -     *          converted to type {@code byte}
 221.567 -     */
 221.568 -    public byte byteValue() {
 221.569 -        return (byte)value;
 221.570 -    }
 221.571 -
 221.572 -    /**
 221.573 -     * Returns the value of this {@code Float} as a {@code short} (by
 221.574 -     * casting to a {@code short}).
 221.575 -     *
 221.576 -     * @return  the {@code float} value represented by this object
 221.577 -     *          converted to type {@code short}
 221.578 -     * @since JDK1.1
 221.579 -     */
 221.580 -    public short shortValue() {
 221.581 -        return (short)value;
 221.582 -    }
 221.583 -
 221.584 -    /**
 221.585 -     * Returns the value of this {@code Float} as an {@code int} (by
 221.586 -     * casting to type {@code int}).
 221.587 -     *
 221.588 -     * @return  the {@code float} value represented by this object
 221.589 -     *          converted to type {@code int}
 221.590 -     */
 221.591 -    public int intValue() {
 221.592 -        return (int)value;
 221.593 -    }
 221.594 -
 221.595 -    /**
 221.596 -     * Returns value of this {@code Float} as a {@code long} (by
 221.597 -     * casting to type {@code long}).
 221.598 -     *
 221.599 -     * @return  the {@code float} value represented by this object
 221.600 -     *          converted to type {@code long}
 221.601 -     */
 221.602 -    public long longValue() {
 221.603 -        return (long)value;
 221.604 -    }
 221.605 -
 221.606 -    /**
 221.607 -     * Returns the {@code float} value of this {@code Float} object.
 221.608 -     *
 221.609 -     * @return the {@code float} value represented by this object
 221.610 -     */
 221.611 -    public float floatValue() {
 221.612 -        return value;
 221.613 -    }
 221.614 -
 221.615 -    /**
 221.616 -     * Returns the {@code double} value of this {@code Float} object.
 221.617 -     *
 221.618 -     * @return the {@code float} value represented by this
 221.619 -     *         object is converted to type {@code double} and the
 221.620 -     *         result of the conversion is returned.
 221.621 -     */
 221.622 -    public double doubleValue() {
 221.623 -        return (double)value;
 221.624 -    }
 221.625 -
 221.626 -    /**
 221.627 -     * Returns a hash code for this {@code Float} object. The
 221.628 -     * result is the integer bit representation, exactly as produced
 221.629 -     * by the method {@link #floatToIntBits(float)}, of the primitive
 221.630 -     * {@code float} value represented by this {@code Float}
 221.631 -     * object.
 221.632 -     *
 221.633 -     * @return a hash code value for this object.
 221.634 -     */
 221.635 -    public int hashCode() {
 221.636 -        return floatToIntBits(value);
 221.637 -    }
 221.638 -
 221.639 -    /**
 221.640 -
 221.641 -     * Compares this object against the specified object.  The result
 221.642 -     * is {@code true} if and only if the argument is not
 221.643 -     * {@code null} and is a {@code Float} object that
 221.644 -     * represents a {@code float} with the same value as the
 221.645 -     * {@code float} represented by this object. For this
 221.646 -     * purpose, two {@code float} values are considered to be the
 221.647 -     * same if and only if the method {@link #floatToIntBits(float)}
 221.648 -     * returns the identical {@code int} value when applied to
 221.649 -     * each.
 221.650 -     *
 221.651 -     * <p>Note that in most cases, for two instances of class
 221.652 -     * {@code Float}, {@code f1} and {@code f2}, the value
 221.653 -     * of {@code f1.equals(f2)} is {@code true} if and only if
 221.654 -     *
 221.655 -     * <blockquote><pre>
 221.656 -     *   f1.floatValue() == f2.floatValue()
 221.657 -     * </pre></blockquote>
 221.658 -     *
 221.659 -     * <p>also has the value {@code true}. However, there are two exceptions:
 221.660 -     * <ul>
 221.661 -     * <li>If {@code f1} and {@code f2} both represent
 221.662 -     *     {@code Float.NaN}, then the {@code equals} method returns
 221.663 -     *     {@code true}, even though {@code Float.NaN==Float.NaN}
 221.664 -     *     has the value {@code false}.
 221.665 -     * <li>If {@code f1} represents {@code +0.0f} while
 221.666 -     *     {@code f2} represents {@code -0.0f}, or vice
 221.667 -     *     versa, the {@code equal} test has the value
 221.668 -     *     {@code false}, even though {@code 0.0f==-0.0f}
 221.669 -     *     has the value {@code true}.
 221.670 -     * </ul>
 221.671 -     *
 221.672 -     * This definition allows hash tables to operate properly.
 221.673 -     *
 221.674 -     * @param obj the object to be compared
 221.675 -     * @return  {@code true} if the objects are the same;
 221.676 -     *          {@code false} otherwise.
 221.677 -     * @see java.lang.Float#floatToIntBits(float)
 221.678 -     */
 221.679 -    public boolean equals(Object obj) {
 221.680 -        return (obj instanceof Float)
 221.681 -               && (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
 221.682 -    }
 221.683 -
 221.684 -    /**
 221.685 -     * Returns a representation of the specified floating-point value
 221.686 -     * according to the IEEE 754 floating-point "single format" bit
 221.687 -     * layout.
 221.688 -     *
 221.689 -     * <p>Bit 31 (the bit that is selected by the mask
 221.690 -     * {@code 0x80000000}) represents the sign of the floating-point
 221.691 -     * number.
 221.692 -     * Bits 30-23 (the bits that are selected by the mask
 221.693 -     * {@code 0x7f800000}) represent the exponent.
 221.694 -     * Bits 22-0 (the bits that are selected by the mask
 221.695 -     * {@code 0x007fffff}) represent the significand (sometimes called
 221.696 -     * the mantissa) of the floating-point number.
 221.697 -     *
 221.698 -     * <p>If the argument is positive infinity, the result is
 221.699 -     * {@code 0x7f800000}.
 221.700 -     *
 221.701 -     * <p>If the argument is negative infinity, the result is
 221.702 -     * {@code 0xff800000}.
 221.703 -     *
 221.704 -     * <p>If the argument is NaN, the result is {@code 0x7fc00000}.
 221.705 -     *
 221.706 -     * <p>In all cases, the result is an integer that, when given to the
 221.707 -     * {@link #intBitsToFloat(int)} method, will produce a floating-point
 221.708 -     * value the same as the argument to {@code floatToIntBits}
 221.709 -     * (except all NaN values are collapsed to a single
 221.710 -     * "canonical" NaN value).
 221.711 -     *
 221.712 -     * @param   value   a floating-point number.
 221.713 -     * @return the bits that represent the floating-point number.
 221.714 -     */
 221.715 -    public static int floatToIntBits(float value) {
 221.716 -        throw new UnsupportedOperationException();
 221.717 -//        int result = floatToRawIntBits(value);
 221.718 -//        // Check for NaN based on values of bit fields, maximum
 221.719 -//        // exponent and nonzero significand.
 221.720 -//        if ( ((result & FloatConsts.EXP_BIT_MASK) ==
 221.721 -//              FloatConsts.EXP_BIT_MASK) &&
 221.722 -//             (result & FloatConsts.SIGNIF_BIT_MASK) != 0)
 221.723 -//            result = 0x7fc00000;
 221.724 -//        return result;
 221.725 -    }
 221.726 -
 221.727 -    /**
 221.728 -     * Returns a representation of the specified floating-point value
 221.729 -     * according to the IEEE 754 floating-point "single format" bit
 221.730 -     * layout, preserving Not-a-Number (NaN) values.
 221.731 -     *
 221.732 -     * <p>Bit 31 (the bit that is selected by the mask
 221.733 -     * {@code 0x80000000}) represents the sign of the floating-point
 221.734 -     * number.
 221.735 -     * Bits 30-23 (the bits that are selected by the mask
 221.736 -     * {@code 0x7f800000}) represent the exponent.
 221.737 -     * Bits 22-0 (the bits that are selected by the mask
 221.738 -     * {@code 0x007fffff}) represent the significand (sometimes called
 221.739 -     * the mantissa) of the floating-point number.
 221.740 -     *
 221.741 -     * <p>If the argument is positive infinity, the result is
 221.742 -     * {@code 0x7f800000}.
 221.743 -     *
 221.744 -     * <p>If the argument is negative infinity, the result is
 221.745 -     * {@code 0xff800000}.
 221.746 -     *
 221.747 -     * <p>If the argument is NaN, the result is the integer representing
 221.748 -     * the actual NaN value.  Unlike the {@code floatToIntBits}
 221.749 -     * method, {@code floatToRawIntBits} does not collapse all the
 221.750 -     * bit patterns encoding a NaN to a single "canonical"
 221.751 -     * NaN value.
 221.752 -     *
 221.753 -     * <p>In all cases, the result is an integer that, when given to the
 221.754 -     * {@link #intBitsToFloat(int)} method, will produce a
 221.755 -     * floating-point value the same as the argument to
 221.756 -     * {@code floatToRawIntBits}.
 221.757 -     *
 221.758 -     * @param   value   a floating-point number.
 221.759 -     * @return the bits that represent the floating-point number.
 221.760 -     * @since 1.3
 221.761 -     */
 221.762 -    public static native int floatToRawIntBits(float value);
 221.763 -
 221.764 -    /**
 221.765 -     * Returns the {@code float} value corresponding to a given
 221.766 -     * bit representation.
 221.767 -     * The argument is considered to be a representation of a
 221.768 -     * floating-point value according to the IEEE 754 floating-point
 221.769 -     * "single format" bit layout.
 221.770 -     *
 221.771 -     * <p>If the argument is {@code 0x7f800000}, the result is positive
 221.772 -     * infinity.
 221.773 -     *
 221.774 -     * <p>If the argument is {@code 0xff800000}, the result is negative
 221.775 -     * infinity.
 221.776 -     *
 221.777 -     * <p>If the argument is any value in the range
 221.778 -     * {@code 0x7f800001} through {@code 0x7fffffff} or in
 221.779 -     * the range {@code 0xff800001} through
 221.780 -     * {@code 0xffffffff}, the result is a NaN.  No IEEE 754
 221.781 -     * floating-point operation provided by Java can distinguish
 221.782 -     * between two NaN values of the same type with different bit
 221.783 -     * patterns.  Distinct values of NaN are only distinguishable by
 221.784 -     * use of the {@code Float.floatToRawIntBits} method.
 221.785 -     *
 221.786 -     * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
 221.787 -     * values that can be computed from the argument:
 221.788 -     *
 221.789 -     * <blockquote><pre>
 221.790 -     * int s = ((bits &gt;&gt; 31) == 0) ? 1 : -1;
 221.791 -     * int e = ((bits &gt;&gt; 23) & 0xff);
 221.792 -     * int m = (e == 0) ?
 221.793 -     *                 (bits & 0x7fffff) &lt;&lt; 1 :
 221.794 -     *                 (bits & 0x7fffff) | 0x800000;
 221.795 -     * </pre></blockquote>
 221.796 -     *
 221.797 -     * Then the floating-point result equals the value of the mathematical
 221.798 -     * expression <i>s</i>&middot;<i>m</i>&middot;2<sup><i>e</i>-150</sup>.
 221.799 -     *
 221.800 -     * <p>Note that this method may not be able to return a
 221.801 -     * {@code float} NaN with exactly same bit pattern as the
 221.802 -     * {@code int} argument.  IEEE 754 distinguishes between two
 221.803 -     * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>.  The
 221.804 -     * differences between the two kinds of NaN are generally not
 221.805 -     * visible in Java.  Arithmetic operations on signaling NaNs turn
 221.806 -     * them into quiet NaNs with a different, but often similar, bit
 221.807 -     * pattern.  However, on some processors merely copying a
 221.808 -     * signaling NaN also performs that conversion.  In particular,
 221.809 -     * copying a signaling NaN to return it to the calling method may
 221.810 -     * perform this conversion.  So {@code intBitsToFloat} may
 221.811 -     * not be able to return a {@code float} with a signaling NaN
 221.812 -     * bit pattern.  Consequently, for some {@code int} values,
 221.813 -     * {@code floatToRawIntBits(intBitsToFloat(start))} may
 221.814 -     * <i>not</i> equal {@code start}.  Moreover, which
 221.815 -     * particular bit patterns represent signaling NaNs is platform
 221.816 -     * dependent; although all NaN bit patterns, quiet or signaling,
 221.817 -     * must be in the NaN range identified above.
 221.818 -     *
 221.819 -     * @param   bits   an integer.
 221.820 -     * @return  the {@code float} floating-point value with the same bit
 221.821 -     *          pattern.
 221.822 -     */
 221.823 -    @JavaScriptBody(args = "bits",
 221.824 -        body = 
 221.825 -          "if (bits === 0x7f800000) return Number.POSITIVE_INFINITY;\n"
 221.826 -        + "if (bits === 0xff800000) return Number.NEGATIVE_INFINITY;\n"
 221.827 -        + "if (bits >= 0x7f800001 && bits <= 0xffffffff) return Number.NaN;\n"
 221.828 -        + "var s = ((bits >> 31) == 0) ? 1 : -1;\n"
 221.829 -        + "var e = ((bits >> 23) & 0xff);\n"
 221.830 -        + "var m = (e == 0) ?\n"
 221.831 -        + "  (bits & 0x7fffff) << 1 :\n"
 221.832 -        + "  (bits & 0x7fffff) | 0x800000;\n"
 221.833 -        + "return s * m * Math.pow(2.0, e - 150);\n"
 221.834 -    )
 221.835 -    public static native float intBitsToFloat(int bits);
 221.836 -
 221.837 -    /**
 221.838 -     * Compares two {@code Float} objects numerically.  There are
 221.839 -     * two ways in which comparisons performed by this method differ
 221.840 -     * from those performed by the Java language numerical comparison
 221.841 -     * operators ({@code <, <=, ==, >=, >}) when
 221.842 -     * applied to primitive {@code float} values:
 221.843 -     *
 221.844 -     * <ul><li>
 221.845 -     *          {@code Float.NaN} is considered by this method to
 221.846 -     *          be equal to itself and greater than all other
 221.847 -     *          {@code float} values
 221.848 -     *          (including {@code Float.POSITIVE_INFINITY}).
 221.849 -     * <li>
 221.850 -     *          {@code 0.0f} is considered by this method to be greater
 221.851 -     *          than {@code -0.0f}.
 221.852 -     * </ul>
 221.853 -     *
 221.854 -     * This ensures that the <i>natural ordering</i> of {@code Float}
 221.855 -     * objects imposed by this method is <i>consistent with equals</i>.
 221.856 -     *
 221.857 -     * @param   anotherFloat   the {@code Float} to be compared.
 221.858 -     * @return  the value {@code 0} if {@code anotherFloat} is
 221.859 -     *          numerically equal to this {@code Float}; a value
 221.860 -     *          less than {@code 0} if this {@code Float}
 221.861 -     *          is numerically less than {@code anotherFloat};
 221.862 -     *          and a value greater than {@code 0} if this
 221.863 -     *          {@code Float} is numerically greater than
 221.864 -     *          {@code anotherFloat}.
 221.865 -     *
 221.866 -     * @since   1.2
 221.867 -     * @see Comparable#compareTo(Object)
 221.868 -     */
 221.869 -    public int compareTo(Float anotherFloat) {
 221.870 -        return Float.compare(value, anotherFloat.value);
 221.871 -    }
 221.872 -
 221.873 -    /**
 221.874 -     * Compares the two specified {@code float} values. The sign
 221.875 -     * of the integer value returned is the same as that of the
 221.876 -     * integer that would be returned by the call:
 221.877 -     * <pre>
 221.878 -     *    new Float(f1).compareTo(new Float(f2))
 221.879 -     * </pre>
 221.880 -     *
 221.881 -     * @param   f1        the first {@code float} to compare.
 221.882 -     * @param   f2        the second {@code float} to compare.
 221.883 -     * @return  the value {@code 0} if {@code f1} is
 221.884 -     *          numerically equal to {@code f2}; a value less than
 221.885 -     *          {@code 0} if {@code f1} is numerically less than
 221.886 -     *          {@code f2}; and a value greater than {@code 0}
 221.887 -     *          if {@code f1} is numerically greater than
 221.888 -     *          {@code f2}.
 221.889 -     * @since 1.4
 221.890 -     */
 221.891 -    public static int compare(float f1, float f2) {
 221.892 -        if (f1 < f2)
 221.893 -            return -1;           // Neither val is NaN, thisVal is smaller
 221.894 -        if (f1 > f2)
 221.895 -            return 1;            // Neither val is NaN, thisVal is larger
 221.896 -
 221.897 -        // Cannot use floatToRawIntBits because of possibility of NaNs.
 221.898 -        int thisBits    = Float.floatToIntBits(f1);
 221.899 -        int anotherBits = Float.floatToIntBits(f2);
 221.900 -
 221.901 -        return (thisBits == anotherBits ?  0 : // Values are equal
 221.902 -                (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
 221.903 -                 1));                          // (0.0, -0.0) or (NaN, !NaN)
 221.904 -    }
 221.905 -
 221.906 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 221.907 -    private static final long serialVersionUID = -2671257302660747028L;
 221.908 -}
   222.1 --- a/emul/src/main/java/java/lang/IllegalAccessException.java	Wed Dec 05 10:03:58 2012 +0100
   222.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   222.3 @@ -1,78 +0,0 @@
   222.4 -/*
   222.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   222.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   222.7 - *
   222.8 - * This code is free software; you can redistribute it and/or modify it
   222.9 - * under the terms of the GNU General Public License version 2 only, as
  222.10 - * published by the Free Software Foundation.  Oracle designates this
  222.11 - * particular file as subject to the "Classpath" exception as provided
  222.12 - * by Oracle in the LICENSE file that accompanied this code.
  222.13 - *
  222.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  222.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  222.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  222.17 - * version 2 for more details (a copy is included in the LICENSE file that
  222.18 - * accompanied this code).
  222.19 - *
  222.20 - * You should have received a copy of the GNU General Public License version
  222.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  222.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  222.23 - *
  222.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  222.25 - * or visit www.oracle.com if you need additional information or have any
  222.26 - * questions.
  222.27 - */
  222.28 -
  222.29 -package java.lang;
  222.30 -
  222.31 -/**
  222.32 - * An IllegalAccessException is thrown when an application tries
  222.33 - * to reflectively create an instance (other than an array),
  222.34 - * set or get a field, or invoke a method, but the currently
  222.35 - * executing method does not have access to the definition of
  222.36 - * the specified class, field, method or constructor.
  222.37 - *
  222.38 - * @author  unascribed
  222.39 - * @see     Class#newInstance()
  222.40 - * @see     java.lang.reflect.Field#set(Object, Object)
  222.41 - * @see     java.lang.reflect.Field#setBoolean(Object, boolean)
  222.42 - * @see     java.lang.reflect.Field#setByte(Object, byte)
  222.43 - * @see     java.lang.reflect.Field#setShort(Object, short)
  222.44 - * @see     java.lang.reflect.Field#setChar(Object, char)
  222.45 - * @see     java.lang.reflect.Field#setInt(Object, int)
  222.46 - * @see     java.lang.reflect.Field#setLong(Object, long)
  222.47 - * @see     java.lang.reflect.Field#setFloat(Object, float)
  222.48 - * @see     java.lang.reflect.Field#setDouble(Object, double)
  222.49 - * @see     java.lang.reflect.Field#get(Object)
  222.50 - * @see     java.lang.reflect.Field#getBoolean(Object)
  222.51 - * @see     java.lang.reflect.Field#getByte(Object)
  222.52 - * @see     java.lang.reflect.Field#getShort(Object)
  222.53 - * @see     java.lang.reflect.Field#getChar(Object)
  222.54 - * @see     java.lang.reflect.Field#getInt(Object)
  222.55 - * @see     java.lang.reflect.Field#getLong(Object)
  222.56 - * @see     java.lang.reflect.Field#getFloat(Object)
  222.57 - * @see     java.lang.reflect.Field#getDouble(Object)
  222.58 - * @see     java.lang.reflect.Method#invoke(Object, Object[])
  222.59 - * @see     java.lang.reflect.Constructor#newInstance(Object[])
  222.60 - * @since   JDK1.0
  222.61 - */
  222.62 -public class IllegalAccessException extends ReflectiveOperationException {
  222.63 -    private static final long serialVersionUID = 6616958222490762034L;
  222.64 -
  222.65 -    /**
  222.66 -     * Constructs an <code>IllegalAccessException</code> without a
  222.67 -     * detail message.
  222.68 -     */
  222.69 -    public IllegalAccessException() {
  222.70 -        super();
  222.71 -    }
  222.72 -
  222.73 -    /**
  222.74 -     * Constructs an <code>IllegalAccessException</code> with a detail message.
  222.75 -     *
  222.76 -     * @param   s   the detail message.
  222.77 -     */
  222.78 -    public IllegalAccessException(String s) {
  222.79 -        super(s);
  222.80 -    }
  222.81 -}
   223.1 --- a/emul/src/main/java/java/lang/IllegalArgumentException.java	Wed Dec 05 10:03:58 2012 +0100
   223.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   223.3 @@ -1,95 +0,0 @@
   223.4 -/*
   223.5 - * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
   223.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   223.7 - *
   223.8 - * This code is free software; you can redistribute it and/or modify it
   223.9 - * under the terms of the GNU General Public License version 2 only, as
  223.10 - * published by the Free Software Foundation.  Oracle designates this
  223.11 - * particular file as subject to the "Classpath" exception as provided
  223.12 - * by Oracle in the LICENSE file that accompanied this code.
  223.13 - *
  223.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  223.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  223.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  223.17 - * version 2 for more details (a copy is included in the LICENSE file that
  223.18 - * accompanied this code).
  223.19 - *
  223.20 - * You should have received a copy of the GNU General Public License version
  223.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  223.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  223.23 - *
  223.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  223.25 - * or visit www.oracle.com if you need additional information or have any
  223.26 - * questions.
  223.27 - */
  223.28 -
  223.29 -package java.lang;
  223.30 -
  223.31 -/**
  223.32 - * Thrown to indicate that a method has been passed an illegal or
  223.33 - * inappropriate argument.
  223.34 - *
  223.35 - * @author  unascribed
  223.36 - * @see     java.lang.Thread#setPriority(int)
  223.37 - * @since   JDK1.0
  223.38 - */
  223.39 -public
  223.40 -class IllegalArgumentException extends RuntimeException {
  223.41 -    /**
  223.42 -     * Constructs an <code>IllegalArgumentException</code> with no
  223.43 -     * detail message.
  223.44 -     */
  223.45 -    public IllegalArgumentException() {
  223.46 -        super();
  223.47 -    }
  223.48 -
  223.49 -    /**
  223.50 -     * Constructs an <code>IllegalArgumentException</code> with the
  223.51 -     * specified detail message.
  223.52 -     *
  223.53 -     * @param   s   the detail message.
  223.54 -     */
  223.55 -    public IllegalArgumentException(String s) {
  223.56 -        super(s);
  223.57 -    }
  223.58 -
  223.59 -    /**
  223.60 -     * Constructs a new exception with the specified detail message and
  223.61 -     * cause.
  223.62 -     *
  223.63 -     * <p>Note that the detail message associated with <code>cause</code> is
  223.64 -     * <i>not</i> automatically incorporated in this exception's detail
  223.65 -     * message.
  223.66 -     *
  223.67 -     * @param  message the detail message (which is saved for later retrieval
  223.68 -     *         by the {@link Throwable#getMessage()} method).
  223.69 -     * @param  cause the cause (which is saved for later retrieval by the
  223.70 -     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value
  223.71 -     *         is permitted, and indicates that the cause is nonexistent or
  223.72 -     *         unknown.)
  223.73 -     * @since 1.5
  223.74 -     */
  223.75 -    public IllegalArgumentException(String message, Throwable cause) {
  223.76 -        super(message, cause);
  223.77 -    }
  223.78 -
  223.79 -    /**
  223.80 -     * Constructs a new exception with the specified cause and a detail
  223.81 -     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  223.82 -     * typically contains the class and detail message of <tt>cause</tt>).
  223.83 -     * This constructor is useful for exceptions that are little more than
  223.84 -     * wrappers for other throwables (for example, {@link
  223.85 -     * java.security.PrivilegedActionException}).
  223.86 -     *
  223.87 -     * @param  cause the cause (which is saved for later retrieval by the
  223.88 -     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value is
  223.89 -     *         permitted, and indicates that the cause is nonexistent or
  223.90 -     *         unknown.)
  223.91 -     * @since  1.5
  223.92 -     */
  223.93 -    public IllegalArgumentException(Throwable cause) {
  223.94 -        super(cause);
  223.95 -    }
  223.96 -
  223.97 -    private static final long serialVersionUID = -5365630128856068164L;
  223.98 -}
   224.1 --- a/emul/src/main/java/java/lang/IllegalStateException.java	Wed Dec 05 10:03:58 2012 +0100
   224.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   224.3 @@ -1,97 +0,0 @@
   224.4 -/*
   224.5 - * Copyright (c) 1996, 2003, Oracle and/or its affiliates. All rights reserved.
   224.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   224.7 - *
   224.8 - * This code is free software; you can redistribute it and/or modify it
   224.9 - * under the terms of the GNU General Public License version 2 only, as
  224.10 - * published by the Free Software Foundation.  Oracle designates this
  224.11 - * particular file as subject to the "Classpath" exception as provided
  224.12 - * by Oracle in the LICENSE file that accompanied this code.
  224.13 - *
  224.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  224.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  224.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  224.17 - * version 2 for more details (a copy is included in the LICENSE file that
  224.18 - * accompanied this code).
  224.19 - *
  224.20 - * You should have received a copy of the GNU General Public License version
  224.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  224.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  224.23 - *
  224.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  224.25 - * or visit www.oracle.com if you need additional information or have any
  224.26 - * questions.
  224.27 - */
  224.28 -
  224.29 -package java.lang;
  224.30 -
  224.31 -/**
  224.32 - * Signals that a method has been invoked at an illegal or
  224.33 - * inappropriate time.  In other words, the Java environment or
  224.34 - * Java application is not in an appropriate state for the requested
  224.35 - * operation.
  224.36 - *
  224.37 - * @author  Jonni Kanerva
  224.38 - * @since   JDK1.1
  224.39 - */
  224.40 -public
  224.41 -class IllegalStateException extends RuntimeException {
  224.42 -    /**
  224.43 -     * Constructs an IllegalStateException with no detail message.
  224.44 -     * A detail message is a String that describes this particular exception.
  224.45 -     */
  224.46 -    public IllegalStateException() {
  224.47 -        super();
  224.48 -    }
  224.49 -
  224.50 -    /**
  224.51 -     * Constructs an IllegalStateException with the specified detail
  224.52 -     * message.  A detail message is a String that describes this particular
  224.53 -     * exception.
  224.54 -     *
  224.55 -     * @param s the String that contains a detailed message
  224.56 -     */
  224.57 -    public IllegalStateException(String s) {
  224.58 -        super(s);
  224.59 -    }
  224.60 -
  224.61 -    /**
  224.62 -     * Constructs a new exception with the specified detail message and
  224.63 -     * cause.
  224.64 -     *
  224.65 -     * <p>Note that the detail message associated with <code>cause</code> is
  224.66 -     * <i>not</i> automatically incorporated in this exception's detail
  224.67 -     * message.
  224.68 -     *
  224.69 -     * @param  message the detail message (which is saved for later retrieval
  224.70 -     *         by the {@link Throwable#getMessage()} method).
  224.71 -     * @param  cause the cause (which is saved for later retrieval by the
  224.72 -     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value
  224.73 -     *         is permitted, and indicates that the cause is nonexistent or
  224.74 -     *         unknown.)
  224.75 -     * @since 1.5
  224.76 -     */
  224.77 -    public IllegalStateException(String message, Throwable cause) {
  224.78 -        super(message, cause);
  224.79 -    }
  224.80 -
  224.81 -    /**
  224.82 -     * Constructs a new exception with the specified cause and a detail
  224.83 -     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  224.84 -     * typically contains the class and detail message of <tt>cause</tt>).
  224.85 -     * This constructor is useful for exceptions that are little more than
  224.86 -     * wrappers for other throwables (for example, {@link
  224.87 -     * java.security.PrivilegedActionException}).
  224.88 -     *
  224.89 -     * @param  cause the cause (which is saved for later retrieval by the
  224.90 -     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value is
  224.91 -     *         permitted, and indicates that the cause is nonexistent or
  224.92 -     *         unknown.)
  224.93 -     * @since  1.5
  224.94 -     */
  224.95 -    public IllegalStateException(Throwable cause) {
  224.96 -        super(cause);
  224.97 -    }
  224.98 -
  224.99 -    static final long serialVersionUID = -1848914673093119416L;
 224.100 -}
   225.1 --- a/emul/src/main/java/java/lang/IndexOutOfBoundsException.java	Wed Dec 05 10:03:58 2012 +0100
   225.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   225.3 @@ -1,58 +0,0 @@
   225.4 -/*
   225.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   225.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   225.7 - *
   225.8 - * This code is free software; you can redistribute it and/or modify it
   225.9 - * under the terms of the GNU General Public License version 2 only, as
  225.10 - * published by the Free Software Foundation.  Oracle designates this
  225.11 - * particular file as subject to the "Classpath" exception as provided
  225.12 - * by Oracle in the LICENSE file that accompanied this code.
  225.13 - *
  225.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  225.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  225.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  225.17 - * version 2 for more details (a copy is included in the LICENSE file that
  225.18 - * accompanied this code).
  225.19 - *
  225.20 - * You should have received a copy of the GNU General Public License version
  225.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  225.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  225.23 - *
  225.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  225.25 - * or visit www.oracle.com if you need additional information or have any
  225.26 - * questions.
  225.27 - */
  225.28 -
  225.29 -package java.lang;
  225.30 -
  225.31 -/**
  225.32 - * Thrown to indicate that an index of some sort (such as to an array, to a
  225.33 - * string, or to a vector) is out of range.
  225.34 - * <p>
  225.35 - * Applications can subclass this class to indicate similar exceptions.
  225.36 - *
  225.37 - * @author  Frank Yellin
  225.38 - * @since   JDK1.0
  225.39 - */
  225.40 -public
  225.41 -class IndexOutOfBoundsException extends RuntimeException {
  225.42 -    private static final long serialVersionUID = 234122996006267687L;
  225.43 -
  225.44 -    /**
  225.45 -     * Constructs an <code>IndexOutOfBoundsException</code> with no
  225.46 -     * detail message.
  225.47 -     */
  225.48 -    public IndexOutOfBoundsException() {
  225.49 -        super();
  225.50 -    }
  225.51 -
  225.52 -    /**
  225.53 -     * Constructs an <code>IndexOutOfBoundsException</code> with the
  225.54 -     * specified detail message.
  225.55 -     *
  225.56 -     * @param   s   the detail message.
  225.57 -     */
  225.58 -    public IndexOutOfBoundsException(String s) {
  225.59 -        super(s);
  225.60 -    }
  225.61 -}
   226.1 --- a/emul/src/main/java/java/lang/InstantiationException.java	Wed Dec 05 10:03:58 2012 +0100
   226.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   226.3 @@ -1,65 +0,0 @@
   226.4 -/*
   226.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   226.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   226.7 - *
   226.8 - * This code is free software; you can redistribute it and/or modify it
   226.9 - * under the terms of the GNU General Public License version 2 only, as
  226.10 - * published by the Free Software Foundation.  Oracle designates this
  226.11 - * particular file as subject to the "Classpath" exception as provided
  226.12 - * by Oracle in the LICENSE file that accompanied this code.
  226.13 - *
  226.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  226.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  226.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  226.17 - * version 2 for more details (a copy is included in the LICENSE file that
  226.18 - * accompanied this code).
  226.19 - *
  226.20 - * You should have received a copy of the GNU General Public License version
  226.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  226.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  226.23 - *
  226.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  226.25 - * or visit www.oracle.com if you need additional information or have any
  226.26 - * questions.
  226.27 - */
  226.28 -
  226.29 -package java.lang;
  226.30 -
  226.31 -/**
  226.32 - * Thrown when an application tries to create an instance of a class
  226.33 - * using the {@code newInstance} method in class
  226.34 - * {@code Class}, but the specified class object cannot be
  226.35 - * instantiated.  The instantiation can fail for a variety of
  226.36 - * reasons including but not limited to:
  226.37 - *
  226.38 - * <ul>
  226.39 - * <li> the class object represents an abstract class, an interface,
  226.40 - *      an array class, a primitive type, or {@code void}
  226.41 - * <li> the class has no nullary constructor
  226.42 - *</ul>
  226.43 - *
  226.44 - * @author  unascribed
  226.45 - * @see     java.lang.Class#newInstance()
  226.46 - * @since   JDK1.0
  226.47 - */
  226.48 -public
  226.49 -class InstantiationException extends ReflectiveOperationException {
  226.50 -    private static final long serialVersionUID = -8441929162975509110L;
  226.51 -
  226.52 -    /**
  226.53 -     * Constructs an {@code InstantiationException} with no detail message.
  226.54 -     */
  226.55 -    public InstantiationException() {
  226.56 -        super();
  226.57 -    }
  226.58 -
  226.59 -    /**
  226.60 -     * Constructs an {@code InstantiationException} with the
  226.61 -     * specified detail message.
  226.62 -     *
  226.63 -     * @param   s   the detail message.
  226.64 -     */
  226.65 -    public InstantiationException(String s) {
  226.66 -        super(s);
  226.67 -    }
  226.68 -}
   227.1 --- a/emul/src/main/java/java/lang/Integer.java	Wed Dec 05 10:03:58 2012 +0100
   227.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   227.3 @@ -1,1246 +0,0 @@
   227.4 -/*
   227.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   227.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   227.7 - *
   227.8 - * This code is free software; you can redistribute it and/or modify it
   227.9 - * under the terms of the GNU General Public License version 2 only, as
  227.10 - * published by the Free Software Foundation.  Oracle designates this
  227.11 - * particular file as subject to the "Classpath" exception as provided
  227.12 - * by Oracle in the LICENSE file that accompanied this code.
  227.13 - *
  227.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  227.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  227.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  227.17 - * version 2 for more details (a copy is included in the LICENSE file that
  227.18 - * accompanied this code).
  227.19 - *
  227.20 - * You should have received a copy of the GNU General Public License version
  227.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  227.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  227.23 - *
  227.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  227.25 - * or visit www.oracle.com if you need additional information or have any
  227.26 - * questions.
  227.27 - */
  227.28 -
  227.29 -package java.lang;
  227.30 -
  227.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  227.32 -
  227.33 -/**
  227.34 - * The {@code Integer} class wraps a value of the primitive type
  227.35 - * {@code int} in an object. An object of type {@code Integer}
  227.36 - * contains a single field whose type is {@code int}.
  227.37 - *
  227.38 - * <p>In addition, this class provides several methods for converting
  227.39 - * an {@code int} to a {@code String} and a {@code String} to an
  227.40 - * {@code int}, as well as other constants and methods useful when
  227.41 - * dealing with an {@code int}.
  227.42 - *
  227.43 - * <p>Implementation note: The implementations of the "bit twiddling"
  227.44 - * methods (such as {@link #highestOneBit(int) highestOneBit} and
  227.45 - * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
  227.46 - * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  227.47 - * Delight</i>, (Addison Wesley, 2002).
  227.48 - *
  227.49 - * @author  Lee Boynton
  227.50 - * @author  Arthur van Hoff
  227.51 - * @author  Josh Bloch
  227.52 - * @author  Joseph D. Darcy
  227.53 - * @since JDK1.0
  227.54 - */
  227.55 -public final class Integer extends Number implements Comparable<Integer> {
  227.56 -    /**
  227.57 -     * A constant holding the minimum value an {@code int} can
  227.58 -     * have, -2<sup>31</sup>.
  227.59 -     */
  227.60 -    public static final int   MIN_VALUE = 0x80000000;
  227.61 -
  227.62 -    /**
  227.63 -     * A constant holding the maximum value an {@code int} can
  227.64 -     * have, 2<sup>31</sup>-1.
  227.65 -     */
  227.66 -    public static final int   MAX_VALUE = 0x7fffffff;
  227.67 -
  227.68 -    /**
  227.69 -     * The {@code Class} instance representing the primitive type
  227.70 -     * {@code int}.
  227.71 -     *
  227.72 -     * @since   JDK1.1
  227.73 -     */
  227.74 -    public static final Class<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");
  227.75 -
  227.76 -    /**
  227.77 -     * All possible chars for representing a number as a String
  227.78 -     */
  227.79 -    final static char[] digits = {
  227.80 -        '0' , '1' , '2' , '3' , '4' , '5' ,
  227.81 -        '6' , '7' , '8' , '9' , 'a' , 'b' ,
  227.82 -        'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
  227.83 -        'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
  227.84 -        'o' , 'p' , 'q' , 'r' , 's' , 't' ,
  227.85 -        'u' , 'v' , 'w' , 'x' , 'y' , 'z'
  227.86 -    };
  227.87 -
  227.88 -    /**
  227.89 -     * Returns a string representation of the first argument in the
  227.90 -     * radix specified by the second argument.
  227.91 -     *
  227.92 -     * <p>If the radix is smaller than {@code Character.MIN_RADIX}
  227.93 -     * or larger than {@code Character.MAX_RADIX}, then the radix
  227.94 -     * {@code 10} is used instead.
  227.95 -     *
  227.96 -     * <p>If the first argument is negative, the first element of the
  227.97 -     * result is the ASCII minus character {@code '-'}
  227.98 -     * (<code>'&#92;u002D'</code>). If the first argument is not
  227.99 -     * negative, no sign character appears in the result.
 227.100 -     *
 227.101 -     * <p>The remaining characters of the result represent the magnitude
 227.102 -     * of the first argument. If the magnitude is zero, it is
 227.103 -     * represented by a single zero character {@code '0'}
 227.104 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 227.105 -     * the representation of the magnitude will not be the zero
 227.106 -     * character.  The following ASCII characters are used as digits:
 227.107 -     *
 227.108 -     * <blockquote>
 227.109 -     *   {@code 0123456789abcdefghijklmnopqrstuvwxyz}
 227.110 -     * </blockquote>
 227.111 -     *
 227.112 -     * These are <code>'&#92;u0030'</code> through
 227.113 -     * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
 227.114 -     * <code>'&#92;u007A'</code>. If {@code radix} is
 227.115 -     * <var>N</var>, then the first <var>N</var> of these characters
 227.116 -     * are used as radix-<var>N</var> digits in the order shown. Thus,
 227.117 -     * the digits for hexadecimal (radix 16) are
 227.118 -     * {@code 0123456789abcdef}. If uppercase letters are
 227.119 -     * desired, the {@link java.lang.String#toUpperCase()} method may
 227.120 -     * be called on the result:
 227.121 -     *
 227.122 -     * <blockquote>
 227.123 -     *  {@code Integer.toString(n, 16).toUpperCase()}
 227.124 -     * </blockquote>
 227.125 -     *
 227.126 -     * @param   i       an integer to be converted to a string.
 227.127 -     * @param   radix   the radix to use in the string representation.
 227.128 -     * @return  a string representation of the argument in the specified radix.
 227.129 -     * @see     java.lang.Character#MAX_RADIX
 227.130 -     * @see     java.lang.Character#MIN_RADIX
 227.131 -     */
 227.132 -    public static String toString(int i, int radix) {
 227.133 -
 227.134 -        if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
 227.135 -            radix = 10;
 227.136 -
 227.137 -        /* Use the faster version */
 227.138 -        if (radix == 10) {
 227.139 -            return toString(i);
 227.140 -        }
 227.141 -
 227.142 -        char buf[] = new char[33];
 227.143 -        boolean negative = (i < 0);
 227.144 -        int charPos = 32;
 227.145 -
 227.146 -        if (!negative) {
 227.147 -            i = -i;
 227.148 -        }
 227.149 -
 227.150 -        while (i <= -radix) {
 227.151 -            buf[charPos--] = digits[-(i % radix)];
 227.152 -            i = i / radix;
 227.153 -        }
 227.154 -        buf[charPos] = digits[-i];
 227.155 -
 227.156 -        if (negative) {
 227.157 -            buf[--charPos] = '-';
 227.158 -        }
 227.159 -
 227.160 -        return new String(buf, charPos, (33 - charPos));
 227.161 -    }
 227.162 -
 227.163 -    /**
 227.164 -     * Returns a string representation of the integer argument as an
 227.165 -     * unsigned integer in base&nbsp;16.
 227.166 -     *
 227.167 -     * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
 227.168 -     * if the argument is negative; otherwise, it is equal to the
 227.169 -     * argument.  This value is converted to a string of ASCII digits
 227.170 -     * in hexadecimal (base&nbsp;16) with no extra leading
 227.171 -     * {@code 0}s. If the unsigned magnitude is zero, it is
 227.172 -     * represented by a single zero character {@code '0'}
 227.173 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 227.174 -     * the representation of the unsigned magnitude will not be the
 227.175 -     * zero character. The following characters are used as
 227.176 -     * hexadecimal digits:
 227.177 -     *
 227.178 -     * <blockquote>
 227.179 -     *  {@code 0123456789abcdef}
 227.180 -     * </blockquote>
 227.181 -     *
 227.182 -     * These are the characters <code>'&#92;u0030'</code> through
 227.183 -     * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
 227.184 -     * <code>'&#92;u0066'</code>. If uppercase letters are
 227.185 -     * desired, the {@link java.lang.String#toUpperCase()} method may
 227.186 -     * be called on the result:
 227.187 -     *
 227.188 -     * <blockquote>
 227.189 -     *  {@code Integer.toHexString(n).toUpperCase()}
 227.190 -     * </blockquote>
 227.191 -     *
 227.192 -     * @param   i   an integer to be converted to a string.
 227.193 -     * @return  the string representation of the unsigned integer value
 227.194 -     *          represented by the argument in hexadecimal (base&nbsp;16).
 227.195 -     * @since   JDK1.0.2
 227.196 -     */
 227.197 -    public static String toHexString(int i) {
 227.198 -        return toUnsignedString(i, 4);
 227.199 -    }
 227.200 -
 227.201 -    /**
 227.202 -     * Returns a string representation of the integer argument as an
 227.203 -     * unsigned integer in base&nbsp;8.
 227.204 -     *
 227.205 -     * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
 227.206 -     * if the argument is negative; otherwise, it is equal to the
 227.207 -     * argument.  This value is converted to a string of ASCII digits
 227.208 -     * in octal (base&nbsp;8) with no extra leading {@code 0}s.
 227.209 -     *
 227.210 -     * <p>If the unsigned magnitude is zero, it is represented by a
 227.211 -     * single zero character {@code '0'}
 227.212 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 227.213 -     * the representation of the unsigned magnitude will not be the
 227.214 -     * zero character. The following characters are used as octal
 227.215 -     * digits:
 227.216 -     *
 227.217 -     * <blockquote>
 227.218 -     * {@code 01234567}
 227.219 -     * </blockquote>
 227.220 -     *
 227.221 -     * These are the characters <code>'&#92;u0030'</code> through
 227.222 -     * <code>'&#92;u0037'</code>.
 227.223 -     *
 227.224 -     * @param   i   an integer to be converted to a string.
 227.225 -     * @return  the string representation of the unsigned integer value
 227.226 -     *          represented by the argument in octal (base&nbsp;8).
 227.227 -     * @since   JDK1.0.2
 227.228 -     */
 227.229 -    public static String toOctalString(int i) {
 227.230 -        return toUnsignedString(i, 3);
 227.231 -    }
 227.232 -
 227.233 -    /**
 227.234 -     * Returns a string representation of the integer argument as an
 227.235 -     * unsigned integer in base&nbsp;2.
 227.236 -     *
 227.237 -     * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
 227.238 -     * if the argument is negative; otherwise it is equal to the
 227.239 -     * argument.  This value is converted to a string of ASCII digits
 227.240 -     * in binary (base&nbsp;2) with no extra leading {@code 0}s.
 227.241 -     * If the unsigned magnitude is zero, it is represented by a
 227.242 -     * single zero character {@code '0'}
 227.243 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 227.244 -     * the representation of the unsigned magnitude will not be the
 227.245 -     * zero character. The characters {@code '0'}
 227.246 -     * (<code>'&#92;u0030'</code>) and {@code '1'}
 227.247 -     * (<code>'&#92;u0031'</code>) are used as binary digits.
 227.248 -     *
 227.249 -     * @param   i   an integer to be converted to a string.
 227.250 -     * @return  the string representation of the unsigned integer value
 227.251 -     *          represented by the argument in binary (base&nbsp;2).
 227.252 -     * @since   JDK1.0.2
 227.253 -     */
 227.254 -    public static String toBinaryString(int i) {
 227.255 -        return toUnsignedString(i, 1);
 227.256 -    }
 227.257 -
 227.258 -    /**
 227.259 -     * Convert the integer to an unsigned number.
 227.260 -     */
 227.261 -    private static String toUnsignedString(int i, int shift) {
 227.262 -        char[] buf = new char[32];
 227.263 -        int charPos = 32;
 227.264 -        int radix = 1 << shift;
 227.265 -        int mask = radix - 1;
 227.266 -        do {
 227.267 -            buf[--charPos] = digits[i & mask];
 227.268 -            i >>>= shift;
 227.269 -        } while (i != 0);
 227.270 -
 227.271 -        return new String(buf, charPos, (32 - charPos));
 227.272 -    }
 227.273 -
 227.274 -
 227.275 -    final static char [] DigitTens = {
 227.276 -        '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
 227.277 -        '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
 227.278 -        '2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
 227.279 -        '3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
 227.280 -        '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
 227.281 -        '5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
 227.282 -        '6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
 227.283 -        '7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
 227.284 -        '8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
 227.285 -        '9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
 227.286 -        } ;
 227.287 -
 227.288 -    final static char [] DigitOnes = {
 227.289 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 227.290 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 227.291 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 227.292 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 227.293 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 227.294 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 227.295 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 227.296 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 227.297 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 227.298 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 227.299 -        } ;
 227.300 -
 227.301 -        // I use the "invariant division by multiplication" trick to
 227.302 -        // accelerate Integer.toString.  In particular we want to
 227.303 -        // avoid division by 10.
 227.304 -        //
 227.305 -        // The "trick" has roughly the same performance characteristics
 227.306 -        // as the "classic" Integer.toString code on a non-JIT VM.
 227.307 -        // The trick avoids .rem and .div calls but has a longer code
 227.308 -        // path and is thus dominated by dispatch overhead.  In the
 227.309 -        // JIT case the dispatch overhead doesn't exist and the
 227.310 -        // "trick" is considerably faster than the classic code.
 227.311 -        //
 227.312 -        // TODO-FIXME: convert (x * 52429) into the equiv shift-add
 227.313 -        // sequence.
 227.314 -        //
 227.315 -        // RE:  Division by Invariant Integers using Multiplication
 227.316 -        //      T Gralund, P Montgomery
 227.317 -        //      ACM PLDI 1994
 227.318 -        //
 227.319 -
 227.320 -    /**
 227.321 -     * Returns a {@code String} object representing the
 227.322 -     * specified integer. The argument is converted to signed decimal
 227.323 -     * representation and returned as a string, exactly as if the
 227.324 -     * argument and radix 10 were given as arguments to the {@link
 227.325 -     * #toString(int, int)} method.
 227.326 -     *
 227.327 -     * @param   i   an integer to be converted.
 227.328 -     * @return  a string representation of the argument in base&nbsp;10.
 227.329 -     */
 227.330 -    @JavaScriptBody(args = "i", body = "return i.toString();")
 227.331 -    public static String toString(int i) {
 227.332 -        if (i == Integer.MIN_VALUE)
 227.333 -            return "-2147483648";
 227.334 -        int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
 227.335 -        char[] buf = new char[size];
 227.336 -        getChars(i, size, buf);
 227.337 -        return new String(buf, 0, size);
 227.338 -    }
 227.339 -
 227.340 -    /**
 227.341 -     * Places characters representing the integer i into the
 227.342 -     * character array buf. The characters are placed into
 227.343 -     * the buffer backwards starting with the least significant
 227.344 -     * digit at the specified index (exclusive), and working
 227.345 -     * backwards from there.
 227.346 -     *
 227.347 -     * Will fail if i == Integer.MIN_VALUE
 227.348 -     */
 227.349 -    static void getChars(int i, int index, char[] buf) {
 227.350 -        int q, r;
 227.351 -        int charPos = index;
 227.352 -        char sign = 0;
 227.353 -
 227.354 -        if (i < 0) {
 227.355 -            sign = '-';
 227.356 -            i = -i;
 227.357 -        }
 227.358 -
 227.359 -        // Generate two digits per iteration
 227.360 -        while (i >= 65536) {
 227.361 -            q = i / 100;
 227.362 -        // really: r = i - (q * 100);
 227.363 -            r = i - ((q << 6) + (q << 5) + (q << 2));
 227.364 -            i = q;
 227.365 -            buf [--charPos] = DigitOnes[r];
 227.366 -            buf [--charPos] = DigitTens[r];
 227.367 -        }
 227.368 -
 227.369 -        // Fall thru to fast mode for smaller numbers
 227.370 -        // assert(i <= 65536, i);
 227.371 -        for (;;) {
 227.372 -            q = (i * 52429) >>> (16+3);
 227.373 -            r = i - ((q << 3) + (q << 1));  // r = i-(q*10) ...
 227.374 -            buf [--charPos] = digits [r];
 227.375 -            i = q;
 227.376 -            if (i == 0) break;
 227.377 -        }
 227.378 -        if (sign != 0) {
 227.379 -            buf [--charPos] = sign;
 227.380 -        }
 227.381 -    }
 227.382 -
 227.383 -    final static int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
 227.384 -                                      99999999, 999999999, Integer.MAX_VALUE };
 227.385 -
 227.386 -    // Requires positive x
 227.387 -    static int stringSize(int x) {
 227.388 -        for (int i=0; ; i++)
 227.389 -            if (x <= sizeTable[i])
 227.390 -                return i+1;
 227.391 -    }
 227.392 -
 227.393 -    /**
 227.394 -     * Parses the string argument as a signed integer in the radix
 227.395 -     * specified by the second argument. The characters in the string
 227.396 -     * must all be digits of the specified radix (as determined by
 227.397 -     * whether {@link java.lang.Character#digit(char, int)} returns a
 227.398 -     * nonnegative value), except that the first character may be an
 227.399 -     * ASCII minus sign {@code '-'} (<code>'&#92;u002D'</code>) to
 227.400 -     * indicate a negative value or an ASCII plus sign {@code '+'}
 227.401 -     * (<code>'&#92;u002B'</code>) to indicate a positive value. The
 227.402 -     * resulting integer value is returned.
 227.403 -     *
 227.404 -     * <p>An exception of type {@code NumberFormatException} is
 227.405 -     * thrown if any of the following situations occurs:
 227.406 -     * <ul>
 227.407 -     * <li>The first argument is {@code null} or is a string of
 227.408 -     * length zero.
 227.409 -     *
 227.410 -     * <li>The radix is either smaller than
 227.411 -     * {@link java.lang.Character#MIN_RADIX} or
 227.412 -     * larger than {@link java.lang.Character#MAX_RADIX}.
 227.413 -     *
 227.414 -     * <li>Any character of the string is not a digit of the specified
 227.415 -     * radix, except that the first character may be a minus sign
 227.416 -     * {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
 227.417 -     * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
 227.418 -     * string is longer than length 1.
 227.419 -     *
 227.420 -     * <li>The value represented by the string is not a value of type
 227.421 -     * {@code int}.
 227.422 -     * </ul>
 227.423 -     *
 227.424 -     * <p>Examples:
 227.425 -     * <blockquote><pre>
 227.426 -     * parseInt("0", 10) returns 0
 227.427 -     * parseInt("473", 10) returns 473
 227.428 -     * parseInt("+42", 10) returns 42
 227.429 -     * parseInt("-0", 10) returns 0
 227.430 -     * parseInt("-FF", 16) returns -255
 227.431 -     * parseInt("1100110", 2) returns 102
 227.432 -     * parseInt("2147483647", 10) returns 2147483647
 227.433 -     * parseInt("-2147483648", 10) returns -2147483648
 227.434 -     * parseInt("2147483648", 10) throws a NumberFormatException
 227.435 -     * parseInt("99", 8) throws a NumberFormatException
 227.436 -     * parseInt("Kona", 10) throws a NumberFormatException
 227.437 -     * parseInt("Kona", 27) returns 411787
 227.438 -     * </pre></blockquote>
 227.439 -     *
 227.440 -     * @param      s   the {@code String} containing the integer
 227.441 -     *                  representation to be parsed
 227.442 -     * @param      radix   the radix to be used while parsing {@code s}.
 227.443 -     * @return     the integer represented by the string argument in the
 227.444 -     *             specified radix.
 227.445 -     * @exception  NumberFormatException if the {@code String}
 227.446 -     *             does not contain a parsable {@code int}.
 227.447 -     */
 227.448 -    @JavaScriptBody(args={"s", "radix"}, body="return parseInt(s,radix);")
 227.449 -    public static int parseInt(String s, int radix)
 227.450 -                throws NumberFormatException
 227.451 -    {
 227.452 -        /*
 227.453 -         * WARNING: This method may be invoked early during VM initialization
 227.454 -         * before IntegerCache is initialized. Care must be taken to not use
 227.455 -         * the valueOf method.
 227.456 -         */
 227.457 -
 227.458 -        if (s == null) {
 227.459 -            throw new NumberFormatException("null");
 227.460 -        }
 227.461 -
 227.462 -        if (radix < Character.MIN_RADIX) {
 227.463 -            throw new NumberFormatException("radix " + radix +
 227.464 -                                            " less than Character.MIN_RADIX");
 227.465 -        }
 227.466 -
 227.467 -        if (radix > Character.MAX_RADIX) {
 227.468 -            throw new NumberFormatException("radix " + radix +
 227.469 -                                            " greater than Character.MAX_RADIX");
 227.470 -        }
 227.471 -
 227.472 -        int result = 0;
 227.473 -        boolean negative = false;
 227.474 -        int i = 0, len = s.length();
 227.475 -        int limit = -Integer.MAX_VALUE;
 227.476 -        int multmin;
 227.477 -        int digit;
 227.478 -
 227.479 -        if (len > 0) {
 227.480 -            char firstChar = s.charAt(0);
 227.481 -            if (firstChar < '0') { // Possible leading "+" or "-"
 227.482 -                if (firstChar == '-') {
 227.483 -                    negative = true;
 227.484 -                    limit = Integer.MIN_VALUE;
 227.485 -                } else if (firstChar != '+')
 227.486 -                    throw NumberFormatException.forInputString(s);
 227.487 -
 227.488 -                if (len == 1) // Cannot have lone "+" or "-"
 227.489 -                    throw NumberFormatException.forInputString(s);
 227.490 -                i++;
 227.491 -            }
 227.492 -            multmin = limit / radix;
 227.493 -            while (i < len) {
 227.494 -                // Accumulating negatively avoids surprises near MAX_VALUE
 227.495 -                digit = Character.digit(s.charAt(i++),radix);
 227.496 -                if (digit < 0) {
 227.497 -                    throw NumberFormatException.forInputString(s);
 227.498 -                }
 227.499 -                if (result < multmin) {
 227.500 -                    throw NumberFormatException.forInputString(s);
 227.501 -                }
 227.502 -                result *= radix;
 227.503 -                if (result < limit + digit) {
 227.504 -                    throw NumberFormatException.forInputString(s);
 227.505 -                }
 227.506 -                result -= digit;
 227.507 -            }
 227.508 -        } else {
 227.509 -            throw NumberFormatException.forInputString(s);
 227.510 -        }
 227.511 -        return negative ? result : -result;
 227.512 -    }
 227.513 -
 227.514 -    /**
 227.515 -     * Parses the string argument as a signed decimal integer. The
 227.516 -     * characters in the string must all be decimal digits, except
 227.517 -     * that the first character may be an ASCII minus sign {@code '-'}
 227.518 -     * (<code>'&#92;u002D'</code>) to indicate a negative value or an
 227.519 -     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
 227.520 -     * indicate a positive value. The resulting integer value is
 227.521 -     * returned, exactly as if the argument and the radix 10 were
 227.522 -     * given as arguments to the {@link #parseInt(java.lang.String,
 227.523 -     * int)} method.
 227.524 -     *
 227.525 -     * @param s    a {@code String} containing the {@code int}
 227.526 -     *             representation to be parsed
 227.527 -     * @return     the integer value represented by the argument in decimal.
 227.528 -     * @exception  NumberFormatException  if the string does not contain a
 227.529 -     *               parsable integer.
 227.530 -     */
 227.531 -    public static int parseInt(String s) throws NumberFormatException {
 227.532 -        return parseInt(s,10);
 227.533 -    }
 227.534 -
 227.535 -    /**
 227.536 -     * Returns an {@code Integer} object holding the value
 227.537 -     * extracted from the specified {@code String} when parsed
 227.538 -     * with the radix given by the second argument. The first argument
 227.539 -     * is interpreted as representing a signed integer in the radix
 227.540 -     * specified by the second argument, exactly as if the arguments
 227.541 -     * were given to the {@link #parseInt(java.lang.String, int)}
 227.542 -     * method. The result is an {@code Integer} object that
 227.543 -     * represents the integer value specified by the string.
 227.544 -     *
 227.545 -     * <p>In other words, this method returns an {@code Integer}
 227.546 -     * object equal to the value of:
 227.547 -     *
 227.548 -     * <blockquote>
 227.549 -     *  {@code new Integer(Integer.parseInt(s, radix))}
 227.550 -     * </blockquote>
 227.551 -     *
 227.552 -     * @param      s   the string to be parsed.
 227.553 -     * @param      radix the radix to be used in interpreting {@code s}
 227.554 -     * @return     an {@code Integer} object holding the value
 227.555 -     *             represented by the string argument in the specified
 227.556 -     *             radix.
 227.557 -     * @exception NumberFormatException if the {@code String}
 227.558 -     *            does not contain a parsable {@code int}.
 227.559 -     */
 227.560 -    public static Integer valueOf(String s, int radix) throws NumberFormatException {
 227.561 -        return Integer.valueOf(parseInt(s,radix));
 227.562 -    }
 227.563 -
 227.564 -    /**
 227.565 -     * Returns an {@code Integer} object holding the
 227.566 -     * value of the specified {@code String}. The argument is
 227.567 -     * interpreted as representing a signed decimal integer, exactly
 227.568 -     * as if the argument were given to the {@link
 227.569 -     * #parseInt(java.lang.String)} method. The result is an
 227.570 -     * {@code Integer} object that represents the integer value
 227.571 -     * specified by the string.
 227.572 -     *
 227.573 -     * <p>In other words, this method returns an {@code Integer}
 227.574 -     * object equal to the value of:
 227.575 -     *
 227.576 -     * <blockquote>
 227.577 -     *  {@code new Integer(Integer.parseInt(s))}
 227.578 -     * </blockquote>
 227.579 -     *
 227.580 -     * @param      s   the string to be parsed.
 227.581 -     * @return     an {@code Integer} object holding the value
 227.582 -     *             represented by the string argument.
 227.583 -     * @exception  NumberFormatException  if the string cannot be parsed
 227.584 -     *             as an integer.
 227.585 -     */
 227.586 -    public static Integer valueOf(String s) throws NumberFormatException {
 227.587 -        return Integer.valueOf(parseInt(s, 10));
 227.588 -    }
 227.589 -
 227.590 -    /**
 227.591 -     * Cache to support the object identity semantics of autoboxing for values between
 227.592 -     * -128 and 127 (inclusive) as required by JLS.
 227.593 -     *
 227.594 -     * The cache is initialized on first usage.  The size of the cache
 227.595 -     * may be controlled by the -XX:AutoBoxCacheMax=<size> option.
 227.596 -     * During VM initialization, java.lang.Integer.IntegerCache.high property
 227.597 -     * may be set and saved in the private system properties in the
 227.598 -     * sun.misc.VM class.
 227.599 -     */
 227.600 -
 227.601 -    private static class IntegerCache {
 227.602 -        static final int low = -128;
 227.603 -        static final int high;
 227.604 -        static final Integer cache[];
 227.605 -
 227.606 -        static {
 227.607 -            // high value may be configured by property
 227.608 -            int h = 127;
 227.609 -            String integerCacheHighPropValue =
 227.610 -                AbstractStringBuilder.getProperty("java.lang.Integer.IntegerCache.high");
 227.611 -            if (integerCacheHighPropValue != null) {
 227.612 -                int i = parseInt(integerCacheHighPropValue);
 227.613 -                i = Math.max(i, 127);
 227.614 -                // Maximum array size is Integer.MAX_VALUE
 227.615 -                h = Math.min(i, Integer.MAX_VALUE - (-low));
 227.616 -            }
 227.617 -            high = h;
 227.618 -
 227.619 -            cache = new Integer[(high - low) + 1];
 227.620 -            int j = low;
 227.621 -            for(int k = 0; k < cache.length; k++)
 227.622 -                cache[k] = new Integer(j++);
 227.623 -        }
 227.624 -
 227.625 -        private IntegerCache() {}
 227.626 -    }
 227.627 -
 227.628 -    /**
 227.629 -     * Returns an {@code Integer} instance representing the specified
 227.630 -     * {@code int} value.  If a new {@code Integer} instance is not
 227.631 -     * required, this method should generally be used in preference to
 227.632 -     * the constructor {@link #Integer(int)}, as this method is likely
 227.633 -     * to yield significantly better space and time performance by
 227.634 -     * caching frequently requested values.
 227.635 -     *
 227.636 -     * This method will always cache values in the range -128 to 127,
 227.637 -     * inclusive, and may cache other values outside of this range.
 227.638 -     *
 227.639 -     * @param  i an {@code int} value.
 227.640 -     * @return an {@code Integer} instance representing {@code i}.
 227.641 -     * @since  1.5
 227.642 -     */
 227.643 -    public static Integer valueOf(int i) {
 227.644 -        //assert IntegerCache.high >= 127;
 227.645 -        if (i >= IntegerCache.low && i <= IntegerCache.high)
 227.646 -            return IntegerCache.cache[i + (-IntegerCache.low)];
 227.647 -        return new Integer(i);
 227.648 -    }
 227.649 -
 227.650 -    /**
 227.651 -     * The value of the {@code Integer}.
 227.652 -     *
 227.653 -     * @serial
 227.654 -     */
 227.655 -    private final int value;
 227.656 -
 227.657 -    /**
 227.658 -     * Constructs a newly allocated {@code Integer} object that
 227.659 -     * represents the specified {@code int} value.
 227.660 -     *
 227.661 -     * @param   value   the value to be represented by the
 227.662 -     *                  {@code Integer} object.
 227.663 -     */
 227.664 -    public Integer(int value) {
 227.665 -        this.value = value;
 227.666 -    }
 227.667 -
 227.668 -    /**
 227.669 -     * Constructs a newly allocated {@code Integer} object that
 227.670 -     * represents the {@code int} value indicated by the
 227.671 -     * {@code String} parameter. The string is converted to an
 227.672 -     * {@code int} value in exactly the manner used by the
 227.673 -     * {@code parseInt} method for radix 10.
 227.674 -     *
 227.675 -     * @param      s   the {@code String} to be converted to an
 227.676 -     *                 {@code Integer}.
 227.677 -     * @exception  NumberFormatException  if the {@code String} does not
 227.678 -     *               contain a parsable integer.
 227.679 -     * @see        java.lang.Integer#parseInt(java.lang.String, int)
 227.680 -     */
 227.681 -    public Integer(String s) throws NumberFormatException {
 227.682 -        this.value = parseInt(s, 10);
 227.683 -    }
 227.684 -
 227.685 -    /**
 227.686 -     * Returns the value of this {@code Integer} as a
 227.687 -     * {@code byte}.
 227.688 -     */
 227.689 -    public byte byteValue() {
 227.690 -        return (byte)value;
 227.691 -    }
 227.692 -
 227.693 -    /**
 227.694 -     * Returns the value of this {@code Integer} as a
 227.695 -     * {@code short}.
 227.696 -     */
 227.697 -    public short shortValue() {
 227.698 -        return (short)value;
 227.699 -    }
 227.700 -
 227.701 -    /**
 227.702 -     * Returns the value of this {@code Integer} as an
 227.703 -     * {@code int}.
 227.704 -     */
 227.705 -    public int intValue() {
 227.706 -        return value;
 227.707 -    }
 227.708 -
 227.709 -    /**
 227.710 -     * Returns the value of this {@code Integer} as a
 227.711 -     * {@code long}.
 227.712 -     */
 227.713 -    public long longValue() {
 227.714 -        return (long)value;
 227.715 -    }
 227.716 -
 227.717 -    /**
 227.718 -     * Returns the value of this {@code Integer} as a
 227.719 -     * {@code float}.
 227.720 -     */
 227.721 -    public float floatValue() {
 227.722 -        return (float)value;
 227.723 -    }
 227.724 -
 227.725 -    /**
 227.726 -     * Returns the value of this {@code Integer} as a
 227.727 -     * {@code double}.
 227.728 -     */
 227.729 -    public double doubleValue() {
 227.730 -        return (double)value;
 227.731 -    }
 227.732 -
 227.733 -    /**
 227.734 -     * Returns a {@code String} object representing this
 227.735 -     * {@code Integer}'s value. The value is converted to signed
 227.736 -     * decimal representation and returned as a string, exactly as if
 227.737 -     * the integer value were given as an argument to the {@link
 227.738 -     * java.lang.Integer#toString(int)} method.
 227.739 -     *
 227.740 -     * @return  a string representation of the value of this object in
 227.741 -     *          base&nbsp;10.
 227.742 -     */
 227.743 -    public String toString() {
 227.744 -        return toString(value);
 227.745 -    }
 227.746 -
 227.747 -    /**
 227.748 -     * Returns a hash code for this {@code Integer}.
 227.749 -     *
 227.750 -     * @return  a hash code value for this object, equal to the
 227.751 -     *          primitive {@code int} value represented by this
 227.752 -     *          {@code Integer} object.
 227.753 -     */
 227.754 -    public int hashCode() {
 227.755 -        return value;
 227.756 -    }
 227.757 -
 227.758 -    /**
 227.759 -     * Compares this object to the specified object.  The result is
 227.760 -     * {@code true} if and only if the argument is not
 227.761 -     * {@code null} and is an {@code Integer} object that
 227.762 -     * contains the same {@code int} value as this object.
 227.763 -     *
 227.764 -     * @param   obj   the object to compare with.
 227.765 -     * @return  {@code true} if the objects are the same;
 227.766 -     *          {@code false} otherwise.
 227.767 -     */
 227.768 -    public boolean equals(Object obj) {
 227.769 -        if (obj instanceof Integer) {
 227.770 -            return value == ((Integer)obj).intValue();
 227.771 -        }
 227.772 -        return false;
 227.773 -    }
 227.774 -
 227.775 -    /**
 227.776 -     * Determines the integer value of the system property with the
 227.777 -     * specified name.
 227.778 -     *
 227.779 -     * <p>The first argument is treated as the name of a system property.
 227.780 -     * System properties are accessible through the
 227.781 -     * {@link java.lang.System#getProperty(java.lang.String)} method. The
 227.782 -     * string value of this property is then interpreted as an integer
 227.783 -     * value and an {@code Integer} object representing this value is
 227.784 -     * returned. Details of possible numeric formats can be found with
 227.785 -     * the definition of {@code getProperty}.
 227.786 -     *
 227.787 -     * <p>If there is no property with the specified name, if the specified name
 227.788 -     * is empty or {@code null}, or if the property does not have
 227.789 -     * the correct numeric format, then {@code null} is returned.
 227.790 -     *
 227.791 -     * <p>In other words, this method returns an {@code Integer}
 227.792 -     * object equal to the value of:
 227.793 -     *
 227.794 -     * <blockquote>
 227.795 -     *  {@code getInteger(nm, null)}
 227.796 -     * </blockquote>
 227.797 -     *
 227.798 -     * @param   nm   property name.
 227.799 -     * @return  the {@code Integer} value of the property.
 227.800 -     * @see     java.lang.System#getProperty(java.lang.String)
 227.801 -     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 227.802 -     */
 227.803 -    public static Integer getInteger(String nm) {
 227.804 -        return getInteger(nm, null);
 227.805 -    }
 227.806 -
 227.807 -    /**
 227.808 -     * Determines the integer value of the system property with the
 227.809 -     * specified name.
 227.810 -     *
 227.811 -     * <p>The first argument is treated as the name of a system property.
 227.812 -     * System properties are accessible through the {@link
 227.813 -     * java.lang.System#getProperty(java.lang.String)} method. The
 227.814 -     * string value of this property is then interpreted as an integer
 227.815 -     * value and an {@code Integer} object representing this value is
 227.816 -     * returned. Details of possible numeric formats can be found with
 227.817 -     * the definition of {@code getProperty}.
 227.818 -     *
 227.819 -     * <p>The second argument is the default value. An {@code Integer} object
 227.820 -     * that represents the value of the second argument is returned if there
 227.821 -     * is no property of the specified name, if the property does not have
 227.822 -     * the correct numeric format, or if the specified name is empty or
 227.823 -     * {@code null}.
 227.824 -     *
 227.825 -     * <p>In other words, this method returns an {@code Integer} object
 227.826 -     * equal to the value of:
 227.827 -     *
 227.828 -     * <blockquote>
 227.829 -     *  {@code getInteger(nm, new Integer(val))}
 227.830 -     * </blockquote>
 227.831 -     *
 227.832 -     * but in practice it may be implemented in a manner such as:
 227.833 -     *
 227.834 -     * <blockquote><pre>
 227.835 -     * Integer result = getInteger(nm, null);
 227.836 -     * return (result == null) ? new Integer(val) : result;
 227.837 -     * </pre></blockquote>
 227.838 -     *
 227.839 -     * to avoid the unnecessary allocation of an {@code Integer}
 227.840 -     * object when the default value is not needed.
 227.841 -     *
 227.842 -     * @param   nm   property name.
 227.843 -     * @param   val   default value.
 227.844 -     * @return  the {@code Integer} value of the property.
 227.845 -     * @see     java.lang.System#getProperty(java.lang.String)
 227.846 -     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 227.847 -     */
 227.848 -    public static Integer getInteger(String nm, int val) {
 227.849 -        Integer result = getInteger(nm, null);
 227.850 -        return (result == null) ? Integer.valueOf(val) : result;
 227.851 -    }
 227.852 -
 227.853 -    /**
 227.854 -     * Returns the integer value of the system property with the
 227.855 -     * specified name.  The first argument is treated as the name of a
 227.856 -     * system property.  System properties are accessible through the
 227.857 -     * {@link java.lang.System#getProperty(java.lang.String)} method.
 227.858 -     * The string value of this property is then interpreted as an
 227.859 -     * integer value, as per the {@code Integer.decode} method,
 227.860 -     * and an {@code Integer} object representing this value is
 227.861 -     * returned.
 227.862 -     *
 227.863 -     * <ul><li>If the property value begins with the two ASCII characters
 227.864 -     *         {@code 0x} or the ASCII character {@code #}, not
 227.865 -     *      followed by a minus sign, then the rest of it is parsed as a
 227.866 -     *      hexadecimal integer exactly as by the method
 227.867 -     *      {@link #valueOf(java.lang.String, int)} with radix 16.
 227.868 -     * <li>If the property value begins with the ASCII character
 227.869 -     *     {@code 0} followed by another character, it is parsed as an
 227.870 -     *     octal integer exactly as by the method
 227.871 -     *     {@link #valueOf(java.lang.String, int)} with radix 8.
 227.872 -     * <li>Otherwise, the property value is parsed as a decimal integer
 227.873 -     * exactly as by the method {@link #valueOf(java.lang.String, int)}
 227.874 -     * with radix 10.
 227.875 -     * </ul>
 227.876 -     *
 227.877 -     * <p>The second argument is the default value. The default value is
 227.878 -     * returned if there is no property of the specified name, if the
 227.879 -     * property does not have the correct numeric format, or if the
 227.880 -     * specified name is empty or {@code null}.
 227.881 -     *
 227.882 -     * @param   nm   property name.
 227.883 -     * @param   val   default value.
 227.884 -     * @return  the {@code Integer} value of the property.
 227.885 -     * @see     java.lang.System#getProperty(java.lang.String)
 227.886 -     * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
 227.887 -     * @see java.lang.Integer#decode
 227.888 -     */
 227.889 -    public static Integer getInteger(String nm, Integer val) {
 227.890 -        String v = null;
 227.891 -        try {
 227.892 -            v = AbstractStringBuilder.getProperty(nm);
 227.893 -        } catch (IllegalArgumentException e) {
 227.894 -        } catch (NullPointerException e) {
 227.895 -        }
 227.896 -        if (v != null) {
 227.897 -            try {
 227.898 -                return Integer.decode(v);
 227.899 -            } catch (NumberFormatException e) {
 227.900 -            }
 227.901 -        }
 227.902 -        return val;
 227.903 -    }
 227.904 -
 227.905 -    /**
 227.906 -     * Decodes a {@code String} into an {@code Integer}.
 227.907 -     * Accepts decimal, hexadecimal, and octal numbers given
 227.908 -     * by the following grammar:
 227.909 -     *
 227.910 -     * <blockquote>
 227.911 -     * <dl>
 227.912 -     * <dt><i>DecodableString:</i>
 227.913 -     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 227.914 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 227.915 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 227.916 -     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 227.917 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 227.918 -     * <p>
 227.919 -     * <dt><i>Sign:</i>
 227.920 -     * <dd>{@code -}
 227.921 -     * <dd>{@code +}
 227.922 -     * </dl>
 227.923 -     * </blockquote>
 227.924 -     *
 227.925 -     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 227.926 -     * are as defined in section 3.10.1 of
 227.927 -     * <cite>The Java&trade; Language Specification</cite>,
 227.928 -     * except that underscores are not accepted between digits.
 227.929 -     *
 227.930 -     * <p>The sequence of characters following an optional
 227.931 -     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 227.932 -     * "{@code #}", or leading zero) is parsed as by the {@code
 227.933 -     * Integer.parseInt} method with the indicated radix (10, 16, or
 227.934 -     * 8).  This sequence of characters must represent a positive
 227.935 -     * value or a {@link NumberFormatException} will be thrown.  The
 227.936 -     * result is negated if first character of the specified {@code
 227.937 -     * String} is the minus sign.  No whitespace characters are
 227.938 -     * permitted in the {@code String}.
 227.939 -     *
 227.940 -     * @param     nm the {@code String} to decode.
 227.941 -     * @return    an {@code Integer} object holding the {@code int}
 227.942 -     *             value represented by {@code nm}
 227.943 -     * @exception NumberFormatException  if the {@code String} does not
 227.944 -     *            contain a parsable integer.
 227.945 -     * @see java.lang.Integer#parseInt(java.lang.String, int)
 227.946 -     */
 227.947 -    public static Integer decode(String nm) throws NumberFormatException {
 227.948 -        int radix = 10;
 227.949 -        int index = 0;
 227.950 -        boolean negative = false;
 227.951 -        Integer result;
 227.952 -
 227.953 -        if (nm.length() == 0)
 227.954 -            throw new NumberFormatException("Zero length string");
 227.955 -        char firstChar = nm.charAt(0);
 227.956 -        // Handle sign, if present
 227.957 -        if (firstChar == '-') {
 227.958 -            negative = true;
 227.959 -            index++;
 227.960 -        } else if (firstChar == '+')
 227.961 -            index++;
 227.962 -
 227.963 -        // Handle radix specifier, if present
 227.964 -        if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
 227.965 -            index += 2;
 227.966 -            radix = 16;
 227.967 -        }
 227.968 -        else if (nm.startsWith("#", index)) {
 227.969 -            index ++;
 227.970 -            radix = 16;
 227.971 -        }
 227.972 -        else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
 227.973 -            index ++;
 227.974 -            radix = 8;
 227.975 -        }
 227.976 -
 227.977 -        if (nm.startsWith("-", index) || nm.startsWith("+", index))
 227.978 -            throw new NumberFormatException("Sign character in wrong position");
 227.979 -
 227.980 -        try {
 227.981 -            result = Integer.valueOf(nm.substring(index), radix);
 227.982 -            result = negative ? Integer.valueOf(-result.intValue()) : result;
 227.983 -        } catch (NumberFormatException e) {
 227.984 -            // If number is Integer.MIN_VALUE, we'll end up here. The next line
 227.985 -            // handles this case, and causes any genuine format error to be
 227.986 -            // rethrown.
 227.987 -            String constant = negative ? ("-" + nm.substring(index))
 227.988 -                                       : nm.substring(index);
 227.989 -            result = Integer.valueOf(constant, radix);
 227.990 -        }
 227.991 -        return result;
 227.992 -    }
 227.993 -
 227.994 -    /**
 227.995 -     * Compares two {@code Integer} objects numerically.
 227.996 -     *
 227.997 -     * @param   anotherInteger   the {@code Integer} to be compared.
 227.998 -     * @return  the value {@code 0} if this {@code Integer} is
 227.999 -     *          equal to the argument {@code Integer}; a value less than
227.1000 -     *          {@code 0} if this {@code Integer} is numerically less
227.1001 -     *          than the argument {@code Integer}; and a value greater
227.1002 -     *          than {@code 0} if this {@code Integer} is numerically
227.1003 -     *           greater than the argument {@code Integer} (signed
227.1004 -     *           comparison).
227.1005 -     * @since   1.2
227.1006 -     */
227.1007 -    public int compareTo(Integer anotherInteger) {
227.1008 -        return compare(this.value, anotherInteger.value);
227.1009 -    }
227.1010 -
227.1011 -    /**
227.1012 -     * Compares two {@code int} values numerically.
227.1013 -     * The value returned is identical to what would be returned by:
227.1014 -     * <pre>
227.1015 -     *    Integer.valueOf(x).compareTo(Integer.valueOf(y))
227.1016 -     * </pre>
227.1017 -     *
227.1018 -     * @param  x the first {@code int} to compare
227.1019 -     * @param  y the second {@code int} to compare
227.1020 -     * @return the value {@code 0} if {@code x == y};
227.1021 -     *         a value less than {@code 0} if {@code x < y}; and
227.1022 -     *         a value greater than {@code 0} if {@code x > y}
227.1023 -     * @since 1.7
227.1024 -     */
227.1025 -    public static int compare(int x, int y) {
227.1026 -        return (x < y) ? -1 : ((x == y) ? 0 : 1);
227.1027 -    }
227.1028 -
227.1029 -
227.1030 -    // Bit twiddling
227.1031 -
227.1032 -    /**
227.1033 -     * The number of bits used to represent an {@code int} value in two's
227.1034 -     * complement binary form.
227.1035 -     *
227.1036 -     * @since 1.5
227.1037 -     */
227.1038 -    public static final int SIZE = 32;
227.1039 -
227.1040 -    /**
227.1041 -     * Returns an {@code int} value with at most a single one-bit, in the
227.1042 -     * position of the highest-order ("leftmost") one-bit in the specified
227.1043 -     * {@code int} value.  Returns zero if the specified value has no
227.1044 -     * one-bits in its two's complement binary representation, that is, if it
227.1045 -     * is equal to zero.
227.1046 -     *
227.1047 -     * @return an {@code int} value with a single one-bit, in the position
227.1048 -     *     of the highest-order one-bit in the specified value, or zero if
227.1049 -     *     the specified value is itself equal to zero.
227.1050 -     * @since 1.5
227.1051 -     */
227.1052 -    public static int highestOneBit(int i) {
227.1053 -        // HD, Figure 3-1
227.1054 -        i |= (i >>  1);
227.1055 -        i |= (i >>  2);
227.1056 -        i |= (i >>  4);
227.1057 -        i |= (i >>  8);
227.1058 -        i |= (i >> 16);
227.1059 -        return i - (i >>> 1);
227.1060 -    }
227.1061 -
227.1062 -    /**
227.1063 -     * Returns an {@code int} value with at most a single one-bit, in the
227.1064 -     * position of the lowest-order ("rightmost") one-bit in the specified
227.1065 -     * {@code int} value.  Returns zero if the specified value has no
227.1066 -     * one-bits in its two's complement binary representation, that is, if it
227.1067 -     * is equal to zero.
227.1068 -     *
227.1069 -     * @return an {@code int} value with a single one-bit, in the position
227.1070 -     *     of the lowest-order one-bit in the specified value, or zero if
227.1071 -     *     the specified value is itself equal to zero.
227.1072 -     * @since 1.5
227.1073 -     */
227.1074 -    public static int lowestOneBit(int i) {
227.1075 -        // HD, Section 2-1
227.1076 -        return i & -i;
227.1077 -    }
227.1078 -
227.1079 -    /**
227.1080 -     * Returns the number of zero bits preceding the highest-order
227.1081 -     * ("leftmost") one-bit in the two's complement binary representation
227.1082 -     * of the specified {@code int} value.  Returns 32 if the
227.1083 -     * specified value has no one-bits in its two's complement representation,
227.1084 -     * in other words if it is equal to zero.
227.1085 -     *
227.1086 -     * <p>Note that this method is closely related to the logarithm base 2.
227.1087 -     * For all positive {@code int} values x:
227.1088 -     * <ul>
227.1089 -     * <li>floor(log<sub>2</sub>(x)) = {@code 31 - numberOfLeadingZeros(x)}
227.1090 -     * <li>ceil(log<sub>2</sub>(x)) = {@code 32 - numberOfLeadingZeros(x - 1)}
227.1091 -     * </ul>
227.1092 -     *
227.1093 -     * @return the number of zero bits preceding the highest-order
227.1094 -     *     ("leftmost") one-bit in the two's complement binary representation
227.1095 -     *     of the specified {@code int} value, or 32 if the value
227.1096 -     *     is equal to zero.
227.1097 -     * @since 1.5
227.1098 -     */
227.1099 -    public static int numberOfLeadingZeros(int i) {
227.1100 -        // HD, Figure 5-6
227.1101 -        if (i == 0)
227.1102 -            return 32;
227.1103 -        int n = 1;
227.1104 -        if (i >>> 16 == 0) { n += 16; i <<= 16; }
227.1105 -        if (i >>> 24 == 0) { n +=  8; i <<=  8; }
227.1106 -        if (i >>> 28 == 0) { n +=  4; i <<=  4; }
227.1107 -        if (i >>> 30 == 0) { n +=  2; i <<=  2; }
227.1108 -        n -= i >>> 31;
227.1109 -        return n;
227.1110 -    }
227.1111 -
227.1112 -    /**
227.1113 -     * Returns the number of zero bits following the lowest-order ("rightmost")
227.1114 -     * one-bit in the two's complement binary representation of the specified
227.1115 -     * {@code int} value.  Returns 32 if the specified value has no
227.1116 -     * one-bits in its two's complement representation, in other words if it is
227.1117 -     * equal to zero.
227.1118 -     *
227.1119 -     * @return the number of zero bits following the lowest-order ("rightmost")
227.1120 -     *     one-bit in the two's complement binary representation of the
227.1121 -     *     specified {@code int} value, or 32 if the value is equal
227.1122 -     *     to zero.
227.1123 -     * @since 1.5
227.1124 -     */
227.1125 -    public static int numberOfTrailingZeros(int i) {
227.1126 -        // HD, Figure 5-14
227.1127 -        int y;
227.1128 -        if (i == 0) return 32;
227.1129 -        int n = 31;
227.1130 -        y = i <<16; if (y != 0) { n = n -16; i = y; }
227.1131 -        y = i << 8; if (y != 0) { n = n - 8; i = y; }
227.1132 -        y = i << 4; if (y != 0) { n = n - 4; i = y; }
227.1133 -        y = i << 2; if (y != 0) { n = n - 2; i = y; }
227.1134 -        return n - ((i << 1) >>> 31);
227.1135 -    }
227.1136 -
227.1137 -    /**
227.1138 -     * Returns the number of one-bits in the two's complement binary
227.1139 -     * representation of the specified {@code int} value.  This function is
227.1140 -     * sometimes referred to as the <i>population count</i>.
227.1141 -     *
227.1142 -     * @return the number of one-bits in the two's complement binary
227.1143 -     *     representation of the specified {@code int} value.
227.1144 -     * @since 1.5
227.1145 -     */
227.1146 -    public static int bitCount(int i) {
227.1147 -        // HD, Figure 5-2
227.1148 -        i = i - ((i >>> 1) & 0x55555555);
227.1149 -        i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
227.1150 -        i = (i + (i >>> 4)) & 0x0f0f0f0f;
227.1151 -        i = i + (i >>> 8);
227.1152 -        i = i + (i >>> 16);
227.1153 -        return i & 0x3f;
227.1154 -    }
227.1155 -
227.1156 -    /**
227.1157 -     * Returns the value obtained by rotating the two's complement binary
227.1158 -     * representation of the specified {@code int} value left by the
227.1159 -     * specified number of bits.  (Bits shifted out of the left hand, or
227.1160 -     * high-order, side reenter on the right, or low-order.)
227.1161 -     *
227.1162 -     * <p>Note that left rotation with a negative distance is equivalent to
227.1163 -     * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val,
227.1164 -     * distance)}.  Note also that rotation by any multiple of 32 is a
227.1165 -     * no-op, so all but the last five bits of the rotation distance can be
227.1166 -     * ignored, even if the distance is negative: {@code rotateLeft(val,
227.1167 -     * distance) == rotateLeft(val, distance & 0x1F)}.
227.1168 -     *
227.1169 -     * @return the value obtained by rotating the two's complement binary
227.1170 -     *     representation of the specified {@code int} value left by the
227.1171 -     *     specified number of bits.
227.1172 -     * @since 1.5
227.1173 -     */
227.1174 -    public static int rotateLeft(int i, int distance) {
227.1175 -        return (i << distance) | (i >>> -distance);
227.1176 -    }
227.1177 -
227.1178 -    /**
227.1179 -     * Returns the value obtained by rotating the two's complement binary
227.1180 -     * representation of the specified {@code int} value right by the
227.1181 -     * specified number of bits.  (Bits shifted out of the right hand, or
227.1182 -     * low-order, side reenter on the left, or high-order.)
227.1183 -     *
227.1184 -     * <p>Note that right rotation with a negative distance is equivalent to
227.1185 -     * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val,
227.1186 -     * distance)}.  Note also that rotation by any multiple of 32 is a
227.1187 -     * no-op, so all but the last five bits of the rotation distance can be
227.1188 -     * ignored, even if the distance is negative: {@code rotateRight(val,
227.1189 -     * distance) == rotateRight(val, distance & 0x1F)}.
227.1190 -     *
227.1191 -     * @return the value obtained by rotating the two's complement binary
227.1192 -     *     representation of the specified {@code int} value right by the
227.1193 -     *     specified number of bits.
227.1194 -     * @since 1.5
227.1195 -     */
227.1196 -    public static int rotateRight(int i, int distance) {
227.1197 -        return (i >>> distance) | (i << -distance);
227.1198 -    }
227.1199 -
227.1200 -    /**
227.1201 -     * Returns the value obtained by reversing the order of the bits in the
227.1202 -     * two's complement binary representation of the specified {@code int}
227.1203 -     * value.
227.1204 -     *
227.1205 -     * @return the value obtained by reversing order of the bits in the
227.1206 -     *     specified {@code int} value.
227.1207 -     * @since 1.5
227.1208 -     */
227.1209 -    public static int reverse(int i) {
227.1210 -        // HD, Figure 7-1
227.1211 -        i = (i & 0x55555555) << 1 | (i >>> 1) & 0x55555555;
227.1212 -        i = (i & 0x33333333) << 2 | (i >>> 2) & 0x33333333;
227.1213 -        i = (i & 0x0f0f0f0f) << 4 | (i >>> 4) & 0x0f0f0f0f;
227.1214 -        i = (i << 24) | ((i & 0xff00) << 8) |
227.1215 -            ((i >>> 8) & 0xff00) | (i >>> 24);
227.1216 -        return i;
227.1217 -    }
227.1218 -
227.1219 -    /**
227.1220 -     * Returns the signum function of the specified {@code int} value.  (The
227.1221 -     * return value is -1 if the specified value is negative; 0 if the
227.1222 -     * specified value is zero; and 1 if the specified value is positive.)
227.1223 -     *
227.1224 -     * @return the signum function of the specified {@code int} value.
227.1225 -     * @since 1.5
227.1226 -     */
227.1227 -    public static int signum(int i) {
227.1228 -        // HD, Section 2-7
227.1229 -        return (i >> 31) | (-i >>> 31);
227.1230 -    }
227.1231 -
227.1232 -    /**
227.1233 -     * Returns the value obtained by reversing the order of the bytes in the
227.1234 -     * two's complement representation of the specified {@code int} value.
227.1235 -     *
227.1236 -     * @return the value obtained by reversing the bytes in the specified
227.1237 -     *     {@code int} value.
227.1238 -     * @since 1.5
227.1239 -     */
227.1240 -    public static int reverseBytes(int i) {
227.1241 -        return ((i >>> 24)           ) |
227.1242 -               ((i >>   8) &   0xFF00) |
227.1243 -               ((i <<   8) & 0xFF0000) |
227.1244 -               ((i << 24));
227.1245 -    }
227.1246 -
227.1247 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
227.1248 -    private static final long serialVersionUID = 1360826667806852920L;
227.1249 -}
   228.1 --- a/emul/src/main/java/java/lang/InterruptedException.java	Wed Dec 05 10:03:58 2012 +0100
   228.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   228.3 @@ -1,69 +0,0 @@
   228.4 -/*
   228.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   228.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   228.7 - *
   228.8 - * This code is free software; you can redistribute it and/or modify it
   228.9 - * under the terms of the GNU General Public License version 2 only, as
  228.10 - * published by the Free Software Foundation.  Oracle designates this
  228.11 - * particular file as subject to the "Classpath" exception as provided
  228.12 - * by Oracle in the LICENSE file that accompanied this code.
  228.13 - *
  228.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  228.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  228.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  228.17 - * version 2 for more details (a copy is included in the LICENSE file that
  228.18 - * accompanied this code).
  228.19 - *
  228.20 - * You should have received a copy of the GNU General Public License version
  228.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  228.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  228.23 - *
  228.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  228.25 - * or visit www.oracle.com if you need additional information or have any
  228.26 - * questions.
  228.27 - */
  228.28 -
  228.29 -package java.lang;
  228.30 -
  228.31 -/**
  228.32 - * Thrown when a thread is waiting, sleeping, or otherwise occupied,
  228.33 - * and the thread is interrupted, either before or during the activity.
  228.34 - * Occasionally a method may wish to test whether the current
  228.35 - * thread has been interrupted, and if so, to immediately throw
  228.36 - * this exception.  The following code can be used to achieve
  228.37 - * this effect:
  228.38 - * <pre>
  228.39 - *  if (Thread.interrupted())  // Clears interrupted status!
  228.40 - *      throw new InterruptedException();
  228.41 - * </pre>
  228.42 - *
  228.43 - * @author  Frank Yellin
  228.44 - * @see     java.lang.Object#wait()
  228.45 - * @see     java.lang.Object#wait(long)
  228.46 - * @see     java.lang.Object#wait(long, int)
  228.47 - * @see     java.lang.Thread#sleep(long)
  228.48 - * @see     java.lang.Thread#interrupt()
  228.49 - * @see     java.lang.Thread#interrupted()
  228.50 - * @since   JDK1.0
  228.51 - */
  228.52 -public
  228.53 -class InterruptedException extends Exception {
  228.54 -    private static final long serialVersionUID = 6700697376100628473L;
  228.55 -
  228.56 -    /**
  228.57 -     * Constructs an <code>InterruptedException</code> with no detail  message.
  228.58 -     */
  228.59 -    public InterruptedException() {
  228.60 -        super();
  228.61 -    }
  228.62 -
  228.63 -    /**
  228.64 -     * Constructs an <code>InterruptedException</code> with the
  228.65 -     * specified detail message.
  228.66 -     *
  228.67 -     * @param   s   the detail message.
  228.68 -     */
  228.69 -    public InterruptedException(String s) {
  228.70 -        super(s);
  228.71 -    }
  228.72 -}
   229.1 --- a/emul/src/main/java/java/lang/LinkageError.java	Wed Dec 05 10:03:58 2012 +0100
   229.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   229.3 @@ -1,69 +0,0 @@
   229.4 -/*
   229.5 - * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
   229.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   229.7 - *
   229.8 - * This code is free software; you can redistribute it and/or modify it
   229.9 - * under the terms of the GNU General Public License version 2 only, as
  229.10 - * published by the Free Software Foundation.  Oracle designates this
  229.11 - * particular file as subject to the "Classpath" exception as provided
  229.12 - * by Oracle in the LICENSE file that accompanied this code.
  229.13 - *
  229.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  229.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  229.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  229.17 - * version 2 for more details (a copy is included in the LICENSE file that
  229.18 - * accompanied this code).
  229.19 - *
  229.20 - * You should have received a copy of the GNU General Public License version
  229.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  229.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  229.23 - *
  229.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  229.25 - * or visit www.oracle.com if you need additional information or have any
  229.26 - * questions.
  229.27 - */
  229.28 -
  229.29 -package java.lang;
  229.30 -
  229.31 -/**
  229.32 - * Subclasses of {@code LinkageError} indicate that a class has
  229.33 - * some dependency on another class; however, the latter class has
  229.34 - * incompatibly changed after the compilation of the former class.
  229.35 - *
  229.36 - *
  229.37 - * @author  Frank Yellin
  229.38 - * @since   JDK1.0
  229.39 - */
  229.40 -public
  229.41 -class LinkageError extends Error {
  229.42 -    private static final long serialVersionUID = 3579600108157160122L;
  229.43 -
  229.44 -    /**
  229.45 -     * Constructs a {@code LinkageError} with no detail message.
  229.46 -     */
  229.47 -    public LinkageError() {
  229.48 -        super();
  229.49 -    }
  229.50 -
  229.51 -    /**
  229.52 -     * Constructs a {@code LinkageError} with the specified detail
  229.53 -     * message.
  229.54 -     *
  229.55 -     * @param   s   the detail message.
  229.56 -     */
  229.57 -    public LinkageError(String s) {
  229.58 -        super(s);
  229.59 -    }
  229.60 -
  229.61 -    /**
  229.62 -     * Constructs a {@code LinkageError} with the specified detail
  229.63 -     * message and cause.
  229.64 -     *
  229.65 -     * @param s     the detail message.
  229.66 -     * @param cause the cause, may be {@code null}
  229.67 -     * @since 1.7
  229.68 -     */
  229.69 -    public LinkageError(String s, Throwable cause) {
  229.70 -        super(s, cause);
  229.71 -    }
  229.72 -}
   230.1 --- a/emul/src/main/java/java/lang/Long.java	Wed Dec 05 10:03:58 2012 +0100
   230.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   230.3 @@ -1,1202 +0,0 @@
   230.4 -/*
   230.5 - * Copyright (c) 1994, 2009, Oracle and/or its affiliates. All rights reserved.
   230.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   230.7 - *
   230.8 - * This code is free software; you can redistribute it and/or modify it
   230.9 - * under the terms of the GNU General Public License version 2 only, as
  230.10 - * published by the Free Software Foundation.  Oracle designates this
  230.11 - * particular file as subject to the "Classpath" exception as provided
  230.12 - * by Oracle in the LICENSE file that accompanied this code.
  230.13 - *
  230.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  230.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  230.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  230.17 - * version 2 for more details (a copy is included in the LICENSE file that
  230.18 - * accompanied this code).
  230.19 - *
  230.20 - * You should have received a copy of the GNU General Public License version
  230.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  230.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  230.23 - *
  230.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  230.25 - * or visit www.oracle.com if you need additional information or have any
  230.26 - * questions.
  230.27 - */
  230.28 -
  230.29 -package java.lang;
  230.30 -
  230.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  230.32 -
  230.33 -/**
  230.34 - * The {@code Long} class wraps a value of the primitive type {@code
  230.35 - * long} in an object. An object of type {@code Long} contains a
  230.36 - * single field whose type is {@code long}.
  230.37 - *
  230.38 - * <p> In addition, this class provides several methods for converting
  230.39 - * a {@code long} to a {@code String} and a {@code String} to a {@code
  230.40 - * long}, as well as other constants and methods useful when dealing
  230.41 - * with a {@code long}.
  230.42 - *
  230.43 - * <p>Implementation note: The implementations of the "bit twiddling"
  230.44 - * methods (such as {@link #highestOneBit(long) highestOneBit} and
  230.45 - * {@link #numberOfTrailingZeros(long) numberOfTrailingZeros}) are
  230.46 - * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  230.47 - * Delight</i>, (Addison Wesley, 2002).
  230.48 - *
  230.49 - * @author  Lee Boynton
  230.50 - * @author  Arthur van Hoff
  230.51 - * @author  Josh Bloch
  230.52 - * @author  Joseph D. Darcy
  230.53 - * @since   JDK1.0
  230.54 - */
  230.55 -public final class Long extends Number implements Comparable<Long> {
  230.56 -    /**
  230.57 -     * A constant holding the minimum value a {@code long} can
  230.58 -     * have, -2<sup>63</sup>.
  230.59 -     */
  230.60 -    public static final long MIN_VALUE = 0x8000000000000000L;
  230.61 -
  230.62 -    /**
  230.63 -     * A constant holding the maximum value a {@code long} can
  230.64 -     * have, 2<sup>63</sup>-1.
  230.65 -     */
  230.66 -    public static final long MAX_VALUE = 0x7fffffffffffffffL;
  230.67 -
  230.68 -    /**
  230.69 -     * The {@code Class} instance representing the primitive type
  230.70 -     * {@code long}.
  230.71 -     *
  230.72 -     * @since   JDK1.1
  230.73 -     */
  230.74 -    public static final Class<Long>     TYPE = (Class<Long>) Class.getPrimitiveClass("long");
  230.75 -
  230.76 -    /**
  230.77 -     * Returns a string representation of the first argument in the
  230.78 -     * radix specified by the second argument.
  230.79 -     *
  230.80 -     * <p>If the radix is smaller than {@code Character.MIN_RADIX}
  230.81 -     * or larger than {@code Character.MAX_RADIX}, then the radix
  230.82 -     * {@code 10} is used instead.
  230.83 -     *
  230.84 -     * <p>If the first argument is negative, the first element of the
  230.85 -     * result is the ASCII minus sign {@code '-'}
  230.86 -     * (<code>'&#92;u002d'</code>). If the first argument is not
  230.87 -     * negative, no sign character appears in the result.
  230.88 -     *
  230.89 -     * <p>The remaining characters of the result represent the magnitude
  230.90 -     * of the first argument. If the magnitude is zero, it is
  230.91 -     * represented by a single zero character {@code '0'}
  230.92 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
  230.93 -     * the representation of the magnitude will not be the zero
  230.94 -     * character.  The following ASCII characters are used as digits:
  230.95 -     *
  230.96 -     * <blockquote>
  230.97 -     *   {@code 0123456789abcdefghijklmnopqrstuvwxyz}
  230.98 -     * </blockquote>
  230.99 -     *
 230.100 -     * These are <code>'&#92;u0030'</code> through
 230.101 -     * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
 230.102 -     * <code>'&#92;u007a'</code>. If {@code radix} is
 230.103 -     * <var>N</var>, then the first <var>N</var> of these characters
 230.104 -     * are used as radix-<var>N</var> digits in the order shown. Thus,
 230.105 -     * the digits for hexadecimal (radix 16) are
 230.106 -     * {@code 0123456789abcdef}. If uppercase letters are
 230.107 -     * desired, the {@link java.lang.String#toUpperCase()} method may
 230.108 -     * be called on the result:
 230.109 -     *
 230.110 -     * <blockquote>
 230.111 -     *  {@code Long.toString(n, 16).toUpperCase()}
 230.112 -     * </blockquote>
 230.113 -     *
 230.114 -     * @param   i       a {@code long} to be converted to a string.
 230.115 -     * @param   radix   the radix to use in the string representation.
 230.116 -     * @return  a string representation of the argument in the specified radix.
 230.117 -     * @see     java.lang.Character#MAX_RADIX
 230.118 -     * @see     java.lang.Character#MIN_RADIX
 230.119 -     */
 230.120 -    public static String toString(long i, int radix) {
 230.121 -        if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
 230.122 -            radix = 10;
 230.123 -        if (radix == 10)
 230.124 -            return toString(i);
 230.125 -        char[] buf = new char[65];
 230.126 -        int charPos = 64;
 230.127 -        boolean negative = (i < 0);
 230.128 -
 230.129 -        if (!negative) {
 230.130 -            i = -i;
 230.131 -        }
 230.132 -
 230.133 -        while (i <= -radix) {
 230.134 -            buf[charPos--] = Integer.digits[(int)(-(i % radix))];
 230.135 -            i = i / radix;
 230.136 -        }
 230.137 -        buf[charPos] = Integer.digits[(int)(-i)];
 230.138 -
 230.139 -        if (negative) {
 230.140 -            buf[--charPos] = '-';
 230.141 -        }
 230.142 -
 230.143 -        return new String(buf, charPos, (65 - charPos));
 230.144 -    }
 230.145 -
 230.146 -    /**
 230.147 -     * Returns a string representation of the {@code long}
 230.148 -     * argument as an unsigned integer in base&nbsp;16.
 230.149 -     *
 230.150 -     * <p>The unsigned {@code long} value is the argument plus
 230.151 -     * 2<sup>64</sup> if the argument is negative; otherwise, it is
 230.152 -     * equal to the argument.  This value is converted to a string of
 230.153 -     * ASCII digits in hexadecimal (base&nbsp;16) with no extra
 230.154 -     * leading {@code 0}s.  If the unsigned magnitude is zero, it
 230.155 -     * is represented by a single zero character {@code '0'}
 230.156 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 230.157 -     * the representation of the unsigned magnitude will not be the
 230.158 -     * zero character. The following characters are used as
 230.159 -     * hexadecimal digits:
 230.160 -     *
 230.161 -     * <blockquote>
 230.162 -     *  {@code 0123456789abcdef}
 230.163 -     * </blockquote>
 230.164 -     *
 230.165 -     * These are the characters <code>'&#92;u0030'</code> through
 230.166 -     * <code>'&#92;u0039'</code> and  <code>'&#92;u0061'</code> through
 230.167 -     * <code>'&#92;u0066'</code>.  If uppercase letters are desired,
 230.168 -     * the {@link java.lang.String#toUpperCase()} method may be called
 230.169 -     * on the result:
 230.170 -     *
 230.171 -     * <blockquote>
 230.172 -     *  {@code Long.toHexString(n).toUpperCase()}
 230.173 -     * </blockquote>
 230.174 -     *
 230.175 -     * @param   i   a {@code long} to be converted to a string.
 230.176 -     * @return  the string representation of the unsigned {@code long}
 230.177 -     *          value represented by the argument in hexadecimal
 230.178 -     *          (base&nbsp;16).
 230.179 -     * @since   JDK 1.0.2
 230.180 -     */
 230.181 -    public static String toHexString(long i) {
 230.182 -        return toUnsignedString(i, 4);
 230.183 -    }
 230.184 -
 230.185 -    /**
 230.186 -     * Returns a string representation of the {@code long}
 230.187 -     * argument as an unsigned integer in base&nbsp;8.
 230.188 -     *
 230.189 -     * <p>The unsigned {@code long} value is the argument plus
 230.190 -     * 2<sup>64</sup> if the argument is negative; otherwise, it is
 230.191 -     * equal to the argument.  This value is converted to a string of
 230.192 -     * ASCII digits in octal (base&nbsp;8) with no extra leading
 230.193 -     * {@code 0}s.
 230.194 -     *
 230.195 -     * <p>If the unsigned magnitude is zero, it is represented by a
 230.196 -     * single zero character {@code '0'}
 230.197 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 230.198 -     * the representation of the unsigned magnitude will not be the
 230.199 -     * zero character. The following characters are used as octal
 230.200 -     * digits:
 230.201 -     *
 230.202 -     * <blockquote>
 230.203 -     *  {@code 01234567}
 230.204 -     * </blockquote>
 230.205 -     *
 230.206 -     * These are the characters <code>'&#92;u0030'</code> through
 230.207 -     * <code>'&#92;u0037'</code>.
 230.208 -     *
 230.209 -     * @param   i   a {@code long} to be converted to a string.
 230.210 -     * @return  the string representation of the unsigned {@code long}
 230.211 -     *          value represented by the argument in octal (base&nbsp;8).
 230.212 -     * @since   JDK 1.0.2
 230.213 -     */
 230.214 -    public static String toOctalString(long i) {
 230.215 -        return toUnsignedString(i, 3);
 230.216 -    }
 230.217 -
 230.218 -    /**
 230.219 -     * Returns a string representation of the {@code long}
 230.220 -     * argument as an unsigned integer in base&nbsp;2.
 230.221 -     *
 230.222 -     * <p>The unsigned {@code long} value is the argument plus
 230.223 -     * 2<sup>64</sup> if the argument is negative; otherwise, it is
 230.224 -     * equal to the argument.  This value is converted to a string of
 230.225 -     * ASCII digits in binary (base&nbsp;2) with no extra leading
 230.226 -     * {@code 0}s.  If the unsigned magnitude is zero, it is
 230.227 -     * represented by a single zero character {@code '0'}
 230.228 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 230.229 -     * the representation of the unsigned magnitude will not be the
 230.230 -     * zero character. The characters {@code '0'}
 230.231 -     * (<code>'&#92;u0030'</code>) and {@code '1'}
 230.232 -     * (<code>'&#92;u0031'</code>) are used as binary digits.
 230.233 -     *
 230.234 -     * @param   i   a {@code long} to be converted to a string.
 230.235 -     * @return  the string representation of the unsigned {@code long}
 230.236 -     *          value represented by the argument in binary (base&nbsp;2).
 230.237 -     * @since   JDK 1.0.2
 230.238 -     */
 230.239 -    public static String toBinaryString(long i) {
 230.240 -        return toUnsignedString(i, 1);
 230.241 -    }
 230.242 -
 230.243 -    /**
 230.244 -     * Convert the integer to an unsigned number.
 230.245 -     */
 230.246 -    private static String toUnsignedString(long i, int shift) {
 230.247 -        char[] buf = new char[64];
 230.248 -        int charPos = 64;
 230.249 -        int radix = 1 << shift;
 230.250 -        long mask = radix - 1;
 230.251 -        do {
 230.252 -            buf[--charPos] = Integer.digits[(int)(i & mask)];
 230.253 -            i >>>= shift;
 230.254 -        } while (i != 0);
 230.255 -        return new String(buf, charPos, (64 - charPos));
 230.256 -    }
 230.257 -
 230.258 -    /**
 230.259 -     * Returns a {@code String} object representing the specified
 230.260 -     * {@code long}.  The argument is converted to signed decimal
 230.261 -     * representation and returned as a string, exactly as if the
 230.262 -     * argument and the radix 10 were given as arguments to the {@link
 230.263 -     * #toString(long, int)} method.
 230.264 -     *
 230.265 -     * @param   i   a {@code long} to be converted.
 230.266 -     * @return  a string representation of the argument in base&nbsp;10.
 230.267 -     */
 230.268 -    @JavaScriptBody(args = "i", body = "return i.toString();")
 230.269 -    public static String toString(long i) {
 230.270 -        if (i == Long.MIN_VALUE)
 230.271 -            return "-9223372036854775808";
 230.272 -        int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
 230.273 -        char[] buf = new char[size];
 230.274 -        getChars(i, size, buf);
 230.275 -        return new String(buf, 0, size);
 230.276 -    }
 230.277 -
 230.278 -    /**
 230.279 -     * Places characters representing the integer i into the
 230.280 -     * character array buf. The characters are placed into
 230.281 -     * the buffer backwards starting with the least significant
 230.282 -     * digit at the specified index (exclusive), and working
 230.283 -     * backwards from there.
 230.284 -     *
 230.285 -     * Will fail if i == Long.MIN_VALUE
 230.286 -     */
 230.287 -    static void getChars(long i, int index, char[] buf) {
 230.288 -        long q;
 230.289 -        int r;
 230.290 -        int charPos = index;
 230.291 -        char sign = 0;
 230.292 -
 230.293 -        if (i < 0) {
 230.294 -            sign = '-';
 230.295 -            i = -i;
 230.296 -        }
 230.297 -
 230.298 -        // Get 2 digits/iteration using longs until quotient fits into an int
 230.299 -        while (i > Integer.MAX_VALUE) {
 230.300 -            q = i / 100;
 230.301 -            // really: r = i - (q * 100);
 230.302 -            r = (int)(i - ((q << 6) + (q << 5) + (q << 2)));
 230.303 -            i = q;
 230.304 -            buf[--charPos] = Integer.DigitOnes[r];
 230.305 -            buf[--charPos] = Integer.DigitTens[r];
 230.306 -        }
 230.307 -
 230.308 -        // Get 2 digits/iteration using ints
 230.309 -        int q2;
 230.310 -        int i2 = (int)i;
 230.311 -        while (i2 >= 65536) {
 230.312 -            q2 = i2 / 100;
 230.313 -            // really: r = i2 - (q * 100);
 230.314 -            r = i2 - ((q2 << 6) + (q2 << 5) + (q2 << 2));
 230.315 -            i2 = q2;
 230.316 -            buf[--charPos] = Integer.DigitOnes[r];
 230.317 -            buf[--charPos] = Integer.DigitTens[r];
 230.318 -        }
 230.319 -
 230.320 -        // Fall thru to fast mode for smaller numbers
 230.321 -        // assert(i2 <= 65536, i2);
 230.322 -        for (;;) {
 230.323 -            q2 = (i2 * 52429) >>> (16+3);
 230.324 -            r = i2 - ((q2 << 3) + (q2 << 1));  // r = i2-(q2*10) ...
 230.325 -            buf[--charPos] = Integer.digits[r];
 230.326 -            i2 = q2;
 230.327 -            if (i2 == 0) break;
 230.328 -        }
 230.329 -        if (sign != 0) {
 230.330 -            buf[--charPos] = sign;
 230.331 -        }
 230.332 -    }
 230.333 -
 230.334 -    // Requires positive x
 230.335 -    static int stringSize(long x) {
 230.336 -        long p = 10;
 230.337 -        for (int i=1; i<19; i++) {
 230.338 -            if (x < p)
 230.339 -                return i;
 230.340 -            p = 10*p;
 230.341 -        }
 230.342 -        return 19;
 230.343 -    }
 230.344 -
 230.345 -    /**
 230.346 -     * Parses the string argument as a signed {@code long} in the
 230.347 -     * radix specified by the second argument. The characters in the
 230.348 -     * string must all be digits of the specified radix (as determined
 230.349 -     * by whether {@link java.lang.Character#digit(char, int)} returns
 230.350 -     * a nonnegative value), except that the first character may be an
 230.351 -     * ASCII minus sign {@code '-'} (<code>'&#92;u002D'</code>) to
 230.352 -     * indicate a negative value or an ASCII plus sign {@code '+'}
 230.353 -     * (<code>'&#92;u002B'</code>) to indicate a positive value. The
 230.354 -     * resulting {@code long} value is returned.
 230.355 -     *
 230.356 -     * <p>Note that neither the character {@code L}
 230.357 -     * (<code>'&#92;u004C'</code>) nor {@code l}
 230.358 -     * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 230.359 -     * of the string as a type indicator, as would be permitted in
 230.360 -     * Java programming language source code - except that either
 230.361 -     * {@code L} or {@code l} may appear as a digit for a
 230.362 -     * radix greater than 22.
 230.363 -     *
 230.364 -     * <p>An exception of type {@code NumberFormatException} is
 230.365 -     * thrown if any of the following situations occurs:
 230.366 -     * <ul>
 230.367 -     *
 230.368 -     * <li>The first argument is {@code null} or is a string of
 230.369 -     * length zero.
 230.370 -     *
 230.371 -     * <li>The {@code radix} is either smaller than {@link
 230.372 -     * java.lang.Character#MIN_RADIX} or larger than {@link
 230.373 -     * java.lang.Character#MAX_RADIX}.
 230.374 -     *
 230.375 -     * <li>Any character of the string is not a digit of the specified
 230.376 -     * radix, except that the first character may be a minus sign
 230.377 -     * {@code '-'} (<code>'&#92;u002d'</code>) or plus sign {@code
 230.378 -     * '+'} (<code>'&#92;u002B'</code>) provided that the string is
 230.379 -     * longer than length 1.
 230.380 -     *
 230.381 -     * <li>The value represented by the string is not a value of type
 230.382 -     *      {@code long}.
 230.383 -     * </ul>
 230.384 -     *
 230.385 -     * <p>Examples:
 230.386 -     * <blockquote><pre>
 230.387 -     * parseLong("0", 10) returns 0L
 230.388 -     * parseLong("473", 10) returns 473L
 230.389 -     * parseLong("+42", 10) returns 42L
 230.390 -     * parseLong("-0", 10) returns 0L
 230.391 -     * parseLong("-FF", 16) returns -255L
 230.392 -     * parseLong("1100110", 2) returns 102L
 230.393 -     * parseLong("99", 8) throws a NumberFormatException
 230.394 -     * parseLong("Hazelnut", 10) throws a NumberFormatException
 230.395 -     * parseLong("Hazelnut", 36) returns 1356099454469L
 230.396 -     * </pre></blockquote>
 230.397 -     *
 230.398 -     * @param      s       the {@code String} containing the
 230.399 -     *                     {@code long} representation to be parsed.
 230.400 -     * @param      radix   the radix to be used while parsing {@code s}.
 230.401 -     * @return     the {@code long} represented by the string argument in
 230.402 -     *             the specified radix.
 230.403 -     * @throws     NumberFormatException  if the string does not contain a
 230.404 -     *             parsable {@code long}.
 230.405 -     */
 230.406 -    public static long parseLong(String s, int radix)
 230.407 -              throws NumberFormatException
 230.408 -    {
 230.409 -        if (s == null) {
 230.410 -            throw new NumberFormatException("null");
 230.411 -        }
 230.412 -
 230.413 -        if (radix < Character.MIN_RADIX) {
 230.414 -            throw new NumberFormatException("radix " + radix +
 230.415 -                                            " less than Character.MIN_RADIX");
 230.416 -        }
 230.417 -        if (radix > Character.MAX_RADIX) {
 230.418 -            throw new NumberFormatException("radix " + radix +
 230.419 -                                            " greater than Character.MAX_RADIX");
 230.420 -        }
 230.421 -
 230.422 -        long result = 0;
 230.423 -        boolean negative = false;
 230.424 -        int i = 0, len = s.length();
 230.425 -        long limit = -Long.MAX_VALUE;
 230.426 -        long multmin;
 230.427 -        int digit;
 230.428 -
 230.429 -        if (len > 0) {
 230.430 -            char firstChar = s.charAt(0);
 230.431 -            if (firstChar < '0') { // Possible leading "+" or "-"
 230.432 -                if (firstChar == '-') {
 230.433 -                    negative = true;
 230.434 -                    limit = Long.MIN_VALUE;
 230.435 -                } else if (firstChar != '+')
 230.436 -                    throw NumberFormatException.forInputString(s);
 230.437 -
 230.438 -                if (len == 1) // Cannot have lone "+" or "-"
 230.439 -                    throw NumberFormatException.forInputString(s);
 230.440 -                i++;
 230.441 -            }
 230.442 -            multmin = limit / radix;
 230.443 -            while (i < len) {
 230.444 -                // Accumulating negatively avoids surprises near MAX_VALUE
 230.445 -                digit = Character.digit(s.charAt(i++),radix);
 230.446 -                if (digit < 0) {
 230.447 -                    throw NumberFormatException.forInputString(s);
 230.448 -                }
 230.449 -                if (result < multmin) {
 230.450 -                    throw NumberFormatException.forInputString(s);
 230.451 -                }
 230.452 -                result *= radix;
 230.453 -                if (result < limit + digit) {
 230.454 -                    throw NumberFormatException.forInputString(s);
 230.455 -                }
 230.456 -                result -= digit;
 230.457 -            }
 230.458 -        } else {
 230.459 -            throw NumberFormatException.forInputString(s);
 230.460 -        }
 230.461 -        return negative ? result : -result;
 230.462 -    }
 230.463 -
 230.464 -    /**
 230.465 -     * Parses the string argument as a signed decimal {@code long}.
 230.466 -     * The characters in the string must all be decimal digits, except
 230.467 -     * that the first character may be an ASCII minus sign {@code '-'}
 230.468 -     * (<code>&#92;u002D'</code>) to indicate a negative value or an
 230.469 -     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
 230.470 -     * indicate a positive value. The resulting {@code long} value is
 230.471 -     * returned, exactly as if the argument and the radix {@code 10}
 230.472 -     * were given as arguments to the {@link
 230.473 -     * #parseLong(java.lang.String, int)} method.
 230.474 -     *
 230.475 -     * <p>Note that neither the character {@code L}
 230.476 -     * (<code>'&#92;u004C'</code>) nor {@code l}
 230.477 -     * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 230.478 -     * of the string as a type indicator, as would be permitted in
 230.479 -     * Java programming language source code.
 230.480 -     *
 230.481 -     * @param      s   a {@code String} containing the {@code long}
 230.482 -     *             representation to be parsed
 230.483 -     * @return     the {@code long} represented by the argument in
 230.484 -     *             decimal.
 230.485 -     * @throws     NumberFormatException  if the string does not contain a
 230.486 -     *             parsable {@code long}.
 230.487 -     */
 230.488 -    public static long parseLong(String s) throws NumberFormatException {
 230.489 -        return parseLong(s, 10);
 230.490 -    }
 230.491 -
 230.492 -    /**
 230.493 -     * Returns a {@code Long} object holding the value
 230.494 -     * extracted from the specified {@code String} when parsed
 230.495 -     * with the radix given by the second argument.  The first
 230.496 -     * argument is interpreted as representing a signed
 230.497 -     * {@code long} in the radix specified by the second
 230.498 -     * argument, exactly as if the arguments were given to the {@link
 230.499 -     * #parseLong(java.lang.String, int)} method. The result is a
 230.500 -     * {@code Long} object that represents the {@code long}
 230.501 -     * value specified by the string.
 230.502 -     *
 230.503 -     * <p>In other words, this method returns a {@code Long} object equal
 230.504 -     * to the value of:
 230.505 -     *
 230.506 -     * <blockquote>
 230.507 -     *  {@code new Long(Long.parseLong(s, radix))}
 230.508 -     * </blockquote>
 230.509 -     *
 230.510 -     * @param      s       the string to be parsed
 230.511 -     * @param      radix   the radix to be used in interpreting {@code s}
 230.512 -     * @return     a {@code Long} object holding the value
 230.513 -     *             represented by the string argument in the specified
 230.514 -     *             radix.
 230.515 -     * @throws     NumberFormatException  If the {@code String} does not
 230.516 -     *             contain a parsable {@code long}.
 230.517 -     */
 230.518 -    public static Long valueOf(String s, int radix) throws NumberFormatException {
 230.519 -        return Long.valueOf(parseLong(s, radix));
 230.520 -    }
 230.521 -
 230.522 -    /**
 230.523 -     * Returns a {@code Long} object holding the value
 230.524 -     * of the specified {@code String}. The argument is
 230.525 -     * interpreted as representing a signed decimal {@code long},
 230.526 -     * exactly as if the argument were given to the {@link
 230.527 -     * #parseLong(java.lang.String)} method. The result is a
 230.528 -     * {@code Long} object that represents the integer value
 230.529 -     * specified by the string.
 230.530 -     *
 230.531 -     * <p>In other words, this method returns a {@code Long} object
 230.532 -     * equal to the value of:
 230.533 -     *
 230.534 -     * <blockquote>
 230.535 -     *  {@code new Long(Long.parseLong(s))}
 230.536 -     * </blockquote>
 230.537 -     *
 230.538 -     * @param      s   the string to be parsed.
 230.539 -     * @return     a {@code Long} object holding the value
 230.540 -     *             represented by the string argument.
 230.541 -     * @throws     NumberFormatException  If the string cannot be parsed
 230.542 -     *             as a {@code long}.
 230.543 -     */
 230.544 -    public static Long valueOf(String s) throws NumberFormatException
 230.545 -    {
 230.546 -        return Long.valueOf(parseLong(s, 10));
 230.547 -    }
 230.548 -
 230.549 -    private static class LongCache {
 230.550 -        private LongCache(){}
 230.551 -
 230.552 -        static final Long cache[] = new Long[-(-128) + 127 + 1];
 230.553 -
 230.554 -        static {
 230.555 -            for(int i = 0; i < cache.length; i++)
 230.556 -                cache[i] = new Long(i - 128);
 230.557 -        }
 230.558 -    }
 230.559 -
 230.560 -    /**
 230.561 -     * Returns a {@code Long} instance representing the specified
 230.562 -     * {@code long} value.
 230.563 -     * If a new {@code Long} instance is not required, this method
 230.564 -     * should generally be used in preference to the constructor
 230.565 -     * {@link #Long(long)}, as this method is likely to yield
 230.566 -     * significantly better space and time performance by caching
 230.567 -     * frequently requested values.
 230.568 -     *
 230.569 -     * Note that unlike the {@linkplain Integer#valueOf(int)
 230.570 -     * corresponding method} in the {@code Integer} class, this method
 230.571 -     * is <em>not</em> required to cache values within a particular
 230.572 -     * range.
 230.573 -     *
 230.574 -     * @param  l a long value.
 230.575 -     * @return a {@code Long} instance representing {@code l}.
 230.576 -     * @since  1.5
 230.577 -     */
 230.578 -    public static Long valueOf(long l) {
 230.579 -        final int offset = 128;
 230.580 -        if (l >= -128 && l <= 127) { // will cache
 230.581 -            return LongCache.cache[(int)l + offset];
 230.582 -        }
 230.583 -        return new Long(l);
 230.584 -    }
 230.585 -
 230.586 -    /**
 230.587 -     * Decodes a {@code String} into a {@code Long}.
 230.588 -     * Accepts decimal, hexadecimal, and octal numbers given by the
 230.589 -     * following grammar:
 230.590 -     *
 230.591 -     * <blockquote>
 230.592 -     * <dl>
 230.593 -     * <dt><i>DecodableString:</i>
 230.594 -     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 230.595 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 230.596 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 230.597 -     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 230.598 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 230.599 -     * <p>
 230.600 -     * <dt><i>Sign:</i>
 230.601 -     * <dd>{@code -}
 230.602 -     * <dd>{@code +}
 230.603 -     * </dl>
 230.604 -     * </blockquote>
 230.605 -     *
 230.606 -     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 230.607 -     * are as defined in section 3.10.1 of
 230.608 -     * <cite>The Java&trade; Language Specification</cite>,
 230.609 -     * except that underscores are not accepted between digits.
 230.610 -     *
 230.611 -     * <p>The sequence of characters following an optional
 230.612 -     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 230.613 -     * "{@code #}", or leading zero) is parsed as by the {@code
 230.614 -     * Long.parseLong} method with the indicated radix (10, 16, or 8).
 230.615 -     * This sequence of characters must represent a positive value or
 230.616 -     * a {@link NumberFormatException} will be thrown.  The result is
 230.617 -     * negated if first character of the specified {@code String} is
 230.618 -     * the minus sign.  No whitespace characters are permitted in the
 230.619 -     * {@code String}.
 230.620 -     *
 230.621 -     * @param     nm the {@code String} to decode.
 230.622 -     * @return    a {@code Long} object holding the {@code long}
 230.623 -     *            value represented by {@code nm}
 230.624 -     * @throws    NumberFormatException  if the {@code String} does not
 230.625 -     *            contain a parsable {@code long}.
 230.626 -     * @see java.lang.Long#parseLong(String, int)
 230.627 -     * @since 1.2
 230.628 -     */
 230.629 -    public static Long decode(String nm) throws NumberFormatException {
 230.630 -        int radix = 10;
 230.631 -        int index = 0;
 230.632 -        boolean negative = false;
 230.633 -        Long result;
 230.634 -
 230.635 -        if (nm.length() == 0)
 230.636 -            throw new NumberFormatException("Zero length string");
 230.637 -        char firstChar = nm.charAt(0);
 230.638 -        // Handle sign, if present
 230.639 -        if (firstChar == '-') {
 230.640 -            negative = true;
 230.641 -            index++;
 230.642 -        } else if (firstChar == '+')
 230.643 -            index++;
 230.644 -
 230.645 -        // Handle radix specifier, if present
 230.646 -        if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
 230.647 -            index += 2;
 230.648 -            radix = 16;
 230.649 -        }
 230.650 -        else if (nm.startsWith("#", index)) {
 230.651 -            index ++;
 230.652 -            radix = 16;
 230.653 -        }
 230.654 -        else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
 230.655 -            index ++;
 230.656 -            radix = 8;
 230.657 -        }
 230.658 -
 230.659 -        if (nm.startsWith("-", index) || nm.startsWith("+", index))
 230.660 -            throw new NumberFormatException("Sign character in wrong position");
 230.661 -
 230.662 -        try {
 230.663 -            result = Long.valueOf(nm.substring(index), radix);
 230.664 -            result = negative ? Long.valueOf(-result.longValue()) : result;
 230.665 -        } catch (NumberFormatException e) {
 230.666 -            // If number is Long.MIN_VALUE, we'll end up here. The next line
 230.667 -            // handles this case, and causes any genuine format error to be
 230.668 -            // rethrown.
 230.669 -            String constant = negative ? ("-" + nm.substring(index))
 230.670 -                                       : nm.substring(index);
 230.671 -            result = Long.valueOf(constant, radix);
 230.672 -        }
 230.673 -        return result;
 230.674 -    }
 230.675 -
 230.676 -    /**
 230.677 -     * The value of the {@code Long}.
 230.678 -     *
 230.679 -     * @serial
 230.680 -     */
 230.681 -    private final long value;
 230.682 -
 230.683 -    /**
 230.684 -     * Constructs a newly allocated {@code Long} object that
 230.685 -     * represents the specified {@code long} argument.
 230.686 -     *
 230.687 -     * @param   value   the value to be represented by the
 230.688 -     *          {@code Long} object.
 230.689 -     */
 230.690 -    public Long(long value) {
 230.691 -        this.value = value;
 230.692 -    }
 230.693 -
 230.694 -    /**
 230.695 -     * Constructs a newly allocated {@code Long} object that
 230.696 -     * represents the {@code long} value indicated by the
 230.697 -     * {@code String} parameter. The string is converted to a
 230.698 -     * {@code long} value in exactly the manner used by the
 230.699 -     * {@code parseLong} method for radix 10.
 230.700 -     *
 230.701 -     * @param      s   the {@code String} to be converted to a
 230.702 -     *             {@code Long}.
 230.703 -     * @throws     NumberFormatException  if the {@code String} does not
 230.704 -     *             contain a parsable {@code long}.
 230.705 -     * @see        java.lang.Long#parseLong(java.lang.String, int)
 230.706 -     */
 230.707 -    public Long(String s) throws NumberFormatException {
 230.708 -        this.value = parseLong(s, 10);
 230.709 -    }
 230.710 -
 230.711 -    /**
 230.712 -     * Returns the value of this {@code Long} as a
 230.713 -     * {@code byte}.
 230.714 -     */
 230.715 -    public byte byteValue() {
 230.716 -        return (byte)value;
 230.717 -    }
 230.718 -
 230.719 -    /**
 230.720 -     * Returns the value of this {@code Long} as a
 230.721 -     * {@code short}.
 230.722 -     */
 230.723 -    public short shortValue() {
 230.724 -        return (short)value;
 230.725 -    }
 230.726 -
 230.727 -    /**
 230.728 -     * Returns the value of this {@code Long} as an
 230.729 -     * {@code int}.
 230.730 -     */
 230.731 -    public int intValue() {
 230.732 -        return (int)value;
 230.733 -    }
 230.734 -
 230.735 -    /**
 230.736 -     * Returns the value of this {@code Long} as a
 230.737 -     * {@code long} value.
 230.738 -     */
 230.739 -    public long longValue() {
 230.740 -        return (long)value;
 230.741 -    }
 230.742 -
 230.743 -    /**
 230.744 -     * Returns the value of this {@code Long} as a
 230.745 -     * {@code float}.
 230.746 -     */
 230.747 -    public float floatValue() {
 230.748 -        return (float)value;
 230.749 -    }
 230.750 -
 230.751 -    /**
 230.752 -     * Returns the value of this {@code Long} as a
 230.753 -     * {@code double}.
 230.754 -     */
 230.755 -    public double doubleValue() {
 230.756 -        return (double)value;
 230.757 -    }
 230.758 -
 230.759 -    /**
 230.760 -     * Returns a {@code String} object representing this
 230.761 -     * {@code Long}'s value.  The value is converted to signed
 230.762 -     * decimal representation and returned as a string, exactly as if
 230.763 -     * the {@code long} value were given as an argument to the
 230.764 -     * {@link java.lang.Long#toString(long)} method.
 230.765 -     *
 230.766 -     * @return  a string representation of the value of this object in
 230.767 -     *          base&nbsp;10.
 230.768 -     */
 230.769 -    public String toString() {
 230.770 -        return toString(value);
 230.771 -    }
 230.772 -
 230.773 -    /**
 230.774 -     * Returns a hash code for this {@code Long}. The result is
 230.775 -     * the exclusive OR of the two halves of the primitive
 230.776 -     * {@code long} value held by this {@code Long}
 230.777 -     * object. That is, the hashcode is the value of the expression:
 230.778 -     *
 230.779 -     * <blockquote>
 230.780 -     *  {@code (int)(this.longValue()^(this.longValue()>>>32))}
 230.781 -     * </blockquote>
 230.782 -     *
 230.783 -     * @return  a hash code value for this object.
 230.784 -     */
 230.785 -    public int hashCode() {
 230.786 -        return (int)(value ^ (value >>> 32));
 230.787 -    }
 230.788 -
 230.789 -    /**
 230.790 -     * Compares this object to the specified object.  The result is
 230.791 -     * {@code true} if and only if the argument is not
 230.792 -     * {@code null} and is a {@code Long} object that
 230.793 -     * contains the same {@code long} value as this object.
 230.794 -     *
 230.795 -     * @param   obj   the object to compare with.
 230.796 -     * @return  {@code true} if the objects are the same;
 230.797 -     *          {@code false} otherwise.
 230.798 -     */
 230.799 -    public boolean equals(Object obj) {
 230.800 -        if (obj instanceof Long) {
 230.801 -            return value == ((Long)obj).longValue();
 230.802 -        }
 230.803 -        return false;
 230.804 -    }
 230.805 -
 230.806 -    /**
 230.807 -     * Determines the {@code long} value of the system property
 230.808 -     * with the specified name.
 230.809 -     *
 230.810 -     * <p>The first argument is treated as the name of a system property.
 230.811 -     * System properties are accessible through the {@link
 230.812 -     * java.lang.System#getProperty(java.lang.String)} method. The
 230.813 -     * string value of this property is then interpreted as a
 230.814 -     * {@code long} value and a {@code Long} object
 230.815 -     * representing this value is returned.  Details of possible
 230.816 -     * numeric formats can be found with the definition of
 230.817 -     * {@code getProperty}.
 230.818 -     *
 230.819 -     * <p>If there is no property with the specified name, if the
 230.820 -     * specified name is empty or {@code null}, or if the
 230.821 -     * property does not have the correct numeric format, then
 230.822 -     * {@code null} is returned.
 230.823 -     *
 230.824 -     * <p>In other words, this method returns a {@code Long} object equal to
 230.825 -     * the value of:
 230.826 -     *
 230.827 -     * <blockquote>
 230.828 -     *  {@code getLong(nm, null)}
 230.829 -     * </blockquote>
 230.830 -     *
 230.831 -     * @param   nm   property name.
 230.832 -     * @return  the {@code Long} value of the property.
 230.833 -     * @see     java.lang.System#getProperty(java.lang.String)
 230.834 -     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 230.835 -     */
 230.836 -    public static Long getLong(String nm) {
 230.837 -        return getLong(nm, null);
 230.838 -    }
 230.839 -
 230.840 -    /**
 230.841 -     * Determines the {@code long} value of the system property
 230.842 -     * with the specified name.
 230.843 -     *
 230.844 -     * <p>The first argument is treated as the name of a system property.
 230.845 -     * System properties are accessible through the {@link
 230.846 -     * java.lang.System#getProperty(java.lang.String)} method. The
 230.847 -     * string value of this property is then interpreted as a
 230.848 -     * {@code long} value and a {@code Long} object
 230.849 -     * representing this value is returned.  Details of possible
 230.850 -     * numeric formats can be found with the definition of
 230.851 -     * {@code getProperty}.
 230.852 -     *
 230.853 -     * <p>The second argument is the default value. A {@code Long} object
 230.854 -     * that represents the value of the second argument is returned if there
 230.855 -     * is no property of the specified name, if the property does not have
 230.856 -     * the correct numeric format, or if the specified name is empty or null.
 230.857 -     *
 230.858 -     * <p>In other words, this method returns a {@code Long} object equal
 230.859 -     * to the value of:
 230.860 -     *
 230.861 -     * <blockquote>
 230.862 -     *  {@code getLong(nm, new Long(val))}
 230.863 -     * </blockquote>
 230.864 -     *
 230.865 -     * but in practice it may be implemented in a manner such as:
 230.866 -     *
 230.867 -     * <blockquote><pre>
 230.868 -     * Long result = getLong(nm, null);
 230.869 -     * return (result == null) ? new Long(val) : result;
 230.870 -     * </pre></blockquote>
 230.871 -     *
 230.872 -     * to avoid the unnecessary allocation of a {@code Long} object when
 230.873 -     * the default value is not needed.
 230.874 -     *
 230.875 -     * @param   nm    property name.
 230.876 -     * @param   val   default value.
 230.877 -     * @return  the {@code Long} value of the property.
 230.878 -     * @see     java.lang.System#getProperty(java.lang.String)
 230.879 -     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 230.880 -     */
 230.881 -    public static Long getLong(String nm, long val) {
 230.882 -        Long result = Long.getLong(nm, null);
 230.883 -        return (result == null) ? Long.valueOf(val) : result;
 230.884 -    }
 230.885 -
 230.886 -    /**
 230.887 -     * Returns the {@code long} value of the system property with
 230.888 -     * the specified name.  The first argument is treated as the name
 230.889 -     * of a system property.  System properties are accessible through
 230.890 -     * the {@link java.lang.System#getProperty(java.lang.String)}
 230.891 -     * method. The string value of this property is then interpreted
 230.892 -     * as a {@code long} value, as per the
 230.893 -     * {@code Long.decode} method, and a {@code Long} object
 230.894 -     * representing this value is returned.
 230.895 -     *
 230.896 -     * <ul>
 230.897 -     * <li>If the property value begins with the two ASCII characters
 230.898 -     * {@code 0x} or the ASCII character {@code #}, not followed by
 230.899 -     * a minus sign, then the rest of it is parsed as a hexadecimal integer
 230.900 -     * exactly as for the method {@link #valueOf(java.lang.String, int)}
 230.901 -     * with radix 16.
 230.902 -     * <li>If the property value begins with the ASCII character
 230.903 -     * {@code 0} followed by another character, it is parsed as
 230.904 -     * an octal integer exactly as by the method {@link
 230.905 -     * #valueOf(java.lang.String, int)} with radix 8.
 230.906 -     * <li>Otherwise the property value is parsed as a decimal
 230.907 -     * integer exactly as by the method
 230.908 -     * {@link #valueOf(java.lang.String, int)} with radix 10.
 230.909 -     * </ul>
 230.910 -     *
 230.911 -     * <p>Note that, in every case, neither {@code L}
 230.912 -     * (<code>'&#92;u004C'</code>) nor {@code l}
 230.913 -     * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 230.914 -     * of the property value as a type indicator, as would be
 230.915 -     * permitted in Java programming language source code.
 230.916 -     *
 230.917 -     * <p>The second argument is the default value. The default value is
 230.918 -     * returned if there is no property of the specified name, if the
 230.919 -     * property does not have the correct numeric format, or if the
 230.920 -     * specified name is empty or {@code null}.
 230.921 -     *
 230.922 -     * @param   nm   property name.
 230.923 -     * @param   val   default value.
 230.924 -     * @return  the {@code Long} value of the property.
 230.925 -     * @see     java.lang.System#getProperty(java.lang.String)
 230.926 -     * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
 230.927 -     * @see java.lang.Long#decode
 230.928 -     */
 230.929 -    public static Long getLong(String nm, Long val) {
 230.930 -        String v = null;
 230.931 -        try {
 230.932 -            v = AbstractStringBuilder.getProperty(nm);
 230.933 -        } catch (IllegalArgumentException e) {
 230.934 -        } catch (NullPointerException e) {
 230.935 -        }
 230.936 -        if (v != null) {
 230.937 -            try {
 230.938 -                return Long.decode(v);
 230.939 -            } catch (NumberFormatException e) {
 230.940 -            }
 230.941 -        }
 230.942 -        return val;
 230.943 -    }
 230.944 -
 230.945 -    /**
 230.946 -     * Compares two {@code Long} objects numerically.
 230.947 -     *
 230.948 -     * @param   anotherLong   the {@code Long} to be compared.
 230.949 -     * @return  the value {@code 0} if this {@code Long} is
 230.950 -     *          equal to the argument {@code Long}; a value less than
 230.951 -     *          {@code 0} if this {@code Long} is numerically less
 230.952 -     *          than the argument {@code Long}; and a value greater
 230.953 -     *          than {@code 0} if this {@code Long} is numerically
 230.954 -     *           greater than the argument {@code Long} (signed
 230.955 -     *           comparison).
 230.956 -     * @since   1.2
 230.957 -     */
 230.958 -    public int compareTo(Long anotherLong) {
 230.959 -        return compare(this.value, anotherLong.value);
 230.960 -    }
 230.961 -
 230.962 -    /**
 230.963 -     * Compares two {@code long} values numerically.
 230.964 -     * The value returned is identical to what would be returned by:
 230.965 -     * <pre>
 230.966 -     *    Long.valueOf(x).compareTo(Long.valueOf(y))
 230.967 -     * </pre>
 230.968 -     *
 230.969 -     * @param  x the first {@code long} to compare
 230.970 -     * @param  y the second {@code long} to compare
 230.971 -     * @return the value {@code 0} if {@code x == y};
 230.972 -     *         a value less than {@code 0} if {@code x < y}; and
 230.973 -     *         a value greater than {@code 0} if {@code x > y}
 230.974 -     * @since 1.7
 230.975 -     */
 230.976 -    public static int compare(long x, long y) {
 230.977 -        return (x < y) ? -1 : ((x == y) ? 0 : 1);
 230.978 -    }
 230.979 -
 230.980 -
 230.981 -    // Bit Twiddling
 230.982 -
 230.983 -    /**
 230.984 -     * The number of bits used to represent a {@code long} value in two's
 230.985 -     * complement binary form.
 230.986 -     *
 230.987 -     * @since 1.5
 230.988 -     */
 230.989 -    public static final int SIZE = 64;
 230.990 -
 230.991 -    /**
 230.992 -     * Returns a {@code long} value with at most a single one-bit, in the
 230.993 -     * position of the highest-order ("leftmost") one-bit in the specified
 230.994 -     * {@code long} value.  Returns zero if the specified value has no
 230.995 -     * one-bits in its two's complement binary representation, that is, if it
 230.996 -     * is equal to zero.
 230.997 -     *
 230.998 -     * @return a {@code long} value with a single one-bit, in the position
 230.999 -     *     of the highest-order one-bit in the specified value, or zero if
230.1000 -     *     the specified value is itself equal to zero.
230.1001 -     * @since 1.5
230.1002 -     */
230.1003 -    public static long highestOneBit(long i) {
230.1004 -        // HD, Figure 3-1
230.1005 -        i |= (i >>  1);
230.1006 -        i |= (i >>  2);
230.1007 -        i |= (i >>  4);
230.1008 -        i |= (i >>  8);
230.1009 -        i |= (i >> 16);
230.1010 -        i |= (i >> 32);
230.1011 -        return i - (i >>> 1);
230.1012 -    }
230.1013 -
230.1014 -    /**
230.1015 -     * Returns a {@code long} value with at most a single one-bit, in the
230.1016 -     * position of the lowest-order ("rightmost") one-bit in the specified
230.1017 -     * {@code long} value.  Returns zero if the specified value has no
230.1018 -     * one-bits in its two's complement binary representation, that is, if it
230.1019 -     * is equal to zero.
230.1020 -     *
230.1021 -     * @return a {@code long} value with a single one-bit, in the position
230.1022 -     *     of the lowest-order one-bit in the specified value, or zero if
230.1023 -     *     the specified value is itself equal to zero.
230.1024 -     * @since 1.5
230.1025 -     */
230.1026 -    public static long lowestOneBit(long i) {
230.1027 -        // HD, Section 2-1
230.1028 -        return i & -i;
230.1029 -    }
230.1030 -
230.1031 -    /**
230.1032 -     * Returns the number of zero bits preceding the highest-order
230.1033 -     * ("leftmost") one-bit in the two's complement binary representation
230.1034 -     * of the specified {@code long} value.  Returns 64 if the
230.1035 -     * specified value has no one-bits in its two's complement representation,
230.1036 -     * in other words if it is equal to zero.
230.1037 -     *
230.1038 -     * <p>Note that this method is closely related to the logarithm base 2.
230.1039 -     * For all positive {@code long} values x:
230.1040 -     * <ul>
230.1041 -     * <li>floor(log<sub>2</sub>(x)) = {@code 63 - numberOfLeadingZeros(x)}
230.1042 -     * <li>ceil(log<sub>2</sub>(x)) = {@code 64 - numberOfLeadingZeros(x - 1)}
230.1043 -     * </ul>
230.1044 -     *
230.1045 -     * @return the number of zero bits preceding the highest-order
230.1046 -     *     ("leftmost") one-bit in the two's complement binary representation
230.1047 -     *     of the specified {@code long} value, or 64 if the value
230.1048 -     *     is equal to zero.
230.1049 -     * @since 1.5
230.1050 -     */
230.1051 -    public static int numberOfLeadingZeros(long i) {
230.1052 -        // HD, Figure 5-6
230.1053 -         if (i == 0)
230.1054 -            return 64;
230.1055 -        int n = 1;
230.1056 -        int x = (int)(i >>> 32);
230.1057 -        if (x == 0) { n += 32; x = (int)i; }
230.1058 -        if (x >>> 16 == 0) { n += 16; x <<= 16; }
230.1059 -        if (x >>> 24 == 0) { n +=  8; x <<=  8; }
230.1060 -        if (x >>> 28 == 0) { n +=  4; x <<=  4; }
230.1061 -        if (x >>> 30 == 0) { n +=  2; x <<=  2; }
230.1062 -        n -= x >>> 31;
230.1063 -        return n;
230.1064 -    }
230.1065 -
230.1066 -    /**
230.1067 -     * Returns the number of zero bits following the lowest-order ("rightmost")
230.1068 -     * one-bit in the two's complement binary representation of the specified
230.1069 -     * {@code long} value.  Returns 64 if the specified value has no
230.1070 -     * one-bits in its two's complement representation, in other words if it is
230.1071 -     * equal to zero.
230.1072 -     *
230.1073 -     * @return the number of zero bits following the lowest-order ("rightmost")
230.1074 -     *     one-bit in the two's complement binary representation of the
230.1075 -     *     specified {@code long} value, or 64 if the value is equal
230.1076 -     *     to zero.
230.1077 -     * @since 1.5
230.1078 -     */
230.1079 -    public static int numberOfTrailingZeros(long i) {
230.1080 -        // HD, Figure 5-14
230.1081 -        int x, y;
230.1082 -        if (i == 0) return 64;
230.1083 -        int n = 63;
230.1084 -        y = (int)i; if (y != 0) { n = n -32; x = y; } else x = (int)(i>>>32);
230.1085 -        y = x <<16; if (y != 0) { n = n -16; x = y; }
230.1086 -        y = x << 8; if (y != 0) { n = n - 8; x = y; }
230.1087 -        y = x << 4; if (y != 0) { n = n - 4; x = y; }
230.1088 -        y = x << 2; if (y != 0) { n = n - 2; x = y; }
230.1089 -        return n - ((x << 1) >>> 31);
230.1090 -    }
230.1091 -
230.1092 -    /**
230.1093 -     * Returns the number of one-bits in the two's complement binary
230.1094 -     * representation of the specified {@code long} value.  This function is
230.1095 -     * sometimes referred to as the <i>population count</i>.
230.1096 -     *
230.1097 -     * @return the number of one-bits in the two's complement binary
230.1098 -     *     representation of the specified {@code long} value.
230.1099 -     * @since 1.5
230.1100 -     */
230.1101 -     public static int bitCount(long i) {
230.1102 -        // HD, Figure 5-14
230.1103 -        i = i - ((i >>> 1) & 0x5555555555555555L);
230.1104 -        i = (i & 0x3333333333333333L) + ((i >>> 2) & 0x3333333333333333L);
230.1105 -        i = (i + (i >>> 4)) & 0x0f0f0f0f0f0f0f0fL;
230.1106 -        i = i + (i >>> 8);
230.1107 -        i = i + (i >>> 16);
230.1108 -        i = i + (i >>> 32);
230.1109 -        return (int)i & 0x7f;
230.1110 -     }
230.1111 -
230.1112 -    /**
230.1113 -     * Returns the value obtained by rotating the two's complement binary
230.1114 -     * representation of the specified {@code long} value left by the
230.1115 -     * specified number of bits.  (Bits shifted out of the left hand, or
230.1116 -     * high-order, side reenter on the right, or low-order.)
230.1117 -     *
230.1118 -     * <p>Note that left rotation with a negative distance is equivalent to
230.1119 -     * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val,
230.1120 -     * distance)}.  Note also that rotation by any multiple of 64 is a
230.1121 -     * no-op, so all but the last six bits of the rotation distance can be
230.1122 -     * ignored, even if the distance is negative: {@code rotateLeft(val,
230.1123 -     * distance) == rotateLeft(val, distance & 0x3F)}.
230.1124 -     *
230.1125 -     * @return the value obtained by rotating the two's complement binary
230.1126 -     *     representation of the specified {@code long} value left by the
230.1127 -     *     specified number of bits.
230.1128 -     * @since 1.5
230.1129 -     */
230.1130 -    public static long rotateLeft(long i, int distance) {
230.1131 -        return (i << distance) | (i >>> -distance);
230.1132 -    }
230.1133 -
230.1134 -    /**
230.1135 -     * Returns the value obtained by rotating the two's complement binary
230.1136 -     * representation of the specified {@code long} value right by the
230.1137 -     * specified number of bits.  (Bits shifted out of the right hand, or
230.1138 -     * low-order, side reenter on the left, or high-order.)
230.1139 -     *
230.1140 -     * <p>Note that right rotation with a negative distance is equivalent to
230.1141 -     * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val,
230.1142 -     * distance)}.  Note also that rotation by any multiple of 64 is a
230.1143 -     * no-op, so all but the last six bits of the rotation distance can be
230.1144 -     * ignored, even if the distance is negative: {@code rotateRight(val,
230.1145 -     * distance) == rotateRight(val, distance & 0x3F)}.
230.1146 -     *
230.1147 -     * @return the value obtained by rotating the two's complement binary
230.1148 -     *     representation of the specified {@code long} value right by the
230.1149 -     *     specified number of bits.
230.1150 -     * @since 1.5
230.1151 -     */
230.1152 -    public static long rotateRight(long i, int distance) {
230.1153 -        return (i >>> distance) | (i << -distance);
230.1154 -    }
230.1155 -
230.1156 -    /**
230.1157 -     * Returns the value obtained by reversing the order of the bits in the
230.1158 -     * two's complement binary representation of the specified {@code long}
230.1159 -     * value.
230.1160 -     *
230.1161 -     * @return the value obtained by reversing order of the bits in the
230.1162 -     *     specified {@code long} value.
230.1163 -     * @since 1.5
230.1164 -     */
230.1165 -    public static long reverse(long i) {
230.1166 -        // HD, Figure 7-1
230.1167 -        i = (i & 0x5555555555555555L) << 1 | (i >>> 1) & 0x5555555555555555L;
230.1168 -        i = (i & 0x3333333333333333L) << 2 | (i >>> 2) & 0x3333333333333333L;
230.1169 -        i = (i & 0x0f0f0f0f0f0f0f0fL) << 4 | (i >>> 4) & 0x0f0f0f0f0f0f0f0fL;
230.1170 -        i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;
230.1171 -        i = (i << 48) | ((i & 0xffff0000L) << 16) |
230.1172 -            ((i >>> 16) & 0xffff0000L) | (i >>> 48);
230.1173 -        return i;
230.1174 -    }
230.1175 -
230.1176 -    /**
230.1177 -     * Returns the signum function of the specified {@code long} value.  (The
230.1178 -     * return value is -1 if the specified value is negative; 0 if the
230.1179 -     * specified value is zero; and 1 if the specified value is positive.)
230.1180 -     *
230.1181 -     * @return the signum function of the specified {@code long} value.
230.1182 -     * @since 1.5
230.1183 -     */
230.1184 -    public static int signum(long i) {
230.1185 -        // HD, Section 2-7
230.1186 -        return (int) ((i >> 63) | (-i >>> 63));
230.1187 -    }
230.1188 -
230.1189 -    /**
230.1190 -     * Returns the value obtained by reversing the order of the bytes in the
230.1191 -     * two's complement representation of the specified {@code long} value.
230.1192 -     *
230.1193 -     * @return the value obtained by reversing the bytes in the specified
230.1194 -     *     {@code long} value.
230.1195 -     * @since 1.5
230.1196 -     */
230.1197 -    public static long reverseBytes(long i) {
230.1198 -        i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;
230.1199 -        return (i << 48) | ((i & 0xffff0000L) << 16) |
230.1200 -            ((i >>> 16) & 0xffff0000L) | (i >>> 48);
230.1201 -    }
230.1202 -
230.1203 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
230.1204 -    private static final long serialVersionUID = 4290774380558885855L;
230.1205 -}
   231.1 --- a/emul/src/main/java/java/lang/Math.java	Wed Dec 05 10:03:58 2012 +0100
   231.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   231.3 @@ -1,1243 +0,0 @@
   231.4 -/*
   231.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   231.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   231.7 - *
   231.8 - * This code is free software; you can redistribute it and/or modify it
   231.9 - * under the terms of the GNU General Public License version 2 only, as
  231.10 - * published by the Free Software Foundation.  Oracle designates this
  231.11 - * particular file as subject to the "Classpath" exception as provided
  231.12 - * by Oracle in the LICENSE file that accompanied this code.
  231.13 - *
  231.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  231.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  231.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  231.17 - * version 2 for more details (a copy is included in the LICENSE file that
  231.18 - * accompanied this code).
  231.19 - *
  231.20 - * You should have received a copy of the GNU General Public License version
  231.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  231.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  231.23 - *
  231.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  231.25 - * or visit www.oracle.com if you need additional information or have any
  231.26 - * questions.
  231.27 - */
  231.28 -
  231.29 -package java.lang;
  231.30 -
  231.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  231.32 -
  231.33 -
  231.34 -/**
  231.35 - * The class {@code Math} contains methods for performing basic
  231.36 - * numeric operations such as the elementary exponential, logarithm,
  231.37 - * square root, and trigonometric functions.
  231.38 - *
  231.39 - * <p>Unlike some of the numeric methods of class
  231.40 - * {@code StrictMath}, all implementations of the equivalent
  231.41 - * functions of class {@code Math} are not defined to return the
  231.42 - * bit-for-bit same results.  This relaxation permits
  231.43 - * better-performing implementations where strict reproducibility is
  231.44 - * not required.
  231.45 - *
  231.46 - * <p>By default many of the {@code Math} methods simply call
  231.47 - * the equivalent method in {@code StrictMath} for their
  231.48 - * implementation.  Code generators are encouraged to use
  231.49 - * platform-specific native libraries or microprocessor instructions,
  231.50 - * where available, to provide higher-performance implementations of
  231.51 - * {@code Math} methods.  Such higher-performance
  231.52 - * implementations still must conform to the specification for
  231.53 - * {@code Math}.
  231.54 - *
  231.55 - * <p>The quality of implementation specifications concern two
  231.56 - * properties, accuracy of the returned result and monotonicity of the
  231.57 - * method.  Accuracy of the floating-point {@code Math} methods
  231.58 - * is measured in terms of <i>ulps</i>, units in the last place.  For
  231.59 - * a given floating-point format, an ulp of a specific real number
  231.60 - * value is the distance between the two floating-point values
  231.61 - * bracketing that numerical value.  When discussing the accuracy of a
  231.62 - * method as a whole rather than at a specific argument, the number of
  231.63 - * ulps cited is for the worst-case error at any argument.  If a
  231.64 - * method always has an error less than 0.5 ulps, the method always
  231.65 - * returns the floating-point number nearest the exact result; such a
  231.66 - * method is <i>correctly rounded</i>.  A correctly rounded method is
  231.67 - * generally the best a floating-point approximation can be; however,
  231.68 - * it is impractical for many floating-point methods to be correctly
  231.69 - * rounded.  Instead, for the {@code Math} class, a larger error
  231.70 - * bound of 1 or 2 ulps is allowed for certain methods.  Informally,
  231.71 - * with a 1 ulp error bound, when the exact result is a representable
  231.72 - * number, the exact result should be returned as the computed result;
  231.73 - * otherwise, either of the two floating-point values which bracket
  231.74 - * the exact result may be returned.  For exact results large in
  231.75 - * magnitude, one of the endpoints of the bracket may be infinite.
  231.76 - * Besides accuracy at individual arguments, maintaining proper
  231.77 - * relations between the method at different arguments is also
  231.78 - * important.  Therefore, most methods with more than 0.5 ulp errors
  231.79 - * are required to be <i>semi-monotonic</i>: whenever the mathematical
  231.80 - * function is non-decreasing, so is the floating-point approximation,
  231.81 - * likewise, whenever the mathematical function is non-increasing, so
  231.82 - * is the floating-point approximation.  Not all approximations that
  231.83 - * have 1 ulp accuracy will automatically meet the monotonicity
  231.84 - * requirements.
  231.85 - *
  231.86 - * @author  unascribed
  231.87 - * @author  Joseph D. Darcy
  231.88 - * @since   JDK1.0
  231.89 - */
  231.90 -
  231.91 -public final class Math {
  231.92 -
  231.93 -    /**
  231.94 -     * Don't let anyone instantiate this class.
  231.95 -     */
  231.96 -    private Math() {}
  231.97 -
  231.98 -    /**
  231.99 -     * The {@code double} value that is closer than any other to
 231.100 -     * <i>e</i>, the base of the natural logarithms.
 231.101 -     */
 231.102 -    public static final double E = 2.7182818284590452354;
 231.103 -
 231.104 -    /**
 231.105 -     * The {@code double} value that is closer than any other to
 231.106 -     * <i>pi</i>, the ratio of the circumference of a circle to its
 231.107 -     * diameter.
 231.108 -     */
 231.109 -    public static final double PI = 3.14159265358979323846;
 231.110 -
 231.111 -    /**
 231.112 -     * Returns the trigonometric sine of an angle.  Special cases:
 231.113 -     * <ul><li>If the argument is NaN or an infinity, then the
 231.114 -     * result is NaN.
 231.115 -     * <li>If the argument is zero, then the result is a zero with the
 231.116 -     * same sign as the argument.</ul>
 231.117 -     *
 231.118 -     * <p>The computed result must be within 1 ulp of the exact result.
 231.119 -     * Results must be semi-monotonic.
 231.120 -     *
 231.121 -     * @param   a   an angle, in radians.
 231.122 -     * @return  the sine of the argument.
 231.123 -     */
 231.124 -    @JavaScriptBody(args="a", body="return Math.sin(a);")
 231.125 -    public static double sin(double a) {
 231.126 -        throw new UnsupportedOperationException();
 231.127 -    }
 231.128 -
 231.129 -    /**
 231.130 -     * Returns the trigonometric cosine of an angle. Special cases:
 231.131 -     * <ul><li>If the argument is NaN or an infinity, then the
 231.132 -     * result is NaN.</ul>
 231.133 -     *
 231.134 -     * <p>The computed result must be within 1 ulp of the exact result.
 231.135 -     * Results must be semi-monotonic.
 231.136 -     *
 231.137 -     * @param   a   an angle, in radians.
 231.138 -     * @return  the cosine of the argument.
 231.139 -     */
 231.140 -    @JavaScriptBody(args="a", body="return Math.cos(a);")
 231.141 -    public static double cos(double a) {
 231.142 -        throw new UnsupportedOperationException();
 231.143 -    }
 231.144 -
 231.145 -    /**
 231.146 -     * Returns the trigonometric tangent of an angle.  Special cases:
 231.147 -     * <ul><li>If the argument is NaN or an infinity, then the result
 231.148 -     * is NaN.
 231.149 -     * <li>If the argument is zero, then the result is a zero with the
 231.150 -     * same sign as the argument.</ul>
 231.151 -     *
 231.152 -     * <p>The computed result must be within 1 ulp of the exact result.
 231.153 -     * Results must be semi-monotonic.
 231.154 -     *
 231.155 -     * @param   a   an angle, in radians.
 231.156 -     * @return  the tangent of the argument.
 231.157 -     */
 231.158 -    @JavaScriptBody(args="a", body="return Math.tan(a);")
 231.159 -    public static double tan(double a) {
 231.160 -        throw new UnsupportedOperationException();
 231.161 -    }
 231.162 -
 231.163 -    /**
 231.164 -     * Returns the arc sine of a value; the returned angle is in the
 231.165 -     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
 231.166 -     * <ul><li>If the argument is NaN or its absolute value is greater
 231.167 -     * than 1, then the result is NaN.
 231.168 -     * <li>If the argument is zero, then the result is a zero with the
 231.169 -     * same sign as the argument.</ul>
 231.170 -     *
 231.171 -     * <p>The computed result must be within 1 ulp of the exact result.
 231.172 -     * Results must be semi-monotonic.
 231.173 -     *
 231.174 -     * @param   a   the value whose arc sine is to be returned.
 231.175 -     * @return  the arc sine of the argument.
 231.176 -     */
 231.177 -    @JavaScriptBody(args="a", body="return Math.asin(a);")
 231.178 -    public static double asin(double a) {
 231.179 -        throw new UnsupportedOperationException();
 231.180 -    }
 231.181 -
 231.182 -    /**
 231.183 -     * Returns the arc cosine of a value; the returned angle is in the
 231.184 -     * range 0.0 through <i>pi</i>.  Special case:
 231.185 -     * <ul><li>If the argument is NaN or its absolute value is greater
 231.186 -     * than 1, then the result is NaN.</ul>
 231.187 -     *
 231.188 -     * <p>The computed result must be within 1 ulp of the exact result.
 231.189 -     * Results must be semi-monotonic.
 231.190 -     *
 231.191 -     * @param   a   the value whose arc cosine is to be returned.
 231.192 -     * @return  the arc cosine of the argument.
 231.193 -     */
 231.194 -    @JavaScriptBody(args="a", body="return Math.acos(a);")
 231.195 -    public static double acos(double a) {
 231.196 -        throw new UnsupportedOperationException();
 231.197 -    }
 231.198 -
 231.199 -    /**
 231.200 -     * Returns the arc tangent of a value; the returned angle is in the
 231.201 -     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
 231.202 -     * <ul><li>If the argument is NaN, then the result is NaN.
 231.203 -     * <li>If the argument is zero, then the result is a zero with the
 231.204 -     * same sign as the argument.</ul>
 231.205 -     *
 231.206 -     * <p>The computed result must be within 1 ulp of the exact result.
 231.207 -     * Results must be semi-monotonic.
 231.208 -     *
 231.209 -     * @param   a   the value whose arc tangent is to be returned.
 231.210 -     * @return  the arc tangent of the argument.
 231.211 -     */
 231.212 -    @JavaScriptBody(args="a", body="return Math.atan(a);")
 231.213 -    public static double atan(double a) {
 231.214 -        throw new UnsupportedOperationException();
 231.215 -    }
 231.216 -
 231.217 -    /**
 231.218 -     * Converts an angle measured in degrees to an approximately
 231.219 -     * equivalent angle measured in radians.  The conversion from
 231.220 -     * degrees to radians is generally inexact.
 231.221 -     *
 231.222 -     * @param   angdeg   an angle, in degrees
 231.223 -     * @return  the measurement of the angle {@code angdeg}
 231.224 -     *          in radians.
 231.225 -     * @since   1.2
 231.226 -     */
 231.227 -    public static double toRadians(double angdeg) {
 231.228 -        return angdeg / 180.0 * PI;
 231.229 -    }
 231.230 -
 231.231 -    /**
 231.232 -     * Converts an angle measured in radians to an approximately
 231.233 -     * equivalent angle measured in degrees.  The conversion from
 231.234 -     * radians to degrees is generally inexact; users should
 231.235 -     * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
 231.236 -     * equal {@code 0.0}.
 231.237 -     *
 231.238 -     * @param   angrad   an angle, in radians
 231.239 -     * @return  the measurement of the angle {@code angrad}
 231.240 -     *          in degrees.
 231.241 -     * @since   1.2
 231.242 -     */
 231.243 -    public static double toDegrees(double angrad) {
 231.244 -        return angrad * 180.0 / PI;
 231.245 -    }
 231.246 -
 231.247 -    /**
 231.248 -     * Returns Euler's number <i>e</i> raised to the power of a
 231.249 -     * {@code double} value.  Special cases:
 231.250 -     * <ul><li>If the argument is NaN, the result is NaN.
 231.251 -     * <li>If the argument is positive infinity, then the result is
 231.252 -     * positive infinity.
 231.253 -     * <li>If the argument is negative infinity, then the result is
 231.254 -     * positive zero.</ul>
 231.255 -     *
 231.256 -     * <p>The computed result must be within 1 ulp of the exact result.
 231.257 -     * Results must be semi-monotonic.
 231.258 -     *
 231.259 -     * @param   a   the exponent to raise <i>e</i> to.
 231.260 -     * @return  the value <i>e</i><sup>{@code a}</sup>,
 231.261 -     *          where <i>e</i> is the base of the natural logarithms.
 231.262 -     */
 231.263 -    @JavaScriptBody(args="a", body="return Math.exp(a);")
 231.264 -    public static double exp(double a) {
 231.265 -        throw new UnsupportedOperationException();
 231.266 -    }
 231.267 -
 231.268 -    /**
 231.269 -     * Returns the natural logarithm (base <i>e</i>) of a {@code double}
 231.270 -     * value.  Special cases:
 231.271 -     * <ul><li>If the argument is NaN or less than zero, then the result
 231.272 -     * is NaN.
 231.273 -     * <li>If the argument is positive infinity, then the result is
 231.274 -     * positive infinity.
 231.275 -     * <li>If the argument is positive zero or negative zero, then the
 231.276 -     * result is negative infinity.</ul>
 231.277 -     *
 231.278 -     * <p>The computed result must be within 1 ulp of the exact result.
 231.279 -     * Results must be semi-monotonic.
 231.280 -     *
 231.281 -     * @param   a   a value
 231.282 -     * @return  the value ln&nbsp;{@code a}, the natural logarithm of
 231.283 -     *          {@code a}.
 231.284 -     */
 231.285 -    @JavaScriptBody(args="a", body="return Math.log(a);")
 231.286 -    public static double log(double a) {
 231.287 -        throw new UnsupportedOperationException();
 231.288 -    }
 231.289 -
 231.290 -    /**
 231.291 -     * Returns the base 10 logarithm of a {@code double} value.
 231.292 -     * Special cases:
 231.293 -     *
 231.294 -     * <ul><li>If the argument is NaN or less than zero, then the result
 231.295 -     * is NaN.
 231.296 -     * <li>If the argument is positive infinity, then the result is
 231.297 -     * positive infinity.
 231.298 -     * <li>If the argument is positive zero or negative zero, then the
 231.299 -     * result is negative infinity.
 231.300 -     * <li> If the argument is equal to 10<sup><i>n</i></sup> for
 231.301 -     * integer <i>n</i>, then the result is <i>n</i>.
 231.302 -     * </ul>
 231.303 -     *
 231.304 -     * <p>The computed result must be within 1 ulp of the exact result.
 231.305 -     * Results must be semi-monotonic.
 231.306 -     *
 231.307 -     * @param   a   a value
 231.308 -     * @return  the base 10 logarithm of  {@code a}.
 231.309 -     * @since 1.5
 231.310 -     */
 231.311 -    @JavaScriptBody(args="a", body="return Math.log(a) / Math.LN10;")
 231.312 -    public static double log10(double a) {
 231.313 -        throw new UnsupportedOperationException();
 231.314 -    }
 231.315 -
 231.316 -    /**
 231.317 -     * Returns the correctly rounded positive square root of a
 231.318 -     * {@code double} value.
 231.319 -     * Special cases:
 231.320 -     * <ul><li>If the argument is NaN or less than zero, then the result
 231.321 -     * is NaN.
 231.322 -     * <li>If the argument is positive infinity, then the result is positive
 231.323 -     * infinity.
 231.324 -     * <li>If the argument is positive zero or negative zero, then the
 231.325 -     * result is the same as the argument.</ul>
 231.326 -     * Otherwise, the result is the {@code double} value closest to
 231.327 -     * the true mathematical square root of the argument value.
 231.328 -     *
 231.329 -     * @param   a   a value.
 231.330 -     * @return  the positive square root of {@code a}.
 231.331 -     *          If the argument is NaN or less than zero, the result is NaN.
 231.332 -     */
 231.333 -    @JavaScriptBody(args="a", body="return Math.sqrt(a);")
 231.334 -    public static double sqrt(double a) {
 231.335 -        throw new UnsupportedOperationException();
 231.336 -    }
 231.337 -
 231.338 -    /**
 231.339 -     * Returns the smallest (closest to negative infinity)
 231.340 -     * {@code double} value that is greater than or equal to the
 231.341 -     * argument and is equal to a mathematical integer. Special cases:
 231.342 -     * <ul><li>If the argument value is already equal to a
 231.343 -     * mathematical integer, then the result is the same as the
 231.344 -     * argument.  <li>If the argument is NaN or an infinity or
 231.345 -     * positive zero or negative zero, then the result is the same as
 231.346 -     * the argument.  <li>If the argument value is less than zero but
 231.347 -     * greater than -1.0, then the result is negative zero.</ul> Note
 231.348 -     * that the value of {@code Math.ceil(x)} is exactly the
 231.349 -     * value of {@code -Math.floor(-x)}.
 231.350 -     *
 231.351 -     *
 231.352 -     * @param   a   a value.
 231.353 -     * @return  the smallest (closest to negative infinity)
 231.354 -     *          floating-point value that is greater than or equal to
 231.355 -     *          the argument and is equal to a mathematical integer.
 231.356 -     */
 231.357 -    @JavaScriptBody(args="a", body="return Math.ceil(a);")
 231.358 -    public static double ceil(double a) {
 231.359 -        throw new UnsupportedOperationException();
 231.360 -    }
 231.361 -
 231.362 -    /**
 231.363 -     * Returns the largest (closest to positive infinity)
 231.364 -     * {@code double} value that is less than or equal to the
 231.365 -     * argument and is equal to a mathematical integer. Special cases:
 231.366 -     * <ul><li>If the argument value is already equal to a
 231.367 -     * mathematical integer, then the result is the same as the
 231.368 -     * argument.  <li>If the argument is NaN or an infinity or
 231.369 -     * positive zero or negative zero, then the result is the same as
 231.370 -     * the argument.</ul>
 231.371 -     *
 231.372 -     * @param   a   a value.
 231.373 -     * @return  the largest (closest to positive infinity)
 231.374 -     *          floating-point value that less than or equal to the argument
 231.375 -     *          and is equal to a mathematical integer.
 231.376 -     */
 231.377 -    @JavaScriptBody(args="a", body="return Math.floor(a);")
 231.378 -    public static double floor(double a) {
 231.379 -        throw new UnsupportedOperationException();
 231.380 -    }
 231.381 -
 231.382 -    /**
 231.383 -     * Returns the angle <i>theta</i> from the conversion of rectangular
 231.384 -     * coordinates ({@code x},&nbsp;{@code y}) to polar
 231.385 -     * coordinates (r,&nbsp;<i>theta</i>).
 231.386 -     * This method computes the phase <i>theta</i> by computing an arc tangent
 231.387 -     * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
 231.388 -     * cases:
 231.389 -     * <ul><li>If either argument is NaN, then the result is NaN.
 231.390 -     * <li>If the first argument is positive zero and the second argument
 231.391 -     * is positive, or the first argument is positive and finite and the
 231.392 -     * second argument is positive infinity, then the result is positive
 231.393 -     * zero.
 231.394 -     * <li>If the first argument is negative zero and the second argument
 231.395 -     * is positive, or the first argument is negative and finite and the
 231.396 -     * second argument is positive infinity, then the result is negative zero.
 231.397 -     * <li>If the first argument is positive zero and the second argument
 231.398 -     * is negative, or the first argument is positive and finite and the
 231.399 -     * second argument is negative infinity, then the result is the
 231.400 -     * {@code double} value closest to <i>pi</i>.
 231.401 -     * <li>If the first argument is negative zero and the second argument
 231.402 -     * is negative, or the first argument is negative and finite and the
 231.403 -     * second argument is negative infinity, then the result is the
 231.404 -     * {@code double} value closest to -<i>pi</i>.
 231.405 -     * <li>If the first argument is positive and the second argument is
 231.406 -     * positive zero or negative zero, or the first argument is positive
 231.407 -     * infinity and the second argument is finite, then the result is the
 231.408 -     * {@code double} value closest to <i>pi</i>/2.
 231.409 -     * <li>If the first argument is negative and the second argument is
 231.410 -     * positive zero or negative zero, or the first argument is negative
 231.411 -     * infinity and the second argument is finite, then the result is the
 231.412 -     * {@code double} value closest to -<i>pi</i>/2.
 231.413 -     * <li>If both arguments are positive infinity, then the result is the
 231.414 -     * {@code double} value closest to <i>pi</i>/4.
 231.415 -     * <li>If the first argument is positive infinity and the second argument
 231.416 -     * is negative infinity, then the result is the {@code double}
 231.417 -     * value closest to 3*<i>pi</i>/4.
 231.418 -     * <li>If the first argument is negative infinity and the second argument
 231.419 -     * is positive infinity, then the result is the {@code double} value
 231.420 -     * closest to -<i>pi</i>/4.
 231.421 -     * <li>If both arguments are negative infinity, then the result is the
 231.422 -     * {@code double} value closest to -3*<i>pi</i>/4.</ul>
 231.423 -     *
 231.424 -     * <p>The computed result must be within 2 ulps of the exact result.
 231.425 -     * Results must be semi-monotonic.
 231.426 -     *
 231.427 -     * @param   y   the ordinate coordinate
 231.428 -     * @param   x   the abscissa coordinate
 231.429 -     * @return  the <i>theta</i> component of the point
 231.430 -     *          (<i>r</i>,&nbsp;<i>theta</i>)
 231.431 -     *          in polar coordinates that corresponds to the point
 231.432 -     *          (<i>x</i>,&nbsp;<i>y</i>) in Cartesian coordinates.
 231.433 -     */
 231.434 -    @JavaScriptBody(args={"y", "x"}, body="return Math.atan2(y, x);")
 231.435 -    public static double atan2(double y, double x) {
 231.436 -        throw new UnsupportedOperationException();
 231.437 -    }
 231.438 -
 231.439 -    /**
 231.440 -     * Returns the value of the first argument raised to the power of the
 231.441 -     * second argument. Special cases:
 231.442 -     *
 231.443 -     * <ul><li>If the second argument is positive or negative zero, then the
 231.444 -     * result is 1.0.
 231.445 -     * <li>If the second argument is 1.0, then the result is the same as the
 231.446 -     * first argument.
 231.447 -     * <li>If the second argument is NaN, then the result is NaN.
 231.448 -     * <li>If the first argument is NaN and the second argument is nonzero,
 231.449 -     * then the result is NaN.
 231.450 -     *
 231.451 -     * <li>If
 231.452 -     * <ul>
 231.453 -     * <li>the absolute value of the first argument is greater than 1
 231.454 -     * and the second argument is positive infinity, or
 231.455 -     * <li>the absolute value of the first argument is less than 1 and
 231.456 -     * the second argument is negative infinity,
 231.457 -     * </ul>
 231.458 -     * then the result is positive infinity.
 231.459 -     *
 231.460 -     * <li>If
 231.461 -     * <ul>
 231.462 -     * <li>the absolute value of the first argument is greater than 1 and
 231.463 -     * the second argument is negative infinity, or
 231.464 -     * <li>the absolute value of the
 231.465 -     * first argument is less than 1 and the second argument is positive
 231.466 -     * infinity,
 231.467 -     * </ul>
 231.468 -     * then the result is positive zero.
 231.469 -     *
 231.470 -     * <li>If the absolute value of the first argument equals 1 and the
 231.471 -     * second argument is infinite, then the result is NaN.
 231.472 -     *
 231.473 -     * <li>If
 231.474 -     * <ul>
 231.475 -     * <li>the first argument is positive zero and the second argument
 231.476 -     * is greater than zero, or
 231.477 -     * <li>the first argument is positive infinity and the second
 231.478 -     * argument is less than zero,
 231.479 -     * </ul>
 231.480 -     * then the result is positive zero.
 231.481 -     *
 231.482 -     * <li>If
 231.483 -     * <ul>
 231.484 -     * <li>the first argument is positive zero and the second argument
 231.485 -     * is less than zero, or
 231.486 -     * <li>the first argument is positive infinity and the second
 231.487 -     * argument is greater than zero,
 231.488 -     * </ul>
 231.489 -     * then the result is positive infinity.
 231.490 -     *
 231.491 -     * <li>If
 231.492 -     * <ul>
 231.493 -     * <li>the first argument is negative zero and the second argument
 231.494 -     * is greater than zero but not a finite odd integer, or
 231.495 -     * <li>the first argument is negative infinity and the second
 231.496 -     * argument is less than zero but not a finite odd integer,
 231.497 -     * </ul>
 231.498 -     * then the result is positive zero.
 231.499 -     *
 231.500 -     * <li>If
 231.501 -     * <ul>
 231.502 -     * <li>the first argument is negative zero and the second argument
 231.503 -     * is a positive finite odd integer, or
 231.504 -     * <li>the first argument is negative infinity and the second
 231.505 -     * argument is a negative finite odd integer,
 231.506 -     * </ul>
 231.507 -     * then the result is negative zero.
 231.508 -     *
 231.509 -     * <li>If
 231.510 -     * <ul>
 231.511 -     * <li>the first argument is negative zero and the second argument
 231.512 -     * is less than zero but not a finite odd integer, or
 231.513 -     * <li>the first argument is negative infinity and the second
 231.514 -     * argument is greater than zero but not a finite odd integer,
 231.515 -     * </ul>
 231.516 -     * then the result is positive infinity.
 231.517 -     *
 231.518 -     * <li>If
 231.519 -     * <ul>
 231.520 -     * <li>the first argument is negative zero and the second argument
 231.521 -     * is a negative finite odd integer, or
 231.522 -     * <li>the first argument is negative infinity and the second
 231.523 -     * argument is a positive finite odd integer,
 231.524 -     * </ul>
 231.525 -     * then the result is negative infinity.
 231.526 -     *
 231.527 -     * <li>If the first argument is finite and less than zero
 231.528 -     * <ul>
 231.529 -     * <li> if the second argument is a finite even integer, the
 231.530 -     * result is equal to the result of raising the absolute value of
 231.531 -     * the first argument to the power of the second argument
 231.532 -     *
 231.533 -     * <li>if the second argument is a finite odd integer, the result
 231.534 -     * is equal to the negative of the result of raising the absolute
 231.535 -     * value of the first argument to the power of the second
 231.536 -     * argument
 231.537 -     *
 231.538 -     * <li>if the second argument is finite and not an integer, then
 231.539 -     * the result is NaN.
 231.540 -     * </ul>
 231.541 -     *
 231.542 -     * <li>If both arguments are integers, then the result is exactly equal
 231.543 -     * to the mathematical result of raising the first argument to the power
 231.544 -     * of the second argument if that result can in fact be represented
 231.545 -     * exactly as a {@code double} value.</ul>
 231.546 -     *
 231.547 -     * <p>(In the foregoing descriptions, a floating-point value is
 231.548 -     * considered to be an integer if and only if it is finite and a
 231.549 -     * fixed point of the method {@link #ceil ceil} or,
 231.550 -     * equivalently, a fixed point of the method {@link #floor
 231.551 -     * floor}. A value is a fixed point of a one-argument
 231.552 -     * method if and only if the result of applying the method to the
 231.553 -     * value is equal to the value.)
 231.554 -     *
 231.555 -     * <p>The computed result must be within 1 ulp of the exact result.
 231.556 -     * Results must be semi-monotonic.
 231.557 -     *
 231.558 -     * @param   a   the base.
 231.559 -     * @param   b   the exponent.
 231.560 -     * @return  the value {@code a}<sup>{@code b}</sup>.
 231.561 -     */
 231.562 -    @JavaScriptBody(args={"a", "b"}, body="return Math.pow(a, b);")
 231.563 -    public static double pow(double a, double b) {
 231.564 -        throw new UnsupportedOperationException();
 231.565 -    }
 231.566 -
 231.567 -    /**
 231.568 -     * Returns the closest {@code int} to the argument, with ties
 231.569 -     * rounding up.
 231.570 -     *
 231.571 -     * <p>
 231.572 -     * Special cases:
 231.573 -     * <ul><li>If the argument is NaN, the result is 0.
 231.574 -     * <li>If the argument is negative infinity or any value less than or
 231.575 -     * equal to the value of {@code Integer.MIN_VALUE}, the result is
 231.576 -     * equal to the value of {@code Integer.MIN_VALUE}.
 231.577 -     * <li>If the argument is positive infinity or any value greater than or
 231.578 -     * equal to the value of {@code Integer.MAX_VALUE}, the result is
 231.579 -     * equal to the value of {@code Integer.MAX_VALUE}.</ul>
 231.580 -     *
 231.581 -     * @param   a   a floating-point value to be rounded to an integer.
 231.582 -     * @return  the value of the argument rounded to the nearest
 231.583 -     *          {@code int} value.
 231.584 -     * @see     java.lang.Integer#MAX_VALUE
 231.585 -     * @see     java.lang.Integer#MIN_VALUE
 231.586 -     */
 231.587 -    @JavaScriptBody(args="a", body="return Math.round(a);")
 231.588 -    public static int round(float a) {
 231.589 -        throw new UnsupportedOperationException();
 231.590 -    }
 231.591 -
 231.592 -    /**
 231.593 -     * Returns the closest {@code long} to the argument, with ties
 231.594 -     * rounding up.
 231.595 -     *
 231.596 -     * <p>Special cases:
 231.597 -     * <ul><li>If the argument is NaN, the result is 0.
 231.598 -     * <li>If the argument is negative infinity or any value less than or
 231.599 -     * equal to the value of {@code Long.MIN_VALUE}, the result is
 231.600 -     * equal to the value of {@code Long.MIN_VALUE}.
 231.601 -     * <li>If the argument is positive infinity or any value greater than or
 231.602 -     * equal to the value of {@code Long.MAX_VALUE}, the result is
 231.603 -     * equal to the value of {@code Long.MAX_VALUE}.</ul>
 231.604 -     *
 231.605 -     * @param   a   a floating-point value to be rounded to a
 231.606 -     *          {@code long}.
 231.607 -     * @return  the value of the argument rounded to the nearest
 231.608 -     *          {@code long} value.
 231.609 -     * @see     java.lang.Long#MAX_VALUE
 231.610 -     * @see     java.lang.Long#MIN_VALUE
 231.611 -     */
 231.612 -    @JavaScriptBody(args="a", body="return Math.round(a);")
 231.613 -    public static long round(double a) {
 231.614 -        throw new UnsupportedOperationException();
 231.615 -    }
 231.616 -
 231.617 -//    private static Random randomNumberGenerator;
 231.618 -//
 231.619 -//    private static synchronized Random initRNG() {
 231.620 -//        Random rnd = randomNumberGenerator;
 231.621 -//        return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
 231.622 -//    }
 231.623 -
 231.624 -    /**
 231.625 -     * Returns a {@code double} value with a positive sign, greater
 231.626 -     * than or equal to {@code 0.0} and less than {@code 1.0}.
 231.627 -     * Returned values are chosen pseudorandomly with (approximately)
 231.628 -     * uniform distribution from that range.
 231.629 -     *
 231.630 -     * <p>When this method is first called, it creates a single new
 231.631 -     * pseudorandom-number generator, exactly as if by the expression
 231.632 -     *
 231.633 -     * <blockquote>{@code new java.util.Random()}</blockquote>
 231.634 -     *
 231.635 -     * This new pseudorandom-number generator is used thereafter for
 231.636 -     * all calls to this method and is used nowhere else.
 231.637 -     *
 231.638 -     * <p>This method is properly synchronized to allow correct use by
 231.639 -     * more than one thread. However, if many threads need to generate
 231.640 -     * pseudorandom numbers at a great rate, it may reduce contention
 231.641 -     * for each thread to have its own pseudorandom-number generator.
 231.642 -     *
 231.643 -     * @return  a pseudorandom {@code double} greater than or equal
 231.644 -     * to {@code 0.0} and less than {@code 1.0}.
 231.645 -     * @see Random#nextDouble()
 231.646 -     */
 231.647 -    public static double random() {
 231.648 -        throw new UnsupportedOperationException();
 231.649 -    }
 231.650 -
 231.651 -    /**
 231.652 -     * Returns the absolute value of an {@code int} value.
 231.653 -     * If the argument is not negative, the argument is returned.
 231.654 -     * If the argument is negative, the negation of the argument is returned.
 231.655 -     *
 231.656 -     * <p>Note that if the argument is equal to the value of
 231.657 -     * {@link Integer#MIN_VALUE}, the most negative representable
 231.658 -     * {@code int} value, the result is that same value, which is
 231.659 -     * negative.
 231.660 -     *
 231.661 -     * @param   a   the argument whose absolute value is to be determined
 231.662 -     * @return  the absolute value of the argument.
 231.663 -     */
 231.664 -    public static int abs(int a) {
 231.665 -        return (a < 0) ? -a : a;
 231.666 -    }
 231.667 -
 231.668 -    /**
 231.669 -     * Returns the absolute value of a {@code long} value.
 231.670 -     * If the argument is not negative, the argument is returned.
 231.671 -     * If the argument is negative, the negation of the argument is returned.
 231.672 -     *
 231.673 -     * <p>Note that if the argument is equal to the value of
 231.674 -     * {@link Long#MIN_VALUE}, the most negative representable
 231.675 -     * {@code long} value, the result is that same value, which
 231.676 -     * is negative.
 231.677 -     *
 231.678 -     * @param   a   the argument whose absolute value is to be determined
 231.679 -     * @return  the absolute value of the argument.
 231.680 -     */
 231.681 -    public static long abs(long a) {
 231.682 -        return (a < 0) ? -a : a;
 231.683 -    }
 231.684 -
 231.685 -    /**
 231.686 -     * Returns the absolute value of a {@code float} value.
 231.687 -     * If the argument is not negative, the argument is returned.
 231.688 -     * If the argument is negative, the negation of the argument is returned.
 231.689 -     * Special cases:
 231.690 -     * <ul><li>If the argument is positive zero or negative zero, the
 231.691 -     * result is positive zero.
 231.692 -     * <li>If the argument is infinite, the result is positive infinity.
 231.693 -     * <li>If the argument is NaN, the result is NaN.</ul>
 231.694 -     * In other words, the result is the same as the value of the expression:
 231.695 -     * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
 231.696 -     *
 231.697 -     * @param   a   the argument whose absolute value is to be determined
 231.698 -     * @return  the absolute value of the argument.
 231.699 -     */
 231.700 -    public static float abs(float a) {
 231.701 -        return (a <= 0.0F) ? 0.0F - a : a;
 231.702 -    }
 231.703 -
 231.704 -    /**
 231.705 -     * Returns the absolute value of a {@code double} value.
 231.706 -     * If the argument is not negative, the argument is returned.
 231.707 -     * If the argument is negative, the negation of the argument is returned.
 231.708 -     * Special cases:
 231.709 -     * <ul><li>If the argument is positive zero or negative zero, the result
 231.710 -     * is positive zero.
 231.711 -     * <li>If the argument is infinite, the result is positive infinity.
 231.712 -     * <li>If the argument is NaN, the result is NaN.</ul>
 231.713 -     * In other words, the result is the same as the value of the expression:
 231.714 -     * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
 231.715 -     *
 231.716 -     * @param   a   the argument whose absolute value is to be determined
 231.717 -     * @return  the absolute value of the argument.
 231.718 -     */
 231.719 -    public static double abs(double a) {
 231.720 -        return (a <= 0.0D) ? 0.0D - a : a;
 231.721 -    }
 231.722 -
 231.723 -    /**
 231.724 -     * Returns the greater of two {@code int} values. That is, the
 231.725 -     * result is the argument closer to the value of
 231.726 -     * {@link Integer#MAX_VALUE}. If the arguments have the same value,
 231.727 -     * the result is that same value.
 231.728 -     *
 231.729 -     * @param   a   an argument.
 231.730 -     * @param   b   another argument.
 231.731 -     * @return  the larger of {@code a} and {@code b}.
 231.732 -     */
 231.733 -    public static int max(int a, int b) {
 231.734 -        return (a >= b) ? a : b;
 231.735 -    }
 231.736 -
 231.737 -    /**
 231.738 -     * Returns the greater of two {@code long} values. That is, the
 231.739 -     * result is the argument closer to the value of
 231.740 -     * {@link Long#MAX_VALUE}. If the arguments have the same value,
 231.741 -     * the result is that same value.
 231.742 -     *
 231.743 -     * @param   a   an argument.
 231.744 -     * @param   b   another argument.
 231.745 -     * @return  the larger of {@code a} and {@code b}.
 231.746 -     */
 231.747 -    public static long max(long a, long b) {
 231.748 -        return (a >= b) ? a : b;
 231.749 -    }
 231.750 -
 231.751 -    /**
 231.752 -     * Returns the greater of two {@code float} values.  That is,
 231.753 -     * the result is the argument closer to positive infinity. If the
 231.754 -     * arguments have the same value, the result is that same
 231.755 -     * value. If either value is NaN, then the result is NaN.  Unlike
 231.756 -     * the numerical comparison operators, this method considers
 231.757 -     * negative zero to be strictly smaller than positive zero. If one
 231.758 -     * argument is positive zero and the other negative zero, the
 231.759 -     * result is positive zero.
 231.760 -     *
 231.761 -     * @param   a   an argument.
 231.762 -     * @param   b   another argument.
 231.763 -     * @return  the larger of {@code a} and {@code b}.
 231.764 -     */
 231.765 -    @JavaScriptBody(args={"a", "b"},
 231.766 -        body="return Math.max(a,b);"
 231.767 -    )
 231.768 -    public static float max(float a, float b) {
 231.769 -        throw new UnsupportedOperationException();
 231.770 -    }
 231.771 -
 231.772 -    /**
 231.773 -     * Returns the greater of two {@code double} values.  That
 231.774 -     * is, the result is the argument closer to positive infinity. If
 231.775 -     * the arguments have the same value, the result is that same
 231.776 -     * value. If either value is NaN, then the result is NaN.  Unlike
 231.777 -     * the numerical comparison operators, this method considers
 231.778 -     * negative zero to be strictly smaller than positive zero. If one
 231.779 -     * argument is positive zero and the other negative zero, the
 231.780 -     * result is positive zero.
 231.781 -     *
 231.782 -     * @param   a   an argument.
 231.783 -     * @param   b   another argument.
 231.784 -     * @return  the larger of {@code a} and {@code b}.
 231.785 -     */
 231.786 -    @JavaScriptBody(args={"a", "b"},
 231.787 -        body="return Math.max(a,b);"
 231.788 -    )
 231.789 -    public static double max(double a, double b) {
 231.790 -        throw new UnsupportedOperationException();
 231.791 -    }
 231.792 -
 231.793 -    /**
 231.794 -     * Returns the smaller of two {@code int} values. That is,
 231.795 -     * the result the argument closer to the value of
 231.796 -     * {@link Integer#MIN_VALUE}.  If the arguments have the same
 231.797 -     * value, the result is that same value.
 231.798 -     *
 231.799 -     * @param   a   an argument.
 231.800 -     * @param   b   another argument.
 231.801 -     * @return  the smaller of {@code a} and {@code b}.
 231.802 -     */
 231.803 -    public static int min(int a, int b) {
 231.804 -        return (a <= b) ? a : b;
 231.805 -    }
 231.806 -
 231.807 -    /**
 231.808 -     * Returns the smaller of two {@code long} values. That is,
 231.809 -     * the result is the argument closer to the value of
 231.810 -     * {@link Long#MIN_VALUE}. If the arguments have the same
 231.811 -     * value, the result is that same value.
 231.812 -     *
 231.813 -     * @param   a   an argument.
 231.814 -     * @param   b   another argument.
 231.815 -     * @return  the smaller of {@code a} and {@code b}.
 231.816 -     */
 231.817 -    public static long min(long a, long b) {
 231.818 -        return (a <= b) ? a : b;
 231.819 -    }
 231.820 -
 231.821 -    /**
 231.822 -     * Returns the smaller of two {@code float} values.  That is,
 231.823 -     * the result is the value closer to negative infinity. If the
 231.824 -     * arguments have the same value, the result is that same
 231.825 -     * value. If either value is NaN, then the result is NaN.  Unlike
 231.826 -     * the numerical comparison operators, this method considers
 231.827 -     * negative zero to be strictly smaller than positive zero.  If
 231.828 -     * one argument is positive zero and the other is negative zero,
 231.829 -     * the result is negative zero.
 231.830 -     *
 231.831 -     * @param   a   an argument.
 231.832 -     * @param   b   another argument.
 231.833 -     * @return  the smaller of {@code a} and {@code b}.
 231.834 -     */
 231.835 -    @JavaScriptBody(args={"a", "b"},
 231.836 -        body="return Math.min(a,b);"
 231.837 -    )
 231.838 -    public static float min(float a, float b) {
 231.839 -        throw new UnsupportedOperationException();
 231.840 -    }
 231.841 -
 231.842 -    /**
 231.843 -     * Returns the smaller of two {@code double} values.  That
 231.844 -     * is, the result is the value closer to negative infinity. If the
 231.845 -     * arguments have the same value, the result is that same
 231.846 -     * value. If either value is NaN, then the result is NaN.  Unlike
 231.847 -     * the numerical comparison operators, this method considers
 231.848 -     * negative zero to be strictly smaller than positive zero. If one
 231.849 -     * argument is positive zero and the other is negative zero, the
 231.850 -     * result is negative zero.
 231.851 -     *
 231.852 -     * @param   a   an argument.
 231.853 -     * @param   b   another argument.
 231.854 -     * @return  the smaller of {@code a} and {@code b}.
 231.855 -     */
 231.856 -    @JavaScriptBody(args={"a", "b"},
 231.857 -        body="return Math.min(a,b);"
 231.858 -    )
 231.859 -    public static double min(double a, double b) {
 231.860 -        throw new UnsupportedOperationException();
 231.861 -    }
 231.862 -
 231.863 -    /**
 231.864 -     * Returns the size of an ulp of the argument.  An ulp of a
 231.865 -     * {@code double} value is the positive distance between this
 231.866 -     * floating-point value and the {@code double} value next
 231.867 -     * larger in magnitude.  Note that for non-NaN <i>x</i>,
 231.868 -     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
 231.869 -     *
 231.870 -     * <p>Special Cases:
 231.871 -     * <ul>
 231.872 -     * <li> If the argument is NaN, then the result is NaN.
 231.873 -     * <li> If the argument is positive or negative infinity, then the
 231.874 -     * result is positive infinity.
 231.875 -     * <li> If the argument is positive or negative zero, then the result is
 231.876 -     * {@code Double.MIN_VALUE}.
 231.877 -     * <li> If the argument is &plusmn;{@code Double.MAX_VALUE}, then
 231.878 -     * the result is equal to 2<sup>971</sup>.
 231.879 -     * </ul>
 231.880 -     *
 231.881 -     * @param d the floating-point value whose ulp is to be returned
 231.882 -     * @return the size of an ulp of the argument
 231.883 -     * @author Joseph D. Darcy
 231.884 -     * @since 1.5
 231.885 -     */
 231.886 -//    public static double ulp(double d) {
 231.887 -//        return sun.misc.FpUtils.ulp(d);
 231.888 -//    }
 231.889 -
 231.890 -    /**
 231.891 -     * Returns the size of an ulp of the argument.  An ulp of a
 231.892 -     * {@code float} value is the positive distance between this
 231.893 -     * floating-point value and the {@code float} value next
 231.894 -     * larger in magnitude.  Note that for non-NaN <i>x</i>,
 231.895 -     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
 231.896 -     *
 231.897 -     * <p>Special Cases:
 231.898 -     * <ul>
 231.899 -     * <li> If the argument is NaN, then the result is NaN.
 231.900 -     * <li> If the argument is positive or negative infinity, then the
 231.901 -     * result is positive infinity.
 231.902 -     * <li> If the argument is positive or negative zero, then the result is
 231.903 -     * {@code Float.MIN_VALUE}.
 231.904 -     * <li> If the argument is &plusmn;{@code Float.MAX_VALUE}, then
 231.905 -     * the result is equal to 2<sup>104</sup>.
 231.906 -     * </ul>
 231.907 -     *
 231.908 -     * @param f the floating-point value whose ulp is to be returned
 231.909 -     * @return the size of an ulp of the argument
 231.910 -     * @author Joseph D. Darcy
 231.911 -     * @since 1.5
 231.912 -     */
 231.913 -//    public static float ulp(float f) {
 231.914 -//        return sun.misc.FpUtils.ulp(f);
 231.915 -//    }
 231.916 -
 231.917 -    /**
 231.918 -     * Returns the signum function of the argument; zero if the argument
 231.919 -     * is zero, 1.0 if the argument is greater than zero, -1.0 if the
 231.920 -     * argument is less than zero.
 231.921 -     *
 231.922 -     * <p>Special Cases:
 231.923 -     * <ul>
 231.924 -     * <li> If the argument is NaN, then the result is NaN.
 231.925 -     * <li> If the argument is positive zero or negative zero, then the
 231.926 -     *      result is the same as the argument.
 231.927 -     * </ul>
 231.928 -     *
 231.929 -     * @param d the floating-point value whose signum is to be returned
 231.930 -     * @return the signum function of the argument
 231.931 -     * @author Joseph D. Darcy
 231.932 -     * @since 1.5
 231.933 -     */
 231.934 -//    public static double signum(double d) {
 231.935 -//        return sun.misc.FpUtils.signum(d);
 231.936 -//    }
 231.937 -
 231.938 -    /**
 231.939 -     * Returns the signum function of the argument; zero if the argument
 231.940 -     * is zero, 1.0f if the argument is greater than zero, -1.0f if the
 231.941 -     * argument is less than zero.
 231.942 -     *
 231.943 -     * <p>Special Cases:
 231.944 -     * <ul>
 231.945 -     * <li> If the argument is NaN, then the result is NaN.
 231.946 -     * <li> If the argument is positive zero or negative zero, then the
 231.947 -     *      result is the same as the argument.
 231.948 -     * </ul>
 231.949 -     *
 231.950 -     * @param f the floating-point value whose signum is to be returned
 231.951 -     * @return the signum function of the argument
 231.952 -     * @author Joseph D. Darcy
 231.953 -     * @since 1.5
 231.954 -     */
 231.955 -//    public static float signum(float f) {
 231.956 -//        return sun.misc.FpUtils.signum(f);
 231.957 -//    }
 231.958 -
 231.959 -    /**
 231.960 -     * Returns the first floating-point argument with the sign of the
 231.961 -     * second floating-point argument.  Note that unlike the {@link
 231.962 -     * StrictMath#copySign(double, double) StrictMath.copySign}
 231.963 -     * method, this method does not require NaN {@code sign}
 231.964 -     * arguments to be treated as positive values; implementations are
 231.965 -     * permitted to treat some NaN arguments as positive and other NaN
 231.966 -     * arguments as negative to allow greater performance.
 231.967 -     *
 231.968 -     * @param magnitude  the parameter providing the magnitude of the result
 231.969 -     * @param sign   the parameter providing the sign of the result
 231.970 -     * @return a value with the magnitude of {@code magnitude}
 231.971 -     * and the sign of {@code sign}.
 231.972 -     * @since 1.6
 231.973 -     */
 231.974 -//    public static double copySign(double magnitude, double sign) {
 231.975 -//        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
 231.976 -//    }
 231.977 -
 231.978 -    /**
 231.979 -     * Returns the first floating-point argument with the sign of the
 231.980 -     * second floating-point argument.  Note that unlike the {@link
 231.981 -     * StrictMath#copySign(float, float) StrictMath.copySign}
 231.982 -     * method, this method does not require NaN {@code sign}
 231.983 -     * arguments to be treated as positive values; implementations are
 231.984 -     * permitted to treat some NaN arguments as positive and other NaN
 231.985 -     * arguments as negative to allow greater performance.
 231.986 -     *
 231.987 -     * @param magnitude  the parameter providing the magnitude of the result
 231.988 -     * @param sign   the parameter providing the sign of the result
 231.989 -     * @return a value with the magnitude of {@code magnitude}
 231.990 -     * and the sign of {@code sign}.
 231.991 -     * @since 1.6
 231.992 -     */
 231.993 -//    public static float copySign(float magnitude, float sign) {
 231.994 -//        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
 231.995 -//    }
 231.996 -
 231.997 -    /**
 231.998 -     * Returns the unbiased exponent used in the representation of a
 231.999 -     * {@code float}.  Special cases:
231.1000 -     *
231.1001 -     * <ul>
231.1002 -     * <li>If the argument is NaN or infinite, then the result is
231.1003 -     * {@link Float#MAX_EXPONENT} + 1.
231.1004 -     * <li>If the argument is zero or subnormal, then the result is
231.1005 -     * {@link Float#MIN_EXPONENT} -1.
231.1006 -     * </ul>
231.1007 -     * @param f a {@code float} value
231.1008 -     * @return the unbiased exponent of the argument
231.1009 -     * @since 1.6
231.1010 -     */
231.1011 -//    public static int getExponent(float f) {
231.1012 -//        return sun.misc.FpUtils.getExponent(f);
231.1013 -//    }
231.1014 -
231.1015 -    /**
231.1016 -     * Returns the unbiased exponent used in the representation of a
231.1017 -     * {@code double}.  Special cases:
231.1018 -     *
231.1019 -     * <ul>
231.1020 -     * <li>If the argument is NaN or infinite, then the result is
231.1021 -     * {@link Double#MAX_EXPONENT} + 1.
231.1022 -     * <li>If the argument is zero or subnormal, then the result is
231.1023 -     * {@link Double#MIN_EXPONENT} -1.
231.1024 -     * </ul>
231.1025 -     * @param d a {@code double} value
231.1026 -     * @return the unbiased exponent of the argument
231.1027 -     * @since 1.6
231.1028 -     */
231.1029 -//    public static int getExponent(double d) {
231.1030 -//        return sun.misc.FpUtils.getExponent(d);
231.1031 -//    }
231.1032 -
231.1033 -    /**
231.1034 -     * Returns the floating-point number adjacent to the first
231.1035 -     * argument in the direction of the second argument.  If both
231.1036 -     * arguments compare as equal the second argument is returned.
231.1037 -     *
231.1038 -     * <p>
231.1039 -     * Special cases:
231.1040 -     * <ul>
231.1041 -     * <li> If either argument is a NaN, then NaN is returned.
231.1042 -     *
231.1043 -     * <li> If both arguments are signed zeros, {@code direction}
231.1044 -     * is returned unchanged (as implied by the requirement of
231.1045 -     * returning the second argument if the arguments compare as
231.1046 -     * equal).
231.1047 -     *
231.1048 -     * <li> If {@code start} is
231.1049 -     * &plusmn;{@link Double#MIN_VALUE} and {@code direction}
231.1050 -     * has a value such that the result should have a smaller
231.1051 -     * magnitude, then a zero with the same sign as {@code start}
231.1052 -     * is returned.
231.1053 -     *
231.1054 -     * <li> If {@code start} is infinite and
231.1055 -     * {@code direction} has a value such that the result should
231.1056 -     * have a smaller magnitude, {@link Double#MAX_VALUE} with the
231.1057 -     * same sign as {@code start} is returned.
231.1058 -     *
231.1059 -     * <li> If {@code start} is equal to &plusmn;
231.1060 -     * {@link Double#MAX_VALUE} and {@code direction} has a
231.1061 -     * value such that the result should have a larger magnitude, an
231.1062 -     * infinity with same sign as {@code start} is returned.
231.1063 -     * </ul>
231.1064 -     *
231.1065 -     * @param start  starting floating-point value
231.1066 -     * @param direction value indicating which of
231.1067 -     * {@code start}'s neighbors or {@code start} should
231.1068 -     * be returned
231.1069 -     * @return The floating-point number adjacent to {@code start} in the
231.1070 -     * direction of {@code direction}.
231.1071 -     * @since 1.6
231.1072 -     */
231.1073 -//    public static double nextAfter(double start, double direction) {
231.1074 -//        return sun.misc.FpUtils.nextAfter(start, direction);
231.1075 -//    }
231.1076 -
231.1077 -    /**
231.1078 -     * Returns the floating-point number adjacent to the first
231.1079 -     * argument in the direction of the second argument.  If both
231.1080 -     * arguments compare as equal a value equivalent to the second argument
231.1081 -     * is returned.
231.1082 -     *
231.1083 -     * <p>
231.1084 -     * Special cases:
231.1085 -     * <ul>
231.1086 -     * <li> If either argument is a NaN, then NaN is returned.
231.1087 -     *
231.1088 -     * <li> If both arguments are signed zeros, a value equivalent
231.1089 -     * to {@code direction} is returned.
231.1090 -     *
231.1091 -     * <li> If {@code start} is
231.1092 -     * &plusmn;{@link Float#MIN_VALUE} and {@code direction}
231.1093 -     * has a value such that the result should have a smaller
231.1094 -     * magnitude, then a zero with the same sign as {@code start}
231.1095 -     * is returned.
231.1096 -     *
231.1097 -     * <li> If {@code start} is infinite and
231.1098 -     * {@code direction} has a value such that the result should
231.1099 -     * have a smaller magnitude, {@link Float#MAX_VALUE} with the
231.1100 -     * same sign as {@code start} is returned.
231.1101 -     *
231.1102 -     * <li> If {@code start} is equal to &plusmn;
231.1103 -     * {@link Float#MAX_VALUE} and {@code direction} has a
231.1104 -     * value such that the result should have a larger magnitude, an
231.1105 -     * infinity with same sign as {@code start} is returned.
231.1106 -     * </ul>
231.1107 -     *
231.1108 -     * @param start  starting floating-point value
231.1109 -     * @param direction value indicating which of
231.1110 -     * {@code start}'s neighbors or {@code start} should
231.1111 -     * be returned
231.1112 -     * @return The floating-point number adjacent to {@code start} in the
231.1113 -     * direction of {@code direction}.
231.1114 -     * @since 1.6
231.1115 -     */
231.1116 -//    public static float nextAfter(float start, double direction) {
231.1117 -//        return sun.misc.FpUtils.nextAfter(start, direction);
231.1118 -//    }
231.1119 -
231.1120 -    /**
231.1121 -     * Returns the floating-point value adjacent to {@code d} in
231.1122 -     * the direction of positive infinity.  This method is
231.1123 -     * semantically equivalent to {@code nextAfter(d,
231.1124 -     * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
231.1125 -     * implementation may run faster than its equivalent
231.1126 -     * {@code nextAfter} call.
231.1127 -     *
231.1128 -     * <p>Special Cases:
231.1129 -     * <ul>
231.1130 -     * <li> If the argument is NaN, the result is NaN.
231.1131 -     *
231.1132 -     * <li> If the argument is positive infinity, the result is
231.1133 -     * positive infinity.
231.1134 -     *
231.1135 -     * <li> If the argument is zero, the result is
231.1136 -     * {@link Double#MIN_VALUE}
231.1137 -     *
231.1138 -     * </ul>
231.1139 -     *
231.1140 -     * @param d starting floating-point value
231.1141 -     * @return The adjacent floating-point value closer to positive
231.1142 -     * infinity.
231.1143 -     * @since 1.6
231.1144 -     */
231.1145 -//    public static double nextUp(double d) {
231.1146 -//        return sun.misc.FpUtils.nextUp(d);
231.1147 -//    }
231.1148 -
231.1149 -    /**
231.1150 -     * Returns the floating-point value adjacent to {@code f} in
231.1151 -     * the direction of positive infinity.  This method is
231.1152 -     * semantically equivalent to {@code nextAfter(f,
231.1153 -     * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
231.1154 -     * implementation may run faster than its equivalent
231.1155 -     * {@code nextAfter} call.
231.1156 -     *
231.1157 -     * <p>Special Cases:
231.1158 -     * <ul>
231.1159 -     * <li> If the argument is NaN, the result is NaN.
231.1160 -     *
231.1161 -     * <li> If the argument is positive infinity, the result is
231.1162 -     * positive infinity.
231.1163 -     *
231.1164 -     * <li> If the argument is zero, the result is
231.1165 -     * {@link Float#MIN_VALUE}
231.1166 -     *
231.1167 -     * </ul>
231.1168 -     *
231.1169 -     * @param f starting floating-point value
231.1170 -     * @return The adjacent floating-point value closer to positive
231.1171 -     * infinity.
231.1172 -     * @since 1.6
231.1173 -     */
231.1174 -//    public static float nextUp(float f) {
231.1175 -//        return sun.misc.FpUtils.nextUp(f);
231.1176 -//    }
231.1177 -
231.1178 -
231.1179 -    /**
231.1180 -     * Return {@code d} &times;
231.1181 -     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
231.1182 -     * by a single correctly rounded floating-point multiply to a
231.1183 -     * member of the double value set.  See the Java
231.1184 -     * Language Specification for a discussion of floating-point
231.1185 -     * value sets.  If the exponent of the result is between {@link
231.1186 -     * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
231.1187 -     * answer is calculated exactly.  If the exponent of the result
231.1188 -     * would be larger than {@code Double.MAX_EXPONENT}, an
231.1189 -     * infinity is returned.  Note that if the result is subnormal,
231.1190 -     * precision may be lost; that is, when {@code scalb(x, n)}
231.1191 -     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
231.1192 -     * <i>x</i>.  When the result is non-NaN, the result has the same
231.1193 -     * sign as {@code d}.
231.1194 -     *
231.1195 -     * <p>Special cases:
231.1196 -     * <ul>
231.1197 -     * <li> If the first argument is NaN, NaN is returned.
231.1198 -     * <li> If the first argument is infinite, then an infinity of the
231.1199 -     * same sign is returned.
231.1200 -     * <li> If the first argument is zero, then a zero of the same
231.1201 -     * sign is returned.
231.1202 -     * </ul>
231.1203 -     *
231.1204 -     * @param d number to be scaled by a power of two.
231.1205 -     * @param scaleFactor power of 2 used to scale {@code d}
231.1206 -     * @return {@code d} &times; 2<sup>{@code scaleFactor}</sup>
231.1207 -     * @since 1.6
231.1208 -     */
231.1209 -//    public static double scalb(double d, int scaleFactor) {
231.1210 -//        return sun.misc.FpUtils.scalb(d, scaleFactor);
231.1211 -//    }
231.1212 -
231.1213 -    /**
231.1214 -     * Return {@code f} &times;
231.1215 -     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
231.1216 -     * by a single correctly rounded floating-point multiply to a
231.1217 -     * member of the float value set.  See the Java
231.1218 -     * Language Specification for a discussion of floating-point
231.1219 -     * value sets.  If the exponent of the result is between {@link
231.1220 -     * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
231.1221 -     * answer is calculated exactly.  If the exponent of the result
231.1222 -     * would be larger than {@code Float.MAX_EXPONENT}, an
231.1223 -     * infinity is returned.  Note that if the result is subnormal,
231.1224 -     * precision may be lost; that is, when {@code scalb(x, n)}
231.1225 -     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
231.1226 -     * <i>x</i>.  When the result is non-NaN, the result has the same
231.1227 -     * sign as {@code f}.
231.1228 -     *
231.1229 -     * <p>Special cases:
231.1230 -     * <ul>
231.1231 -     * <li> If the first argument is NaN, NaN is returned.
231.1232 -     * <li> If the first argument is infinite, then an infinity of the
231.1233 -     * same sign is returned.
231.1234 -     * <li> If the first argument is zero, then a zero of the same
231.1235 -     * sign is returned.
231.1236 -     * </ul>
231.1237 -     *
231.1238 -     * @param f number to be scaled by a power of two.
231.1239 -     * @param scaleFactor power of 2 used to scale {@code f}
231.1240 -     * @return {@code f} &times; 2<sup>{@code scaleFactor}</sup>
231.1241 -     * @since 1.6
231.1242 -     */
231.1243 -//    public static float scalb(float f, int scaleFactor) {
231.1244 -//        return sun.misc.FpUtils.scalb(f, scaleFactor);
231.1245 -//    }
231.1246 -}
   232.1 --- a/emul/src/main/java/java/lang/NullPointerException.java	Wed Dec 05 10:03:58 2012 +0100
   232.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   232.3 @@ -1,72 +0,0 @@
   232.4 -/*
   232.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   232.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   232.7 - *
   232.8 - * This code is free software; you can redistribute it and/or modify it
   232.9 - * under the terms of the GNU General Public License version 2 only, as
  232.10 - * published by the Free Software Foundation.  Oracle designates this
  232.11 - * particular file as subject to the "Classpath" exception as provided
  232.12 - * by Oracle in the LICENSE file that accompanied this code.
  232.13 - *
  232.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  232.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  232.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  232.17 - * version 2 for more details (a copy is included in the LICENSE file that
  232.18 - * accompanied this code).
  232.19 - *
  232.20 - * You should have received a copy of the GNU General Public License version
  232.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  232.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  232.23 - *
  232.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  232.25 - * or visit www.oracle.com if you need additional information or have any
  232.26 - * questions.
  232.27 - */
  232.28 -
  232.29 -package java.lang;
  232.30 -
  232.31 -/**
  232.32 - * Thrown when an application attempts to use {@code null} in a
  232.33 - * case where an object is required. These include:
  232.34 - * <ul>
  232.35 - * <li>Calling the instance method of a {@code null} object.
  232.36 - * <li>Accessing or modifying the field of a {@code null} object.
  232.37 - * <li>Taking the length of {@code null} as if it were an array.
  232.38 - * <li>Accessing or modifying the slots of {@code null} as if it
  232.39 - *     were an array.
  232.40 - * <li>Throwing {@code null} as if it were a {@code Throwable}
  232.41 - *     value.
  232.42 - * </ul>
  232.43 - * <p>
  232.44 - * Applications should throw instances of this class to indicate
  232.45 - * other illegal uses of the {@code null} object.
  232.46 - *
  232.47 - * {@code NullPointerException} objects may be constructed by the
  232.48 - * virtual machine as if {@linkplain Throwable#Throwable(String,
  232.49 - * Throwable, boolean, boolean) suppression were disabled and/or the
  232.50 - * stack trace was not writable}.
  232.51 - *
  232.52 - * @author  unascribed
  232.53 - * @since   JDK1.0
  232.54 - */
  232.55 -public
  232.56 -class NullPointerException extends RuntimeException {
  232.57 -    private static final long serialVersionUID = 5162710183389028792L;
  232.58 -
  232.59 -    /**
  232.60 -     * Constructs a {@code NullPointerException} with no detail message.
  232.61 -     */
  232.62 -    public NullPointerException() {
  232.63 -        super();
  232.64 -    }
  232.65 -
  232.66 -    /**
  232.67 -     * Constructs a {@code NullPointerException} with the specified
  232.68 -     * detail message.
  232.69 -     *
  232.70 -     * @param   s   the detail message.
  232.71 -     */
  232.72 -    public NullPointerException(String s) {
  232.73 -        super(s);
  232.74 -    }
  232.75 -}
   233.1 --- a/emul/src/main/java/java/lang/Number.java	Wed Dec 05 10:03:58 2012 +0100
   233.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   233.3 @@ -1,112 +0,0 @@
   233.4 -/*
   233.5 - * Copyright (c) 1994, 2001, Oracle and/or its affiliates. All rights reserved.
   233.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   233.7 - *
   233.8 - * This code is free software; you can redistribute it and/or modify it
   233.9 - * under the terms of the GNU General Public License version 2 only, as
  233.10 - * published by the Free Software Foundation.  Oracle designates this
  233.11 - * particular file as subject to the "Classpath" exception as provided
  233.12 - * by Oracle in the LICENSE file that accompanied this code.
  233.13 - *
  233.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  233.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  233.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  233.17 - * version 2 for more details (a copy is included in the LICENSE file that
  233.18 - * accompanied this code).
  233.19 - *
  233.20 - * You should have received a copy of the GNU General Public License version
  233.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  233.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  233.23 - *
  233.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  233.25 - * or visit www.oracle.com if you need additional information or have any
  233.26 - * questions.
  233.27 - */
  233.28 -
  233.29 -package java.lang;
  233.30 -
  233.31 -/**
  233.32 - * The abstract class <code>Number</code> is the superclass of classes
  233.33 - * <code>BigDecimal</code>, <code>BigInteger</code>,
  233.34 - * <code>Byte</code>, <code>Double</code>, <code>Float</code>,
  233.35 - * <code>Integer</code>, <code>Long</code>, and <code>Short</code>.
  233.36 - * <p>
  233.37 - * Subclasses of <code>Number</code> must provide methods to convert
  233.38 - * the represented numeric value to <code>byte</code>, <code>double</code>,
  233.39 - * <code>float</code>, <code>int</code>, <code>long</code>, and
  233.40 - * <code>short</code>.
  233.41 - *
  233.42 - * @author      Lee Boynton
  233.43 - * @author      Arthur van Hoff
  233.44 - * @see     java.lang.Byte
  233.45 - * @see     java.lang.Double
  233.46 - * @see     java.lang.Float
  233.47 - * @see     java.lang.Integer
  233.48 - * @see     java.lang.Long
  233.49 - * @see     java.lang.Short
  233.50 - * @since   JDK1.0
  233.51 - */
  233.52 -public abstract class Number implements java.io.Serializable {
  233.53 -    /**
  233.54 -     * Returns the value of the specified number as an <code>int</code>.
  233.55 -     * This may involve rounding or truncation.
  233.56 -     *
  233.57 -     * @return  the numeric value represented by this object after conversion
  233.58 -     *          to type <code>int</code>.
  233.59 -     */
  233.60 -    public abstract int intValue();
  233.61 -
  233.62 -    /**
  233.63 -     * Returns the value of the specified number as a <code>long</code>.
  233.64 -     * This may involve rounding or truncation.
  233.65 -     *
  233.66 -     * @return  the numeric value represented by this object after conversion
  233.67 -     *          to type <code>long</code>.
  233.68 -     */
  233.69 -    public abstract long longValue();
  233.70 -
  233.71 -    /**
  233.72 -     * Returns the value of the specified number as a <code>float</code>.
  233.73 -     * This may involve rounding.
  233.74 -     *
  233.75 -     * @return  the numeric value represented by this object after conversion
  233.76 -     *          to type <code>float</code>.
  233.77 -     */
  233.78 -    public abstract float floatValue();
  233.79 -
  233.80 -    /**
  233.81 -     * Returns the value of the specified number as a <code>double</code>.
  233.82 -     * This may involve rounding.
  233.83 -     *
  233.84 -     * @return  the numeric value represented by this object after conversion
  233.85 -     *          to type <code>double</code>.
  233.86 -     */
  233.87 -    public abstract double doubleValue();
  233.88 -
  233.89 -    /**
  233.90 -     * Returns the value of the specified number as a <code>byte</code>.
  233.91 -     * This may involve rounding or truncation.
  233.92 -     *
  233.93 -     * @return  the numeric value represented by this object after conversion
  233.94 -     *          to type <code>byte</code>.
  233.95 -     * @since   JDK1.1
  233.96 -     */
  233.97 -    public byte byteValue() {
  233.98 -        return (byte)intValue();
  233.99 -    }
 233.100 -
 233.101 -    /**
 233.102 -     * Returns the value of the specified number as a <code>short</code>.
 233.103 -     * This may involve rounding or truncation.
 233.104 -     *
 233.105 -     * @return  the numeric value represented by this object after conversion
 233.106 -     *          to type <code>short</code>.
 233.107 -     * @since   JDK1.1
 233.108 -     */
 233.109 -    public short shortValue() {
 233.110 -        return (short)intValue();
 233.111 -    }
 233.112 -
 233.113 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 233.114 -    private static final long serialVersionUID = -8742448824652078965L;
 233.115 -}
   234.1 --- a/emul/src/main/java/java/lang/NumberFormatException.java	Wed Dec 05 10:03:58 2012 +0100
   234.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   234.3 @@ -1,67 +0,0 @@
   234.4 -/*
   234.5 - * Copyright (c) 1994, 2001, Oracle and/or its affiliates. All rights reserved.
   234.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   234.7 - *
   234.8 - * This code is free software; you can redistribute it and/or modify it
   234.9 - * under the terms of the GNU General Public License version 2 only, as
  234.10 - * published by the Free Software Foundation.  Oracle designates this
  234.11 - * particular file as subject to the "Classpath" exception as provided
  234.12 - * by Oracle in the LICENSE file that accompanied this code.
  234.13 - *
  234.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  234.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  234.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  234.17 - * version 2 for more details (a copy is included in the LICENSE file that
  234.18 - * accompanied this code).
  234.19 - *
  234.20 - * You should have received a copy of the GNU General Public License version
  234.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  234.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  234.23 - *
  234.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  234.25 - * or visit www.oracle.com if you need additional information or have any
  234.26 - * questions.
  234.27 - */
  234.28 -
  234.29 -package java.lang;
  234.30 -
  234.31 -/**
  234.32 - * Thrown to indicate that the application has attempted to convert
  234.33 - * a string to one of the numeric types, but that the string does not
  234.34 - * have the appropriate format.
  234.35 - *
  234.36 - * @author  unascribed
  234.37 - * @see     java.lang.Integer#toString()
  234.38 - * @since   JDK1.0
  234.39 - */
  234.40 -public
  234.41 -class NumberFormatException extends IllegalArgumentException {
  234.42 -    static final long serialVersionUID = -2848938806368998894L;
  234.43 -
  234.44 -    /**
  234.45 -     * Constructs a <code>NumberFormatException</code> with no detail message.
  234.46 -     */
  234.47 -    public NumberFormatException () {
  234.48 -        super();
  234.49 -    }
  234.50 -
  234.51 -    /**
  234.52 -     * Constructs a <code>NumberFormatException</code> with the
  234.53 -     * specified detail message.
  234.54 -     *
  234.55 -     * @param   s   the detail message.
  234.56 -     */
  234.57 -    public NumberFormatException (String s) {
  234.58 -        super (s);
  234.59 -    }
  234.60 -
  234.61 -    /**
  234.62 -     * Factory method for making a <code>NumberFormatException</code>
  234.63 -     * given the specified input which caused the error.
  234.64 -     *
  234.65 -     * @param   s   the input causing the error
  234.66 -     */
  234.67 -    static NumberFormatException forInputString(String s) {
  234.68 -        return new NumberFormatException("For input string: \"" + s + "\"");
  234.69 -    }
  234.70 -}
   235.1 --- a/emul/src/main/java/java/lang/Object.java	Wed Dec 05 10:03:58 2012 +0100
   235.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   235.3 @@ -1,560 +0,0 @@
   235.4 -/*
   235.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   235.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   235.7 - *
   235.8 - * This code is free software; you can redistribute it and/or modify it
   235.9 - * under the terms of the GNU General Public License version 2 only, as
  235.10 - * published by the Free Software Foundation.  Oracle designates this
  235.11 - * particular file as subject to the "Classpath" exception as provided
  235.12 - * by Oracle in the LICENSE file that accompanied this code.
  235.13 - *
  235.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  235.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  235.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  235.17 - * version 2 for more details (a copy is included in the LICENSE file that
  235.18 - * accompanied this code).
  235.19 - *
  235.20 - * You should have received a copy of the GNU General Public License version
  235.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  235.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  235.23 - *
  235.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  235.25 - * or visit www.oracle.com if you need additional information or have any
  235.26 - * questions.
  235.27 - */
  235.28 -
  235.29 -package java.lang;
  235.30 -
  235.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  235.32 -import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  235.33 -
  235.34 -/**
  235.35 - * Class {@code Object} is the root of the class hierarchy.
  235.36 - * Every class has {@code Object} as a superclass. All objects,
  235.37 - * including arrays, implement the methods of this class.
  235.38 - *
  235.39 - * @author  unascribed
  235.40 - * @see     java.lang.Class
  235.41 - * @since   JDK1.0
  235.42 - */
  235.43 -@JavaScriptPrototype(container = "Object.prototype", prototype = "new Object")
  235.44 -public class Object {
  235.45 -
  235.46 -    @JavaScriptBody(args = {}, body = "")
  235.47 -    private static native void registerNatives();
  235.48 -    static {
  235.49 -        registerNatives();
  235.50 -    }
  235.51 -
  235.52 -    /**
  235.53 -     * Returns the runtime class of this {@code Object}. The returned
  235.54 -     * {@code Class} object is the object that is locked by {@code
  235.55 -     * static synchronized} methods of the represented class.
  235.56 -     *
  235.57 -     * <p><b>The actual result type is {@code Class<? extends |X|>}
  235.58 -     * where {@code |X|} is the erasure of the static type of the
  235.59 -     * expression on which {@code getClass} is called.</b> For
  235.60 -     * example, no cast is required in this code fragment:</p>
  235.61 -     *
  235.62 -     * <p>
  235.63 -     * {@code Number n = 0;                             }<br>
  235.64 -     * {@code Class<? extends Number> c = n.getClass(); }
  235.65 -     * </p>
  235.66 -     *
  235.67 -     * @return The {@code Class} object that represents the runtime
  235.68 -     *         class of this object.
  235.69 -     * @see    Class Literals, section 15.8.2 of
  235.70 -     *         <cite>The Java&trade; Language Specification</cite>.
  235.71 -     */
  235.72 -    @JavaScriptBody(args="self", body="return self.constructor.$class;")
  235.73 -    public final native Class<?> getClass();
  235.74 -
  235.75 -    /**
  235.76 -     * Returns a hash code value for the object. This method is
  235.77 -     * supported for the benefit of hash tables such as those provided by
  235.78 -     * {@link java.util.HashMap}.
  235.79 -     * <p>
  235.80 -     * The general contract of {@code hashCode} is:
  235.81 -     * <ul>
  235.82 -     * <li>Whenever it is invoked on the same object more than once during
  235.83 -     *     an execution of a Java application, the {@code hashCode} method
  235.84 -     *     must consistently return the same integer, provided no information
  235.85 -     *     used in {@code equals} comparisons on the object is modified.
  235.86 -     *     This integer need not remain consistent from one execution of an
  235.87 -     *     application to another execution of the same application.
  235.88 -     * <li>If two objects are equal according to the {@code equals(Object)}
  235.89 -     *     method, then calling the {@code hashCode} method on each of
  235.90 -     *     the two objects must produce the same integer result.
  235.91 -     * <li>It is <em>not</em> required that if two objects are unequal
  235.92 -     *     according to the {@link java.lang.Object#equals(java.lang.Object)}
  235.93 -     *     method, then calling the {@code hashCode} method on each of the
  235.94 -     *     two objects must produce distinct integer results.  However, the
  235.95 -     *     programmer should be aware that producing distinct integer results
  235.96 -     *     for unequal objects may improve the performance of hash tables.
  235.97 -     * </ul>
  235.98 -     * <p>
  235.99 -     * As much as is reasonably practical, the hashCode method defined by
 235.100 -     * class {@code Object} does return distinct integers for distinct
 235.101 -     * objects. (This is typically implemented by converting the internal
 235.102 -     * address of the object into an integer, but this implementation
 235.103 -     * technique is not required by the
 235.104 -     * Java<font size="-2"><sup>TM</sup></font> programming language.)
 235.105 -     *
 235.106 -     * @return  a hash code value for this object.
 235.107 -     * @see     java.lang.Object#equals(java.lang.Object)
 235.108 -     * @see     java.lang.System#identityHashCode
 235.109 -     */
 235.110 -    public native int hashCode();
 235.111 -
 235.112 -    /**
 235.113 -     * Indicates whether some other object is "equal to" this one.
 235.114 -     * <p>
 235.115 -     * The {@code equals} method implements an equivalence relation
 235.116 -     * on non-null object references:
 235.117 -     * <ul>
 235.118 -     * <li>It is <i>reflexive</i>: for any non-null reference value
 235.119 -     *     {@code x}, {@code x.equals(x)} should return
 235.120 -     *     {@code true}.
 235.121 -     * <li>It is <i>symmetric</i>: for any non-null reference values
 235.122 -     *     {@code x} and {@code y}, {@code x.equals(y)}
 235.123 -     *     should return {@code true} if and only if
 235.124 -     *     {@code y.equals(x)} returns {@code true}.
 235.125 -     * <li>It is <i>transitive</i>: for any non-null reference values
 235.126 -     *     {@code x}, {@code y}, and {@code z}, if
 235.127 -     *     {@code x.equals(y)} returns {@code true} and
 235.128 -     *     {@code y.equals(z)} returns {@code true}, then
 235.129 -     *     {@code x.equals(z)} should return {@code true}.
 235.130 -     * <li>It is <i>consistent</i>: for any non-null reference values
 235.131 -     *     {@code x} and {@code y}, multiple invocations of
 235.132 -     *     {@code x.equals(y)} consistently return {@code true}
 235.133 -     *     or consistently return {@code false}, provided no
 235.134 -     *     information used in {@code equals} comparisons on the
 235.135 -     *     objects is modified.
 235.136 -     * <li>For any non-null reference value {@code x},
 235.137 -     *     {@code x.equals(null)} should return {@code false}.
 235.138 -     * </ul>
 235.139 -     * <p>
 235.140 -     * The {@code equals} method for class {@code Object} implements
 235.141 -     * the most discriminating possible equivalence relation on objects;
 235.142 -     * that is, for any non-null reference values {@code x} and
 235.143 -     * {@code y}, this method returns {@code true} if and only
 235.144 -     * if {@code x} and {@code y} refer to the same object
 235.145 -     * ({@code x == y} has the value {@code true}).
 235.146 -     * <p>
 235.147 -     * Note that it is generally necessary to override the {@code hashCode}
 235.148 -     * method whenever this method is overridden, so as to maintain the
 235.149 -     * general contract for the {@code hashCode} method, which states
 235.150 -     * that equal objects must have equal hash codes.
 235.151 -     *
 235.152 -     * @param   obj   the reference object with which to compare.
 235.153 -     * @return  {@code true} if this object is the same as the obj
 235.154 -     *          argument; {@code false} otherwise.
 235.155 -     * @see     #hashCode()
 235.156 -     * @see     java.util.HashMap
 235.157 -     */
 235.158 -    public boolean equals(Object obj) {
 235.159 -        return (this == obj);
 235.160 -    }
 235.161 -
 235.162 -    /**
 235.163 -     * Creates and returns a copy of this object.  The precise meaning
 235.164 -     * of "copy" may depend on the class of the object. The general
 235.165 -     * intent is that, for any object {@code x}, the expression:
 235.166 -     * <blockquote>
 235.167 -     * <pre>
 235.168 -     * x.clone() != x</pre></blockquote>
 235.169 -     * will be true, and that the expression:
 235.170 -     * <blockquote>
 235.171 -     * <pre>
 235.172 -     * x.clone().getClass() == x.getClass()</pre></blockquote>
 235.173 -     * will be {@code true}, but these are not absolute requirements.
 235.174 -     * While it is typically the case that:
 235.175 -     * <blockquote>
 235.176 -     * <pre>
 235.177 -     * x.clone().equals(x)</pre></blockquote>
 235.178 -     * will be {@code true}, this is not an absolute requirement.
 235.179 -     * <p>
 235.180 -     * By convention, the returned object should be obtained by calling
 235.181 -     * {@code super.clone}.  If a class and all of its superclasses (except
 235.182 -     * {@code Object}) obey this convention, it will be the case that
 235.183 -     * {@code x.clone().getClass() == x.getClass()}.
 235.184 -     * <p>
 235.185 -     * By convention, the object returned by this method should be independent
 235.186 -     * of this object (which is being cloned).  To achieve this independence,
 235.187 -     * it may be necessary to modify one or more fields of the object returned
 235.188 -     * by {@code super.clone} before returning it.  Typically, this means
 235.189 -     * copying any mutable objects that comprise the internal "deep structure"
 235.190 -     * of the object being cloned and replacing the references to these
 235.191 -     * objects with references to the copies.  If a class contains only
 235.192 -     * primitive fields or references to immutable objects, then it is usually
 235.193 -     * the case that no fields in the object returned by {@code super.clone}
 235.194 -     * need to be modified.
 235.195 -     * <p>
 235.196 -     * The method {@code clone} for class {@code Object} performs a
 235.197 -     * specific cloning operation. First, if the class of this object does
 235.198 -     * not implement the interface {@code Cloneable}, then a
 235.199 -     * {@code CloneNotSupportedException} is thrown. Note that all arrays
 235.200 -     * are considered to implement the interface {@code Cloneable} and that
 235.201 -     * the return type of the {@code clone} method of an array type {@code T[]}
 235.202 -     * is {@code T[]} where T is any reference or primitive type.
 235.203 -     * Otherwise, this method creates a new instance of the class of this
 235.204 -     * object and initializes all its fields with exactly the contents of
 235.205 -     * the corresponding fields of this object, as if by assignment; the
 235.206 -     * contents of the fields are not themselves cloned. Thus, this method
 235.207 -     * performs a "shallow copy" of this object, not a "deep copy" operation.
 235.208 -     * <p>
 235.209 -     * The class {@code Object} does not itself implement the interface
 235.210 -     * {@code Cloneable}, so calling the {@code clone} method on an object
 235.211 -     * whose class is {@code Object} will result in throwing an
 235.212 -     * exception at run time.
 235.213 -     *
 235.214 -     * @return     a clone of this instance.
 235.215 -     * @exception  CloneNotSupportedException  if the object's class does not
 235.216 -     *               support the {@code Cloneable} interface. Subclasses
 235.217 -     *               that override the {@code clone} method can also
 235.218 -     *               throw this exception to indicate that an instance cannot
 235.219 -     *               be cloned.
 235.220 -     * @see java.lang.Cloneable
 235.221 -     */
 235.222 -    protected native Object clone() throws CloneNotSupportedException;
 235.223 -
 235.224 -    /**
 235.225 -     * Returns a string representation of the object. In general, the
 235.226 -     * {@code toString} method returns a string that
 235.227 -     * "textually represents" this object. The result should
 235.228 -     * be a concise but informative representation that is easy for a
 235.229 -     * person to read.
 235.230 -     * It is recommended that all subclasses override this method.
 235.231 -     * <p>
 235.232 -     * The {@code toString} method for class {@code Object}
 235.233 -     * returns a string consisting of the name of the class of which the
 235.234 -     * object is an instance, the at-sign character `{@code @}', and
 235.235 -     * the unsigned hexadecimal representation of the hash code of the
 235.236 -     * object. In other words, this method returns a string equal to the
 235.237 -     * value of:
 235.238 -     * <blockquote>
 235.239 -     * <pre>
 235.240 -     * getClass().getName() + '@' + Integer.toHexString(hashCode())
 235.241 -     * </pre></blockquote>
 235.242 -     *
 235.243 -     * @return  a string representation of the object.
 235.244 -     */
 235.245 -    public String toString() {
 235.246 -        return getClass().getName() + "@" + Integer.toHexString(hashCode());
 235.247 -    }
 235.248 -
 235.249 -    /**
 235.250 -     * Wakes up a single thread that is waiting on this object's
 235.251 -     * monitor. If any threads are waiting on this object, one of them
 235.252 -     * is chosen to be awakened. The choice is arbitrary and occurs at
 235.253 -     * the discretion of the implementation. A thread waits on an object's
 235.254 -     * monitor by calling one of the {@code wait} methods.
 235.255 -     * <p>
 235.256 -     * The awakened thread will not be able to proceed until the current
 235.257 -     * thread relinquishes the lock on this object. The awakened thread will
 235.258 -     * compete in the usual manner with any other threads that might be
 235.259 -     * actively competing to synchronize on this object; for example, the
 235.260 -     * awakened thread enjoys no reliable privilege or disadvantage in being
 235.261 -     * the next thread to lock this object.
 235.262 -     * <p>
 235.263 -     * This method should only be called by a thread that is the owner
 235.264 -     * of this object's monitor. A thread becomes the owner of the
 235.265 -     * object's monitor in one of three ways:
 235.266 -     * <ul>
 235.267 -     * <li>By executing a synchronized instance method of that object.
 235.268 -     * <li>By executing the body of a {@code synchronized} statement
 235.269 -     *     that synchronizes on the object.
 235.270 -     * <li>For objects of type {@code Class,} by executing a
 235.271 -     *     synchronized static method of that class.
 235.272 -     * </ul>
 235.273 -     * <p>
 235.274 -     * Only one thread at a time can own an object's monitor.
 235.275 -     *
 235.276 -     * @exception  IllegalMonitorStateException  if the current thread is not
 235.277 -     *               the owner of this object's monitor.
 235.278 -     * @see        java.lang.Object#notifyAll()
 235.279 -     * @see        java.lang.Object#wait()
 235.280 -     */
 235.281 -    public final native void notify();
 235.282 -
 235.283 -    /**
 235.284 -     * Wakes up all threads that are waiting on this object's monitor. A
 235.285 -     * thread waits on an object's monitor by calling one of the
 235.286 -     * {@code wait} methods.
 235.287 -     * <p>
 235.288 -     * The awakened threads will not be able to proceed until the current
 235.289 -     * thread relinquishes the lock on this object. The awakened threads
 235.290 -     * will compete in the usual manner with any other threads that might
 235.291 -     * be actively competing to synchronize on this object; for example,
 235.292 -     * the awakened threads enjoy no reliable privilege or disadvantage in
 235.293 -     * being the next thread to lock this object.
 235.294 -     * <p>
 235.295 -     * This method should only be called by a thread that is the owner
 235.296 -     * of this object's monitor. See the {@code notify} method for a
 235.297 -     * description of the ways in which a thread can become the owner of
 235.298 -     * a monitor.
 235.299 -     *
 235.300 -     * @exception  IllegalMonitorStateException  if the current thread is not
 235.301 -     *               the owner of this object's monitor.
 235.302 -     * @see        java.lang.Object#notify()
 235.303 -     * @see        java.lang.Object#wait()
 235.304 -     */
 235.305 -    public final native void notifyAll();
 235.306 -
 235.307 -    /**
 235.308 -     * Causes the current thread to wait until either another thread invokes the
 235.309 -     * {@link java.lang.Object#notify()} method or the
 235.310 -     * {@link java.lang.Object#notifyAll()} method for this object, or a
 235.311 -     * specified amount of time has elapsed.
 235.312 -     * <p>
 235.313 -     * The current thread must own this object's monitor.
 235.314 -     * <p>
 235.315 -     * This method causes the current thread (call it <var>T</var>) to
 235.316 -     * place itself in the wait set for this object and then to relinquish
 235.317 -     * any and all synchronization claims on this object. Thread <var>T</var>
 235.318 -     * becomes disabled for thread scheduling purposes and lies dormant
 235.319 -     * until one of four things happens:
 235.320 -     * <ul>
 235.321 -     * <li>Some other thread invokes the {@code notify} method for this
 235.322 -     * object and thread <var>T</var> happens to be arbitrarily chosen as
 235.323 -     * the thread to be awakened.
 235.324 -     * <li>Some other thread invokes the {@code notifyAll} method for this
 235.325 -     * object.
 235.326 -     * <li>Some other thread {@linkplain Thread#interrupt() interrupts}
 235.327 -     * thread <var>T</var>.
 235.328 -     * <li>The specified amount of real time has elapsed, more or less.  If
 235.329 -     * {@code timeout} is zero, however, then real time is not taken into
 235.330 -     * consideration and the thread simply waits until notified.
 235.331 -     * </ul>
 235.332 -     * The thread <var>T</var> is then removed from the wait set for this
 235.333 -     * object and re-enabled for thread scheduling. It then competes in the
 235.334 -     * usual manner with other threads for the right to synchronize on the
 235.335 -     * object; once it has gained control of the object, all its
 235.336 -     * synchronization claims on the object are restored to the status quo
 235.337 -     * ante - that is, to the situation as of the time that the {@code wait}
 235.338 -     * method was invoked. Thread <var>T</var> then returns from the
 235.339 -     * invocation of the {@code wait} method. Thus, on return from the
 235.340 -     * {@code wait} method, the synchronization state of the object and of
 235.341 -     * thread {@code T} is exactly as it was when the {@code wait} method
 235.342 -     * was invoked.
 235.343 -     * <p>
 235.344 -     * A thread can also wake up without being notified, interrupted, or
 235.345 -     * timing out, a so-called <i>spurious wakeup</i>.  While this will rarely
 235.346 -     * occur in practice, applications must guard against it by testing for
 235.347 -     * the condition that should have caused the thread to be awakened, and
 235.348 -     * continuing to wait if the condition is not satisfied.  In other words,
 235.349 -     * waits should always occur in loops, like this one:
 235.350 -     * <pre>
 235.351 -     *     synchronized (obj) {
 235.352 -     *         while (&lt;condition does not hold&gt;)
 235.353 -     *             obj.wait(timeout);
 235.354 -     *         ... // Perform action appropriate to condition
 235.355 -     *     }
 235.356 -     * </pre>
 235.357 -     * (For more information on this topic, see Section 3.2.3 in Doug Lea's
 235.358 -     * "Concurrent Programming in Java (Second Edition)" (Addison-Wesley,
 235.359 -     * 2000), or Item 50 in Joshua Bloch's "Effective Java Programming
 235.360 -     * Language Guide" (Addison-Wesley, 2001).
 235.361 -     *
 235.362 -     * <p>If the current thread is {@linkplain java.lang.Thread#interrupt()
 235.363 -     * interrupted} by any thread before or while it is waiting, then an
 235.364 -     * {@code InterruptedException} is thrown.  This exception is not
 235.365 -     * thrown until the lock status of this object has been restored as
 235.366 -     * described above.
 235.367 -     *
 235.368 -     * <p>
 235.369 -     * Note that the {@code wait} method, as it places the current thread
 235.370 -     * into the wait set for this object, unlocks only this object; any
 235.371 -     * other objects on which the current thread may be synchronized remain
 235.372 -     * locked while the thread waits.
 235.373 -     * <p>
 235.374 -     * This method should only be called by a thread that is the owner
 235.375 -     * of this object's monitor. See the {@code notify} method for a
 235.376 -     * description of the ways in which a thread can become the owner of
 235.377 -     * a monitor.
 235.378 -     *
 235.379 -     * @param      timeout   the maximum time to wait in milliseconds.
 235.380 -     * @exception  IllegalArgumentException      if the value of timeout is
 235.381 -     *               negative.
 235.382 -     * @exception  IllegalMonitorStateException  if the current thread is not
 235.383 -     *               the owner of the object's monitor.
 235.384 -     * @exception  InterruptedException if any thread interrupted the
 235.385 -     *             current thread before or while the current thread
 235.386 -     *             was waiting for a notification.  The <i>interrupted
 235.387 -     *             status</i> of the current thread is cleared when
 235.388 -     *             this exception is thrown.
 235.389 -     * @see        java.lang.Object#notify()
 235.390 -     * @see        java.lang.Object#notifyAll()
 235.391 -     */
 235.392 -    public final native void wait(long timeout) throws InterruptedException;
 235.393 -
 235.394 -    /**
 235.395 -     * Causes the current thread to wait until another thread invokes the
 235.396 -     * {@link java.lang.Object#notify()} method or the
 235.397 -     * {@link java.lang.Object#notifyAll()} method for this object, or
 235.398 -     * some other thread interrupts the current thread, or a certain
 235.399 -     * amount of real time has elapsed.
 235.400 -     * <p>
 235.401 -     * This method is similar to the {@code wait} method of one
 235.402 -     * argument, but it allows finer control over the amount of time to
 235.403 -     * wait for a notification before giving up. The amount of real time,
 235.404 -     * measured in nanoseconds, is given by:
 235.405 -     * <blockquote>
 235.406 -     * <pre>
 235.407 -     * 1000000*timeout+nanos</pre></blockquote>
 235.408 -     * <p>
 235.409 -     * In all other respects, this method does the same thing as the
 235.410 -     * method {@link #wait(long)} of one argument. In particular,
 235.411 -     * {@code wait(0, 0)} means the same thing as {@code wait(0)}.
 235.412 -     * <p>
 235.413 -     * The current thread must own this object's monitor. The thread
 235.414 -     * releases ownership of this monitor and waits until either of the
 235.415 -     * following two conditions has occurred:
 235.416 -     * <ul>
 235.417 -     * <li>Another thread notifies threads waiting on this object's monitor
 235.418 -     *     to wake up either through a call to the {@code notify} method
 235.419 -     *     or the {@code notifyAll} method.
 235.420 -     * <li>The timeout period, specified by {@code timeout}
 235.421 -     *     milliseconds plus {@code nanos} nanoseconds arguments, has
 235.422 -     *     elapsed.
 235.423 -     * </ul>
 235.424 -     * <p>
 235.425 -     * The thread then waits until it can re-obtain ownership of the
 235.426 -     * monitor and resumes execution.
 235.427 -     * <p>
 235.428 -     * As in the one argument version, interrupts and spurious wakeups are
 235.429 -     * possible, and this method should always be used in a loop:
 235.430 -     * <pre>
 235.431 -     *     synchronized (obj) {
 235.432 -     *         while (&lt;condition does not hold&gt;)
 235.433 -     *             obj.wait(timeout, nanos);
 235.434 -     *         ... // Perform action appropriate to condition
 235.435 -     *     }
 235.436 -     * </pre>
 235.437 -     * This method should only be called by a thread that is the owner
 235.438 -     * of this object's monitor. See the {@code notify} method for a
 235.439 -     * description of the ways in which a thread can become the owner of
 235.440 -     * a monitor.
 235.441 -     *
 235.442 -     * @param      timeout   the maximum time to wait in milliseconds.
 235.443 -     * @param      nanos      additional time, in nanoseconds range
 235.444 -     *                       0-999999.
 235.445 -     * @exception  IllegalArgumentException      if the value of timeout is
 235.446 -     *                      negative or the value of nanos is
 235.447 -     *                      not in the range 0-999999.
 235.448 -     * @exception  IllegalMonitorStateException  if the current thread is not
 235.449 -     *               the owner of this object's monitor.
 235.450 -     * @exception  InterruptedException if any thread interrupted the
 235.451 -     *             current thread before or while the current thread
 235.452 -     *             was waiting for a notification.  The <i>interrupted
 235.453 -     *             status</i> of the current thread is cleared when
 235.454 -     *             this exception is thrown.
 235.455 -     */
 235.456 -    public final void wait(long timeout, int nanos) throws InterruptedException {
 235.457 -        if (timeout < 0) {
 235.458 -            throw new IllegalArgumentException("timeout value is negative");
 235.459 -        }
 235.460 -
 235.461 -        if (nanos < 0 || nanos > 999999) {
 235.462 -            throw new IllegalArgumentException(
 235.463 -                                "nanosecond timeout value out of range");
 235.464 -        }
 235.465 -
 235.466 -        if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
 235.467 -            timeout++;
 235.468 -        }
 235.469 -
 235.470 -        wait(timeout);
 235.471 -    }
 235.472 -
 235.473 -    /**
 235.474 -     * Causes the current thread to wait until another thread invokes the
 235.475 -     * {@link java.lang.Object#notify()} method or the
 235.476 -     * {@link java.lang.Object#notifyAll()} method for this object.
 235.477 -     * In other words, this method behaves exactly as if it simply
 235.478 -     * performs the call {@code wait(0)}.
 235.479 -     * <p>
 235.480 -     * The current thread must own this object's monitor. The thread
 235.481 -     * releases ownership of this monitor and waits until another thread
 235.482 -     * notifies threads waiting on this object's monitor to wake up
 235.483 -     * either through a call to the {@code notify} method or the
 235.484 -     * {@code notifyAll} method. The thread then waits until it can
 235.485 -     * re-obtain ownership of the monitor and resumes execution.
 235.486 -     * <p>
 235.487 -     * As in the one argument version, interrupts and spurious wakeups are
 235.488 -     * possible, and this method should always be used in a loop:
 235.489 -     * <pre>
 235.490 -     *     synchronized (obj) {
 235.491 -     *         while (&lt;condition does not hold&gt;)
 235.492 -     *             obj.wait();
 235.493 -     *         ... // Perform action appropriate to condition
 235.494 -     *     }
 235.495 -     * </pre>
 235.496 -     * This method should only be called by a thread that is the owner
 235.497 -     * of this object's monitor. See the {@code notify} method for a
 235.498 -     * description of the ways in which a thread can become the owner of
 235.499 -     * a monitor.
 235.500 -     *
 235.501 -     * @exception  IllegalMonitorStateException  if the current thread is not
 235.502 -     *               the owner of the object's monitor.
 235.503 -     * @exception  InterruptedException if any thread interrupted the
 235.504 -     *             current thread before or while the current thread
 235.505 -     *             was waiting for a notification.  The <i>interrupted
 235.506 -     *             status</i> of the current thread is cleared when
 235.507 -     *             this exception is thrown.
 235.508 -     * @see        java.lang.Object#notify()
 235.509 -     * @see        java.lang.Object#notifyAll()
 235.510 -     */
 235.511 -    public final void wait() throws InterruptedException {
 235.512 -        wait(0);
 235.513 -    }
 235.514 -
 235.515 -    /**
 235.516 -     * Called by the garbage collector on an object when garbage collection
 235.517 -     * determines that there are no more references to the object.
 235.518 -     * A subclass overrides the {@code finalize} method to dispose of
 235.519 -     * system resources or to perform other cleanup.
 235.520 -     * <p>
 235.521 -     * The general contract of {@code finalize} is that it is invoked
 235.522 -     * if and when the Java<font size="-2"><sup>TM</sup></font> virtual
 235.523 -     * machine has determined that there is no longer any
 235.524 -     * means by which this object can be accessed by any thread that has
 235.525 -     * not yet died, except as a result of an action taken by the
 235.526 -     * finalization of some other object or class which is ready to be
 235.527 -     * finalized. The {@code finalize} method may take any action, including
 235.528 -     * making this object available again to other threads; the usual purpose
 235.529 -     * of {@code finalize}, however, is to perform cleanup actions before
 235.530 -     * the object is irrevocably discarded. For example, the finalize method
 235.531 -     * for an object that represents an input/output connection might perform
 235.532 -     * explicit I/O transactions to break the connection before the object is
 235.533 -     * permanently discarded.
 235.534 -     * <p>
 235.535 -     * The {@code finalize} method of class {@code Object} performs no
 235.536 -     * special action; it simply returns normally. Subclasses of
 235.537 -     * {@code Object} may override this definition.
 235.538 -     * <p>
 235.539 -     * The Java programming language does not guarantee which thread will
 235.540 -     * invoke the {@code finalize} method for any given object. It is
 235.541 -     * guaranteed, however, that the thread that invokes finalize will not
 235.542 -     * be holding any user-visible synchronization locks when finalize is
 235.543 -     * invoked. If an uncaught exception is thrown by the finalize method,
 235.544 -     * the exception is ignored and finalization of that object terminates.
 235.545 -     * <p>
 235.546 -     * After the {@code finalize} method has been invoked for an object, no
 235.547 -     * further action is taken until the Java virtual machine has again
 235.548 -     * determined that there is no longer any means by which this object can
 235.549 -     * be accessed by any thread that has not yet died, including possible
 235.550 -     * actions by other objects or classes which are ready to be finalized,
 235.551 -     * at which point the object may be discarded.
 235.552 -     * <p>
 235.553 -     * The {@code finalize} method is never invoked more than once by a Java
 235.554 -     * virtual machine for any given object.
 235.555 -     * <p>
 235.556 -     * Any exception thrown by the {@code finalize} method causes
 235.557 -     * the finalization of this object to be halted, but is otherwise
 235.558 -     * ignored.
 235.559 -     *
 235.560 -     * @throws Throwable the {@code Exception} raised by this method
 235.561 -     */
 235.562 -    protected void finalize() throws Throwable { }
 235.563 -}
   236.1 --- a/emul/src/main/java/java/lang/OutOfMemoryError.java	Wed Dec 05 10:03:58 2012 +0100
   236.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   236.3 @@ -1,60 +0,0 @@
   236.4 -/*
   236.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   236.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   236.7 - *
   236.8 - * This code is free software; you can redistribute it and/or modify it
   236.9 - * under the terms of the GNU General Public License version 2 only, as
  236.10 - * published by the Free Software Foundation.  Oracle designates this
  236.11 - * particular file as subject to the "Classpath" exception as provided
  236.12 - * by Oracle in the LICENSE file that accompanied this code.
  236.13 - *
  236.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  236.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  236.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  236.17 - * version 2 for more details (a copy is included in the LICENSE file that
  236.18 - * accompanied this code).
  236.19 - *
  236.20 - * You should have received a copy of the GNU General Public License version
  236.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  236.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  236.23 - *
  236.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  236.25 - * or visit www.oracle.com if you need additional information or have any
  236.26 - * questions.
  236.27 - */
  236.28 -
  236.29 -package java.lang;
  236.30 -
  236.31 -/**
  236.32 - * Thrown when the Java Virtual Machine cannot allocate an object
  236.33 - * because it is out of memory, and no more memory could be made
  236.34 - * available by the garbage collector.
  236.35 - *
  236.36 - * {@code OutOfMemoryError} objects may be constructed by the virtual
  236.37 - * machine as if {@linkplain Throwable#Throwable(String, Throwable,
  236.38 - * boolean, boolean) suppression were disabled and/or the stack trace was not
  236.39 - * writable}.
  236.40 - *
  236.41 - * @author  unascribed
  236.42 - * @since   JDK1.0
  236.43 - */
  236.44 -public class OutOfMemoryError extends VirtualMachineError {
  236.45 -    private static final long serialVersionUID = 8228564086184010517L;
  236.46 -
  236.47 -    /**
  236.48 -     * Constructs an {@code OutOfMemoryError} with no detail message.
  236.49 -     */
  236.50 -    public OutOfMemoryError() {
  236.51 -        super();
  236.52 -    }
  236.53 -
  236.54 -    /**
  236.55 -     * Constructs an {@code OutOfMemoryError} with the specified
  236.56 -     * detail message.
  236.57 -     *
  236.58 -     * @param   s   the detail message.
  236.59 -     */
  236.60 -    public OutOfMemoryError(String s) {
  236.61 -        super(s);
  236.62 -    }
  236.63 -}
   237.1 --- a/emul/src/main/java/java/lang/ReflectiveOperationException.java	Wed Dec 05 10:03:58 2012 +0100
   237.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   237.3 @@ -1,91 +0,0 @@
   237.4 -/*
   237.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
   237.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   237.7 - *
   237.8 - * This code is free software; you can redistribute it and/or modify it
   237.9 - * under the terms of the GNU General Public License version 2 only, as
  237.10 - * published by the Free Software Foundation.  Oracle designates this
  237.11 - * particular file as subject to the "Classpath" exception as provided
  237.12 - * by Oracle in the LICENSE file that accompanied this code.
  237.13 - *
  237.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  237.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  237.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  237.17 - * version 2 for more details (a copy is included in the LICENSE file that
  237.18 - * accompanied this code).
  237.19 - *
  237.20 - * You should have received a copy of the GNU General Public License version
  237.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  237.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  237.23 - *
  237.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  237.25 - * or visit www.oracle.com if you need additional information or have any
  237.26 - * questions.
  237.27 - */
  237.28 -
  237.29 -package java.lang;
  237.30 -
  237.31 -/**
  237.32 - * Common superclass of exceptions thrown by reflective operations in
  237.33 - * core reflection.
  237.34 - *
  237.35 - * @see LinkageError
  237.36 - * @since 1.7
  237.37 - */
  237.38 -public class ReflectiveOperationException extends Exception {
  237.39 -    static final long serialVersionUID = 123456789L;
  237.40 -
  237.41 -    /**
  237.42 -     * Constructs a new exception with {@code null} as its detail
  237.43 -     * message.  The cause is not initialized, and may subsequently be
  237.44 -     * initialized by a call to {@link #initCause}.
  237.45 -     */
  237.46 -    public ReflectiveOperationException() {
  237.47 -        super();
  237.48 -    }
  237.49 -
  237.50 -    /**
  237.51 -     * Constructs a new exception with the specified detail message.
  237.52 -     * The cause is not initialized, and may subsequently be
  237.53 -     * initialized by a call to {@link #initCause}.
  237.54 -     *
  237.55 -     * @param   message   the detail message. The detail message is saved for
  237.56 -     *          later retrieval by the {@link #getMessage()} method.
  237.57 -     */
  237.58 -    public ReflectiveOperationException(String message) {
  237.59 -        super(message);
  237.60 -    }
  237.61 -
  237.62 -    /**
  237.63 -     * Constructs a new exception with the specified detail message
  237.64 -     * and cause.
  237.65 -     *
  237.66 -     * <p>Note that the detail message associated with
  237.67 -     * {@code cause} is <em>not</em> automatically incorporated in
  237.68 -     * this exception's detail message.
  237.69 -     *
  237.70 -     * @param  message the detail message (which is saved for later retrieval
  237.71 -     *         by the {@link #getMessage()} method).
  237.72 -     * @param  cause the cause (which is saved for later retrieval by the
  237.73 -     *         {@link #getCause()} method).  (A {@code null} value is
  237.74 -     *         permitted, and indicates that the cause is nonexistent or
  237.75 -     *         unknown.)
  237.76 -     */
  237.77 -    public ReflectiveOperationException(String message, Throwable cause) {
  237.78 -        super(message, cause);
  237.79 -    }
  237.80 -
  237.81 -    /**
  237.82 -     * Constructs a new exception with the specified cause and a detail
  237.83 -     * message of {@code (cause==null ? null : cause.toString())} (which
  237.84 -     * typically contains the class and detail message of {@code cause}).
  237.85 -     *
  237.86 -     * @param  cause the cause (which is saved for later retrieval by the
  237.87 -     *         {@link #getCause()} method).  (A {@code null} value is
  237.88 -     *         permitted, and indicates that the cause is nonexistent or
  237.89 -     *         unknown.)
  237.90 -     */
  237.91 -    public ReflectiveOperationException(Throwable cause) {
  237.92 -        super(cause);
  237.93 -    }
  237.94 -}
   238.1 --- a/emul/src/main/java/java/lang/RuntimeException.java	Wed Dec 05 10:03:58 2012 +0100
   238.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   238.3 @@ -1,119 +0,0 @@
   238.4 -/*
   238.5 - * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
   238.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   238.7 - *
   238.8 - * This code is free software; you can redistribute it and/or modify it
   238.9 - * under the terms of the GNU General Public License version 2 only, as
  238.10 - * published by the Free Software Foundation.  Oracle designates this
  238.11 - * particular file as subject to the "Classpath" exception as provided
  238.12 - * by Oracle in the LICENSE file that accompanied this code.
  238.13 - *
  238.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  238.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  238.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  238.17 - * version 2 for more details (a copy is included in the LICENSE file that
  238.18 - * accompanied this code).
  238.19 - *
  238.20 - * You should have received a copy of the GNU General Public License version
  238.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  238.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  238.23 - *
  238.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  238.25 - * or visit www.oracle.com if you need additional information or have any
  238.26 - * questions.
  238.27 - */
  238.28 -
  238.29 -package java.lang;
  238.30 -
  238.31 -/**
  238.32 - * {@code RuntimeException} is the superclass of those
  238.33 - * exceptions that can be thrown during the normal operation of the
  238.34 - * Java Virtual Machine.
  238.35 - *
  238.36 - * <p>{@code RuntimeException} and its subclasses are <em>unchecked
  238.37 - * exceptions</em>.  Unchecked exceptions do <em>not</em> need to be
  238.38 - * declared in a method or constructor's {@code throws} clause if they
  238.39 - * can be thrown by the execution of the method or constructor and
  238.40 - * propagate outside the method or constructor boundary.
  238.41 - *
  238.42 - * @author  Frank Yellin
  238.43 - * @jls 11.2 Compile-Time Checking of Exceptions
  238.44 - * @since   JDK1.0
  238.45 - */
  238.46 -public class RuntimeException extends Exception {
  238.47 -    static final long serialVersionUID = -7034897190745766939L;
  238.48 -
  238.49 -    /** Constructs a new runtime exception with {@code null} as its
  238.50 -     * detail message.  The cause is not initialized, and may subsequently be
  238.51 -     * initialized by a call to {@link #initCause}.
  238.52 -     */
  238.53 -    public RuntimeException() {
  238.54 -        super();
  238.55 -    }
  238.56 -
  238.57 -    /** Constructs a new runtime exception with the specified detail message.
  238.58 -     * The cause is not initialized, and may subsequently be initialized by a
  238.59 -     * call to {@link #initCause}.
  238.60 -     *
  238.61 -     * @param   message   the detail message. The detail message is saved for
  238.62 -     *          later retrieval by the {@link #getMessage()} method.
  238.63 -     */
  238.64 -    public RuntimeException(String message) {
  238.65 -        super(message);
  238.66 -    }
  238.67 -
  238.68 -    /**
  238.69 -     * Constructs a new runtime exception with the specified detail message and
  238.70 -     * cause.  <p>Note that the detail message associated with
  238.71 -     * {@code cause} is <i>not</i> automatically incorporated in
  238.72 -     * this runtime exception's detail message.
  238.73 -     *
  238.74 -     * @param  message the detail message (which is saved for later retrieval
  238.75 -     *         by the {@link #getMessage()} method).
  238.76 -     * @param  cause the cause (which is saved for later retrieval by the
  238.77 -     *         {@link #getCause()} method).  (A <tt>null</tt> value is
  238.78 -     *         permitted, and indicates that the cause is nonexistent or
  238.79 -     *         unknown.)
  238.80 -     * @since  1.4
  238.81 -     */
  238.82 -    public RuntimeException(String message, Throwable cause) {
  238.83 -        super(message, cause);
  238.84 -    }
  238.85 -
  238.86 -    /** Constructs a new runtime exception with the specified cause and a
  238.87 -     * detail message of <tt>(cause==null ? null : cause.toString())</tt>
  238.88 -     * (which typically contains the class and detail message of
  238.89 -     * <tt>cause</tt>).  This constructor is useful for runtime exceptions
  238.90 -     * that are little more than wrappers for other throwables.
  238.91 -     *
  238.92 -     * @param  cause the cause (which is saved for later retrieval by the
  238.93 -     *         {@link #getCause()} method).  (A <tt>null</tt> value is
  238.94 -     *         permitted, and indicates that the cause is nonexistent or
  238.95 -     *         unknown.)
  238.96 -     * @since  1.4
  238.97 -     */
  238.98 -    public RuntimeException(Throwable cause) {
  238.99 -        super(cause);
 238.100 -    }
 238.101 -
 238.102 -    /**
 238.103 -     * Constructs a new runtime exception with the specified detail
 238.104 -     * message, cause, suppression enabled or disabled, and writable
 238.105 -     * stack trace enabled or disabled.
 238.106 -     *
 238.107 -     * @param  message the detail message.
 238.108 -     * @param cause the cause.  (A {@code null} value is permitted,
 238.109 -     * and indicates that the cause is nonexistent or unknown.)
 238.110 -     * @param enableSuppression whether or not suppression is enabled
 238.111 -     *                          or disabled
 238.112 -     * @param writableStackTrace whether or not the stack trace should
 238.113 -     *                           be writable
 238.114 -     *
 238.115 -     * @since 1.7
 238.116 -     */
 238.117 -    protected RuntimeException(String message, Throwable cause,
 238.118 -                               boolean enableSuppression,
 238.119 -                               boolean writableStackTrace) {
 238.120 -        super(message, cause, enableSuppression, writableStackTrace);
 238.121 -    }
 238.122 -}
   239.1 --- a/emul/src/main/java/java/lang/SecurityException.java	Wed Dec 05 10:03:58 2012 +0100
   239.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   239.3 @@ -1,84 +0,0 @@
   239.4 -/*
   239.5 - * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
   239.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   239.7 - *
   239.8 - * This code is free software; you can redistribute it and/or modify it
   239.9 - * under the terms of the GNU General Public License version 2 only, as
  239.10 - * published by the Free Software Foundation.  Oracle designates this
  239.11 - * particular file as subject to the "Classpath" exception as provided
  239.12 - * by Oracle in the LICENSE file that accompanied this code.
  239.13 - *
  239.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  239.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  239.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  239.17 - * version 2 for more details (a copy is included in the LICENSE file that
  239.18 - * accompanied this code).
  239.19 - *
  239.20 - * You should have received a copy of the GNU General Public License version
  239.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  239.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  239.23 - *
  239.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  239.25 - * or visit www.oracle.com if you need additional information or have any
  239.26 - * questions.
  239.27 - */
  239.28 -package java.lang;
  239.29 -
  239.30 -/**
  239.31 - * Thrown by the security manager to indicate a security violation.
  239.32 - *
  239.33 - * @author  unascribed
  239.34 - * @see     java.lang.SecurityManager
  239.35 - * @since   JDK1.0
  239.36 - */
  239.37 -public class SecurityException extends RuntimeException {
  239.38 -
  239.39 -    private static final long serialVersionUID = 6878364983674394167L;
  239.40 -
  239.41 -    /**
  239.42 -     * Constructs a <code>SecurityException</code> with no detail  message.
  239.43 -     */
  239.44 -    public SecurityException() {
  239.45 -        super();
  239.46 -    }
  239.47 -
  239.48 -    /**
  239.49 -     * Constructs a <code>SecurityException</code> with the specified
  239.50 -     * detail message.
  239.51 -     *
  239.52 -     * @param   s   the detail message.
  239.53 -     */
  239.54 -    public SecurityException(String s) {
  239.55 -        super(s);
  239.56 -    }
  239.57 -
  239.58 -    /**
  239.59 -     * Creates a <code>SecurityException</code> with the specified
  239.60 -     * detail message and cause.
  239.61 -     *
  239.62 -     * @param message the detail message (which is saved for later retrieval
  239.63 -     *        by the {@link #getMessage()} method).
  239.64 -     * @param cause the cause (which is saved for later retrieval by the
  239.65 -     *        {@link #getCause()} method).  (A <tt>null</tt> value is permitted,
  239.66 -     *        and indicates that the cause is nonexistent or unknown.)
  239.67 -     * @since 1.5
  239.68 -     */
  239.69 -    public SecurityException(String message, Throwable cause) {
  239.70 -        super(message, cause);
  239.71 -    }
  239.72 -
  239.73 -    /**
  239.74 -     * Creates a <code>SecurityException</code> with the specified cause
  239.75 -     * and a detail message of <tt>(cause==null ? null : cause.toString())</tt>
  239.76 -     * (which typically contains the class and detail message of
  239.77 -     * <tt>cause</tt>).
  239.78 -     *
  239.79 -     * @param cause the cause (which is saved for later retrieval by the
  239.80 -     *        {@link #getCause()} method).  (A <tt>null</tt> value is permitted,
  239.81 -     *        and indicates that the cause is nonexistent or unknown.)
  239.82 -     * @since 1.5
  239.83 -     */
  239.84 -    public SecurityException(Throwable cause) {
  239.85 -        super(cause);
  239.86 -    }
  239.87 -}
   240.1 --- a/emul/src/main/java/java/lang/Short.java	Wed Dec 05 10:03:58 2012 +0100
   240.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   240.3 @@ -1,468 +0,0 @@
   240.4 -/*
   240.5 - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
   240.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   240.7 - *
   240.8 - * This code is free software; you can redistribute it and/or modify it
   240.9 - * under the terms of the GNU General Public License version 2 only, as
  240.10 - * published by the Free Software Foundation.  Oracle designates this
  240.11 - * particular file as subject to the "Classpath" exception as provided
  240.12 - * by Oracle in the LICENSE file that accompanied this code.
  240.13 - *
  240.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  240.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  240.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  240.17 - * version 2 for more details (a copy is included in the LICENSE file that
  240.18 - * accompanied this code).
  240.19 - *
  240.20 - * You should have received a copy of the GNU General Public License version
  240.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  240.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  240.23 - *
  240.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  240.25 - * or visit www.oracle.com if you need additional information or have any
  240.26 - * questions.
  240.27 - */
  240.28 -
  240.29 -package java.lang;
  240.30 -
  240.31 -/**
  240.32 - * The {@code Short} class wraps a value of primitive type {@code
  240.33 - * short} in an object.  An object of type {@code Short} contains a
  240.34 - * single field whose type is {@code short}.
  240.35 - *
  240.36 - * <p>In addition, this class provides several methods for converting
  240.37 - * a {@code short} to a {@code String} and a {@code String} to a
  240.38 - * {@code short}, as well as other constants and methods useful when
  240.39 - * dealing with a {@code short}.
  240.40 - *
  240.41 - * @author  Nakul Saraiya
  240.42 - * @author  Joseph D. Darcy
  240.43 - * @see     java.lang.Number
  240.44 - * @since   JDK1.1
  240.45 - */
  240.46 -public final class Short extends Number implements Comparable<Short> {
  240.47 -
  240.48 -    /**
  240.49 -     * A constant holding the minimum value a {@code short} can
  240.50 -     * have, -2<sup>15</sup>.
  240.51 -     */
  240.52 -    public static final short   MIN_VALUE = -32768;
  240.53 -
  240.54 -    /**
  240.55 -     * A constant holding the maximum value a {@code short} can
  240.56 -     * have, 2<sup>15</sup>-1.
  240.57 -     */
  240.58 -    public static final short   MAX_VALUE = 32767;
  240.59 -
  240.60 -    /**
  240.61 -     * The {@code Class} instance representing the primitive type
  240.62 -     * {@code short}.
  240.63 -     */
  240.64 -    public static final Class<Short>    TYPE = (Class<Short>) Class.getPrimitiveClass("short");
  240.65 -
  240.66 -    /**
  240.67 -     * Returns a new {@code String} object representing the
  240.68 -     * specified {@code short}. The radix is assumed to be 10.
  240.69 -     *
  240.70 -     * @param s the {@code short} to be converted
  240.71 -     * @return the string representation of the specified {@code short}
  240.72 -     * @see java.lang.Integer#toString(int)
  240.73 -     */
  240.74 -    public static String toString(short s) {
  240.75 -        return Integer.toString((int)s, 10);
  240.76 -    }
  240.77 -
  240.78 -    /**
  240.79 -     * Parses the string argument as a signed {@code short} in the
  240.80 -     * radix specified by the second argument. The characters in the
  240.81 -     * string must all be digits, of the specified radix (as
  240.82 -     * determined by whether {@link java.lang.Character#digit(char,
  240.83 -     * int)} returns a nonnegative value) except that the first
  240.84 -     * character may be an ASCII minus sign {@code '-'}
  240.85 -     * (<code>'&#92;u002D'</code>) to indicate a negative value or an
  240.86 -     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
  240.87 -     * indicate a positive value.  The resulting {@code short} value
  240.88 -     * is returned.
  240.89 -     *
  240.90 -     * <p>An exception of type {@code NumberFormatException} is
  240.91 -     * thrown if any of the following situations occurs:
  240.92 -     * <ul>
  240.93 -     * <li> The first argument is {@code null} or is a string of
  240.94 -     * length zero.
  240.95 -     *
  240.96 -     * <li> The radix is either smaller than {@link
  240.97 -     * java.lang.Character#MIN_RADIX} or larger than {@link
  240.98 -     * java.lang.Character#MAX_RADIX}.
  240.99 -     *
 240.100 -     * <li> Any character of the string is not a digit of the
 240.101 -     * specified radix, except that the first character may be a minus
 240.102 -     * sign {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
 240.103 -     * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
 240.104 -     * string is longer than length 1.
 240.105 -     *
 240.106 -     * <li> The value represented by the string is not a value of type
 240.107 -     * {@code short}.
 240.108 -     * </ul>
 240.109 -     *
 240.110 -     * @param s         the {@code String} containing the
 240.111 -     *                  {@code short} representation to be parsed
 240.112 -     * @param radix     the radix to be used while parsing {@code s}
 240.113 -     * @return          the {@code short} represented by the string
 240.114 -     *                  argument in the specified radix.
 240.115 -     * @throws          NumberFormatException If the {@code String}
 240.116 -     *                  does not contain a parsable {@code short}.
 240.117 -     */
 240.118 -    public static short parseShort(String s, int radix)
 240.119 -        throws NumberFormatException {
 240.120 -        int i = Integer.parseInt(s, radix);
 240.121 -        if (i < MIN_VALUE || i > MAX_VALUE)
 240.122 -            throw new NumberFormatException(
 240.123 -                "Value out of range. Value:\"" + s + "\" Radix:" + radix);
 240.124 -        return (short)i;
 240.125 -    }
 240.126 -
 240.127 -    /**
 240.128 -     * Parses the string argument as a signed decimal {@code
 240.129 -     * short}. The characters in the string must all be decimal
 240.130 -     * digits, except that the first character may be an ASCII minus
 240.131 -     * sign {@code '-'} (<code>'&#92;u002D'</code>) to indicate a
 240.132 -     * negative value or an ASCII plus sign {@code '+'}
 240.133 -     * (<code>'&#92;u002B'</code>) to indicate a positive value.  The
 240.134 -     * resulting {@code short} value is returned, exactly as if the
 240.135 -     * argument and the radix 10 were given as arguments to the {@link
 240.136 -     * #parseShort(java.lang.String, int)} method.
 240.137 -     *
 240.138 -     * @param s a {@code String} containing the {@code short}
 240.139 -     *          representation to be parsed
 240.140 -     * @return  the {@code short} value represented by the
 240.141 -     *          argument in decimal.
 240.142 -     * @throws  NumberFormatException If the string does not
 240.143 -     *          contain a parsable {@code short}.
 240.144 -     */
 240.145 -    public static short parseShort(String s) throws NumberFormatException {
 240.146 -        return parseShort(s, 10);
 240.147 -    }
 240.148 -
 240.149 -    /**
 240.150 -     * Returns a {@code Short} object holding the value
 240.151 -     * extracted from the specified {@code String} when parsed
 240.152 -     * with the radix given by the second argument. The first argument
 240.153 -     * is interpreted as representing a signed {@code short} in
 240.154 -     * the radix specified by the second argument, exactly as if the
 240.155 -     * argument were given to the {@link #parseShort(java.lang.String,
 240.156 -     * int)} method. The result is a {@code Short} object that
 240.157 -     * represents the {@code short} value specified by the string.
 240.158 -     *
 240.159 -     * <p>In other words, this method returns a {@code Short} object
 240.160 -     * equal to the value of:
 240.161 -     *
 240.162 -     * <blockquote>
 240.163 -     *  {@code new Short(Short.parseShort(s, radix))}
 240.164 -     * </blockquote>
 240.165 -     *
 240.166 -     * @param s         the string to be parsed
 240.167 -     * @param radix     the radix to be used in interpreting {@code s}
 240.168 -     * @return          a {@code Short} object holding the value
 240.169 -     *                  represented by the string argument in the
 240.170 -     *                  specified radix.
 240.171 -     * @throws          NumberFormatException If the {@code String} does
 240.172 -     *                  not contain a parsable {@code short}.
 240.173 -     */
 240.174 -    public static Short valueOf(String s, int radix)
 240.175 -        throws NumberFormatException {
 240.176 -        return valueOf(parseShort(s, radix));
 240.177 -    }
 240.178 -
 240.179 -    /**
 240.180 -     * Returns a {@code Short} object holding the
 240.181 -     * value given by the specified {@code String}. The argument
 240.182 -     * is interpreted as representing a signed decimal
 240.183 -     * {@code short}, exactly as if the argument were given to
 240.184 -     * the {@link #parseShort(java.lang.String)} method. The result is
 240.185 -     * a {@code Short} object that represents the
 240.186 -     * {@code short} value specified by the string.
 240.187 -     *
 240.188 -     * <p>In other words, this method returns a {@code Short} object
 240.189 -     * equal to the value of:
 240.190 -     *
 240.191 -     * <blockquote>
 240.192 -     *  {@code new Short(Short.parseShort(s))}
 240.193 -     * </blockquote>
 240.194 -     *
 240.195 -     * @param s the string to be parsed
 240.196 -     * @return  a {@code Short} object holding the value
 240.197 -     *          represented by the string argument
 240.198 -     * @throws  NumberFormatException If the {@code String} does
 240.199 -     *          not contain a parsable {@code short}.
 240.200 -     */
 240.201 -    public static Short valueOf(String s) throws NumberFormatException {
 240.202 -        return valueOf(s, 10);
 240.203 -    }
 240.204 -
 240.205 -    private static class ShortCache {
 240.206 -        private ShortCache(){}
 240.207 -
 240.208 -        static final Short cache[] = new Short[-(-128) + 127 + 1];
 240.209 -
 240.210 -        static {
 240.211 -            for(int i = 0; i < cache.length; i++)
 240.212 -                cache[i] = new Short((short)(i - 128));
 240.213 -        }
 240.214 -    }
 240.215 -
 240.216 -    /**
 240.217 -     * Returns a {@code Short} instance representing the specified
 240.218 -     * {@code short} value.
 240.219 -     * If a new {@code Short} instance is not required, this method
 240.220 -     * should generally be used in preference to the constructor
 240.221 -     * {@link #Short(short)}, as this method is likely to yield
 240.222 -     * significantly better space and time performance by caching
 240.223 -     * frequently requested values.
 240.224 -     *
 240.225 -     * This method will always cache values in the range -128 to 127,
 240.226 -     * inclusive, and may cache other values outside of this range.
 240.227 -     *
 240.228 -     * @param  s a short value.
 240.229 -     * @return a {@code Short} instance representing {@code s}.
 240.230 -     * @since  1.5
 240.231 -     */
 240.232 -    public static Short valueOf(short s) {
 240.233 -        final int offset = 128;
 240.234 -        int sAsInt = s;
 240.235 -        if (sAsInt >= -128 && sAsInt <= 127) { // must cache
 240.236 -            return ShortCache.cache[sAsInt + offset];
 240.237 -        }
 240.238 -        return new Short(s);
 240.239 -    }
 240.240 -
 240.241 -    /**
 240.242 -     * Decodes a {@code String} into a {@code Short}.
 240.243 -     * Accepts decimal, hexadecimal, and octal numbers given by
 240.244 -     * the following grammar:
 240.245 -     *
 240.246 -     * <blockquote>
 240.247 -     * <dl>
 240.248 -     * <dt><i>DecodableString:</i>
 240.249 -     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 240.250 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 240.251 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 240.252 -     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 240.253 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 240.254 -     * <p>
 240.255 -     * <dt><i>Sign:</i>
 240.256 -     * <dd>{@code -}
 240.257 -     * <dd>{@code +}
 240.258 -     * </dl>
 240.259 -     * </blockquote>
 240.260 -     *
 240.261 -     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 240.262 -     * are as defined in section 3.10.1 of
 240.263 -     * <cite>The Java&trade; Language Specification</cite>,
 240.264 -     * except that underscores are not accepted between digits.
 240.265 -     *
 240.266 -     * <p>The sequence of characters following an optional
 240.267 -     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 240.268 -     * "{@code #}", or leading zero) is parsed as by the {@code
 240.269 -     * Short.parseShort} method with the indicated radix (10, 16, or
 240.270 -     * 8).  This sequence of characters must represent a positive
 240.271 -     * value or a {@link NumberFormatException} will be thrown.  The
 240.272 -     * result is negated if first character of the specified {@code
 240.273 -     * String} is the minus sign.  No whitespace characters are
 240.274 -     * permitted in the {@code String}.
 240.275 -     *
 240.276 -     * @param     nm the {@code String} to decode.
 240.277 -     * @return    a {@code Short} object holding the {@code short}
 240.278 -     *            value represented by {@code nm}
 240.279 -     * @throws    NumberFormatException  if the {@code String} does not
 240.280 -     *            contain a parsable {@code short}.
 240.281 -     * @see java.lang.Short#parseShort(java.lang.String, int)
 240.282 -     */
 240.283 -    public static Short decode(String nm) throws NumberFormatException {
 240.284 -        int i = Integer.decode(nm);
 240.285 -        if (i < MIN_VALUE || i > MAX_VALUE)
 240.286 -            throw new NumberFormatException(
 240.287 -                    "Value " + i + " out of range from input " + nm);
 240.288 -        return valueOf((short)i);
 240.289 -    }
 240.290 -
 240.291 -    /**
 240.292 -     * The value of the {@code Short}.
 240.293 -     *
 240.294 -     * @serial
 240.295 -     */
 240.296 -    private final short value;
 240.297 -
 240.298 -    /**
 240.299 -     * Constructs a newly allocated {@code Short} object that
 240.300 -     * represents the specified {@code short} value.
 240.301 -     *
 240.302 -     * @param value     the value to be represented by the
 240.303 -     *                  {@code Short}.
 240.304 -     */
 240.305 -    public Short(short value) {
 240.306 -        this.value = value;
 240.307 -    }
 240.308 -
 240.309 -    /**
 240.310 -     * Constructs a newly allocated {@code Short} object that
 240.311 -     * represents the {@code short} value indicated by the
 240.312 -     * {@code String} parameter. The string is converted to a
 240.313 -     * {@code short} value in exactly the manner used by the
 240.314 -     * {@code parseShort} method for radix 10.
 240.315 -     *
 240.316 -     * @param s the {@code String} to be converted to a
 240.317 -     *          {@code Short}
 240.318 -     * @throws  NumberFormatException If the {@code String}
 240.319 -     *          does not contain a parsable {@code short}.
 240.320 -     * @see     java.lang.Short#parseShort(java.lang.String, int)
 240.321 -     */
 240.322 -    public Short(String s) throws NumberFormatException {
 240.323 -        this.value = parseShort(s, 10);
 240.324 -    }
 240.325 -
 240.326 -    /**
 240.327 -     * Returns the value of this {@code Short} as a
 240.328 -     * {@code byte}.
 240.329 -     */
 240.330 -    public byte byteValue() {
 240.331 -        return (byte)value;
 240.332 -    }
 240.333 -
 240.334 -    /**
 240.335 -     * Returns the value of this {@code Short} as a
 240.336 -     * {@code short}.
 240.337 -     */
 240.338 -    public short shortValue() {
 240.339 -        return value;
 240.340 -    }
 240.341 -
 240.342 -    /**
 240.343 -     * Returns the value of this {@code Short} as an
 240.344 -     * {@code int}.
 240.345 -     */
 240.346 -    public int intValue() {
 240.347 -        return (int)value;
 240.348 -    }
 240.349 -
 240.350 -    /**
 240.351 -     * Returns the value of this {@code Short} as a
 240.352 -     * {@code long}.
 240.353 -     */
 240.354 -    public long longValue() {
 240.355 -        return (long)value;
 240.356 -    }
 240.357 -
 240.358 -    /**
 240.359 -     * Returns the value of this {@code Short} as a
 240.360 -     * {@code float}.
 240.361 -     */
 240.362 -    public float floatValue() {
 240.363 -        return (float)value;
 240.364 -    }
 240.365 -
 240.366 -    /**
 240.367 -     * Returns the value of this {@code Short} as a
 240.368 -     * {@code double}.
 240.369 -     */
 240.370 -    public double doubleValue() {
 240.371 -        return (double)value;
 240.372 -    }
 240.373 -
 240.374 -    /**
 240.375 -     * Returns a {@code String} object representing this
 240.376 -     * {@code Short}'s value.  The value is converted to signed
 240.377 -     * decimal representation and returned as a string, exactly as if
 240.378 -     * the {@code short} value were given as an argument to the
 240.379 -     * {@link java.lang.Short#toString(short)} method.
 240.380 -     *
 240.381 -     * @return  a string representation of the value of this object in
 240.382 -     *          base&nbsp;10.
 240.383 -     */
 240.384 -    public String toString() {
 240.385 -        return Integer.toString((int)value);
 240.386 -    }
 240.387 -
 240.388 -    /**
 240.389 -     * Returns a hash code for this {@code Short}; equal to the result
 240.390 -     * of invoking {@code intValue()}.
 240.391 -     *
 240.392 -     * @return a hash code value for this {@code Short}
 240.393 -     */
 240.394 -    public int hashCode() {
 240.395 -        return (int)value;
 240.396 -    }
 240.397 -
 240.398 -    /**
 240.399 -     * Compares this object to the specified object.  The result is
 240.400 -     * {@code true} if and only if the argument is not
 240.401 -     * {@code null} and is a {@code Short} object that
 240.402 -     * contains the same {@code short} value as this object.
 240.403 -     *
 240.404 -     * @param obj       the object to compare with
 240.405 -     * @return          {@code true} if the objects are the same;
 240.406 -     *                  {@code false} otherwise.
 240.407 -     */
 240.408 -    public boolean equals(Object obj) {
 240.409 -        if (obj instanceof Short) {
 240.410 -            return value == ((Short)obj).shortValue();
 240.411 -        }
 240.412 -        return false;
 240.413 -    }
 240.414 -
 240.415 -    /**
 240.416 -     * Compares two {@code Short} objects numerically.
 240.417 -     *
 240.418 -     * @param   anotherShort   the {@code Short} to be compared.
 240.419 -     * @return  the value {@code 0} if this {@code Short} is
 240.420 -     *          equal to the argument {@code Short}; a value less than
 240.421 -     *          {@code 0} if this {@code Short} is numerically less
 240.422 -     *          than the argument {@code Short}; and a value greater than
 240.423 -     *           {@code 0} if this {@code Short} is numerically
 240.424 -     *           greater than the argument {@code Short} (signed
 240.425 -     *           comparison).
 240.426 -     * @since   1.2
 240.427 -     */
 240.428 -    public int compareTo(Short anotherShort) {
 240.429 -        return compare(this.value, anotherShort.value);
 240.430 -    }
 240.431 -
 240.432 -    /**
 240.433 -     * Compares two {@code short} values numerically.
 240.434 -     * The value returned is identical to what would be returned by:
 240.435 -     * <pre>
 240.436 -     *    Short.valueOf(x).compareTo(Short.valueOf(y))
 240.437 -     * </pre>
 240.438 -     *
 240.439 -     * @param  x the first {@code short} to compare
 240.440 -     * @param  y the second {@code short} to compare
 240.441 -     * @return the value {@code 0} if {@code x == y};
 240.442 -     *         a value less than {@code 0} if {@code x < y}; and
 240.443 -     *         a value greater than {@code 0} if {@code x > y}
 240.444 -     * @since 1.7
 240.445 -     */
 240.446 -    public static int compare(short x, short y) {
 240.447 -        return x - y;
 240.448 -    }
 240.449 -
 240.450 -    /**
 240.451 -     * The number of bits used to represent a {@code short} value in two's
 240.452 -     * complement binary form.
 240.453 -     * @since 1.5
 240.454 -     */
 240.455 -    public static final int SIZE = 16;
 240.456 -
 240.457 -    /**
 240.458 -     * Returns the value obtained by reversing the order of the bytes in the
 240.459 -     * two's complement representation of the specified {@code short} value.
 240.460 -     *
 240.461 -     * @return the value obtained by reversing (or, equivalently, swapping)
 240.462 -     *     the bytes in the specified {@code short} value.
 240.463 -     * @since 1.5
 240.464 -     */
 240.465 -    public static short reverseBytes(short i) {
 240.466 -        return (short) (((i & 0xFF00) >> 8) | (i << 8));
 240.467 -    }
 240.468 -
 240.469 -    /** use serialVersionUID from JDK 1.1. for interoperability */
 240.470 -    private static final long serialVersionUID = 7515723908773894738L;
 240.471 -}
   241.1 --- a/emul/src/main/java/java/lang/StackTraceElement.java	Wed Dec 05 10:03:58 2012 +0100
   241.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   241.3 @@ -1,223 +0,0 @@
   241.4 -/*
   241.5 - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
   241.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   241.7 - *
   241.8 - * This code is free software; you can redistribute it and/or modify it
   241.9 - * under the terms of the GNU General Public License version 2 only, as
  241.10 - * published by the Free Software Foundation.  Oracle designates this
  241.11 - * particular file as subject to the "Classpath" exception as provided
  241.12 - * by Oracle in the LICENSE file that accompanied this code.
  241.13 - *
  241.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  241.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  241.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  241.17 - * version 2 for more details (a copy is included in the LICENSE file that
  241.18 - * accompanied this code).
  241.19 - *
  241.20 - * You should have received a copy of the GNU General Public License version
  241.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  241.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  241.23 - *
  241.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  241.25 - * or visit www.oracle.com if you need additional information or have any
  241.26 - * questions.
  241.27 - */
  241.28 -
  241.29 -package java.lang;
  241.30 -
  241.31 -/**
  241.32 - * An element in a stack trace, as returned by {@link
  241.33 - * Throwable#getStackTrace()}.  Each element represents a single stack frame.
  241.34 - * All stack frames except for the one at the top of the stack represent
  241.35 - * a method invocation.  The frame at the top of the stack represents the
  241.36 - * execution point at which the stack trace was generated.  Typically,
  241.37 - * this is the point at which the throwable corresponding to the stack trace
  241.38 - * was created.
  241.39 - *
  241.40 - * @since  1.4
  241.41 - * @author Josh Bloch
  241.42 - */
  241.43 -public final class StackTraceElement implements java.io.Serializable {
  241.44 -    // Normally initialized by VM (public constructor added in 1.5)
  241.45 -    private String declaringClass;
  241.46 -    private String methodName;
  241.47 -    private String fileName;
  241.48 -    private int    lineNumber;
  241.49 -
  241.50 -    /**
  241.51 -     * Creates a stack trace element representing the specified execution
  241.52 -     * point.
  241.53 -     *
  241.54 -     * @param declaringClass the fully qualified name of the class containing
  241.55 -     *        the execution point represented by the stack trace element
  241.56 -     * @param methodName the name of the method containing the execution point
  241.57 -     *        represented by the stack trace element
  241.58 -     * @param fileName the name of the file containing the execution point
  241.59 -     *         represented by the stack trace element, or {@code null} if
  241.60 -     *         this information is unavailable
  241.61 -     * @param lineNumber the line number of the source line containing the
  241.62 -     *         execution point represented by this stack trace element, or
  241.63 -     *         a negative number if this information is unavailable. A value
  241.64 -     *         of -2 indicates that the method containing the execution point
  241.65 -     *         is a native method
  241.66 -     * @throws NullPointerException if {@code declaringClass} or
  241.67 -     *         {@code methodName} is null
  241.68 -     * @since 1.5
  241.69 -     */
  241.70 -    public StackTraceElement(String declaringClass, String methodName,
  241.71 -                             String fileName, int lineNumber) {
  241.72 -        this.declaringClass = declaringClass;
  241.73 -        this.methodName     = methodName;
  241.74 -        this.fileName       = fileName;
  241.75 -        this.lineNumber     = lineNumber;
  241.76 -    }
  241.77 -
  241.78 -    /**
  241.79 -     * Returns the name of the source file containing the execution point
  241.80 -     * represented by this stack trace element.  Generally, this corresponds
  241.81 -     * to the {@code SourceFile} attribute of the relevant {@code class}
  241.82 -     * file (as per <i>The Java Virtual Machine Specification</i>, Section
  241.83 -     * 4.7.7).  In some systems, the name may refer to some source code unit
  241.84 -     * other than a file, such as an entry in source repository.
  241.85 -     *
  241.86 -     * @return the name of the file containing the execution point
  241.87 -     *         represented by this stack trace element, or {@code null} if
  241.88 -     *         this information is unavailable.
  241.89 -     */
  241.90 -    public String getFileName() {
  241.91 -        return fileName;
  241.92 -    }
  241.93 -
  241.94 -    /**
  241.95 -     * Returns the line number of the source line containing the execution
  241.96 -     * point represented by this stack trace element.  Generally, this is
  241.97 -     * derived from the {@code LineNumberTable} attribute of the relevant
  241.98 -     * {@code class} file (as per <i>The Java Virtual Machine
  241.99 -     * Specification</i>, Section 4.7.8).
 241.100 -     *
 241.101 -     * @return the line number of the source line containing the execution
 241.102 -     *         point represented by this stack trace element, or a negative
 241.103 -     *         number if this information is unavailable.
 241.104 -     */
 241.105 -    public int getLineNumber() {
 241.106 -        return lineNumber;
 241.107 -    }
 241.108 -
 241.109 -    /**
 241.110 -     * Returns the fully qualified name of the class containing the
 241.111 -     * execution point represented by this stack trace element.
 241.112 -     *
 241.113 -     * @return the fully qualified name of the {@code Class} containing
 241.114 -     *         the execution point represented by this stack trace element.
 241.115 -     */
 241.116 -    public String getClassName() {
 241.117 -        return declaringClass;
 241.118 -    }
 241.119 -
 241.120 -    /**
 241.121 -     * Returns the name of the method containing the execution point
 241.122 -     * represented by this stack trace element.  If the execution point is
 241.123 -     * contained in an instance or class initializer, this method will return
 241.124 -     * the appropriate <i>special method name</i>, {@code <init>} or
 241.125 -     * {@code <clinit>}, as per Section 3.9 of <i>The Java Virtual
 241.126 -     * Machine Specification</i>.
 241.127 -     *
 241.128 -     * @return the name of the method containing the execution point
 241.129 -     *         represented by this stack trace element.
 241.130 -     */
 241.131 -    public String getMethodName() {
 241.132 -        return methodName;
 241.133 -    }
 241.134 -
 241.135 -    /**
 241.136 -     * Returns true if the method containing the execution point
 241.137 -     * represented by this stack trace element is a native method.
 241.138 -     *
 241.139 -     * @return {@code true} if the method containing the execution point
 241.140 -     *         represented by this stack trace element is a native method.
 241.141 -     */
 241.142 -    public boolean isNativeMethod() {
 241.143 -        return lineNumber == -2;
 241.144 -    }
 241.145 -
 241.146 -    /**
 241.147 -     * Returns a string representation of this stack trace element.  The
 241.148 -     * format of this string depends on the implementation, but the following
 241.149 -     * examples may be regarded as typical:
 241.150 -     * <ul>
 241.151 -     * <li>
 241.152 -     *   {@code "MyClass.mash(MyClass.java:9)"} - Here, {@code "MyClass"}
 241.153 -     *   is the <i>fully-qualified name</i> of the class containing the
 241.154 -     *   execution point represented by this stack trace element,
 241.155 -     *   {@code "mash"} is the name of the method containing the execution
 241.156 -     *   point, {@code "MyClass.java"} is the source file containing the
 241.157 -     *   execution point, and {@code "9"} is the line number of the source
 241.158 -     *   line containing the execution point.
 241.159 -     * <li>
 241.160 -     *   {@code "MyClass.mash(MyClass.java)"} - As above, but the line
 241.161 -     *   number is unavailable.
 241.162 -     * <li>
 241.163 -     *   {@code "MyClass.mash(Unknown Source)"} - As above, but neither
 241.164 -     *   the file name nor the line  number are available.
 241.165 -     * <li>
 241.166 -     *   {@code "MyClass.mash(Native Method)"} - As above, but neither
 241.167 -     *   the file name nor the line  number are available, and the method
 241.168 -     *   containing the execution point is known to be a native method.
 241.169 -     * </ul>
 241.170 -     * @see    Throwable#printStackTrace()
 241.171 -     */
 241.172 -    public String toString() {
 241.173 -        return getClassName() + "." + methodName +
 241.174 -            (isNativeMethod() ? "(Native Method)" :
 241.175 -             (fileName != null && lineNumber >= 0 ?
 241.176 -              "(" + fileName + ":" + lineNumber + ")" :
 241.177 -              (fileName != null ?  "("+fileName+")" : "(Unknown Source)")));
 241.178 -    }
 241.179 -
 241.180 -    /**
 241.181 -     * Returns true if the specified object is another
 241.182 -     * {@code StackTraceElement} instance representing the same execution
 241.183 -     * point as this instance.  Two stack trace elements {@code a} and
 241.184 -     * {@code b} are equal if and only if:
 241.185 -     * <pre>
 241.186 -     *     equals(a.getFileName(), b.getFileName()) &&
 241.187 -     *     a.getLineNumber() == b.getLineNumber()) &&
 241.188 -     *     equals(a.getClassName(), b.getClassName()) &&
 241.189 -     *     equals(a.getMethodName(), b.getMethodName())
 241.190 -     * </pre>
 241.191 -     * where {@code equals} has the semantics of {@link
 241.192 -     * java.util.Objects#equals(Object, Object) Objects.equals}.
 241.193 -     *
 241.194 -     * @param  obj the object to be compared with this stack trace element.
 241.195 -     * @return true if the specified object is another
 241.196 -     *         {@code StackTraceElement} instance representing the same
 241.197 -     *         execution point as this instance.
 241.198 -     */
 241.199 -    public boolean equals(Object obj) {
 241.200 -        if (obj==this)
 241.201 -            return true;
 241.202 -        if (!(obj instanceof StackTraceElement))
 241.203 -            return false;
 241.204 -        StackTraceElement e = (StackTraceElement)obj;
 241.205 -        return e.declaringClass.equals(declaringClass) &&
 241.206 -            e.lineNumber == lineNumber &&
 241.207 -            equals(methodName, e.methodName) &&
 241.208 -            equals(fileName, e.fileName);
 241.209 -    }
 241.210 -
 241.211 -    /**
 241.212 -     * Returns a hash code value for this stack trace element.
 241.213 -     */
 241.214 -    public int hashCode() {
 241.215 -        int result = 31*declaringClass.hashCode() + methodName.hashCode();
 241.216 -        result = 31*result + (fileName == null ? 0 : fileName.hashCode());
 241.217 -        result = 31*result + lineNumber;
 241.218 -        return result;
 241.219 -    }
 241.220 -    
 241.221 -    private static boolean equals(Object a, Object b) {
 241.222 -        return (a == b) || (a != null && a.equals(b));
 241.223 -    }
 241.224 -
 241.225 -    private static final long serialVersionUID = 6992337162326171013L;
 241.226 -}
   242.1 --- a/emul/src/main/java/java/lang/String.java	Wed Dec 05 10:03:58 2012 +0100
   242.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   242.3 @@ -1,3067 +0,0 @@
   242.4 -/*
   242.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   242.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   242.7 - *
   242.8 - * This code is free software; you can redistribute it and/or modify it
   242.9 - * under the terms of the GNU General Public License version 2 only, as
  242.10 - * published by the Free Software Foundation.  Oracle designates this
  242.11 - * particular file as subject to the "Classpath" exception as provided
  242.12 - * by Oracle in the LICENSE file that accompanied this code.
  242.13 - *
  242.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  242.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  242.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  242.17 - * version 2 for more details (a copy is included in the LICENSE file that
  242.18 - * accompanied this code).
  242.19 - *
  242.20 - * You should have received a copy of the GNU General Public License version
  242.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  242.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  242.23 - *
  242.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  242.25 - * or visit www.oracle.com if you need additional information or have any
  242.26 - * questions.
  242.27 - */
  242.28 -
  242.29 -package java.lang;
  242.30 -
  242.31 -import java.util.Comparator;
  242.32 -import org.apidesign.bck2brwsr.core.ExtraJavaScript;
  242.33 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  242.34 -import org.apidesign.bck2brwsr.core.JavaScriptOnly;
  242.35 -import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  242.36 -
  242.37 -/**
  242.38 - * The <code>String</code> class represents character strings. All
  242.39 - * string literals in Java programs, such as <code>"abc"</code>, are
  242.40 - * implemented as instances of this class.
  242.41 - * <p>
  242.42 - * Strings are constant; their values cannot be changed after they
  242.43 - * are created. String buffers support mutable strings.
  242.44 - * Because String objects are immutable they can be shared. For example:
  242.45 - * <p><blockquote><pre>
  242.46 - *     String str = "abc";
  242.47 - * </pre></blockquote><p>
  242.48 - * is equivalent to:
  242.49 - * <p><blockquote><pre>
  242.50 - *     char data[] = {'a', 'b', 'c'};
  242.51 - *     String str = new String(data);
  242.52 - * </pre></blockquote><p>
  242.53 - * Here are some more examples of how strings can be used:
  242.54 - * <p><blockquote><pre>
  242.55 - *     System.out.println("abc");
  242.56 - *     String cde = "cde";
  242.57 - *     System.out.println("abc" + cde);
  242.58 - *     String c = "abc".substring(2,3);
  242.59 - *     String d = cde.substring(1, 2);
  242.60 - * </pre></blockquote>
  242.61 - * <p>
  242.62 - * The class <code>String</code> includes methods for examining
  242.63 - * individual characters of the sequence, for comparing strings, for
  242.64 - * searching strings, for extracting substrings, and for creating a
  242.65 - * copy of a string with all characters translated to uppercase or to
  242.66 - * lowercase. Case mapping is based on the Unicode Standard version
  242.67 - * specified by the {@link java.lang.Character Character} class.
  242.68 - * <p>
  242.69 - * The Java language provides special support for the string
  242.70 - * concatenation operator (&nbsp;+&nbsp;), and for conversion of
  242.71 - * other objects to strings. String concatenation is implemented
  242.72 - * through the <code>StringBuilder</code>(or <code>StringBuffer</code>)
  242.73 - * class and its <code>append</code> method.
  242.74 - * String conversions are implemented through the method
  242.75 - * <code>toString</code>, defined by <code>Object</code> and
  242.76 - * inherited by all classes in Java. For additional information on
  242.77 - * string concatenation and conversion, see Gosling, Joy, and Steele,
  242.78 - * <i>The Java Language Specification</i>.
  242.79 - *
  242.80 - * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
  242.81 - * or method in this class will cause a {@link NullPointerException} to be
  242.82 - * thrown.
  242.83 - *
  242.84 - * <p>A <code>String</code> represents a string in the UTF-16 format
  242.85 - * in which <em>supplementary characters</em> are represented by <em>surrogate
  242.86 - * pairs</em> (see the section <a href="Character.html#unicode">Unicode
  242.87 - * Character Representations</a> in the <code>Character</code> class for
  242.88 - * more information).
  242.89 - * Index values refer to <code>char</code> code units, so a supplementary
  242.90 - * character uses two positions in a <code>String</code>.
  242.91 - * <p>The <code>String</code> class provides methods for dealing with
  242.92 - * Unicode code points (i.e., characters), in addition to those for
  242.93 - * dealing with Unicode code units (i.e., <code>char</code> values).
  242.94 - *
  242.95 - * @author  Lee Boynton
  242.96 - * @author  Arthur van Hoff
  242.97 - * @author  Martin Buchholz
  242.98 - * @author  Ulf Zibis
  242.99 - * @see     java.lang.Object#toString()
 242.100 - * @see     java.lang.StringBuffer
 242.101 - * @see     java.lang.StringBuilder
 242.102 - * @see     java.nio.charset.Charset
 242.103 - * @since   JDK1.0
 242.104 - */
 242.105 -
 242.106 -@ExtraJavaScript(
 242.107 -    resource="/org/apidesign/vm4brwsr/emul/java_lang_String.js",
 242.108 -    processByteCode=true
 242.109 -)
 242.110 -@JavaScriptPrototype(container = "String.prototype", prototype = "new String")
 242.111 -public final class String
 242.112 -    implements java.io.Serializable, Comparable<String>, CharSequence
 242.113 -{
 242.114 -    @JavaScriptOnly
 242.115 -    /** Cache the hash code for the string */
 242.116 -    private int hash; // Default to 0
 242.117 -    
 242.118 -    /** real string to delegate to */
 242.119 -    private Object r;
 242.120 -
 242.121 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 242.122 -    private static final long serialVersionUID = -6849794470754667710L;
 242.123 -    
 242.124 -    @JavaScriptOnly(name="toString", value="function() { return this.fld_r; }")
 242.125 -    private static void jsToString() {
 242.126 -    }
 242.127 -    
 242.128 -    @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
 242.129 -    private static void jsValudOf() {
 242.130 -    }
 242.131 -
 242.132 -    /**
 242.133 -     * Class String is special cased within the Serialization Stream Protocol.
 242.134 -     *
 242.135 -     * A String instance is written initially into an ObjectOutputStream in the
 242.136 -     * following format:
 242.137 -     * <pre>
 242.138 -     *      <code>TC_STRING</code> (utf String)
 242.139 -     * </pre>
 242.140 -     * The String is written by method <code>DataOutput.writeUTF</code>.
 242.141 -     * A new handle is generated to  refer to all future references to the
 242.142 -     * string instance within the stream.
 242.143 -     */
 242.144 -//    private static final ObjectStreamField[] serialPersistentFields =
 242.145 -//        new ObjectStreamField[0];
 242.146 -
 242.147 -    /**
 242.148 -     * Initializes a newly created {@code String} object so that it represents
 242.149 -     * an empty character sequence.  Note that use of this constructor is
 242.150 -     * unnecessary since Strings are immutable.
 242.151 -     */
 242.152 -    public String() {
 242.153 -        this.r = "";
 242.154 -    }
 242.155 -
 242.156 -    /**
 242.157 -     * Initializes a newly created {@code String} object so that it represents
 242.158 -     * the same sequence of characters as the argument; in other words, the
 242.159 -     * newly created string is a copy of the argument string. Unless an
 242.160 -     * explicit copy of {@code original} is needed, use of this constructor is
 242.161 -     * unnecessary since Strings are immutable.
 242.162 -     *
 242.163 -     * @param  original
 242.164 -     *         A {@code String}
 242.165 -     */
 242.166 -    public String(String original) {
 242.167 -        this.r = original.toString();
 242.168 -    }
 242.169 -
 242.170 -    /**
 242.171 -     * Allocates a new {@code String} so that it represents the sequence of
 242.172 -     * characters currently contained in the character array argument. The
 242.173 -     * contents of the character array are copied; subsequent modification of
 242.174 -     * the character array does not affect the newly created string.
 242.175 -     *
 242.176 -     * @param  value
 242.177 -     *         The initial value of the string
 242.178 -     */
 242.179 -    @JavaScriptBody(args = { "self", "charArr" }, body=
 242.180 -        "for (var i = 0; i < charArr.length; i++) {\n"
 242.181 -      + "  if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n"
 242.182 -      + "}\n"
 242.183 -      + "self.fld_r = charArr.join('');\n"
 242.184 -    )
 242.185 -    public String(char value[]) {
 242.186 -    }
 242.187 -
 242.188 -    /**
 242.189 -     * Allocates a new {@code String} that contains characters from a subarray
 242.190 -     * of the character array argument. The {@code offset} argument is the
 242.191 -     * index of the first character of the subarray and the {@code count}
 242.192 -     * argument specifies the length of the subarray. The contents of the
 242.193 -     * subarray are copied; subsequent modification of the character array does
 242.194 -     * not affect the newly created string.
 242.195 -     *
 242.196 -     * @param  value
 242.197 -     *         Array that is the source of characters
 242.198 -     *
 242.199 -     * @param  offset
 242.200 -     *         The initial offset
 242.201 -     *
 242.202 -     * @param  count
 242.203 -     *         The length
 242.204 -     *
 242.205 -     * @throws  IndexOutOfBoundsException
 242.206 -     *          If the {@code offset} and {@code count} arguments index
 242.207 -     *          characters outside the bounds of the {@code value} array
 242.208 -     */
 242.209 -    @JavaScriptBody(args = { "self", "charArr", "off", "cnt" }, body =
 242.210 -        "var up = off + cnt;\n" +
 242.211 -        "for (var i = off; i < up; i++) {\n" +
 242.212 -        "  if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n" +
 242.213 -        "}\n" +
 242.214 -        "self.fld_r = charArr.slice(off, up).join(\"\");\n"
 242.215 -    )
 242.216 -    public String(char value[], int offset, int count) {
 242.217 -    }
 242.218 -
 242.219 -    /**
 242.220 -     * Allocates a new {@code String} that contains characters from a subarray
 242.221 -     * of the <a href="Character.html#unicode">Unicode code point</a> array
 242.222 -     * argument.  The {@code offset} argument is the index of the first code
 242.223 -     * point of the subarray and the {@code count} argument specifies the
 242.224 -     * length of the subarray.  The contents of the subarray are converted to
 242.225 -     * {@code char}s; subsequent modification of the {@code int} array does not
 242.226 -     * affect the newly created string.
 242.227 -     *
 242.228 -     * @param  codePoints
 242.229 -     *         Array that is the source of Unicode code points
 242.230 -     *
 242.231 -     * @param  offset
 242.232 -     *         The initial offset
 242.233 -     *
 242.234 -     * @param  count
 242.235 -     *         The length
 242.236 -     *
 242.237 -     * @throws  IllegalArgumentException
 242.238 -     *          If any invalid Unicode code point is found in {@code
 242.239 -     *          codePoints}
 242.240 -     *
 242.241 -     * @throws  IndexOutOfBoundsException
 242.242 -     *          If the {@code offset} and {@code count} arguments index
 242.243 -     *          characters outside the bounds of the {@code codePoints} array
 242.244 -     *
 242.245 -     * @since  1.5
 242.246 -     */
 242.247 -    public String(int[] codePoints, int offset, int count) {
 242.248 -        if (offset < 0) {
 242.249 -            throw new StringIndexOutOfBoundsException(offset);
 242.250 -        }
 242.251 -        if (count < 0) {
 242.252 -            throw new StringIndexOutOfBoundsException(count);
 242.253 -        }
 242.254 -        // Note: offset or count might be near -1>>>1.
 242.255 -        if (offset > codePoints.length - count) {
 242.256 -            throw new StringIndexOutOfBoundsException(offset + count);
 242.257 -        }
 242.258 -
 242.259 -        final int end = offset + count;
 242.260 -
 242.261 -        // Pass 1: Compute precise size of char[]
 242.262 -        int n = count;
 242.263 -        for (int i = offset; i < end; i++) {
 242.264 -            int c = codePoints[i];
 242.265 -            if (Character.isBmpCodePoint(c))
 242.266 -                continue;
 242.267 -            else if (Character.isValidCodePoint(c))
 242.268 -                n++;
 242.269 -            else throw new IllegalArgumentException(Integer.toString(c));
 242.270 -        }
 242.271 -
 242.272 -        // Pass 2: Allocate and fill in char[]
 242.273 -        final char[] v = new char[n];
 242.274 -
 242.275 -        for (int i = offset, j = 0; i < end; i++, j++) {
 242.276 -            int c = codePoints[i];
 242.277 -            if (Character.isBmpCodePoint(c))
 242.278 -                v[j] = (char) c;
 242.279 -            else
 242.280 -                Character.toSurrogates(c, v, j++);
 242.281 -        }
 242.282 -
 242.283 -        this.r = new String(v, 0, n);
 242.284 -    }
 242.285 -
 242.286 -    /**
 242.287 -     * Allocates a new {@code String} constructed from a subarray of an array
 242.288 -     * of 8-bit integer values.
 242.289 -     *
 242.290 -     * <p> The {@code offset} argument is the index of the first byte of the
 242.291 -     * subarray, and the {@code count} argument specifies the length of the
 242.292 -     * subarray.
 242.293 -     *
 242.294 -     * <p> Each {@code byte} in the subarray is converted to a {@code char} as
 242.295 -     * specified in the method above.
 242.296 -     *
 242.297 -     * @deprecated This method does not properly convert bytes into characters.
 242.298 -     * As of JDK&nbsp;1.1, the preferred way to do this is via the
 242.299 -     * {@code String} constructors that take a {@link
 242.300 -     * java.nio.charset.Charset}, charset name, or that use the platform's
 242.301 -     * default charset.
 242.302 -     *
 242.303 -     * @param  ascii
 242.304 -     *         The bytes to be converted to characters
 242.305 -     *
 242.306 -     * @param  hibyte
 242.307 -     *         The top 8 bits of each 16-bit Unicode code unit
 242.308 -     *
 242.309 -     * @param  offset
 242.310 -     *         The initial offset
 242.311 -     * @param  count
 242.312 -     *         The length
 242.313 -     *
 242.314 -     * @throws  IndexOutOfBoundsException
 242.315 -     *          If the {@code offset} or {@code count} argument is invalid
 242.316 -     *
 242.317 -     * @see  #String(byte[], int)
 242.318 -     * @see  #String(byte[], int, int, java.lang.String)
 242.319 -     * @see  #String(byte[], int, int, java.nio.charset.Charset)
 242.320 -     * @see  #String(byte[], int, int)
 242.321 -     * @see  #String(byte[], java.lang.String)
 242.322 -     * @see  #String(byte[], java.nio.charset.Charset)
 242.323 -     * @see  #String(byte[])
 242.324 -     */
 242.325 -    @Deprecated
 242.326 -    public String(byte ascii[], int hibyte, int offset, int count) {
 242.327 -        checkBounds(ascii, offset, count);
 242.328 -        char value[] = new char[count];
 242.329 -
 242.330 -        if (hibyte == 0) {
 242.331 -            for (int i = count ; i-- > 0 ;) {
 242.332 -                value[i] = (char) (ascii[i + offset] & 0xff);
 242.333 -            }
 242.334 -        } else {
 242.335 -            hibyte <<= 8;
 242.336 -            for (int i = count ; i-- > 0 ;) {
 242.337 -                value[i] = (char) (hibyte | (ascii[i + offset] & 0xff));
 242.338 -            }
 242.339 -        }
 242.340 -        this.r = new String(value, 0, count);
 242.341 -    }
 242.342 -
 242.343 -    /**
 242.344 -     * Allocates a new {@code String} containing characters constructed from
 242.345 -     * an array of 8-bit integer values. Each character <i>c</i>in the
 242.346 -     * resulting string is constructed from the corresponding component
 242.347 -     * <i>b</i> in the byte array such that:
 242.348 -     *
 242.349 -     * <blockquote><pre>
 242.350 -     *     <b><i>c</i></b> == (char)(((hibyte &amp; 0xff) &lt;&lt; 8)
 242.351 -     *                         | (<b><i>b</i></b> &amp; 0xff))
 242.352 -     * </pre></blockquote>
 242.353 -     *
 242.354 -     * @deprecated  This method does not properly convert bytes into
 242.355 -     * characters.  As of JDK&nbsp;1.1, the preferred way to do this is via the
 242.356 -     * {@code String} constructors that take a {@link
 242.357 -     * java.nio.charset.Charset}, charset name, or that use the platform's
 242.358 -     * default charset.
 242.359 -     *
 242.360 -     * @param  ascii
 242.361 -     *         The bytes to be converted to characters
 242.362 -     *
 242.363 -     * @param  hibyte
 242.364 -     *         The top 8 bits of each 16-bit Unicode code unit
 242.365 -     *
 242.366 -     * @see  #String(byte[], int, int, java.lang.String)
 242.367 -     * @see  #String(byte[], int, int, java.nio.charset.Charset)
 242.368 -     * @see  #String(byte[], int, int)
 242.369 -     * @see  #String(byte[], java.lang.String)
 242.370 -     * @see  #String(byte[], java.nio.charset.Charset)
 242.371 -     * @see  #String(byte[])
 242.372 -     */
 242.373 -    @Deprecated
 242.374 -    public String(byte ascii[], int hibyte) {
 242.375 -        this(ascii, hibyte, 0, ascii.length);
 242.376 -    }
 242.377 -
 242.378 -    /* Common private utility method used to bounds check the byte array
 242.379 -     * and requested offset & length values used by the String(byte[],..)
 242.380 -     * constructors.
 242.381 -     */
 242.382 -    private static void checkBounds(byte[] bytes, int offset, int length) {
 242.383 -        if (length < 0)
 242.384 -            throw new StringIndexOutOfBoundsException(length);
 242.385 -        if (offset < 0)
 242.386 -            throw new StringIndexOutOfBoundsException(offset);
 242.387 -        if (offset > bytes.length - length)
 242.388 -            throw new StringIndexOutOfBoundsException(offset + length);
 242.389 -    }
 242.390 -
 242.391 -    /**
 242.392 -     * Constructs a new {@code String} by decoding the specified subarray of
 242.393 -     * bytes using the specified charset.  The length of the new {@code String}
 242.394 -     * is a function of the charset, and hence may not be equal to the length
 242.395 -     * of the subarray.
 242.396 -     *
 242.397 -     * <p> The behavior of this constructor when the given bytes are not valid
 242.398 -     * in the given charset is unspecified.  The {@link
 242.399 -     * java.nio.charset.CharsetDecoder} class should be used when more control
 242.400 -     * over the decoding process is required.
 242.401 -     *
 242.402 -     * @param  bytes
 242.403 -     *         The bytes to be decoded into characters
 242.404 -     *
 242.405 -     * @param  offset
 242.406 -     *         The index of the first byte to decode
 242.407 -     *
 242.408 -     * @param  length
 242.409 -     *         The number of bytes to decode
 242.410 -
 242.411 -     * @param  charsetName
 242.412 -     *         The name of a supported {@linkplain java.nio.charset.Charset
 242.413 -     *         charset}
 242.414 -     *
 242.415 -     * @throws  UnsupportedEncodingException
 242.416 -     *          If the named charset is not supported
 242.417 -     *
 242.418 -     * @throws  IndexOutOfBoundsException
 242.419 -     *          If the {@code offset} and {@code length} arguments index
 242.420 -     *          characters outside the bounds of the {@code bytes} array
 242.421 -     *
 242.422 -     * @since  JDK1.1
 242.423 -     */
 242.424 -//    public String(byte bytes[], int offset, int length, String charsetName)
 242.425 -//        throws UnsupportedEncodingException
 242.426 -//    {
 242.427 -//        if (charsetName == null)
 242.428 -//            throw new NullPointerException("charsetName");
 242.429 -//        checkBounds(bytes, offset, length);
 242.430 -//        char[] v = StringCoding.decode(charsetName, bytes, offset, length);
 242.431 -//        this.offset = 0;
 242.432 -//        this.count = v.length;
 242.433 -//        this.value = v;
 242.434 -//    }
 242.435 -
 242.436 -    /**
 242.437 -     * Constructs a new {@code String} by decoding the specified subarray of
 242.438 -     * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
 242.439 -     * The length of the new {@code String} is a function of the charset, and
 242.440 -     * hence may not be equal to the length of the subarray.
 242.441 -     *
 242.442 -     * <p> This method always replaces malformed-input and unmappable-character
 242.443 -     * sequences with this charset's default replacement string.  The {@link
 242.444 -     * java.nio.charset.CharsetDecoder} class should be used when more control
 242.445 -     * over the decoding process is required.
 242.446 -     *
 242.447 -     * @param  bytes
 242.448 -     *         The bytes to be decoded into characters
 242.449 -     *
 242.450 -     * @param  offset
 242.451 -     *         The index of the first byte to decode
 242.452 -     *
 242.453 -     * @param  length
 242.454 -     *         The number of bytes to decode
 242.455 -     *
 242.456 -     * @param  charset
 242.457 -     *         The {@linkplain java.nio.charset.Charset charset} to be used to
 242.458 -     *         decode the {@code bytes}
 242.459 -     *
 242.460 -     * @throws  IndexOutOfBoundsException
 242.461 -     *          If the {@code offset} and {@code length} arguments index
 242.462 -     *          characters outside the bounds of the {@code bytes} array
 242.463 -     *
 242.464 -     * @since  1.6
 242.465 -     */
 242.466 -    /* don't want dependnecy on Charset
 242.467 -    public String(byte bytes[], int offset, int length, Charset charset) {
 242.468 -        if (charset == null)
 242.469 -            throw new NullPointerException("charset");
 242.470 -        checkBounds(bytes, offset, length);
 242.471 -        char[] v = StringCoding.decode(charset, bytes, offset, length);
 242.472 -        this.offset = 0;
 242.473 -        this.count = v.length;
 242.474 -        this.value = v;
 242.475 -    }
 242.476 -    */
 242.477 -
 242.478 -    /**
 242.479 -     * Constructs a new {@code String} by decoding the specified array of bytes
 242.480 -     * using the specified {@linkplain java.nio.charset.Charset charset}.  The
 242.481 -     * length of the new {@code String} is a function of the charset, and hence
 242.482 -     * may not be equal to the length of the byte array.
 242.483 -     *
 242.484 -     * <p> The behavior of this constructor when the given bytes are not valid
 242.485 -     * in the given charset is unspecified.  The {@link
 242.486 -     * java.nio.charset.CharsetDecoder} class should be used when more control
 242.487 -     * over the decoding process is required.
 242.488 -     *
 242.489 -     * @param  bytes
 242.490 -     *         The bytes to be decoded into characters
 242.491 -     *
 242.492 -     * @param  charsetName
 242.493 -     *         The name of a supported {@linkplain java.nio.charset.Charset
 242.494 -     *         charset}
 242.495 -     *
 242.496 -     * @throws  UnsupportedEncodingException
 242.497 -     *          If the named charset is not supported
 242.498 -     *
 242.499 -     * @since  JDK1.1
 242.500 -     */
 242.501 -//    public String(byte bytes[], String charsetName)
 242.502 -//        throws UnsupportedEncodingException
 242.503 -//    {
 242.504 -//        this(bytes, 0, bytes.length, charsetName);
 242.505 -//    }
 242.506 -
 242.507 -    /**
 242.508 -     * Constructs a new {@code String} by decoding the specified array of
 242.509 -     * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
 242.510 -     * The length of the new {@code String} is a function of the charset, and
 242.511 -     * hence may not be equal to the length of the byte array.
 242.512 -     *
 242.513 -     * <p> This method always replaces malformed-input and unmappable-character
 242.514 -     * sequences with this charset's default replacement string.  The {@link
 242.515 -     * java.nio.charset.CharsetDecoder} class should be used when more control
 242.516 -     * over the decoding process is required.
 242.517 -     *
 242.518 -     * @param  bytes
 242.519 -     *         The bytes to be decoded into characters
 242.520 -     *
 242.521 -     * @param  charset
 242.522 -     *         The {@linkplain java.nio.charset.Charset charset} to be used to
 242.523 -     *         decode the {@code bytes}
 242.524 -     *
 242.525 -     * @since  1.6
 242.526 -     */
 242.527 -    /* don't want dep on Charset
 242.528 -    public String(byte bytes[], Charset charset) {
 242.529 -        this(bytes, 0, bytes.length, charset);
 242.530 -    }
 242.531 -    */
 242.532 -
 242.533 -    /**
 242.534 -     * Constructs a new {@code String} by decoding the specified subarray of
 242.535 -     * bytes using the platform's default charset.  The length of the new
 242.536 -     * {@code String} is a function of the charset, and hence may not be equal
 242.537 -     * to the length of the subarray.
 242.538 -     *
 242.539 -     * <p> The behavior of this constructor when the given bytes are not valid
 242.540 -     * in the default charset is unspecified.  The {@link
 242.541 -     * java.nio.charset.CharsetDecoder} class should be used when more control
 242.542 -     * over the decoding process is required.
 242.543 -     *
 242.544 -     * @param  bytes
 242.545 -     *         The bytes to be decoded into characters
 242.546 -     *
 242.547 -     * @param  offset
 242.548 -     *         The index of the first byte to decode
 242.549 -     *
 242.550 -     * @param  length
 242.551 -     *         The number of bytes to decode
 242.552 -     *
 242.553 -     * @throws  IndexOutOfBoundsException
 242.554 -     *          If the {@code offset} and the {@code length} arguments index
 242.555 -     *          characters outside the bounds of the {@code bytes} array
 242.556 -     *
 242.557 -     * @since  JDK1.1
 242.558 -     */
 242.559 -    public String(byte bytes[], int offset, int length) {
 242.560 -        checkBounds(bytes, offset, length);
 242.561 -        char[] v  = new char[length];
 242.562 -        for (int i = 0; i < length; i++) {
 242.563 -            v[i] = (char)bytes[offset++];
 242.564 -        }
 242.565 -        this.r = new String(v, 0, v.length);
 242.566 -    }
 242.567 -
 242.568 -    /**
 242.569 -     * Constructs a new {@code String} by decoding the specified array of bytes
 242.570 -     * using the platform's default charset.  The length of the new {@code
 242.571 -     * String} is a function of the charset, and hence may not be equal to the
 242.572 -     * length of the byte array.
 242.573 -     *
 242.574 -     * <p> The behavior of this constructor when the given bytes are not valid
 242.575 -     * in the default charset is unspecified.  The {@link
 242.576 -     * java.nio.charset.CharsetDecoder} class should be used when more control
 242.577 -     * over the decoding process is required.
 242.578 -     *
 242.579 -     * @param  bytes
 242.580 -     *         The bytes to be decoded into characters
 242.581 -     *
 242.582 -     * @since  JDK1.1
 242.583 -     */
 242.584 -    public String(byte bytes[]) {
 242.585 -        this(bytes, 0, bytes.length);
 242.586 -    }
 242.587 -
 242.588 -    /**
 242.589 -     * Allocates a new string that contains the sequence of characters
 242.590 -     * currently contained in the string buffer argument. The contents of the
 242.591 -     * string buffer are copied; subsequent modification of the string buffer
 242.592 -     * does not affect the newly created string.
 242.593 -     *
 242.594 -     * @param  buffer
 242.595 -     *         A {@code StringBuffer}
 242.596 -     */
 242.597 -    public String(StringBuffer buffer) {
 242.598 -        this.r = buffer.toString();
 242.599 -    }
 242.600 -
 242.601 -    /**
 242.602 -     * Allocates a new string that contains the sequence of characters
 242.603 -     * currently contained in the string builder argument. The contents of the
 242.604 -     * string builder are copied; subsequent modification of the string builder
 242.605 -     * does not affect the newly created string.
 242.606 -     *
 242.607 -     * <p> This constructor is provided to ease migration to {@code
 242.608 -     * StringBuilder}. Obtaining a string from a string builder via the {@code
 242.609 -     * toString} method is likely to run faster and is generally preferred.
 242.610 -     *
 242.611 -     * @param   builder
 242.612 -     *          A {@code StringBuilder}
 242.613 -     *
 242.614 -     * @since  1.5
 242.615 -     */
 242.616 -    public String(StringBuilder builder) {
 242.617 -        this.r = builder.toString();
 242.618 -    }
 242.619 -
 242.620 -    /**
 242.621 -     * Returns the length of this string.
 242.622 -     * The length is equal to the number of <a href="Character.html#unicode">Unicode
 242.623 -     * code units</a> in the string.
 242.624 -     *
 242.625 -     * @return  the length of the sequence of characters represented by this
 242.626 -     *          object.
 242.627 -     */
 242.628 -    @JavaScriptBody(args = "self", body = "return self.toString().length;")
 242.629 -    public int length() {
 242.630 -        throw new UnsupportedOperationException();
 242.631 -    }
 242.632 -
 242.633 -    /**
 242.634 -     * Returns <tt>true</tt> if, and only if, {@link #length()} is <tt>0</tt>.
 242.635 -     *
 242.636 -     * @return <tt>true</tt> if {@link #length()} is <tt>0</tt>, otherwise
 242.637 -     * <tt>false</tt>
 242.638 -     *
 242.639 -     * @since 1.6
 242.640 -     */
 242.641 -    @JavaScriptBody(args = "self", body="return self.toString().length === 0;")
 242.642 -    public boolean isEmpty() {
 242.643 -        return length() == 0;
 242.644 -    }
 242.645 -
 242.646 -    /**
 242.647 -     * Returns the <code>char</code> value at the
 242.648 -     * specified index. An index ranges from <code>0</code> to
 242.649 -     * <code>length() - 1</code>. The first <code>char</code> value of the sequence
 242.650 -     * is at index <code>0</code>, the next at index <code>1</code>,
 242.651 -     * and so on, as for array indexing.
 242.652 -     *
 242.653 -     * <p>If the <code>char</code> value specified by the index is a
 242.654 -     * <a href="Character.html#unicode">surrogate</a>, the surrogate
 242.655 -     * value is returned.
 242.656 -     *
 242.657 -     * @param      index   the index of the <code>char</code> value.
 242.658 -     * @return     the <code>char</code> value at the specified index of this string.
 242.659 -     *             The first <code>char</code> value is at index <code>0</code>.
 242.660 -     * @exception  IndexOutOfBoundsException  if the <code>index</code>
 242.661 -     *             argument is negative or not less than the length of this
 242.662 -     *             string.
 242.663 -     */
 242.664 -    @JavaScriptBody(args = { "self", "index" }, 
 242.665 -        body = "return self.toString().charCodeAt(index);"
 242.666 -    )
 242.667 -    public char charAt(int index) {
 242.668 -        throw new UnsupportedOperationException();
 242.669 -    }
 242.670 -
 242.671 -    /**
 242.672 -     * Returns the character (Unicode code point) at the specified
 242.673 -     * index. The index refers to <code>char</code> values
 242.674 -     * (Unicode code units) and ranges from <code>0</code> to
 242.675 -     * {@link #length()}<code> - 1</code>.
 242.676 -     *
 242.677 -     * <p> If the <code>char</code> value specified at the given index
 242.678 -     * is in the high-surrogate range, the following index is less
 242.679 -     * than the length of this <code>String</code>, and the
 242.680 -     * <code>char</code> value at the following index is in the
 242.681 -     * low-surrogate range, then the supplementary code point
 242.682 -     * corresponding to this surrogate pair is returned. Otherwise,
 242.683 -     * the <code>char</code> value at the given index is returned.
 242.684 -     *
 242.685 -     * @param      index the index to the <code>char</code> values
 242.686 -     * @return     the code point value of the character at the
 242.687 -     *             <code>index</code>
 242.688 -     * @exception  IndexOutOfBoundsException  if the <code>index</code>
 242.689 -     *             argument is negative or not less than the length of this
 242.690 -     *             string.
 242.691 -     * @since      1.5
 242.692 -     */
 242.693 -    public int codePointAt(int index) {
 242.694 -        if ((index < 0) || (index >= length())) {
 242.695 -            throw new StringIndexOutOfBoundsException(index);
 242.696 -        }
 242.697 -        return Character.codePointAtImpl(toCharArray(), offset() + index, offset() + length());
 242.698 -    }
 242.699 -
 242.700 -    /**
 242.701 -     * Returns the character (Unicode code point) before the specified
 242.702 -     * index. The index refers to <code>char</code> values
 242.703 -     * (Unicode code units) and ranges from <code>1</code> to {@link
 242.704 -     * CharSequence#length() length}.
 242.705 -     *
 242.706 -     * <p> If the <code>char</code> value at <code>(index - 1)</code>
 242.707 -     * is in the low-surrogate range, <code>(index - 2)</code> is not
 242.708 -     * negative, and the <code>char</code> value at <code>(index -
 242.709 -     * 2)</code> is in the high-surrogate range, then the
 242.710 -     * supplementary code point value of the surrogate pair is
 242.711 -     * returned. If the <code>char</code> value at <code>index -
 242.712 -     * 1</code> is an unpaired low-surrogate or a high-surrogate, the
 242.713 -     * surrogate value is returned.
 242.714 -     *
 242.715 -     * @param     index the index following the code point that should be returned
 242.716 -     * @return    the Unicode code point value before the given index.
 242.717 -     * @exception IndexOutOfBoundsException if the <code>index</code>
 242.718 -     *            argument is less than 1 or greater than the length
 242.719 -     *            of this string.
 242.720 -     * @since     1.5
 242.721 -     */
 242.722 -    public int codePointBefore(int index) {
 242.723 -        int i = index - 1;
 242.724 -        if ((i < 0) || (i >= length())) {
 242.725 -            throw new StringIndexOutOfBoundsException(index);
 242.726 -        }
 242.727 -        return Character.codePointBeforeImpl(toCharArray(), offset() + index, offset());
 242.728 -    }
 242.729 -
 242.730 -    /**
 242.731 -     * Returns the number of Unicode code points in the specified text
 242.732 -     * range of this <code>String</code>. The text range begins at the
 242.733 -     * specified <code>beginIndex</code> and extends to the
 242.734 -     * <code>char</code> at index <code>endIndex - 1</code>. Thus the
 242.735 -     * length (in <code>char</code>s) of the text range is
 242.736 -     * <code>endIndex-beginIndex</code>. Unpaired surrogates within
 242.737 -     * the text range count as one code point each.
 242.738 -     *
 242.739 -     * @param beginIndex the index to the first <code>char</code> of
 242.740 -     * the text range.
 242.741 -     * @param endIndex the index after the last <code>char</code> of
 242.742 -     * the text range.
 242.743 -     * @return the number of Unicode code points in the specified text
 242.744 -     * range
 242.745 -     * @exception IndexOutOfBoundsException if the
 242.746 -     * <code>beginIndex</code> is negative, or <code>endIndex</code>
 242.747 -     * is larger than the length of this <code>String</code>, or
 242.748 -     * <code>beginIndex</code> is larger than <code>endIndex</code>.
 242.749 -     * @since  1.5
 242.750 -     */
 242.751 -    public int codePointCount(int beginIndex, int endIndex) {
 242.752 -        if (beginIndex < 0 || endIndex > length() || beginIndex > endIndex) {
 242.753 -            throw new IndexOutOfBoundsException();
 242.754 -        }
 242.755 -        return Character.codePointCountImpl(toCharArray(), offset()+beginIndex, endIndex-beginIndex);
 242.756 -    }
 242.757 -
 242.758 -    /**
 242.759 -     * Returns the index within this <code>String</code> that is
 242.760 -     * offset from the given <code>index</code> by
 242.761 -     * <code>codePointOffset</code> code points. Unpaired surrogates
 242.762 -     * within the text range given by <code>index</code> and
 242.763 -     * <code>codePointOffset</code> count as one code point each.
 242.764 -     *
 242.765 -     * @param index the index to be offset
 242.766 -     * @param codePointOffset the offset in code points
 242.767 -     * @return the index within this <code>String</code>
 242.768 -     * @exception IndexOutOfBoundsException if <code>index</code>
 242.769 -     *   is negative or larger then the length of this
 242.770 -     *   <code>String</code>, or if <code>codePointOffset</code> is positive
 242.771 -     *   and the substring starting with <code>index</code> has fewer
 242.772 -     *   than <code>codePointOffset</code> code points,
 242.773 -     *   or if <code>codePointOffset</code> is negative and the substring
 242.774 -     *   before <code>index</code> has fewer than the absolute value
 242.775 -     *   of <code>codePointOffset</code> code points.
 242.776 -     * @since 1.5
 242.777 -     */
 242.778 -    public int offsetByCodePoints(int index, int codePointOffset) {
 242.779 -        if (index < 0 || index > length()) {
 242.780 -            throw new IndexOutOfBoundsException();
 242.781 -        }
 242.782 -        return Character.offsetByCodePointsImpl(toCharArray(), offset(), length(),
 242.783 -                                                offset()+index, codePointOffset) - offset();
 242.784 -    }
 242.785 -
 242.786 -    /**
 242.787 -     * Copy characters from this string into dst starting at dstBegin.
 242.788 -     * This method doesn't perform any range checking.
 242.789 -     */
 242.790 -    @JavaScriptBody(args = { "self", "arr", "to" }, body = 
 242.791 -        "var s = self.toString();\n" +
 242.792 -        "for (var i = 0; i < s.length; i++) {\n" +
 242.793 -        "   arr[to++] = s[i];\n" +
 242.794 -        "}"
 242.795 -    )
 242.796 -    void getChars(char dst[], int dstBegin) {
 242.797 -        AbstractStringBuilder.arraycopy(toCharArray(), offset(), dst, dstBegin, length());
 242.798 -    }
 242.799 -
 242.800 -    /**
 242.801 -     * Copies characters from this string into the destination character
 242.802 -     * array.
 242.803 -     * <p>
 242.804 -     * The first character to be copied is at index <code>srcBegin</code>;
 242.805 -     * the last character to be copied is at index <code>srcEnd-1</code>
 242.806 -     * (thus the total number of characters to be copied is
 242.807 -     * <code>srcEnd-srcBegin</code>). The characters are copied into the
 242.808 -     * subarray of <code>dst</code> starting at index <code>dstBegin</code>
 242.809 -     * and ending at index:
 242.810 -     * <p><blockquote><pre>
 242.811 -     *     dstbegin + (srcEnd-srcBegin) - 1
 242.812 -     * </pre></blockquote>
 242.813 -     *
 242.814 -     * @param      srcBegin   index of the first character in the string
 242.815 -     *                        to copy.
 242.816 -     * @param      srcEnd     index after the last character in the string
 242.817 -     *                        to copy.
 242.818 -     * @param      dst        the destination array.
 242.819 -     * @param      dstBegin   the start offset in the destination array.
 242.820 -     * @exception IndexOutOfBoundsException If any of the following
 242.821 -     *            is true:
 242.822 -     *            <ul><li><code>srcBegin</code> is negative.
 242.823 -     *            <li><code>srcBegin</code> is greater than <code>srcEnd</code>
 242.824 -     *            <li><code>srcEnd</code> is greater than the length of this
 242.825 -     *                string
 242.826 -     *            <li><code>dstBegin</code> is negative
 242.827 -     *            <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
 242.828 -     *                <code>dst.length</code></ul>
 242.829 -     */
 242.830 -    @JavaScriptBody(args = { "self", "beg", "end", "arr", "dst" }, body=
 242.831 -        "var s = self.toString();\n" +
 242.832 -        "while (beg < end) {\n" +
 242.833 -        "  arr[dst++] = s[beg++];\n" +
 242.834 -        "}\n"
 242.835 -    )
 242.836 -    public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
 242.837 -        if (srcBegin < 0) {
 242.838 -            throw new StringIndexOutOfBoundsException(srcBegin);
 242.839 -        }
 242.840 -        if (srcEnd > length()) {
 242.841 -            throw new StringIndexOutOfBoundsException(srcEnd);
 242.842 -        }
 242.843 -        if (srcBegin > srcEnd) {
 242.844 -            throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
 242.845 -        }
 242.846 -        AbstractStringBuilder.arraycopy(toCharArray(), offset() + srcBegin, dst, dstBegin,
 242.847 -             srcEnd - srcBegin);
 242.848 -    }
 242.849 -
 242.850 -    /**
 242.851 -     * Copies characters from this string into the destination byte array. Each
 242.852 -     * byte receives the 8 low-order bits of the corresponding character. The
 242.853 -     * eight high-order bits of each character are not copied and do not
 242.854 -     * participate in the transfer in any way.
 242.855 -     *
 242.856 -     * <p> The first character to be copied is at index {@code srcBegin}; the
 242.857 -     * last character to be copied is at index {@code srcEnd-1}.  The total
 242.858 -     * number of characters to be copied is {@code srcEnd-srcBegin}. The
 242.859 -     * characters, converted to bytes, are copied into the subarray of {@code
 242.860 -     * dst} starting at index {@code dstBegin} and ending at index:
 242.861 -     *
 242.862 -     * <blockquote><pre>
 242.863 -     *     dstbegin + (srcEnd-srcBegin) - 1
 242.864 -     * </pre></blockquote>
 242.865 -     *
 242.866 -     * @deprecated  This method does not properly convert characters into
 242.867 -     * bytes.  As of JDK&nbsp;1.1, the preferred way to do this is via the
 242.868 -     * {@link #getBytes()} method, which uses the platform's default charset.
 242.869 -     *
 242.870 -     * @param  srcBegin
 242.871 -     *         Index of the first character in the string to copy
 242.872 -     *
 242.873 -     * @param  srcEnd
 242.874 -     *         Index after the last character in the string to copy
 242.875 -     *
 242.876 -     * @param  dst
 242.877 -     *         The destination array
 242.878 -     *
 242.879 -     * @param  dstBegin
 242.880 -     *         The start offset in the destination array
 242.881 -     *
 242.882 -     * @throws  IndexOutOfBoundsException
 242.883 -     *          If any of the following is true:
 242.884 -     *          <ul>
 242.885 -     *            <li> {@code srcBegin} is negative
 242.886 -     *            <li> {@code srcBegin} is greater than {@code srcEnd}
 242.887 -     *            <li> {@code srcEnd} is greater than the length of this String
 242.888 -     *            <li> {@code dstBegin} is negative
 242.889 -     *            <li> {@code dstBegin+(srcEnd-srcBegin)} is larger than {@code
 242.890 -     *                 dst.length}
 242.891 -     *          </ul>
 242.892 -     */
 242.893 -    @Deprecated
 242.894 -    public void getBytes(int srcBegin, int srcEnd, byte dst[], int dstBegin) {
 242.895 -        if (srcBegin < 0) {
 242.896 -            throw new StringIndexOutOfBoundsException(srcBegin);
 242.897 -        }
 242.898 -        if (srcEnd > length()) {
 242.899 -            throw new StringIndexOutOfBoundsException(srcEnd);
 242.900 -        }
 242.901 -        if (srcBegin > srcEnd) {
 242.902 -            throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
 242.903 -        }
 242.904 -        int j = dstBegin;
 242.905 -        int n = offset() + srcEnd;
 242.906 -        int i = offset() + srcBegin;
 242.907 -        char[] val = toCharArray();   /* avoid getfield opcode */
 242.908 -
 242.909 -        while (i < n) {
 242.910 -            dst[j++] = (byte)val[i++];
 242.911 -        }
 242.912 -    }
 242.913 -
 242.914 -    /**
 242.915 -     * Encodes this {@code String} into a sequence of bytes using the named
 242.916 -     * charset, storing the result into a new byte array.
 242.917 -     *
 242.918 -     * <p> The behavior of this method when this string cannot be encoded in
 242.919 -     * the given charset is unspecified.  The {@link
 242.920 -     * java.nio.charset.CharsetEncoder} class should be used when more control
 242.921 -     * over the encoding process is required.
 242.922 -     *
 242.923 -     * @param  charsetName
 242.924 -     *         The name of a supported {@linkplain java.nio.charset.Charset
 242.925 -     *         charset}
 242.926 -     *
 242.927 -     * @return  The resultant byte array
 242.928 -     *
 242.929 -     * @throws  UnsupportedEncodingException
 242.930 -     *          If the named charset is not supported
 242.931 -     *
 242.932 -     * @since  JDK1.1
 242.933 -     */
 242.934 -//    public byte[] getBytes(String charsetName)
 242.935 -//        throws UnsupportedEncodingException
 242.936 -//    {
 242.937 -//        if (charsetName == null) throw new NullPointerException();
 242.938 -//        return StringCoding.encode(charsetName, value, offset, count);
 242.939 -//    }
 242.940 -
 242.941 -    /**
 242.942 -     * Encodes this {@code String} into a sequence of bytes using the given
 242.943 -     * {@linkplain java.nio.charset.Charset charset}, storing the result into a
 242.944 -     * new byte array.
 242.945 -     *
 242.946 -     * <p> This method always replaces malformed-input and unmappable-character
 242.947 -     * sequences with this charset's default replacement byte array.  The
 242.948 -     * {@link java.nio.charset.CharsetEncoder} class should be used when more
 242.949 -     * control over the encoding process is required.
 242.950 -     *
 242.951 -     * @param  charset
 242.952 -     *         The {@linkplain java.nio.charset.Charset} to be used to encode
 242.953 -     *         the {@code String}
 242.954 -     *
 242.955 -     * @return  The resultant byte array
 242.956 -     *
 242.957 -     * @since  1.6
 242.958 -     */
 242.959 -    /* don't want dep on Charset
 242.960 -    public byte[] getBytes(Charset charset) {
 242.961 -        if (charset == null) throw new NullPointerException();
 242.962 -        return StringCoding.encode(charset, value, offset, count);
 242.963 -    }
 242.964 -    */
 242.965 -
 242.966 -    /**
 242.967 -     * Encodes this {@code String} into a sequence of bytes using the
 242.968 -     * platform's default charset, storing the result into a new byte array.
 242.969 -     *
 242.970 -     * <p> The behavior of this method when this string cannot be encoded in
 242.971 -     * the default charset is unspecified.  The {@link
 242.972 -     * java.nio.charset.CharsetEncoder} class should be used when more control
 242.973 -     * over the encoding process is required.
 242.974 -     *
 242.975 -     * @return  The resultant byte array
 242.976 -     *
 242.977 -     * @since      JDK1.1
 242.978 -     */
 242.979 -    public byte[] getBytes() {
 242.980 -        byte[] arr = new byte[length()];
 242.981 -        for (int i = 0; i < arr.length; i++) {
 242.982 -            final char v = charAt(i);
 242.983 -            arr[i] = (byte)v;
 242.984 -        }
 242.985 -        return arr;
 242.986 -    }
 242.987 -
 242.988 -    /**
 242.989 -     * Compares this string to the specified object.  The result is {@code
 242.990 -     * true} if and only if the argument is not {@code null} and is a {@code
 242.991 -     * String} object that represents the same sequence of characters as this
 242.992 -     * object.
 242.993 -     *
 242.994 -     * @param  anObject
 242.995 -     *         The object to compare this {@code String} against
 242.996 -     *
 242.997 -     * @return  {@code true} if the given object represents a {@code String}
 242.998 -     *          equivalent to this string, {@code false} otherwise
 242.999 -     *
242.1000 -     * @see  #compareTo(String)
242.1001 -     * @see  #equalsIgnoreCase(String)
242.1002 -     */
242.1003 -    @JavaScriptBody(args = { "self", "obj" }, body = 
242.1004 -        "return obj.$instOf_java_lang_String && "
242.1005 -        + "self.toString() === obj.toString();"
242.1006 -    )
242.1007 -    public boolean equals(Object anObject) {
242.1008 -        if (this == anObject) {
242.1009 -            return true;
242.1010 -        }
242.1011 -        if (anObject instanceof String) {
242.1012 -            String anotherString = (String)anObject;
242.1013 -            int n = length();
242.1014 -            if (n == anotherString.length()) {
242.1015 -                char v1[] = toCharArray();
242.1016 -                char v2[] = anotherString.toCharArray();
242.1017 -                int i = offset();
242.1018 -                int j = anotherString.offset();
242.1019 -                while (n-- != 0) {
242.1020 -                    if (v1[i++] != v2[j++])
242.1021 -                        return false;
242.1022 -                }
242.1023 -                return true;
242.1024 -            }
242.1025 -        }
242.1026 -        return false;
242.1027 -    }
242.1028 -
242.1029 -    /**
242.1030 -     * Compares this string to the specified {@code StringBuffer}.  The result
242.1031 -     * is {@code true} if and only if this {@code String} represents the same
242.1032 -     * sequence of characters as the specified {@code StringBuffer}.
242.1033 -     *
242.1034 -     * @param  sb
242.1035 -     *         The {@code StringBuffer} to compare this {@code String} against
242.1036 -     *
242.1037 -     * @return  {@code true} if this {@code String} represents the same
242.1038 -     *          sequence of characters as the specified {@code StringBuffer},
242.1039 -     *          {@code false} otherwise
242.1040 -     *
242.1041 -     * @since  1.4
242.1042 -     */
242.1043 -    public boolean contentEquals(StringBuffer sb) {
242.1044 -        synchronized(sb) {
242.1045 -            return contentEquals((CharSequence)sb);
242.1046 -        }
242.1047 -    }
242.1048 -
242.1049 -    /**
242.1050 -     * Compares this string to the specified {@code CharSequence}.  The result
242.1051 -     * is {@code true} if and only if this {@code String} represents the same
242.1052 -     * sequence of char values as the specified sequence.
242.1053 -     *
242.1054 -     * @param  cs
242.1055 -     *         The sequence to compare this {@code String} against
242.1056 -     *
242.1057 -     * @return  {@code true} if this {@code String} represents the same
242.1058 -     *          sequence of char values as the specified sequence, {@code
242.1059 -     *          false} otherwise
242.1060 -     *
242.1061 -     * @since  1.5
242.1062 -     */
242.1063 -    public boolean contentEquals(CharSequence cs) {
242.1064 -        if (length() != cs.length())
242.1065 -            return false;
242.1066 -        // Argument is a StringBuffer, StringBuilder
242.1067 -        if (cs instanceof AbstractStringBuilder) {
242.1068 -            char v1[] = toCharArray();
242.1069 -            char v2[] = ((AbstractStringBuilder)cs).getValue();
242.1070 -            int i = offset();
242.1071 -            int j = 0;
242.1072 -            int n = length();
242.1073 -            while (n-- != 0) {
242.1074 -                if (v1[i++] != v2[j++])
242.1075 -                    return false;
242.1076 -            }
242.1077 -            return true;
242.1078 -        }
242.1079 -        // Argument is a String
242.1080 -        if (cs.equals(this))
242.1081 -            return true;
242.1082 -        // Argument is a generic CharSequence
242.1083 -        char v1[] = toCharArray();
242.1084 -        int i = offset();
242.1085 -        int j = 0;
242.1086 -        int n = length();
242.1087 -        while (n-- != 0) {
242.1088 -            if (v1[i++] != cs.charAt(j++))
242.1089 -                return false;
242.1090 -        }
242.1091 -        return true;
242.1092 -    }
242.1093 -
242.1094 -    /**
242.1095 -     * Compares this {@code String} to another {@code String}, ignoring case
242.1096 -     * considerations.  Two strings are considered equal ignoring case if they
242.1097 -     * are of the same length and corresponding characters in the two strings
242.1098 -     * are equal ignoring case.
242.1099 -     *
242.1100 -     * <p> Two characters {@code c1} and {@code c2} are considered the same
242.1101 -     * ignoring case if at least one of the following is true:
242.1102 -     * <ul>
242.1103 -     *   <li> The two characters are the same (as compared by the
242.1104 -     *        {@code ==} operator)
242.1105 -     *   <li> Applying the method {@link
242.1106 -     *        java.lang.Character#toUpperCase(char)} to each character
242.1107 -     *        produces the same result
242.1108 -     *   <li> Applying the method {@link
242.1109 -     *        java.lang.Character#toLowerCase(char)} to each character
242.1110 -     *        produces the same result
242.1111 -     * </ul>
242.1112 -     *
242.1113 -     * @param  anotherString
242.1114 -     *         The {@code String} to compare this {@code String} against
242.1115 -     *
242.1116 -     * @return  {@code true} if the argument is not {@code null} and it
242.1117 -     *          represents an equivalent {@code String} ignoring case; {@code
242.1118 -     *          false} otherwise
242.1119 -     *
242.1120 -     * @see  #equals(Object)
242.1121 -     */
242.1122 -    public boolean equalsIgnoreCase(String anotherString) {
242.1123 -        return (this == anotherString) ? true :
242.1124 -               (anotherString != null) && (anotherString.length() == length()) &&
242.1125 -               regionMatches(true, 0, anotherString, 0, length());
242.1126 -    }
242.1127 -
242.1128 -    /**
242.1129 -     * Compares two strings lexicographically.
242.1130 -     * The comparison is based on the Unicode value of each character in
242.1131 -     * the strings. The character sequence represented by this
242.1132 -     * <code>String</code> object is compared lexicographically to the
242.1133 -     * character sequence represented by the argument string. The result is
242.1134 -     * a negative integer if this <code>String</code> object
242.1135 -     * lexicographically precedes the argument string. The result is a
242.1136 -     * positive integer if this <code>String</code> object lexicographically
242.1137 -     * follows the argument string. The result is zero if the strings
242.1138 -     * are equal; <code>compareTo</code> returns <code>0</code> exactly when
242.1139 -     * the {@link #equals(Object)} method would return <code>true</code>.
242.1140 -     * <p>
242.1141 -     * This is the definition of lexicographic ordering. If two strings are
242.1142 -     * different, then either they have different characters at some index
242.1143 -     * that is a valid index for both strings, or their lengths are different,
242.1144 -     * or both. If they have different characters at one or more index
242.1145 -     * positions, let <i>k</i> be the smallest such index; then the string
242.1146 -     * whose character at position <i>k</i> has the smaller value, as
242.1147 -     * determined by using the &lt; operator, lexicographically precedes the
242.1148 -     * other string. In this case, <code>compareTo</code> returns the
242.1149 -     * difference of the two character values at position <code>k</code> in
242.1150 -     * the two string -- that is, the value:
242.1151 -     * <blockquote><pre>
242.1152 -     * this.charAt(k)-anotherString.charAt(k)
242.1153 -     * </pre></blockquote>
242.1154 -     * If there is no index position at which they differ, then the shorter
242.1155 -     * string lexicographically precedes the longer string. In this case,
242.1156 -     * <code>compareTo</code> returns the difference of the lengths of the
242.1157 -     * strings -- that is, the value:
242.1158 -     * <blockquote><pre>
242.1159 -     * this.length()-anotherString.length()
242.1160 -     * </pre></blockquote>
242.1161 -     *
242.1162 -     * @param   anotherString   the <code>String</code> to be compared.
242.1163 -     * @return  the value <code>0</code> if the argument string is equal to
242.1164 -     *          this string; a value less than <code>0</code> if this string
242.1165 -     *          is lexicographically less than the string argument; and a
242.1166 -     *          value greater than <code>0</code> if this string is
242.1167 -     *          lexicographically greater than the string argument.
242.1168 -     */
242.1169 -    public int compareTo(String anotherString) {
242.1170 -        int len1 = length();
242.1171 -        int len2 = anotherString.length();
242.1172 -        int n = Math.min(len1, len2);
242.1173 -        char v1[] = toCharArray();
242.1174 -        char v2[] = anotherString.toCharArray();
242.1175 -        int i = offset();
242.1176 -        int j = anotherString.offset();
242.1177 -
242.1178 -        if (i == j) {
242.1179 -            int k = i;
242.1180 -            int lim = n + i;
242.1181 -            while (k < lim) {
242.1182 -                char c1 = v1[k];
242.1183 -                char c2 = v2[k];
242.1184 -                if (c1 != c2) {
242.1185 -                    return c1 - c2;
242.1186 -                }
242.1187 -                k++;
242.1188 -            }
242.1189 -        } else {
242.1190 -            while (n-- != 0) {
242.1191 -                char c1 = v1[i++];
242.1192 -                char c2 = v2[j++];
242.1193 -                if (c1 != c2) {
242.1194 -                    return c1 - c2;
242.1195 -                }
242.1196 -            }
242.1197 -        }
242.1198 -        return len1 - len2;
242.1199 -    }
242.1200 -
242.1201 -    /**
242.1202 -     * A Comparator that orders <code>String</code> objects as by
242.1203 -     * <code>compareToIgnoreCase</code>. This comparator is serializable.
242.1204 -     * <p>
242.1205 -     * Note that this Comparator does <em>not</em> take locale into account,
242.1206 -     * and will result in an unsatisfactory ordering for certain locales.
242.1207 -     * The java.text package provides <em>Collators</em> to allow
242.1208 -     * locale-sensitive ordering.
242.1209 -     *
242.1210 -     * @see     java.text.Collator#compare(String, String)
242.1211 -     * @since   1.2
242.1212 -     */
242.1213 -    public static final Comparator<String> CASE_INSENSITIVE_ORDER
242.1214 -                                         = new CaseInsensitiveComparator();
242.1215 -
242.1216 -    private static int offset() {
242.1217 -        return 0;
242.1218 -    }
242.1219 -    
242.1220 -    private static class CaseInsensitiveComparator
242.1221 -                         implements Comparator<String>, java.io.Serializable {
242.1222 -        // use serialVersionUID from JDK 1.2.2 for interoperability
242.1223 -        private static final long serialVersionUID = 8575799808933029326L;
242.1224 -
242.1225 -        public int compare(String s1, String s2) {
242.1226 -            int n1 = s1.length();
242.1227 -            int n2 = s2.length();
242.1228 -            int min = Math.min(n1, n2);
242.1229 -            for (int i = 0; i < min; i++) {
242.1230 -                char c1 = s1.charAt(i);
242.1231 -                char c2 = s2.charAt(i);
242.1232 -                if (c1 != c2) {
242.1233 -                    c1 = Character.toUpperCase(c1);
242.1234 -                    c2 = Character.toUpperCase(c2);
242.1235 -                    if (c1 != c2) {
242.1236 -                        c1 = Character.toLowerCase(c1);
242.1237 -                        c2 = Character.toLowerCase(c2);
242.1238 -                        if (c1 != c2) {
242.1239 -                            // No overflow because of numeric promotion
242.1240 -                            return c1 - c2;
242.1241 -                        }
242.1242 -                    }
242.1243 -                }
242.1244 -            }
242.1245 -            return n1 - n2;
242.1246 -        }
242.1247 -    }
242.1248 -
242.1249 -    /**
242.1250 -     * Compares two strings lexicographically, ignoring case
242.1251 -     * differences. This method returns an integer whose sign is that of
242.1252 -     * calling <code>compareTo</code> with normalized versions of the strings
242.1253 -     * where case differences have been eliminated by calling
242.1254 -     * <code>Character.toLowerCase(Character.toUpperCase(character))</code> on
242.1255 -     * each character.
242.1256 -     * <p>
242.1257 -     * Note that this method does <em>not</em> take locale into account,
242.1258 -     * and will result in an unsatisfactory ordering for certain locales.
242.1259 -     * The java.text package provides <em>collators</em> to allow
242.1260 -     * locale-sensitive ordering.
242.1261 -     *
242.1262 -     * @param   str   the <code>String</code> to be compared.
242.1263 -     * @return  a negative integer, zero, or a positive integer as the
242.1264 -     *          specified String is greater than, equal to, or less
242.1265 -     *          than this String, ignoring case considerations.
242.1266 -     * @see     java.text.Collator#compare(String, String)
242.1267 -     * @since   1.2
242.1268 -     */
242.1269 -    public int compareToIgnoreCase(String str) {
242.1270 -        return CASE_INSENSITIVE_ORDER.compare(this, str);
242.1271 -    }
242.1272 -
242.1273 -    /**
242.1274 -     * Tests if two string regions are equal.
242.1275 -     * <p>
242.1276 -     * A substring of this <tt>String</tt> object is compared to a substring
242.1277 -     * of the argument other. The result is true if these substrings
242.1278 -     * represent identical character sequences. The substring of this
242.1279 -     * <tt>String</tt> object to be compared begins at index <tt>toffset</tt>
242.1280 -     * and has length <tt>len</tt>. The substring of other to be compared
242.1281 -     * begins at index <tt>ooffset</tt> and has length <tt>len</tt>. The
242.1282 -     * result is <tt>false</tt> if and only if at least one of the following
242.1283 -     * is true:
242.1284 -     * <ul><li><tt>toffset</tt> is negative.
242.1285 -     * <li><tt>ooffset</tt> is negative.
242.1286 -     * <li><tt>toffset+len</tt> is greater than the length of this
242.1287 -     * <tt>String</tt> object.
242.1288 -     * <li><tt>ooffset+len</tt> is greater than the length of the other
242.1289 -     * argument.
242.1290 -     * <li>There is some nonnegative integer <i>k</i> less than <tt>len</tt>
242.1291 -     * such that:
242.1292 -     * <tt>this.charAt(toffset+<i>k</i>)&nbsp;!=&nbsp;other.charAt(ooffset+<i>k</i>)</tt>
242.1293 -     * </ul>
242.1294 -     *
242.1295 -     * @param   toffset   the starting offset of the subregion in this string.
242.1296 -     * @param   other     the string argument.
242.1297 -     * @param   ooffset   the starting offset of the subregion in the string
242.1298 -     *                    argument.
242.1299 -     * @param   len       the number of characters to compare.
242.1300 -     * @return  <code>true</code> if the specified subregion of this string
242.1301 -     *          exactly matches the specified subregion of the string argument;
242.1302 -     *          <code>false</code> otherwise.
242.1303 -     */
242.1304 -    public boolean regionMatches(int toffset, String other, int ooffset,
242.1305 -                                 int len) {
242.1306 -        char ta[] = toCharArray();
242.1307 -        int to = offset() + toffset;
242.1308 -        char pa[] = other.toCharArray();
242.1309 -        int po = other.offset() + ooffset;
242.1310 -        // Note: toffset, ooffset, or len might be near -1>>>1.
242.1311 -        if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len)
242.1312 -            || (ooffset > (long)other.length() - len)) {
242.1313 -            return false;
242.1314 -        }
242.1315 -        while (len-- > 0) {
242.1316 -            if (ta[to++] != pa[po++]) {
242.1317 -                return false;
242.1318 -            }
242.1319 -        }
242.1320 -        return true;
242.1321 -    }
242.1322 -
242.1323 -    /**
242.1324 -     * Tests if two string regions are equal.
242.1325 -     * <p>
242.1326 -     * A substring of this <tt>String</tt> object is compared to a substring
242.1327 -     * of the argument <tt>other</tt>. The result is <tt>true</tt> if these
242.1328 -     * substrings represent character sequences that are the same, ignoring
242.1329 -     * case if and only if <tt>ignoreCase</tt> is true. The substring of
242.1330 -     * this <tt>String</tt> object to be compared begins at index
242.1331 -     * <tt>toffset</tt> and has length <tt>len</tt>. The substring of
242.1332 -     * <tt>other</tt> to be compared begins at index <tt>ooffset</tt> and
242.1333 -     * has length <tt>len</tt>. The result is <tt>false</tt> if and only if
242.1334 -     * at least one of the following is true:
242.1335 -     * <ul><li><tt>toffset</tt> is negative.
242.1336 -     * <li><tt>ooffset</tt> is negative.
242.1337 -     * <li><tt>toffset+len</tt> is greater than the length of this
242.1338 -     * <tt>String</tt> object.
242.1339 -     * <li><tt>ooffset+len</tt> is greater than the length of the other
242.1340 -     * argument.
242.1341 -     * <li><tt>ignoreCase</tt> is <tt>false</tt> and there is some nonnegative
242.1342 -     * integer <i>k</i> less than <tt>len</tt> such that:
242.1343 -     * <blockquote><pre>
242.1344 -     * this.charAt(toffset+k) != other.charAt(ooffset+k)
242.1345 -     * </pre></blockquote>
242.1346 -     * <li><tt>ignoreCase</tt> is <tt>true</tt> and there is some nonnegative
242.1347 -     * integer <i>k</i> less than <tt>len</tt> such that:
242.1348 -     * <blockquote><pre>
242.1349 -     * Character.toLowerCase(this.charAt(toffset+k)) !=
242.1350 -               Character.toLowerCase(other.charAt(ooffset+k))
242.1351 -     * </pre></blockquote>
242.1352 -     * and:
242.1353 -     * <blockquote><pre>
242.1354 -     * Character.toUpperCase(this.charAt(toffset+k)) !=
242.1355 -     *         Character.toUpperCase(other.charAt(ooffset+k))
242.1356 -     * </pre></blockquote>
242.1357 -     * </ul>
242.1358 -     *
242.1359 -     * @param   ignoreCase   if <code>true</code>, ignore case when comparing
242.1360 -     *                       characters.
242.1361 -     * @param   toffset      the starting offset of the subregion in this
242.1362 -     *                       string.
242.1363 -     * @param   other        the string argument.
242.1364 -     * @param   ooffset      the starting offset of the subregion in the string
242.1365 -     *                       argument.
242.1366 -     * @param   len          the number of characters to compare.
242.1367 -     * @return  <code>true</code> if the specified subregion of this string
242.1368 -     *          matches the specified subregion of the string argument;
242.1369 -     *          <code>false</code> otherwise. Whether the matching is exact
242.1370 -     *          or case insensitive depends on the <code>ignoreCase</code>
242.1371 -     *          argument.
242.1372 -     */
242.1373 -    public boolean regionMatches(boolean ignoreCase, int toffset,
242.1374 -                           String other, int ooffset, int len) {
242.1375 -        char ta[] = toCharArray();
242.1376 -        int to = offset() + toffset;
242.1377 -        char pa[] = other.toCharArray();
242.1378 -        int po = other.offset() + ooffset;
242.1379 -        // Note: toffset, ooffset, or len might be near -1>>>1.
242.1380 -        if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len) ||
242.1381 -                (ooffset > (long)other.length() - len)) {
242.1382 -            return false;
242.1383 -        }
242.1384 -        while (len-- > 0) {
242.1385 -            char c1 = ta[to++];
242.1386 -            char c2 = pa[po++];
242.1387 -            if (c1 == c2) {
242.1388 -                continue;
242.1389 -            }
242.1390 -            if (ignoreCase) {
242.1391 -                // If characters don't match but case may be ignored,
242.1392 -                // try converting both characters to uppercase.
242.1393 -                // If the results match, then the comparison scan should
242.1394 -                // continue.
242.1395 -                char u1 = Character.toUpperCase(c1);
242.1396 -                char u2 = Character.toUpperCase(c2);
242.1397 -                if (u1 == u2) {
242.1398 -                    continue;
242.1399 -                }
242.1400 -                // Unfortunately, conversion to uppercase does not work properly
242.1401 -                // for the Georgian alphabet, which has strange rules about case
242.1402 -                // conversion.  So we need to make one last check before
242.1403 -                // exiting.
242.1404 -                if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
242.1405 -                    continue;
242.1406 -                }
242.1407 -            }
242.1408 -            return false;
242.1409 -        }
242.1410 -        return true;
242.1411 -    }
242.1412 -
242.1413 -    /**
242.1414 -     * Tests if the substring of this string beginning at the
242.1415 -     * specified index starts with the specified prefix.
242.1416 -     *
242.1417 -     * @param   prefix    the prefix.
242.1418 -     * @param   toffset   where to begin looking in this string.
242.1419 -     * @return  <code>true</code> if the character sequence represented by the
242.1420 -     *          argument is a prefix of the substring of this object starting
242.1421 -     *          at index <code>toffset</code>; <code>false</code> otherwise.
242.1422 -     *          The result is <code>false</code> if <code>toffset</code> is
242.1423 -     *          negative or greater than the length of this
242.1424 -     *          <code>String</code> object; otherwise the result is the same
242.1425 -     *          as the result of the expression
242.1426 -     *          <pre>
242.1427 -     *          this.substring(toffset).startsWith(prefix)
242.1428 -     *          </pre>
242.1429 -     */
242.1430 -    @JavaScriptBody(args = { "self", "find", "from" }, body=
242.1431 -        "find = find.toString();\n" +
242.1432 -        "return self.toString().substring(from, find.length) === find;\n"
242.1433 -    )
242.1434 -    public boolean startsWith(String prefix, int toffset) {
242.1435 -        char ta[] = toCharArray();
242.1436 -        int to = offset() + toffset;
242.1437 -        char pa[] = prefix.toCharArray();
242.1438 -        int po = prefix.offset();
242.1439 -        int pc = prefix.length();
242.1440 -        // Note: toffset might be near -1>>>1.
242.1441 -        if ((toffset < 0) || (toffset > length() - pc)) {
242.1442 -            return false;
242.1443 -        }
242.1444 -        while (--pc >= 0) {
242.1445 -            if (ta[to++] != pa[po++]) {
242.1446 -                return false;
242.1447 -            }
242.1448 -        }
242.1449 -        return true;
242.1450 -    }
242.1451 -
242.1452 -    /**
242.1453 -     * Tests if this string starts with the specified prefix.
242.1454 -     *
242.1455 -     * @param   prefix   the prefix.
242.1456 -     * @return  <code>true</code> if the character sequence represented by the
242.1457 -     *          argument is a prefix of the character sequence represented by
242.1458 -     *          this string; <code>false</code> otherwise.
242.1459 -     *          Note also that <code>true</code> will be returned if the
242.1460 -     *          argument is an empty string or is equal to this
242.1461 -     *          <code>String</code> object as determined by the
242.1462 -     *          {@link #equals(Object)} method.
242.1463 -     * @since   1. 0
242.1464 -     */
242.1465 -    public boolean startsWith(String prefix) {
242.1466 -        return startsWith(prefix, 0);
242.1467 -    }
242.1468 -
242.1469 -    /**
242.1470 -     * Tests if this string ends with the specified suffix.
242.1471 -     *
242.1472 -     * @param   suffix   the suffix.
242.1473 -     * @return  <code>true</code> if the character sequence represented by the
242.1474 -     *          argument is a suffix of the character sequence represented by
242.1475 -     *          this object; <code>false</code> otherwise. Note that the
242.1476 -     *          result will be <code>true</code> if the argument is the
242.1477 -     *          empty string or is equal to this <code>String</code> object
242.1478 -     *          as determined by the {@link #equals(Object)} method.
242.1479 -     */
242.1480 -    public boolean endsWith(String suffix) {
242.1481 -        return startsWith(suffix, length() - suffix.length());
242.1482 -    }
242.1483 -
242.1484 -    /**
242.1485 -     * Returns a hash code for this string. The hash code for a
242.1486 -     * <code>String</code> object is computed as
242.1487 -     * <blockquote><pre>
242.1488 -     * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
242.1489 -     * </pre></blockquote>
242.1490 -     * using <code>int</code> arithmetic, where <code>s[i]</code> is the
242.1491 -     * <i>i</i>th character of the string, <code>n</code> is the length of
242.1492 -     * the string, and <code>^</code> indicates exponentiation.
242.1493 -     * (The hash value of the empty string is zero.)
242.1494 -     *
242.1495 -     * @return  a hash code value for this object.
242.1496 -     */
242.1497 -    @JavaScriptBody(args = "self", body = 
242.1498 -        "var h = 0;\n" +
242.1499 -        "var s = self.toString();\n" +
242.1500 -        "for (var i = 0; i < s.length; i++) {\n" +
242.1501 -        "  var high = (h >> 16) & 0xffff, low = h & 0xffff;\n" +
242.1502 -        "  h = (((((31 * high) & 0xffff) << 16) >>> 0) + (31 * low) + s.charCodeAt(i)) & 0xffffffff;\n" +
242.1503 -        "}\n" +
242.1504 -        "return h;\n"
242.1505 -    )
242.1506 -    public int hashCode() {
242.1507 -        int h = hash;
242.1508 -        if (h == 0 && length() > 0) {
242.1509 -            int off = offset();
242.1510 -            char val[] = toCharArray();
242.1511 -            int len = length();
242.1512 -
242.1513 -            for (int i = 0; i < len; i++) {
242.1514 -                h = 31*h + val[off++];
242.1515 -            }
242.1516 -            hash = h;
242.1517 -        }
242.1518 -        return h;
242.1519 -    }
242.1520 -
242.1521 -    /**
242.1522 -     * Returns the index within this string of the first occurrence of
242.1523 -     * the specified character. If a character with value
242.1524 -     * <code>ch</code> occurs in the character sequence represented by
242.1525 -     * this <code>String</code> object, then the index (in Unicode
242.1526 -     * code units) of the first such occurrence is returned. For
242.1527 -     * values of <code>ch</code> in the range from 0 to 0xFFFF
242.1528 -     * (inclusive), this is the smallest value <i>k</i> such that:
242.1529 -     * <blockquote><pre>
242.1530 -     * this.charAt(<i>k</i>) == ch
242.1531 -     * </pre></blockquote>
242.1532 -     * is true. For other values of <code>ch</code>, it is the
242.1533 -     * smallest value <i>k</i> such that:
242.1534 -     * <blockquote><pre>
242.1535 -     * this.codePointAt(<i>k</i>) == ch
242.1536 -     * </pre></blockquote>
242.1537 -     * is true. In either case, if no such character occurs in this
242.1538 -     * string, then <code>-1</code> is returned.
242.1539 -     *
242.1540 -     * @param   ch   a character (Unicode code point).
242.1541 -     * @return  the index of the first occurrence of the character in the
242.1542 -     *          character sequence represented by this object, or
242.1543 -     *          <code>-1</code> if the character does not occur.
242.1544 -     */
242.1545 -    public int indexOf(int ch) {
242.1546 -        return indexOf(ch, 0);
242.1547 -    }
242.1548 -
242.1549 -    /**
242.1550 -     * Returns the index within this string of the first occurrence of the
242.1551 -     * specified character, starting the search at the specified index.
242.1552 -     * <p>
242.1553 -     * If a character with value <code>ch</code> occurs in the
242.1554 -     * character sequence represented by this <code>String</code>
242.1555 -     * object at an index no smaller than <code>fromIndex</code>, then
242.1556 -     * the index of the first such occurrence is returned. For values
242.1557 -     * of <code>ch</code> in the range from 0 to 0xFFFF (inclusive),
242.1558 -     * this is the smallest value <i>k</i> such that:
242.1559 -     * <blockquote><pre>
242.1560 -     * (this.charAt(<i>k</i>) == ch) && (<i>k</i> &gt;= fromIndex)
242.1561 -     * </pre></blockquote>
242.1562 -     * is true. For other values of <code>ch</code>, it is the
242.1563 -     * smallest value <i>k</i> such that:
242.1564 -     * <blockquote><pre>
242.1565 -     * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> &gt;= fromIndex)
242.1566 -     * </pre></blockquote>
242.1567 -     * is true. In either case, if no such character occurs in this
242.1568 -     * string at or after position <code>fromIndex</code>, then
242.1569 -     * <code>-1</code> is returned.
242.1570 -     *
242.1571 -     * <p>
242.1572 -     * There is no restriction on the value of <code>fromIndex</code>. If it
242.1573 -     * is negative, it has the same effect as if it were zero: this entire
242.1574 -     * string may be searched. If it is greater than the length of this
242.1575 -     * string, it has the same effect as if it were equal to the length of
242.1576 -     * this string: <code>-1</code> is returned.
242.1577 -     *
242.1578 -     * <p>All indices are specified in <code>char</code> values
242.1579 -     * (Unicode code units).
242.1580 -     *
242.1581 -     * @param   ch          a character (Unicode code point).
242.1582 -     * @param   fromIndex   the index to start the search from.
242.1583 -     * @return  the index of the first occurrence of the character in the
242.1584 -     *          character sequence represented by this object that is greater
242.1585 -     *          than or equal to <code>fromIndex</code>, or <code>-1</code>
242.1586 -     *          if the character does not occur.
242.1587 -     */
242.1588 -    @JavaScriptBody(args = { "self", "ch", "from" }, body = 
242.1589 -        "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
242.1590 -        "return self.toString().indexOf(ch, from);\n"
242.1591 -    )
242.1592 -    public int indexOf(int ch, int fromIndex) {
242.1593 -        if (fromIndex < 0) {
242.1594 -            fromIndex = 0;
242.1595 -        } else if (fromIndex >= length()) {
242.1596 -            // Note: fromIndex might be near -1>>>1.
242.1597 -            return -1;
242.1598 -        }
242.1599 -
242.1600 -        if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
242.1601 -            // handle most cases here (ch is a BMP code point or a
242.1602 -            // negative value (invalid code point))
242.1603 -            final char[] value = this.toCharArray();
242.1604 -            final int offset = this.offset();
242.1605 -            final int max = offset + length();
242.1606 -            for (int i = offset + fromIndex; i < max ; i++) {
242.1607 -                if (value[i] == ch) {
242.1608 -                    return i - offset;
242.1609 -                }
242.1610 -            }
242.1611 -            return -1;
242.1612 -        } else {
242.1613 -            return indexOfSupplementary(ch, fromIndex);
242.1614 -        }
242.1615 -    }
242.1616 -
242.1617 -    /**
242.1618 -     * Handles (rare) calls of indexOf with a supplementary character.
242.1619 -     */
242.1620 -    private int indexOfSupplementary(int ch, int fromIndex) {
242.1621 -        if (Character.isValidCodePoint(ch)) {
242.1622 -            final char[] value = this.toCharArray();
242.1623 -            final int offset = this.offset();
242.1624 -            final char hi = Character.highSurrogate(ch);
242.1625 -            final char lo = Character.lowSurrogate(ch);
242.1626 -            final int max = offset + length() - 1;
242.1627 -            for (int i = offset + fromIndex; i < max; i++) {
242.1628 -                if (value[i] == hi && value[i+1] == lo) {
242.1629 -                    return i - offset;
242.1630 -                }
242.1631 -            }
242.1632 -        }
242.1633 -        return -1;
242.1634 -    }
242.1635 -
242.1636 -    /**
242.1637 -     * Returns the index within this string of the last occurrence of
242.1638 -     * the specified character. For values of <code>ch</code> in the
242.1639 -     * range from 0 to 0xFFFF (inclusive), the index (in Unicode code
242.1640 -     * units) returned is the largest value <i>k</i> such that:
242.1641 -     * <blockquote><pre>
242.1642 -     * this.charAt(<i>k</i>) == ch
242.1643 -     * </pre></blockquote>
242.1644 -     * is true. For other values of <code>ch</code>, it is the
242.1645 -     * largest value <i>k</i> such that:
242.1646 -     * <blockquote><pre>
242.1647 -     * this.codePointAt(<i>k</i>) == ch
242.1648 -     * </pre></blockquote>
242.1649 -     * is true.  In either case, if no such character occurs in this
242.1650 -     * string, then <code>-1</code> is returned.  The
242.1651 -     * <code>String</code> is searched backwards starting at the last
242.1652 -     * character.
242.1653 -     *
242.1654 -     * @param   ch   a character (Unicode code point).
242.1655 -     * @return  the index of the last occurrence of the character in the
242.1656 -     *          character sequence represented by this object, or
242.1657 -     *          <code>-1</code> if the character does not occur.
242.1658 -     */
242.1659 -    public int lastIndexOf(int ch) {
242.1660 -        return lastIndexOf(ch, length() - 1);
242.1661 -    }
242.1662 -
242.1663 -    /**
242.1664 -     * Returns the index within this string of the last occurrence of
242.1665 -     * the specified character, searching backward starting at the
242.1666 -     * specified index. For values of <code>ch</code> in the range
242.1667 -     * from 0 to 0xFFFF (inclusive), the index returned is the largest
242.1668 -     * value <i>k</i> such that:
242.1669 -     * <blockquote><pre>
242.1670 -     * (this.charAt(<i>k</i>) == ch) && (<i>k</i> &lt;= fromIndex)
242.1671 -     * </pre></blockquote>
242.1672 -     * is true. For other values of <code>ch</code>, it is the
242.1673 -     * largest value <i>k</i> such that:
242.1674 -     * <blockquote><pre>
242.1675 -     * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> &lt;= fromIndex)
242.1676 -     * </pre></blockquote>
242.1677 -     * is true. In either case, if no such character occurs in this
242.1678 -     * string at or before position <code>fromIndex</code>, then
242.1679 -     * <code>-1</code> is returned.
242.1680 -     *
242.1681 -     * <p>All indices are specified in <code>char</code> values
242.1682 -     * (Unicode code units).
242.1683 -     *
242.1684 -     * @param   ch          a character (Unicode code point).
242.1685 -     * @param   fromIndex   the index to start the search from. There is no
242.1686 -     *          restriction on the value of <code>fromIndex</code>. If it is
242.1687 -     *          greater than or equal to the length of this string, it has
242.1688 -     *          the same effect as if it were equal to one less than the
242.1689 -     *          length of this string: this entire string may be searched.
242.1690 -     *          If it is negative, it has the same effect as if it were -1:
242.1691 -     *          -1 is returned.
242.1692 -     * @return  the index of the last occurrence of the character in the
242.1693 -     *          character sequence represented by this object that is less
242.1694 -     *          than or equal to <code>fromIndex</code>, or <code>-1</code>
242.1695 -     *          if the character does not occur before that point.
242.1696 -     */
242.1697 -    @JavaScriptBody(args = { "self", "ch", "from" }, body = 
242.1698 -        "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
242.1699 -        "return self.toString().lastIndexOf(ch, from);"
242.1700 -    )
242.1701 -    public int lastIndexOf(int ch, int fromIndex) {
242.1702 -        if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
242.1703 -            // handle most cases here (ch is a BMP code point or a
242.1704 -            // negative value (invalid code point))
242.1705 -            final char[] value = this.toCharArray();
242.1706 -            final int offset = this.offset();
242.1707 -            int i = offset + Math.min(fromIndex, length() - 1);
242.1708 -            for (; i >= offset ; i--) {
242.1709 -                if (value[i] == ch) {
242.1710 -                    return i - offset;
242.1711 -                }
242.1712 -            }
242.1713 -            return -1;
242.1714 -        } else {
242.1715 -            return lastIndexOfSupplementary(ch, fromIndex);
242.1716 -        }
242.1717 -    }
242.1718 -
242.1719 -    /**
242.1720 -     * Handles (rare) calls of lastIndexOf with a supplementary character.
242.1721 -     */
242.1722 -    private int lastIndexOfSupplementary(int ch, int fromIndex) {
242.1723 -        if (Character.isValidCodePoint(ch)) {
242.1724 -            final char[] value = this.toCharArray();
242.1725 -            final int offset = this.offset();
242.1726 -            char hi = Character.highSurrogate(ch);
242.1727 -            char lo = Character.lowSurrogate(ch);
242.1728 -            int i = offset + Math.min(fromIndex, length() - 2);
242.1729 -            for (; i >= offset; i--) {
242.1730 -                if (value[i] == hi && value[i+1] == lo) {
242.1731 -                    return i - offset;
242.1732 -                }
242.1733 -            }
242.1734 -        }
242.1735 -        return -1;
242.1736 -    }
242.1737 -
242.1738 -    /**
242.1739 -     * Returns the index within this string of the first occurrence of the
242.1740 -     * specified substring.
242.1741 -     *
242.1742 -     * <p>The returned index is the smallest value <i>k</i> for which:
242.1743 -     * <blockquote><pre>
242.1744 -     * this.startsWith(str, <i>k</i>)
242.1745 -     * </pre></blockquote>
242.1746 -     * If no such value of <i>k</i> exists, then {@code -1} is returned.
242.1747 -     *
242.1748 -     * @param   str   the substring to search for.
242.1749 -     * @return  the index of the first occurrence of the specified substring,
242.1750 -     *          or {@code -1} if there is no such occurrence.
242.1751 -     */
242.1752 -    public int indexOf(String str) {
242.1753 -        return indexOf(str, 0);
242.1754 -    }
242.1755 -
242.1756 -    /**
242.1757 -     * Returns the index within this string of the first occurrence of the
242.1758 -     * specified substring, starting at the specified index.
242.1759 -     *
242.1760 -     * <p>The returned index is the smallest value <i>k</i> for which:
242.1761 -     * <blockquote><pre>
242.1762 -     * <i>k</i> &gt;= fromIndex && this.startsWith(str, <i>k</i>)
242.1763 -     * </pre></blockquote>
242.1764 -     * If no such value of <i>k</i> exists, then {@code -1} is returned.
242.1765 -     *
242.1766 -     * @param   str         the substring to search for.
242.1767 -     * @param   fromIndex   the index from which to start the search.
242.1768 -     * @return  the index of the first occurrence of the specified substring,
242.1769 -     *          starting at the specified index,
242.1770 -     *          or {@code -1} if there is no such occurrence.
242.1771 -     */
242.1772 -    @JavaScriptBody(args = { "self", "str", "fromIndex" }, body =
242.1773 -        "return self.toString().indexOf(str.toString(), fromIndex);"
242.1774 -    )
242.1775 -    public int indexOf(String str, int fromIndex) {
242.1776 -        return indexOf(toCharArray(), offset(), length(), str.toCharArray(), str.offset(), str.length(), fromIndex);
242.1777 -    }
242.1778 -
242.1779 -    /**
242.1780 -     * Code shared by String and StringBuffer to do searches. The
242.1781 -     * source is the character array being searched, and the target
242.1782 -     * is the string being searched for.
242.1783 -     *
242.1784 -     * @param   source       the characters being searched.
242.1785 -     * @param   sourceOffset offset of the source string.
242.1786 -     * @param   sourceCount  count of the source string.
242.1787 -     * @param   target       the characters being searched for.
242.1788 -     * @param   targetOffset offset of the target string.
242.1789 -     * @param   targetCount  count of the target string.
242.1790 -     * @param   fromIndex    the index to begin searching from.
242.1791 -     */
242.1792 -    static int indexOf(char[] source, int sourceOffset, int sourceCount,
242.1793 -                       char[] target, int targetOffset, int targetCount,
242.1794 -                       int fromIndex) {
242.1795 -        if (fromIndex >= sourceCount) {
242.1796 -            return (targetCount == 0 ? sourceCount : -1);
242.1797 -        }
242.1798 -        if (fromIndex < 0) {
242.1799 -            fromIndex = 0;
242.1800 -        }
242.1801 -        if (targetCount == 0) {
242.1802 -            return fromIndex;
242.1803 -        }
242.1804 -
242.1805 -        char first  = target[targetOffset];
242.1806 -        int max = sourceOffset + (sourceCount - targetCount);
242.1807 -
242.1808 -        for (int i = sourceOffset + fromIndex; i <= max; i++) {
242.1809 -            /* Look for first character. */
242.1810 -            if (source[i] != first) {
242.1811 -                while (++i <= max && source[i] != first);
242.1812 -            }
242.1813 -
242.1814 -            /* Found first character, now look at the rest of v2 */
242.1815 -            if (i <= max) {
242.1816 -                int j = i + 1;
242.1817 -                int end = j + targetCount - 1;
242.1818 -                for (int k = targetOffset + 1; j < end && source[j] ==
242.1819 -                         target[k]; j++, k++);
242.1820 -
242.1821 -                if (j == end) {
242.1822 -                    /* Found whole string. */
242.1823 -                    return i - sourceOffset;
242.1824 -                }
242.1825 -            }
242.1826 -        }
242.1827 -        return -1;
242.1828 -    }
242.1829 -
242.1830 -    /**
242.1831 -     * Returns the index within this string of the last occurrence of the
242.1832 -     * specified substring.  The last occurrence of the empty string ""
242.1833 -     * is considered to occur at the index value {@code this.length()}.
242.1834 -     *
242.1835 -     * <p>The returned index is the largest value <i>k</i> for which:
242.1836 -     * <blockquote><pre>
242.1837 -     * this.startsWith(str, <i>k</i>)
242.1838 -     * </pre></blockquote>
242.1839 -     * If no such value of <i>k</i> exists, then {@code -1} is returned.
242.1840 -     *
242.1841 -     * @param   str   the substring to search for.
242.1842 -     * @return  the index of the last occurrence of the specified substring,
242.1843 -     *          or {@code -1} if there is no such occurrence.
242.1844 -     */
242.1845 -    public int lastIndexOf(String str) {
242.1846 -        return lastIndexOf(str, length());
242.1847 -    }
242.1848 -
242.1849 -    /**
242.1850 -     * Returns the index within this string of the last occurrence of the
242.1851 -     * specified substring, searching backward starting at the specified index.
242.1852 -     *
242.1853 -     * <p>The returned index is the largest value <i>k</i> for which:
242.1854 -     * <blockquote><pre>
242.1855 -     * <i>k</i> &lt;= fromIndex && this.startsWith(str, <i>k</i>)
242.1856 -     * </pre></blockquote>
242.1857 -     * If no such value of <i>k</i> exists, then {@code -1} is returned.
242.1858 -     *
242.1859 -     * @param   str         the substring to search for.
242.1860 -     * @param   fromIndex   the index to start the search from.
242.1861 -     * @return  the index of the last occurrence of the specified substring,
242.1862 -     *          searching backward from the specified index,
242.1863 -     *          or {@code -1} if there is no such occurrence.
242.1864 -     */
242.1865 -    @JavaScriptBody(args = { "self", "s", "from" }, body = 
242.1866 -        "return self.toString().lastIndexOf(s.toString(), from);"
242.1867 -    )
242.1868 -    public int lastIndexOf(String str, int fromIndex) {
242.1869 -        return lastIndexOf(toCharArray(), offset(), length(), str.toCharArray(), str.offset(), str.length(), fromIndex);
242.1870 -    }
242.1871 -
242.1872 -    /**
242.1873 -     * Code shared by String and StringBuffer to do searches. The
242.1874 -     * source is the character array being searched, and the target
242.1875 -     * is the string being searched for.
242.1876 -     *
242.1877 -     * @param   source       the characters being searched.
242.1878 -     * @param   sourceOffset offset of the source string.
242.1879 -     * @param   sourceCount  count of the source string.
242.1880 -     * @param   target       the characters being searched for.
242.1881 -     * @param   targetOffset offset of the target string.
242.1882 -     * @param   targetCount  count of the target string.
242.1883 -     * @param   fromIndex    the index to begin searching from.
242.1884 -     */
242.1885 -    static int lastIndexOf(char[] source, int sourceOffset, int sourceCount,
242.1886 -                           char[] target, int targetOffset, int targetCount,
242.1887 -                           int fromIndex) {
242.1888 -        /*
242.1889 -         * Check arguments; return immediately where possible. For
242.1890 -         * consistency, don't check for null str.
242.1891 -         */
242.1892 -        int rightIndex = sourceCount - targetCount;
242.1893 -        if (fromIndex < 0) {
242.1894 -            return -1;
242.1895 -        }
242.1896 -        if (fromIndex > rightIndex) {
242.1897 -            fromIndex = rightIndex;
242.1898 -        }
242.1899 -        /* Empty string always matches. */
242.1900 -        if (targetCount == 0) {
242.1901 -            return fromIndex;
242.1902 -        }
242.1903 -
242.1904 -        int strLastIndex = targetOffset + targetCount - 1;
242.1905 -        char strLastChar = target[strLastIndex];
242.1906 -        int min = sourceOffset + targetCount - 1;
242.1907 -        int i = min + fromIndex;
242.1908 -
242.1909 -    startSearchForLastChar:
242.1910 -        while (true) {
242.1911 -            while (i >= min && source[i] != strLastChar) {
242.1912 -                i--;
242.1913 -            }
242.1914 -            if (i < min) {
242.1915 -                return -1;
242.1916 -            }
242.1917 -            int j = i - 1;
242.1918 -            int start = j - (targetCount - 1);
242.1919 -            int k = strLastIndex - 1;
242.1920 -
242.1921 -            while (j > start) {
242.1922 -                if (source[j--] != target[k--]) {
242.1923 -                    i--;
242.1924 -                    continue startSearchForLastChar;
242.1925 -                }
242.1926 -            }
242.1927 -            return start - sourceOffset + 1;
242.1928 -        }
242.1929 -    }
242.1930 -
242.1931 -    /**
242.1932 -     * Returns a new string that is a substring of this string. The
242.1933 -     * substring begins with the character at the specified index and
242.1934 -     * extends to the end of this string. <p>
242.1935 -     * Examples:
242.1936 -     * <blockquote><pre>
242.1937 -     * "unhappy".substring(2) returns "happy"
242.1938 -     * "Harbison".substring(3) returns "bison"
242.1939 -     * "emptiness".substring(9) returns "" (an empty string)
242.1940 -     * </pre></blockquote>
242.1941 -     *
242.1942 -     * @param      beginIndex   the beginning index, inclusive.
242.1943 -     * @return     the specified substring.
242.1944 -     * @exception  IndexOutOfBoundsException  if
242.1945 -     *             <code>beginIndex</code> is negative or larger than the
242.1946 -     *             length of this <code>String</code> object.
242.1947 -     */
242.1948 -    public String substring(int beginIndex) {
242.1949 -        return substring(beginIndex, length());
242.1950 -    }
242.1951 -
242.1952 -    /**
242.1953 -     * Returns a new string that is a substring of this string. The
242.1954 -     * substring begins at the specified <code>beginIndex</code> and
242.1955 -     * extends to the character at index <code>endIndex - 1</code>.
242.1956 -     * Thus the length of the substring is <code>endIndex-beginIndex</code>.
242.1957 -     * <p>
242.1958 -     * Examples:
242.1959 -     * <blockquote><pre>
242.1960 -     * "hamburger".substring(4, 8) returns "urge"
242.1961 -     * "smiles".substring(1, 5) returns "mile"
242.1962 -     * </pre></blockquote>
242.1963 -     *
242.1964 -     * @param      beginIndex   the beginning index, inclusive.
242.1965 -     * @param      endIndex     the ending index, exclusive.
242.1966 -     * @return     the specified substring.
242.1967 -     * @exception  IndexOutOfBoundsException  if the
242.1968 -     *             <code>beginIndex</code> is negative, or
242.1969 -     *             <code>endIndex</code> is larger than the length of
242.1970 -     *             this <code>String</code> object, or
242.1971 -     *             <code>beginIndex</code> is larger than
242.1972 -     *             <code>endIndex</code>.
242.1973 -     */
242.1974 -    @JavaScriptBody(args = { "self", "beginIndex", "endIndex" }, body = 
242.1975 -        "return self.toString().substring(beginIndex, endIndex);"
242.1976 -    )
242.1977 -    public String substring(int beginIndex, int endIndex) {
242.1978 -        if (beginIndex < 0) {
242.1979 -            throw new StringIndexOutOfBoundsException(beginIndex);
242.1980 -        }
242.1981 -        if (endIndex > length()) {
242.1982 -            throw new StringIndexOutOfBoundsException(endIndex);
242.1983 -        }
242.1984 -        if (beginIndex > endIndex) {
242.1985 -            throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
242.1986 -        }
242.1987 -        return ((beginIndex == 0) && (endIndex == length())) ? this :
242.1988 -            new String(toCharArray(), offset() + beginIndex, endIndex - beginIndex);
242.1989 -    }
242.1990 -
242.1991 -    /**
242.1992 -     * Returns a new character sequence that is a subsequence of this sequence.
242.1993 -     *
242.1994 -     * <p> An invocation of this method of the form
242.1995 -     *
242.1996 -     * <blockquote><pre>
242.1997 -     * str.subSequence(begin,&nbsp;end)</pre></blockquote>
242.1998 -     *
242.1999 -     * behaves in exactly the same way as the invocation
242.2000 -     *
242.2001 -     * <blockquote><pre>
242.2002 -     * str.substring(begin,&nbsp;end)</pre></blockquote>
242.2003 -     *
242.2004 -     * This method is defined so that the <tt>String</tt> class can implement
242.2005 -     * the {@link CharSequence} interface. </p>
242.2006 -     *
242.2007 -     * @param      beginIndex   the begin index, inclusive.
242.2008 -     * @param      endIndex     the end index, exclusive.
242.2009 -     * @return     the specified subsequence.
242.2010 -     *
242.2011 -     * @throws  IndexOutOfBoundsException
242.2012 -     *          if <tt>beginIndex</tt> or <tt>endIndex</tt> are negative,
242.2013 -     *          if <tt>endIndex</tt> is greater than <tt>length()</tt>,
242.2014 -     *          or if <tt>beginIndex</tt> is greater than <tt>startIndex</tt>
242.2015 -     *
242.2016 -     * @since 1.4
242.2017 -     * @spec JSR-51
242.2018 -     */
242.2019 -    public CharSequence subSequence(int beginIndex, int endIndex) {
242.2020 -        return this.substring(beginIndex, endIndex);
242.2021 -    }
242.2022 -
242.2023 -    /**
242.2024 -     * Concatenates the specified string to the end of this string.
242.2025 -     * <p>
242.2026 -     * If the length of the argument string is <code>0</code>, then this
242.2027 -     * <code>String</code> object is returned. Otherwise, a new
242.2028 -     * <code>String</code> object is created, representing a character
242.2029 -     * sequence that is the concatenation of the character sequence
242.2030 -     * represented by this <code>String</code> object and the character
242.2031 -     * sequence represented by the argument string.<p>
242.2032 -     * Examples:
242.2033 -     * <blockquote><pre>
242.2034 -     * "cares".concat("s") returns "caress"
242.2035 -     * "to".concat("get").concat("her") returns "together"
242.2036 -     * </pre></blockquote>
242.2037 -     *
242.2038 -     * @param   str   the <code>String</code> that is concatenated to the end
242.2039 -     *                of this <code>String</code>.
242.2040 -     * @return  a string that represents the concatenation of this object's
242.2041 -     *          characters followed by the string argument's characters.
242.2042 -     */
242.2043 -    public String concat(String str) {
242.2044 -        int otherLen = str.length();
242.2045 -        if (otherLen == 0) {
242.2046 -            return this;
242.2047 -        }
242.2048 -        char buf[] = new char[length() + otherLen];
242.2049 -        getChars(0, length(), buf, 0);
242.2050 -        str.getChars(0, otherLen, buf, length());
242.2051 -        return new String(buf, 0, length() + otherLen);
242.2052 -    }
242.2053 -
242.2054 -    /**
242.2055 -     * Returns a new string resulting from replacing all occurrences of
242.2056 -     * <code>oldChar</code> in this string with <code>newChar</code>.
242.2057 -     * <p>
242.2058 -     * If the character <code>oldChar</code> does not occur in the
242.2059 -     * character sequence represented by this <code>String</code> object,
242.2060 -     * then a reference to this <code>String</code> object is returned.
242.2061 -     * Otherwise, a new <code>String</code> object is created that
242.2062 -     * represents a character sequence identical to the character sequence
242.2063 -     * represented by this <code>String</code> object, except that every
242.2064 -     * occurrence of <code>oldChar</code> is replaced by an occurrence
242.2065 -     * of <code>newChar</code>.
242.2066 -     * <p>
242.2067 -     * Examples:
242.2068 -     * <blockquote><pre>
242.2069 -     * "mesquite in your cellar".replace('e', 'o')
242.2070 -     *         returns "mosquito in your collar"
242.2071 -     * "the war of baronets".replace('r', 'y')
242.2072 -     *         returns "the way of bayonets"
242.2073 -     * "sparring with a purple porpoise".replace('p', 't')
242.2074 -     *         returns "starring with a turtle tortoise"
242.2075 -     * "JonL".replace('q', 'x') returns "JonL" (no change)
242.2076 -     * </pre></blockquote>
242.2077 -     *
242.2078 -     * @param   oldChar   the old character.
242.2079 -     * @param   newChar   the new character.
242.2080 -     * @return  a string derived from this string by replacing every
242.2081 -     *          occurrence of <code>oldChar</code> with <code>newChar</code>.
242.2082 -     */
242.2083 -    @JavaScriptBody(args = { "self", "arg1", "arg2" }, body =
242.2084 -        "if (typeof arg1 === 'number') arg1 = String.fromCharCode(arg1);\n" +
242.2085 -        "if (typeof arg2 === 'number') arg2 = String.fromCharCode(arg2);\n" +
242.2086 -        "var s = self.toString();\n" +
242.2087 -        "for (;;) {\n" +
242.2088 -        "  var ret = s.replace(arg1, arg2);\n" +
242.2089 -        "  if (ret === s) {\n" +
242.2090 -        "    return ret;\n" +
242.2091 -        "  }\n" +
242.2092 -        "  s = ret;\n" +
242.2093 -        "}"
242.2094 -    )
242.2095 -    public String replace(char oldChar, char newChar) {
242.2096 -        if (oldChar != newChar) {
242.2097 -            int len = length();
242.2098 -            int i = -1;
242.2099 -            char[] val = toCharArray(); /* avoid getfield opcode */
242.2100 -            int off = offset();   /* avoid getfield opcode */
242.2101 -
242.2102 -            while (++i < len) {
242.2103 -                if (val[off + i] == oldChar) {
242.2104 -                    break;
242.2105 -                }
242.2106 -            }
242.2107 -            if (i < len) {
242.2108 -                char buf[] = new char[len];
242.2109 -                for (int j = 0 ; j < i ; j++) {
242.2110 -                    buf[j] = val[off+j];
242.2111 -                }
242.2112 -                while (i < len) {
242.2113 -                    char c = val[off + i];
242.2114 -                    buf[i] = (c == oldChar) ? newChar : c;
242.2115 -                    i++;
242.2116 -                }
242.2117 -                return new String(buf, 0, len);
242.2118 -            }
242.2119 -        }
242.2120 -        return this;
242.2121 -    }
242.2122 -
242.2123 -    /**
242.2124 -     * Tells whether or not this string matches the given <a
242.2125 -     * href="../util/regex/Pattern.html#sum">regular expression</a>.
242.2126 -     *
242.2127 -     * <p> An invocation of this method of the form
242.2128 -     * <i>str</i><tt>.matches(</tt><i>regex</i><tt>)</tt> yields exactly the
242.2129 -     * same result as the expression
242.2130 -     *
242.2131 -     * <blockquote><tt> {@link java.util.regex.Pattern}.{@link
242.2132 -     * java.util.regex.Pattern#matches(String,CharSequence)
242.2133 -     * matches}(</tt><i>regex</i><tt>,</tt> <i>str</i><tt>)</tt></blockquote>
242.2134 -     *
242.2135 -     * @param   regex
242.2136 -     *          the regular expression to which this string is to be matched
242.2137 -     *
242.2138 -     * @return  <tt>true</tt> if, and only if, this string matches the
242.2139 -     *          given regular expression
242.2140 -     *
242.2141 -     * @throws  PatternSyntaxException
242.2142 -     *          if the regular expression's syntax is invalid
242.2143 -     *
242.2144 -     * @see java.util.regex.Pattern
242.2145 -     *
242.2146 -     * @since 1.4
242.2147 -     * @spec JSR-51
242.2148 -     */
242.2149 -    public boolean matches(String regex) {
242.2150 -        throw new UnsupportedOperationException();
242.2151 -    }
242.2152 -
242.2153 -    /**
242.2154 -     * Returns true if and only if this string contains the specified
242.2155 -     * sequence of char values.
242.2156 -     *
242.2157 -     * @param s the sequence to search for
242.2158 -     * @return true if this string contains <code>s</code>, false otherwise
242.2159 -     * @throws NullPointerException if <code>s</code> is <code>null</code>
242.2160 -     * @since 1.5
242.2161 -     */
242.2162 -    public boolean contains(CharSequence s) {
242.2163 -        return indexOf(s.toString()) > -1;
242.2164 -    }
242.2165 -
242.2166 -    /**
242.2167 -     * Replaces the first substring of this string that matches the given <a
242.2168 -     * href="../util/regex/Pattern.html#sum">regular expression</a> with the
242.2169 -     * given replacement.
242.2170 -     *
242.2171 -     * <p> An invocation of this method of the form
242.2172 -     * <i>str</i><tt>.replaceFirst(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
242.2173 -     * yields exactly the same result as the expression
242.2174 -     *
242.2175 -     * <blockquote><tt>
242.2176 -     * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
242.2177 -     * compile}(</tt><i>regex</i><tt>).{@link
242.2178 -     * java.util.regex.Pattern#matcher(java.lang.CharSequence)
242.2179 -     * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceFirst
242.2180 -     * replaceFirst}(</tt><i>repl</i><tt>)</tt></blockquote>
242.2181 -     *
242.2182 -     *<p>
242.2183 -     * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
242.2184 -     * replacement string may cause the results to be different than if it were
242.2185 -     * being treated as a literal replacement string; see
242.2186 -     * {@link java.util.regex.Matcher#replaceFirst}.
242.2187 -     * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
242.2188 -     * meaning of these characters, if desired.
242.2189 -     *
242.2190 -     * @param   regex
242.2191 -     *          the regular expression to which this string is to be matched
242.2192 -     * @param   replacement
242.2193 -     *          the string to be substituted for the first match
242.2194 -     *
242.2195 -     * @return  The resulting <tt>String</tt>
242.2196 -     *
242.2197 -     * @throws  PatternSyntaxException
242.2198 -     *          if the regular expression's syntax is invalid
242.2199 -     *
242.2200 -     * @see java.util.regex.Pattern
242.2201 -     *
242.2202 -     * @since 1.4
242.2203 -     * @spec JSR-51
242.2204 -     */
242.2205 -    public String replaceFirst(String regex, String replacement) {
242.2206 -        throw new UnsupportedOperationException();
242.2207 -    }
242.2208 -
242.2209 -    /**
242.2210 -     * Replaces each substring of this string that matches the given <a
242.2211 -     * href="../util/regex/Pattern.html#sum">regular expression</a> with the
242.2212 -     * given replacement.
242.2213 -     *
242.2214 -     * <p> An invocation of this method of the form
242.2215 -     * <i>str</i><tt>.replaceAll(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
242.2216 -     * yields exactly the same result as the expression
242.2217 -     *
242.2218 -     * <blockquote><tt>
242.2219 -     * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
242.2220 -     * compile}(</tt><i>regex</i><tt>).{@link
242.2221 -     * java.util.regex.Pattern#matcher(java.lang.CharSequence)
242.2222 -     * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceAll
242.2223 -     * replaceAll}(</tt><i>repl</i><tt>)</tt></blockquote>
242.2224 -     *
242.2225 -     *<p>
242.2226 -     * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
242.2227 -     * replacement string may cause the results to be different than if it were
242.2228 -     * being treated as a literal replacement string; see
242.2229 -     * {@link java.util.regex.Matcher#replaceAll Matcher.replaceAll}.
242.2230 -     * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
242.2231 -     * meaning of these characters, if desired.
242.2232 -     *
242.2233 -     * @param   regex
242.2234 -     *          the regular expression to which this string is to be matched
242.2235 -     * @param   replacement
242.2236 -     *          the string to be substituted for each match
242.2237 -     *
242.2238 -     * @return  The resulting <tt>String</tt>
242.2239 -     *
242.2240 -     * @throws  PatternSyntaxException
242.2241 -     *          if the regular expression's syntax is invalid
242.2242 -     *
242.2243 -     * @see java.util.regex.Pattern
242.2244 -     *
242.2245 -     * @since 1.4
242.2246 -     * @spec JSR-51
242.2247 -     */
242.2248 -    public String replaceAll(String regex, String replacement) {
242.2249 -        throw new UnsupportedOperationException();
242.2250 -    }
242.2251 -
242.2252 -    /**
242.2253 -     * Replaces each substring of this string that matches the literal target
242.2254 -     * sequence with the specified literal replacement sequence. The
242.2255 -     * replacement proceeds from the beginning of the string to the end, for
242.2256 -     * example, replacing "aa" with "b" in the string "aaa" will result in
242.2257 -     * "ba" rather than "ab".
242.2258 -     *
242.2259 -     * @param  target The sequence of char values to be replaced
242.2260 -     * @param  replacement The replacement sequence of char values
242.2261 -     * @return  The resulting string
242.2262 -     * @throws NullPointerException if <code>target</code> or
242.2263 -     *         <code>replacement</code> is <code>null</code>.
242.2264 -     * @since 1.5
242.2265 -     */
242.2266 -    public String replace(CharSequence target, CharSequence replacement) {
242.2267 -        throw new UnsupportedOperationException("This one should be supported, but without dep on rest of regexp");
242.2268 -    }
242.2269 -
242.2270 -    /**
242.2271 -     * Splits this string around matches of the given
242.2272 -     * <a href="../util/regex/Pattern.html#sum">regular expression</a>.
242.2273 -     *
242.2274 -     * <p> The array returned by this method contains each substring of this
242.2275 -     * string that is terminated by another substring that matches the given
242.2276 -     * expression or is terminated by the end of the string.  The substrings in
242.2277 -     * the array are in the order in which they occur in this string.  If the
242.2278 -     * expression does not match any part of the input then the resulting array
242.2279 -     * has just one element, namely this string.
242.2280 -     *
242.2281 -     * <p> The <tt>limit</tt> parameter controls the number of times the
242.2282 -     * pattern is applied and therefore affects the length of the resulting
242.2283 -     * array.  If the limit <i>n</i> is greater than zero then the pattern
242.2284 -     * will be applied at most <i>n</i>&nbsp;-&nbsp;1 times, the array's
242.2285 -     * length will be no greater than <i>n</i>, and the array's last entry
242.2286 -     * will contain all input beyond the last matched delimiter.  If <i>n</i>
242.2287 -     * is non-positive then the pattern will be applied as many times as
242.2288 -     * possible and the array can have any length.  If <i>n</i> is zero then
242.2289 -     * the pattern will be applied as many times as possible, the array can
242.2290 -     * have any length, and trailing empty strings will be discarded.
242.2291 -     *
242.2292 -     * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the
242.2293 -     * following results with these parameters:
242.2294 -     *
242.2295 -     * <blockquote><table cellpadding=1 cellspacing=0 summary="Split example showing regex, limit, and result">
242.2296 -     * <tr>
242.2297 -     *     <th>Regex</th>
242.2298 -     *     <th>Limit</th>
242.2299 -     *     <th>Result</th>
242.2300 -     * </tr>
242.2301 -     * <tr><td align=center>:</td>
242.2302 -     *     <td align=center>2</td>
242.2303 -     *     <td><tt>{ "boo", "and:foo" }</tt></td></tr>
242.2304 -     * <tr><td align=center>:</td>
242.2305 -     *     <td align=center>5</td>
242.2306 -     *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
242.2307 -     * <tr><td align=center>:</td>
242.2308 -     *     <td align=center>-2</td>
242.2309 -     *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
242.2310 -     * <tr><td align=center>o</td>
242.2311 -     *     <td align=center>5</td>
242.2312 -     *     <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
242.2313 -     * <tr><td align=center>o</td>
242.2314 -     *     <td align=center>-2</td>
242.2315 -     *     <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
242.2316 -     * <tr><td align=center>o</td>
242.2317 -     *     <td align=center>0</td>
242.2318 -     *     <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
242.2319 -     * </table></blockquote>
242.2320 -     *
242.2321 -     * <p> An invocation of this method of the form
242.2322 -     * <i>str.</i><tt>split(</tt><i>regex</i><tt>,</tt>&nbsp;<i>n</i><tt>)</tt>
242.2323 -     * yields the same result as the expression
242.2324 -     *
242.2325 -     * <blockquote>
242.2326 -     * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
242.2327 -     * compile}<tt>(</tt><i>regex</i><tt>)</tt>.{@link
242.2328 -     * java.util.regex.Pattern#split(java.lang.CharSequence,int)
242.2329 -     * split}<tt>(</tt><i>str</i><tt>,</tt>&nbsp;<i>n</i><tt>)</tt>
242.2330 -     * </blockquote>
242.2331 -     *
242.2332 -     *
242.2333 -     * @param  regex
242.2334 -     *         the delimiting regular expression
242.2335 -     *
242.2336 -     * @param  limit
242.2337 -     *         the result threshold, as described above
242.2338 -     *
242.2339 -     * @return  the array of strings computed by splitting this string
242.2340 -     *          around matches of the given regular expression
242.2341 -     *
242.2342 -     * @throws  PatternSyntaxException
242.2343 -     *          if the regular expression's syntax is invalid
242.2344 -     *
242.2345 -     * @see java.util.regex.Pattern
242.2346 -     *
242.2347 -     * @since 1.4
242.2348 -     * @spec JSR-51
242.2349 -     */
242.2350 -    public String[] split(String regex, int limit) {
242.2351 -        throw new UnsupportedOperationException("Needs regexp");
242.2352 -    }
242.2353 -
242.2354 -    /**
242.2355 -     * Splits this string around matches of the given <a
242.2356 -     * href="../util/regex/Pattern.html#sum">regular expression</a>.
242.2357 -     *
242.2358 -     * <p> This method works as if by invoking the two-argument {@link
242.2359 -     * #split(String, int) split} method with the given expression and a limit
242.2360 -     * argument of zero.  Trailing empty strings are therefore not included in
242.2361 -     * the resulting array.
242.2362 -     *
242.2363 -     * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the following
242.2364 -     * results with these expressions:
242.2365 -     *
242.2366 -     * <blockquote><table cellpadding=1 cellspacing=0 summary="Split examples showing regex and result">
242.2367 -     * <tr>
242.2368 -     *  <th>Regex</th>
242.2369 -     *  <th>Result</th>
242.2370 -     * </tr>
242.2371 -     * <tr><td align=center>:</td>
242.2372 -     *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
242.2373 -     * <tr><td align=center>o</td>
242.2374 -     *     <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
242.2375 -     * </table></blockquote>
242.2376 -     *
242.2377 -     *
242.2378 -     * @param  regex
242.2379 -     *         the delimiting regular expression
242.2380 -     *
242.2381 -     * @return  the array of strings computed by splitting this string
242.2382 -     *          around matches of the given regular expression
242.2383 -     *
242.2384 -     * @throws  PatternSyntaxException
242.2385 -     *          if the regular expression's syntax is invalid
242.2386 -     *
242.2387 -     * @see java.util.regex.Pattern
242.2388 -     *
242.2389 -     * @since 1.4
242.2390 -     * @spec JSR-51
242.2391 -     */
242.2392 -    public String[] split(String regex) {
242.2393 -        return split(regex, 0);
242.2394 -    }
242.2395 -
242.2396 -    /**
242.2397 -     * Converts all of the characters in this <code>String</code> to lower
242.2398 -     * case using the rules of the given <code>Locale</code>.  Case mapping is based
242.2399 -     * on the Unicode Standard version specified by the {@link java.lang.Character Character}
242.2400 -     * class. Since case mappings are not always 1:1 char mappings, the resulting
242.2401 -     * <code>String</code> may be a different length than the original <code>String</code>.
242.2402 -     * <p>
242.2403 -     * Examples of lowercase  mappings are in the following table:
242.2404 -     * <table border="1" summary="Lowercase mapping examples showing language code of locale, upper case, lower case, and description">
242.2405 -     * <tr>
242.2406 -     *   <th>Language Code of Locale</th>
242.2407 -     *   <th>Upper Case</th>
242.2408 -     *   <th>Lower Case</th>
242.2409 -     *   <th>Description</th>
242.2410 -     * </tr>
242.2411 -     * <tr>
242.2412 -     *   <td>tr (Turkish)</td>
242.2413 -     *   <td>&#92;u0130</td>
242.2414 -     *   <td>&#92;u0069</td>
242.2415 -     *   <td>capital letter I with dot above -&gt; small letter i</td>
242.2416 -     * </tr>
242.2417 -     * <tr>
242.2418 -     *   <td>tr (Turkish)</td>
242.2419 -     *   <td>&#92;u0049</td>
242.2420 -     *   <td>&#92;u0131</td>
242.2421 -     *   <td>capital letter I -&gt; small letter dotless i </td>
242.2422 -     * </tr>
242.2423 -     * <tr>
242.2424 -     *   <td>(all)</td>
242.2425 -     *   <td>French Fries</td>
242.2426 -     *   <td>french fries</td>
242.2427 -     *   <td>lowercased all chars in String</td>
242.2428 -     * </tr>
242.2429 -     * <tr>
242.2430 -     *   <td>(all)</td>
242.2431 -     *   <td><img src="doc-files/capiota.gif" alt="capiota"><img src="doc-files/capchi.gif" alt="capchi">
242.2432 -     *       <img src="doc-files/captheta.gif" alt="captheta"><img src="doc-files/capupsil.gif" alt="capupsil">
242.2433 -     *       <img src="doc-files/capsigma.gif" alt="capsigma"></td>
242.2434 -     *   <td><img src="doc-files/iota.gif" alt="iota"><img src="doc-files/chi.gif" alt="chi">
242.2435 -     *       <img src="doc-files/theta.gif" alt="theta"><img src="doc-files/upsilon.gif" alt="upsilon">
242.2436 -     *       <img src="doc-files/sigma1.gif" alt="sigma"></td>
242.2437 -     *   <td>lowercased all chars in String</td>
242.2438 -     * </tr>
242.2439 -     * </table>
242.2440 -     *
242.2441 -     * @param locale use the case transformation rules for this locale
242.2442 -     * @return the <code>String</code>, converted to lowercase.
242.2443 -     * @see     java.lang.String#toLowerCase()
242.2444 -     * @see     java.lang.String#toUpperCase()
242.2445 -     * @see     java.lang.String#toUpperCase(Locale)
242.2446 -     * @since   1.1
242.2447 -     */
242.2448 -//    public String toLowerCase(Locale locale) {
242.2449 -//        if (locale == null) {
242.2450 -//            throw new NullPointerException();
242.2451 -//        }
242.2452 -//
242.2453 -//        int     firstUpper;
242.2454 -//
242.2455 -//        /* Now check if there are any characters that need to be changed. */
242.2456 -//        scan: {
242.2457 -//            for (firstUpper = 0 ; firstUpper < count; ) {
242.2458 -//                char c = value[offset+firstUpper];
242.2459 -//                if ((c >= Character.MIN_HIGH_SURROGATE) &&
242.2460 -//                    (c <= Character.MAX_HIGH_SURROGATE)) {
242.2461 -//                    int supplChar = codePointAt(firstUpper);
242.2462 -//                    if (supplChar != Character.toLowerCase(supplChar)) {
242.2463 -//                        break scan;
242.2464 -//                    }
242.2465 -//                    firstUpper += Character.charCount(supplChar);
242.2466 -//                } else {
242.2467 -//                    if (c != Character.toLowerCase(c)) {
242.2468 -//                        break scan;
242.2469 -//                    }
242.2470 -//                    firstUpper++;
242.2471 -//                }
242.2472 -//            }
242.2473 -//            return this;
242.2474 -//        }
242.2475 -//
242.2476 -//        char[]  result = new char[count];
242.2477 -//        int     resultOffset = 0;  /* result may grow, so i+resultOffset
242.2478 -//                                    * is the write location in result */
242.2479 -//
242.2480 -//        /* Just copy the first few lowerCase characters. */
242.2481 -//        arraycopy(value, offset, result, 0, firstUpper);
242.2482 -//
242.2483 -//        String lang = locale.getLanguage();
242.2484 -//        boolean localeDependent =
242.2485 -//            (lang == "tr" || lang == "az" || lang == "lt");
242.2486 -//        char[] lowerCharArray;
242.2487 -//        int lowerChar;
242.2488 -//        int srcChar;
242.2489 -//        int srcCount;
242.2490 -//        for (int i = firstUpper; i < count; i += srcCount) {
242.2491 -//            srcChar = (int)value[offset+i];
242.2492 -//            if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
242.2493 -//                (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
242.2494 -//                srcChar = codePointAt(i);
242.2495 -//                srcCount = Character.charCount(srcChar);
242.2496 -//            } else {
242.2497 -//                srcCount = 1;
242.2498 -//            }
242.2499 -//            if (localeDependent || srcChar == '\u03A3') { // GREEK CAPITAL LETTER SIGMA
242.2500 -//                lowerChar = ConditionalSpecialCasing.toLowerCaseEx(this, i, locale);
242.2501 -//            } else if (srcChar == '\u0130') { // LATIN CAPITAL LETTER I DOT
242.2502 -//                lowerChar = Character.ERROR;
242.2503 -//            } else {
242.2504 -//                lowerChar = Character.toLowerCase(srcChar);
242.2505 -//            }
242.2506 -//            if ((lowerChar == Character.ERROR) ||
242.2507 -//                (lowerChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
242.2508 -//                if (lowerChar == Character.ERROR) {
242.2509 -//                     if (!localeDependent && srcChar == '\u0130') {
242.2510 -//                         lowerCharArray =
242.2511 -//                             ConditionalSpecialCasing.toLowerCaseCharArray(this, i, Locale.ENGLISH);
242.2512 -//                     } else {
242.2513 -//                        lowerCharArray =
242.2514 -//                            ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale);
242.2515 -//                     }
242.2516 -//                } else if (srcCount == 2) {
242.2517 -//                    resultOffset += Character.toChars(lowerChar, result, i + resultOffset) - srcCount;
242.2518 -//                    continue;
242.2519 -//                } else {
242.2520 -//                    lowerCharArray = Character.toChars(lowerChar);
242.2521 -//                }
242.2522 -//
242.2523 -//                /* Grow result if needed */
242.2524 -//                int mapLen = lowerCharArray.length;
242.2525 -//                if (mapLen > srcCount) {
242.2526 -//                    char[] result2 = new char[result.length + mapLen - srcCount];
242.2527 -//                    arraycopy(result, 0, result2, 0,
242.2528 -//                        i + resultOffset);
242.2529 -//                    result = result2;
242.2530 -//                }
242.2531 -//                for (int x=0; x<mapLen; ++x) {
242.2532 -//                    result[i+resultOffset+x] = lowerCharArray[x];
242.2533 -//                }
242.2534 -//                resultOffset += (mapLen - srcCount);
242.2535 -//            } else {
242.2536 -//                result[i+resultOffset] = (char)lowerChar;
242.2537 -//            }
242.2538 -//        }
242.2539 -//        return new String(0, count+resultOffset, result);
242.2540 -//    }
242.2541 -
242.2542 -    /**
242.2543 -     * Converts all of the characters in this <code>String</code> to lower
242.2544 -     * case using the rules of the default locale. This is equivalent to calling
242.2545 -     * <code>toLowerCase(Locale.getDefault())</code>.
242.2546 -     * <p>
242.2547 -     * <b>Note:</b> This method is locale sensitive, and may produce unexpected
242.2548 -     * results if used for strings that are intended to be interpreted locale
242.2549 -     * independently.
242.2550 -     * Examples are programming language identifiers, protocol keys, and HTML
242.2551 -     * tags.
242.2552 -     * For instance, <code>"TITLE".toLowerCase()</code> in a Turkish locale
242.2553 -     * returns <code>"t\u005Cu0131tle"</code>, where '\u005Cu0131' is the
242.2554 -     * LATIN SMALL LETTER DOTLESS I character.
242.2555 -     * To obtain correct results for locale insensitive strings, use
242.2556 -     * <code>toLowerCase(Locale.ENGLISH)</code>.
242.2557 -     * <p>
242.2558 -     * @return  the <code>String</code>, converted to lowercase.
242.2559 -     * @see     java.lang.String#toLowerCase(Locale)
242.2560 -     */
242.2561 -    public String toLowerCase() {
242.2562 -        throw new UnsupportedOperationException("Should be supported but without connection to locale");
242.2563 -    }
242.2564 -
242.2565 -    /**
242.2566 -     * Converts all of the characters in this <code>String</code> to upper
242.2567 -     * case using the rules of the given <code>Locale</code>. Case mapping is based
242.2568 -     * on the Unicode Standard version specified by the {@link java.lang.Character Character}
242.2569 -     * class. Since case mappings are not always 1:1 char mappings, the resulting
242.2570 -     * <code>String</code> may be a different length than the original <code>String</code>.
242.2571 -     * <p>
242.2572 -     * Examples of locale-sensitive and 1:M case mappings are in the following table.
242.2573 -     * <p>
242.2574 -     * <table border="1" summary="Examples of locale-sensitive and 1:M case mappings. Shows Language code of locale, lower case, upper case, and description.">
242.2575 -     * <tr>
242.2576 -     *   <th>Language Code of Locale</th>
242.2577 -     *   <th>Lower Case</th>
242.2578 -     *   <th>Upper Case</th>
242.2579 -     *   <th>Description</th>
242.2580 -     * </tr>
242.2581 -     * <tr>
242.2582 -     *   <td>tr (Turkish)</td>
242.2583 -     *   <td>&#92;u0069</td>
242.2584 -     *   <td>&#92;u0130</td>
242.2585 -     *   <td>small letter i -&gt; capital letter I with dot above</td>
242.2586 -     * </tr>
242.2587 -     * <tr>
242.2588 -     *   <td>tr (Turkish)</td>
242.2589 -     *   <td>&#92;u0131</td>
242.2590 -     *   <td>&#92;u0049</td>
242.2591 -     *   <td>small letter dotless i -&gt; capital letter I</td>
242.2592 -     * </tr>
242.2593 -     * <tr>
242.2594 -     *   <td>(all)</td>
242.2595 -     *   <td>&#92;u00df</td>
242.2596 -     *   <td>&#92;u0053 &#92;u0053</td>
242.2597 -     *   <td>small letter sharp s -&gt; two letters: SS</td>
242.2598 -     * </tr>
242.2599 -     * <tr>
242.2600 -     *   <td>(all)</td>
242.2601 -     *   <td>Fahrvergn&uuml;gen</td>
242.2602 -     *   <td>FAHRVERGN&Uuml;GEN</td>
242.2603 -     *   <td></td>
242.2604 -     * </tr>
242.2605 -     * </table>
242.2606 -     * @param locale use the case transformation rules for this locale
242.2607 -     * @return the <code>String</code>, converted to uppercase.
242.2608 -     * @see     java.lang.String#toUpperCase()
242.2609 -     * @see     java.lang.String#toLowerCase()
242.2610 -     * @see     java.lang.String#toLowerCase(Locale)
242.2611 -     * @since   1.1
242.2612 -     */
242.2613 -    /* not for javascript 
242.2614 -    public String toUpperCase(Locale locale) {
242.2615 -        if (locale == null) {
242.2616 -            throw new NullPointerException();
242.2617 -        }
242.2618 -
242.2619 -        int     firstLower;
242.2620 -
242.2621 -        // Now check if there are any characters that need to be changed. 
242.2622 -        scan: {
242.2623 -            for (firstLower = 0 ; firstLower < count; ) {
242.2624 -                int c = (int)value[offset+firstLower];
242.2625 -                int srcCount;
242.2626 -                if ((c >= Character.MIN_HIGH_SURROGATE) &&
242.2627 -                    (c <= Character.MAX_HIGH_SURROGATE)) {
242.2628 -                    c = codePointAt(firstLower);
242.2629 -                    srcCount = Character.charCount(c);
242.2630 -                } else {
242.2631 -                    srcCount = 1;
242.2632 -                }
242.2633 -                int upperCaseChar = Character.toUpperCaseEx(c);
242.2634 -                if ((upperCaseChar == Character.ERROR) ||
242.2635 -                    (c != upperCaseChar)) {
242.2636 -                    break scan;
242.2637 -                }
242.2638 -                firstLower += srcCount;
242.2639 -            }
242.2640 -            return this;
242.2641 -        }
242.2642 -
242.2643 -        char[]  result       = new char[count]; /* may grow *
242.2644 -        int     resultOffset = 0;  /* result may grow, so i+resultOffset
242.2645 -                                    * is the write location in result *
242.2646 -
242.2647 -        /* Just copy the first few upperCase characters. *
242.2648 -        arraycopy(value, offset, result, 0, firstLower);
242.2649 -
242.2650 -        String lang = locale.getLanguage();
242.2651 -        boolean localeDependent =
242.2652 -            (lang == "tr" || lang == "az" || lang == "lt");
242.2653 -        char[] upperCharArray;
242.2654 -        int upperChar;
242.2655 -        int srcChar;
242.2656 -        int srcCount;
242.2657 -        for (int i = firstLower; i < count; i += srcCount) {
242.2658 -            srcChar = (int)value[offset+i];
242.2659 -            if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
242.2660 -                (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
242.2661 -                srcChar = codePointAt(i);
242.2662 -                srcCount = Character.charCount(srcChar);
242.2663 -            } else {
242.2664 -                srcCount = 1;
242.2665 -            }
242.2666 -            if (localeDependent) {
242.2667 -                upperChar = ConditionalSpecialCasing.toUpperCaseEx(this, i, locale);
242.2668 -            } else {
242.2669 -                upperChar = Character.toUpperCaseEx(srcChar);
242.2670 -            }
242.2671 -            if ((upperChar == Character.ERROR) ||
242.2672 -                (upperChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
242.2673 -                if (upperChar == Character.ERROR) {
242.2674 -                    if (localeDependent) {
242.2675 -                        upperCharArray =
242.2676 -                            ConditionalSpecialCasing.toUpperCaseCharArray(this, i, locale);
242.2677 -                    } else {
242.2678 -                        upperCharArray = Character.toUpperCaseCharArray(srcChar);
242.2679 -                    }
242.2680 -                } else if (srcCount == 2) {
242.2681 -                    resultOffset += Character.toChars(upperChar, result, i + resultOffset) - srcCount;
242.2682 -                    continue;
242.2683 -                } else {
242.2684 -                    upperCharArray = Character.toChars(upperChar);
242.2685 -                }
242.2686 -
242.2687 -                /* Grow result if needed *
242.2688 -                int mapLen = upperCharArray.length;
242.2689 -                if (mapLen > srcCount) {
242.2690 -                    char[] result2 = new char[result.length + mapLen - srcCount];
242.2691 -                    arraycopy(result, 0, result2, 0,
242.2692 -                        i + resultOffset);
242.2693 -                    result = result2;
242.2694 -                }
242.2695 -                for (int x=0; x<mapLen; ++x) {
242.2696 -                    result[i+resultOffset+x] = upperCharArray[x];
242.2697 -                }
242.2698 -                resultOffset += (mapLen - srcCount);
242.2699 -            } else {
242.2700 -                result[i+resultOffset] = (char)upperChar;
242.2701 -            }
242.2702 -        }
242.2703 -        return new String(0, count+resultOffset, result);
242.2704 -    }
242.2705 -    */
242.2706 -
242.2707 -    /**
242.2708 -     * Converts all of the characters in this <code>String</code> to upper
242.2709 -     * case using the rules of the default locale. This method is equivalent to
242.2710 -     * <code>toUpperCase(Locale.getDefault())</code>.
242.2711 -     * <p>
242.2712 -     * <b>Note:</b> This method is locale sensitive, and may produce unexpected
242.2713 -     * results if used for strings that are intended to be interpreted locale
242.2714 -     * independently.
242.2715 -     * Examples are programming language identifiers, protocol keys, and HTML
242.2716 -     * tags.
242.2717 -     * For instance, <code>"title".toUpperCase()</code> in a Turkish locale
242.2718 -     * returns <code>"T\u005Cu0130TLE"</code>, where '\u005Cu0130' is the
242.2719 -     * LATIN CAPITAL LETTER I WITH DOT ABOVE character.
242.2720 -     * To obtain correct results for locale insensitive strings, use
242.2721 -     * <code>toUpperCase(Locale.ENGLISH)</code>.
242.2722 -     * <p>
242.2723 -     * @return  the <code>String</code>, converted to uppercase.
242.2724 -     * @see     java.lang.String#toUpperCase(Locale)
242.2725 -     */
242.2726 -    public String toUpperCase() {
242.2727 -        throw new UnsupportedOperationException();
242.2728 -    }
242.2729 -
242.2730 -    /**
242.2731 -     * Returns a copy of the string, with leading and trailing whitespace
242.2732 -     * omitted.
242.2733 -     * <p>
242.2734 -     * If this <code>String</code> object represents an empty character
242.2735 -     * sequence, or the first and last characters of character sequence
242.2736 -     * represented by this <code>String</code> object both have codes
242.2737 -     * greater than <code>'&#92;u0020'</code> (the space character), then a
242.2738 -     * reference to this <code>String</code> object is returned.
242.2739 -     * <p>
242.2740 -     * Otherwise, if there is no character with a code greater than
242.2741 -     * <code>'&#92;u0020'</code> in the string, then a new
242.2742 -     * <code>String</code> object representing an empty string is created
242.2743 -     * and returned.
242.2744 -     * <p>
242.2745 -     * Otherwise, let <i>k</i> be the index of the first character in the
242.2746 -     * string whose code is greater than <code>'&#92;u0020'</code>, and let
242.2747 -     * <i>m</i> be the index of the last character in the string whose code
242.2748 -     * is greater than <code>'&#92;u0020'</code>. A new <code>String</code>
242.2749 -     * object is created, representing the substring of this string that
242.2750 -     * begins with the character at index <i>k</i> and ends with the
242.2751 -     * character at index <i>m</i>-that is, the result of
242.2752 -     * <code>this.substring(<i>k</i>,&nbsp;<i>m</i>+1)</code>.
242.2753 -     * <p>
242.2754 -     * This method may be used to trim whitespace (as defined above) from
242.2755 -     * the beginning and end of a string.
242.2756 -     *
242.2757 -     * @return  A copy of this string with leading and trailing white
242.2758 -     *          space removed, or this string if it has no leading or
242.2759 -     *          trailing white space.
242.2760 -     */
242.2761 -    public String trim() {
242.2762 -        int len = length();
242.2763 -        int st = 0;
242.2764 -        int off = offset();      /* avoid getfield opcode */
242.2765 -        char[] val = toCharArray();    /* avoid getfield opcode */
242.2766 -
242.2767 -        while ((st < len) && (val[off + st] <= ' ')) {
242.2768 -            st++;
242.2769 -        }
242.2770 -        while ((st < len) && (val[off + len - 1] <= ' ')) {
242.2771 -            len--;
242.2772 -        }
242.2773 -        return ((st > 0) || (len < length())) ? substring(st, len) : this;
242.2774 -    }
242.2775 -
242.2776 -    /**
242.2777 -     * This object (which is already a string!) is itself returned.
242.2778 -     *
242.2779 -     * @return  the string itself.
242.2780 -     */
242.2781 -    @JavaScriptBody(args = "self", body = "return self.toString();")
242.2782 -    public String toString() {
242.2783 -        return this;
242.2784 -    }
242.2785 -
242.2786 -    /**
242.2787 -     * Converts this string to a new character array.
242.2788 -     *
242.2789 -     * @return  a newly allocated character array whose length is the length
242.2790 -     *          of this string and whose contents are initialized to contain
242.2791 -     *          the character sequence represented by this string.
242.2792 -     */
242.2793 -    @JavaScriptBody(args = "self", body = "return self.toString().split('');")
242.2794 -    public char[] toCharArray() {
242.2795 -        char result[] = new char[length()];
242.2796 -        getChars(0, length(), result, 0);
242.2797 -        return result;
242.2798 -    }
242.2799 -
242.2800 -    /**
242.2801 -     * Returns a formatted string using the specified format string and
242.2802 -     * arguments.
242.2803 -     *
242.2804 -     * <p> The locale always used is the one returned by {@link
242.2805 -     * java.util.Locale#getDefault() Locale.getDefault()}.
242.2806 -     *
242.2807 -     * @param  format
242.2808 -     *         A <a href="../util/Formatter.html#syntax">format string</a>
242.2809 -     *
242.2810 -     * @param  args
242.2811 -     *         Arguments referenced by the format specifiers in the format
242.2812 -     *         string.  If there are more arguments than format specifiers, the
242.2813 -     *         extra arguments are ignored.  The number of arguments is
242.2814 -     *         variable and may be zero.  The maximum number of arguments is
242.2815 -     *         limited by the maximum dimension of a Java array as defined by
242.2816 -     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
242.2817 -     *         The behaviour on a
242.2818 -     *         <tt>null</tt> argument depends on the <a
242.2819 -     *         href="../util/Formatter.html#syntax">conversion</a>.
242.2820 -     *
242.2821 -     * @throws  IllegalFormatException
242.2822 -     *          If a format string contains an illegal syntax, a format
242.2823 -     *          specifier that is incompatible with the given arguments,
242.2824 -     *          insufficient arguments given the format string, or other
242.2825 -     *          illegal conditions.  For specification of all possible
242.2826 -     *          formatting errors, see the <a
242.2827 -     *          href="../util/Formatter.html#detail">Details</a> section of the
242.2828 -     *          formatter class specification.
242.2829 -     *
242.2830 -     * @throws  NullPointerException
242.2831 -     *          If the <tt>format</tt> is <tt>null</tt>
242.2832 -     *
242.2833 -     * @return  A formatted string
242.2834 -     *
242.2835 -     * @see  java.util.Formatter
242.2836 -     * @since  1.5
242.2837 -     */
242.2838 -    public static String format(String format, Object ... args) {
242.2839 -        throw new UnsupportedOperationException();
242.2840 -    }
242.2841 -
242.2842 -    /**
242.2843 -     * Returns a formatted string using the specified locale, format string,
242.2844 -     * and arguments.
242.2845 -     *
242.2846 -     * @param  l
242.2847 -     *         The {@linkplain java.util.Locale locale} to apply during
242.2848 -     *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
242.2849 -     *         is applied.
242.2850 -     *
242.2851 -     * @param  format
242.2852 -     *         A <a href="../util/Formatter.html#syntax">format string</a>
242.2853 -     *
242.2854 -     * @param  args
242.2855 -     *         Arguments referenced by the format specifiers in the format
242.2856 -     *         string.  If there are more arguments than format specifiers, the
242.2857 -     *         extra arguments are ignored.  The number of arguments is
242.2858 -     *         variable and may be zero.  The maximum number of arguments is
242.2859 -     *         limited by the maximum dimension of a Java array as defined by
242.2860 -     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
242.2861 -     *         The behaviour on a
242.2862 -     *         <tt>null</tt> argument depends on the <a
242.2863 -     *         href="../util/Formatter.html#syntax">conversion</a>.
242.2864 -     *
242.2865 -     * @throws  IllegalFormatException
242.2866 -     *          If a format string contains an illegal syntax, a format
242.2867 -     *          specifier that is incompatible with the given arguments,
242.2868 -     *          insufficient arguments given the format string, or other
242.2869 -     *          illegal conditions.  For specification of all possible
242.2870 -     *          formatting errors, see the <a
242.2871 -     *          href="../util/Formatter.html#detail">Details</a> section of the
242.2872 -     *          formatter class specification
242.2873 -     *
242.2874 -     * @throws  NullPointerException
242.2875 -     *          If the <tt>format</tt> is <tt>null</tt>
242.2876 -     *
242.2877 -     * @return  A formatted string
242.2878 -     *
242.2879 -     * @see  java.util.Formatter
242.2880 -     * @since  1.5
242.2881 -     */
242.2882 -//    public static String format(Locale l, String format, Object ... args) {
242.2883 -//        return new Formatter(l).format(format, args).toString();
242.2884 -//    }
242.2885 -
242.2886 -    /**
242.2887 -     * Returns the string representation of the <code>Object</code> argument.
242.2888 -     *
242.2889 -     * @param   obj   an <code>Object</code>.
242.2890 -     * @return  if the argument is <code>null</code>, then a string equal to
242.2891 -     *          <code>"null"</code>; otherwise, the value of
242.2892 -     *          <code>obj.toString()</code> is returned.
242.2893 -     * @see     java.lang.Object#toString()
242.2894 -     */
242.2895 -    public static String valueOf(Object obj) {
242.2896 -        return (obj == null) ? "null" : obj.toString();
242.2897 -    }
242.2898 -
242.2899 -    /**
242.2900 -     * Returns the string representation of the <code>char</code> array
242.2901 -     * argument. The contents of the character array are copied; subsequent
242.2902 -     * modification of the character array does not affect the newly
242.2903 -     * created string.
242.2904 -     *
242.2905 -     * @param   data   a <code>char</code> array.
242.2906 -     * @return  a newly allocated string representing the same sequence of
242.2907 -     *          characters contained in the character array argument.
242.2908 -     */
242.2909 -    public static String valueOf(char data[]) {
242.2910 -        return new String(data);
242.2911 -    }
242.2912 -
242.2913 -    /**
242.2914 -     * Returns the string representation of a specific subarray of the
242.2915 -     * <code>char</code> array argument.
242.2916 -     * <p>
242.2917 -     * The <code>offset</code> argument is the index of the first
242.2918 -     * character of the subarray. The <code>count</code> argument
242.2919 -     * specifies the length of the subarray. The contents of the subarray
242.2920 -     * are copied; subsequent modification of the character array does not
242.2921 -     * affect the newly created string.
242.2922 -     *
242.2923 -     * @param   data     the character array.
242.2924 -     * @param   offset   the initial offset into the value of the
242.2925 -     *                  <code>String</code>.
242.2926 -     * @param   count    the length of the value of the <code>String</code>.
242.2927 -     * @return  a string representing the sequence of characters contained
242.2928 -     *          in the subarray of the character array argument.
242.2929 -     * @exception IndexOutOfBoundsException if <code>offset</code> is
242.2930 -     *          negative, or <code>count</code> is negative, or
242.2931 -     *          <code>offset+count</code> is larger than
242.2932 -     *          <code>data.length</code>.
242.2933 -     */
242.2934 -    public static String valueOf(char data[], int offset, int count) {
242.2935 -        return new String(data, offset, count);
242.2936 -    }
242.2937 -
242.2938 -    /**
242.2939 -     * Returns a String that represents the character sequence in the
242.2940 -     * array specified.
242.2941 -     *
242.2942 -     * @param   data     the character array.
242.2943 -     * @param   offset   initial offset of the subarray.
242.2944 -     * @param   count    length of the subarray.
242.2945 -     * @return  a <code>String</code> that contains the characters of the
242.2946 -     *          specified subarray of the character array.
242.2947 -     */
242.2948 -    public static String copyValueOf(char data[], int offset, int count) {
242.2949 -        // All public String constructors now copy the data.
242.2950 -        return new String(data, offset, count);
242.2951 -    }
242.2952 -
242.2953 -    /**
242.2954 -     * Returns a String that represents the character sequence in the
242.2955 -     * array specified.
242.2956 -     *
242.2957 -     * @param   data   the character array.
242.2958 -     * @return  a <code>String</code> that contains the characters of the
242.2959 -     *          character array.
242.2960 -     */
242.2961 -    public static String copyValueOf(char data[]) {
242.2962 -        return copyValueOf(data, 0, data.length);
242.2963 -    }
242.2964 -
242.2965 -    /**
242.2966 -     * Returns the string representation of the <code>boolean</code> argument.
242.2967 -     *
242.2968 -     * @param   b   a <code>boolean</code>.
242.2969 -     * @return  if the argument is <code>true</code>, a string equal to
242.2970 -     *          <code>"true"</code> is returned; otherwise, a string equal to
242.2971 -     *          <code>"false"</code> is returned.
242.2972 -     */
242.2973 -    public static String valueOf(boolean b) {
242.2974 -        return b ? "true" : "false";
242.2975 -    }
242.2976 -
242.2977 -    /**
242.2978 -     * Returns the string representation of the <code>char</code>
242.2979 -     * argument.
242.2980 -     *
242.2981 -     * @param   c   a <code>char</code>.
242.2982 -     * @return  a string of length <code>1</code> containing
242.2983 -     *          as its single character the argument <code>c</code>.
242.2984 -     */
242.2985 -    public static String valueOf(char c) {
242.2986 -        char data[] = {c};
242.2987 -        return new String(data, 0, 1);
242.2988 -    }
242.2989 -
242.2990 -    /**
242.2991 -     * Returns the string representation of the <code>int</code> argument.
242.2992 -     * <p>
242.2993 -     * The representation is exactly the one returned by the
242.2994 -     * <code>Integer.toString</code> method of one argument.
242.2995 -     *
242.2996 -     * @param   i   an <code>int</code>.
242.2997 -     * @return  a string representation of the <code>int</code> argument.
242.2998 -     * @see     java.lang.Integer#toString(int, int)
242.2999 -     */
242.3000 -    public static String valueOf(int i) {
242.3001 -        return Integer.toString(i);
242.3002 -    }
242.3003 -
242.3004 -    /**
242.3005 -     * Returns the string representation of the <code>long</code> argument.
242.3006 -     * <p>
242.3007 -     * The representation is exactly the one returned by the
242.3008 -     * <code>Long.toString</code> method of one argument.
242.3009 -     *
242.3010 -     * @param   l   a <code>long</code>.
242.3011 -     * @return  a string representation of the <code>long</code> argument.
242.3012 -     * @see     java.lang.Long#toString(long)
242.3013 -     */
242.3014 -    public static String valueOf(long l) {
242.3015 -        return Long.toString(l);
242.3016 -    }
242.3017 -
242.3018 -    /**
242.3019 -     * Returns the string representation of the <code>float</code> argument.
242.3020 -     * <p>
242.3021 -     * The representation is exactly the one returned by the
242.3022 -     * <code>Float.toString</code> method of one argument.
242.3023 -     *
242.3024 -     * @param   f   a <code>float</code>.
242.3025 -     * @return  a string representation of the <code>float</code> argument.
242.3026 -     * @see     java.lang.Float#toString(float)
242.3027 -     */
242.3028 -    public static String valueOf(float f) {
242.3029 -        return Float.toString(f);
242.3030 -    }
242.3031 -
242.3032 -    /**
242.3033 -     * Returns the string representation of the <code>double</code> argument.
242.3034 -     * <p>
242.3035 -     * The representation is exactly the one returned by the
242.3036 -     * <code>Double.toString</code> method of one argument.
242.3037 -     *
242.3038 -     * @param   d   a <code>double</code>.
242.3039 -     * @return  a  string representation of the <code>double</code> argument.
242.3040 -     * @see     java.lang.Double#toString(double)
242.3041 -     */
242.3042 -    public static String valueOf(double d) {
242.3043 -        return Double.toString(d);
242.3044 -    }
242.3045 -
242.3046 -    /**
242.3047 -     * Returns a canonical representation for the string object.
242.3048 -     * <p>
242.3049 -     * A pool of strings, initially empty, is maintained privately by the
242.3050 -     * class <code>String</code>.
242.3051 -     * <p>
242.3052 -     * When the intern method is invoked, if the pool already contains a
242.3053 -     * string equal to this <code>String</code> object as determined by
242.3054 -     * the {@link #equals(Object)} method, then the string from the pool is
242.3055 -     * returned. Otherwise, this <code>String</code> object is added to the
242.3056 -     * pool and a reference to this <code>String</code> object is returned.
242.3057 -     * <p>
242.3058 -     * It follows that for any two strings <code>s</code> and <code>t</code>,
242.3059 -     * <code>s.intern()&nbsp;==&nbsp;t.intern()</code> is <code>true</code>
242.3060 -     * if and only if <code>s.equals(t)</code> is <code>true</code>.
242.3061 -     * <p>
242.3062 -     * All literal strings and string-valued constant expressions are
242.3063 -     * interned. String literals are defined in section 3.10.5 of the
242.3064 -     * <cite>The Java&trade; Language Specification</cite>.
242.3065 -     *
242.3066 -     * @return  a string that has the same contents as this string, but is
242.3067 -     *          guaranteed to be from a pool of unique strings.
242.3068 -     */
242.3069 -    public native String intern();
242.3070 -}
   243.1 --- a/emul/src/main/java/java/lang/StringBuffer.java	Wed Dec 05 10:03:58 2012 +0100
   243.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   243.3 @@ -1,605 +0,0 @@
   243.4 -/*
   243.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   243.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   243.7 - *
   243.8 - * This code is free software; you can redistribute it and/or modify it
   243.9 - * under the terms of the GNU General Public License version 2 only, as
  243.10 - * published by the Free Software Foundation.  Oracle designates this
  243.11 - * particular file as subject to the "Classpath" exception as provided
  243.12 - * by Oracle in the LICENSE file that accompanied this code.
  243.13 - *
  243.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  243.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  243.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  243.17 - * version 2 for more details (a copy is included in the LICENSE file that
  243.18 - * accompanied this code).
  243.19 - *
  243.20 - * You should have received a copy of the GNU General Public License version
  243.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  243.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  243.23 - *
  243.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  243.25 - * or visit www.oracle.com if you need additional information or have any
  243.26 - * questions.
  243.27 - */
  243.28 -
  243.29 -package java.lang;
  243.30 -
  243.31 -
  243.32 -/**
  243.33 - * A thread-safe, mutable sequence of characters.
  243.34 - * A string buffer is like a {@link String}, but can be modified. At any
  243.35 - * point in time it contains some particular sequence of characters, but
  243.36 - * the length and content of the sequence can be changed through certain
  243.37 - * method calls.
  243.38 - * <p>
  243.39 - * String buffers are safe for use by multiple threads. The methods
  243.40 - * are synchronized where necessary so that all the operations on any
  243.41 - * particular instance behave as if they occur in some serial order
  243.42 - * that is consistent with the order of the method calls made by each of
  243.43 - * the individual threads involved.
  243.44 - * <p>
  243.45 - * The principal operations on a <code>StringBuffer</code> are the
  243.46 - * <code>append</code> and <code>insert</code> methods, which are
  243.47 - * overloaded so as to accept data of any type. Each effectively
  243.48 - * converts a given datum to a string and then appends or inserts the
  243.49 - * characters of that string to the string buffer. The
  243.50 - * <code>append</code> method always adds these characters at the end
  243.51 - * of the buffer; the <code>insert</code> method adds the characters at
  243.52 - * a specified point.
  243.53 - * <p>
  243.54 - * For example, if <code>z</code> refers to a string buffer object
  243.55 - * whose current contents are "<code>start</code>", then
  243.56 - * the method call <code>z.append("le")</code> would cause the string
  243.57 - * buffer to contain "<code>startle</code>", whereas
  243.58 - * <code>z.insert(4, "le")</code> would alter the string buffer to
  243.59 - * contain "<code>starlet</code>".
  243.60 - * <p>
  243.61 - * In general, if sb refers to an instance of a <code>StringBuffer</code>,
  243.62 - * then <code>sb.append(x)</code> has the same effect as
  243.63 - * <code>sb.insert(sb.length(),&nbsp;x)</code>.
  243.64 - * <p>
  243.65 - * Whenever an operation occurs involving a source sequence (such as
  243.66 - * appending or inserting from a source sequence) this class synchronizes
  243.67 - * only on the string buffer performing the operation, not on the source.
  243.68 - * <p>
  243.69 - * Every string buffer has a capacity. As long as the length of the
  243.70 - * character sequence contained in the string buffer does not exceed
  243.71 - * the capacity, it is not necessary to allocate a new internal
  243.72 - * buffer array. If the internal buffer overflows, it is
  243.73 - * automatically made larger.
  243.74 - *
  243.75 - * As of  release JDK 5, this class has been supplemented with an equivalent
  243.76 - * class designed for use by a single thread, {@link StringBuilder}.  The
  243.77 - * <tt>StringBuilder</tt> class should generally be used in preference to
  243.78 - * this one, as it supports all of the same operations but it is faster, as
  243.79 - * it performs no synchronization.
  243.80 - *
  243.81 - * @author      Arthur van Hoff
  243.82 - * @see     java.lang.StringBuilder
  243.83 - * @see     java.lang.String
  243.84 - * @since   JDK1.0
  243.85 - */
  243.86 - public final class StringBuffer
  243.87 -    extends AbstractStringBuilder
  243.88 -    implements java.io.Serializable, CharSequence
  243.89 -{
  243.90 -
  243.91 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
  243.92 -    static final long serialVersionUID = 3388685877147921107L;
  243.93 -
  243.94 -    /**
  243.95 -     * Constructs a string buffer with no characters in it and an
  243.96 -     * initial capacity of 16 characters.
  243.97 -     */
  243.98 -    public StringBuffer() {
  243.99 -        super(16);
 243.100 -    }
 243.101 -
 243.102 -    /**
 243.103 -     * Constructs a string buffer with no characters in it and
 243.104 -     * the specified initial capacity.
 243.105 -     *
 243.106 -     * @param      capacity  the initial capacity.
 243.107 -     * @exception  NegativeArraySizeException  if the <code>capacity</code>
 243.108 -     *               argument is less than <code>0</code>.
 243.109 -     */
 243.110 -    public StringBuffer(int capacity) {
 243.111 -        super(capacity);
 243.112 -    }
 243.113 -
 243.114 -    /**
 243.115 -     * Constructs a string buffer initialized to the contents of the
 243.116 -     * specified string. The initial capacity of the string buffer is
 243.117 -     * <code>16</code> plus the length of the string argument.
 243.118 -     *
 243.119 -     * @param   str   the initial contents of the buffer.
 243.120 -     * @exception NullPointerException if <code>str</code> is <code>null</code>
 243.121 -     */
 243.122 -    public StringBuffer(String str) {
 243.123 -        super(str.length() + 16);
 243.124 -        append(str);
 243.125 -    }
 243.126 -
 243.127 -    /**
 243.128 -     * Constructs a string buffer that contains the same characters
 243.129 -     * as the specified <code>CharSequence</code>. The initial capacity of
 243.130 -     * the string buffer is <code>16</code> plus the length of the
 243.131 -     * <code>CharSequence</code> argument.
 243.132 -     * <p>
 243.133 -     * If the length of the specified <code>CharSequence</code> is
 243.134 -     * less than or equal to zero, then an empty buffer of capacity
 243.135 -     * <code>16</code> is returned.
 243.136 -     *
 243.137 -     * @param      seq   the sequence to copy.
 243.138 -     * @exception NullPointerException if <code>seq</code> is <code>null</code>
 243.139 -     * @since 1.5
 243.140 -     */
 243.141 -    public StringBuffer(CharSequence seq) {
 243.142 -        this(seq.length() + 16);
 243.143 -        append(seq);
 243.144 -    }
 243.145 -
 243.146 -    public synchronized int length() {
 243.147 -        return count;
 243.148 -    }
 243.149 -
 243.150 -    public synchronized int capacity() {
 243.151 -        return value.length;
 243.152 -    }
 243.153 -
 243.154 -
 243.155 -    public synchronized void ensureCapacity(int minimumCapacity) {
 243.156 -        if (minimumCapacity > value.length) {
 243.157 -            expandCapacity(minimumCapacity);
 243.158 -        }
 243.159 -    }
 243.160 -
 243.161 -    /**
 243.162 -     * @since      1.5
 243.163 -     */
 243.164 -    public synchronized void trimToSize() {
 243.165 -        super.trimToSize();
 243.166 -    }
 243.167 -
 243.168 -    /**
 243.169 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 243.170 -     * @see        #length()
 243.171 -     */
 243.172 -    public synchronized void setLength(int newLength) {
 243.173 -        super.setLength(newLength);
 243.174 -    }
 243.175 -
 243.176 -    /**
 243.177 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 243.178 -     * @see        #length()
 243.179 -     */
 243.180 -    public synchronized char charAt(int index) {
 243.181 -        if ((index < 0) || (index >= count))
 243.182 -            throw new StringIndexOutOfBoundsException(index);
 243.183 -        return value[index];
 243.184 -    }
 243.185 -
 243.186 -    /**
 243.187 -     * @since      1.5
 243.188 -     */
 243.189 -    public synchronized int codePointAt(int index) {
 243.190 -        return super.codePointAt(index);
 243.191 -    }
 243.192 -
 243.193 -    /**
 243.194 -     * @since     1.5
 243.195 -     */
 243.196 -    public synchronized int codePointBefore(int index) {
 243.197 -        return super.codePointBefore(index);
 243.198 -    }
 243.199 -
 243.200 -    /**
 243.201 -     * @since     1.5
 243.202 -     */
 243.203 -    public synchronized int codePointCount(int beginIndex, int endIndex) {
 243.204 -        return super.codePointCount(beginIndex, endIndex);
 243.205 -    }
 243.206 -
 243.207 -    /**
 243.208 -     * @since     1.5
 243.209 -     */
 243.210 -    public synchronized int offsetByCodePoints(int index, int codePointOffset) {
 243.211 -        return super.offsetByCodePoints(index, codePointOffset);
 243.212 -    }
 243.213 -
 243.214 -    /**
 243.215 -     * @throws NullPointerException {@inheritDoc}
 243.216 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 243.217 -     */
 243.218 -    public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
 243.219 -                                      int dstBegin)
 243.220 -    {
 243.221 -        super.getChars(srcBegin, srcEnd, dst, dstBegin);
 243.222 -    }
 243.223 -
 243.224 -    /**
 243.225 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 243.226 -     * @see        #length()
 243.227 -     */
 243.228 -    public synchronized void setCharAt(int index, char ch) {
 243.229 -        if ((index < 0) || (index >= count))
 243.230 -            throw new StringIndexOutOfBoundsException(index);
 243.231 -        value[index] = ch;
 243.232 -    }
 243.233 -
 243.234 -    public synchronized StringBuffer append(Object obj) {
 243.235 -        super.append(String.valueOf(obj));
 243.236 -        return this;
 243.237 -    }
 243.238 -
 243.239 -    public synchronized StringBuffer append(String str) {
 243.240 -        super.append(str);
 243.241 -        return this;
 243.242 -    }
 243.243 -
 243.244 -    /**
 243.245 -     * Appends the specified <tt>StringBuffer</tt> to this sequence.
 243.246 -     * <p>
 243.247 -     * The characters of the <tt>StringBuffer</tt> argument are appended,
 243.248 -     * in order, to the contents of this <tt>StringBuffer</tt>, increasing the
 243.249 -     * length of this <tt>StringBuffer</tt> by the length of the argument.
 243.250 -     * If <tt>sb</tt> is <tt>null</tt>, then the four characters
 243.251 -     * <tt>"null"</tt> are appended to this <tt>StringBuffer</tt>.
 243.252 -     * <p>
 243.253 -     * Let <i>n</i> be the length of the old character sequence, the one
 243.254 -     * contained in the <tt>StringBuffer</tt> just prior to execution of the
 243.255 -     * <tt>append</tt> method. Then the character at index <i>k</i> in
 243.256 -     * the new character sequence is equal to the character at index <i>k</i>
 243.257 -     * in the old character sequence, if <i>k</i> is less than <i>n</i>;
 243.258 -     * otherwise, it is equal to the character at index <i>k-n</i> in the
 243.259 -     * argument <code>sb</code>.
 243.260 -     * <p>
 243.261 -     * This method synchronizes on <code>this</code> (the destination)
 243.262 -     * object but does not synchronize on the source (<code>sb</code>).
 243.263 -     *
 243.264 -     * @param   sb   the <tt>StringBuffer</tt> to append.
 243.265 -     * @return  a reference to this object.
 243.266 -     * @since 1.4
 243.267 -     */
 243.268 -    public synchronized StringBuffer append(StringBuffer sb) {
 243.269 -        super.append(sb);
 243.270 -        return this;
 243.271 -    }
 243.272 -
 243.273 -
 243.274 -    /**
 243.275 -     * Appends the specified <code>CharSequence</code> to this
 243.276 -     * sequence.
 243.277 -     * <p>
 243.278 -     * The characters of the <code>CharSequence</code> argument are appended,
 243.279 -     * in order, increasing the length of this sequence by the length of the
 243.280 -     * argument.
 243.281 -     *
 243.282 -     * <p>The result of this method is exactly the same as if it were an
 243.283 -     * invocation of this.append(s, 0, s.length());
 243.284 -     *
 243.285 -     * <p>This method synchronizes on this (the destination)
 243.286 -     * object but does not synchronize on the source (<code>s</code>).
 243.287 -     *
 243.288 -     * <p>If <code>s</code> is <code>null</code>, then the four characters
 243.289 -     * <code>"null"</code> are appended.
 243.290 -     *
 243.291 -     * @param   s the <code>CharSequence</code> to append.
 243.292 -     * @return  a reference to this object.
 243.293 -     * @since 1.5
 243.294 -     */
 243.295 -    public StringBuffer append(CharSequence s) {
 243.296 -        // Note, synchronization achieved via other invocations
 243.297 -        if (s == null)
 243.298 -            s = "null";
 243.299 -        if (s instanceof String)
 243.300 -            return this.append((String)s);
 243.301 -        if (s instanceof StringBuffer)
 243.302 -            return this.append((StringBuffer)s);
 243.303 -        return this.append(s, 0, s.length());
 243.304 -    }
 243.305 -
 243.306 -    /**
 243.307 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 243.308 -     * @since      1.5
 243.309 -     */
 243.310 -    public synchronized StringBuffer append(CharSequence s, int start, int end)
 243.311 -    {
 243.312 -        super.append(s, start, end);
 243.313 -        return this;
 243.314 -    }
 243.315 -
 243.316 -    public synchronized StringBuffer append(char[] str) {
 243.317 -        super.append(str);
 243.318 -        return this;
 243.319 -    }
 243.320 -
 243.321 -    /**
 243.322 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 243.323 -     */
 243.324 -    public synchronized StringBuffer append(char[] str, int offset, int len) {
 243.325 -        super.append(str, offset, len);
 243.326 -        return this;
 243.327 -    }
 243.328 -
 243.329 -    public synchronized StringBuffer append(boolean b) {
 243.330 -        super.append(b);
 243.331 -        return this;
 243.332 -    }
 243.333 -
 243.334 -    public synchronized StringBuffer append(char c) {
 243.335 -        super.append(c);
 243.336 -        return this;
 243.337 -    }
 243.338 -
 243.339 -    public synchronized StringBuffer append(int i) {
 243.340 -        super.append(i);
 243.341 -        return this;
 243.342 -    }
 243.343 -
 243.344 -    /**
 243.345 -     * @since 1.5
 243.346 -     */
 243.347 -    public synchronized StringBuffer appendCodePoint(int codePoint) {
 243.348 -        super.appendCodePoint(codePoint);
 243.349 -        return this;
 243.350 -    }
 243.351 -
 243.352 -    public synchronized StringBuffer append(long lng) {
 243.353 -        super.append(lng);
 243.354 -        return this;
 243.355 -    }
 243.356 -
 243.357 -    public synchronized StringBuffer append(float f) {
 243.358 -        super.append(f);
 243.359 -        return this;
 243.360 -    }
 243.361 -
 243.362 -    public synchronized StringBuffer append(double d) {
 243.363 -        super.append(d);
 243.364 -        return this;
 243.365 -    }
 243.366 -
 243.367 -    /**
 243.368 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.369 -     * @since      1.2
 243.370 -     */
 243.371 -    public synchronized StringBuffer delete(int start, int end) {
 243.372 -        super.delete(start, end);
 243.373 -        return this;
 243.374 -    }
 243.375 -
 243.376 -    /**
 243.377 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.378 -     * @since      1.2
 243.379 -     */
 243.380 -    public synchronized StringBuffer deleteCharAt(int index) {
 243.381 -        super.deleteCharAt(index);
 243.382 -        return this;
 243.383 -    }
 243.384 -
 243.385 -    /**
 243.386 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.387 -     * @since      1.2
 243.388 -     */
 243.389 -    public synchronized StringBuffer replace(int start, int end, String str) {
 243.390 -        super.replace(start, end, str);
 243.391 -        return this;
 243.392 -    }
 243.393 -
 243.394 -    /**
 243.395 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.396 -     * @since      1.2
 243.397 -     */
 243.398 -    public synchronized String substring(int start) {
 243.399 -        return substring(start, count);
 243.400 -    }
 243.401 -
 243.402 -    /**
 243.403 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 243.404 -     * @since      1.4
 243.405 -     */
 243.406 -    public synchronized CharSequence subSequence(int start, int end) {
 243.407 -        return super.substring(start, end);
 243.408 -    }
 243.409 -
 243.410 -    /**
 243.411 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.412 -     * @since      1.2
 243.413 -     */
 243.414 -    public synchronized String substring(int start, int end) {
 243.415 -        return super.substring(start, end);
 243.416 -    }
 243.417 -
 243.418 -    /**
 243.419 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.420 -     * @since      1.2
 243.421 -     */
 243.422 -    public synchronized StringBuffer insert(int index, char[] str, int offset,
 243.423 -                                            int len)
 243.424 -    {
 243.425 -        super.insert(index, str, offset, len);
 243.426 -        return this;
 243.427 -    }
 243.428 -
 243.429 -    /**
 243.430 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.431 -     */
 243.432 -    public synchronized StringBuffer insert(int offset, Object obj) {
 243.433 -        super.insert(offset, String.valueOf(obj));
 243.434 -        return this;
 243.435 -    }
 243.436 -
 243.437 -    /**
 243.438 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.439 -     */
 243.440 -    public synchronized StringBuffer insert(int offset, String str) {
 243.441 -        super.insert(offset, str);
 243.442 -        return this;
 243.443 -    }
 243.444 -
 243.445 -    /**
 243.446 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.447 -     */
 243.448 -    public synchronized StringBuffer insert(int offset, char[] str) {
 243.449 -        super.insert(offset, str);
 243.450 -        return this;
 243.451 -    }
 243.452 -
 243.453 -    /**
 243.454 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 243.455 -     * @since      1.5
 243.456 -     */
 243.457 -    public StringBuffer insert(int dstOffset, CharSequence s) {
 243.458 -        // Note, synchronization achieved via other invocations
 243.459 -        if (s == null)
 243.460 -            s = "null";
 243.461 -        if (s instanceof String)
 243.462 -            return this.insert(dstOffset, (String)s);
 243.463 -        return this.insert(dstOffset, s, 0, s.length());
 243.464 -    }
 243.465 -
 243.466 -    /**
 243.467 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 243.468 -     * @since      1.5
 243.469 -     */
 243.470 -    public synchronized StringBuffer insert(int dstOffset, CharSequence s,
 243.471 -                                            int start, int end)
 243.472 -    {
 243.473 -        super.insert(dstOffset, s, start, end);
 243.474 -        return this;
 243.475 -    }
 243.476 -
 243.477 -    /**
 243.478 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.479 -     */
 243.480 -    public StringBuffer insert(int offset, boolean b) {
 243.481 -        return insert(offset, String.valueOf(b));
 243.482 -    }
 243.483 -
 243.484 -    /**
 243.485 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 243.486 -     */
 243.487 -    public synchronized StringBuffer insert(int offset, char c) {
 243.488 -        super.insert(offset, c);
 243.489 -        return this;
 243.490 -    }
 243.491 -
 243.492 -    /**
 243.493 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.494 -     */
 243.495 -    public StringBuffer insert(int offset, int i) {
 243.496 -        return insert(offset, String.valueOf(i));
 243.497 -    }
 243.498 -
 243.499 -    /**
 243.500 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.501 -     */
 243.502 -    public StringBuffer insert(int offset, long l) {
 243.503 -        return insert(offset, String.valueOf(l));
 243.504 -    }
 243.505 -
 243.506 -    /**
 243.507 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.508 -     */
 243.509 -    public StringBuffer insert(int offset, float f) {
 243.510 -        return insert(offset, String.valueOf(f));
 243.511 -    }
 243.512 -
 243.513 -    /**
 243.514 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 243.515 -     */
 243.516 -    public StringBuffer insert(int offset, double d) {
 243.517 -        return insert(offset, String.valueOf(d));
 243.518 -    }
 243.519 -
 243.520 -    /**
 243.521 -     * @throws NullPointerException {@inheritDoc}
 243.522 -     * @since      1.4
 243.523 -     */
 243.524 -    public int indexOf(String str) {
 243.525 -        return indexOf(str, 0);
 243.526 -    }
 243.527 -
 243.528 -    /**
 243.529 -     * @throws NullPointerException {@inheritDoc}
 243.530 -     * @since      1.4
 243.531 -     */
 243.532 -    public synchronized int indexOf(String str, int fromIndex) {
 243.533 -        return String.indexOf(value, 0, count,
 243.534 -                              str.toCharArray(), 0, str.length(), fromIndex);
 243.535 -    }
 243.536 -
 243.537 -    /**
 243.538 -     * @throws NullPointerException {@inheritDoc}
 243.539 -     * @since      1.4
 243.540 -     */
 243.541 -    public int lastIndexOf(String str) {
 243.542 -        // Note, synchronization achieved via other invocations
 243.543 -        return lastIndexOf(str, count);
 243.544 -    }
 243.545 -
 243.546 -    /**
 243.547 -     * @throws NullPointerException {@inheritDoc}
 243.548 -     * @since      1.4
 243.549 -     */
 243.550 -    public synchronized int lastIndexOf(String str, int fromIndex) {
 243.551 -        return String.lastIndexOf(value, 0, count,
 243.552 -                              str.toCharArray(), 0, str.length(), fromIndex);
 243.553 -    }
 243.554 -
 243.555 -    /**
 243.556 -     * @since   JDK1.0.2
 243.557 -     */
 243.558 -    public synchronized StringBuffer reverse() {
 243.559 -        super.reverse();
 243.560 -        return this;
 243.561 -    }
 243.562 -
 243.563 -    public synchronized String toString() {
 243.564 -        return new String(value, 0, count);
 243.565 -    }
 243.566 -
 243.567 -//    /**
 243.568 -//     * Serializable fields for StringBuffer.
 243.569 -//     *
 243.570 -//     * @serialField value  char[]
 243.571 -//     *              The backing character array of this StringBuffer.
 243.572 -//     * @serialField count int
 243.573 -//     *              The number of characters in this StringBuffer.
 243.574 -//     * @serialField shared  boolean
 243.575 -//     *              A flag indicating whether the backing array is shared.
 243.576 -//     *              The value is ignored upon deserialization.
 243.577 -//     */
 243.578 -//    private static final java.io.ObjectStreamField[] serialPersistentFields =
 243.579 -//    {
 243.580 -//        new java.io.ObjectStreamField("value", char[].class),
 243.581 -//        new java.io.ObjectStreamField("count", Integer.TYPE),
 243.582 -//        new java.io.ObjectStreamField("shared", Boolean.TYPE),
 243.583 -//    };
 243.584 -//
 243.585 -//    /**
 243.586 -//     * readObject is called to restore the state of the StringBuffer from
 243.587 -//     * a stream.
 243.588 -//     */
 243.589 -//    private synchronized void writeObject(java.io.ObjectOutputStream s)
 243.590 -//        throws java.io.IOException {
 243.591 -//        java.io.ObjectOutputStream.PutField fields = s.putFields();
 243.592 -//        fields.put("value", value);
 243.593 -//        fields.put("count", count);
 243.594 -//        fields.put("shared", false);
 243.595 -//        s.writeFields();
 243.596 -//    }
 243.597 -//
 243.598 -//    /**
 243.599 -//     * readObject is called to restore the state of the StringBuffer from
 243.600 -//     * a stream.
 243.601 -//     */
 243.602 -//    private void readObject(java.io.ObjectInputStream s)
 243.603 -//        throws java.io.IOException, ClassNotFoundException {
 243.604 -//        java.io.ObjectInputStream.GetField fields = s.readFields();
 243.605 -//        value = (char[])fields.get("value", null);
 243.606 -//        count = fields.get("count", 0);
 243.607 -//    }
 243.608 -}
   244.1 --- a/emul/src/main/java/java/lang/StringBuilder.java	Wed Dec 05 10:03:58 2012 +0100
   244.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   244.3 @@ -1,437 +0,0 @@
   244.4 -/*
   244.5 - * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
   244.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   244.7 - *
   244.8 - * This code is free software; you can redistribute it and/or modify it
   244.9 - * under the terms of the GNU General Public License version 2 only, as
  244.10 - * published by the Free Software Foundation.  Oracle designates this
  244.11 - * particular file as subject to the "Classpath" exception as provided
  244.12 - * by Oracle in the LICENSE file that accompanied this code.
  244.13 - *
  244.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  244.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  244.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  244.17 - * version 2 for more details (a copy is included in the LICENSE file that
  244.18 - * accompanied this code).
  244.19 - *
  244.20 - * You should have received a copy of the GNU General Public License version
  244.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  244.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  244.23 - *
  244.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  244.25 - * or visit www.oracle.com if you need additional information or have any
  244.26 - * questions.
  244.27 - */
  244.28 -
  244.29 -package java.lang;
  244.30 -
  244.31 -
  244.32 -/**
  244.33 - * A mutable sequence of characters.  This class provides an API compatible
  244.34 - * with <code>StringBuffer</code>, but with no guarantee of synchronization.
  244.35 - * This class is designed for use as a drop-in replacement for
  244.36 - * <code>StringBuffer</code> in places where the string buffer was being
  244.37 - * used by a single thread (as is generally the case).   Where possible,
  244.38 - * it is recommended that this class be used in preference to
  244.39 - * <code>StringBuffer</code> as it will be faster under most implementations.
  244.40 - *
  244.41 - * <p>The principal operations on a <code>StringBuilder</code> are the
  244.42 - * <code>append</code> and <code>insert</code> methods, which are
  244.43 - * overloaded so as to accept data of any type. Each effectively
  244.44 - * converts a given datum to a string and then appends or inserts the
  244.45 - * characters of that string to the string builder. The
  244.46 - * <code>append</code> method always adds these characters at the end
  244.47 - * of the builder; the <code>insert</code> method adds the characters at
  244.48 - * a specified point.
  244.49 - * <p>
  244.50 - * For example, if <code>z</code> refers to a string builder object
  244.51 - * whose current contents are "<code>start</code>", then
  244.52 - * the method call <code>z.append("le")</code> would cause the string
  244.53 - * builder to contain "<code>startle</code>", whereas
  244.54 - * <code>z.insert(4, "le")</code> would alter the string builder to
  244.55 - * contain "<code>starlet</code>".
  244.56 - * <p>
  244.57 - * In general, if sb refers to an instance of a <code>StringBuilder</code>,
  244.58 - * then <code>sb.append(x)</code> has the same effect as
  244.59 - * <code>sb.insert(sb.length(),&nbsp;x)</code>.
  244.60 - *
  244.61 - * Every string builder has a capacity. As long as the length of the
  244.62 - * character sequence contained in the string builder does not exceed
  244.63 - * the capacity, it is not necessary to allocate a new internal
  244.64 - * buffer. If the internal buffer overflows, it is automatically made larger.
  244.65 - *
  244.66 - * <p>Instances of <code>StringBuilder</code> are not safe for
  244.67 - * use by multiple threads. If such synchronization is required then it is
  244.68 - * recommended that {@link java.lang.StringBuffer} be used.
  244.69 - *
  244.70 - * @author      Michael McCloskey
  244.71 - * @see         java.lang.StringBuffer
  244.72 - * @see         java.lang.String
  244.73 - * @since       1.5
  244.74 - */
  244.75 -public final class StringBuilder
  244.76 -    extends AbstractStringBuilder
  244.77 -    implements java.io.Serializable, CharSequence
  244.78 -{
  244.79 -
  244.80 -    /** use serialVersionUID for interoperability */
  244.81 -    static final long serialVersionUID = 4383685877147921099L;
  244.82 -
  244.83 -    /**
  244.84 -     * Constructs a string builder with no characters in it and an
  244.85 -     * initial capacity of 16 characters.
  244.86 -     */
  244.87 -    public StringBuilder() {
  244.88 -        super(16);
  244.89 -    }
  244.90 -
  244.91 -    /**
  244.92 -     * Constructs a string builder with no characters in it and an
  244.93 -     * initial capacity specified by the <code>capacity</code> argument.
  244.94 -     *
  244.95 -     * @param      capacity  the initial capacity.
  244.96 -     * @throws     NegativeArraySizeException  if the <code>capacity</code>
  244.97 -     *               argument is less than <code>0</code>.
  244.98 -     */
  244.99 -    public StringBuilder(int capacity) {
 244.100 -        super(capacity);
 244.101 -    }
 244.102 -
 244.103 -    /**
 244.104 -     * Constructs a string builder initialized to the contents of the
 244.105 -     * specified string. The initial capacity of the string builder is
 244.106 -     * <code>16</code> plus the length of the string argument.
 244.107 -     *
 244.108 -     * @param   str   the initial contents of the buffer.
 244.109 -     * @throws    NullPointerException if <code>str</code> is <code>null</code>
 244.110 -     */
 244.111 -    public StringBuilder(String str) {
 244.112 -        super(str.length() + 16);
 244.113 -        append(str);
 244.114 -    }
 244.115 -
 244.116 -    /**
 244.117 -     * Constructs a string builder that contains the same characters
 244.118 -     * as the specified <code>CharSequence</code>. The initial capacity of
 244.119 -     * the string builder is <code>16</code> plus the length of the
 244.120 -     * <code>CharSequence</code> argument.
 244.121 -     *
 244.122 -     * @param      seq   the sequence to copy.
 244.123 -     * @throws    NullPointerException if <code>seq</code> is <code>null</code>
 244.124 -     */
 244.125 -    public StringBuilder(CharSequence seq) {
 244.126 -        this(seq.length() + 16);
 244.127 -        append(seq);
 244.128 -    }
 244.129 -
 244.130 -    public StringBuilder append(Object obj) {
 244.131 -        return append(String.valueOf(obj));
 244.132 -    }
 244.133 -
 244.134 -    public StringBuilder append(String str) {
 244.135 -        super.append(str);
 244.136 -        return this;
 244.137 -    }
 244.138 -
 244.139 -    // Appends the specified string builder to this sequence.
 244.140 -    private StringBuilder append(StringBuilder sb) {
 244.141 -        if (sb == null)
 244.142 -            return append("null");
 244.143 -        int len = sb.length();
 244.144 -        int newcount = count + len;
 244.145 -        if (newcount > value.length)
 244.146 -            expandCapacity(newcount);
 244.147 -        sb.getChars(0, len, value, count);
 244.148 -        count = newcount;
 244.149 -        return this;
 244.150 -    }
 244.151 -
 244.152 -    /**
 244.153 -     * Appends the specified <tt>StringBuffer</tt> to this sequence.
 244.154 -     * <p>
 244.155 -     * The characters of the <tt>StringBuffer</tt> argument are appended,
 244.156 -     * in order, to this sequence, increasing the
 244.157 -     * length of this sequence by the length of the argument.
 244.158 -     * If <tt>sb</tt> is <tt>null</tt>, then the four characters
 244.159 -     * <tt>"null"</tt> are appended to this sequence.
 244.160 -     * <p>
 244.161 -     * Let <i>n</i> be the length of this character sequence just prior to
 244.162 -     * execution of the <tt>append</tt> method. Then the character at index
 244.163 -     * <i>k</i> in the new character sequence is equal to the character at
 244.164 -     * index <i>k</i> in the old character sequence, if <i>k</i> is less than
 244.165 -     * <i>n</i>; otherwise, it is equal to the character at index <i>k-n</i>
 244.166 -     * in the argument <code>sb</code>.
 244.167 -     *
 244.168 -     * @param   sb   the <tt>StringBuffer</tt> to append.
 244.169 -     * @return  a reference to this object.
 244.170 -     */
 244.171 -    public StringBuilder append(StringBuffer sb) {
 244.172 -        super.append(sb);
 244.173 -        return this;
 244.174 -    }
 244.175 -
 244.176 -    /**
 244.177 -     */
 244.178 -    public StringBuilder append(CharSequence s) {
 244.179 -        if (s == null)
 244.180 -            s = "null";
 244.181 -        if (s instanceof String)
 244.182 -            return this.append((String)s);
 244.183 -        if (s instanceof StringBuffer)
 244.184 -            return this.append((StringBuffer)s);
 244.185 -        if (s instanceof StringBuilder)
 244.186 -            return this.append((StringBuilder)s);
 244.187 -        return this.append(s, 0, s.length());
 244.188 -    }
 244.189 -
 244.190 -    /**
 244.191 -     * @throws     IndexOutOfBoundsException {@inheritDoc}
 244.192 -     */
 244.193 -    public StringBuilder append(CharSequence s, int start, int end) {
 244.194 -        super.append(s, start, end);
 244.195 -        return this;
 244.196 -    }
 244.197 -
 244.198 -    public StringBuilder append(char[] str) {
 244.199 -        super.append(str);
 244.200 -        return this;
 244.201 -    }
 244.202 -
 244.203 -    /**
 244.204 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 244.205 -     */
 244.206 -    public StringBuilder append(char[] str, int offset, int len) {
 244.207 -        super.append(str, offset, len);
 244.208 -        return this;
 244.209 -    }
 244.210 -
 244.211 -    public StringBuilder append(boolean b) {
 244.212 -        super.append(b);
 244.213 -        return this;
 244.214 -    }
 244.215 -
 244.216 -    public StringBuilder append(char c) {
 244.217 -        super.append(c);
 244.218 -        return this;
 244.219 -    }
 244.220 -
 244.221 -    public StringBuilder append(int i) {
 244.222 -        super.append(i);
 244.223 -        return this;
 244.224 -    }
 244.225 -
 244.226 -    public StringBuilder append(long lng) {
 244.227 -        super.append(lng);
 244.228 -        return this;
 244.229 -    }
 244.230 -
 244.231 -    public StringBuilder append(float f) {
 244.232 -        super.append(f);
 244.233 -        return this;
 244.234 -    }
 244.235 -
 244.236 -    public StringBuilder append(double d) {
 244.237 -        super.append(d);
 244.238 -        return this;
 244.239 -    }
 244.240 -
 244.241 -    /**
 244.242 -     * @since 1.5
 244.243 -     */
 244.244 -    public StringBuilder appendCodePoint(int codePoint) {
 244.245 -        super.appendCodePoint(codePoint);
 244.246 -        return this;
 244.247 -    }
 244.248 -
 244.249 -    /**
 244.250 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 244.251 -     */
 244.252 -    public StringBuilder delete(int start, int end) {
 244.253 -        super.delete(start, end);
 244.254 -        return this;
 244.255 -    }
 244.256 -
 244.257 -    /**
 244.258 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 244.259 -     */
 244.260 -    public StringBuilder deleteCharAt(int index) {
 244.261 -        super.deleteCharAt(index);
 244.262 -        return this;
 244.263 -    }
 244.264 -
 244.265 -    /**
 244.266 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 244.267 -     */
 244.268 -    public StringBuilder replace(int start, int end, String str) {
 244.269 -        super.replace(start, end, str);
 244.270 -        return this;
 244.271 -    }
 244.272 -
 244.273 -    /**
 244.274 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 244.275 -     */
 244.276 -    public StringBuilder insert(int index, char[] str, int offset,
 244.277 -                                int len)
 244.278 -    {
 244.279 -        super.insert(index, str, offset, len);
 244.280 -        return this;
 244.281 -    }
 244.282 -
 244.283 -    /**
 244.284 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 244.285 -     */
 244.286 -    public StringBuilder insert(int offset, Object obj) {
 244.287 -        return insert(offset, String.valueOf(obj));
 244.288 -    }
 244.289 -
 244.290 -    /**
 244.291 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 244.292 -     */
 244.293 -    public StringBuilder insert(int offset, String str) {
 244.294 -        super.insert(offset, str);
 244.295 -        return this;
 244.296 -    }
 244.297 -
 244.298 -    /**
 244.299 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 244.300 -     */
 244.301 -    public StringBuilder insert(int offset, char[] str) {
 244.302 -        super.insert(offset, str);
 244.303 -        return this;
 244.304 -    }
 244.305 -
 244.306 -    /**
 244.307 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 244.308 -     */
 244.309 -    public StringBuilder insert(int dstOffset, CharSequence s) {
 244.310 -        if (s == null)
 244.311 -            s = "null";
 244.312 -        if (s instanceof String)
 244.313 -            return this.insert(dstOffset, (String)s);
 244.314 -        return this.insert(dstOffset, s, 0, s.length());
 244.315 -    }
 244.316 -
 244.317 -    /**
 244.318 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 244.319 -     */
 244.320 -    public StringBuilder insert(int dstOffset, CharSequence s,
 244.321 -                                int start, int end)
 244.322 -    {
 244.323 -        super.insert(dstOffset, s, start, end);
 244.324 -        return this;
 244.325 -    }
 244.326 -
 244.327 -    /**
 244.328 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 244.329 -     */
 244.330 -    public StringBuilder insert(int offset, boolean b) {
 244.331 -        super.insert(offset, b);
 244.332 -        return this;
 244.333 -    }
 244.334 -
 244.335 -    /**
 244.336 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 244.337 -     */
 244.338 -    public StringBuilder insert(int offset, char c) {
 244.339 -        super.insert(offset, c);
 244.340 -        return this;
 244.341 -    }
 244.342 -
 244.343 -    /**
 244.344 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 244.345 -     */
 244.346 -    public StringBuilder insert(int offset, int i) {
 244.347 -        return insert(offset, String.valueOf(i));
 244.348 -    }
 244.349 -
 244.350 -    /**
 244.351 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 244.352 -     */
 244.353 -    public StringBuilder insert(int offset, long l) {
 244.354 -        return insert(offset, String.valueOf(l));
 244.355 -    }
 244.356 -
 244.357 -    /**
 244.358 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 244.359 -     */
 244.360 -    public StringBuilder insert(int offset, float f) {
 244.361 -        return insert(offset, String.valueOf(f));
 244.362 -    }
 244.363 -
 244.364 -    /**
 244.365 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 244.366 -     */
 244.367 -    public StringBuilder insert(int offset, double d) {
 244.368 -        return insert(offset, String.valueOf(d));
 244.369 -    }
 244.370 -
 244.371 -    /**
 244.372 -     * @throws NullPointerException {@inheritDoc}
 244.373 -     */
 244.374 -    public int indexOf(String str) {
 244.375 -        return indexOf(str, 0);
 244.376 -    }
 244.377 -
 244.378 -    /**
 244.379 -     * @throws NullPointerException {@inheritDoc}
 244.380 -     */
 244.381 -    public int indexOf(String str, int fromIndex) {
 244.382 -        return String.indexOf(value, 0, count,
 244.383 -                              str.toCharArray(), 0, str.length(), fromIndex);
 244.384 -    }
 244.385 -
 244.386 -    /**
 244.387 -     * @throws NullPointerException {@inheritDoc}
 244.388 -     */
 244.389 -    public int lastIndexOf(String str) {
 244.390 -        return lastIndexOf(str, count);
 244.391 -    }
 244.392 -
 244.393 -    /**
 244.394 -     * @throws NullPointerException {@inheritDoc}
 244.395 -     */
 244.396 -    public int lastIndexOf(String str, int fromIndex) {
 244.397 -        return String.lastIndexOf(value, 0, count,
 244.398 -                              str.toCharArray(), 0, str.length(), fromIndex);
 244.399 -    }
 244.400 -
 244.401 -    public StringBuilder reverse() {
 244.402 -        super.reverse();
 244.403 -        return this;
 244.404 -    }
 244.405 -
 244.406 -    public String toString() {
 244.407 -        // Create a copy, don't share the array
 244.408 -        return new String(value, 0, count);
 244.409 -    }
 244.410 -
 244.411 -    /**
 244.412 -     * Save the state of the <tt>StringBuilder</tt> instance to a stream
 244.413 -     * (that is, serialize it).
 244.414 -     *
 244.415 -     * @serialData the number of characters currently stored in the string
 244.416 -     *             builder (<tt>int</tt>), followed by the characters in the
 244.417 -     *             string builder (<tt>char[]</tt>).   The length of the
 244.418 -     *             <tt>char</tt> array may be greater than the number of
 244.419 -     *             characters currently stored in the string builder, in which
 244.420 -     *             case extra characters are ignored.
 244.421 -     */
 244.422 -//    private void writeObject(java.io.ObjectOutputStream s)
 244.423 -//        throws java.io.IOException {
 244.424 -//        s.defaultWriteObject();
 244.425 -//        s.writeInt(count);
 244.426 -//        s.writeObject(value);
 244.427 -//    }
 244.428 -
 244.429 -    /**
 244.430 -     * readObject is called to restore the state of the StringBuffer from
 244.431 -     * a stream.
 244.432 -     */
 244.433 -//    private void readObject(java.io.ObjectInputStream s)
 244.434 -//        throws java.io.IOException, ClassNotFoundException {
 244.435 -//        s.defaultReadObject();
 244.436 -//        count = s.readInt();
 244.437 -//        value = (char[]) s.readObject();
 244.438 -//    }
 244.439 -
 244.440 -}
   245.1 --- a/emul/src/main/java/java/lang/StringIndexOutOfBoundsException.java	Wed Dec 05 10:03:58 2012 +0100
   245.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   245.3 @@ -1,71 +0,0 @@
   245.4 -/*
   245.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   245.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   245.7 - *
   245.8 - * This code is free software; you can redistribute it and/or modify it
   245.9 - * under the terms of the GNU General Public License version 2 only, as
  245.10 - * published by the Free Software Foundation.  Oracle designates this
  245.11 - * particular file as subject to the "Classpath" exception as provided
  245.12 - * by Oracle in the LICENSE file that accompanied this code.
  245.13 - *
  245.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  245.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  245.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  245.17 - * version 2 for more details (a copy is included in the LICENSE file that
  245.18 - * accompanied this code).
  245.19 - *
  245.20 - * You should have received a copy of the GNU General Public License version
  245.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  245.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  245.23 - *
  245.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  245.25 - * or visit www.oracle.com if you need additional information or have any
  245.26 - * questions.
  245.27 - */
  245.28 -
  245.29 -package java.lang;
  245.30 -
  245.31 -/**
  245.32 - * Thrown by <code>String</code> methods to indicate that an index
  245.33 - * is either negative or greater than the size of the string.  For
  245.34 - * some methods such as the charAt method, this exception also is
  245.35 - * thrown when the index is equal to the size of the string.
  245.36 - *
  245.37 - * @author  unascribed
  245.38 - * @see     java.lang.String#charAt(int)
  245.39 - * @since   JDK1.0
  245.40 - */
  245.41 -public
  245.42 -class StringIndexOutOfBoundsException extends IndexOutOfBoundsException {
  245.43 -    private static final long serialVersionUID = -6762910422159637258L;
  245.44 -
  245.45 -    /**
  245.46 -     * Constructs a <code>StringIndexOutOfBoundsException</code> with no
  245.47 -     * detail message.
  245.48 -     *
  245.49 -     * @since   JDK1.0.
  245.50 -     */
  245.51 -    public StringIndexOutOfBoundsException() {
  245.52 -        super();
  245.53 -    }
  245.54 -
  245.55 -    /**
  245.56 -     * Constructs a <code>StringIndexOutOfBoundsException</code> with
  245.57 -     * the specified detail message.
  245.58 -     *
  245.59 -     * @param   s   the detail message.
  245.60 -     */
  245.61 -    public StringIndexOutOfBoundsException(String s) {
  245.62 -        super(s);
  245.63 -    }
  245.64 -
  245.65 -    /**
  245.66 -     * Constructs a new <code>StringIndexOutOfBoundsException</code>
  245.67 -     * class with an argument indicating the illegal index.
  245.68 -     *
  245.69 -     * @param   index   the illegal index.
  245.70 -     */
  245.71 -    public StringIndexOutOfBoundsException(int index) {
  245.72 -        super("String index out of range: " + index);
  245.73 -    }
  245.74 -}
   246.1 --- a/emul/src/main/java/java/lang/Throwable.java	Wed Dec 05 10:03:58 2012 +0100
   246.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   246.3 @@ -1,1080 +0,0 @@
   246.4 -/*
   246.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   246.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   246.7 - *
   246.8 - * This code is free software; you can redistribute it and/or modify it
   246.9 - * under the terms of the GNU General Public License version 2 only, as
  246.10 - * published by the Free Software Foundation.  Oracle designates this
  246.11 - * particular file as subject to the "Classpath" exception as provided
  246.12 - * by Oracle in the LICENSE file that accompanied this code.
  246.13 - *
  246.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  246.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  246.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  246.17 - * version 2 for more details (a copy is included in the LICENSE file that
  246.18 - * accompanied this code).
  246.19 - *
  246.20 - * You should have received a copy of the GNU General Public License version
  246.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  246.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  246.23 - *
  246.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  246.25 - * or visit www.oracle.com if you need additional information or have any
  246.26 - * questions.
  246.27 - */
  246.28 -
  246.29 -package java.lang;
  246.30 -import  java.io.*;
  246.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  246.32 -
  246.33 -/**
  246.34 - * The {@code Throwable} class is the superclass of all errors and
  246.35 - * exceptions in the Java language. Only objects that are instances of this
  246.36 - * class (or one of its subclasses) are thrown by the Java Virtual Machine or
  246.37 - * can be thrown by the Java {@code throw} statement. Similarly, only
  246.38 - * this class or one of its subclasses can be the argument type in a
  246.39 - * {@code catch} clause.
  246.40 - *
  246.41 - * For the purposes of compile-time checking of exceptions, {@code
  246.42 - * Throwable} and any subclass of {@code Throwable} that is not also a
  246.43 - * subclass of either {@link RuntimeException} or {@link Error} are
  246.44 - * regarded as checked exceptions.
  246.45 - *
  246.46 - * <p>Instances of two subclasses, {@link java.lang.Error} and
  246.47 - * {@link java.lang.Exception}, are conventionally used to indicate
  246.48 - * that exceptional situations have occurred. Typically, these instances
  246.49 - * are freshly created in the context of the exceptional situation so
  246.50 - * as to include relevant information (such as stack trace data).
  246.51 - *
  246.52 - * <p>A throwable contains a snapshot of the execution stack of its
  246.53 - * thread at the time it was created. It can also contain a message
  246.54 - * string that gives more information about the error. Over time, a
  246.55 - * throwable can {@linkplain Throwable#addSuppressed suppress} other
  246.56 - * throwables from being propagated.  Finally, the throwable can also
  246.57 - * contain a <i>cause</i>: another throwable that caused this
  246.58 - * throwable to be constructed.  The recording of this causal information
  246.59 - * is referred to as the <i>chained exception</i> facility, as the
  246.60 - * cause can, itself, have a cause, and so on, leading to a "chain" of
  246.61 - * exceptions, each caused by another.
  246.62 - *
  246.63 - * <p>One reason that a throwable may have a cause is that the class that
  246.64 - * throws it is built atop a lower layered abstraction, and an operation on
  246.65 - * the upper layer fails due to a failure in the lower layer.  It would be bad
  246.66 - * design to let the throwable thrown by the lower layer propagate outward, as
  246.67 - * it is generally unrelated to the abstraction provided by the upper layer.
  246.68 - * Further, doing so would tie the API of the upper layer to the details of
  246.69 - * its implementation, assuming the lower layer's exception was a checked
  246.70 - * exception.  Throwing a "wrapped exception" (i.e., an exception containing a
  246.71 - * cause) allows the upper layer to communicate the details of the failure to
  246.72 - * its caller without incurring either of these shortcomings.  It preserves
  246.73 - * the flexibility to change the implementation of the upper layer without
  246.74 - * changing its API (in particular, the set of exceptions thrown by its
  246.75 - * methods).
  246.76 - *
  246.77 - * <p>A second reason that a throwable may have a cause is that the method
  246.78 - * that throws it must conform to a general-purpose interface that does not
  246.79 - * permit the method to throw the cause directly.  For example, suppose
  246.80 - * a persistent collection conforms to the {@link java.util.Collection
  246.81 - * Collection} interface, and that its persistence is implemented atop
  246.82 - * {@code java.io}.  Suppose the internals of the {@code add} method
  246.83 - * can throw an {@link java.io.IOException IOException}.  The implementation
  246.84 - * can communicate the details of the {@code IOException} to its caller
  246.85 - * while conforming to the {@code Collection} interface by wrapping the
  246.86 - * {@code IOException} in an appropriate unchecked exception.  (The
  246.87 - * specification for the persistent collection should indicate that it is
  246.88 - * capable of throwing such exceptions.)
  246.89 - *
  246.90 - * <p>A cause can be associated with a throwable in two ways: via a
  246.91 - * constructor that takes the cause as an argument, or via the
  246.92 - * {@link #initCause(Throwable)} method.  New throwable classes that
  246.93 - * wish to allow causes to be associated with them should provide constructors
  246.94 - * that take a cause and delegate (perhaps indirectly) to one of the
  246.95 - * {@code Throwable} constructors that takes a cause.
  246.96 - *
  246.97 - * Because the {@code initCause} method is public, it allows a cause to be
  246.98 - * associated with any throwable, even a "legacy throwable" whose
  246.99 - * implementation predates the addition of the exception chaining mechanism to
 246.100 - * {@code Throwable}.
 246.101 - *
 246.102 - * <p>By convention, class {@code Throwable} and its subclasses have two
 246.103 - * constructors, one that takes no arguments and one that takes a
 246.104 - * {@code String} argument that can be used to produce a detail message.
 246.105 - * Further, those subclasses that might likely have a cause associated with
 246.106 - * them should have two more constructors, one that takes a
 246.107 - * {@code Throwable} (the cause), and one that takes a
 246.108 - * {@code String} (the detail message) and a {@code Throwable} (the
 246.109 - * cause).
 246.110 - *
 246.111 - * @author  unascribed
 246.112 - * @author  Josh Bloch (Added exception chaining and programmatic access to
 246.113 - *          stack trace in 1.4.)
 246.114 - * @jls 11.2 Compile-Time Checking of Exceptions
 246.115 - * @since JDK1.0
 246.116 - */
 246.117 -public class Throwable implements Serializable {
 246.118 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 246.119 -    private static final long serialVersionUID = -3042686055658047285L;
 246.120 -
 246.121 -    /**
 246.122 -     * Native code saves some indication of the stack backtrace in this slot.
 246.123 -     */
 246.124 -    private transient Object backtrace;
 246.125 -
 246.126 -    /**
 246.127 -     * Specific details about the Throwable.  For example, for
 246.128 -     * {@code FileNotFoundException}, this contains the name of
 246.129 -     * the file that could not be found.
 246.130 -     *
 246.131 -     * @serial
 246.132 -     */
 246.133 -    private String detailMessage;
 246.134 -
 246.135 -
 246.136 -    /**
 246.137 -     * Holder class to defer initializing sentinel objects only used
 246.138 -     * for serialization.
 246.139 -     */
 246.140 -    private static class SentinelHolder {
 246.141 -        /**
 246.142 -         * {@linkplain #setStackTrace(StackTraceElement[]) Setting the
 246.143 -         * stack trace} to a one-element array containing this sentinel
 246.144 -         * value indicates future attempts to set the stack trace will be
 246.145 -         * ignored.  The sentinal is equal to the result of calling:<br>
 246.146 -         * {@code new StackTraceElement("", "", null, Integer.MIN_VALUE)}
 246.147 -         */
 246.148 -        public static final StackTraceElement STACK_TRACE_ELEMENT_SENTINEL =
 246.149 -            new StackTraceElement("", "", null, Integer.MIN_VALUE);
 246.150 -
 246.151 -        /**
 246.152 -         * Sentinel value used in the serial form to indicate an immutable
 246.153 -         * stack trace.
 246.154 -         */
 246.155 -        public static final StackTraceElement[] STACK_TRACE_SENTINEL =
 246.156 -            new StackTraceElement[] {STACK_TRACE_ELEMENT_SENTINEL};
 246.157 -    }
 246.158 -
 246.159 -    /**
 246.160 -     * A shared value for an empty stack.
 246.161 -     */
 246.162 -    private static final StackTraceElement[] UNASSIGNED_STACK = new StackTraceElement[0];
 246.163 -
 246.164 -    /*
 246.165 -     * To allow Throwable objects to be made immutable and safely
 246.166 -     * reused by the JVM, such as OutOfMemoryErrors, fields of
 246.167 -     * Throwable that are writable in response to user actions, cause,
 246.168 -     * stackTrace, and suppressedExceptions obey the following
 246.169 -     * protocol:
 246.170 -     *
 246.171 -     * 1) The fields are initialized to a non-null sentinel value
 246.172 -     * which indicates the value has logically not been set.
 246.173 -     *
 246.174 -     * 2) Writing a null to the field indicates further writes
 246.175 -     * are forbidden
 246.176 -     *
 246.177 -     * 3) The sentinel value may be replaced with another non-null
 246.178 -     * value.
 246.179 -     *
 246.180 -     * For example, implementations of the HotSpot JVM have
 246.181 -     * preallocated OutOfMemoryError objects to provide for better
 246.182 -     * diagnosability of that situation.  These objects are created
 246.183 -     * without calling the constructor for that class and the fields
 246.184 -     * in question are initialized to null.  To support this
 246.185 -     * capability, any new fields added to Throwable that require
 246.186 -     * being initialized to a non-null value require a coordinated JVM
 246.187 -     * change.
 246.188 -     */
 246.189 -
 246.190 -    /**
 246.191 -     * The throwable that caused this throwable to get thrown, or null if this
 246.192 -     * throwable was not caused by another throwable, or if the causative
 246.193 -     * throwable is unknown.  If this field is equal to this throwable itself,
 246.194 -     * it indicates that the cause of this throwable has not yet been
 246.195 -     * initialized.
 246.196 -     *
 246.197 -     * @serial
 246.198 -     * @since 1.4
 246.199 -     */
 246.200 -    private Throwable cause = this;
 246.201 -
 246.202 -    /**
 246.203 -     * The stack trace, as returned by {@link #getStackTrace()}.
 246.204 -     *
 246.205 -     * The field is initialized to a zero-length array.  A {@code
 246.206 -     * null} value of this field indicates subsequent calls to {@link
 246.207 -     * #setStackTrace(StackTraceElement[])} and {@link
 246.208 -     * #fillInStackTrace()} will be be no-ops.
 246.209 -     *
 246.210 -     * @serial
 246.211 -     * @since 1.4
 246.212 -     */
 246.213 -    private StackTraceElement[] stackTrace = UNASSIGNED_STACK;
 246.214 -
 246.215 -    // Setting this static field introduces an acceptable
 246.216 -    // initialization dependency on a few java.util classes.
 246.217 -// I don't think this dependency is acceptable
 246.218 -//    private static final List<Throwable> SUPPRESSED_SENTINEL =
 246.219 -//        Collections.unmodifiableList(new ArrayList<Throwable>(0));
 246.220 -
 246.221 -    /**
 246.222 -     * The list of suppressed exceptions, as returned by {@link
 246.223 -     * #getSuppressed()}.  The list is initialized to a zero-element
 246.224 -     * unmodifiable sentinel list.  When a serialized Throwable is
 246.225 -     * read in, if the {@code suppressedExceptions} field points to a
 246.226 -     * zero-element list, the field is reset to the sentinel value.
 246.227 -     *
 246.228 -     * @serial
 246.229 -     * @since 1.7
 246.230 -     */
 246.231 -//    private List<Throwable> suppressedExceptions = SUPPRESSED_SENTINEL;
 246.232 -
 246.233 -    /** Message for trying to suppress a null exception. */
 246.234 -    private static final String NULL_CAUSE_MESSAGE = "Cannot suppress a null exception.";
 246.235 -
 246.236 -    /** Message for trying to suppress oneself. */
 246.237 -    private static final String SELF_SUPPRESSION_MESSAGE = "Self-suppression not permitted";
 246.238 -
 246.239 -    /** Caption  for labeling causative exception stack traces */
 246.240 -    private static final String CAUSE_CAPTION = "Caused by: ";
 246.241 -
 246.242 -    /** Caption for labeling suppressed exception stack traces */
 246.243 -    private static final String SUPPRESSED_CAPTION = "Suppressed: ";
 246.244 -
 246.245 -    /**
 246.246 -     * Constructs a new throwable with {@code null} as its detail message.
 246.247 -     * The cause is not initialized, and may subsequently be initialized by a
 246.248 -     * call to {@link #initCause}.
 246.249 -     *
 246.250 -     * <p>The {@link #fillInStackTrace()} method is called to initialize
 246.251 -     * the stack trace data in the newly created throwable.
 246.252 -     */
 246.253 -    public Throwable() {
 246.254 -        fillInStackTrace();
 246.255 -    }
 246.256 -
 246.257 -    /**
 246.258 -     * Constructs a new throwable with the specified detail message.  The
 246.259 -     * cause is not initialized, and may subsequently be initialized by
 246.260 -     * a call to {@link #initCause}.
 246.261 -     *
 246.262 -     * <p>The {@link #fillInStackTrace()} method is called to initialize
 246.263 -     * the stack trace data in the newly created throwable.
 246.264 -     *
 246.265 -     * @param   message   the detail message. The detail message is saved for
 246.266 -     *          later retrieval by the {@link #getMessage()} method.
 246.267 -     */
 246.268 -    public Throwable(String message) {
 246.269 -        fillInStackTrace();
 246.270 -        detailMessage = message;
 246.271 -    }
 246.272 -
 246.273 -    /**
 246.274 -     * Constructs a new throwable with the specified detail message and
 246.275 -     * cause.  <p>Note that the detail message associated with
 246.276 -     * {@code cause} is <i>not</i> automatically incorporated in
 246.277 -     * this throwable's detail message.
 246.278 -     *
 246.279 -     * <p>The {@link #fillInStackTrace()} method is called to initialize
 246.280 -     * the stack trace data in the newly created throwable.
 246.281 -     *
 246.282 -     * @param  message the detail message (which is saved for later retrieval
 246.283 -     *         by the {@link #getMessage()} method).
 246.284 -     * @param  cause the cause (which is saved for later retrieval by the
 246.285 -     *         {@link #getCause()} method).  (A {@code null} value is
 246.286 -     *         permitted, and indicates that the cause is nonexistent or
 246.287 -     *         unknown.)
 246.288 -     * @since  1.4
 246.289 -     */
 246.290 -    public Throwable(String message, Throwable cause) {
 246.291 -        fillInStackTrace();
 246.292 -        detailMessage = message;
 246.293 -        this.cause = cause;
 246.294 -    }
 246.295 -
 246.296 -    /**
 246.297 -     * Constructs a new throwable with the specified cause and a detail
 246.298 -     * message of {@code (cause==null ? null : cause.toString())} (which
 246.299 -     * typically contains the class and detail message of {@code cause}).
 246.300 -     * This constructor is useful for throwables that are little more than
 246.301 -     * wrappers for other throwables (for example, {@link
 246.302 -     * java.security.PrivilegedActionException}).
 246.303 -     *
 246.304 -     * <p>The {@link #fillInStackTrace()} method is called to initialize
 246.305 -     * the stack trace data in the newly created throwable.
 246.306 -     *
 246.307 -     * @param  cause the cause (which is saved for later retrieval by the
 246.308 -     *         {@link #getCause()} method).  (A {@code null} value is
 246.309 -     *         permitted, and indicates that the cause is nonexistent or
 246.310 -     *         unknown.)
 246.311 -     * @since  1.4
 246.312 -     */
 246.313 -    public Throwable(Throwable cause) {
 246.314 -        fillInStackTrace();
 246.315 -        detailMessage = (cause==null ? null : cause.toString());
 246.316 -        this.cause = cause;
 246.317 -    }
 246.318 -
 246.319 -    /**
 246.320 -     * Constructs a new throwable with the specified detail message,
 246.321 -     * cause, {@linkplain #addSuppressed suppression} enabled or
 246.322 -     * disabled, and writable stack trace enabled or disabled.  If
 246.323 -     * suppression is disabled, {@link #getSuppressed} for this object
 246.324 -     * will return a zero-length array and calls to {@link
 246.325 -     * #addSuppressed} that would otherwise append an exception to the
 246.326 -     * suppressed list will have no effect.  If the writable stack
 246.327 -     * trace is false, this constructor will not call {@link
 246.328 -     * #fillInStackTrace()}, a {@code null} will be written to the
 246.329 -     * {@code stackTrace} field, and subsequent calls to {@code
 246.330 -     * fillInStackTrace} and {@link
 246.331 -     * #setStackTrace(StackTraceElement[])} will not set the stack
 246.332 -     * trace.  If the writable stack trace is false, {@link
 246.333 -     * #getStackTrace} will return a zero length array.
 246.334 -     *
 246.335 -     * <p>Note that the other constructors of {@code Throwable} treat
 246.336 -     * suppression as being enabled and the stack trace as being
 246.337 -     * writable.  Subclasses of {@code Throwable} should document any
 246.338 -     * conditions under which suppression is disabled and document
 246.339 -     * conditions under which the stack trace is not writable.
 246.340 -     * Disabling of suppression should only occur in exceptional
 246.341 -     * circumstances where special requirements exist, such as a
 246.342 -     * virtual machine reusing exception objects under low-memory
 246.343 -     * situations.  Circumstances where a given exception object is
 246.344 -     * repeatedly caught and rethrown, such as to implement control
 246.345 -     * flow between two sub-systems, is another situation where
 246.346 -     * immutable throwable objects would be appropriate.
 246.347 -     *
 246.348 -     * @param  message the detail message.
 246.349 -     * @param cause the cause.  (A {@code null} value is permitted,
 246.350 -     * and indicates that the cause is nonexistent or unknown.)
 246.351 -     * @param enableSuppression whether or not suppression is enabled or disabled
 246.352 -     * @param writableStackTrace whether or not the stack trace should be
 246.353 -     *                           writable
 246.354 -     *
 246.355 -     * @see OutOfMemoryError
 246.356 -     * @see NullPointerException
 246.357 -     * @see ArithmeticException
 246.358 -     * @since 1.7
 246.359 -     */
 246.360 -    protected Throwable(String message, Throwable cause,
 246.361 -                        boolean enableSuppression,
 246.362 -                        boolean writableStackTrace) {
 246.363 -        if (writableStackTrace) {
 246.364 -            fillInStackTrace();
 246.365 -        } else {
 246.366 -            stackTrace = null;
 246.367 -        }
 246.368 -        detailMessage = message;
 246.369 -        this.cause = cause;
 246.370 -//        if (!enableSuppression)
 246.371 -//            suppressedExceptions = null;
 246.372 -    }
 246.373 -
 246.374 -    /**
 246.375 -     * Returns the detail message string of this throwable.
 246.376 -     *
 246.377 -     * @return  the detail message string of this {@code Throwable} instance
 246.378 -     *          (which may be {@code null}).
 246.379 -     */
 246.380 -    public String getMessage() {
 246.381 -        return detailMessage;
 246.382 -    }
 246.383 -
 246.384 -    /**
 246.385 -     * Creates a localized description of this throwable.
 246.386 -     * Subclasses may override this method in order to produce a
 246.387 -     * locale-specific message.  For subclasses that do not override this
 246.388 -     * method, the default implementation returns the same result as
 246.389 -     * {@code getMessage()}.
 246.390 -     *
 246.391 -     * @return  The localized description of this throwable.
 246.392 -     * @since   JDK1.1
 246.393 -     */
 246.394 -    public String getLocalizedMessage() {
 246.395 -        return getMessage();
 246.396 -    }
 246.397 -
 246.398 -    /**
 246.399 -     * Returns the cause of this throwable or {@code null} if the
 246.400 -     * cause is nonexistent or unknown.  (The cause is the throwable that
 246.401 -     * caused this throwable to get thrown.)
 246.402 -     *
 246.403 -     * <p>This implementation returns the cause that was supplied via one of
 246.404 -     * the constructors requiring a {@code Throwable}, or that was set after
 246.405 -     * creation with the {@link #initCause(Throwable)} method.  While it is
 246.406 -     * typically unnecessary to override this method, a subclass can override
 246.407 -     * it to return a cause set by some other means.  This is appropriate for
 246.408 -     * a "legacy chained throwable" that predates the addition of chained
 246.409 -     * exceptions to {@code Throwable}.  Note that it is <i>not</i>
 246.410 -     * necessary to override any of the {@code PrintStackTrace} methods,
 246.411 -     * all of which invoke the {@code getCause} method to determine the
 246.412 -     * cause of a throwable.
 246.413 -     *
 246.414 -     * @return  the cause of this throwable or {@code null} if the
 246.415 -     *          cause is nonexistent or unknown.
 246.416 -     * @since 1.4
 246.417 -     */
 246.418 -    public synchronized Throwable getCause() {
 246.419 -        return (cause==this ? null : cause);
 246.420 -    }
 246.421 -
 246.422 -    /**
 246.423 -     * Initializes the <i>cause</i> of this throwable to the specified value.
 246.424 -     * (The cause is the throwable that caused this throwable to get thrown.)
 246.425 -     *
 246.426 -     * <p>This method can be called at most once.  It is generally called from
 246.427 -     * within the constructor, or immediately after creating the
 246.428 -     * throwable.  If this throwable was created
 246.429 -     * with {@link #Throwable(Throwable)} or
 246.430 -     * {@link #Throwable(String,Throwable)}, this method cannot be called
 246.431 -     * even once.
 246.432 -     *
 246.433 -     * <p>An example of using this method on a legacy throwable type
 246.434 -     * without other support for setting the cause is:
 246.435 -     *
 246.436 -     * <pre>
 246.437 -     * try {
 246.438 -     *     lowLevelOp();
 246.439 -     * } catch (LowLevelException le) {
 246.440 -     *     throw (HighLevelException)
 246.441 -     *           new HighLevelException().initCause(le); // Legacy constructor
 246.442 -     * }
 246.443 -     * </pre>
 246.444 -     *
 246.445 -     * @param  cause the cause (which is saved for later retrieval by the
 246.446 -     *         {@link #getCause()} method).  (A {@code null} value is
 246.447 -     *         permitted, and indicates that the cause is nonexistent or
 246.448 -     *         unknown.)
 246.449 -     * @return  a reference to this {@code Throwable} instance.
 246.450 -     * @throws IllegalArgumentException if {@code cause} is this
 246.451 -     *         throwable.  (A throwable cannot be its own cause.)
 246.452 -     * @throws IllegalStateException if this throwable was
 246.453 -     *         created with {@link #Throwable(Throwable)} or
 246.454 -     *         {@link #Throwable(String,Throwable)}, or this method has already
 246.455 -     *         been called on this throwable.
 246.456 -     * @since  1.4
 246.457 -     */
 246.458 -    public synchronized Throwable initCause(Throwable cause) {
 246.459 -        if (this.cause != this)
 246.460 -            throw new IllegalStateException("Can't overwrite cause");
 246.461 -        if (cause == this)
 246.462 -            throw new IllegalArgumentException("Self-causation not permitted");
 246.463 -        this.cause = cause;
 246.464 -        return this;
 246.465 -    }
 246.466 -
 246.467 -    /**
 246.468 -     * Returns a short description of this throwable.
 246.469 -     * The result is the concatenation of:
 246.470 -     * <ul>
 246.471 -     * <li> the {@linkplain Class#getName() name} of the class of this object
 246.472 -     * <li> ": " (a colon and a space)
 246.473 -     * <li> the result of invoking this object's {@link #getLocalizedMessage}
 246.474 -     *      method
 246.475 -     * </ul>
 246.476 -     * If {@code getLocalizedMessage} returns {@code null}, then just
 246.477 -     * the class name is returned.
 246.478 -     *
 246.479 -     * @return a string representation of this throwable.
 246.480 -     */
 246.481 -    public String toString() {
 246.482 -        String s = getClass().getName();
 246.483 -        String message = getLocalizedMessage();
 246.484 -        return (message != null) ? (s + ": " + message) : s;
 246.485 -    }
 246.486 -
 246.487 -    /**
 246.488 -     * Prints this throwable and its backtrace to the
 246.489 -     * standard error stream. This method prints a stack trace for this
 246.490 -     * {@code Throwable} object on the error output stream that is
 246.491 -     * the value of the field {@code System.err}. The first line of
 246.492 -     * output contains the result of the {@link #toString()} method for
 246.493 -     * this object.  Remaining lines represent data previously recorded by
 246.494 -     * the method {@link #fillInStackTrace()}. The format of this
 246.495 -     * information depends on the implementation, but the following
 246.496 -     * example may be regarded as typical:
 246.497 -     * <blockquote><pre>
 246.498 -     * java.lang.NullPointerException
 246.499 -     *         at MyClass.mash(MyClass.java:9)
 246.500 -     *         at MyClass.crunch(MyClass.java:6)
 246.501 -     *         at MyClass.main(MyClass.java:3)
 246.502 -     * </pre></blockquote>
 246.503 -     * This example was produced by running the program:
 246.504 -     * <pre>
 246.505 -     * class MyClass {
 246.506 -     *     public static void main(String[] args) {
 246.507 -     *         crunch(null);
 246.508 -     *     }
 246.509 -     *     static void crunch(int[] a) {
 246.510 -     *         mash(a);
 246.511 -     *     }
 246.512 -     *     static void mash(int[] b) {
 246.513 -     *         System.out.println(b[0]);
 246.514 -     *     }
 246.515 -     * }
 246.516 -     * </pre>
 246.517 -     * The backtrace for a throwable with an initialized, non-null cause
 246.518 -     * should generally include the backtrace for the cause.  The format
 246.519 -     * of this information depends on the implementation, but the following
 246.520 -     * example may be regarded as typical:
 246.521 -     * <pre>
 246.522 -     * HighLevelException: MidLevelException: LowLevelException
 246.523 -     *         at Junk.a(Junk.java:13)
 246.524 -     *         at Junk.main(Junk.java:4)
 246.525 -     * Caused by: MidLevelException: LowLevelException
 246.526 -     *         at Junk.c(Junk.java:23)
 246.527 -     *         at Junk.b(Junk.java:17)
 246.528 -     *         at Junk.a(Junk.java:11)
 246.529 -     *         ... 1 more
 246.530 -     * Caused by: LowLevelException
 246.531 -     *         at Junk.e(Junk.java:30)
 246.532 -     *         at Junk.d(Junk.java:27)
 246.533 -     *         at Junk.c(Junk.java:21)
 246.534 -     *         ... 3 more
 246.535 -     * </pre>
 246.536 -     * Note the presence of lines containing the characters {@code "..."}.
 246.537 -     * These lines indicate that the remainder of the stack trace for this
 246.538 -     * exception matches the indicated number of frames from the bottom of the
 246.539 -     * stack trace of the exception that was caused by this exception (the
 246.540 -     * "enclosing" exception).  This shorthand can greatly reduce the length
 246.541 -     * of the output in the common case where a wrapped exception is thrown
 246.542 -     * from same method as the "causative exception" is caught.  The above
 246.543 -     * example was produced by running the program:
 246.544 -     * <pre>
 246.545 -     * public class Junk {
 246.546 -     *     public static void main(String args[]) {
 246.547 -     *         try {
 246.548 -     *             a();
 246.549 -     *         } catch(HighLevelException e) {
 246.550 -     *             e.printStackTrace();
 246.551 -     *         }
 246.552 -     *     }
 246.553 -     *     static void a() throws HighLevelException {
 246.554 -     *         try {
 246.555 -     *             b();
 246.556 -     *         } catch(MidLevelException e) {
 246.557 -     *             throw new HighLevelException(e);
 246.558 -     *         }
 246.559 -     *     }
 246.560 -     *     static void b() throws MidLevelException {
 246.561 -     *         c();
 246.562 -     *     }
 246.563 -     *     static void c() throws MidLevelException {
 246.564 -     *         try {
 246.565 -     *             d();
 246.566 -     *         } catch(LowLevelException e) {
 246.567 -     *             throw new MidLevelException(e);
 246.568 -     *         }
 246.569 -     *     }
 246.570 -     *     static void d() throws LowLevelException {
 246.571 -     *        e();
 246.572 -     *     }
 246.573 -     *     static void e() throws LowLevelException {
 246.574 -     *         throw new LowLevelException();
 246.575 -     *     }
 246.576 -     * }
 246.577 -     *
 246.578 -     * class HighLevelException extends Exception {
 246.579 -     *     HighLevelException(Throwable cause) { super(cause); }
 246.580 -     * }
 246.581 -     *
 246.582 -     * class MidLevelException extends Exception {
 246.583 -     *     MidLevelException(Throwable cause)  { super(cause); }
 246.584 -     * }
 246.585 -     *
 246.586 -     * class LowLevelException extends Exception {
 246.587 -     * }
 246.588 -     * </pre>
 246.589 -     * As of release 7, the platform supports the notion of
 246.590 -     * <i>suppressed exceptions</i> (in conjunction with the {@code
 246.591 -     * try}-with-resources statement). Any exceptions that were
 246.592 -     * suppressed in order to deliver an exception are printed out
 246.593 -     * beneath the stack trace.  The format of this information
 246.594 -     * depends on the implementation, but the following example may be
 246.595 -     * regarded as typical:
 246.596 -     *
 246.597 -     * <pre>
 246.598 -     * Exception in thread "main" java.lang.Exception: Something happened
 246.599 -     *  at Foo.bar(Foo.java:10)
 246.600 -     *  at Foo.main(Foo.java:5)
 246.601 -     *  Suppressed: Resource$CloseFailException: Resource ID = 0
 246.602 -     *          at Resource.close(Resource.java:26)
 246.603 -     *          at Foo.bar(Foo.java:9)
 246.604 -     *          ... 1 more
 246.605 -     * </pre>
 246.606 -     * Note that the "... n more" notation is used on suppressed exceptions
 246.607 -     * just at it is used on causes. Unlike causes, suppressed exceptions are
 246.608 -     * indented beyond their "containing exceptions."
 246.609 -     *
 246.610 -     * <p>An exception can have both a cause and one or more suppressed
 246.611 -     * exceptions:
 246.612 -     * <pre>
 246.613 -     * Exception in thread "main" java.lang.Exception: Main block
 246.614 -     *  at Foo3.main(Foo3.java:7)
 246.615 -     *  Suppressed: Resource$CloseFailException: Resource ID = 2
 246.616 -     *          at Resource.close(Resource.java:26)
 246.617 -     *          at Foo3.main(Foo3.java:5)
 246.618 -     *  Suppressed: Resource$CloseFailException: Resource ID = 1
 246.619 -     *          at Resource.close(Resource.java:26)
 246.620 -     *          at Foo3.main(Foo3.java:5)
 246.621 -     * Caused by: java.lang.Exception: I did it
 246.622 -     *  at Foo3.main(Foo3.java:8)
 246.623 -     * </pre>
 246.624 -     * Likewise, a suppressed exception can have a cause:
 246.625 -     * <pre>
 246.626 -     * Exception in thread "main" java.lang.Exception: Main block
 246.627 -     *  at Foo4.main(Foo4.java:6)
 246.628 -     *  Suppressed: Resource2$CloseFailException: Resource ID = 1
 246.629 -     *          at Resource2.close(Resource2.java:20)
 246.630 -     *          at Foo4.main(Foo4.java:5)
 246.631 -     *  Caused by: java.lang.Exception: Rats, you caught me
 246.632 -     *          at Resource2$CloseFailException.<init>(Resource2.java:45)
 246.633 -     *          ... 2 more
 246.634 -     * </pre>
 246.635 -     */
 246.636 -//    public void printStackTrace() {
 246.637 -//        printStackTrace(System.err);
 246.638 -//    }
 246.639 -//
 246.640 -//    /**
 246.641 -//     * Prints this throwable and its backtrace to the specified print stream.
 246.642 -//     *
 246.643 -//     * @param s {@code PrintStream} to use for output
 246.644 -//     */
 246.645 -//    public void printStackTrace(PrintStream s) {
 246.646 -//        printStackTrace(new WrappedPrintStream(s));
 246.647 -//    }
 246.648 -//
 246.649 -//    private void printStackTrace(PrintStreamOrWriter s) {
 246.650 -//        // Guard against malicious overrides of Throwable.equals by
 246.651 -//        // using a Set with identity equality semantics.
 246.652 -////        Set<Throwable> dejaVu =
 246.653 -////            Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
 246.654 -////        dejaVu.add(this);
 246.655 -//
 246.656 -//        synchronized (s.lock()) {
 246.657 -//            // Print our stack trace
 246.658 -//            s.println(this);
 246.659 -//            StackTraceElement[] trace = getOurStackTrace();
 246.660 -//            for (StackTraceElement traceElement : trace)
 246.661 -//                s.println("\tat " + traceElement);
 246.662 -//
 246.663 -//            // Print suppressed exceptions, if any
 246.664 -////            for (Throwable se : getSuppressed())
 246.665 -////                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
 246.666 -//
 246.667 -//            // Print cause, if any
 246.668 -//            Throwable ourCause = getCause();
 246.669 -////            if (ourCause != null)
 246.670 -////                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
 246.671 -//        }
 246.672 -//    }
 246.673 -//
 246.674 -//    /**
 246.675 -//     * Print our stack trace as an enclosed exception for the specified
 246.676 -//     * stack trace.
 246.677 -//     */
 246.678 -//    private void printEnclosedStackTrace(PrintStreamOrWriter s,
 246.679 -//                                         StackTraceElement[] enclosingTrace,
 246.680 -//                                         String caption,
 246.681 -//                                         String prefix,
 246.682 -//                                         Object dejaVu) {
 246.683 -//        assert Thread.holdsLock(s.lock());
 246.684 -//        {
 246.685 -//            // Compute number of frames in common between this and enclosing trace
 246.686 -//            StackTraceElement[] trace = getOurStackTrace();
 246.687 -//            int m = trace.length - 1;
 246.688 -//            int n = enclosingTrace.length - 1;
 246.689 -//            while (m >= 0 && n >=0 && trace[m].equals(enclosingTrace[n])) {
 246.690 -//                m--; n--;
 246.691 -//            }
 246.692 -//            int framesInCommon = trace.length - 1 - m;
 246.693 -//
 246.694 -//            // Print our stack trace
 246.695 -//            s.println(prefix + caption + this);
 246.696 -//            for (int i = 0; i <= m; i++)
 246.697 -//                s.println(prefix + "\tat " + trace[i]);
 246.698 -//            if (framesInCommon != 0)
 246.699 -//                s.println(prefix + "\t... " + framesInCommon + " more");
 246.700 -//
 246.701 -//            // Print suppressed exceptions, if any
 246.702 -//            for (Throwable se : getSuppressed())
 246.703 -//                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION,
 246.704 -//                                           prefix +"\t", dejaVu);
 246.705 -//
 246.706 -//            // Print cause, if any
 246.707 -//            Throwable ourCause = getCause();
 246.708 -//            if (ourCause != null)
 246.709 -//                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, prefix, dejaVu);
 246.710 -//        }
 246.711 -//    }
 246.712 -//
 246.713 -//    /**
 246.714 -//     * Prints this throwable and its backtrace to the specified
 246.715 -//     * print writer.
 246.716 -//     *
 246.717 -//     * @param s {@code PrintWriter} to use for output
 246.718 -//     * @since   JDK1.1
 246.719 -//     */
 246.720 -//    public void printStackTrace(PrintWriter s) {
 246.721 -//        printStackTrace(new WrappedPrintWriter(s));
 246.722 -//    }
 246.723 -//
 246.724 -//    /**
 246.725 -//     * Wrapper class for PrintStream and PrintWriter to enable a single
 246.726 -//     * implementation of printStackTrace.
 246.727 -//     */
 246.728 -//    private abstract static class PrintStreamOrWriter {
 246.729 -//        /** Returns the object to be locked when using this StreamOrWriter */
 246.730 -//        abstract Object lock();
 246.731 -//
 246.732 -//        /** Prints the specified string as a line on this StreamOrWriter */
 246.733 -//        abstract void println(Object o);
 246.734 -//    }
 246.735 -//
 246.736 -//    private static class WrappedPrintStream extends PrintStreamOrWriter {
 246.737 -//        private final PrintStream printStream;
 246.738 -//
 246.739 -//        WrappedPrintStream(PrintStream printStream) {
 246.740 -//            this.printStream = printStream;
 246.741 -//        }
 246.742 -//
 246.743 -//        Object lock() {
 246.744 -//            return printStream;
 246.745 -//        }
 246.746 -//
 246.747 -//        void println(Object o) {
 246.748 -//            printStream.println(o);
 246.749 -//        }
 246.750 -//    }
 246.751 -//
 246.752 -//    private static class WrappedPrintWriter extends PrintStreamOrWriter {
 246.753 -//        private final PrintWriter printWriter;
 246.754 -//
 246.755 -//        WrappedPrintWriter(PrintWriter printWriter) {
 246.756 -//            this.printWriter = printWriter;
 246.757 -//        }
 246.758 -//
 246.759 -//        Object lock() {
 246.760 -//            return printWriter;
 246.761 -//        }
 246.762 -//
 246.763 -//        void println(Object o) {
 246.764 -//            printWriter.println(o);
 246.765 -//        }
 246.766 -//    }
 246.767 -
 246.768 -    /**
 246.769 -     * Fills in the execution stack trace. This method records within this
 246.770 -     * {@code Throwable} object information about the current state of
 246.771 -     * the stack frames for the current thread.
 246.772 -     *
 246.773 -     * <p>If the stack trace of this {@code Throwable} {@linkplain
 246.774 -     * Throwable#Throwable(String, Throwable, boolean, boolean) is not
 246.775 -     * writable}, calling this method has no effect.
 246.776 -     *
 246.777 -     * @return  a reference to this {@code Throwable} instance.
 246.778 -     * @see     java.lang.Throwable#printStackTrace()
 246.779 -     */
 246.780 -    public synchronized Throwable fillInStackTrace() {
 246.781 -        if (stackTrace != null ||
 246.782 -            backtrace != null /* Out of protocol state */ ) {
 246.783 -            fillInStackTrace(0);
 246.784 -            stackTrace = UNASSIGNED_STACK;
 246.785 -        }
 246.786 -        return this;
 246.787 -    }
 246.788 -
 246.789 -    @JavaScriptBody(args = { "self", "dummy" }, body = "")
 246.790 -    private native Throwable fillInStackTrace(int dummy);
 246.791 -
 246.792 -    /**
 246.793 -     * Provides programmatic access to the stack trace information printed by
 246.794 -     * {@link #printStackTrace()}.  Returns an array of stack trace elements,
 246.795 -     * each representing one stack frame.  The zeroth element of the array
 246.796 -     * (assuming the array's length is non-zero) represents the top of the
 246.797 -     * stack, which is the last method invocation in the sequence.  Typically,
 246.798 -     * this is the point at which this throwable was created and thrown.
 246.799 -     * The last element of the array (assuming the array's length is non-zero)
 246.800 -     * represents the bottom of the stack, which is the first method invocation
 246.801 -     * in the sequence.
 246.802 -     *
 246.803 -     * <p>Some virtual machines may, under some circumstances, omit one
 246.804 -     * or more stack frames from the stack trace.  In the extreme case,
 246.805 -     * a virtual machine that has no stack trace information concerning
 246.806 -     * this throwable is permitted to return a zero-length array from this
 246.807 -     * method.  Generally speaking, the array returned by this method will
 246.808 -     * contain one element for every frame that would be printed by
 246.809 -     * {@code printStackTrace}.  Writes to the returned array do not
 246.810 -     * affect future calls to this method.
 246.811 -     *
 246.812 -     * @return an array of stack trace elements representing the stack trace
 246.813 -     *         pertaining to this throwable.
 246.814 -     * @since  1.4
 246.815 -     */
 246.816 -    public StackTraceElement[] getStackTrace() {
 246.817 -        return getOurStackTrace().clone();
 246.818 -    }
 246.819 -
 246.820 -    private synchronized StackTraceElement[] getOurStackTrace() {
 246.821 -        // Initialize stack trace field with information from
 246.822 -        // backtrace if this is the first call to this method
 246.823 -        if (stackTrace == UNASSIGNED_STACK ||
 246.824 -            (stackTrace == null && backtrace != null) /* Out of protocol state */) {
 246.825 -            int depth = getStackTraceDepth();
 246.826 -            stackTrace = new StackTraceElement[depth];
 246.827 -            for (int i=0; i < depth; i++)
 246.828 -                stackTrace[i] = getStackTraceElement(i);
 246.829 -        } else if (stackTrace == null) {
 246.830 -            return UNASSIGNED_STACK;
 246.831 -        }
 246.832 -        return stackTrace;
 246.833 -    }
 246.834 -
 246.835 -    /**
 246.836 -     * Sets the stack trace elements that will be returned by
 246.837 -     * {@link #getStackTrace()} and printed by {@link #printStackTrace()}
 246.838 -     * and related methods.
 246.839 -     *
 246.840 -     * This method, which is designed for use by RPC frameworks and other
 246.841 -     * advanced systems, allows the client to override the default
 246.842 -     * stack trace that is either generated by {@link #fillInStackTrace()}
 246.843 -     * when a throwable is constructed or deserialized when a throwable is
 246.844 -     * read from a serialization stream.
 246.845 -     *
 246.846 -     * <p>If the stack trace of this {@code Throwable} {@linkplain
 246.847 -     * Throwable#Throwable(String, Throwable, boolean, boolean) is not
 246.848 -     * writable}, calling this method has no effect other than
 246.849 -     * validating its argument.
 246.850 -     *
 246.851 -     * @param   stackTrace the stack trace elements to be associated with
 246.852 -     * this {@code Throwable}.  The specified array is copied by this
 246.853 -     * call; changes in the specified array after the method invocation
 246.854 -     * returns will have no affect on this {@code Throwable}'s stack
 246.855 -     * trace.
 246.856 -     *
 246.857 -     * @throws NullPointerException if {@code stackTrace} is
 246.858 -     *         {@code null} or if any of the elements of
 246.859 -     *         {@code stackTrace} are {@code null}
 246.860 -     *
 246.861 -     * @since  1.4
 246.862 -     */
 246.863 -    public void setStackTrace(StackTraceElement[] stackTrace) {
 246.864 -        // Validate argument
 246.865 -        StackTraceElement[] defensiveCopy = stackTrace.clone();
 246.866 -        for (int i = 0; i < defensiveCopy.length; i++) {
 246.867 -            if (defensiveCopy[i] == null)
 246.868 -                throw new NullPointerException("stackTrace[" + i + "]");
 246.869 -        }
 246.870 -
 246.871 -        synchronized (this) {
 246.872 -            if (this.stackTrace == null && // Immutable stack
 246.873 -                backtrace == null) // Test for out of protocol state
 246.874 -                return;
 246.875 -            this.stackTrace = defensiveCopy;
 246.876 -        }
 246.877 -    }
 246.878 -
 246.879 -    /**
 246.880 -     * Returns the number of elements in the stack trace (or 0 if the stack
 246.881 -     * trace is unavailable).
 246.882 -     *
 246.883 -     * package-protection for use by SharedSecrets.
 246.884 -     */
 246.885 -    native int getStackTraceDepth();
 246.886 -
 246.887 -    /**
 246.888 -     * Returns the specified element of the stack trace.
 246.889 -     *
 246.890 -     * package-protection for use by SharedSecrets.
 246.891 -     *
 246.892 -     * @param index index of the element to return.
 246.893 -     * @throws IndexOutOfBoundsException if {@code index < 0 ||
 246.894 -     *         index >= getStackTraceDepth() }
 246.895 -     */
 246.896 -    native StackTraceElement getStackTraceElement(int index);
 246.897 -
 246.898 -    /**
 246.899 -     * Reads a {@code Throwable} from a stream, enforcing
 246.900 -     * well-formedness constraints on fields.  Null entries and
 246.901 -     * self-pointers are not allowed in the list of {@code
 246.902 -     * suppressedExceptions}.  Null entries are not allowed for stack
 246.903 -     * trace elements.  A null stack trace in the serial form results
 246.904 -     * in a zero-length stack element array. A single-element stack
 246.905 -     * trace whose entry is equal to {@code new StackTraceElement("",
 246.906 -     * "", null, Integer.MIN_VALUE)} results in a {@code null} {@code
 246.907 -     * stackTrace} field.
 246.908 -     *
 246.909 -     * Note that there are no constraints on the value the {@code
 246.910 -     * cause} field can hold; both {@code null} and {@code this} are
 246.911 -     * valid values for the field.
 246.912 -     */
 246.913 -//    private void readObject(ObjectInputStream s)
 246.914 -//        throws IOException, ClassNotFoundException {
 246.915 -//        s.defaultReadObject();     // read in all fields
 246.916 -//        if (suppressedExceptions != null) {
 246.917 -//            List<Throwable> suppressed = null;
 246.918 -//            if (suppressedExceptions.isEmpty()) {
 246.919 -//                // Use the sentinel for a zero-length list
 246.920 -//                suppressed = SUPPRESSED_SENTINEL;
 246.921 -//            } else { // Copy Throwables to new list
 246.922 -//                suppressed = new ArrayList<Throwable>(1);
 246.923 -//                for (Throwable t : suppressedExceptions) {
 246.924 -//                    // Enforce constraints on suppressed exceptions in
 246.925 -//                    // case of corrupt or malicious stream.
 246.926 -//                    if (t == null)
 246.927 -//                        throw new NullPointerException(NULL_CAUSE_MESSAGE);
 246.928 -//                    if (t == this)
 246.929 -//                        throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
 246.930 -//                    suppressed.add(t);
 246.931 -//                }
 246.932 -//            }
 246.933 -//            suppressedExceptions = suppressed;
 246.934 -//        } // else a null suppressedExceptions field remains null
 246.935 -//
 246.936 -//        /*
 246.937 -//         * For zero-length stack traces, use a clone of
 246.938 -//         * UNASSIGNED_STACK rather than UNASSIGNED_STACK itself to
 246.939 -//         * allow identity comparison against UNASSIGNED_STACK in
 246.940 -//         * getOurStackTrace.  The identity of UNASSIGNED_STACK in
 246.941 -//         * stackTrace indicates to the getOurStackTrace method that
 246.942 -//         * the stackTrace needs to be constructed from the information
 246.943 -//         * in backtrace.
 246.944 -//         */
 246.945 -//        if (stackTrace != null) {
 246.946 -//            if (stackTrace.length == 0) {
 246.947 -//                stackTrace = UNASSIGNED_STACK.clone();
 246.948 -//            }  else if (stackTrace.length == 1 &&
 246.949 -//                        // Check for the marker of an immutable stack trace
 246.950 -//                        SentinelHolder.STACK_TRACE_ELEMENT_SENTINEL.equals(stackTrace[0])) {
 246.951 -//                stackTrace = null;
 246.952 -//            } else { // Verify stack trace elements are non-null.
 246.953 -//                for(StackTraceElement ste : stackTrace) {
 246.954 -//                    if (ste == null)
 246.955 -//                        throw new NullPointerException("null StackTraceElement in serial stream. ");
 246.956 -//                }
 246.957 -//            }
 246.958 -//        } else {
 246.959 -//            // A null stackTrace field in the serial form can result
 246.960 -//            // from an exception serialized without that field in
 246.961 -//            // older JDK releases; treat such exceptions as having
 246.962 -//            // empty stack traces.
 246.963 -//            stackTrace = UNASSIGNED_STACK.clone();
 246.964 -//        }
 246.965 -//    }
 246.966 -
 246.967 -    /**
 246.968 -     * Write a {@code Throwable} object to a stream.
 246.969 -     *
 246.970 -     * A {@code null} stack trace field is represented in the serial
 246.971 -     * form as a one-element array whose element is equal to {@code
 246.972 -     * new StackTraceElement("", "", null, Integer.MIN_VALUE)}.
 246.973 -     */
 246.974 -//    private synchronized void writeObject(ObjectOutputStream s)
 246.975 -//        throws IOException {
 246.976 -//        // Ensure that the stackTrace field is initialized to a
 246.977 -//        // non-null value, if appropriate.  As of JDK 7, a null stack
 246.978 -//        // trace field is a valid value indicating the stack trace
 246.979 -//        // should not be set.
 246.980 -//        getOurStackTrace();
 246.981 -//
 246.982 -//        StackTraceElement[] oldStackTrace = stackTrace;
 246.983 -//        try {
 246.984 -//            if (stackTrace == null)
 246.985 -//                stackTrace = SentinelHolder.STACK_TRACE_SENTINEL;
 246.986 -//            s.defaultWriteObject();
 246.987 -//        } finally {
 246.988 -//            stackTrace = oldStackTrace;
 246.989 -//        }
 246.990 -//    }
 246.991 -
 246.992 -    /**
 246.993 -     * Appends the specified exception to the exceptions that were
 246.994 -     * suppressed in order to deliver this exception. This method is
 246.995 -     * thread-safe and typically called (automatically and implicitly)
 246.996 -     * by the {@code try}-with-resources statement.
 246.997 -     *
 246.998 -     * <p>The suppression behavior is enabled <em>unless</em> disabled
 246.999 -     * {@linkplain #Throwable(String, Throwable, boolean, boolean) via
246.1000 -     * a constructor}.  When suppression is disabled, this method does
246.1001 -     * nothing other than to validate its argument.
246.1002 -     *
246.1003 -     * <p>Note that when one exception {@linkplain
246.1004 -     * #initCause(Throwable) causes} another exception, the first
246.1005 -     * exception is usually caught and then the second exception is
246.1006 -     * thrown in response.  In other words, there is a causal
246.1007 -     * connection between the two exceptions.
246.1008 -     *
246.1009 -     * In contrast, there are situations where two independent
246.1010 -     * exceptions can be thrown in sibling code blocks, in particular
246.1011 -     * in the {@code try} block of a {@code try}-with-resources
246.1012 -     * statement and the compiler-generated {@code finally} block
246.1013 -     * which closes the resource.
246.1014 -     *
246.1015 -     * In these situations, only one of the thrown exceptions can be
246.1016 -     * propagated.  In the {@code try}-with-resources statement, when
246.1017 -     * there are two such exceptions, the exception originating from
246.1018 -     * the {@code try} block is propagated and the exception from the
246.1019 -     * {@code finally} block is added to the list of exceptions
246.1020 -     * suppressed by the exception from the {@code try} block.  As an
246.1021 -     * exception unwinds the stack, it can accumulate multiple
246.1022 -     * suppressed exceptions.
246.1023 -     *
246.1024 -     * <p>An exception may have suppressed exceptions while also being
246.1025 -     * caused by another exception.  Whether or not an exception has a
246.1026 -     * cause is semantically known at the time of its creation, unlike
246.1027 -     * whether or not an exception will suppress other exceptions
246.1028 -     * which is typically only determined after an exception is
246.1029 -     * thrown.
246.1030 -     *
246.1031 -     * <p>Note that programmer written code is also able to take
246.1032 -     * advantage of calling this method in situations where there are
246.1033 -     * multiple sibling exceptions and only one can be propagated.
246.1034 -     *
246.1035 -     * @param exception the exception to be added to the list of
246.1036 -     *        suppressed exceptions
246.1037 -     * @throws IllegalArgumentException if {@code exception} is this
246.1038 -     *         throwable; a throwable cannot suppress itself.
246.1039 -     * @throws NullPointerException if {@code exception} is {@code null}
246.1040 -     * @since 1.7
246.1041 -     */
246.1042 -    public final synchronized void addSuppressed(Throwable exception) {
246.1043 -        if (exception == this)
246.1044 -            throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
246.1045 -
246.1046 -        if (exception == null)
246.1047 -            throw new NullPointerException(NULL_CAUSE_MESSAGE);
246.1048 -
246.1049 -//        if (suppressedExceptions == null) // Suppressed exceptions not recorded
246.1050 -//            return;
246.1051 -//
246.1052 -//        if (suppressedExceptions == SUPPRESSED_SENTINEL)
246.1053 -//            suppressedExceptions = new ArrayList<Throwable>(1);
246.1054 -//
246.1055 -//        suppressedExceptions.add(exception);
246.1056 -    }
246.1057 -
246.1058 -    private static final Throwable[] EMPTY_THROWABLE_ARRAY = new Throwable[0];
246.1059 -
246.1060 -    /**
246.1061 -     * Returns an array containing all of the exceptions that were
246.1062 -     * suppressed, typically by the {@code try}-with-resources
246.1063 -     * statement, in order to deliver this exception.
246.1064 -     *
246.1065 -     * If no exceptions were suppressed or {@linkplain
246.1066 -     * #Throwable(String, Throwable, boolean, boolean) suppression is
246.1067 -     * disabled}, an empty array is returned.  This method is
246.1068 -     * thread-safe.  Writes to the returned array do not affect future
246.1069 -     * calls to this method.
246.1070 -     *
246.1071 -     * @return an array containing all of the exceptions that were
246.1072 -     *         suppressed to deliver this exception.
246.1073 -     * @since 1.7
246.1074 -     */
246.1075 -    public final synchronized Throwable[] getSuppressed() {
246.1076 -        return new Throwable[0];
246.1077 -//        if (suppressedExceptions == SUPPRESSED_SENTINEL ||
246.1078 -//            suppressedExceptions == null)
246.1079 -//            return EMPTY_THROWABLE_ARRAY;
246.1080 -//        else
246.1081 -//            return suppressedExceptions.toArray(EMPTY_THROWABLE_ARRAY);
246.1082 -    }
246.1083 -}
   247.1 --- a/emul/src/main/java/java/lang/VirtualMachineError.java	Wed Dec 05 10:03:58 2012 +0100
   247.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   247.3 @@ -1,54 +0,0 @@
   247.4 -/*
   247.5 - * Copyright (c) 1995, 1997, Oracle and/or its affiliates. All rights reserved.
   247.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   247.7 - *
   247.8 - * This code is free software; you can redistribute it and/or modify it
   247.9 - * under the terms of the GNU General Public License version 2 only, as
  247.10 - * published by the Free Software Foundation.  Oracle designates this
  247.11 - * particular file as subject to the "Classpath" exception as provided
  247.12 - * by Oracle in the LICENSE file that accompanied this code.
  247.13 - *
  247.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  247.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  247.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  247.17 - * version 2 for more details (a copy is included in the LICENSE file that
  247.18 - * accompanied this code).
  247.19 - *
  247.20 - * You should have received a copy of the GNU General Public License version
  247.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  247.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  247.23 - *
  247.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  247.25 - * or visit www.oracle.com if you need additional information or have any
  247.26 - * questions.
  247.27 - */
  247.28 -
  247.29 -package java.lang;
  247.30 -
  247.31 -/**
  247.32 - * Thrown to indicate that the Java Virtual Machine is broken or has
  247.33 - * run out of resources necessary for it to continue operating.
  247.34 - *
  247.35 - *
  247.36 - * @author  Frank Yellin
  247.37 - * @since   JDK1.0
  247.38 - */
  247.39 -abstract public
  247.40 -class VirtualMachineError extends Error {
  247.41 -    /**
  247.42 -     * Constructs a <code>VirtualMachineError</code> with no detail message.
  247.43 -     */
  247.44 -    public VirtualMachineError() {
  247.45 -        super();
  247.46 -    }
  247.47 -
  247.48 -    /**
  247.49 -     * Constructs a <code>VirtualMachineError</code> with the specified
  247.50 -     * detail message.
  247.51 -     *
  247.52 -     * @param   s   the detail message.
  247.53 -     */
  247.54 -    public VirtualMachineError(String s) {
  247.55 -        super(s);
  247.56 -    }
  247.57 -}
   248.1 --- a/emul/src/main/java/java/lang/annotation/Annotation.java	Wed Dec 05 10:03:58 2012 +0100
   248.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   248.3 @@ -1,131 +0,0 @@
   248.4 -/*
   248.5 - * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
   248.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   248.7 - *
   248.8 - * This code is free software; you can redistribute it and/or modify it
   248.9 - * under the terms of the GNU General Public License version 2 only, as
  248.10 - * published by the Free Software Foundation.  Oracle designates this
  248.11 - * particular file as subject to the "Classpath" exception as provided
  248.12 - * by Oracle in the LICENSE file that accompanied this code.
  248.13 - *
  248.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  248.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  248.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  248.17 - * version 2 for more details (a copy is included in the LICENSE file that
  248.18 - * accompanied this code).
  248.19 - *
  248.20 - * You should have received a copy of the GNU General Public License version
  248.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  248.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  248.23 - *
  248.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  248.25 - * or visit www.oracle.com if you need additional information or have any
  248.26 - * questions.
  248.27 - */
  248.28 -
  248.29 -package java.lang.annotation;
  248.30 -
  248.31 -/**
  248.32 - * The common interface extended by all annotation types.  Note that an
  248.33 - * interface that manually extends this one does <i>not</i> define
  248.34 - * an annotation type.  Also note that this interface does not itself
  248.35 - * define an annotation type.
  248.36 - *
  248.37 - * More information about annotation types can be found in section 9.6 of
  248.38 - * <cite>The Java&trade; Language Specification</cite>.
  248.39 - *
  248.40 - * @author  Josh Bloch
  248.41 - * @since   1.5
  248.42 - */
  248.43 -public interface Annotation {
  248.44 -    /**
  248.45 -     * Returns true if the specified object represents an annotation
  248.46 -     * that is logically equivalent to this one.  In other words,
  248.47 -     * returns true if the specified object is an instance of the same
  248.48 -     * annotation type as this instance, all of whose members are equal
  248.49 -     * to the corresponding member of this annotation, as defined below:
  248.50 -     * <ul>
  248.51 -     *    <li>Two corresponding primitive typed members whose values are
  248.52 -     *    <tt>x</tt> and <tt>y</tt> are considered equal if <tt>x == y</tt>,
  248.53 -     *    unless their type is <tt>float</tt> or <tt>double</tt>.
  248.54 -     *
  248.55 -     *    <li>Two corresponding <tt>float</tt> members whose values
  248.56 -     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
  248.57 -     *    <tt>Float.valueOf(x).equals(Float.valueOf(y))</tt>.
  248.58 -     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
  248.59 -     *    to itself, and <tt>0.0f</tt> unequal to <tt>-0.0f</tt>.)
  248.60 -     *
  248.61 -     *    <li>Two corresponding <tt>double</tt> members whose values
  248.62 -     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
  248.63 -     *    <tt>Double.valueOf(x).equals(Double.valueOf(y))</tt>.
  248.64 -     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
  248.65 -     *    to itself, and <tt>0.0</tt> unequal to <tt>-0.0</tt>.)
  248.66 -     *
  248.67 -     *    <li>Two corresponding <tt>String</tt>, <tt>Class</tt>, enum, or
  248.68 -     *    annotation typed members whose values are <tt>x</tt> and <tt>y</tt>
  248.69 -     *    are considered equal if <tt>x.equals(y)</tt>.  (Note that this
  248.70 -     *    definition is recursive for annotation typed members.)
  248.71 -     *
  248.72 -     *    <li>Two corresponding array typed members <tt>x</tt> and <tt>y</tt>
  248.73 -     *    are considered equal if <tt>Arrays.equals(x, y)</tt>, for the
  248.74 -     *    appropriate overloading of {@link java.util.Arrays#equals}.
  248.75 -     * </ul>
  248.76 -     *
  248.77 -     * @return true if the specified object represents an annotation
  248.78 -     *     that is logically equivalent to this one, otherwise false
  248.79 -     */
  248.80 -    boolean equals(Object obj);
  248.81 -
  248.82 -    /**
  248.83 -     * Returns the hash code of this annotation, as defined below:
  248.84 -     *
  248.85 -     * <p>The hash code of an annotation is the sum of the hash codes
  248.86 -     * of its members (including those with default values), as defined
  248.87 -     * below:
  248.88 -     *
  248.89 -     * The hash code of an annotation member is (127 times the hash code
  248.90 -     * of the member-name as computed by {@link String#hashCode()}) XOR
  248.91 -     * the hash code of the member-value, as defined below:
  248.92 -     *
  248.93 -     * <p>The hash code of a member-value depends on its type:
  248.94 -     * <ul>
  248.95 -     * <li>The hash code of a primitive value <tt><i>v</i></tt> is equal to
  248.96 -     *     <tt><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</tt>, where
  248.97 -     *     <tt><i>WrapperType</i></tt> is the wrapper type corresponding
  248.98 -     *     to the primitive type of <tt><i>v</i></tt> ({@link Byte},
  248.99 -     *     {@link Character}, {@link Double}, {@link Float}, {@link Integer},
 248.100 -     *     {@link Long}, {@link Short}, or {@link Boolean}).
 248.101 -     *
 248.102 -     * <li>The hash code of a string, enum, class, or annotation member-value
 248.103 -     I     <tt><i>v</i></tt> is computed as by calling
 248.104 -     *     <tt><i>v</i>.hashCode()</tt>.  (In the case of annotation
 248.105 -     *     member values, this is a recursive definition.)
 248.106 -     *
 248.107 -     * <li>The hash code of an array member-value is computed by calling
 248.108 -     *     the appropriate overloading of
 248.109 -     *     {@link java.util.Arrays#hashCode(long[]) Arrays.hashCode}
 248.110 -     *     on the value.  (There is one overloading for each primitive
 248.111 -     *     type, and one for object reference types.)
 248.112 -     * </ul>
 248.113 -     *
 248.114 -     * @return the hash code of this annotation
 248.115 -     */
 248.116 -    int hashCode();
 248.117 -
 248.118 -    /**
 248.119 -     * Returns a string representation of this annotation.  The details
 248.120 -     * of the representation are implementation-dependent, but the following
 248.121 -     * may be regarded as typical:
 248.122 -     * <pre>
 248.123 -     *   &#064;com.acme.util.Name(first=Alfred, middle=E., last=Neuman)
 248.124 -     * </pre>
 248.125 -     *
 248.126 -     * @return a string representation of this annotation
 248.127 -     */
 248.128 -    String toString();
 248.129 -
 248.130 -    /**
 248.131 -     * Returns the annotation type of this annotation.
 248.132 -     */
 248.133 -    Class<? extends Annotation> annotationType();
 248.134 -}
   249.1 --- a/emul/src/main/java/java/lang/annotation/Documented.java	Wed Dec 05 10:03:58 2012 +0100
   249.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   249.3 @@ -1,43 +0,0 @@
   249.4 -/*
   249.5 - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
   249.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   249.7 - *
   249.8 - * This code is free software; you can redistribute it and/or modify it
   249.9 - * under the terms of the GNU General Public License version 2 only, as
  249.10 - * published by the Free Software Foundation.  Oracle designates this
  249.11 - * particular file as subject to the "Classpath" exception as provided
  249.12 - * by Oracle in the LICENSE file that accompanied this code.
  249.13 - *
  249.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  249.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  249.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  249.17 - * version 2 for more details (a copy is included in the LICENSE file that
  249.18 - * accompanied this code).
  249.19 - *
  249.20 - * You should have received a copy of the GNU General Public License version
  249.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  249.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  249.23 - *
  249.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  249.25 - * or visit www.oracle.com if you need additional information or have any
  249.26 - * questions.
  249.27 - */
  249.28 -
  249.29 -package java.lang.annotation;
  249.30 -
  249.31 -/**
  249.32 - * Indicates that annotations with a type are to be documented by javadoc
  249.33 - * and similar tools by default.  This type should be used to annotate the
  249.34 - * declarations of types whose annotations affect the use of annotated
  249.35 - * elements by their clients.  If a type declaration is annotated with
  249.36 - * Documented, its annotations become part of the public API
  249.37 - * of the annotated elements.
  249.38 - *
  249.39 - * @author  Joshua Bloch
  249.40 - * @since 1.5
  249.41 - */
  249.42 -@Documented
  249.43 -@Retention(RetentionPolicy.RUNTIME)
  249.44 -@Target(ElementType.ANNOTATION_TYPE)
  249.45 -public @interface Documented {
  249.46 -}
   250.1 --- a/emul/src/main/java/java/lang/annotation/ElementType.java	Wed Dec 05 10:03:58 2012 +0100
   250.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   250.3 @@ -1,63 +0,0 @@
   250.4 -/*
   250.5 - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   250.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   250.7 - *
   250.8 - * This code is free software; you can redistribute it and/or modify it
   250.9 - * under the terms of the GNU General Public License version 2 only, as
  250.10 - * published by the Free Software Foundation.  Oracle designates this
  250.11 - * particular file as subject to the "Classpath" exception as provided
  250.12 - * by Oracle in the LICENSE file that accompanied this code.
  250.13 - *
  250.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  250.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  250.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  250.17 - * version 2 for more details (a copy is included in the LICENSE file that
  250.18 - * accompanied this code).
  250.19 - *
  250.20 - * You should have received a copy of the GNU General Public License version
  250.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  250.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  250.23 - *
  250.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  250.25 - * or visit www.oracle.com if you need additional information or have any
  250.26 - * questions.
  250.27 - */
  250.28 -
  250.29 -package java.lang.annotation;
  250.30 -
  250.31 -/**
  250.32 - * A program element type.  The constants of this enumerated type
  250.33 - * provide a simple classification of the declared elements in a
  250.34 - * Java program.
  250.35 - *
  250.36 - * <p>These constants are used with the {@link Target} meta-annotation type
  250.37 - * to specify where it is legal to use an annotation type.
  250.38 - *
  250.39 - * @author  Joshua Bloch
  250.40 - * @since 1.5
  250.41 - */
  250.42 -public enum ElementType {
  250.43 -    /** Class, interface (including annotation type), or enum declaration */
  250.44 -    TYPE,
  250.45 -
  250.46 -    /** Field declaration (includes enum constants) */
  250.47 -    FIELD,
  250.48 -
  250.49 -    /** Method declaration */
  250.50 -    METHOD,
  250.51 -
  250.52 -    /** Parameter declaration */
  250.53 -    PARAMETER,
  250.54 -
  250.55 -    /** Constructor declaration */
  250.56 -    CONSTRUCTOR,
  250.57 -
  250.58 -    /** Local variable declaration */
  250.59 -    LOCAL_VARIABLE,
  250.60 -
  250.61 -    /** Annotation type declaration */
  250.62 -    ANNOTATION_TYPE,
  250.63 -
  250.64 -    /** Package declaration */
  250.65 -    PACKAGE
  250.66 -}
   251.1 --- a/emul/src/main/java/java/lang/annotation/Retention.java	Wed Dec 05 10:03:58 2012 +0100
   251.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   251.3 @@ -1,47 +0,0 @@
   251.4 -/*
   251.5 - * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
   251.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   251.7 - *
   251.8 - * This code is free software; you can redistribute it and/or modify it
   251.9 - * under the terms of the GNU General Public License version 2 only, as
  251.10 - * published by the Free Software Foundation.  Oracle designates this
  251.11 - * particular file as subject to the "Classpath" exception as provided
  251.12 - * by Oracle in the LICENSE file that accompanied this code.
  251.13 - *
  251.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  251.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  251.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  251.17 - * version 2 for more details (a copy is included in the LICENSE file that
  251.18 - * accompanied this code).
  251.19 - *
  251.20 - * You should have received a copy of the GNU General Public License version
  251.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  251.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  251.23 - *
  251.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  251.25 - * or visit www.oracle.com if you need additional information or have any
  251.26 - * questions.
  251.27 - */
  251.28 -
  251.29 -package java.lang.annotation;
  251.30 -
  251.31 -/**
  251.32 - * Indicates how long annotations with the annotated type are to
  251.33 - * be retained.  If no Retention annotation is present on
  251.34 - * an annotation type declaration, the retention policy defaults to
  251.35 - * {@code RetentionPolicy.CLASS}.
  251.36 - *
  251.37 - * <p>A Retention meta-annotation has effect only if the
  251.38 - * meta-annotated type is used directly for annotation.  It has no
  251.39 - * effect if the meta-annotated type is used as a member type in
  251.40 - * another annotation type.
  251.41 - *
  251.42 - * @author  Joshua Bloch
  251.43 - * @since 1.5
  251.44 - */
  251.45 -@Documented
  251.46 -@Retention(RetentionPolicy.RUNTIME)
  251.47 -@Target(ElementType.ANNOTATION_TYPE)
  251.48 -public @interface Retention {
  251.49 -    RetentionPolicy value();
  251.50 -}
   252.1 --- a/emul/src/main/java/java/lang/annotation/RetentionPolicy.java	Wed Dec 05 10:03:58 2012 +0100
   252.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   252.3 @@ -1,57 +0,0 @@
   252.4 -/*
   252.5 - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
   252.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   252.7 - *
   252.8 - * This code is free software; you can redistribute it and/or modify it
   252.9 - * under the terms of the GNU General Public License version 2 only, as
  252.10 - * published by the Free Software Foundation.  Oracle designates this
  252.11 - * particular file as subject to the "Classpath" exception as provided
  252.12 - * by Oracle in the LICENSE file that accompanied this code.
  252.13 - *
  252.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  252.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  252.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  252.17 - * version 2 for more details (a copy is included in the LICENSE file that
  252.18 - * accompanied this code).
  252.19 - *
  252.20 - * You should have received a copy of the GNU General Public License version
  252.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  252.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  252.23 - *
  252.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  252.25 - * or visit www.oracle.com if you need additional information or have any
  252.26 - * questions.
  252.27 - */
  252.28 -
  252.29 -package java.lang.annotation;
  252.30 -
  252.31 -/**
  252.32 - * Annotation retention policy.  The constants of this enumerated type
  252.33 - * describe the various policies for retaining annotations.  They are used
  252.34 - * in conjunction with the {@link Retention} meta-annotation type to specify
  252.35 - * how long annotations are to be retained.
  252.36 - *
  252.37 - * @author  Joshua Bloch
  252.38 - * @since 1.5
  252.39 - */
  252.40 -public enum RetentionPolicy {
  252.41 -    /**
  252.42 -     * Annotations are to be discarded by the compiler.
  252.43 -     */
  252.44 -    SOURCE,
  252.45 -
  252.46 -    /**
  252.47 -     * Annotations are to be recorded in the class file by the compiler
  252.48 -     * but need not be retained by the VM at run time.  This is the default
  252.49 -     * behavior.
  252.50 -     */
  252.51 -    CLASS,
  252.52 -
  252.53 -    /**
  252.54 -     * Annotations are to be recorded in the class file by the compiler and
  252.55 -     * retained by the VM at run time, so they may be read reflectively.
  252.56 -     *
  252.57 -     * @see java.lang.reflect.AnnotatedElement
  252.58 -     */
  252.59 -    RUNTIME
  252.60 -}
   253.1 --- a/emul/src/main/java/java/lang/annotation/Target.java	Wed Dec 05 10:03:58 2012 +0100
   253.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   253.3 @@ -1,68 +0,0 @@
   253.4 -/*
   253.5 - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
   253.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   253.7 - *
   253.8 - * This code is free software; you can redistribute it and/or modify it
   253.9 - * under the terms of the GNU General Public License version 2 only, as
  253.10 - * published by the Free Software Foundation.  Oracle designates this
  253.11 - * particular file as subject to the "Classpath" exception as provided
  253.12 - * by Oracle in the LICENSE file that accompanied this code.
  253.13 - *
  253.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  253.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  253.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  253.17 - * version 2 for more details (a copy is included in the LICENSE file that
  253.18 - * accompanied this code).
  253.19 - *
  253.20 - * You should have received a copy of the GNU General Public License version
  253.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  253.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  253.23 - *
  253.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  253.25 - * or visit www.oracle.com if you need additional information or have any
  253.26 - * questions.
  253.27 - */
  253.28 -
  253.29 -package java.lang.annotation;
  253.30 -
  253.31 -/**
  253.32 - * Indicates the kinds of program element to which an annotation type
  253.33 - * is applicable.  If a Target meta-annotation is not present on an
  253.34 - * annotation type declaration, the declared type may be used on any
  253.35 - * program element.  If such a meta-annotation is present, the compiler
  253.36 - * will enforce the specified usage restriction.
  253.37 - *
  253.38 - * For example, this meta-annotation indicates that the declared type is
  253.39 - * itself a meta-annotation type.  It can only be used on annotation type
  253.40 - * declarations:
  253.41 - * <pre>
  253.42 - *    &#064;Target(ElementType.ANNOTATION_TYPE)
  253.43 - *    public &#064;interface MetaAnnotationType {
  253.44 - *        ...
  253.45 - *    }
  253.46 - * </pre>
  253.47 - * This meta-annotation indicates that the declared type is intended solely
  253.48 - * for use as a member type in complex annotation type declarations.  It
  253.49 - * cannot be used to annotate anything directly:
  253.50 - * <pre>
  253.51 - *    &#064;Target({})
  253.52 - *    public &#064;interface MemberType {
  253.53 - *        ...
  253.54 - *    }
  253.55 - * </pre>
  253.56 - * It is a compile-time error for a single ElementType constant to
  253.57 - * appear more than once in a Target annotation.  For example, the
  253.58 - * following meta-annotation is illegal:
  253.59 - * <pre>
  253.60 - *    &#064;Target({ElementType.FIELD, ElementType.METHOD, ElementType.FIELD})
  253.61 - *    public &#064;interface Bogus {
  253.62 - *        ...
  253.63 - *    }
  253.64 - * </pre>
  253.65 - */
  253.66 -@Documented
  253.67 -@Retention(RetentionPolicy.RUNTIME)
  253.68 -@Target(ElementType.ANNOTATION_TYPE)
  253.69 -public @interface Target {
  253.70 -    ElementType[] value();
  253.71 -}
   254.1 --- a/emul/src/main/java/java/lang/annotation/UnsupportedOperationException.java	Wed Dec 05 10:03:58 2012 +0100
   254.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   254.3 @@ -1,94 +0,0 @@
   254.4 -/*
   254.5 - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
   254.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   254.7 - *
   254.8 - * This code is free software; you can redistribute it and/or modify it
   254.9 - * under the terms of the GNU General Public License version 2 only, as
  254.10 - * published by the Free Software Foundation.  Oracle designates this
  254.11 - * particular file as subject to the "Classpath" exception as provided
  254.12 - * by Oracle in the LICENSE file that accompanied this code.
  254.13 - *
  254.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  254.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  254.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  254.17 - * version 2 for more details (a copy is included in the LICENSE file that
  254.18 - * accompanied this code).
  254.19 - *
  254.20 - * You should have received a copy of the GNU General Public License version
  254.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  254.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  254.23 - *
  254.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  254.25 - * or visit www.oracle.com if you need additional information or have any
  254.26 - * questions.
  254.27 - */
  254.28 -
  254.29 -package java.lang;
  254.30 -
  254.31 -/**
  254.32 - * Thrown to indicate that the requested operation is not supported.<p>
  254.33 - *
  254.34 - * This class is a member of the
  254.35 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  254.36 - * Java Collections Framework</a>.
  254.37 - *
  254.38 - * @author  Josh Bloch
  254.39 - * @since   1.2
  254.40 - */
  254.41 -public class UnsupportedOperationException extends RuntimeException {
  254.42 -    /**
  254.43 -     * Constructs an UnsupportedOperationException with no detail message.
  254.44 -     */
  254.45 -    public UnsupportedOperationException() {
  254.46 -    }
  254.47 -
  254.48 -    /**
  254.49 -     * Constructs an UnsupportedOperationException with the specified
  254.50 -     * detail message.
  254.51 -     *
  254.52 -     * @param message the detail message
  254.53 -     */
  254.54 -    public UnsupportedOperationException(String message) {
  254.55 -        super(message);
  254.56 -    }
  254.57 -
  254.58 -    /**
  254.59 -     * Constructs a new exception with the specified detail message and
  254.60 -     * cause.
  254.61 -     *
  254.62 -     * <p>Note that the detail message associated with <code>cause</code> is
  254.63 -     * <i>not</i> automatically incorporated in this exception's detail
  254.64 -     * message.
  254.65 -     *
  254.66 -     * @param  message the detail message (which is saved for later retrieval
  254.67 -     *         by the {@link Throwable#getMessage()} method).
  254.68 -     * @param  cause the cause (which is saved for later retrieval by the
  254.69 -     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value
  254.70 -     *         is permitted, and indicates that the cause is nonexistent or
  254.71 -     *         unknown.)
  254.72 -     * @since 1.5
  254.73 -     */
  254.74 -    public UnsupportedOperationException(String message, Throwable cause) {
  254.75 -        super(message, cause);
  254.76 -    }
  254.77 -
  254.78 -    /**
  254.79 -     * Constructs a new exception with the specified cause and a detail
  254.80 -     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  254.81 -     * typically contains the class and detail message of <tt>cause</tt>).
  254.82 -     * This constructor is useful for exceptions that are little more than
  254.83 -     * wrappers for other throwables (for example, {@link
  254.84 -     * java.security.PrivilegedActionException}).
  254.85 -     *
  254.86 -     * @param  cause the cause (which is saved for later retrieval by the
  254.87 -     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value is
  254.88 -     *         permitted, and indicates that the cause is nonexistent or
  254.89 -     *         unknown.)
  254.90 -     * @since  1.5
  254.91 -     */
  254.92 -    public UnsupportedOperationException(Throwable cause) {
  254.93 -        super(cause);
  254.94 -    }
  254.95 -
  254.96 -    static final long serialVersionUID = -1242599979055084673L;
  254.97 -}
   255.1 --- a/emul/src/main/java/java/lang/reflect/AccessibleObject.java	Wed Dec 05 10:03:58 2012 +0100
   255.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   255.3 @@ -1,167 +0,0 @@
   255.4 -/*
   255.5 - * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
   255.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   255.7 - *
   255.8 - * This code is free software; you can redistribute it and/or modify it
   255.9 - * under the terms of the GNU General Public License version 2 only, as
  255.10 - * published by the Free Software Foundation.  Oracle designates this
  255.11 - * particular file as subject to the "Classpath" exception as provided
  255.12 - * by Oracle in the LICENSE file that accompanied this code.
  255.13 - *
  255.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  255.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  255.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  255.17 - * version 2 for more details (a copy is included in the LICENSE file that
  255.18 - * accompanied this code).
  255.19 - *
  255.20 - * You should have received a copy of the GNU General Public License version
  255.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  255.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  255.23 - *
  255.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  255.25 - * or visit www.oracle.com if you need additional information or have any
  255.26 - * questions.
  255.27 - */
  255.28 -
  255.29 -package java.lang.reflect;
  255.30 -
  255.31 -import java.lang.annotation.Annotation;
  255.32 -
  255.33 -/**
  255.34 - * The AccessibleObject class is the base class for Field, Method and
  255.35 - * Constructor objects.  It provides the ability to flag a reflected
  255.36 - * object as suppressing default Java language access control checks
  255.37 - * when it is used.  The access checks--for public, default (package)
  255.38 - * access, protected, and private members--are performed when Fields,
  255.39 - * Methods or Constructors are used to set or get fields, to invoke
  255.40 - * methods, or to create and initialize new instances of classes,
  255.41 - * respectively.
  255.42 - *
  255.43 - * <p>Setting the {@code accessible} flag in a reflected object
  255.44 - * permits sophisticated applications with sufficient privilege, such
  255.45 - * as Java Object Serialization or other persistence mechanisms, to
  255.46 - * manipulate objects in a manner that would normally be prohibited.
  255.47 - *
  255.48 - * <p>By default, a reflected object is <em>not</em> accessible.
  255.49 - *
  255.50 - * @see Field
  255.51 - * @see Method
  255.52 - * @see Constructor
  255.53 - * @see ReflectPermission
  255.54 - *
  255.55 - * @since 1.2
  255.56 - */
  255.57 -public class AccessibleObject implements AnnotatedElement {
  255.58 -
  255.59 -    /**
  255.60 -     * Convenience method to set the {@code accessible} flag for an
  255.61 -     * array of objects with a single security check (for efficiency).
  255.62 -     *
  255.63 -     * <p>First, if there is a security manager, its
  255.64 -     * {@code checkPermission} method is called with a
  255.65 -     * {@code ReflectPermission("suppressAccessChecks")} permission.
  255.66 -     *
  255.67 -     * <p>A {@code SecurityException} is raised if {@code flag} is
  255.68 -     * {@code true} but accessibility of any of the elements of the input
  255.69 -     * {@code array} may not be changed (for example, if the element
  255.70 -     * object is a {@link Constructor} object for the class {@link
  255.71 -     * java.lang.Class}).  In the event of such a SecurityException, the
  255.72 -     * accessibility of objects is set to {@code flag} for array elements
  255.73 -     * upto (and excluding) the element for which the exception occurred; the
  255.74 -     * accessibility of elements beyond (and including) the element for which
  255.75 -     * the exception occurred is unchanged.
  255.76 -     *
  255.77 -     * @param array the array of AccessibleObjects
  255.78 -     * @param flag  the new value for the {@code accessible} flag
  255.79 -     *              in each object
  255.80 -     * @throws SecurityException if the request is denied.
  255.81 -     * @see SecurityManager#checkPermission
  255.82 -     * @see java.lang.RuntimePermission
  255.83 -     */
  255.84 -    public static void setAccessible(AccessibleObject[] array, boolean flag)
  255.85 -        throws SecurityException {
  255.86 -        throw new SecurityException();
  255.87 -    }
  255.88 -
  255.89 -    /**
  255.90 -     * Set the {@code accessible} flag for this object to
  255.91 -     * the indicated boolean value.  A value of {@code true} indicates that
  255.92 -     * the reflected object should suppress Java language access
  255.93 -     * checking when it is used.  A value of {@code false} indicates
  255.94 -     * that the reflected object should enforce Java language access checks.
  255.95 -     *
  255.96 -     * <p>First, if there is a security manager, its
  255.97 -     * {@code checkPermission} method is called with a
  255.98 -     * {@code ReflectPermission("suppressAccessChecks")} permission.
  255.99 -     *
 255.100 -     * <p>A {@code SecurityException} is raised if {@code flag} is
 255.101 -     * {@code true} but accessibility of this object may not be changed
 255.102 -     * (for example, if this element object is a {@link Constructor} object for
 255.103 -     * the class {@link java.lang.Class}).
 255.104 -     *
 255.105 -     * <p>A {@code SecurityException} is raised if this object is a {@link
 255.106 -     * java.lang.reflect.Constructor} object for the class
 255.107 -     * {@code java.lang.Class}, and {@code flag} is true.
 255.108 -     *
 255.109 -     * @param flag the new value for the {@code accessible} flag
 255.110 -     * @throws SecurityException if the request is denied.
 255.111 -     * @see SecurityManager#checkPermission
 255.112 -     * @see java.lang.RuntimePermission
 255.113 -     */
 255.114 -    public void setAccessible(boolean flag) throws SecurityException {
 255.115 -        throw new SecurityException();
 255.116 -    }
 255.117 -
 255.118 -    /**
 255.119 -     * Get the value of the {@code accessible} flag for this object.
 255.120 -     *
 255.121 -     * @return the value of the object's {@code accessible} flag
 255.122 -     */
 255.123 -    public boolean isAccessible() {
 255.124 -        return override;
 255.125 -    }
 255.126 -
 255.127 -    /**
 255.128 -     * Constructor: only used by the Java Virtual Machine.
 255.129 -     */
 255.130 -    protected AccessibleObject() {}
 255.131 -
 255.132 -    // Indicates whether language-level access checks are overridden
 255.133 -    // by this object. Initializes to "false". This field is used by
 255.134 -    // Field, Method, and Constructor.
 255.135 -    //
 255.136 -    // NOTE: for security purposes, this field must not be visible
 255.137 -    // outside this package.
 255.138 -    boolean override;
 255.139 -
 255.140 -    /**
 255.141 -     * @throws NullPointerException {@inheritDoc}
 255.142 -     * @since 1.5
 255.143 -     */
 255.144 -    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 255.145 -        throw new AssertionError("All subclasses should override this method");
 255.146 -    }
 255.147 -
 255.148 -    /**
 255.149 -     * @throws NullPointerException {@inheritDoc}
 255.150 -     * @since 1.5
 255.151 -     */
 255.152 -    public boolean isAnnotationPresent(
 255.153 -        Class<? extends Annotation> annotationClass) {
 255.154 -        return getAnnotation(annotationClass) != null;
 255.155 -    }
 255.156 -
 255.157 -    /**
 255.158 -     * @since 1.5
 255.159 -     */
 255.160 -    public Annotation[] getAnnotations() {
 255.161 -        return getDeclaredAnnotations();
 255.162 -    }
 255.163 -
 255.164 -    /**
 255.165 -     * @since 1.5
 255.166 -     */
 255.167 -    public Annotation[] getDeclaredAnnotations()  {
 255.168 -        throw new AssertionError("All subclasses should override this method");
 255.169 -    }
 255.170 -}
   256.1 --- a/emul/src/main/java/java/lang/reflect/AnnotatedElement.java	Wed Dec 05 10:03:58 2012 +0100
   256.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   256.3 @@ -1,112 +0,0 @@
   256.4 -/*
   256.5 - * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
   256.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   256.7 - *
   256.8 - * This code is free software; you can redistribute it and/or modify it
   256.9 - * under the terms of the GNU General Public License version 2 only, as
  256.10 - * published by the Free Software Foundation.  Oracle designates this
  256.11 - * particular file as subject to the "Classpath" exception as provided
  256.12 - * by Oracle in the LICENSE file that accompanied this code.
  256.13 - *
  256.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  256.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  256.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  256.17 - * version 2 for more details (a copy is included in the LICENSE file that
  256.18 - * accompanied this code).
  256.19 - *
  256.20 - * You should have received a copy of the GNU General Public License version
  256.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  256.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  256.23 - *
  256.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  256.25 - * or visit www.oracle.com if you need additional information or have any
  256.26 - * questions.
  256.27 - */
  256.28 -
  256.29 -package java.lang.reflect;
  256.30 -
  256.31 -import java.lang.annotation.Annotation;
  256.32 -
  256.33 -/**
  256.34 - * Represents an annotated element of the program currently running in this
  256.35 - * VM.  This interface allows annotations to be read reflectively.  All
  256.36 - * annotations returned by methods in this interface are immutable and
  256.37 - * serializable.  It is permissible for the caller to modify the
  256.38 - * arrays returned by accessors for array-valued enum members; it will
  256.39 - * have no affect on the arrays returned to other callers.
  256.40 - *
  256.41 - * <p>If an annotation returned by a method in this interface contains
  256.42 - * (directly or indirectly) a {@link Class}-valued member referring to
  256.43 - * a class that is not accessible in this VM, attempting to read the class
  256.44 - * by calling the relevant Class-returning method on the returned annotation
  256.45 - * will result in a {@link TypeNotPresentException}.
  256.46 - *
  256.47 - * <p>Similarly, attempting to read an enum-valued member will result in
  256.48 - * a {@link EnumConstantNotPresentException} if the enum constant in the
  256.49 - * annotation is no longer present in the enum type.
  256.50 - *
  256.51 - * <p>Finally, Attempting to read a member whose definition has evolved
  256.52 - * incompatibly will result in a {@link
  256.53 - * java.lang.annotation.AnnotationTypeMismatchException} or an
  256.54 - * {@link java.lang.annotation.IncompleteAnnotationException}.
  256.55 - *
  256.56 - * @see java.lang.EnumConstantNotPresentException
  256.57 - * @see java.lang.TypeNotPresentException
  256.58 - * @see java.lang.annotation.AnnotationFormatError
  256.59 - * @see java.lang.annotation.AnnotationTypeMismatchException
  256.60 - * @see java.lang.annotation.IncompleteAnnotationException
  256.61 - * @since 1.5
  256.62 - * @author Josh Bloch
  256.63 - */
  256.64 -public interface AnnotatedElement {
  256.65 -    /**
  256.66 -     * Returns true if an annotation for the specified type
  256.67 -     * is present on this element, else false.  This method
  256.68 -     * is designed primarily for convenient access to marker annotations.
  256.69 -     *
  256.70 -     * @param annotationClass the Class object corresponding to the
  256.71 -     *        annotation type
  256.72 -     * @return true if an annotation for the specified annotation
  256.73 -     *     type is present on this element, else false
  256.74 -     * @throws NullPointerException if the given annotation class is null
  256.75 -     * @since 1.5
  256.76 -     */
  256.77 -     boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
  256.78 -
  256.79 -   /**
  256.80 -     * Returns this element's annotation for the specified type if
  256.81 -     * such an annotation is present, else null.
  256.82 -     *
  256.83 -     * @param annotationClass the Class object corresponding to the
  256.84 -     *        annotation type
  256.85 -     * @return this element's annotation for the specified annotation type if
  256.86 -     *     present on this element, else null
  256.87 -     * @throws NullPointerException if the given annotation class is null
  256.88 -     * @since 1.5
  256.89 -     */
  256.90 -    <T extends Annotation> T getAnnotation(Class<T> annotationClass);
  256.91 -
  256.92 -    /**
  256.93 -     * Returns all annotations present on this element.  (Returns an array
  256.94 -     * of length zero if this element has no annotations.)  The caller of
  256.95 -     * this method is free to modify the returned array; it will have no
  256.96 -     * effect on the arrays returned to other callers.
  256.97 -     *
  256.98 -     * @return all annotations present on this element
  256.99 -     * @since 1.5
 256.100 -     */
 256.101 -    Annotation[] getAnnotations();
 256.102 -
 256.103 -    /**
 256.104 -     * Returns all annotations that are directly present on this
 256.105 -     * element.  Unlike the other methods in this interface, this method
 256.106 -     * ignores inherited annotations.  (Returns an array of length zero if
 256.107 -     * no annotations are directly present on this element.)  The caller of
 256.108 -     * this method is free to modify the returned array; it will have no
 256.109 -     * effect on the arrays returned to other callers.
 256.110 -     *
 256.111 -     * @return All annotations directly present on this element
 256.112 -     * @since 1.5
 256.113 -     */
 256.114 -    Annotation[] getDeclaredAnnotations();
 256.115 -}
   257.1 --- a/emul/src/main/java/java/lang/reflect/Field.java	Wed Dec 05 10:03:58 2012 +0100
   257.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   257.3 @@ -1,953 +0,0 @@
   257.4 -/*
   257.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   257.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   257.7 - *
   257.8 - * This code is free software; you can redistribute it and/or modify it
   257.9 - * under the terms of the GNU General Public License version 2 only, as
  257.10 - * published by the Free Software Foundation.  Oracle designates this
  257.11 - * particular file as subject to the "Classpath" exception as provided
  257.12 - * by Oracle in the LICENSE file that accompanied this code.
  257.13 - *
  257.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  257.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  257.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  257.17 - * version 2 for more details (a copy is included in the LICENSE file that
  257.18 - * accompanied this code).
  257.19 - *
  257.20 - * You should have received a copy of the GNU General Public License version
  257.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  257.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  257.23 - *
  257.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  257.25 - * or visit www.oracle.com if you need additional information or have any
  257.26 - * questions.
  257.27 - */
  257.28 -
  257.29 -package java.lang.reflect;
  257.30 -
  257.31 -import java.lang.annotation.Annotation;
  257.32 -
  257.33 -
  257.34 -/**
  257.35 - * A {@code Field} provides information about, and dynamic access to, a
  257.36 - * single field of a class or an interface.  The reflected field may
  257.37 - * be a class (static) field or an instance field.
  257.38 - *
  257.39 - * <p>A {@code Field} permits widening conversions to occur during a get or
  257.40 - * set access operation, but throws an {@code IllegalArgumentException} if a
  257.41 - * narrowing conversion would occur.
  257.42 - *
  257.43 - * @see Member
  257.44 - * @see java.lang.Class
  257.45 - * @see java.lang.Class#getFields()
  257.46 - * @see java.lang.Class#getField(String)
  257.47 - * @see java.lang.Class#getDeclaredFields()
  257.48 - * @see java.lang.Class#getDeclaredField(String)
  257.49 - *
  257.50 - * @author Kenneth Russell
  257.51 - * @author Nakul Saraiya
  257.52 - */
  257.53 -public final
  257.54 -class Field extends AccessibleObject implements Member {
  257.55 -
  257.56 -    private Class<?>            clazz;
  257.57 -    private int                 slot;
  257.58 -    // This is guaranteed to be interned by the VM in the 1.4
  257.59 -    // reflection implementation
  257.60 -    private String              name;
  257.61 -    private Class<?>            type;
  257.62 -    private int                 modifiers;
  257.63 -    // Generics and annotations support
  257.64 -    private transient String    signature;
  257.65 -    private byte[]              annotations;
  257.66 -    // For sharing of FieldAccessors. This branching structure is
  257.67 -    // currently only two levels deep (i.e., one root Field and
  257.68 -    // potentially many Field objects pointing to it.)
  257.69 -    private Field               root;
  257.70 -
  257.71 -    // Generics infrastructure
  257.72 -
  257.73 -    private String getGenericSignature() {return signature;}
  257.74 -
  257.75 -
  257.76 -    /**
  257.77 -     * Package-private constructor used by ReflectAccess to enable
  257.78 -     * instantiation of these objects in Java code from the java.lang
  257.79 -     * package via sun.reflect.LangReflectAccess.
  257.80 -     */
  257.81 -    Field(Class<?> declaringClass,
  257.82 -          String name,
  257.83 -          Class<?> type,
  257.84 -          int modifiers,
  257.85 -          int slot,
  257.86 -          String signature,
  257.87 -          byte[] annotations)
  257.88 -    {
  257.89 -        this.clazz = declaringClass;
  257.90 -        this.name = name;
  257.91 -        this.type = type;
  257.92 -        this.modifiers = modifiers;
  257.93 -        this.slot = slot;
  257.94 -        this.signature = signature;
  257.95 -        this.annotations = annotations;
  257.96 -    }
  257.97 -
  257.98 -    /**
  257.99 -     * Package-private routine (exposed to java.lang.Class via
 257.100 -     * ReflectAccess) which returns a copy of this Field. The copy's
 257.101 -     * "root" field points to this Field.
 257.102 -     */
 257.103 -    Field copy() {
 257.104 -        // This routine enables sharing of FieldAccessor objects
 257.105 -        // among Field objects which refer to the same underlying
 257.106 -        // method in the VM. (All of this contortion is only necessary
 257.107 -        // because of the "accessibility" bit in AccessibleObject,
 257.108 -        // which implicitly requires that new java.lang.reflect
 257.109 -        // objects be fabricated for each reflective call on Class
 257.110 -        // objects.)
 257.111 -        Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
 257.112 -        res.root = this;
 257.113 -        return res;
 257.114 -    }
 257.115 -
 257.116 -    /**
 257.117 -     * Returns the {@code Class} object representing the class or interface
 257.118 -     * that declares the field represented by this {@code Field} object.
 257.119 -     */
 257.120 -    public Class<?> getDeclaringClass() {
 257.121 -        return clazz;
 257.122 -    }
 257.123 -
 257.124 -    /**
 257.125 -     * Returns the name of the field represented by this {@code Field} object.
 257.126 -     */
 257.127 -    public String getName() {
 257.128 -        return name;
 257.129 -    }
 257.130 -
 257.131 -    /**
 257.132 -     * Returns the Java language modifiers for the field represented
 257.133 -     * by this {@code Field} object, as an integer. The {@code Modifier} class should
 257.134 -     * be used to decode the modifiers.
 257.135 -     *
 257.136 -     * @see Modifier
 257.137 -     */
 257.138 -    public int getModifiers() {
 257.139 -        return modifiers;
 257.140 -    }
 257.141 -
 257.142 -    /**
 257.143 -     * Returns {@code true} if this field represents an element of
 257.144 -     * an enumerated type; returns {@code false} otherwise.
 257.145 -     *
 257.146 -     * @return {@code true} if and only if this field represents an element of
 257.147 -     * an enumerated type.
 257.148 -     * @since 1.5
 257.149 -     */
 257.150 -    public boolean isEnumConstant() {
 257.151 -        return (getModifiers() & Modifier.ENUM) != 0;
 257.152 -    }
 257.153 -
 257.154 -    /**
 257.155 -     * Returns {@code true} if this field is a synthetic
 257.156 -     * field; returns {@code false} otherwise.
 257.157 -     *
 257.158 -     * @return true if and only if this field is a synthetic
 257.159 -     * field as defined by the Java Language Specification.
 257.160 -     * @since 1.5
 257.161 -     */
 257.162 -    public boolean isSynthetic() {
 257.163 -        return Modifier.isSynthetic(getModifiers());
 257.164 -    }
 257.165 -
 257.166 -    /**
 257.167 -     * Returns a {@code Class} object that identifies the
 257.168 -     * declared type for the field represented by this
 257.169 -     * {@code Field} object.
 257.170 -     *
 257.171 -     * @return a {@code Class} object identifying the declared
 257.172 -     * type of the field represented by this object
 257.173 -     */
 257.174 -    public Class<?> getType() {
 257.175 -        return type;
 257.176 -    }
 257.177 -
 257.178 -    /**
 257.179 -     * Returns a {@code Type} object that represents the declared type for
 257.180 -     * the field represented by this {@code Field} object.
 257.181 -     *
 257.182 -     * <p>If the {@code Type} is a parameterized type, the
 257.183 -     * {@code Type} object returned must accurately reflect the
 257.184 -     * actual type parameters used in the source code.
 257.185 -     *
 257.186 -     * <p>If the type of the underlying field is a type variable or a
 257.187 -     * parameterized type, it is created. Otherwise, it is resolved.
 257.188 -     *
 257.189 -     * @return a {@code Type} object that represents the declared type for
 257.190 -     *     the field represented by this {@code Field} object
 257.191 -     * @throws GenericSignatureFormatError if the generic field
 257.192 -     *     signature does not conform to the format specified in
 257.193 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 257.194 -     * @throws TypeNotPresentException if the generic type
 257.195 -     *     signature of the underlying field refers to a non-existent
 257.196 -     *     type declaration
 257.197 -     * @throws MalformedParameterizedTypeException if the generic
 257.198 -     *     signature of the underlying field refers to a parameterized type
 257.199 -     *     that cannot be instantiated for any reason
 257.200 -     * @since 1.5
 257.201 -     */
 257.202 -    public Type getGenericType() {
 257.203 -        throw new UnsupportedOperationException();
 257.204 -    }
 257.205 -
 257.206 -
 257.207 -    /**
 257.208 -     * Compares this {@code Field} against the specified object.  Returns
 257.209 -     * true if the objects are the same.  Two {@code Field} objects are the same if
 257.210 -     * they were declared by the same class and have the same name
 257.211 -     * and type.
 257.212 -     */
 257.213 -    public boolean equals(Object obj) {
 257.214 -        if (obj != null && obj instanceof Field) {
 257.215 -            Field other = (Field)obj;
 257.216 -            return (getDeclaringClass() == other.getDeclaringClass())
 257.217 -                && (getName() == other.getName())
 257.218 -                && (getType() == other.getType());
 257.219 -        }
 257.220 -        return false;
 257.221 -    }
 257.222 -
 257.223 -    /**
 257.224 -     * Returns a hashcode for this {@code Field}.  This is computed as the
 257.225 -     * exclusive-or of the hashcodes for the underlying field's
 257.226 -     * declaring class name and its name.
 257.227 -     */
 257.228 -    public int hashCode() {
 257.229 -        return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
 257.230 -    }
 257.231 -
 257.232 -    /**
 257.233 -     * Returns a string describing this {@code Field}.  The format is
 257.234 -     * the access modifiers for the field, if any, followed
 257.235 -     * by the field type, followed by a space, followed by
 257.236 -     * the fully-qualified name of the class declaring the field,
 257.237 -     * followed by a period, followed by the name of the field.
 257.238 -     * For example:
 257.239 -     * <pre>
 257.240 -     *    public static final int java.lang.Thread.MIN_PRIORITY
 257.241 -     *    private int java.io.FileDescriptor.fd
 257.242 -     * </pre>
 257.243 -     *
 257.244 -     * <p>The modifiers are placed in canonical order as specified by
 257.245 -     * "The Java Language Specification".  This is {@code public},
 257.246 -     * {@code protected} or {@code private} first, and then other
 257.247 -     * modifiers in the following order: {@code static}, {@code final},
 257.248 -     * {@code transient}, {@code volatile}.
 257.249 -     */
 257.250 -    public String toString() {
 257.251 -        int mod = getModifiers();
 257.252 -        return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
 257.253 -            + getTypeName(getType()) + " "
 257.254 -            + getTypeName(getDeclaringClass()) + "."
 257.255 -            + getName());
 257.256 -    }
 257.257 -
 257.258 -    /**
 257.259 -     * Returns a string describing this {@code Field}, including
 257.260 -     * its generic type.  The format is the access modifiers for the
 257.261 -     * field, if any, followed by the generic field type, followed by
 257.262 -     * a space, followed by the fully-qualified name of the class
 257.263 -     * declaring the field, followed by a period, followed by the name
 257.264 -     * of the field.
 257.265 -     *
 257.266 -     * <p>The modifiers are placed in canonical order as specified by
 257.267 -     * "The Java Language Specification".  This is {@code public},
 257.268 -     * {@code protected} or {@code private} first, and then other
 257.269 -     * modifiers in the following order: {@code static}, {@code final},
 257.270 -     * {@code transient}, {@code volatile}.
 257.271 -     *
 257.272 -     * @return a string describing this {@code Field}, including
 257.273 -     * its generic type
 257.274 -     *
 257.275 -     * @since 1.5
 257.276 -     */
 257.277 -    public String toGenericString() {
 257.278 -        int mod = getModifiers();
 257.279 -        Type fieldType = getGenericType();
 257.280 -        return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
 257.281 -            +  ((fieldType instanceof Class) ?
 257.282 -                getTypeName((Class)fieldType): fieldType.toString())+ " "
 257.283 -            + getTypeName(getDeclaringClass()) + "."
 257.284 -            + getName());
 257.285 -    }
 257.286 -
 257.287 -    /**
 257.288 -     * Returns the value of the field represented by this {@code Field}, on
 257.289 -     * the specified object. The value is automatically wrapped in an
 257.290 -     * object if it has a primitive type.
 257.291 -     *
 257.292 -     * <p>The underlying field's value is obtained as follows:
 257.293 -     *
 257.294 -     * <p>If the underlying field is a static field, the {@code obj} argument
 257.295 -     * is ignored; it may be null.
 257.296 -     *
 257.297 -     * <p>Otherwise, the underlying field is an instance field.  If the
 257.298 -     * specified {@code obj} argument is null, the method throws a
 257.299 -     * {@code NullPointerException}. If the specified object is not an
 257.300 -     * instance of the class or interface declaring the underlying
 257.301 -     * field, the method throws an {@code IllegalArgumentException}.
 257.302 -     *
 257.303 -     * <p>If this {@code Field} object is enforcing Java language access control, and
 257.304 -     * the underlying field is inaccessible, the method throws an
 257.305 -     * {@code IllegalAccessException}.
 257.306 -     * If the underlying field is static, the class that declared the
 257.307 -     * field is initialized if it has not already been initialized.
 257.308 -     *
 257.309 -     * <p>Otherwise, the value is retrieved from the underlying instance
 257.310 -     * or static field.  If the field has a primitive type, the value
 257.311 -     * is wrapped in an object before being returned, otherwise it is
 257.312 -     * returned as is.
 257.313 -     *
 257.314 -     * <p>If the field is hidden in the type of {@code obj},
 257.315 -     * the field's value is obtained according to the preceding rules.
 257.316 -     *
 257.317 -     * @param obj object from which the represented field's value is
 257.318 -     * to be extracted
 257.319 -     * @return the value of the represented field in object
 257.320 -     * {@code obj}; primitive values are wrapped in an appropriate
 257.321 -     * object before being returned
 257.322 -     *
 257.323 -     * @exception IllegalAccessException    if this {@code Field} object
 257.324 -     *              is enforcing Java language access control and the underlying
 257.325 -     *              field is inaccessible.
 257.326 -     * @exception IllegalArgumentException  if the specified object is not an
 257.327 -     *              instance of the class or interface declaring the underlying
 257.328 -     *              field (or a subclass or implementor thereof).
 257.329 -     * @exception NullPointerException      if the specified object is null
 257.330 -     *              and the field is an instance field.
 257.331 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.332 -     *              by this method fails.
 257.333 -     */
 257.334 -    public Object get(Object obj)
 257.335 -        throws IllegalArgumentException, IllegalAccessException
 257.336 -    {
 257.337 -        return getFieldAccessor(obj).get(obj);
 257.338 -    }
 257.339 -
 257.340 -    /**
 257.341 -     * Gets the value of a static or instance {@code boolean} field.
 257.342 -     *
 257.343 -     * @param obj the object to extract the {@code boolean} value
 257.344 -     * from
 257.345 -     * @return the value of the {@code boolean} field
 257.346 -     *
 257.347 -     * @exception IllegalAccessException    if this {@code Field} object
 257.348 -     *              is enforcing Java language access control and the underlying
 257.349 -     *              field is inaccessible.
 257.350 -     * @exception IllegalArgumentException  if the specified object is not
 257.351 -     *              an instance of the class or interface declaring the
 257.352 -     *              underlying field (or a subclass or implementor
 257.353 -     *              thereof), or if the field value cannot be
 257.354 -     *              converted to the type {@code boolean} by a
 257.355 -     *              widening conversion.
 257.356 -     * @exception NullPointerException      if the specified object is null
 257.357 -     *              and the field is an instance field.
 257.358 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.359 -     *              by this method fails.
 257.360 -     * @see       Field#get
 257.361 -     */
 257.362 -    public boolean getBoolean(Object obj)
 257.363 -        throws IllegalArgumentException, IllegalAccessException
 257.364 -    {
 257.365 -        return getFieldAccessor(obj).getBoolean(obj);
 257.366 -    }
 257.367 -
 257.368 -    /**
 257.369 -     * Gets the value of a static or instance {@code byte} field.
 257.370 -     *
 257.371 -     * @param obj the object to extract the {@code byte} value
 257.372 -     * from
 257.373 -     * @return the value of the {@code byte} field
 257.374 -     *
 257.375 -     * @exception IllegalAccessException    if this {@code Field} object
 257.376 -     *              is enforcing Java language access control and the underlying
 257.377 -     *              field is inaccessible.
 257.378 -     * @exception IllegalArgumentException  if the specified object is not
 257.379 -     *              an instance of the class or interface declaring the
 257.380 -     *              underlying field (or a subclass or implementor
 257.381 -     *              thereof), or if the field value cannot be
 257.382 -     *              converted to the type {@code byte} by a
 257.383 -     *              widening conversion.
 257.384 -     * @exception NullPointerException      if the specified object is null
 257.385 -     *              and the field is an instance field.
 257.386 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.387 -     *              by this method fails.
 257.388 -     * @see       Field#get
 257.389 -     */
 257.390 -    public byte getByte(Object obj)
 257.391 -        throws IllegalArgumentException, IllegalAccessException
 257.392 -    {
 257.393 -        return getFieldAccessor(obj).getByte(obj);
 257.394 -    }
 257.395 -
 257.396 -    /**
 257.397 -     * Gets the value of a static or instance field of type
 257.398 -     * {@code char} or of another primitive type convertible to
 257.399 -     * type {@code char} via a widening conversion.
 257.400 -     *
 257.401 -     * @param obj the object to extract the {@code char} value
 257.402 -     * from
 257.403 -     * @return the value of the field converted to type {@code char}
 257.404 -     *
 257.405 -     * @exception IllegalAccessException    if this {@code Field} object
 257.406 -     *              is enforcing Java language access control and the underlying
 257.407 -     *              field is inaccessible.
 257.408 -     * @exception IllegalArgumentException  if the specified object is not
 257.409 -     *              an instance of the class or interface declaring the
 257.410 -     *              underlying field (or a subclass or implementor
 257.411 -     *              thereof), or if the field value cannot be
 257.412 -     *              converted to the type {@code char} by a
 257.413 -     *              widening conversion.
 257.414 -     * @exception NullPointerException      if the specified object is null
 257.415 -     *              and the field is an instance field.
 257.416 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.417 -     *              by this method fails.
 257.418 -     * @see Field#get
 257.419 -     */
 257.420 -    public char getChar(Object obj)
 257.421 -        throws IllegalArgumentException, IllegalAccessException
 257.422 -    {
 257.423 -        return getFieldAccessor(obj).getChar(obj);
 257.424 -    }
 257.425 -
 257.426 -    /**
 257.427 -     * Gets the value of a static or instance field of type
 257.428 -     * {@code short} or of another primitive type convertible to
 257.429 -     * type {@code short} via a widening conversion.
 257.430 -     *
 257.431 -     * @param obj the object to extract the {@code short} value
 257.432 -     * from
 257.433 -     * @return the value of the field converted to type {@code short}
 257.434 -     *
 257.435 -     * @exception IllegalAccessException    if this {@code Field} object
 257.436 -     *              is enforcing Java language access control and the underlying
 257.437 -     *              field is inaccessible.
 257.438 -     * @exception IllegalArgumentException  if the specified object is not
 257.439 -     *              an instance of the class or interface declaring the
 257.440 -     *              underlying field (or a subclass or implementor
 257.441 -     *              thereof), or if the field value cannot be
 257.442 -     *              converted to the type {@code short} by a
 257.443 -     *              widening conversion.
 257.444 -     * @exception NullPointerException      if the specified object is null
 257.445 -     *              and the field is an instance field.
 257.446 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.447 -     *              by this method fails.
 257.448 -     * @see       Field#get
 257.449 -     */
 257.450 -    public short getShort(Object obj)
 257.451 -        throws IllegalArgumentException, IllegalAccessException
 257.452 -    {
 257.453 -        return getFieldAccessor(obj).getShort(obj);
 257.454 -    }
 257.455 -
 257.456 -    /**
 257.457 -     * Gets the value of a static or instance field of type
 257.458 -     * {@code int} or of another primitive type convertible to
 257.459 -     * type {@code int} via a widening conversion.
 257.460 -     *
 257.461 -     * @param obj the object to extract the {@code int} value
 257.462 -     * from
 257.463 -     * @return the value of the field converted to type {@code int}
 257.464 -     *
 257.465 -     * @exception IllegalAccessException    if this {@code Field} object
 257.466 -     *              is enforcing Java language access control and the underlying
 257.467 -     *              field is inaccessible.
 257.468 -     * @exception IllegalArgumentException  if the specified object is not
 257.469 -     *              an instance of the class or interface declaring the
 257.470 -     *              underlying field (or a subclass or implementor
 257.471 -     *              thereof), or if the field value cannot be
 257.472 -     *              converted to the type {@code int} by a
 257.473 -     *              widening conversion.
 257.474 -     * @exception NullPointerException      if the specified object is null
 257.475 -     *              and the field is an instance field.
 257.476 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.477 -     *              by this method fails.
 257.478 -     * @see       Field#get
 257.479 -     */
 257.480 -    public int getInt(Object obj)
 257.481 -        throws IllegalArgumentException, IllegalAccessException
 257.482 -    {
 257.483 -        return getFieldAccessor(obj).getInt(obj);
 257.484 -    }
 257.485 -
 257.486 -    /**
 257.487 -     * Gets the value of a static or instance field of type
 257.488 -     * {@code long} or of another primitive type convertible to
 257.489 -     * type {@code long} via a widening conversion.
 257.490 -     *
 257.491 -     * @param obj the object to extract the {@code long} value
 257.492 -     * from
 257.493 -     * @return the value of the field converted to type {@code long}
 257.494 -     *
 257.495 -     * @exception IllegalAccessException    if this {@code Field} object
 257.496 -     *              is enforcing Java language access control and the underlying
 257.497 -     *              field is inaccessible.
 257.498 -     * @exception IllegalArgumentException  if the specified object is not
 257.499 -     *              an instance of the class or interface declaring the
 257.500 -     *              underlying field (or a subclass or implementor
 257.501 -     *              thereof), or if the field value cannot be
 257.502 -     *              converted to the type {@code long} by a
 257.503 -     *              widening conversion.
 257.504 -     * @exception NullPointerException      if the specified object is null
 257.505 -     *              and the field is an instance field.
 257.506 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.507 -     *              by this method fails.
 257.508 -     * @see       Field#get
 257.509 -     */
 257.510 -    public long getLong(Object obj)
 257.511 -        throws IllegalArgumentException, IllegalAccessException
 257.512 -    {
 257.513 -        return getFieldAccessor(obj).getLong(obj);
 257.514 -    }
 257.515 -
 257.516 -    /**
 257.517 -     * Gets the value of a static or instance field of type
 257.518 -     * {@code float} or of another primitive type convertible to
 257.519 -     * type {@code float} via a widening conversion.
 257.520 -     *
 257.521 -     * @param obj the object to extract the {@code float} value
 257.522 -     * from
 257.523 -     * @return the value of the field converted to type {@code float}
 257.524 -     *
 257.525 -     * @exception IllegalAccessException    if this {@code Field} object
 257.526 -     *              is enforcing Java language access control and the underlying
 257.527 -     *              field is inaccessible.
 257.528 -     * @exception IllegalArgumentException  if the specified object is not
 257.529 -     *              an instance of the class or interface declaring the
 257.530 -     *              underlying field (or a subclass or implementor
 257.531 -     *              thereof), or if the field value cannot be
 257.532 -     *              converted to the type {@code float} by a
 257.533 -     *              widening conversion.
 257.534 -     * @exception NullPointerException      if the specified object is null
 257.535 -     *              and the field is an instance field.
 257.536 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.537 -     *              by this method fails.
 257.538 -     * @see Field#get
 257.539 -     */
 257.540 -    public float getFloat(Object obj)
 257.541 -        throws IllegalArgumentException, IllegalAccessException
 257.542 -    {
 257.543 -        return getFieldAccessor(obj).getFloat(obj);
 257.544 -    }
 257.545 -
 257.546 -    /**
 257.547 -     * Gets the value of a static or instance field of type
 257.548 -     * {@code double} or of another primitive type convertible to
 257.549 -     * type {@code double} via a widening conversion.
 257.550 -     *
 257.551 -     * @param obj the object to extract the {@code double} value
 257.552 -     * from
 257.553 -     * @return the value of the field converted to type {@code double}
 257.554 -     *
 257.555 -     * @exception IllegalAccessException    if this {@code Field} object
 257.556 -     *              is enforcing Java language access control and the underlying
 257.557 -     *              field is inaccessible.
 257.558 -     * @exception IllegalArgumentException  if the specified object is not
 257.559 -     *              an instance of the class or interface declaring the
 257.560 -     *              underlying field (or a subclass or implementor
 257.561 -     *              thereof), or if the field value cannot be
 257.562 -     *              converted to the type {@code double} by a
 257.563 -     *              widening conversion.
 257.564 -     * @exception NullPointerException      if the specified object is null
 257.565 -     *              and the field is an instance field.
 257.566 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.567 -     *              by this method fails.
 257.568 -     * @see       Field#get
 257.569 -     */
 257.570 -    public double getDouble(Object obj)
 257.571 -        throws IllegalArgumentException, IllegalAccessException
 257.572 -    {
 257.573 -        return getFieldAccessor(obj).getDouble(obj);
 257.574 -    }
 257.575 -
 257.576 -    /**
 257.577 -     * Sets the field represented by this {@code Field} object on the
 257.578 -     * specified object argument to the specified new value. The new
 257.579 -     * value is automatically unwrapped if the underlying field has a
 257.580 -     * primitive type.
 257.581 -     *
 257.582 -     * <p>The operation proceeds as follows:
 257.583 -     *
 257.584 -     * <p>If the underlying field is static, the {@code obj} argument is
 257.585 -     * ignored; it may be null.
 257.586 -     *
 257.587 -     * <p>Otherwise the underlying field is an instance field.  If the
 257.588 -     * specified object argument is null, the method throws a
 257.589 -     * {@code NullPointerException}.  If the specified object argument is not
 257.590 -     * an instance of the class or interface declaring the underlying
 257.591 -     * field, the method throws an {@code IllegalArgumentException}.
 257.592 -     *
 257.593 -     * <p>If this {@code Field} object is enforcing Java language access control, and
 257.594 -     * the underlying field is inaccessible, the method throws an
 257.595 -     * {@code IllegalAccessException}.
 257.596 -     *
 257.597 -     * <p>If the underlying field is final, the method throws an
 257.598 -     * {@code IllegalAccessException} unless {@code setAccessible(true)}
 257.599 -     * has succeeded for this {@code Field} object
 257.600 -     * and the field is non-static. Setting a final field in this way
 257.601 -     * is meaningful only during deserialization or reconstruction of
 257.602 -     * instances of classes with blank final fields, before they are
 257.603 -     * made available for access by other parts of a program. Use in
 257.604 -     * any other context may have unpredictable effects, including cases
 257.605 -     * in which other parts of a program continue to use the original
 257.606 -     * value of this field.
 257.607 -     *
 257.608 -     * <p>If the underlying field is of a primitive type, an unwrapping
 257.609 -     * conversion is attempted to convert the new value to a value of
 257.610 -     * a primitive type.  If this attempt fails, the method throws an
 257.611 -     * {@code IllegalArgumentException}.
 257.612 -     *
 257.613 -     * <p>If, after possible unwrapping, the new value cannot be
 257.614 -     * converted to the type of the underlying field by an identity or
 257.615 -     * widening conversion, the method throws an
 257.616 -     * {@code IllegalArgumentException}.
 257.617 -     *
 257.618 -     * <p>If the underlying field is static, the class that declared the
 257.619 -     * field is initialized if it has not already been initialized.
 257.620 -     *
 257.621 -     * <p>The field is set to the possibly unwrapped and widened new value.
 257.622 -     *
 257.623 -     * <p>If the field is hidden in the type of {@code obj},
 257.624 -     * the field's value is set according to the preceding rules.
 257.625 -     *
 257.626 -     * @param obj the object whose field should be modified
 257.627 -     * @param value the new value for the field of {@code obj}
 257.628 -     * being modified
 257.629 -     *
 257.630 -     * @exception IllegalAccessException    if this {@code Field} object
 257.631 -     *              is enforcing Java language access control and the underlying
 257.632 -     *              field is either inaccessible or final.
 257.633 -     * @exception IllegalArgumentException  if the specified object is not an
 257.634 -     *              instance of the class or interface declaring the underlying
 257.635 -     *              field (or a subclass or implementor thereof),
 257.636 -     *              or if an unwrapping conversion fails.
 257.637 -     * @exception NullPointerException      if the specified object is null
 257.638 -     *              and the field is an instance field.
 257.639 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.640 -     *              by this method fails.
 257.641 -     */
 257.642 -    public void set(Object obj, Object value)
 257.643 -        throws IllegalArgumentException, IllegalAccessException
 257.644 -    {
 257.645 -        getFieldAccessor(obj).set(obj, value);
 257.646 -    }
 257.647 -
 257.648 -    /**
 257.649 -     * Sets the value of a field as a {@code boolean} on the specified object.
 257.650 -     * This method is equivalent to
 257.651 -     * {@code set(obj, zObj)},
 257.652 -     * where {@code zObj} is a {@code Boolean} object and
 257.653 -     * {@code zObj.booleanValue() == z}.
 257.654 -     *
 257.655 -     * @param obj the object whose field should be modified
 257.656 -     * @param z   the new value for the field of {@code obj}
 257.657 -     * being modified
 257.658 -     *
 257.659 -     * @exception IllegalAccessException    if this {@code Field} object
 257.660 -     *              is enforcing Java language access control and the underlying
 257.661 -     *              field is either inaccessible or final.
 257.662 -     * @exception IllegalArgumentException  if the specified object is not an
 257.663 -     *              instance of the class or interface declaring the underlying
 257.664 -     *              field (or a subclass or implementor thereof),
 257.665 -     *              or if an unwrapping conversion fails.
 257.666 -     * @exception NullPointerException      if the specified object is null
 257.667 -     *              and the field is an instance field.
 257.668 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.669 -     *              by this method fails.
 257.670 -     * @see       Field#set
 257.671 -     */
 257.672 -    public void setBoolean(Object obj, boolean z)
 257.673 -        throws IllegalArgumentException, IllegalAccessException
 257.674 -    {
 257.675 -        getFieldAccessor(obj).setBoolean(obj, z);
 257.676 -    }
 257.677 -
 257.678 -    /**
 257.679 -     * Sets the value of a field as a {@code byte} on the specified object.
 257.680 -     * This method is equivalent to
 257.681 -     * {@code set(obj, bObj)},
 257.682 -     * where {@code bObj} is a {@code Byte} object and
 257.683 -     * {@code bObj.byteValue() == b}.
 257.684 -     *
 257.685 -     * @param obj the object whose field should be modified
 257.686 -     * @param b   the new value for the field of {@code obj}
 257.687 -     * being modified
 257.688 -     *
 257.689 -     * @exception IllegalAccessException    if this {@code Field} object
 257.690 -     *              is enforcing Java language access control and the underlying
 257.691 -     *              field is either inaccessible or final.
 257.692 -     * @exception IllegalArgumentException  if the specified object is not an
 257.693 -     *              instance of the class or interface declaring the underlying
 257.694 -     *              field (or a subclass or implementor thereof),
 257.695 -     *              or if an unwrapping conversion fails.
 257.696 -     * @exception NullPointerException      if the specified object is null
 257.697 -     *              and the field is an instance field.
 257.698 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.699 -     *              by this method fails.
 257.700 -     * @see       Field#set
 257.701 -     */
 257.702 -    public void setByte(Object obj, byte b)
 257.703 -        throws IllegalArgumentException, IllegalAccessException
 257.704 -    {
 257.705 -        getFieldAccessor(obj).setByte(obj, b);
 257.706 -    }
 257.707 -
 257.708 -    /**
 257.709 -     * Sets the value of a field as a {@code char} on the specified object.
 257.710 -     * This method is equivalent to
 257.711 -     * {@code set(obj, cObj)},
 257.712 -     * where {@code cObj} is a {@code Character} object and
 257.713 -     * {@code cObj.charValue() == c}.
 257.714 -     *
 257.715 -     * @param obj the object whose field should be modified
 257.716 -     * @param c   the new value for the field of {@code obj}
 257.717 -     * being modified
 257.718 -     *
 257.719 -     * @exception IllegalAccessException    if this {@code Field} object
 257.720 -     *              is enforcing Java language access control and the underlying
 257.721 -     *              field is either inaccessible or final.
 257.722 -     * @exception IllegalArgumentException  if the specified object is not an
 257.723 -     *              instance of the class or interface declaring the underlying
 257.724 -     *              field (or a subclass or implementor thereof),
 257.725 -     *              or if an unwrapping conversion fails.
 257.726 -     * @exception NullPointerException      if the specified object is null
 257.727 -     *              and the field is an instance field.
 257.728 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.729 -     *              by this method fails.
 257.730 -     * @see       Field#set
 257.731 -     */
 257.732 -    public void setChar(Object obj, char c)
 257.733 -        throws IllegalArgumentException, IllegalAccessException
 257.734 -    {
 257.735 -        getFieldAccessor(obj).setChar(obj, c);
 257.736 -    }
 257.737 -
 257.738 -    /**
 257.739 -     * Sets the value of a field as a {@code short} on the specified object.
 257.740 -     * This method is equivalent to
 257.741 -     * {@code set(obj, sObj)},
 257.742 -     * where {@code sObj} is a {@code Short} object and
 257.743 -     * {@code sObj.shortValue() == s}.
 257.744 -     *
 257.745 -     * @param obj the object whose field should be modified
 257.746 -     * @param s   the new value for the field of {@code obj}
 257.747 -     * being modified
 257.748 -     *
 257.749 -     * @exception IllegalAccessException    if this {@code Field} object
 257.750 -     *              is enforcing Java language access control and the underlying
 257.751 -     *              field is either inaccessible or final.
 257.752 -     * @exception IllegalArgumentException  if the specified object is not an
 257.753 -     *              instance of the class or interface declaring the underlying
 257.754 -     *              field (or a subclass or implementor thereof),
 257.755 -     *              or if an unwrapping conversion fails.
 257.756 -     * @exception NullPointerException      if the specified object is null
 257.757 -     *              and the field is an instance field.
 257.758 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.759 -     *              by this method fails.
 257.760 -     * @see       Field#set
 257.761 -     */
 257.762 -    public void setShort(Object obj, short s)
 257.763 -        throws IllegalArgumentException, IllegalAccessException
 257.764 -    {
 257.765 -        getFieldAccessor(obj).setShort(obj, s);
 257.766 -    }
 257.767 -
 257.768 -    /**
 257.769 -     * Sets the value of a field as an {@code int} on the specified object.
 257.770 -     * This method is equivalent to
 257.771 -     * {@code set(obj, iObj)},
 257.772 -     * where {@code iObj} is a {@code Integer} object and
 257.773 -     * {@code iObj.intValue() == i}.
 257.774 -     *
 257.775 -     * @param obj the object whose field should be modified
 257.776 -     * @param i   the new value for the field of {@code obj}
 257.777 -     * being modified
 257.778 -     *
 257.779 -     * @exception IllegalAccessException    if this {@code Field} object
 257.780 -     *              is enforcing Java language access control and the underlying
 257.781 -     *              field is either inaccessible or final.
 257.782 -     * @exception IllegalArgumentException  if the specified object is not an
 257.783 -     *              instance of the class or interface declaring the underlying
 257.784 -     *              field (or a subclass or implementor thereof),
 257.785 -     *              or if an unwrapping conversion fails.
 257.786 -     * @exception NullPointerException      if the specified object is null
 257.787 -     *              and the field is an instance field.
 257.788 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.789 -     *              by this method fails.
 257.790 -     * @see       Field#set
 257.791 -     */
 257.792 -    public void setInt(Object obj, int i)
 257.793 -        throws IllegalArgumentException, IllegalAccessException
 257.794 -    {
 257.795 -        getFieldAccessor(obj).setInt(obj, i);
 257.796 -    }
 257.797 -
 257.798 -    /**
 257.799 -     * Sets the value of a field as a {@code long} on the specified object.
 257.800 -     * This method is equivalent to
 257.801 -     * {@code set(obj, lObj)},
 257.802 -     * where {@code lObj} is a {@code Long} object and
 257.803 -     * {@code lObj.longValue() == l}.
 257.804 -     *
 257.805 -     * @param obj the object whose field should be modified
 257.806 -     * @param l   the new value for the field of {@code obj}
 257.807 -     * being modified
 257.808 -     *
 257.809 -     * @exception IllegalAccessException    if this {@code Field} object
 257.810 -     *              is enforcing Java language access control and the underlying
 257.811 -     *              field is either inaccessible or final.
 257.812 -     * @exception IllegalArgumentException  if the specified object is not an
 257.813 -     *              instance of the class or interface declaring the underlying
 257.814 -     *              field (or a subclass or implementor thereof),
 257.815 -     *              or if an unwrapping conversion fails.
 257.816 -     * @exception NullPointerException      if the specified object is null
 257.817 -     *              and the field is an instance field.
 257.818 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.819 -     *              by this method fails.
 257.820 -     * @see       Field#set
 257.821 -     */
 257.822 -    public void setLong(Object obj, long l)
 257.823 -        throws IllegalArgumentException, IllegalAccessException
 257.824 -    {
 257.825 -        getFieldAccessor(obj).setLong(obj, l);
 257.826 -    }
 257.827 -
 257.828 -    /**
 257.829 -     * Sets the value of a field as a {@code float} on the specified object.
 257.830 -     * This method is equivalent to
 257.831 -     * {@code set(obj, fObj)},
 257.832 -     * where {@code fObj} is a {@code Float} object and
 257.833 -     * {@code fObj.floatValue() == f}.
 257.834 -     *
 257.835 -     * @param obj the object whose field should be modified
 257.836 -     * @param f   the new value for the field of {@code obj}
 257.837 -     * being modified
 257.838 -     *
 257.839 -     * @exception IllegalAccessException    if this {@code Field} object
 257.840 -     *              is enforcing Java language access control and the underlying
 257.841 -     *              field is either inaccessible or final.
 257.842 -     * @exception IllegalArgumentException  if the specified object is not an
 257.843 -     *              instance of the class or interface declaring the underlying
 257.844 -     *              field (or a subclass or implementor thereof),
 257.845 -     *              or if an unwrapping conversion fails.
 257.846 -     * @exception NullPointerException      if the specified object is null
 257.847 -     *              and the field is an instance field.
 257.848 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.849 -     *              by this method fails.
 257.850 -     * @see       Field#set
 257.851 -     */
 257.852 -    public void setFloat(Object obj, float f)
 257.853 -        throws IllegalArgumentException, IllegalAccessException
 257.854 -    {
 257.855 -        getFieldAccessor(obj).setFloat(obj, f);
 257.856 -    }
 257.857 -
 257.858 -    /**
 257.859 -     * Sets the value of a field as a {@code double} on the specified object.
 257.860 -     * This method is equivalent to
 257.861 -     * {@code set(obj, dObj)},
 257.862 -     * where {@code dObj} is a {@code Double} object and
 257.863 -     * {@code dObj.doubleValue() == d}.
 257.864 -     *
 257.865 -     * @param obj the object whose field should be modified
 257.866 -     * @param d   the new value for the field of {@code obj}
 257.867 -     * being modified
 257.868 -     *
 257.869 -     * @exception IllegalAccessException    if this {@code Field} object
 257.870 -     *              is enforcing Java language access control and the underlying
 257.871 -     *              field is either inaccessible or final.
 257.872 -     * @exception IllegalArgumentException  if the specified object is not an
 257.873 -     *              instance of the class or interface declaring the underlying
 257.874 -     *              field (or a subclass or implementor thereof),
 257.875 -     *              or if an unwrapping conversion fails.
 257.876 -     * @exception NullPointerException      if the specified object is null
 257.877 -     *              and the field is an instance field.
 257.878 -     * @exception ExceptionInInitializerError if the initialization provoked
 257.879 -     *              by this method fails.
 257.880 -     * @see       Field#set
 257.881 -     */
 257.882 -    public void setDouble(Object obj, double d)
 257.883 -        throws IllegalArgumentException, IllegalAccessException
 257.884 -    {
 257.885 -        getFieldAccessor(obj).setDouble(obj, d);
 257.886 -    }
 257.887 -
 257.888 -    // Convenience routine which performs security checks
 257.889 -    private FieldAccessor getFieldAccessor(Object obj)
 257.890 -        throws IllegalAccessException
 257.891 -    {
 257.892 -        throw new SecurityException();
 257.893 -    }
 257.894 -    
 257.895 -    private static abstract class FieldAccessor {
 257.896 -        abstract void setShort(Object obj, short s);
 257.897 -        abstract void setInt(Object obj, int i);
 257.898 -        abstract void setChar(Object obj, char c);
 257.899 -        abstract void setByte(Object obj, byte b);
 257.900 -        abstract void setBoolean(Object obj, boolean z);
 257.901 -        abstract void set(Object obj, Object value);
 257.902 -        abstract double getDouble(Object obj);
 257.903 -        abstract void setLong(Object obj, long l);
 257.904 -        abstract void setFloat(Object obj, float f);
 257.905 -        abstract void setDouble(Object obj, double d);
 257.906 -        abstract long getLong(Object obj);
 257.907 -        abstract int getInt(Object obj);
 257.908 -        abstract short getShort(Object obj);
 257.909 -        abstract char getChar(Object obj);
 257.910 -        abstract byte getByte(Object obj);
 257.911 -        abstract boolean getBoolean(Object obj);
 257.912 -        abstract Object get(Object obj);
 257.913 -        abstract float getFloat(Object obj);
 257.914 -    }
 257.915 -
 257.916 -    /*
 257.917 -     * Utility routine to paper over array type names
 257.918 -     */
 257.919 -    static String getTypeName(Class<?> type) {
 257.920 -        if (type.isArray()) {
 257.921 -            try {
 257.922 -                Class<?> cl = type;
 257.923 -                int dimensions = 0;
 257.924 -                while (cl.isArray()) {
 257.925 -                    dimensions++;
 257.926 -                    cl = cl.getComponentType();
 257.927 -                }
 257.928 -                StringBuffer sb = new StringBuffer();
 257.929 -                sb.append(cl.getName());
 257.930 -                for (int i = 0; i < dimensions; i++) {
 257.931 -                    sb.append("[]");
 257.932 -                }
 257.933 -                return sb.toString();
 257.934 -            } catch (Throwable e) { /*FALLTHRU*/ }
 257.935 -        }
 257.936 -        return type.getName();
 257.937 -    }
 257.938 -
 257.939 -    /**
 257.940 -     * @throws NullPointerException {@inheritDoc}
 257.941 -     * @since 1.5
 257.942 -     */
 257.943 -    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 257.944 -        if (annotationClass == null)
 257.945 -            throw new NullPointerException();
 257.946 -
 257.947 -        throw new UnsupportedOperationException();
 257.948 -    }
 257.949 -
 257.950 -    /**
 257.951 -     * @since 1.5
 257.952 -     */
 257.953 -    public Annotation[] getDeclaredAnnotations()  {
 257.954 -        throw new UnsupportedOperationException();
 257.955 -    }
 257.956 -}
   258.1 --- a/emul/src/main/java/java/lang/reflect/GenericDeclaration.java	Wed Dec 05 10:03:58 2012 +0100
   258.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   258.3 @@ -1,49 +0,0 @@
   258.4 -/*
   258.5 - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
   258.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   258.7 - *
   258.8 - * This code is free software; you can redistribute it and/or modify it
   258.9 - * under the terms of the GNU General Public License version 2 only, as
  258.10 - * published by the Free Software Foundation.  Oracle designates this
  258.11 - * particular file as subject to the "Classpath" exception as provided
  258.12 - * by Oracle in the LICENSE file that accompanied this code.
  258.13 - *
  258.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  258.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  258.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  258.17 - * version 2 for more details (a copy is included in the LICENSE file that
  258.18 - * accompanied this code).
  258.19 - *
  258.20 - * You should have received a copy of the GNU General Public License version
  258.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  258.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  258.23 - *
  258.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  258.25 - * or visit www.oracle.com if you need additional information or have any
  258.26 - * questions.
  258.27 - */
  258.28 -
  258.29 -package java.lang.reflect;
  258.30 -
  258.31 -/**
  258.32 - * A common interface for all entities that declare type variables.
  258.33 - *
  258.34 - * @since 1.5
  258.35 - */
  258.36 -public interface GenericDeclaration {
  258.37 -    /**
  258.38 -     * Returns an array of {@code TypeVariable} objects that
  258.39 -     * represent the type variables declared by the generic
  258.40 -     * declaration represented by this {@code GenericDeclaration}
  258.41 -     * object, in declaration order.  Returns an array of length 0 if
  258.42 -     * the underlying generic declaration declares no type variables.
  258.43 -     *
  258.44 -     * @return an array of {@code TypeVariable} objects that represent
  258.45 -     *     the type variables declared by this generic declaration
  258.46 -     * @throws GenericSignatureFormatError if the generic
  258.47 -     *     signature of this generic declaration does not conform to
  258.48 -     *     the format specified in
  258.49 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
  258.50 -     */
  258.51 -    public TypeVariable<?>[] getTypeParameters();
  258.52 -}
   259.1 --- a/emul/src/main/java/java/lang/reflect/InvocationTargetException.java	Wed Dec 05 10:03:58 2012 +0100
   259.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   259.3 @@ -1,111 +0,0 @@
   259.4 -/*
   259.5 - * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
   259.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   259.7 - *
   259.8 - * This code is free software; you can redistribute it and/or modify it
   259.9 - * under the terms of the GNU General Public License version 2 only, as
  259.10 - * published by the Free Software Foundation.  Oracle designates this
  259.11 - * particular file as subject to the "Classpath" exception as provided
  259.12 - * by Oracle in the LICENSE file that accompanied this code.
  259.13 - *
  259.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  259.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  259.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  259.17 - * version 2 for more details (a copy is included in the LICENSE file that
  259.18 - * accompanied this code).
  259.19 - *
  259.20 - * You should have received a copy of the GNU General Public License version
  259.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  259.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  259.23 - *
  259.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  259.25 - * or visit www.oracle.com if you need additional information or have any
  259.26 - * questions.
  259.27 - */
  259.28 -
  259.29 -package java.lang.reflect;
  259.30 -
  259.31 -/**
  259.32 - * InvocationTargetException is a checked exception that wraps
  259.33 - * an exception thrown by an invoked method or constructor.
  259.34 - *
  259.35 - * <p>As of release 1.4, this exception has been retrofitted to conform to
  259.36 - * the general purpose exception-chaining mechanism.  The "target exception"
  259.37 - * that is provided at construction time and accessed via the
  259.38 - * {@link #getTargetException()} method is now known as the <i>cause</i>,
  259.39 - * and may be accessed via the {@link Throwable#getCause()} method,
  259.40 - * as well as the aforementioned "legacy method."
  259.41 - *
  259.42 - * @see Method
  259.43 - * @see Constructor
  259.44 - */
  259.45 -public class InvocationTargetException extends ReflectiveOperationException {
  259.46 -    /**
  259.47 -     * Use serialVersionUID from JDK 1.1.X for interoperability
  259.48 -     */
  259.49 -    private static final long serialVersionUID = 4085088731926701167L;
  259.50 -
  259.51 -     /**
  259.52 -     * This field holds the target if the
  259.53 -     * InvocationTargetException(Throwable target) constructor was
  259.54 -     * used to instantiate the object
  259.55 -     *
  259.56 -     * @serial
  259.57 -     *
  259.58 -     */
  259.59 -    private Throwable target;
  259.60 -
  259.61 -    /**
  259.62 -     * Constructs an {@code InvocationTargetException} with
  259.63 -     * {@code null} as the target exception.
  259.64 -     */
  259.65 -    protected InvocationTargetException() {
  259.66 -        super((Throwable)null);  // Disallow initCause
  259.67 -    }
  259.68 -
  259.69 -    /**
  259.70 -     * Constructs a InvocationTargetException with a target exception.
  259.71 -     *
  259.72 -     * @param target the target exception
  259.73 -     */
  259.74 -    public InvocationTargetException(Throwable target) {
  259.75 -        super((Throwable)null);  // Disallow initCause
  259.76 -        this.target = target;
  259.77 -    }
  259.78 -
  259.79 -    /**
  259.80 -     * Constructs a InvocationTargetException with a target exception
  259.81 -     * and a detail message.
  259.82 -     *
  259.83 -     * @param target the target exception
  259.84 -     * @param s      the detail message
  259.85 -     */
  259.86 -    public InvocationTargetException(Throwable target, String s) {
  259.87 -        super(s, null);  // Disallow initCause
  259.88 -        this.target = target;
  259.89 -    }
  259.90 -
  259.91 -    /**
  259.92 -     * Get the thrown target exception.
  259.93 -     *
  259.94 -     * <p>This method predates the general-purpose exception chaining facility.
  259.95 -     * The {@link Throwable#getCause()} method is now the preferred means of
  259.96 -     * obtaining this information.
  259.97 -     *
  259.98 -     * @return the thrown target exception (cause of this exception).
  259.99 -     */
 259.100 -    public Throwable getTargetException() {
 259.101 -        return target;
 259.102 -    }
 259.103 -
 259.104 -    /**
 259.105 -     * Returns the cause of this exception (the thrown target exception,
 259.106 -     * which may be {@code null}).
 259.107 -     *
 259.108 -     * @return  the cause of this exception.
 259.109 -     * @since   1.4
 259.110 -     */
 259.111 -    public Throwable getCause() {
 259.112 -        return target;
 259.113 -    }
 259.114 -}
   260.1 --- a/emul/src/main/java/java/lang/reflect/Member.java	Wed Dec 05 10:03:58 2012 +0100
   260.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   260.3 @@ -1,93 +0,0 @@
   260.4 -/*
   260.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   260.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   260.7 - *
   260.8 - * This code is free software; you can redistribute it and/or modify it
   260.9 - * under the terms of the GNU General Public License version 2 only, as
  260.10 - * published by the Free Software Foundation.  Oracle designates this
  260.11 - * particular file as subject to the "Classpath" exception as provided
  260.12 - * by Oracle in the LICENSE file that accompanied this code.
  260.13 - *
  260.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  260.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  260.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  260.17 - * version 2 for more details (a copy is included in the LICENSE file that
  260.18 - * accompanied this code).
  260.19 - *
  260.20 - * You should have received a copy of the GNU General Public License version
  260.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  260.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  260.23 - *
  260.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  260.25 - * or visit www.oracle.com if you need additional information or have any
  260.26 - * questions.
  260.27 - */
  260.28 -
  260.29 -package java.lang.reflect;
  260.30 -
  260.31 -/**
  260.32 - * Member is an interface that reflects identifying information about
  260.33 - * a single member (a field or a method) or a constructor.
  260.34 - *
  260.35 - * @see java.lang.Class
  260.36 - * @see Field
  260.37 - * @see Method
  260.38 - * @see Constructor
  260.39 - *
  260.40 - * @author Nakul Saraiya
  260.41 - */
  260.42 -public
  260.43 -interface Member {
  260.44 -
  260.45 -    /**
  260.46 -     * Identifies the set of all public members of a class or interface,
  260.47 -     * including inherited members.
  260.48 -     * @see java.lang.SecurityManager#checkMemberAccess
  260.49 -     */
  260.50 -    public static final int PUBLIC = 0;
  260.51 -
  260.52 -    /**
  260.53 -     * Identifies the set of declared members of a class or interface.
  260.54 -     * Inherited members are not included.
  260.55 -     * @see java.lang.SecurityManager#checkMemberAccess
  260.56 -     */
  260.57 -    public static final int DECLARED = 1;
  260.58 -
  260.59 -    /**
  260.60 -     * Returns the Class object representing the class or interface
  260.61 -     * that declares the member or constructor represented by this Member.
  260.62 -     *
  260.63 -     * @return an object representing the declaring class of the
  260.64 -     * underlying member
  260.65 -     */
  260.66 -    public Class<?> getDeclaringClass();
  260.67 -
  260.68 -    /**
  260.69 -     * Returns the simple name of the underlying member or constructor
  260.70 -     * represented by this Member.
  260.71 -     *
  260.72 -     * @return the simple name of the underlying member
  260.73 -     */
  260.74 -    public String getName();
  260.75 -
  260.76 -    /**
  260.77 -     * Returns the Java language modifiers for the member or
  260.78 -     * constructor represented by this Member, as an integer.  The
  260.79 -     * Modifier class should be used to decode the modifiers in
  260.80 -     * the integer.
  260.81 -     *
  260.82 -     * @return the Java language modifiers for the underlying member
  260.83 -     * @see Modifier
  260.84 -     */
  260.85 -    public int getModifiers();
  260.86 -
  260.87 -    /**
  260.88 -     * Returns {@code true} if this member was introduced by
  260.89 -     * the compiler; returns {@code false} otherwise.
  260.90 -     *
  260.91 -     * @return true if and only if this member was introduced by
  260.92 -     * the compiler.
  260.93 -     * @since 1.5
  260.94 -     */
  260.95 -    public boolean isSynthetic();
  260.96 -}
   261.1 --- a/emul/src/main/java/java/lang/reflect/Method.java	Wed Dec 05 10:03:58 2012 +0100
   261.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   261.3 @@ -1,655 +0,0 @@
   261.4 -/*
   261.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   261.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   261.7 - *
   261.8 - * This code is free software; you can redistribute it and/or modify it
   261.9 - * under the terms of the GNU General Public License version 2 only, as
  261.10 - * published by the Free Software Foundation.  Oracle designates this
  261.11 - * particular file as subject to the "Classpath" exception as provided
  261.12 - * by Oracle in the LICENSE file that accompanied this code.
  261.13 - *
  261.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  261.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  261.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  261.17 - * version 2 for more details (a copy is included in the LICENSE file that
  261.18 - * accompanied this code).
  261.19 - *
  261.20 - * You should have received a copy of the GNU General Public License version
  261.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  261.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  261.23 - *
  261.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  261.25 - * or visit www.oracle.com if you need additional information or have any
  261.26 - * questions.
  261.27 - */
  261.28 -
  261.29 -package java.lang.reflect;
  261.30 -
  261.31 -import java.lang.annotation.Annotation;
  261.32 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  261.33 -import org.apidesign.bck2brwsr.emul.AnnotationImpl;
  261.34 -
  261.35 -/**
  261.36 - * A {@code Method} provides information about, and access to, a single method
  261.37 - * on a class or interface.  The reflected method may be a class method
  261.38 - * or an instance method (including an abstract method).
  261.39 - *
  261.40 - * <p>A {@code Method} permits widening conversions to occur when matching the
  261.41 - * actual parameters to invoke with the underlying method's formal
  261.42 - * parameters, but it throws an {@code IllegalArgumentException} if a
  261.43 - * narrowing conversion would occur.
  261.44 - *
  261.45 - * @see Member
  261.46 - * @see java.lang.Class
  261.47 - * @see java.lang.Class#getMethods()
  261.48 - * @see java.lang.Class#getMethod(String, Class[])
  261.49 - * @see java.lang.Class#getDeclaredMethods()
  261.50 - * @see java.lang.Class#getDeclaredMethod(String, Class[])
  261.51 - *
  261.52 - * @author Kenneth Russell
  261.53 - * @author Nakul Saraiya
  261.54 - */
  261.55 -public final
  261.56 -    class Method extends AccessibleObject implements GenericDeclaration,
  261.57 -                                                     Member {
  261.58 -    private final Class<?> clazz;
  261.59 -    private final String name;
  261.60 -    private final Object data;
  261.61 -    private final String sig;
  261.62 -    private int modifiers;
  261.63 -
  261.64 -   // Generics infrastructure
  261.65 -
  261.66 -    private String getGenericSignature() {return null;}
  261.67 -
  261.68 -    /**
  261.69 -     * Package-private constructor used by ReflectAccess to enable
  261.70 -     * instantiation of these objects in Java code from the java.lang
  261.71 -     * package via sun.reflect.LangReflectAccess.
  261.72 -     */
  261.73 -    Method(Class<?> declaringClass, String name, Object data, String sig)
  261.74 -    {
  261.75 -        this.clazz = declaringClass;
  261.76 -        this.name = name;
  261.77 -        this.data = data;
  261.78 -        this.sig = sig;
  261.79 -    }
  261.80 -
  261.81 -    /**
  261.82 -     * Package-private routine (exposed to java.lang.Class via
  261.83 -     * ReflectAccess) which returns a copy of this Method. The copy's
  261.84 -     * "root" field points to this Method.
  261.85 -     */
  261.86 -    Method copy() {
  261.87 -        return this;
  261.88 -    }
  261.89 -
  261.90 -    /**
  261.91 -     * Returns the {@code Class} object representing the class or interface
  261.92 -     * that declares the method represented by this {@code Method} object.
  261.93 -     */
  261.94 -    public Class<?> getDeclaringClass() {
  261.95 -        return clazz;
  261.96 -    }
  261.97 -
  261.98 -    /**
  261.99 -     * Returns the name of the method represented by this {@code Method}
 261.100 -     * object, as a {@code String}.
 261.101 -     */
 261.102 -    public String getName() {
 261.103 -        return name;
 261.104 -    }
 261.105 -
 261.106 -    /**
 261.107 -     * Returns the Java language modifiers for the method represented
 261.108 -     * by this {@code Method} object, as an integer. The {@code Modifier} class should
 261.109 -     * be used to decode the modifiers.
 261.110 -     *
 261.111 -     * @see Modifier
 261.112 -     */
 261.113 -    public int getModifiers() {
 261.114 -        return modifiers;
 261.115 -    }
 261.116 -
 261.117 -    /**
 261.118 -     * Returns an array of {@code TypeVariable} objects that represent the
 261.119 -     * type variables declared by the generic declaration represented by this
 261.120 -     * {@code GenericDeclaration} object, in declaration order.  Returns an
 261.121 -     * array of length 0 if the underlying generic declaration declares no type
 261.122 -     * variables.
 261.123 -     *
 261.124 -     * @return an array of {@code TypeVariable} objects that represent
 261.125 -     *     the type variables declared by this generic declaration
 261.126 -     * @throws GenericSignatureFormatError if the generic
 261.127 -     *     signature of this generic declaration does not conform to
 261.128 -     *     the format specified in
 261.129 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 261.130 -     * @since 1.5
 261.131 -     */
 261.132 -    public TypeVariable<Method>[] getTypeParameters() {
 261.133 -        throw new UnsupportedOperationException();
 261.134 -    }
 261.135 -
 261.136 -    /**
 261.137 -     * Returns a {@code Class} object that represents the formal return type
 261.138 -     * of the method represented by this {@code Method} object.
 261.139 -     *
 261.140 -     * @return the return type for the method this object represents
 261.141 -     */
 261.142 -    public Class<?> getReturnType() {
 261.143 -        throw new UnsupportedOperationException();
 261.144 -    }
 261.145 -
 261.146 -    /**
 261.147 -     * Returns a {@code Type} object that represents the formal return
 261.148 -     * type of the method represented by this {@code Method} object.
 261.149 -     *
 261.150 -     * <p>If the return type is a parameterized type,
 261.151 -     * the {@code Type} object returned must accurately reflect
 261.152 -     * the actual type parameters used in the source code.
 261.153 -     *
 261.154 -     * <p>If the return type is a type variable or a parameterized type, it
 261.155 -     * is created. Otherwise, it is resolved.
 261.156 -     *
 261.157 -     * @return  a {@code Type} object that represents the formal return
 261.158 -     *     type of the underlying  method
 261.159 -     * @throws GenericSignatureFormatError
 261.160 -     *     if the generic method signature does not conform to the format
 261.161 -     *     specified in
 261.162 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 261.163 -     * @throws TypeNotPresentException if the underlying method's
 261.164 -     *     return type refers to a non-existent type declaration
 261.165 -     * @throws MalformedParameterizedTypeException if the
 261.166 -     *     underlying method's return typed refers to a parameterized
 261.167 -     *     type that cannot be instantiated for any reason
 261.168 -     * @since 1.5
 261.169 -     */
 261.170 -    public Type getGenericReturnType() {
 261.171 -        throw new UnsupportedOperationException();
 261.172 -    }
 261.173 -
 261.174 -
 261.175 -    /**
 261.176 -     * Returns an array of {@code Class} objects that represent the formal
 261.177 -     * parameter types, in declaration order, of the method
 261.178 -     * represented by this {@code Method} object.  Returns an array of length
 261.179 -     * 0 if the underlying method takes no parameters.
 261.180 -     *
 261.181 -     * @return the parameter types for the method this object
 261.182 -     * represents
 261.183 -     */
 261.184 -    public Class<?>[] getParameterTypes() {
 261.185 -        throw new UnsupportedOperationException();
 261.186 -        //return (Class<?>[]) parameterTypes.clone();
 261.187 -    }
 261.188 -
 261.189 -    /**
 261.190 -     * Returns an array of {@code Type} objects that represent the formal
 261.191 -     * parameter types, in declaration order, of the method represented by
 261.192 -     * this {@code Method} object. Returns an array of length 0 if the
 261.193 -     * underlying method takes no parameters.
 261.194 -     *
 261.195 -     * <p>If a formal parameter type is a parameterized type,
 261.196 -     * the {@code Type} object returned for it must accurately reflect
 261.197 -     * the actual type parameters used in the source code.
 261.198 -     *
 261.199 -     * <p>If a formal parameter type is a type variable or a parameterized
 261.200 -     * type, it is created. Otherwise, it is resolved.
 261.201 -     *
 261.202 -     * @return an array of Types that represent the formal
 261.203 -     *     parameter types of the underlying method, in declaration order
 261.204 -     * @throws GenericSignatureFormatError
 261.205 -     *     if the generic method signature does not conform to the format
 261.206 -     *     specified in
 261.207 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 261.208 -     * @throws TypeNotPresentException if any of the parameter
 261.209 -     *     types of the underlying method refers to a non-existent type
 261.210 -     *     declaration
 261.211 -     * @throws MalformedParameterizedTypeException if any of
 261.212 -     *     the underlying method's parameter types refer to a parameterized
 261.213 -     *     type that cannot be instantiated for any reason
 261.214 -     * @since 1.5
 261.215 -     */
 261.216 -    public Type[] getGenericParameterTypes() {
 261.217 -        throw new UnsupportedOperationException();
 261.218 -    }
 261.219 -
 261.220 -
 261.221 -    /**
 261.222 -     * Returns an array of {@code Class} objects that represent
 261.223 -     * the types of the exceptions declared to be thrown
 261.224 -     * by the underlying method
 261.225 -     * represented by this {@code Method} object.  Returns an array of length
 261.226 -     * 0 if the method declares no exceptions in its {@code throws} clause.
 261.227 -     *
 261.228 -     * @return the exception types declared as being thrown by the
 261.229 -     * method this object represents
 261.230 -     */
 261.231 -    public Class<?>[] getExceptionTypes() {
 261.232 -        throw new UnsupportedOperationException();
 261.233 -        //return (Class<?>[]) exceptionTypes.clone();
 261.234 -    }
 261.235 -
 261.236 -    /**
 261.237 -     * Returns an array of {@code Type} objects that represent the
 261.238 -     * exceptions declared to be thrown by this {@code Method} object.
 261.239 -     * Returns an array of length 0 if the underlying method declares
 261.240 -     * no exceptions in its {@code throws} clause.
 261.241 -     *
 261.242 -     * <p>If an exception type is a type variable or a parameterized
 261.243 -     * type, it is created. Otherwise, it is resolved.
 261.244 -     *
 261.245 -     * @return an array of Types that represent the exception types
 261.246 -     *     thrown by the underlying method
 261.247 -     * @throws GenericSignatureFormatError
 261.248 -     *     if the generic method signature does not conform to the format
 261.249 -     *     specified in
 261.250 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 261.251 -     * @throws TypeNotPresentException if the underlying method's
 261.252 -     *     {@code throws} clause refers to a non-existent type declaration
 261.253 -     * @throws MalformedParameterizedTypeException if
 261.254 -     *     the underlying method's {@code throws} clause refers to a
 261.255 -     *     parameterized type that cannot be instantiated for any reason
 261.256 -     * @since 1.5
 261.257 -     */
 261.258 -      public Type[] getGenericExceptionTypes() {
 261.259 -        throw new UnsupportedOperationException();
 261.260 -      }
 261.261 -
 261.262 -    /**
 261.263 -     * Compares this {@code Method} against the specified object.  Returns
 261.264 -     * true if the objects are the same.  Two {@code Methods} are the same if
 261.265 -     * they were declared by the same class and have the same name
 261.266 -     * and formal parameter types and return type.
 261.267 -     */
 261.268 -    public boolean equals(Object obj) {
 261.269 -        if (obj != null && obj instanceof Method) {
 261.270 -            Method other = (Method)obj;
 261.271 -            return data == other.data;
 261.272 -        }
 261.273 -        return false;
 261.274 -    }
 261.275 -
 261.276 -    /**
 261.277 -     * Returns a hashcode for this {@code Method}.  The hashcode is computed
 261.278 -     * as the exclusive-or of the hashcodes for the underlying
 261.279 -     * method's declaring class name and the method's name.
 261.280 -     */
 261.281 -    public int hashCode() {
 261.282 -        return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
 261.283 -    }
 261.284 -
 261.285 -    /**
 261.286 -     * Returns a string describing this {@code Method}.  The string is
 261.287 -     * formatted as the method access modifiers, if any, followed by
 261.288 -     * the method return type, followed by a space, followed by the
 261.289 -     * class declaring the method, followed by a period, followed by
 261.290 -     * the method name, followed by a parenthesized, comma-separated
 261.291 -     * list of the method's formal parameter types. If the method
 261.292 -     * throws checked exceptions, the parameter list is followed by a
 261.293 -     * space, followed by the word throws followed by a
 261.294 -     * comma-separated list of the thrown exception types.
 261.295 -     * For example:
 261.296 -     * <pre>
 261.297 -     *    public boolean java.lang.Object.equals(java.lang.Object)
 261.298 -     * </pre>
 261.299 -     *
 261.300 -     * <p>The access modifiers are placed in canonical order as
 261.301 -     * specified by "The Java Language Specification".  This is
 261.302 -     * {@code public}, {@code protected} or {@code private} first,
 261.303 -     * and then other modifiers in the following order:
 261.304 -     * {@code abstract}, {@code static}, {@code final},
 261.305 -     * {@code synchronized}, {@code native}, {@code strictfp}.
 261.306 -     */
 261.307 -    public String toString() {
 261.308 -        try {
 261.309 -            StringBuilder sb = new StringBuilder();
 261.310 -            int mod = getModifiers() & Modifier.methodModifiers();
 261.311 -            if (mod != 0) {
 261.312 -                sb.append(Modifier.toString(mod)).append(' ');
 261.313 -            }
 261.314 -            sb.append(Field.getTypeName(getReturnType())).append(' ');
 261.315 -            sb.append(Field.getTypeName(getDeclaringClass())).append('.');
 261.316 -            sb.append(getName()).append('(');
 261.317 -            /*
 261.318 -            Class<?>[] params = parameterTypes; // avoid clone
 261.319 -            for (int j = 0; j < params.length; j++) {
 261.320 -                sb.append(Field.getTypeName(params[j]));
 261.321 -                if (j < (params.length - 1))
 261.322 -                    sb.append(',');
 261.323 -            }
 261.324 -            sb.append(')');
 261.325 -            Class<?>[] exceptions = exceptionTypes; // avoid clone
 261.326 -            if (exceptions.length > 0) {
 261.327 -                sb.append(" throws ");
 261.328 -                for (int k = 0; k < exceptions.length; k++) {
 261.329 -                    sb.append(exceptions[k].getName());
 261.330 -                    if (k < (exceptions.length - 1))
 261.331 -                        sb.append(',');
 261.332 -                }
 261.333 -            }
 261.334 -            */
 261.335 -            return sb.toString();
 261.336 -        } catch (Exception e) {
 261.337 -            return "<" + e + ">";
 261.338 -        }
 261.339 -    }
 261.340 -
 261.341 -    /**
 261.342 -     * Returns a string describing this {@code Method}, including
 261.343 -     * type parameters.  The string is formatted as the method access
 261.344 -     * modifiers, if any, followed by an angle-bracketed
 261.345 -     * comma-separated list of the method's type parameters, if any,
 261.346 -     * followed by the method's generic return type, followed by a
 261.347 -     * space, followed by the class declaring the method, followed by
 261.348 -     * a period, followed by the method name, followed by a
 261.349 -     * parenthesized, comma-separated list of the method's generic
 261.350 -     * formal parameter types.
 261.351 -     *
 261.352 -     * If this method was declared to take a variable number of
 261.353 -     * arguments, instead of denoting the last parameter as
 261.354 -     * "<tt><i>Type</i>[]</tt>", it is denoted as
 261.355 -     * "<tt><i>Type</i>...</tt>".
 261.356 -     *
 261.357 -     * A space is used to separate access modifiers from one another
 261.358 -     * and from the type parameters or return type.  If there are no
 261.359 -     * type parameters, the type parameter list is elided; if the type
 261.360 -     * parameter list is present, a space separates the list from the
 261.361 -     * class name.  If the method is declared to throw exceptions, the
 261.362 -     * parameter list is followed by a space, followed by the word
 261.363 -     * throws followed by a comma-separated list of the generic thrown
 261.364 -     * exception types.  If there are no type parameters, the type
 261.365 -     * parameter list is elided.
 261.366 -     *
 261.367 -     * <p>The access modifiers are placed in canonical order as
 261.368 -     * specified by "The Java Language Specification".  This is
 261.369 -     * {@code public}, {@code protected} or {@code private} first,
 261.370 -     * and then other modifiers in the following order:
 261.371 -     * {@code abstract}, {@code static}, {@code final},
 261.372 -     * {@code synchronized}, {@code native}, {@code strictfp}.
 261.373 -     *
 261.374 -     * @return a string describing this {@code Method},
 261.375 -     * include type parameters
 261.376 -     *
 261.377 -     * @since 1.5
 261.378 -     */
 261.379 -    public String toGenericString() {
 261.380 -        try {
 261.381 -            StringBuilder sb = new StringBuilder();
 261.382 -            int mod = getModifiers() & Modifier.methodModifiers();
 261.383 -            if (mod != 0) {
 261.384 -                sb.append(Modifier.toString(mod)).append(' ');
 261.385 -            }
 261.386 -            TypeVariable<?>[] typeparms = getTypeParameters();
 261.387 -            if (typeparms.length > 0) {
 261.388 -                boolean first = true;
 261.389 -                sb.append('<');
 261.390 -                for(TypeVariable<?> typeparm: typeparms) {
 261.391 -                    if (!first)
 261.392 -                        sb.append(',');
 261.393 -                    // Class objects can't occur here; no need to test
 261.394 -                    // and call Class.getName().
 261.395 -                    sb.append(typeparm.toString());
 261.396 -                    first = false;
 261.397 -                }
 261.398 -                sb.append("> ");
 261.399 -            }
 261.400 -
 261.401 -            Type genRetType = getGenericReturnType();
 261.402 -            sb.append( ((genRetType instanceof Class<?>)?
 261.403 -                        Field.getTypeName((Class<?>)genRetType):genRetType.toString()))
 261.404 -                    .append(' ');
 261.405 -
 261.406 -            sb.append(Field.getTypeName(getDeclaringClass())).append('.');
 261.407 -            sb.append(getName()).append('(');
 261.408 -            Type[] params = getGenericParameterTypes();
 261.409 -            for (int j = 0; j < params.length; j++) {
 261.410 -                String param = (params[j] instanceof Class)?
 261.411 -                    Field.getTypeName((Class)params[j]):
 261.412 -                    (params[j].toString());
 261.413 -                if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
 261.414 -                    param = param.replaceFirst("\\[\\]$", "...");
 261.415 -                sb.append(param);
 261.416 -                if (j < (params.length - 1))
 261.417 -                    sb.append(',');
 261.418 -            }
 261.419 -            sb.append(')');
 261.420 -            Type[] exceptions = getGenericExceptionTypes();
 261.421 -            if (exceptions.length > 0) {
 261.422 -                sb.append(" throws ");
 261.423 -                for (int k = 0; k < exceptions.length; k++) {
 261.424 -                    sb.append((exceptions[k] instanceof Class)?
 261.425 -                              ((Class)exceptions[k]).getName():
 261.426 -                              exceptions[k].toString());
 261.427 -                    if (k < (exceptions.length - 1))
 261.428 -                        sb.append(',');
 261.429 -                }
 261.430 -            }
 261.431 -            return sb.toString();
 261.432 -        } catch (Exception e) {
 261.433 -            return "<" + e + ">";
 261.434 -        }
 261.435 -    }
 261.436 -
 261.437 -    /**
 261.438 -     * Invokes the underlying method represented by this {@code Method}
 261.439 -     * object, on the specified object with the specified parameters.
 261.440 -     * Individual parameters are automatically unwrapped to match
 261.441 -     * primitive formal parameters, and both primitive and reference
 261.442 -     * parameters are subject to method invocation conversions as
 261.443 -     * necessary.
 261.444 -     *
 261.445 -     * <p>If the underlying method is static, then the specified {@code obj}
 261.446 -     * argument is ignored. It may be null.
 261.447 -     *
 261.448 -     * <p>If the number of formal parameters required by the underlying method is
 261.449 -     * 0, the supplied {@code args} array may be of length 0 or null.
 261.450 -     *
 261.451 -     * <p>If the underlying method is an instance method, it is invoked
 261.452 -     * using dynamic method lookup as documented in The Java Language
 261.453 -     * Specification, Second Edition, section 15.12.4.4; in particular,
 261.454 -     * overriding based on the runtime type of the target object will occur.
 261.455 -     *
 261.456 -     * <p>If the underlying method is static, the class that declared
 261.457 -     * the method is initialized if it has not already been initialized.
 261.458 -     *
 261.459 -     * <p>If the method completes normally, the value it returns is
 261.460 -     * returned to the caller of invoke; if the value has a primitive
 261.461 -     * type, it is first appropriately wrapped in an object. However,
 261.462 -     * if the value has the type of an array of a primitive type, the
 261.463 -     * elements of the array are <i>not</i> wrapped in objects; in
 261.464 -     * other words, an array of primitive type is returned.  If the
 261.465 -     * underlying method return type is void, the invocation returns
 261.466 -     * null.
 261.467 -     *
 261.468 -     * @param obj  the object the underlying method is invoked from
 261.469 -     * @param args the arguments used for the method call
 261.470 -     * @return the result of dispatching the method represented by
 261.471 -     * this object on {@code obj} with parameters
 261.472 -     * {@code args}
 261.473 -     *
 261.474 -     * @exception IllegalAccessException    if this {@code Method} object
 261.475 -     *              is enforcing Java language access control and the underlying
 261.476 -     *              method is inaccessible.
 261.477 -     * @exception IllegalArgumentException  if the method is an
 261.478 -     *              instance method and the specified object argument
 261.479 -     *              is not an instance of the class or interface
 261.480 -     *              declaring the underlying method (or of a subclass
 261.481 -     *              or implementor thereof); if the number of actual
 261.482 -     *              and formal parameters differ; if an unwrapping
 261.483 -     *              conversion for primitive arguments fails; or if,
 261.484 -     *              after possible unwrapping, a parameter value
 261.485 -     *              cannot be converted to the corresponding formal
 261.486 -     *              parameter type by a method invocation conversion.
 261.487 -     * @exception InvocationTargetException if the underlying method
 261.488 -     *              throws an exception.
 261.489 -     * @exception NullPointerException      if the specified object is null
 261.490 -     *              and the method is an instance method.
 261.491 -     * @exception ExceptionInInitializerError if the initialization
 261.492 -     * provoked by this method fails.
 261.493 -     */
 261.494 -    @JavaScriptBody(args = { "method", "self", "args" }, body =
 261.495 -          "if (args.length > 0) throw 'unsupported now';"
 261.496 -        + "return method.fld_data(self);"
 261.497 -    )
 261.498 -    public Object invoke(Object obj, Object... args)
 261.499 -        throws IllegalAccessException, IllegalArgumentException,
 261.500 -           InvocationTargetException
 261.501 -    {
 261.502 -        throw new UnsupportedOperationException();
 261.503 -    }
 261.504 -
 261.505 -    /**
 261.506 -     * Returns {@code true} if this method is a bridge
 261.507 -     * method; returns {@code false} otherwise.
 261.508 -     *
 261.509 -     * @return true if and only if this method is a bridge
 261.510 -     * method as defined by the Java Language Specification.
 261.511 -     * @since 1.5
 261.512 -     */
 261.513 -    public boolean isBridge() {
 261.514 -        return (getModifiers() & Modifier.BRIDGE) != 0;
 261.515 -    }
 261.516 -
 261.517 -    /**
 261.518 -     * Returns {@code true} if this method was declared to take
 261.519 -     * a variable number of arguments; returns {@code false}
 261.520 -     * otherwise.
 261.521 -     *
 261.522 -     * @return {@code true} if an only if this method was declared to
 261.523 -     * take a variable number of arguments.
 261.524 -     * @since 1.5
 261.525 -     */
 261.526 -    public boolean isVarArgs() {
 261.527 -        return (getModifiers() & Modifier.VARARGS) != 0;
 261.528 -    }
 261.529 -
 261.530 -    /**
 261.531 -     * Returns {@code true} if this method is a synthetic
 261.532 -     * method; returns {@code false} otherwise.
 261.533 -     *
 261.534 -     * @return true if and only if this method is a synthetic
 261.535 -     * method as defined by the Java Language Specification.
 261.536 -     * @since 1.5
 261.537 -     */
 261.538 -    public boolean isSynthetic() {
 261.539 -        return Modifier.isSynthetic(getModifiers());
 261.540 -    }
 261.541 -
 261.542 -    @JavaScriptBody(args = { "self", "ac" }, 
 261.543 -        body = 
 261.544 -          "if (self.fld_data.anno) {"
 261.545 -        + "  return self.fld_data.anno['L' + ac.jvmName + ';'];"
 261.546 -        + "} else return null;"
 261.547 -    )
 261.548 -    private Object getAnnotationData(Class<?> annotationClass) {
 261.549 -        throw new UnsupportedOperationException();
 261.550 -    }
 261.551 -    
 261.552 -    /**
 261.553 -     * @throws NullPointerException {@inheritDoc}
 261.554 -     * @since 1.5
 261.555 -     */
 261.556 -    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 261.557 -        Object data = getAnnotationData(annotationClass);
 261.558 -        return data == null ? null : AnnotationImpl.create(annotationClass, data);
 261.559 -    }
 261.560 -
 261.561 -    /**
 261.562 -     * @since 1.5
 261.563 -     */
 261.564 -    public Annotation[] getDeclaredAnnotations()  {
 261.565 -        throw new UnsupportedOperationException();
 261.566 -    }
 261.567 -
 261.568 -    /**
 261.569 -     * Returns the default value for the annotation member represented by
 261.570 -     * this {@code Method} instance.  If the member is of a primitive type,
 261.571 -     * an instance of the corresponding wrapper type is returned. Returns
 261.572 -     * null if no default is associated with the member, or if the method
 261.573 -     * instance does not represent a declared member of an annotation type.
 261.574 -     *
 261.575 -     * @return the default value for the annotation member represented
 261.576 -     *     by this {@code Method} instance.
 261.577 -     * @throws TypeNotPresentException if the annotation is of type
 261.578 -     *     {@link Class} and no definition can be found for the
 261.579 -     *     default class value.
 261.580 -     * @since  1.5
 261.581 -     */
 261.582 -    public Object getDefaultValue() {
 261.583 -        throw new UnsupportedOperationException();
 261.584 -    }
 261.585 -
 261.586 -    /**
 261.587 -     * Returns an array of arrays that represent the annotations on the formal
 261.588 -     * parameters, in declaration order, of the method represented by
 261.589 -     * this {@code Method} object. (Returns an array of length zero if the
 261.590 -     * underlying method is parameterless.  If the method has one or more
 261.591 -     * parameters, a nested array of length zero is returned for each parameter
 261.592 -     * with no annotations.) The annotation objects contained in the returned
 261.593 -     * arrays are serializable.  The caller of this method is free to modify
 261.594 -     * the returned arrays; it will have no effect on the arrays returned to
 261.595 -     * other callers.
 261.596 -     *
 261.597 -     * @return an array of arrays that represent the annotations on the formal
 261.598 -     *    parameters, in declaration order, of the method represented by this
 261.599 -     *    Method object
 261.600 -     * @since 1.5
 261.601 -     */
 261.602 -    public Annotation[][] getParameterAnnotations() {
 261.603 -        throw new UnsupportedOperationException();
 261.604 -    }
 261.605 -    
 261.606 -    //
 261.607 -    // bck2brwsr implementation
 261.608 -    //
 261.609 -
 261.610 -    @JavaScriptBody(args = { "clazz", "prefix" },
 261.611 -        body = ""
 261.612 -        + "var c = clazz.cnstr.prototype;"
 261.613 -        + "var arr = new Array();\n"
 261.614 -        + "for (m in c) {\n"
 261.615 -        + "  if (m.indexOf(prefix) === 0) {\n"
 261.616 -        + "     arr.push(m);\n"
 261.617 -        + "     arr.push(c[m]);\n"
 261.618 -        + "  }"
 261.619 -        + "}\n"
 261.620 -        + "return arr;"
 261.621 -    )
 261.622 -    private static native Object[] findMethodData(
 261.623 -        Class<?> clazz, String prefix
 261.624 -    );
 261.625 -
 261.626 -    // XXX should not be public
 261.627 -    public static Method findMethod(
 261.628 -        Class<?> clazz, String name, Class<?>... parameterTypes
 261.629 -    ) {
 261.630 -        Object[] data = findMethodData(clazz, name + "__");
 261.631 -        if (data.length == 0) {
 261.632 -            return null;
 261.633 -        }
 261.634 -        String sig = ((String)data[0]).substring(name.length() + 2);
 261.635 -        return new Method(clazz, name, data[1], sig);
 261.636 -    }
 261.637 -    
 261.638 -    public static Method[] findMethods(Class<?> clazz) {
 261.639 -        Object[] namesAndData = findMethodData(clazz, "");
 261.640 -        int cnt = 0;
 261.641 -        for (int i = 0; i < namesAndData.length; i += 2) {
 261.642 -            String sig = (String) namesAndData[i];
 261.643 -            Object data = namesAndData[i + 1];
 261.644 -            int middle = sig.indexOf("__");
 261.645 -            if (middle == -1) {
 261.646 -                continue;
 261.647 -            }
 261.648 -            String name = sig.substring(0, middle);
 261.649 -            sig = sig.substring(middle + 2);
 261.650 -            namesAndData[cnt++] = new Method(clazz, name, data, sig);
 261.651 -        }
 261.652 -        Method[] arr = new Method[cnt];
 261.653 -        for (int i = 0; i < cnt; i++) {
 261.654 -            arr[i] = (Method)namesAndData[i];
 261.655 -        }
 261.656 -        return arr;
 261.657 -    }
 261.658 -}
   262.1 --- a/emul/src/main/java/java/lang/reflect/Modifier.java	Wed Dec 05 10:03:58 2012 +0100
   262.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   262.3 @@ -1,437 +0,0 @@
   262.4 -/*
   262.5 - * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
   262.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   262.7 - *
   262.8 - * This code is free software; you can redistribute it and/or modify it
   262.9 - * under the terms of the GNU General Public License version 2 only, as
  262.10 - * published by the Free Software Foundation.  Oracle designates this
  262.11 - * particular file as subject to the "Classpath" exception as provided
  262.12 - * by Oracle in the LICENSE file that accompanied this code.
  262.13 - *
  262.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  262.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  262.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  262.17 - * version 2 for more details (a copy is included in the LICENSE file that
  262.18 - * accompanied this code).
  262.19 - *
  262.20 - * You should have received a copy of the GNU General Public License version
  262.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  262.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  262.23 - *
  262.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  262.25 - * or visit www.oracle.com if you need additional information or have any
  262.26 - * questions.
  262.27 - */
  262.28 -
  262.29 -package java.lang.reflect;
  262.30 -
  262.31 -/**
  262.32 - * The Modifier class provides {@code static} methods and
  262.33 - * constants to decode class and member access modifiers.  The sets of
  262.34 - * modifiers are represented as integers with distinct bit positions
  262.35 - * representing different modifiers.  The values for the constants
  262.36 - * representing the modifiers are taken from the tables in sections 4.1, 4.4, 4.5, and 4.7 of
  262.37 - * <cite>The Java&trade; Virtual Machine Specification</cite>.
  262.38 - *
  262.39 - * @see Class#getModifiers()
  262.40 - * @see Member#getModifiers()
  262.41 - *
  262.42 - * @author Nakul Saraiya
  262.43 - * @author Kenneth Russell
  262.44 - */
  262.45 -public
  262.46 -class Modifier {
  262.47 -
  262.48 -    /**
  262.49 -     * Return {@code true} if the integer argument includes the
  262.50 -     * {@code public} modifier, {@code false} otherwise.
  262.51 -     *
  262.52 -     * @param   mod a set of modifiers
  262.53 -     * @return {@code true} if {@code mod} includes the
  262.54 -     * {@code public} modifier; {@code false} otherwise.
  262.55 -     */
  262.56 -    public static boolean isPublic(int mod) {
  262.57 -        return (mod & PUBLIC) != 0;
  262.58 -    }
  262.59 -
  262.60 -    /**
  262.61 -     * Return {@code true} if the integer argument includes the
  262.62 -     * {@code private} modifier, {@code false} otherwise.
  262.63 -     *
  262.64 -     * @param   mod a set of modifiers
  262.65 -     * @return {@code true} if {@code mod} includes the
  262.66 -     * {@code private} modifier; {@code false} otherwise.
  262.67 -     */
  262.68 -    public static boolean isPrivate(int mod) {
  262.69 -        return (mod & PRIVATE) != 0;
  262.70 -    }
  262.71 -
  262.72 -    /**
  262.73 -     * Return {@code true} if the integer argument includes the
  262.74 -     * {@code protected} modifier, {@code false} otherwise.
  262.75 -     *
  262.76 -     * @param   mod a set of modifiers
  262.77 -     * @return {@code true} if {@code mod} includes the
  262.78 -     * {@code protected} modifier; {@code false} otherwise.
  262.79 -     */
  262.80 -    public static boolean isProtected(int mod) {
  262.81 -        return (mod & PROTECTED) != 0;
  262.82 -    }
  262.83 -
  262.84 -    /**
  262.85 -     * Return {@code true} if the integer argument includes the
  262.86 -     * {@code static} modifier, {@code false} otherwise.
  262.87 -     *
  262.88 -     * @param   mod a set of modifiers
  262.89 -     * @return {@code true} if {@code mod} includes the
  262.90 -     * {@code static} modifier; {@code false} otherwise.
  262.91 -     */
  262.92 -    public static boolean isStatic(int mod) {
  262.93 -        return (mod & STATIC) != 0;
  262.94 -    }
  262.95 -
  262.96 -    /**
  262.97 -     * Return {@code true} if the integer argument includes the
  262.98 -     * {@code final} modifier, {@code false} otherwise.
  262.99 -     *
 262.100 -     * @param   mod a set of modifiers
 262.101 -     * @return {@code true} if {@code mod} includes the
 262.102 -     * {@code final} modifier; {@code false} otherwise.
 262.103 -     */
 262.104 -    public static boolean isFinal(int mod) {
 262.105 -        return (mod & FINAL) != 0;
 262.106 -    }
 262.107 -
 262.108 -    /**
 262.109 -     * Return {@code true} if the integer argument includes the
 262.110 -     * {@code synchronized} modifier, {@code false} otherwise.
 262.111 -     *
 262.112 -     * @param   mod a set of modifiers
 262.113 -     * @return {@code true} if {@code mod} includes the
 262.114 -     * {@code synchronized} modifier; {@code false} otherwise.
 262.115 -     */
 262.116 -    public static boolean isSynchronized(int mod) {
 262.117 -        return (mod & SYNCHRONIZED) != 0;
 262.118 -    }
 262.119 -
 262.120 -    /**
 262.121 -     * Return {@code true} if the integer argument includes the
 262.122 -     * {@code volatile} modifier, {@code false} otherwise.
 262.123 -     *
 262.124 -     * @param   mod a set of modifiers
 262.125 -     * @return {@code true} if {@code mod} includes the
 262.126 -     * {@code volatile} modifier; {@code false} otherwise.
 262.127 -     */
 262.128 -    public static boolean isVolatile(int mod) {
 262.129 -        return (mod & VOLATILE) != 0;
 262.130 -    }
 262.131 -
 262.132 -    /**
 262.133 -     * Return {@code true} if the integer argument includes the
 262.134 -     * {@code transient} modifier, {@code false} otherwise.
 262.135 -     *
 262.136 -     * @param   mod a set of modifiers
 262.137 -     * @return {@code true} if {@code mod} includes the
 262.138 -     * {@code transient} modifier; {@code false} otherwise.
 262.139 -     */
 262.140 -    public static boolean isTransient(int mod) {
 262.141 -        return (mod & TRANSIENT) != 0;
 262.142 -    }
 262.143 -
 262.144 -    /**
 262.145 -     * Return {@code true} if the integer argument includes the
 262.146 -     * {@code native} modifier, {@code false} otherwise.
 262.147 -     *
 262.148 -     * @param   mod a set of modifiers
 262.149 -     * @return {@code true} if {@code mod} includes the
 262.150 -     * {@code native} modifier; {@code false} otherwise.
 262.151 -     */
 262.152 -    public static boolean isNative(int mod) {
 262.153 -        return (mod & NATIVE) != 0;
 262.154 -    }
 262.155 -
 262.156 -    /**
 262.157 -     * Return {@code true} if the integer argument includes the
 262.158 -     * {@code interface} modifier, {@code false} otherwise.
 262.159 -     *
 262.160 -     * @param   mod a set of modifiers
 262.161 -     * @return {@code true} if {@code mod} includes the
 262.162 -     * {@code interface} modifier; {@code false} otherwise.
 262.163 -     */
 262.164 -    public static boolean isInterface(int mod) {
 262.165 -        return (mod & INTERFACE) != 0;
 262.166 -    }
 262.167 -
 262.168 -    /**
 262.169 -     * Return {@code true} if the integer argument includes the
 262.170 -     * {@code abstract} modifier, {@code false} otherwise.
 262.171 -     *
 262.172 -     * @param   mod a set of modifiers
 262.173 -     * @return {@code true} if {@code mod} includes the
 262.174 -     * {@code abstract} modifier; {@code false} otherwise.
 262.175 -     */
 262.176 -    public static boolean isAbstract(int mod) {
 262.177 -        return (mod & ABSTRACT) != 0;
 262.178 -    }
 262.179 -
 262.180 -    /**
 262.181 -     * Return {@code true} if the integer argument includes the
 262.182 -     * {@code strictfp} modifier, {@code false} otherwise.
 262.183 -     *
 262.184 -     * @param   mod a set of modifiers
 262.185 -     * @return {@code true} if {@code mod} includes the
 262.186 -     * {@code strictfp} modifier; {@code false} otherwise.
 262.187 -     */
 262.188 -    public static boolean isStrict(int mod) {
 262.189 -        return (mod & STRICT) != 0;
 262.190 -    }
 262.191 -
 262.192 -    /**
 262.193 -     * Return a string describing the access modifier flags in
 262.194 -     * the specified modifier. For example:
 262.195 -     * <blockquote><pre>
 262.196 -     *    public final synchronized strictfp
 262.197 -     * </pre></blockquote>
 262.198 -     * The modifier names are returned in an order consistent with the
 262.199 -     * suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of
 262.200 -     * <cite>The Java&trade; Language Specification</cite>.
 262.201 -     * The full modifier ordering used by this method is:
 262.202 -     * <blockquote> {@code
 262.203 -     * public protected private abstract static final transient
 262.204 -     * volatile synchronized native strictfp
 262.205 -     * interface } </blockquote>
 262.206 -     * The {@code interface} modifier discussed in this class is
 262.207 -     * not a true modifier in the Java language and it appears after
 262.208 -     * all other modifiers listed by this method.  This method may
 262.209 -     * return a string of modifiers that are not valid modifiers of a
 262.210 -     * Java entity; in other words, no checking is done on the
 262.211 -     * possible validity of the combination of modifiers represented
 262.212 -     * by the input.
 262.213 -     *
 262.214 -     * Note that to perform such checking for a known kind of entity,
 262.215 -     * such as a constructor or method, first AND the argument of
 262.216 -     * {@code toString} with the appropriate mask from a method like
 262.217 -     * {@link #constructorModifiers} or {@link #methodModifiers}.
 262.218 -     *
 262.219 -     * @param   mod a set of modifiers
 262.220 -     * @return  a string representation of the set of modifiers
 262.221 -     * represented by {@code mod}
 262.222 -     */
 262.223 -    public static String toString(int mod) {
 262.224 -        StringBuffer sb = new StringBuffer();
 262.225 -        int len;
 262.226 -
 262.227 -        if ((mod & PUBLIC) != 0)        sb.append("public ");
 262.228 -        if ((mod & PROTECTED) != 0)     sb.append("protected ");
 262.229 -        if ((mod & PRIVATE) != 0)       sb.append("private ");
 262.230 -
 262.231 -        /* Canonical order */
 262.232 -        if ((mod & ABSTRACT) != 0)      sb.append("abstract ");
 262.233 -        if ((mod & STATIC) != 0)        sb.append("static ");
 262.234 -        if ((mod & FINAL) != 0)         sb.append("final ");
 262.235 -        if ((mod & TRANSIENT) != 0)     sb.append("transient ");
 262.236 -        if ((mod & VOLATILE) != 0)      sb.append("volatile ");
 262.237 -        if ((mod & SYNCHRONIZED) != 0)  sb.append("synchronized ");
 262.238 -        if ((mod & NATIVE) != 0)        sb.append("native ");
 262.239 -        if ((mod & STRICT) != 0)        sb.append("strictfp ");
 262.240 -        if ((mod & INTERFACE) != 0)     sb.append("interface ");
 262.241 -
 262.242 -        if ((len = sb.length()) > 0)    /* trim trailing space */
 262.243 -            return sb.toString().substring(0, len-1);
 262.244 -        return "";
 262.245 -    }
 262.246 -
 262.247 -    /*
 262.248 -     * Access modifier flag constants from tables 4.1, 4.4, 4.5, and 4.7 of
 262.249 -     * <cite>The Java&trade; Virtual Machine Specification</cite>
 262.250 -     */
 262.251 -
 262.252 -    /**
 262.253 -     * The {@code int} value representing the {@code public}
 262.254 -     * modifier.
 262.255 -     */
 262.256 -    public static final int PUBLIC           = 0x00000001;
 262.257 -
 262.258 -    /**
 262.259 -     * The {@code int} value representing the {@code private}
 262.260 -     * modifier.
 262.261 -     */
 262.262 -    public static final int PRIVATE          = 0x00000002;
 262.263 -
 262.264 -    /**
 262.265 -     * The {@code int} value representing the {@code protected}
 262.266 -     * modifier.
 262.267 -     */
 262.268 -    public static final int PROTECTED        = 0x00000004;
 262.269 -
 262.270 -    /**
 262.271 -     * The {@code int} value representing the {@code static}
 262.272 -     * modifier.
 262.273 -     */
 262.274 -    public static final int STATIC           = 0x00000008;
 262.275 -
 262.276 -    /**
 262.277 -     * The {@code int} value representing the {@code final}
 262.278 -     * modifier.
 262.279 -     */
 262.280 -    public static final int FINAL            = 0x00000010;
 262.281 -
 262.282 -    /**
 262.283 -     * The {@code int} value representing the {@code synchronized}
 262.284 -     * modifier.
 262.285 -     */
 262.286 -    public static final int SYNCHRONIZED     = 0x00000020;
 262.287 -
 262.288 -    /**
 262.289 -     * The {@code int} value representing the {@code volatile}
 262.290 -     * modifier.
 262.291 -     */
 262.292 -    public static final int VOLATILE         = 0x00000040;
 262.293 -
 262.294 -    /**
 262.295 -     * The {@code int} value representing the {@code transient}
 262.296 -     * modifier.
 262.297 -     */
 262.298 -    public static final int TRANSIENT        = 0x00000080;
 262.299 -
 262.300 -    /**
 262.301 -     * The {@code int} value representing the {@code native}
 262.302 -     * modifier.
 262.303 -     */
 262.304 -    public static final int NATIVE           = 0x00000100;
 262.305 -
 262.306 -    /**
 262.307 -     * The {@code int} value representing the {@code interface}
 262.308 -     * modifier.
 262.309 -     */
 262.310 -    public static final int INTERFACE        = 0x00000200;
 262.311 -
 262.312 -    /**
 262.313 -     * The {@code int} value representing the {@code abstract}
 262.314 -     * modifier.
 262.315 -     */
 262.316 -    public static final int ABSTRACT         = 0x00000400;
 262.317 -
 262.318 -    /**
 262.319 -     * The {@code int} value representing the {@code strictfp}
 262.320 -     * modifier.
 262.321 -     */
 262.322 -    public static final int STRICT           = 0x00000800;
 262.323 -
 262.324 -    // Bits not (yet) exposed in the public API either because they
 262.325 -    // have different meanings for fields and methods and there is no
 262.326 -    // way to distinguish between the two in this class, or because
 262.327 -    // they are not Java programming language keywords
 262.328 -    static final int BRIDGE    = 0x00000040;
 262.329 -    static final int VARARGS   = 0x00000080;
 262.330 -    static final int SYNTHETIC = 0x00001000;
 262.331 -    static final int ANNOTATION= 0x00002000;
 262.332 -    static final int ENUM      = 0x00004000;
 262.333 -    static boolean isSynthetic(int mod) {
 262.334 -      return (mod & SYNTHETIC) != 0;
 262.335 -    }
 262.336 -
 262.337 -    /**
 262.338 -     * See JLSv3 section 8.1.1.
 262.339 -     */
 262.340 -    private static final int CLASS_MODIFIERS =
 262.341 -        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 262.342 -        Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.FINAL   |
 262.343 -        Modifier.STRICT;
 262.344 -
 262.345 -    /**
 262.346 -     * See JLSv3 section 9.1.1.
 262.347 -     */
 262.348 -    private static final int INTERFACE_MODIFIERS =
 262.349 -        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 262.350 -        Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.STRICT;
 262.351 -
 262.352 -
 262.353 -    /**
 262.354 -     * See JLSv3 section 8.8.3.
 262.355 -     */
 262.356 -    private static final int CONSTRUCTOR_MODIFIERS =
 262.357 -        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE;
 262.358 -
 262.359 -    /**
 262.360 -     * See JLSv3 section 8.4.3.
 262.361 -     */
 262.362 -    private static final int METHOD_MODIFIERS =
 262.363 -        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 262.364 -        Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.FINAL   |
 262.365 -        Modifier.SYNCHRONIZED   | Modifier.NATIVE       | Modifier.STRICT;
 262.366 -
 262.367 -    /**
 262.368 -     * See JLSv3 section 8.3.1.
 262.369 -     */
 262.370 -    private static final int FIELD_MODIFIERS =
 262.371 -        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 262.372 -        Modifier.STATIC         | Modifier.FINAL        | Modifier.TRANSIENT |
 262.373 -        Modifier.VOLATILE;
 262.374 -
 262.375 -    /**
 262.376 -     * Return an {@code int} value OR-ing together the source language
 262.377 -     * modifiers that can be applied to a class.
 262.378 -     * @return an {@code int} value OR-ing together the source language
 262.379 -     * modifiers that can be applied to a class.
 262.380 -     *
 262.381 -     * @jls 8.1.1 Class Modifiers
 262.382 -     * @since 1.7
 262.383 -     */
 262.384 -    public static int classModifiers() {
 262.385 -        return CLASS_MODIFIERS;
 262.386 -    }
 262.387 -
 262.388 -    /**
 262.389 -     * Return an {@code int} value OR-ing together the source language
 262.390 -     * modifiers that can be applied to an interface.
 262.391 -     * @return an {@code int} value OR-ing together the source language
 262.392 -     * modifiers that can be applied to an inteface.
 262.393 -     *
 262.394 -     * @jls 9.1.1 Interface Modifiers
 262.395 -     * @since 1.7
 262.396 -     */
 262.397 -    public static int interfaceModifiers() {
 262.398 -        return INTERFACE_MODIFIERS;
 262.399 -    }
 262.400 -
 262.401 -    /**
 262.402 -     * Return an {@code int} value OR-ing together the source language
 262.403 -     * modifiers that can be applied to a constructor.
 262.404 -     * @return an {@code int} value OR-ing together the source language
 262.405 -     * modifiers that can be applied to a constructor.
 262.406 -     *
 262.407 -     * @jls 8.8.3 Constructor Modifiers
 262.408 -     * @since 1.7
 262.409 -     */
 262.410 -    public static int constructorModifiers() {
 262.411 -        return CONSTRUCTOR_MODIFIERS;
 262.412 -    }
 262.413 -
 262.414 -    /**
 262.415 -     * Return an {@code int} value OR-ing together the source language
 262.416 -     * modifiers that can be applied to a method.
 262.417 -     * @return an {@code int} value OR-ing together the source language
 262.418 -     * modifiers that can be applied to a method.
 262.419 -     *
 262.420 -     * @jls 8.4.3 Method Modifiers
 262.421 -     * @since 1.7
 262.422 -     */
 262.423 -    public static int methodModifiers() {
 262.424 -        return METHOD_MODIFIERS;
 262.425 -    }
 262.426 -
 262.427 -
 262.428 -    /**
 262.429 -     * Return an {@code int} value OR-ing together the source language
 262.430 -     * modifiers that can be applied to a field.
 262.431 -     * @return an {@code int} value OR-ing together the source language
 262.432 -     * modifiers that can be applied to a field.
 262.433 -     *
 262.434 -     * @jls 8.3.1 Field Modifiers
 262.435 -     * @since 1.7
 262.436 -     */
 262.437 -    public static int fieldModifiers() {
 262.438 -        return FIELD_MODIFIERS;
 262.439 -    }
 262.440 -}
   263.1 --- a/emul/src/main/java/java/lang/reflect/Type.java	Wed Dec 05 10:03:58 2012 +0100
   263.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   263.3 @@ -1,37 +0,0 @@
   263.4 -/*
   263.5 - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
   263.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   263.7 - *
   263.8 - * This code is free software; you can redistribute it and/or modify it
   263.9 - * under the terms of the GNU General Public License version 2 only, as
  263.10 - * published by the Free Software Foundation.  Oracle designates this
  263.11 - * particular file as subject to the "Classpath" exception as provided
  263.12 - * by Oracle in the LICENSE file that accompanied this code.
  263.13 - *
  263.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  263.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  263.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  263.17 - * version 2 for more details (a copy is included in the LICENSE file that
  263.18 - * accompanied this code).
  263.19 - *
  263.20 - * You should have received a copy of the GNU General Public License version
  263.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  263.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  263.23 - *
  263.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  263.25 - * or visit www.oracle.com if you need additional information or have any
  263.26 - * questions.
  263.27 - */
  263.28 -
  263.29 -package java.lang.reflect;
  263.30 -
  263.31 -/**
  263.32 - * Type is the common superinterface for all types in the Java
  263.33 - * programming language. These include raw types, parameterized types,
  263.34 - * array types, type variables and primitive types.
  263.35 - *
  263.36 - * @since 1.5
  263.37 - */
  263.38 -
  263.39 -public interface Type {
  263.40 -}
   264.1 --- a/emul/src/main/java/java/lang/reflect/TypeVariable.java	Wed Dec 05 10:03:58 2012 +0100
   264.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   264.3 @@ -1,89 +0,0 @@
   264.4 -/*
   264.5 - * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
   264.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   264.7 - *
   264.8 - * This code is free software; you can redistribute it and/or modify it
   264.9 - * under the terms of the GNU General Public License version 2 only, as
  264.10 - * published by the Free Software Foundation.  Oracle designates this
  264.11 - * particular file as subject to the "Classpath" exception as provided
  264.12 - * by Oracle in the LICENSE file that accompanied this code.
  264.13 - *
  264.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  264.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  264.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  264.17 - * version 2 for more details (a copy is included in the LICENSE file that
  264.18 - * accompanied this code).
  264.19 - *
  264.20 - * You should have received a copy of the GNU General Public License version
  264.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  264.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  264.23 - *
  264.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  264.25 - * or visit www.oracle.com if you need additional information or have any
  264.26 - * questions.
  264.27 - */
  264.28 -
  264.29 -package java.lang.reflect;
  264.30 -
  264.31 -/**
  264.32 - * TypeVariable is the common superinterface for type variables of kinds.
  264.33 - * A type variable is created the first time it is needed by a reflective
  264.34 - * method, as specified in this package.  If a type variable t is referenced
  264.35 - * by a type (i.e, class, interface or annotation type) T, and T is declared
  264.36 - * by the nth enclosing class of T (see JLS 8.1.2), then the creation of t
  264.37 - * requires the resolution (see JVMS 5) of the ith enclosing class of T,
  264.38 - * for i = 0 to n, inclusive. Creating a type variable must not cause the
  264.39 - * creation of its bounds. Repeated creation of a type variable has no effect.
  264.40 - *
  264.41 - * <p>Multiple objects may be instantiated at run-time to
  264.42 - * represent a given type variable. Even though a type variable is
  264.43 - * created only once, this does not imply any requirement to cache
  264.44 - * instances representing the type variable. However, all instances
  264.45 - * representing a type variable must be equal() to each other.
  264.46 - * As a consequence, users of type variables must not rely on the identity
  264.47 - * of instances of classes implementing this interface.
  264.48 - *
  264.49 - * @param <D> the type of generic declaration that declared the
  264.50 - * underlying type variable.
  264.51 - *
  264.52 - * @since 1.5
  264.53 - */
  264.54 -public interface TypeVariable<D extends GenericDeclaration> extends Type {
  264.55 -    /**
  264.56 -     * Returns an array of {@code Type} objects representing the
  264.57 -     * upper bound(s) of this type variable.  Note that if no upper bound is
  264.58 -     * explicitly declared, the upper bound is {@code Object}.
  264.59 -     *
  264.60 -     * <p>For each upper bound B: <ul> <li>if B is a parameterized
  264.61 -     * type or a type variable, it is created, (see {@link
  264.62 -     * java.lang.reflect.ParameterizedType ParameterizedType} for the
  264.63 -     * details of the creation process for parameterized types).
  264.64 -     * <li>Otherwise, B is resolved.  </ul>
  264.65 -     *
  264.66 -     * @throws TypeNotPresentException  if any of the
  264.67 -     *     bounds refers to a non-existent type declaration
  264.68 -     * @throws MalformedParameterizedTypeException if any of the
  264.69 -     *     bounds refer to a parameterized type that cannot be instantiated
  264.70 -     *     for any reason
  264.71 -     * @return an array of {@code Type}s representing the upper
  264.72 -     *     bound(s) of this type variable
  264.73 -    */
  264.74 -    Type[] getBounds();
  264.75 -
  264.76 -    /**
  264.77 -     * Returns the {@code GenericDeclaration} object representing the
  264.78 -     * generic declaration declared this type variable.
  264.79 -     *
  264.80 -     * @return the generic declaration declared for this type variable.
  264.81 -     *
  264.82 -     * @since 1.5
  264.83 -     */
  264.84 -    D getGenericDeclaration();
  264.85 -
  264.86 -    /**
  264.87 -     * Returns the name of this type variable, as it occurs in the source code.
  264.88 -     *
  264.89 -     * @return the name of this type variable, as it appears in the source code
  264.90 -     */
  264.91 -    String getName();
  264.92 -}
   265.1 --- a/emul/src/main/java/java/lang/reflect/package-info.java	Wed Dec 05 10:03:58 2012 +0100
   265.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   265.3 @@ -1,49 +0,0 @@
   265.4 -/*
   265.5 - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
   265.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   265.7 - *
   265.8 - * This code is free software; you can redistribute it and/or modify it
   265.9 - * under the terms of the GNU General Public License version 2 only, as
  265.10 - * published by the Free Software Foundation.  Oracle designates this
  265.11 - * particular file as subject to the "Classpath" exception as provided
  265.12 - * by Oracle in the LICENSE file that accompanied this code.
  265.13 - *
  265.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  265.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  265.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  265.17 - * version 2 for more details (a copy is included in the LICENSE file that
  265.18 - * accompanied this code).
  265.19 - *
  265.20 - * You should have received a copy of the GNU General Public License version
  265.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  265.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  265.23 - *
  265.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  265.25 - * or visit www.oracle.com if you need additional information or have any
  265.26 - * questions.
  265.27 - */
  265.28 -
  265.29 -/**
  265.30 - * Provides classes and interfaces for obtaining reflective
  265.31 - * information about classes and objects.  Reflection allows
  265.32 - * programmatic access to information about the fields, methods and
  265.33 - * constructors of loaded classes, and the use of reflected fields,
  265.34 - * methods, and constructors to operate on their underlying
  265.35 - * counterparts, within security restrictions.
  265.36 - *
  265.37 - * <p>{@code AccessibleObject} allows suppression of access checks if
  265.38 - * the necessary {@code ReflectPermission} is available.
  265.39 - *
  265.40 - * <p>{@code Array} provides static methods to dynamically create and
  265.41 - * access arrays.
  265.42 - *
  265.43 - * <p>Classes in this package, along with {@code java.lang.Class}
  265.44 - * accommodate applications such as debuggers, interpreters, object
  265.45 - * inspectors, class browsers, and services such as Object
  265.46 - * Serialization and JavaBeans that need access to either the public
  265.47 - * members of a target object (based on its runtime class) or the
  265.48 - * members declared by a given class.
  265.49 - *
  265.50 - * @since JDK1.1
  265.51 - */
  265.52 -package java.lang.reflect;
   266.1 --- a/emul/src/main/java/java/net/MalformedURLException.java	Wed Dec 05 10:03:58 2012 +0100
   266.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   266.3 @@ -1,56 +0,0 @@
   266.4 -/*
   266.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   266.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   266.7 - *
   266.8 - * This code is free software; you can redistribute it and/or modify it
   266.9 - * under the terms of the GNU General Public License version 2 only, as
  266.10 - * published by the Free Software Foundation.  Oracle designates this
  266.11 - * particular file as subject to the "Classpath" exception as provided
  266.12 - * by Oracle in the LICENSE file that accompanied this code.
  266.13 - *
  266.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  266.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  266.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  266.17 - * version 2 for more details (a copy is included in the LICENSE file that
  266.18 - * accompanied this code).
  266.19 - *
  266.20 - * You should have received a copy of the GNU General Public License version
  266.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  266.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  266.23 - *
  266.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  266.25 - * or visit www.oracle.com if you need additional information or have any
  266.26 - * questions.
  266.27 - */
  266.28 -
  266.29 -package java.net;
  266.30 -
  266.31 -import java.io.IOException;
  266.32 -
  266.33 -/**
  266.34 - * Thrown to indicate that a malformed URL has occurred. Either no
  266.35 - * legal protocol could be found in a specification string or the
  266.36 - * string could not be parsed.
  266.37 - *
  266.38 - * @author  Arthur van Hoff
  266.39 - * @since   JDK1.0
  266.40 - */
  266.41 -public class MalformedURLException extends IOException {
  266.42 -    private static final long serialVersionUID = -182787522200415866L;
  266.43 -
  266.44 -    /**
  266.45 -     * Constructs a <code>MalformedURLException</code> with no detail message.
  266.46 -     */
  266.47 -    public MalformedURLException() {
  266.48 -    }
  266.49 -
  266.50 -    /**
  266.51 -     * Constructs a <code>MalformedURLException</code> with the
  266.52 -     * specified detail message.
  266.53 -     *
  266.54 -     * @param   msg   the detail message.
  266.55 -     */
  266.56 -    public MalformedURLException(String msg) {
  266.57 -        super(msg);
  266.58 -    }
  266.59 -}
   267.1 --- a/emul/src/main/java/java/net/URL.java	Wed Dec 05 10:03:58 2012 +0100
   267.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   267.3 @@ -1,958 +0,0 @@
   267.4 -/*
   267.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   267.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   267.7 - *
   267.8 - * This code is free software; you can redistribute it and/or modify it
   267.9 - * under the terms of the GNU General Public License version 2 only, as
  267.10 - * published by the Free Software Foundation.  Oracle designates this
  267.11 - * particular file as subject to the "Classpath" exception as provided
  267.12 - * by Oracle in the LICENSE file that accompanied this code.
  267.13 - *
  267.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  267.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  267.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  267.17 - * version 2 for more details (a copy is included in the LICENSE file that
  267.18 - * accompanied this code).
  267.19 - *
  267.20 - * You should have received a copy of the GNU General Public License version
  267.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  267.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  267.23 - *
  267.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  267.25 - * or visit www.oracle.com if you need additional information or have any
  267.26 - * questions.
  267.27 - */
  267.28 -
  267.29 -package java.net;
  267.30 -
  267.31 -import java.io.IOException;
  267.32 -import java.io.InputStream;
  267.33 -
  267.34 -/**
  267.35 - * Class <code>URL</code> represents a Uniform Resource
  267.36 - * Locator, a pointer to a "resource" on the World
  267.37 - * Wide Web. A resource can be something as simple as a file or a
  267.38 - * directory, or it can be a reference to a more complicated object,
  267.39 - * such as a query to a database or to a search engine. More
  267.40 - * information on the types of URLs and their formats can be found at:
  267.41 - * <blockquote>
  267.42 - *     <a href="http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html">
  267.43 - *    <i>http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html</i></a>
  267.44 - * </blockquote>
  267.45 - * <p>
  267.46 - * In general, a URL can be broken into several parts. The previous
  267.47 - * example of a URL indicates that the protocol to use is
  267.48 - * <code>http</code> (HyperText Transfer Protocol) and that the
  267.49 - * information resides on a host machine named
  267.50 - * <code>www.socs.uts.edu.au</code>. The information on that host
  267.51 - * machine is named <code>/MosaicDocs-old/url-primer.html</code>. The exact
  267.52 - * meaning of this name on the host machine is both protocol
  267.53 - * dependent and host dependent. The information normally resides in
  267.54 - * a file, but it could be generated on the fly. This component of
  267.55 - * the URL is called the <i>path</i> component.
  267.56 - * <p>
  267.57 - * A URL can optionally specify a "port", which is the
  267.58 - * port number to which the TCP connection is made on the remote host
  267.59 - * machine. If the port is not specified, the default port for
  267.60 - * the protocol is used instead. For example, the default port for
  267.61 - * <code>http</code> is <code>80</code>. An alternative port could be
  267.62 - * specified as:
  267.63 - * <blockquote><pre>
  267.64 - *     http://www.socs.uts.edu.au:80/MosaicDocs-old/url-primer.html
  267.65 - * </pre></blockquote>
  267.66 - * <p>
  267.67 - * The syntax of <code>URL</code> is defined by  <a
  267.68 - * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC&nbsp;2396: Uniform
  267.69 - * Resource Identifiers (URI): Generic Syntax</i></a>, amended by <a
  267.70 - * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC&nbsp;2732: Format for
  267.71 - * Literal IPv6 Addresses in URLs</i></a>. The Literal IPv6 address format
  267.72 - * also supports scope_ids. The syntax and usage of scope_ids is described
  267.73 - * <a href="Inet6Address.html#scoped">here</a>.
  267.74 - * <p>
  267.75 - * A URL may have appended to it a "fragment", also known
  267.76 - * as a "ref" or a "reference". The fragment is indicated by the sharp
  267.77 - * sign character "#" followed by more characters. For example,
  267.78 - * <blockquote><pre>
  267.79 - *     http://java.sun.com/index.html#chapter1
  267.80 - * </pre></blockquote>
  267.81 - * <p>
  267.82 - * This fragment is not technically part of the URL. Rather, it
  267.83 - * indicates that after the specified resource is retrieved, the
  267.84 - * application is specifically interested in that part of the
  267.85 - * document that has the tag <code>chapter1</code> attached to it. The
  267.86 - * meaning of a tag is resource specific.
  267.87 - * <p>
  267.88 - * An application can also specify a "relative URL",
  267.89 - * which contains only enough information to reach the resource
  267.90 - * relative to another URL. Relative URLs are frequently used within
  267.91 - * HTML pages. For example, if the contents of the URL:
  267.92 - * <blockquote><pre>
  267.93 - *     http://java.sun.com/index.html
  267.94 - * </pre></blockquote>
  267.95 - * contained within it the relative URL:
  267.96 - * <blockquote><pre>
  267.97 - *     FAQ.html
  267.98 - * </pre></blockquote>
  267.99 - * it would be a shorthand for:
 267.100 - * <blockquote><pre>
 267.101 - *     http://java.sun.com/FAQ.html
 267.102 - * </pre></blockquote>
 267.103 - * <p>
 267.104 - * The relative URL need not specify all the components of a URL. If
 267.105 - * the protocol, host name, or port number is missing, the value is
 267.106 - * inherited from the fully specified URL. The file component must be
 267.107 - * specified. The optional fragment is not inherited.
 267.108 - * <p>
 267.109 - * The URL class does not itself encode or decode any URL components
 267.110 - * according to the escaping mechanism defined in RFC2396. It is the
 267.111 - * responsibility of the caller to encode any fields, which need to be
 267.112 - * escaped prior to calling URL, and also to decode any escaped fields,
 267.113 - * that are returned from URL. Furthermore, because URL has no knowledge
 267.114 - * of URL escaping, it does not recognise equivalence between the encoded
 267.115 - * or decoded form of the same URL. For example, the two URLs:<br>
 267.116 - * <pre>    http://foo.com/hello world/ and http://foo.com/hello%20world</pre>
 267.117 - * would be considered not equal to each other.
 267.118 - * <p>
 267.119 - * Note, the {@link java.net.URI} class does perform escaping of its
 267.120 - * component fields in certain circumstances. The recommended way
 267.121 - * to manage the encoding and decoding of URLs is to use {@link java.net.URI},
 267.122 - * and to convert between these two classes using {@link #toURI()} and
 267.123 - * {@link URI#toURL()}.
 267.124 - * <p>
 267.125 - * The {@link URLEncoder} and {@link URLDecoder} classes can also be
 267.126 - * used, but only for HTML form encoding, which is not the same
 267.127 - * as the encoding scheme defined in RFC2396.
 267.128 - *
 267.129 - * @author  James Gosling
 267.130 - * @since JDK1.0
 267.131 - */
 267.132 -public final class URL implements java.io.Serializable {
 267.133 -
 267.134 -    static final long serialVersionUID = -7627629688361524110L;
 267.135 -
 267.136 -    /**
 267.137 -     * The property which specifies the package prefix list to be scanned
 267.138 -     * for protocol handlers.  The value of this property (if any) should
 267.139 -     * be a vertical bar delimited list of package names to search through
 267.140 -     * for a protocol handler to load.  The policy of this class is that
 267.141 -     * all protocol handlers will be in a class called <protocolname>.Handler,
 267.142 -     * and each package in the list is examined in turn for a matching
 267.143 -     * handler.  If none are found (or the property is not specified), the
 267.144 -     * default package prefix, sun.net.www.protocol, is used.  The search
 267.145 -     * proceeds from the first package in the list to the last and stops
 267.146 -     * when a match is found.
 267.147 -     */
 267.148 -    private static final String protocolPathProp = "java.protocol.handler.pkgs";
 267.149 -
 267.150 -    /**
 267.151 -     * The protocol to use (ftp, http, nntp, ... etc.) .
 267.152 -     * @serial
 267.153 -     */
 267.154 -    private String protocol;
 267.155 -
 267.156 -    /**
 267.157 -     * The host name to connect to.
 267.158 -     * @serial
 267.159 -     */
 267.160 -    private String host;
 267.161 -
 267.162 -    /**
 267.163 -     * The protocol port to connect to.
 267.164 -     * @serial
 267.165 -     */
 267.166 -    private int port = -1;
 267.167 -
 267.168 -    /**
 267.169 -     * The specified file name on that host. <code>file</code> is
 267.170 -     * defined as <code>path[?query]</code>
 267.171 -     * @serial
 267.172 -     */
 267.173 -    private String file;
 267.174 -
 267.175 -    /**
 267.176 -     * The query part of this URL.
 267.177 -     */
 267.178 -    private transient String query;
 267.179 -
 267.180 -    /**
 267.181 -     * The authority part of this URL.
 267.182 -     * @serial
 267.183 -     */
 267.184 -    private String authority;
 267.185 -
 267.186 -    /**
 267.187 -     * The path part of this URL.
 267.188 -     */
 267.189 -    private transient String path;
 267.190 -
 267.191 -    /**
 267.192 -     * The userinfo part of this URL.
 267.193 -     */
 267.194 -    private transient String userInfo;
 267.195 -
 267.196 -    /**
 267.197 -     * # reference.
 267.198 -     * @serial
 267.199 -     */
 267.200 -    private String ref;
 267.201 -
 267.202 -    /* Our hash code.
 267.203 -     * @serial
 267.204 -     */
 267.205 -    private int hashCode = -1;
 267.206 -
 267.207 -    /**
 267.208 -     * Creates a <code>URL</code> object from the specified
 267.209 -     * <code>protocol</code>, <code>host</code>, <code>port</code>
 267.210 -     * number, and <code>file</code>.<p>
 267.211 -     *
 267.212 -     * <code>host</code> can be expressed as a host name or a literal
 267.213 -     * IP address. If IPv6 literal address is used, it should be
 267.214 -     * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>), as
 267.215 -     * specified by <a
 267.216 -     * href="http://www.ietf.org/rfc/rfc2732.txt">RFC&nbsp;2732</a>;
 267.217 -     * However, the literal IPv6 address format defined in <a
 267.218 -     * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC&nbsp;2373: IP
 267.219 -     * Version 6 Addressing Architecture</i></a> is also accepted.<p>
 267.220 -     *
 267.221 -     * Specifying a <code>port</code> number of <code>-1</code>
 267.222 -     * indicates that the URL should use the default port for the
 267.223 -     * protocol.<p>
 267.224 -     *
 267.225 -     * If this is the first URL object being created with the specified
 267.226 -     * protocol, a <i>stream protocol handler</i> object, an instance of
 267.227 -     * class <code>URLStreamHandler</code>, is created for that protocol:
 267.228 -     * <ol>
 267.229 -     * <li>If the application has previously set up an instance of
 267.230 -     *     <code>URLStreamHandlerFactory</code> as the stream handler factory,
 267.231 -     *     then the <code>createURLStreamHandler</code> method of that instance
 267.232 -     *     is called with the protocol string as an argument to create the
 267.233 -     *     stream protocol handler.
 267.234 -     * <li>If no <code>URLStreamHandlerFactory</code> has yet been set up,
 267.235 -     *     or if the factory's <code>createURLStreamHandler</code> method
 267.236 -     *     returns <code>null</code>, then the constructor finds the
 267.237 -     *     value of the system property:
 267.238 -     *     <blockquote><pre>
 267.239 -     *         java.protocol.handler.pkgs
 267.240 -     *     </pre></blockquote>
 267.241 -     *     If the value of that system property is not <code>null</code>,
 267.242 -     *     it is interpreted as a list of packages separated by a vertical
 267.243 -     *     slash character '<code>|</code>'. The constructor tries to load
 267.244 -     *     the class named:
 267.245 -     *     <blockquote><pre>
 267.246 -     *         &lt;<i>package</i>&gt;.&lt;<i>protocol</i>&gt;.Handler
 267.247 -     *     </pre></blockquote>
 267.248 -     *     where &lt;<i>package</i>&gt; is replaced by the name of the package
 267.249 -     *     and &lt;<i>protocol</i>&gt; is replaced by the name of the protocol.
 267.250 -     *     If this class does not exist, or if the class exists but it is not
 267.251 -     *     a subclass of <code>URLStreamHandler</code>, then the next package
 267.252 -     *     in the list is tried.
 267.253 -     * <li>If the previous step fails to find a protocol handler, then the
 267.254 -     *     constructor tries to load from a system default package.
 267.255 -     *     <blockquote><pre>
 267.256 -     *         &lt;<i>system default package</i>&gt;.&lt;<i>protocol</i>&gt;.Handler
 267.257 -     *     </pre></blockquote>
 267.258 -     *     If this class does not exist, or if the class exists but it is not a
 267.259 -     *     subclass of <code>URLStreamHandler</code>, then a
 267.260 -     *     <code>MalformedURLException</code> is thrown.
 267.261 -     * </ol>
 267.262 -     *
 267.263 -     * <p>Protocol handlers for the following protocols are guaranteed
 267.264 -     * to exist on the search path :-
 267.265 -     * <blockquote><pre>
 267.266 -     *     http, https, ftp, file, and jar
 267.267 -     * </pre></blockquote>
 267.268 -     * Protocol handlers for additional protocols may also be
 267.269 -     * available.
 267.270 -     *
 267.271 -     * <p>No validation of the inputs is performed by this constructor.
 267.272 -     *
 267.273 -     * @param      protocol   the name of the protocol to use.
 267.274 -     * @param      host       the name of the host.
 267.275 -     * @param      port       the port number on the host.
 267.276 -     * @param      file       the file on the host
 267.277 -     * @exception  MalformedURLException  if an unknown protocol is specified.
 267.278 -     * @see        java.lang.System#getProperty(java.lang.String)
 267.279 -     * @see        java.net.URL#setURLStreamHandlerFactory(
 267.280 -     *                  java.net.URLStreamHandlerFactory)
 267.281 -     * @see        java.net.URLStreamHandler
 267.282 -     * @see        java.net.URLStreamHandlerFactory#createURLStreamHandler(
 267.283 -     *                  java.lang.String)
 267.284 -     */
 267.285 -    public URL(String protocol, String host, int port, String file)
 267.286 -        throws MalformedURLException
 267.287 -    {
 267.288 -        this(protocol, host, port, file, null);
 267.289 -    }
 267.290 -
 267.291 -    /**
 267.292 -     * Creates a URL from the specified <code>protocol</code>
 267.293 -     * name, <code>host</code> name, and <code>file</code> name. The
 267.294 -     * default port for the specified protocol is used.
 267.295 -     * <p>
 267.296 -     * This method is equivalent to calling the four-argument
 267.297 -     * constructor with the arguments being <code>protocol</code>,
 267.298 -     * <code>host</code>, <code>-1</code>, and <code>file</code>.
 267.299 -     *
 267.300 -     * No validation of the inputs is performed by this constructor.
 267.301 -     *
 267.302 -     * @param      protocol   the name of the protocol to use.
 267.303 -     * @param      host       the name of the host.
 267.304 -     * @param      file       the file on the host.
 267.305 -     * @exception  MalformedURLException  if an unknown protocol is specified.
 267.306 -     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 267.307 -     *                  int, java.lang.String)
 267.308 -     */
 267.309 -    public URL(String protocol, String host, String file)
 267.310 -            throws MalformedURLException {
 267.311 -        this(protocol, host, -1, file);
 267.312 -    }
 267.313 -
 267.314 -    private URL(String protocol, String host, int port, String file,
 267.315 -               Object handler) throws MalformedURLException {
 267.316 -        if (handler != null) {
 267.317 -            throw new SecurityException();
 267.318 -        }
 267.319 -
 267.320 -        protocol = protocol.toLowerCase();
 267.321 -        this.protocol = protocol;
 267.322 -        if (host != null) {
 267.323 -
 267.324 -            /**
 267.325 -             * if host is a literal IPv6 address,
 267.326 -             * we will make it conform to RFC 2732
 267.327 -             */
 267.328 -            if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
 267.329 -                host = "["+host+"]";
 267.330 -            }
 267.331 -            this.host = host;
 267.332 -
 267.333 -            if (port < -1) {
 267.334 -                throw new MalformedURLException("Invalid port number :" +
 267.335 -                                                    port);
 267.336 -            }
 267.337 -            this.port = port;
 267.338 -            authority = (port == -1) ? host : host + ":" + port;
 267.339 -        }
 267.340 -
 267.341 -        Parts parts = new Parts(file);
 267.342 -        path = parts.getPath();
 267.343 -        query = parts.getQuery();
 267.344 -
 267.345 -        if (query != null) {
 267.346 -            this.file = path + "?" + query;
 267.347 -        } else {
 267.348 -            this.file = path;
 267.349 -        }
 267.350 -        ref = parts.getRef();
 267.351 -
 267.352 -        // Note: we don't do validation of the URL here. Too risky to change
 267.353 -        // right now, but worth considering for future reference. -br
 267.354 -//        if (handler == null &&
 267.355 -//            (handler = getURLStreamHandler(protocol)) == null) {
 267.356 -//            throw new MalformedURLException("unknown protocol: " + protocol);
 267.357 -//        }
 267.358 -    }
 267.359 -
 267.360 -    /**
 267.361 -     * Creates a <code>URL</code> object from the <code>String</code>
 267.362 -     * representation.
 267.363 -     * <p>
 267.364 -     * This constructor is equivalent to a call to the two-argument
 267.365 -     * constructor with a <code>null</code> first argument.
 267.366 -     *
 267.367 -     * @param      spec   the <code>String</code> to parse as a URL.
 267.368 -     * @exception  MalformedURLException  if no protocol is specified, or an
 267.369 -     *               unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
 267.370 -     * @see        java.net.URL#URL(java.net.URL, java.lang.String)
 267.371 -     */
 267.372 -    public URL(String spec) throws MalformedURLException {
 267.373 -        this(null, spec);
 267.374 -    }
 267.375 -
 267.376 -    /**
 267.377 -     * Creates a URL by parsing the given spec within a specified context.
 267.378 -     *
 267.379 -     * The new URL is created from the given context URL and the spec
 267.380 -     * argument as described in
 267.381 -     * RFC2396 &quot;Uniform Resource Identifiers : Generic * Syntax&quot; :
 267.382 -     * <blockquote><pre>
 267.383 -     *          &lt;scheme&gt;://&lt;authority&gt;&lt;path&gt;?&lt;query&gt;#&lt;fragment&gt;
 267.384 -     * </pre></blockquote>
 267.385 -     * The reference is parsed into the scheme, authority, path, query and
 267.386 -     * fragment parts. If the path component is empty and the scheme,
 267.387 -     * authority, and query components are undefined, then the new URL is a
 267.388 -     * reference to the current document. Otherwise, the fragment and query
 267.389 -     * parts present in the spec are used in the new URL.
 267.390 -     * <p>
 267.391 -     * If the scheme component is defined in the given spec and does not match
 267.392 -     * the scheme of the context, then the new URL is created as an absolute
 267.393 -     * URL based on the spec alone. Otherwise the scheme component is inherited
 267.394 -     * from the context URL.
 267.395 -     * <p>
 267.396 -     * If the authority component is present in the spec then the spec is
 267.397 -     * treated as absolute and the spec authority and path will replace the
 267.398 -     * context authority and path. If the authority component is absent in the
 267.399 -     * spec then the authority of the new URL will be inherited from the
 267.400 -     * context.
 267.401 -     * <p>
 267.402 -     * If the spec's path component begins with a slash character
 267.403 -     * &quot;/&quot; then the
 267.404 -     * path is treated as absolute and the spec path replaces the context path.
 267.405 -     * <p>
 267.406 -     * Otherwise, the path is treated as a relative path and is appended to the
 267.407 -     * context path, as described in RFC2396. Also, in this case,
 267.408 -     * the path is canonicalized through the removal of directory
 267.409 -     * changes made by occurences of &quot;..&quot; and &quot;.&quot;.
 267.410 -     * <p>
 267.411 -     * For a more detailed description of URL parsing, refer to RFC2396.
 267.412 -     *
 267.413 -     * @param      context   the context in which to parse the specification.
 267.414 -     * @param      spec      the <code>String</code> to parse as a URL.
 267.415 -     * @exception  MalformedURLException  if no protocol is specified, or an
 267.416 -     *               unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
 267.417 -     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 267.418 -     *                  int, java.lang.String)
 267.419 -     * @see        java.net.URLStreamHandler
 267.420 -     * @see        java.net.URLStreamHandler#parseURL(java.net.URL,
 267.421 -     *                  java.lang.String, int, int)
 267.422 -     */
 267.423 -    public URL(URL context, String spec) throws MalformedURLException {
 267.424 -        this(context, spec, null);
 267.425 -    }
 267.426 -
 267.427 -    /**
 267.428 -     * Creates a URL by parsing the given spec with the specified handler
 267.429 -     * within a specified context. If the handler is null, the parsing
 267.430 -     * occurs as with the two argument constructor.
 267.431 -     *
 267.432 -     * @param      context   the context in which to parse the specification.
 267.433 -     * @param      spec      the <code>String</code> to parse as a URL.
 267.434 -     * @param      handler   the stream handler for the URL.
 267.435 -     * @exception  MalformedURLException  if no protocol is specified, or an
 267.436 -     *               unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
 267.437 -     * @exception  SecurityException
 267.438 -     *        if a security manager exists and its
 267.439 -     *        <code>checkPermission</code> method doesn't allow
 267.440 -     *        specifying a stream handler.
 267.441 -     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 267.442 -     *                  int, java.lang.String)
 267.443 -     * @see        java.net.URLStreamHandler
 267.444 -     * @see        java.net.URLStreamHandler#parseURL(java.net.URL,
 267.445 -     *                  java.lang.String, int, int)
 267.446 -     */
 267.447 -    private URL(URL context, String spec, Object handler)
 267.448 -        throws MalformedURLException
 267.449 -    {
 267.450 -        String original = spec;
 267.451 -        int i, limit, c;
 267.452 -        int start = 0;
 267.453 -        String newProtocol = null;
 267.454 -        boolean aRef=false;
 267.455 -        boolean isRelative = false;
 267.456 -
 267.457 -        // Check for permission to specify a handler
 267.458 -        if (handler != null) {
 267.459 -            throw new SecurityException();
 267.460 -        }
 267.461 -
 267.462 -        try {
 267.463 -            limit = spec.length();
 267.464 -            while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) {
 267.465 -                limit--;        //eliminate trailing whitespace
 267.466 -            }
 267.467 -            while ((start < limit) && (spec.charAt(start) <= ' ')) {
 267.468 -                start++;        // eliminate leading whitespace
 267.469 -            }
 267.470 -
 267.471 -            if (spec.regionMatches(true, start, "url:", 0, 4)) {
 267.472 -                start += 4;
 267.473 -            }
 267.474 -            if (start < spec.length() && spec.charAt(start) == '#') {
 267.475 -                /* we're assuming this is a ref relative to the context URL.
 267.476 -                 * This means protocols cannot start w/ '#', but we must parse
 267.477 -                 * ref URL's like: "hello:there" w/ a ':' in them.
 267.478 -                 */
 267.479 -                aRef=true;
 267.480 -            }
 267.481 -            for (i = start ; !aRef && (i < limit) &&
 267.482 -                     ((c = spec.charAt(i)) != '/') ; i++) {
 267.483 -                if (c == ':') {
 267.484 -
 267.485 -                    String s = spec.substring(start, i).toLowerCase();
 267.486 -                    if (isValidProtocol(s)) {
 267.487 -                        newProtocol = s;
 267.488 -                        start = i + 1;
 267.489 -                    }
 267.490 -                    break;
 267.491 -                }
 267.492 -            }
 267.493 -
 267.494 -            // Only use our context if the protocols match.
 267.495 -            protocol = newProtocol;
 267.496 -            if ((context != null) && ((newProtocol == null) ||
 267.497 -                            newProtocol.equalsIgnoreCase(context.protocol))) {
 267.498 -                // inherit the protocol handler from the context
 267.499 -                // if not specified to the constructor
 267.500 -//                if (handler == null) {
 267.501 -//                    handler = context.handler;
 267.502 -//                }
 267.503 -
 267.504 -                // If the context is a hierarchical URL scheme and the spec
 267.505 -                // contains a matching scheme then maintain backwards
 267.506 -                // compatibility and treat it as if the spec didn't contain
 267.507 -                // the scheme; see 5.2.3 of RFC2396
 267.508 -                if (context.path != null && context.path.startsWith("/"))
 267.509 -                    newProtocol = null;
 267.510 -
 267.511 -                if (newProtocol == null) {
 267.512 -                    protocol = context.protocol;
 267.513 -                    authority = context.authority;
 267.514 -                    userInfo = context.userInfo;
 267.515 -                    host = context.host;
 267.516 -                    port = context.port;
 267.517 -                    file = context.file;
 267.518 -                    path = context.path;
 267.519 -                    isRelative = true;
 267.520 -                }
 267.521 -            }
 267.522 -
 267.523 -            if (protocol == null) {
 267.524 -                throw new MalformedURLException("no protocol: "+original);
 267.525 -            }
 267.526 -
 267.527 -            // Get the protocol handler if not specified or the protocol
 267.528 -            // of the context could not be used
 267.529 -//            if (handler == null &&
 267.530 -//                (handler = getURLStreamHandler(protocol)) == null) {
 267.531 -//                throw new MalformedURLException("unknown protocol: "+protocol);
 267.532 -//            }
 267.533 -
 267.534 -//            this.handler = handler;
 267.535 -
 267.536 -            i = spec.indexOf('#', start);
 267.537 -            if (i >= 0) {
 267.538 -                ref = spec.substring(i + 1, limit);
 267.539 -                limit = i;
 267.540 -            }
 267.541 -
 267.542 -            /*
 267.543 -             * Handle special case inheritance of query and fragment
 267.544 -             * implied by RFC2396 section 5.2.2.
 267.545 -             */
 267.546 -            if (isRelative && start == limit) {
 267.547 -                query = context.query;
 267.548 -                if (ref == null) {
 267.549 -                    ref = context.ref;
 267.550 -                }
 267.551 -            }
 267.552 -
 267.553 -//            handler.parseURL(this, spec, start, limit);
 267.554 -
 267.555 -        } catch(MalformedURLException e) {
 267.556 -            throw e;
 267.557 -        } catch(Exception e) {
 267.558 -            MalformedURLException exception = new MalformedURLException(e.getMessage());
 267.559 -            exception.initCause(e);
 267.560 -            throw exception;
 267.561 -        }
 267.562 -    }
 267.563 -
 267.564 -    /*
 267.565 -     * Returns true if specified string is a valid protocol name.
 267.566 -     */
 267.567 -    private boolean isValidProtocol(String protocol) {
 267.568 -        int len = protocol.length();
 267.569 -        if (len < 1)
 267.570 -            return false;
 267.571 -        char c = protocol.charAt(0);
 267.572 -        if (!Character.isLetter(c))
 267.573 -            return false;
 267.574 -        for (int i = 1; i < len; i++) {
 267.575 -            c = protocol.charAt(i);
 267.576 -            if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' &&
 267.577 -                c != '-') {
 267.578 -                return false;
 267.579 -            }
 267.580 -        }
 267.581 -        return true;
 267.582 -    }
 267.583 -
 267.584 -    /**
 267.585 -     * Sets the fields of the URL. This is not a public method so that
 267.586 -     * only URLStreamHandlers can modify URL fields. URLs are
 267.587 -     * otherwise constant.
 267.588 -     *
 267.589 -     * @param protocol the name of the protocol to use
 267.590 -     * @param host the name of the host
 267.591 -       @param port the port number on the host
 267.592 -     * @param file the file on the host
 267.593 -     * @param ref the internal reference in the URL
 267.594 -     */
 267.595 -    protected void set(String protocol, String host,
 267.596 -                       int port, String file, String ref) {
 267.597 -        synchronized (this) {
 267.598 -            this.protocol = protocol;
 267.599 -            this.host = host;
 267.600 -            authority = port == -1 ? host : host + ":" + port;
 267.601 -            this.port = port;
 267.602 -            this.file = file;
 267.603 -            this.ref = ref;
 267.604 -            /* This is very important. We must recompute this after the
 267.605 -             * URL has been changed. */
 267.606 -            hashCode = -1;
 267.607 -            int q = file.lastIndexOf('?');
 267.608 -            if (q != -1) {
 267.609 -                query = file.substring(q+1);
 267.610 -                path = file.substring(0, q);
 267.611 -            } else
 267.612 -                path = file;
 267.613 -        }
 267.614 -    }
 267.615 -
 267.616 -    /**
 267.617 -     * Sets the specified 8 fields of the URL. This is not a public method so
 267.618 -     * that only URLStreamHandlers can modify URL fields. URLs are otherwise
 267.619 -     * constant.
 267.620 -     *
 267.621 -     * @param protocol the name of the protocol to use
 267.622 -     * @param host the name of the host
 267.623 -     * @param port the port number on the host
 267.624 -     * @param authority the authority part for the url
 267.625 -     * @param userInfo the username and password
 267.626 -     * @param path the file on the host
 267.627 -     * @param ref the internal reference in the URL
 267.628 -     * @param query the query part of this URL
 267.629 -     * @since 1.3
 267.630 -     */
 267.631 -    protected void set(String protocol, String host, int port,
 267.632 -                       String authority, String userInfo, String path,
 267.633 -                       String query, String ref) {
 267.634 -        synchronized (this) {
 267.635 -            this.protocol = protocol;
 267.636 -            this.host = host;
 267.637 -            this.port = port;
 267.638 -            this.file = query == null ? path : path + "?" + query;
 267.639 -            this.userInfo = userInfo;
 267.640 -            this.path = path;
 267.641 -            this.ref = ref;
 267.642 -            /* This is very important. We must recompute this after the
 267.643 -             * URL has been changed. */
 267.644 -            hashCode = -1;
 267.645 -            this.query = query;
 267.646 -            this.authority = authority;
 267.647 -        }
 267.648 -    }
 267.649 -
 267.650 -    /**
 267.651 -     * Gets the query part of this <code>URL</code>.
 267.652 -     *
 267.653 -     * @return  the query part of this <code>URL</code>,
 267.654 -     * or <CODE>null</CODE> if one does not exist
 267.655 -     * @since 1.3
 267.656 -     */
 267.657 -    public String getQuery() {
 267.658 -        return query;
 267.659 -    }
 267.660 -
 267.661 -    /**
 267.662 -     * Gets the path part of this <code>URL</code>.
 267.663 -     *
 267.664 -     * @return  the path part of this <code>URL</code>, or an
 267.665 -     * empty string if one does not exist
 267.666 -     * @since 1.3
 267.667 -     */
 267.668 -    public String getPath() {
 267.669 -        return path;
 267.670 -    }
 267.671 -
 267.672 -    /**
 267.673 -     * Gets the userInfo part of this <code>URL</code>.
 267.674 -     *
 267.675 -     * @return  the userInfo part of this <code>URL</code>, or
 267.676 -     * <CODE>null</CODE> if one does not exist
 267.677 -     * @since 1.3
 267.678 -     */
 267.679 -    public String getUserInfo() {
 267.680 -        return userInfo;
 267.681 -    }
 267.682 -
 267.683 -    /**
 267.684 -     * Gets the authority part of this <code>URL</code>.
 267.685 -     *
 267.686 -     * @return  the authority part of this <code>URL</code>
 267.687 -     * @since 1.3
 267.688 -     */
 267.689 -    public String getAuthority() {
 267.690 -        return authority;
 267.691 -    }
 267.692 -
 267.693 -    /**
 267.694 -     * Gets the port number of this <code>URL</code>.
 267.695 -     *
 267.696 -     * @return  the port number, or -1 if the port is not set
 267.697 -     */
 267.698 -    public int getPort() {
 267.699 -        return port;
 267.700 -    }
 267.701 -
 267.702 -    /**
 267.703 -     * Gets the protocol name of this <code>URL</code>.
 267.704 -     *
 267.705 -     * @return  the protocol of this <code>URL</code>.
 267.706 -     */
 267.707 -    public String getProtocol() {
 267.708 -        return protocol;
 267.709 -    }
 267.710 -
 267.711 -    /**
 267.712 -     * Gets the host name of this <code>URL</code>, if applicable.
 267.713 -     * The format of the host conforms to RFC 2732, i.e. for a
 267.714 -     * literal IPv6 address, this method will return the IPv6 address
 267.715 -     * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>).
 267.716 -     *
 267.717 -     * @return  the host name of this <code>URL</code>.
 267.718 -     */
 267.719 -    public String getHost() {
 267.720 -        return host;
 267.721 -    }
 267.722 -
 267.723 -    /**
 267.724 -     * Gets the file name of this <code>URL</code>.
 267.725 -     * The returned file portion will be
 267.726 -     * the same as <CODE>getPath()</CODE>, plus the concatenation of
 267.727 -     * the value of <CODE>getQuery()</CODE>, if any. If there is
 267.728 -     * no query portion, this method and <CODE>getPath()</CODE> will
 267.729 -     * return identical results.
 267.730 -     *
 267.731 -     * @return  the file name of this <code>URL</code>,
 267.732 -     * or an empty string if one does not exist
 267.733 -     */
 267.734 -    public String getFile() {
 267.735 -        return file;
 267.736 -    }
 267.737 -
 267.738 -    /**
 267.739 -     * Gets the anchor (also known as the "reference") of this
 267.740 -     * <code>URL</code>.
 267.741 -     *
 267.742 -     * @return  the anchor (also known as the "reference") of this
 267.743 -     *          <code>URL</code>, or <CODE>null</CODE> if one does not exist
 267.744 -     */
 267.745 -    public String getRef() {
 267.746 -        return ref;
 267.747 -    }
 267.748 -
 267.749 -    /**
 267.750 -     * Compares this URL for equality with another object.<p>
 267.751 -     *
 267.752 -     * If the given object is not a URL then this method immediately returns
 267.753 -     * <code>false</code>.<p>
 267.754 -     *
 267.755 -     * Two URL objects are equal if they have the same protocol, reference
 267.756 -     * equivalent hosts, have the same port number on the host, and the same
 267.757 -     * file and fragment of the file.<p>
 267.758 -     *
 267.759 -     * Two hosts are considered equivalent if both host names can be resolved
 267.760 -     * into the same IP addresses; else if either host name can't be
 267.761 -     * resolved, the host names must be equal without regard to case; or both
 267.762 -     * host names equal to null.<p>
 267.763 -     *
 267.764 -     * Since hosts comparison requires name resolution, this operation is a
 267.765 -     * blocking operation. <p>
 267.766 -     *
 267.767 -     * Note: The defined behavior for <code>equals</code> is known to
 267.768 -     * be inconsistent with virtual hosting in HTTP.
 267.769 -     *
 267.770 -     * @param   obj   the URL to compare against.
 267.771 -     * @return  <code>true</code> if the objects are the same;
 267.772 -     *          <code>false</code> otherwise.
 267.773 -     */
 267.774 -    public boolean equals(Object obj) {
 267.775 -        if (!(obj instanceof URL))
 267.776 -            return false;
 267.777 -        URL u2 = (URL)obj;
 267.778 -
 267.779 -     //   return handler.equals(this, u2);
 267.780 -        return u2 == this;
 267.781 -    }
 267.782 -
 267.783 -    /**
 267.784 -     * Creates an integer suitable for hash table indexing.<p>
 267.785 -     *
 267.786 -     * The hash code is based upon all the URL components relevant for URL
 267.787 -     * comparison. As such, this operation is a blocking operation.<p>
 267.788 -     *
 267.789 -     * @return  a hash code for this <code>URL</code>.
 267.790 -     */
 267.791 -    public synchronized int hashCode() {
 267.792 -        if (hashCode != -1)
 267.793 -            return hashCode;
 267.794 -
 267.795 -     //   hashCode = handler.hashCode(this);
 267.796 -        return hashCode;
 267.797 -    }
 267.798 -
 267.799 -    /**
 267.800 -     * Compares two URLs, excluding the fragment component.<p>
 267.801 -     *
 267.802 -     * Returns <code>true</code> if this <code>URL</code> and the
 267.803 -     * <code>other</code> argument are equal without taking the
 267.804 -     * fragment component into consideration.
 267.805 -     *
 267.806 -     * @param   other   the <code>URL</code> to compare against.
 267.807 -     * @return  <code>true</code> if they reference the same remote object;
 267.808 -     *          <code>false</code> otherwise.
 267.809 -     */
 267.810 -    public boolean sameFile(URL other) {
 267.811 -//        return handler.sameFile(this, other);
 267.812 -        throw new UnsupportedOperationException();
 267.813 -    }
 267.814 -
 267.815 -    /**
 267.816 -     * Constructs a string representation of this <code>URL</code>. The
 267.817 -     * string is created by calling the <code>toExternalForm</code>
 267.818 -     * method of the stream protocol handler for this object.
 267.819 -     *
 267.820 -     * @return  a string representation of this object.
 267.821 -     * @see     java.net.URL#URL(java.lang.String, java.lang.String, int,
 267.822 -     *                  java.lang.String)
 267.823 -     * @see     java.net.URLStreamHandler#toExternalForm(java.net.URL)
 267.824 -     */
 267.825 -    public String toString() {
 267.826 -        return toExternalForm();
 267.827 -    }
 267.828 -
 267.829 -    /**
 267.830 -     * Constructs a string representation of this <code>URL</code>. The
 267.831 -     * string is created by calling the <code>toExternalForm</code>
 267.832 -     * method of the stream protocol handler for this object.
 267.833 -     *
 267.834 -     * @return  a string representation of this object.
 267.835 -     * @see     java.net.URL#URL(java.lang.String, java.lang.String,
 267.836 -     *                  int, java.lang.String)
 267.837 -     * @see     java.net.URLStreamHandler#toExternalForm(java.net.URL)
 267.838 -     */
 267.839 -    public String toExternalForm() {
 267.840 -        throw new UnsupportedOperationException();
 267.841 -//        return handler.toExternalForm(this);
 267.842 -    }
 267.843 -
 267.844 -    /**
 267.845 -     * Returns a {@link java.net.URLConnection URLConnection} instance that
 267.846 -     * represents a connection to the remote object referred to by the
 267.847 -     * {@code URL}.
 267.848 -     *
 267.849 -     * <P>A new instance of {@linkplain java.net.URLConnection URLConnection} is
 267.850 -     * created every time when invoking the
 267.851 -     * {@linkplain java.net.URLStreamHandler#openConnection(URL)
 267.852 -     * URLStreamHandler.openConnection(URL)} method of the protocol handler for
 267.853 -     * this URL.</P>
 267.854 -     *
 267.855 -     * <P>It should be noted that a URLConnection instance does not establish
 267.856 -     * the actual network connection on creation. This will happen only when
 267.857 -     * calling {@linkplain java.net.URLConnection#connect() URLConnection.connect()}.</P>
 267.858 -     *
 267.859 -     * <P>If for the URL's protocol (such as HTTP or JAR), there
 267.860 -     * exists a public, specialized URLConnection subclass belonging
 267.861 -     * to one of the following packages or one of their subpackages:
 267.862 -     * java.lang, java.io, java.util, java.net, the connection
 267.863 -     * returned will be of that subclass. For example, for HTTP an
 267.864 -     * HttpURLConnection will be returned, and for JAR a
 267.865 -     * JarURLConnection will be returned.</P>
 267.866 -     *
 267.867 -     * @return     a {@link java.net.URLConnection URLConnection} linking
 267.868 -     *             to the URL.
 267.869 -     * @exception  IOException  if an I/O exception occurs.
 267.870 -     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 267.871 -     *             int, java.lang.String)
 267.872 -     */
 267.873 -//    public URLConnection openConnection() throws java.io.IOException {
 267.874 -//        return handler.openConnection(this);
 267.875 -//    }
 267.876 -
 267.877 -
 267.878 -    /**
 267.879 -     * Opens a connection to this <code>URL</code> and returns an
 267.880 -     * <code>InputStream</code> for reading from that connection. This
 267.881 -     * method is a shorthand for:
 267.882 -     * <blockquote><pre>
 267.883 -     *     openConnection().getInputStream()
 267.884 -     * </pre></blockquote>
 267.885 -     *
 267.886 -     * @return     an input stream for reading from the URL connection.
 267.887 -     * @exception  IOException  if an I/O exception occurs.
 267.888 -     * @see        java.net.URL#openConnection()
 267.889 -     * @see        java.net.URLConnection#getInputStream()
 267.890 -     */
 267.891 -    public final InputStream openStream() throws java.io.IOException {
 267.892 -        throw new IOException();
 267.893 -//        return openConnection().getInputStream();
 267.894 -    }
 267.895 -
 267.896 -    /**
 267.897 -     * Gets the contents of this URL. This method is a shorthand for:
 267.898 -     * <blockquote><pre>
 267.899 -     *     openConnection().getContent()
 267.900 -     * </pre></blockquote>
 267.901 -     *
 267.902 -     * @return     the contents of this URL.
 267.903 -     * @exception  IOException  if an I/O exception occurs.
 267.904 -     * @see        java.net.URLConnection#getContent()
 267.905 -     */
 267.906 -    public final Object getContent() throws java.io.IOException {
 267.907 -        throw new IOException();
 267.908 -//        return openConnection().getContent();
 267.909 -    }
 267.910 -
 267.911 -    /**
 267.912 -     * Gets the contents of this URL. This method is a shorthand for:
 267.913 -     * <blockquote><pre>
 267.914 -     *     openConnection().getContent(Class[])
 267.915 -     * </pre></blockquote>
 267.916 -     *
 267.917 -     * @param classes an array of Java types
 267.918 -     * @return     the content object of this URL that is the first match of
 267.919 -     *               the types specified in the classes array.
 267.920 -     *               null if none of the requested types are supported.
 267.921 -     * @exception  IOException  if an I/O exception occurs.
 267.922 -     * @see        java.net.URLConnection#getContent(Class[])
 267.923 -     * @since 1.3
 267.924 -     */
 267.925 -    public final Object getContent(Class[] classes)
 267.926 -    throws java.io.IOException {
 267.927 -        throw new IOException();
 267.928 -//        return openConnection().getContent(classes);
 267.929 -    }
 267.930 -
 267.931 -
 267.932 -}
 267.933 -
 267.934 -class Parts {
 267.935 -    String path, query, ref;
 267.936 -
 267.937 -    Parts(String file) {
 267.938 -        int ind = file.indexOf('#');
 267.939 -        ref = ind < 0 ? null: file.substring(ind + 1);
 267.940 -        file = ind < 0 ? file: file.substring(0, ind);
 267.941 -        int q = file.lastIndexOf('?');
 267.942 -        if (q != -1) {
 267.943 -            query = file.substring(q+1);
 267.944 -            path = file.substring(0, q);
 267.945 -        } else {
 267.946 -            path = file;
 267.947 -        }
 267.948 -    }
 267.949 -
 267.950 -    String getPath() {
 267.951 -        return path;
 267.952 -    }
 267.953 -
 267.954 -    String getQuery() {
 267.955 -        return query;
 267.956 -    }
 267.957 -
 267.958 -    String getRef() {
 267.959 -        return ref;
 267.960 -    }
 267.961 -}
   268.1 --- a/emul/src/main/java/java/util/Comparator.java	Wed Dec 05 10:03:58 2012 +0100
   268.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   268.3 @@ -1,168 +0,0 @@
   268.4 -/*
   268.5 - * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
   268.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   268.7 - *
   268.8 - * This code is free software; you can redistribute it and/or modify it
   268.9 - * under the terms of the GNU General Public License version 2 only, as
  268.10 - * published by the Free Software Foundation.  Oracle designates this
  268.11 - * particular file as subject to the "Classpath" exception as provided
  268.12 - * by Oracle in the LICENSE file that accompanied this code.
  268.13 - *
  268.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  268.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  268.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  268.17 - * version 2 for more details (a copy is included in the LICENSE file that
  268.18 - * accompanied this code).
  268.19 - *
  268.20 - * You should have received a copy of the GNU General Public License version
  268.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  268.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  268.23 - *
  268.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  268.25 - * or visit www.oracle.com if you need additional information or have any
  268.26 - * questions.
  268.27 - */
  268.28 -
  268.29 -package java.util;
  268.30 -
  268.31 -/**
  268.32 - * A comparison function, which imposes a <i>total ordering</i> on some
  268.33 - * collection of objects.  Comparators can be passed to a sort method (such
  268.34 - * as {@link Collections#sort(List,Comparator) Collections.sort} or {@link
  268.35 - * Arrays#sort(Object[],Comparator) Arrays.sort}) to allow precise control
  268.36 - * over the sort order.  Comparators can also be used to control the order of
  268.37 - * certain data structures (such as {@link SortedSet sorted sets} or {@link
  268.38 - * SortedMap sorted maps}), or to provide an ordering for collections of
  268.39 - * objects that don't have a {@link Comparable natural ordering}.<p>
  268.40 - *
  268.41 - * The ordering imposed by a comparator <tt>c</tt> on a set of elements
  268.42 - * <tt>S</tt> is said to be <i>consistent with equals</i> if and only if
  268.43 - * <tt>c.compare(e1, e2)==0</tt> has the same boolean value as
  268.44 - * <tt>e1.equals(e2)</tt> for every <tt>e1</tt> and <tt>e2</tt> in
  268.45 - * <tt>S</tt>.<p>
  268.46 - *
  268.47 - * Caution should be exercised when using a comparator capable of imposing an
  268.48 - * ordering inconsistent with equals to order a sorted set (or sorted map).
  268.49 - * Suppose a sorted set (or sorted map) with an explicit comparator <tt>c</tt>
  268.50 - * is used with elements (or keys) drawn from a set <tt>S</tt>.  If the
  268.51 - * ordering imposed by <tt>c</tt> on <tt>S</tt> is inconsistent with equals,
  268.52 - * the sorted set (or sorted map) will behave "strangely."  In particular the
  268.53 - * sorted set (or sorted map) will violate the general contract for set (or
  268.54 - * map), which is defined in terms of <tt>equals</tt>.<p>
  268.55 - *
  268.56 - * For example, suppose one adds two elements {@code a} and {@code b} such that
  268.57 - * {@code (a.equals(b) && c.compare(a, b) != 0)}
  268.58 - * to an empty {@code TreeSet} with comparator {@code c}.
  268.59 - * The second {@code add} operation will return
  268.60 - * true (and the size of the tree set will increase) because {@code a} and
  268.61 - * {@code b} are not equivalent from the tree set's perspective, even though
  268.62 - * this is contrary to the specification of the
  268.63 - * {@link Set#add Set.add} method.<p>
  268.64 - *
  268.65 - * Note: It is generally a good idea for comparators to also implement
  268.66 - * <tt>java.io.Serializable</tt>, as they may be used as ordering methods in
  268.67 - * serializable data structures (like {@link TreeSet}, {@link TreeMap}).  In
  268.68 - * order for the data structure to serialize successfully, the comparator (if
  268.69 - * provided) must implement <tt>Serializable</tt>.<p>
  268.70 - *
  268.71 - * For the mathematically inclined, the <i>relation</i> that defines the
  268.72 - * <i>imposed ordering</i> that a given comparator <tt>c</tt> imposes on a
  268.73 - * given set of objects <tt>S</tt> is:<pre>
  268.74 - *       {(x, y) such that c.compare(x, y) &lt;= 0}.
  268.75 - * </pre> The <i>quotient</i> for this total order is:<pre>
  268.76 - *       {(x, y) such that c.compare(x, y) == 0}.
  268.77 - * </pre>
  268.78 - *
  268.79 - * It follows immediately from the contract for <tt>compare</tt> that the
  268.80 - * quotient is an <i>equivalence relation</i> on <tt>S</tt>, and that the
  268.81 - * imposed ordering is a <i>total order</i> on <tt>S</tt>.  When we say that
  268.82 - * the ordering imposed by <tt>c</tt> on <tt>S</tt> is <i>consistent with
  268.83 - * equals</i>, we mean that the quotient for the ordering is the equivalence
  268.84 - * relation defined by the objects' {@link Object#equals(Object)
  268.85 - * equals(Object)} method(s):<pre>
  268.86 - *     {(x, y) such that x.equals(y)}. </pre>
  268.87 - *
  268.88 - * <p>Unlike {@code Comparable}, a comparator may optionally permit
  268.89 - * comparison of null arguments, while maintaining the requirements for
  268.90 - * an equivalence relation.
  268.91 - *
  268.92 - * <p>This interface is a member of the
  268.93 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  268.94 - * Java Collections Framework</a>.
  268.95 - *
  268.96 - * @param <T> the type of objects that may be compared by this comparator
  268.97 - *
  268.98 - * @author  Josh Bloch
  268.99 - * @author  Neal Gafter
 268.100 - * @see Comparable
 268.101 - * @see java.io.Serializable
 268.102 - * @since 1.2
 268.103 - */
 268.104 -
 268.105 -public interface Comparator<T> {
 268.106 -    /**
 268.107 -     * Compares its two arguments for order.  Returns a negative integer,
 268.108 -     * zero, or a positive integer as the first argument is less than, equal
 268.109 -     * to, or greater than the second.<p>
 268.110 -     *
 268.111 -     * In the foregoing description, the notation
 268.112 -     * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
 268.113 -     * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
 268.114 -     * <tt>0</tt>, or <tt>1</tt> according to whether the value of
 268.115 -     * <i>expression</i> is negative, zero or positive.<p>
 268.116 -     *
 268.117 -     * The implementor must ensure that <tt>sgn(compare(x, y)) ==
 268.118 -     * -sgn(compare(y, x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
 268.119 -     * implies that <tt>compare(x, y)</tt> must throw an exception if and only
 268.120 -     * if <tt>compare(y, x)</tt> throws an exception.)<p>
 268.121 -     *
 268.122 -     * The implementor must also ensure that the relation is transitive:
 268.123 -     * <tt>((compare(x, y)&gt;0) &amp;&amp; (compare(y, z)&gt;0))</tt> implies
 268.124 -     * <tt>compare(x, z)&gt;0</tt>.<p>
 268.125 -     *
 268.126 -     * Finally, the implementor must ensure that <tt>compare(x, y)==0</tt>
 268.127 -     * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all
 268.128 -     * <tt>z</tt>.<p>
 268.129 -     *
 268.130 -     * It is generally the case, but <i>not</i> strictly required that
 268.131 -     * <tt>(compare(x, y)==0) == (x.equals(y))</tt>.  Generally speaking,
 268.132 -     * any comparator that violates this condition should clearly indicate
 268.133 -     * this fact.  The recommended language is "Note: this comparator
 268.134 -     * imposes orderings that are inconsistent with equals."
 268.135 -     *
 268.136 -     * @param o1 the first object to be compared.
 268.137 -     * @param o2 the second object to be compared.
 268.138 -     * @return a negative integer, zero, or a positive integer as the
 268.139 -     *         first argument is less than, equal to, or greater than the
 268.140 -     *         second.
 268.141 -     * @throws NullPointerException if an argument is null and this
 268.142 -     *         comparator does not permit null arguments
 268.143 -     * @throws ClassCastException if the arguments' types prevent them from
 268.144 -     *         being compared by this comparator.
 268.145 -     */
 268.146 -    int compare(T o1, T o2);
 268.147 -
 268.148 -    /**
 268.149 -     * Indicates whether some other object is &quot;equal to&quot; this
 268.150 -     * comparator.  This method must obey the general contract of
 268.151 -     * {@link Object#equals(Object)}.  Additionally, this method can return
 268.152 -     * <tt>true</tt> <i>only</i> if the specified object is also a comparator
 268.153 -     * and it imposes the same ordering as this comparator.  Thus,
 268.154 -     * <code>comp1.equals(comp2)</code> implies that <tt>sgn(comp1.compare(o1,
 268.155 -     * o2))==sgn(comp2.compare(o1, o2))</tt> for every object reference
 268.156 -     * <tt>o1</tt> and <tt>o2</tt>.<p>
 268.157 -     *
 268.158 -     * Note that it is <i>always</i> safe <i>not</i> to override
 268.159 -     * <tt>Object.equals(Object)</tt>.  However, overriding this method may,
 268.160 -     * in some cases, improve performance by allowing programs to determine
 268.161 -     * that two distinct comparators impose the same order.
 268.162 -     *
 268.163 -     * @param   obj   the reference object with which to compare.
 268.164 -     * @return  <code>true</code> only if the specified object is also
 268.165 -     *          a comparator and it imposes the same ordering as this
 268.166 -     *          comparator.
 268.167 -     * @see Object#equals(Object)
 268.168 -     * @see Object#hashCode()
 268.169 -     */
 268.170 -    boolean equals(Object obj);
 268.171 -}
   269.1 --- a/emul/src/main/java/java/util/Enumeration.java	Wed Dec 05 10:03:58 2012 +0100
   269.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   269.3 @@ -1,79 +0,0 @@
   269.4 -/*
   269.5 - * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
   269.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   269.7 - *
   269.8 - * This code is free software; you can redistribute it and/or modify it
   269.9 - * under the terms of the GNU General Public License version 2 only, as
  269.10 - * published by the Free Software Foundation.  Oracle designates this
  269.11 - * particular file as subject to the "Classpath" exception as provided
  269.12 - * by Oracle in the LICENSE file that accompanied this code.
  269.13 - *
  269.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  269.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  269.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  269.17 - * version 2 for more details (a copy is included in the LICENSE file that
  269.18 - * accompanied this code).
  269.19 - *
  269.20 - * You should have received a copy of the GNU General Public License version
  269.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  269.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  269.23 - *
  269.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  269.25 - * or visit www.oracle.com if you need additional information or have any
  269.26 - * questions.
  269.27 - */
  269.28 -
  269.29 -package java.util;
  269.30 -
  269.31 -/**
  269.32 - * An object that implements the Enumeration interface generates a
  269.33 - * series of elements, one at a time. Successive calls to the
  269.34 - * <code>nextElement</code> method return successive elements of the
  269.35 - * series.
  269.36 - * <p>
  269.37 - * For example, to print all elements of a <tt>Vector&lt;E&gt;</tt> <i>v</i>:
  269.38 - * <pre>
  269.39 - *   for (Enumeration&lt;E&gt; e = v.elements(); e.hasMoreElements();)
  269.40 - *       System.out.println(e.nextElement());</pre>
  269.41 - * <p>
  269.42 - * Methods are provided to enumerate through the elements of a
  269.43 - * vector, the keys of a hashtable, and the values in a hashtable.
  269.44 - * Enumerations are also used to specify the input streams to a
  269.45 - * <code>SequenceInputStream</code>.
  269.46 - * <p>
  269.47 - * NOTE: The functionality of this interface is duplicated by the Iterator
  269.48 - * interface.  In addition, Iterator adds an optional remove operation, and
  269.49 - * has shorter method names.  New implementations should consider using
  269.50 - * Iterator in preference to Enumeration.
  269.51 - *
  269.52 - * @see     java.util.Iterator
  269.53 - * @see     java.io.SequenceInputStream
  269.54 - * @see     java.util.Enumeration#nextElement()
  269.55 - * @see     java.util.Hashtable
  269.56 - * @see     java.util.Hashtable#elements()
  269.57 - * @see     java.util.Hashtable#keys()
  269.58 - * @see     java.util.Vector
  269.59 - * @see     java.util.Vector#elements()
  269.60 - *
  269.61 - * @author  Lee Boynton
  269.62 - * @since   JDK1.0
  269.63 - */
  269.64 -public interface Enumeration<E> {
  269.65 -    /**
  269.66 -     * Tests if this enumeration contains more elements.
  269.67 -     *
  269.68 -     * @return  <code>true</code> if and only if this enumeration object
  269.69 -     *           contains at least one more element to provide;
  269.70 -     *          <code>false</code> otherwise.
  269.71 -     */
  269.72 -    boolean hasMoreElements();
  269.73 -
  269.74 -    /**
  269.75 -     * Returns the next element of this enumeration if this enumeration
  269.76 -     * object has at least one more element to provide.
  269.77 -     *
  269.78 -     * @return     the next element of this enumeration.
  269.79 -     * @exception  NoSuchElementException  if no more elements exist.
  269.80 -     */
  269.81 -    E nextElement();
  269.82 -}
   270.1 --- a/emul/src/main/java/java/util/NoSuchElementException.java	Wed Dec 05 10:03:58 2012 +0100
   270.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   270.3 @@ -1,60 +0,0 @@
   270.4 -/*
   270.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   270.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   270.7 - *
   270.8 - * This code is free software; you can redistribute it and/or modify it
   270.9 - * under the terms of the GNU General Public License version 2 only, as
  270.10 - * published by the Free Software Foundation.  Oracle designates this
  270.11 - * particular file as subject to the "Classpath" exception as provided
  270.12 - * by Oracle in the LICENSE file that accompanied this code.
  270.13 - *
  270.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  270.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  270.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  270.17 - * version 2 for more details (a copy is included in the LICENSE file that
  270.18 - * accompanied this code).
  270.19 - *
  270.20 - * You should have received a copy of the GNU General Public License version
  270.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  270.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  270.23 - *
  270.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  270.25 - * or visit www.oracle.com if you need additional information or have any
  270.26 - * questions.
  270.27 - */
  270.28 -
  270.29 -package java.util;
  270.30 -
  270.31 -/**
  270.32 - * Thrown by the <code>nextElement</code> method of an
  270.33 - * <code>Enumeration</code> to indicate that there are no more
  270.34 - * elements in the enumeration.
  270.35 - *
  270.36 - * @author  unascribed
  270.37 - * @see     java.util.Enumeration
  270.38 - * @see     java.util.Enumeration#nextElement()
  270.39 - * @since   JDK1.0
  270.40 - */
  270.41 -public
  270.42 -class NoSuchElementException extends RuntimeException {
  270.43 -    private static final long serialVersionUID = 6769829250639411880L;
  270.44 -
  270.45 -    /**
  270.46 -     * Constructs a <code>NoSuchElementException</code> with <tt>null</tt>
  270.47 -     * as its error message string.
  270.48 -     */
  270.49 -    public NoSuchElementException() {
  270.50 -        super();
  270.51 -    }
  270.52 -
  270.53 -    /**
  270.54 -     * Constructs a <code>NoSuchElementException</code>, saving a reference
  270.55 -     * to the error message string <tt>s</tt> for later retrieval by the
  270.56 -     * <tt>getMessage</tt> method.
  270.57 -     *
  270.58 -     * @param   s   the detail message.
  270.59 -     */
  270.60 -    public NoSuchElementException(String s) {
  270.61 -        super(s);
  270.62 -    }
  270.63 -}
   271.1 --- a/emul/src/main/java/org/apidesign/bck2brwsr/emul/AnnotationImpl.java	Wed Dec 05 10:03:58 2012 +0100
   271.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   271.3 @@ -1,68 +0,0 @@
   271.4 -/*
   271.5 - * To change this template, choose Tools | Templates
   271.6 - * and open the template in the editor.
   271.7 - */
   271.8 -package org.apidesign.bck2brwsr.emul;
   271.9 -
  271.10 -import java.lang.annotation.Annotation;
  271.11 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  271.12 -
  271.13 -/**
  271.14 - *
  271.15 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  271.16 - */
  271.17 -public final class AnnotationImpl implements Annotation {
  271.18 -    public Class<? extends Annotation> annotationType() {
  271.19 -        return getClass();
  271.20 -    }
  271.21 -
  271.22 -    @JavaScriptBody(args = { "a", "n", "values" }, body = ""
  271.23 -        + "function f(v, p) {\n"
  271.24 -        + "  var val = v;\n"
  271.25 -        + "  var prop = p;\n"
  271.26 -        + "  return function() {\n"
  271.27 -        + "    return val[prop];\n"
  271.28 -        + "  };\n"
  271.29 -        + "}\n"
  271.30 -        + "var props = Object.getOwnPropertyNames(values);\n"
  271.31 -        + "for (var i = 0; i < props.length; i++) {\n"
  271.32 -        + "  var p = props[i];\n"
  271.33 -        + "  a[p] = new f(values, p);\n"
  271.34 -        + "}\n"
  271.35 -        + "a['$instOf_' + n] = true;\n"
  271.36 -        + "return a;"
  271.37 -    )
  271.38 -    private static <T extends Annotation> T create(AnnotationImpl a, String n, Object values) {
  271.39 -        return null;
  271.40 -    }
  271.41 -    public static <T extends Annotation> T create(Class<T> annoClass, Object values) {
  271.42 -        return create(new AnnotationImpl(), annoClass.getName().replace('.', '_'), values);
  271.43 -    }
  271.44 -
  271.45 -    public static Annotation[] create(Object anno) {
  271.46 -        String[] names = findNames(anno);
  271.47 -        Annotation[] ret = new Annotation[names.length];
  271.48 -        for (int i = 0; i < names.length; i++) {
  271.49 -            String n = names[i].substring(1, names[i].length() - 1).replace('/', '_');
  271.50 -            ret[i] = create(new AnnotationImpl(), n, findData(anno, names[i]));
  271.51 -        }
  271.52 -        return ret;
  271.53 -    }
  271.54 -    @JavaScriptBody(args = "anno", body =
  271.55 -          "var arr = new Array();"
  271.56 -        + "var props = Object.getOwnPropertyNames(anno);\n"
  271.57 -        + "for (var i = 0; i < props.length; i++) {\n"
  271.58 -        + "  var p = props[i];\n"
  271.59 -        + "  arr.push(p);"
  271.60 -        + "}"
  271.61 -        + "return arr;"
  271.62 -    )
  271.63 -    private static String[] findNames(Object anno) {
  271.64 -        throw new UnsupportedOperationException();
  271.65 -    }
  271.66 -
  271.67 -    @JavaScriptBody(args={ "anno", "p"}, body="return anno[p];")
  271.68 -    private static Object findData(Object anno, String p) {
  271.69 -        throw new UnsupportedOperationException();
  271.70 -    }
  271.71 -}
   272.1 --- a/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js	Wed Dec 05 10:03:58 2012 +0100
   272.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   272.3 @@ -1,2 +0,0 @@
   272.4 -// initialize methods on String constants
   272.5 -java_lang_String(false);
   273.1 --- a/javap/pom.xml	Wed Dec 05 10:03:58 2012 +0100
   273.2 +++ b/javap/pom.xml	Sun Feb 03 07:48:42 2013 +0100
   273.3 @@ -34,7 +34,7 @@
   273.4    <dependencies>
   273.5      <dependency>
   273.6        <groupId>org.apidesign.bck2brwsr</groupId>
   273.7 -      <artifactId>emul</artifactId>
   273.8 +      <artifactId>emul.mini</artifactId>
   273.9        <version>0.3-SNAPSHOT</version>
  273.10      </dependency>
  273.11    </dependencies>
   274.1 --- a/javap/src/main/java/org/apidesign/javap/ClassData.java	Wed Dec 05 10:03:58 2012 +0100
   274.2 +++ b/javap/src/main/java/org/apidesign/javap/ClassData.java	Sun Feb 03 07:48:42 2013 +0100
   274.3 @@ -326,6 +326,10 @@
   274.4              return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
   274.5          }
   274.6      }
   274.7 +    
   274.8 +    public int getAccessFlags() {
   274.9 +        return access;
  274.10 +    }
  274.11  
  274.12      /**
  274.13       * Returns true if it is a class
  274.14 @@ -554,14 +558,14 @@
  274.15              return in.toString();
  274.16          }
  274.17          case CONSTANT_CLASS:
  274.18 -            String jn = javaName(getClassName(cpx));
  274.19 +            String jn = getClassName(cpx);
  274.20              if (textual) {
  274.21                  if (refs != null) {
  274.22                      refs[0] = jn;
  274.23                  }
  274.24 -                return jn.replace('/', '_') + "(false).constructor.$class";
  274.25 +                return jn;
  274.26              }
  274.27 -            return jn;
  274.28 +            return javaName(jn);
  274.29          case CONSTANT_STRING:
  274.30              String sv = stringValue(((CPX)x).cpx, textual);
  274.31              if (textual) {
   275.1 --- a/javap/src/main/java/org/apidesign/javap/Hashtable.java	Wed Dec 05 10:03:58 2012 +0100
   275.2 +++ b/javap/src/main/java/org/apidesign/javap/Hashtable.java	Sun Feb 03 07:48:42 2013 +0100
   275.3 @@ -1,6 +1,19 @@
   275.4 -/*
   275.5 - * To change this template, choose Tools | Templates
   275.6 - * and open the template in the editor.
   275.7 +/**
   275.8 + * Back 2 Browser Bytecode Translator
   275.9 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
  275.10 + *
  275.11 + * This program is free software: you can redistribute it and/or modify
  275.12 + * it under the terms of the GNU General Public License as published by
  275.13 + * the Free Software Foundation, version 2 of the License.
  275.14 + *
  275.15 + * This program is distributed in the hope that it will be useful,
  275.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  275.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  275.18 + * GNU General Public License for more details.
  275.19 + *
  275.20 + * You should have received a copy of the GNU General Public License
  275.21 + * along with this program. Look for COPYING file in the top folder.
  275.22 + * If not, see http://opensource.org/licenses/GPL-2.0.
  275.23   */
  275.24  package org.apidesign.javap;
  275.25  
   276.1 --- a/javap/src/main/java/org/apidesign/javap/MethodData.java	Wed Dec 05 10:03:58 2012 +0100
   276.2 +++ b/javap/src/main/java/org/apidesign/javap/MethodData.java	Sun Feb 03 07:48:42 2013 +0100
   276.3 @@ -25,9 +25,9 @@
   276.4  
   276.5  package org.apidesign.javap;
   276.6  
   276.7 -import java.io.*;
   276.8 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
   276.9  
  276.10 +import java.io.DataInputStream;
  276.11 +import java.io.IOException;
  276.12  import static org.apidesign.javap.RuntimeConstants.*;
  276.13  
  276.14  /**
  276.15 @@ -235,22 +235,8 @@
  276.16      /**
  276.17       * Return access of the method.
  276.18       */
  276.19 -    public String[] getAccess(){
  276.20 -
  276.21 -        Vector v = new Vector();
  276.22 -        if ((access & ACC_PUBLIC)   !=0) v.addElement("public");
  276.23 -        if ((access & ACC_PRIVATE)   !=0) v.addElement("private");
  276.24 -        if ((access & ACC_PROTECTED)   !=0) v.addElement("protected");
  276.25 -        if ((access & ACC_STATIC)   !=0) v.addElement("static");
  276.26 -        if ((access & ACC_FINAL)    !=0) v.addElement("final");
  276.27 -        if ((access & ACC_SYNCHRONIZED) !=0) v.addElement("synchronized");
  276.28 -        if ((access & ACC_NATIVE) !=0) v.addElement("native");
  276.29 -        if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
  276.30 -        if ((access & ACC_STRICT) !=0) v.addElement("strictfp");
  276.31 -
  276.32 -        String[] accflags = new String[v.size()];
  276.33 -        v.copyInto(accflags);
  276.34 -        return accflags;
  276.35 +    public int getAccess(){
  276.36 +        return access;
  276.37      }
  276.38  
  276.39      /**
  276.40 @@ -317,6 +303,10 @@
  276.41          return stackMapTable;
  276.42      }
  276.43  
  276.44 +    public StackMapIterator createStackMapIterator() {
  276.45 +        return new StackMapIterator(this);
  276.46 +    }
  276.47 +
  276.48      /**
  276.49       * Return true if method is static
  276.50       */
  276.51 @@ -353,10 +343,10 @@
  276.52      /**
  276.53       * Return exception table in code attributre.
  276.54       */
  276.55 -    public Vector getexception_table(){
  276.56 -        return exception_table;
  276.57 +    public TrapDataIterator getTrapDataIterator(){
  276.58 +        return new TrapDataIterator(exception_table);
  276.59      }
  276.60 -
  276.61 +    
  276.62  
  276.63      /**
  276.64       * Return method attributes.
  276.65 @@ -397,4 +387,8 @@
  276.66          attrs.copyInto(arr);
  276.67          return ClassData.findAttr(n, arr);
  276.68      }
  276.69 +
  276.70 +    public boolean isConstructor() {
  276.71 +        return "<init>".equals(getName());
  276.72 +    }
  276.73  }
   277.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   277.2 +++ b/javap/src/main/java/org/apidesign/javap/StackMapIterator.java	Sun Feb 03 07:48:42 2013 +0100
   277.3 @@ -0,0 +1,179 @@
   277.4 +/*
   277.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   277.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   277.7 + *
   277.8 + * This code is free software; you can redistribute it and/or modify it
   277.9 + * under the terms of the GNU General Public License version 2 only, as
  277.10 + * published by the Free Software Foundation.  Oracle designates this
  277.11 + * particular file as subject to the "Classpath" exception as provided
  277.12 + * by Oracle in the LICENSE file that accompanied this code.
  277.13 + *
  277.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  277.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  277.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  277.17 + * version 2 for more details (a copy is included in the LICENSE file that
  277.18 + * accompanied this code).
  277.19 + *
  277.20 + * You should have received a copy of the GNU General Public License version
  277.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  277.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  277.23 + *
  277.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  277.25 + * or visit www.oracle.com if you need additional information or have any
  277.26 + * questions.
  277.27 + */
  277.28 +
  277.29 +package org.apidesign.javap;
  277.30 +
  277.31 +import static org.apidesign.javap.RuntimeConstants.ITEM_Integer;
  277.32 +import static org.apidesign.javap.RuntimeConstants.ITEM_Float;
  277.33 +import static org.apidesign.javap.RuntimeConstants.ITEM_Double;
  277.34 +import static org.apidesign.javap.RuntimeConstants.ITEM_Long;
  277.35 +import static org.apidesign.javap.RuntimeConstants.ITEM_Object;
  277.36 +
  277.37 +public final class StackMapIterator {
  277.38 +    private final StackMapTableData[] stackMapTable;
  277.39 +    private final TypeArray argTypes;
  277.40 +    private final TypeArray localTypes;
  277.41 +    private final TypeArray stackTypes;
  277.42 +
  277.43 +    private int nextFrameIndex;
  277.44 +    private int lastFrameByteCodeOffset;
  277.45 +
  277.46 +    private int byteCodeOffset;
  277.47 +
  277.48 +    StackMapIterator(final MethodData methodData) {
  277.49 +        this(methodData.getStackMapTable(),
  277.50 +             methodData.getInternalSig(),
  277.51 +             methodData.isStatic());
  277.52 +    }
  277.53 +
  277.54 +    StackMapIterator(final StackMapTableData[] stackMapTable,
  277.55 +                     final String methodSignature,
  277.56 +                     final boolean isStaticMethod) {
  277.57 +        this.stackMapTable = (stackMapTable != null)
  277.58 +                                 ? stackMapTable
  277.59 +                                 : new StackMapTableData[0];
  277.60 +
  277.61 +        argTypes = getArgTypes(methodSignature, isStaticMethod);
  277.62 +        localTypes = new TypeArray();
  277.63 +        stackTypes = new TypeArray();
  277.64 +
  277.65 +        localTypes.addAll(argTypes);
  277.66 +
  277.67 +        lastFrameByteCodeOffset = -1;
  277.68 +        advanceBy(0);
  277.69 +    }
  277.70 +
  277.71 +    public String getFrameAsString() {
  277.72 +        return (nextFrameIndex == 0)
  277.73 +                   ? StackMapTableData.toString("INITIAL", 0, null, null)
  277.74 +                   : stackMapTable[nextFrameIndex - 1].toString();
  277.75 +    }
  277.76 +
  277.77 +    public int getFrameIndex() {
  277.78 +        return nextFrameIndex;
  277.79 +    }
  277.80 +
  277.81 +    public TypeArray getFrameStack() {
  277.82 +        return stackTypes;
  277.83 +    }
  277.84 +
  277.85 +    public TypeArray getFrameLocals() {
  277.86 +        return localTypes;
  277.87 +    }
  277.88 +
  277.89 +    public TypeArray getArguments() {
  277.90 +        return argTypes;
  277.91 +    }
  277.92 +
  277.93 +    public void advanceBy(final int numByteCodes) {
  277.94 +        if (numByteCodes < 0) {
  277.95 +            throw new IllegalStateException("Forward only iterator");
  277.96 +        }
  277.97 +
  277.98 +        byteCodeOffset += numByteCodes;
  277.99 +        while ((nextFrameIndex < stackMapTable.length)
 277.100 +                    && ((byteCodeOffset - lastFrameByteCodeOffset)
 277.101 +                            >= (stackMapTable[nextFrameIndex].offsetDelta
 277.102 +                                    + 1))) {
 277.103 +            final StackMapTableData nextFrame = stackMapTable[nextFrameIndex];
 277.104 +
 277.105 +            lastFrameByteCodeOffset += nextFrame.offsetDelta + 1;
 277.106 +            nextFrame.applyTo(localTypes, stackTypes);
 277.107 +
 277.108 +            ++nextFrameIndex;
 277.109 +        }
 277.110 +    }
 277.111 +
 277.112 +    public void advanceTo(final int nextByteCodeOffset) {
 277.113 +        advanceBy(nextByteCodeOffset - byteCodeOffset);
 277.114 +    }
 277.115 +
 277.116 +    private static TypeArray getArgTypes(final String methodSignature,
 277.117 +                                         final boolean isStaticMethod) {
 277.118 +        final TypeArray argTypes = new TypeArray();
 277.119 +
 277.120 +        if (!isStaticMethod) {
 277.121 +            argTypes.add(ITEM_Object);
 277.122 +        }
 277.123 +
 277.124 +        if (methodSignature.charAt(0) != '(') {
 277.125 +            throw new IllegalArgumentException("Invalid method signature");
 277.126 +        }
 277.127 +
 277.128 +        final int length = methodSignature.length();
 277.129 +        boolean skipType = false;
 277.130 +        int argType;
 277.131 +        for (int i = 1; i < length; ++i) {
 277.132 +            switch (methodSignature.charAt(i)) {
 277.133 +                case 'B':
 277.134 +                case 'C':
 277.135 +                case 'S':
 277.136 +                case 'Z':
 277.137 +                case 'I':
 277.138 +                    argType = ITEM_Integer;
 277.139 +                    break;
 277.140 +                case 'J':
 277.141 +                    argType = ITEM_Long;
 277.142 +                    break;
 277.143 +                case 'F':
 277.144 +                    argType = ITEM_Float;
 277.145 +                    break;
 277.146 +                case 'D':
 277.147 +                    argType = ITEM_Double;
 277.148 +                    break;
 277.149 +                case 'L': {
 277.150 +                    i = methodSignature.indexOf(';', i + 1);
 277.151 +                    if (i == -1) {
 277.152 +                        throw new IllegalArgumentException(
 277.153 +                                      "Invalid method signature");
 277.154 +                    }
 277.155 +                    argType = ITEM_Object;
 277.156 +                    break;
 277.157 +                }
 277.158 +                case ')':
 277.159 +                    // not interested in the return value type
 277.160 +                    return argTypes;
 277.161 +                case '[':
 277.162 +                    if (!skipType) {
 277.163 +                        argTypes.add(ITEM_Object);
 277.164 +                        skipType = true;
 277.165 +                    }
 277.166 +                    continue;
 277.167 +
 277.168 +                default:
 277.169 +                    throw new IllegalArgumentException(
 277.170 +                                  "Invalid method signature");
 277.171 +            }
 277.172 +
 277.173 +            if (!skipType) {
 277.174 +                argTypes.add(argType);
 277.175 +            } else {
 277.176 +                skipType = false;
 277.177 +            }
 277.178 +        }
 277.179 +
 277.180 +        return argTypes;
 277.181 +    }
 277.182 +}
   278.1 --- a/javap/src/main/java/org/apidesign/javap/StackMapTableData.java	Wed Dec 05 10:03:58 2012 +0100
   278.2 +++ b/javap/src/main/java/org/apidesign/javap/StackMapTableData.java	Sun Feb 03 07:48:42 2013 +0100
   278.3 @@ -32,7 +32,7 @@
   278.4  
   278.5  /* represents one entry of StackMapTable attribute
   278.6   */
   278.7 -class StackMapTableData {
   278.8 +abstract class StackMapTableData {
   278.9      final int frameType;
  278.10      int offsetDelta;
  278.11  
  278.12 @@ -40,11 +40,59 @@
  278.13          this.frameType = frameType;
  278.14      }
  278.15  
  278.16 +    abstract void applyTo(TypeArray localTypes, TypeArray stackTypes);
  278.17 +
  278.18 +    protected static String toString(
  278.19 +            final String frameType,
  278.20 +            final int offset,
  278.21 +            final int[] localTypes,
  278.22 +            final int[] stackTypes) {
  278.23 +        final StringBuilder sb = new StringBuilder(frameType);
  278.24 +
  278.25 +        sb.append("(off: +").append(offset);
  278.26 +        if (localTypes != null) {
  278.27 +            sb.append(", locals: ");
  278.28 +            appendTypes(sb, localTypes);
  278.29 +        }
  278.30 +        if (stackTypes != null) {
  278.31 +            sb.append(", stack: ");
  278.32 +            appendTypes(sb, stackTypes);
  278.33 +        }
  278.34 +        sb.append(')');
  278.35 +
  278.36 +        return sb.toString();
  278.37 +    }
  278.38 +
  278.39 +    private static void appendTypes(final StringBuilder sb, final int[] types) {
  278.40 +        sb.append('[');
  278.41 +        if (types.length > 0) {
  278.42 +            sb.append(TypeArray.typeString(types[0]));
  278.43 +            for (int i = 1; i < types.length; ++i) {
  278.44 +                sb.append(", ");
  278.45 +                sb.append(TypeArray.typeString(types[i]));
  278.46 +            }
  278.47 +        }
  278.48 +        sb.append(']');
  278.49 +    }
  278.50 +
  278.51      static class SameFrame extends StackMapTableData {
  278.52          SameFrame(int frameType, int offsetDelta) {
  278.53              super(frameType);
  278.54              this.offsetDelta = offsetDelta;
  278.55          }
  278.56 +
  278.57 +        @Override
  278.58 +        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
  278.59 +            stackTypes.clear();
  278.60 +        }
  278.61 +
  278.62 +        @Override
  278.63 +        public String toString() {
  278.64 +            return toString("SAME" + ((frameType == SAME_FRAME_EXTENDED)
  278.65 +                                          ? "_FRAME_EXTENDED" : ""),
  278.66 +                            offsetDelta,
  278.67 +                            null, null);
  278.68 +        }
  278.69      }
  278.70  
  278.71      static class SameLocals1StackItem extends StackMapTableData {
  278.72 @@ -54,6 +102,21 @@
  278.73              this.offsetDelta = offsetDelta;
  278.74              this.stack = stack;
  278.75          }
  278.76 +
  278.77 +        @Override
  278.78 +        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
  278.79 +            stackTypes.setAll(stack);
  278.80 +        }
  278.81 +
  278.82 +        @Override
  278.83 +        public String toString() {
  278.84 +            return toString(
  278.85 +                       "SAME_LOCALS_1_STACK_ITEM"
  278.86 +                           + ((frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED)
  278.87 +                                  ? "_EXTENDED" : ""),
  278.88 +                       offsetDelta,
  278.89 +                       null, stack);
  278.90 +        }
  278.91      }
  278.92  
  278.93      static class ChopFrame extends StackMapTableData {
  278.94 @@ -61,6 +124,18 @@
  278.95              super(frameType);
  278.96              this.offsetDelta = offsetDelta;
  278.97          }
  278.98 +
  278.99 +        @Override
 278.100 +        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
 278.101 +            localTypes.setSize(localTypes.getSize()
 278.102 +                                   - (SAME_FRAME_EXTENDED - frameType));
 278.103 +            stackTypes.clear();
 278.104 +        }
 278.105 +
 278.106 +        @Override
 278.107 +        public String toString() {
 278.108 +            return toString("CHOP", offsetDelta, null, null);
 278.109 +        }
 278.110      }
 278.111  
 278.112      static class AppendFrame extends StackMapTableData {
 278.113 @@ -70,6 +145,17 @@
 278.114              this.offsetDelta = offsetDelta;
 278.115              this.locals = locals;
 278.116          }
 278.117 +
 278.118 +        @Override
 278.119 +        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
 278.120 +            localTypes.addAll(locals);
 278.121 +            stackTypes.clear();
 278.122 +        }
 278.123 +
 278.124 +        @Override
 278.125 +        public String toString() {
 278.126 +            return toString("APPEND", offsetDelta, locals, null);
 278.127 +        }
 278.128      }
 278.129  
 278.130      static class FullFrame extends StackMapTableData {
 278.131 @@ -81,6 +167,17 @@
 278.132              this.locals = locals;
 278.133              this.stack = stack;
 278.134          }
 278.135 +
 278.136 +        @Override
 278.137 +        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
 278.138 +            localTypes.setAll(locals);
 278.139 +            stackTypes.setAll(stack);
 278.140 +        }
 278.141 +
 278.142 +        @Override
 278.143 +        public String toString() {
 278.144 +            return toString("FULL", offsetDelta, locals, stack);
 278.145 +        }
 278.146      }
 278.147  
 278.148      static StackMapTableData getInstance(DataInputStream in, MethodData method)
   279.1 --- a/javap/src/main/java/org/apidesign/javap/TrapData.java	Wed Dec 05 10:03:58 2012 +0100
   279.2 +++ b/javap/src/main/java/org/apidesign/javap/TrapData.java	Sun Feb 03 07:48:42 2013 +0100
   279.3 @@ -26,7 +26,6 @@
   279.4  
   279.5  package org.apidesign.javap;
   279.6  
   279.7 -import java.util.*;
   279.8  import java.io.*;
   279.9  
  279.10  /**
  279.11 @@ -34,15 +33,18 @@
  279.12   *
  279.13   * @author  Sucheta Dambalkar (Adopted code from jdis)
  279.14   */
  279.15 -class TrapData {
  279.16 -    short start_pc, end_pc, handler_pc, catch_cpx;
  279.17 -  int num;
  279.18 +public final class TrapData {
  279.19 +  public final short start_pc;
  279.20 +  public final short end_pc;
  279.21 +  public final short handler_pc;
  279.22 +  public final short catch_cpx;
  279.23 +  final int num;
  279.24  
  279.25  
  279.26      /**
  279.27       * Read and store exception table data in code attribute.
  279.28       */
  279.29 -    public TrapData(DataInputStream in, int num) throws IOException {
  279.30 +    TrapData(DataInputStream in, int num) throws IOException {
  279.31          this.num=num;
  279.32          start_pc = in.readShort();
  279.33          end_pc=in.readShort();
   280.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   280.2 +++ b/javap/src/main/java/org/apidesign/javap/TrapDataIterator.java	Sun Feb 03 07:48:42 2013 +0100
   280.3 @@ -0,0 +1,114 @@
   280.4 +/**
   280.5 + * Back 2 Browser Bytecode Translator
   280.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   280.7 + *
   280.8 + * This program is free software: you can redistribute it and/or modify
   280.9 + * it under the terms of the GNU General Public License as published by
  280.10 + * the Free Software Foundation, version 2 of the License.
  280.11 + *
  280.12 + * This program is distributed in the hope that it will be useful,
  280.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  280.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  280.15 + * GNU General Public License for more details.
  280.16 + *
  280.17 + * You should have received a copy of the GNU General Public License
  280.18 + * along with this program. Look for COPYING file in the top folder.
  280.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  280.20 + */
  280.21 +package org.apidesign.javap;
  280.22 +
  280.23 +/**
  280.24 + *
  280.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  280.26 + */
  280.27 +public final class TrapDataIterator {
  280.28 +    private final Hashtable exStart = new Hashtable();
  280.29 +    private final Hashtable exStop = new Hashtable();
  280.30 +    private TrapData[] current = new TrapData[10];
  280.31 +    private int currentCount;
  280.32 +    
  280.33 +    TrapDataIterator(Vector exceptionTable) {
  280.34 +        for (int i=0 ; i < exceptionTable.size(); i++) {
  280.35 +            final TrapData td = (TrapData)exceptionTable.elementAt(i);
  280.36 +            put(exStart, td.start_pc, td);
  280.37 +            put(exStop, td.end_pc, td);
  280.38 +        }
  280.39 +    }
  280.40 +    
  280.41 +    private static void put(Hashtable h, short key, TrapData td) {
  280.42 +        Short s = Short.valueOf((short)key);
  280.43 +        Vector v = (Vector) h.get(s);
  280.44 +        if (v == null) {
  280.45 +            v = new Vector(1);
  280.46 +            h.put(s, v);
  280.47 +        }
  280.48 +        v.add(td);
  280.49 +    }
  280.50 +    
  280.51 +    private boolean processAll(Hashtable h, Short key, boolean add) {
  280.52 +        boolean change = false;
  280.53 +        Vector v = (Vector)h.get(key);
  280.54 +        if (v != null) {
  280.55 +            int s = v.size();
  280.56 +            for (int i = 0; i < s; i++) {
  280.57 +                TrapData td = (TrapData)v.elementAt(i);
  280.58 +                if (add) {
  280.59 +                    add(td);
  280.60 +                    change = true;
  280.61 +                } else {
  280.62 +                    remove(td);
  280.63 +                    change = true;
  280.64 +                }
  280.65 +            }
  280.66 +        }
  280.67 +        return change;
  280.68 +    }
  280.69 +    
  280.70 +    public boolean advanceTo(int i) {
  280.71 +        Short s = Short.valueOf((short)i);
  280.72 +        boolean ch1 = processAll(exStart, s, true);
  280.73 +        boolean ch2 = processAll(exStop, s, false);
  280.74 +        return ch1 || ch2;
  280.75 +    }
  280.76 +
  280.77 +    public boolean useTry() {
  280.78 +        return currentCount > 0;
  280.79 +    }
  280.80 +
  280.81 +    public TrapData[] current() {
  280.82 +        TrapData[] copy = new TrapData[currentCount];
  280.83 +        for (int i = 0; i < currentCount; i++) {
  280.84 +            copy[i] = current[i];
  280.85 +        }
  280.86 +        return copy;
  280.87 +    }
  280.88 +
  280.89 +    private void add(TrapData e) {
  280.90 +        if (currentCount == current.length) {
  280.91 +            TrapData[] data = new TrapData[currentCount * 2];
  280.92 +            for (int i = 0; i < currentCount; i++) {
  280.93 +                data[i] = current[i];
  280.94 +            }
  280.95 +            current = data;
  280.96 +        }
  280.97 +        current[currentCount++] = e;
  280.98 +    }
  280.99 +
 280.100 +    private void remove(TrapData e) {
 280.101 +        if (currentCount == 0) {
 280.102 +            return;
 280.103 +        }
 280.104 +        int from = 0;
 280.105 +        while (from < currentCount) {
 280.106 +            if (e == current[from++]) {
 280.107 +                break;
 280.108 +            }
 280.109 +        }
 280.110 +        while (from < currentCount) {
 280.111 +            current[from - 1] = current[from];
 280.112 +            current[from] = null;
 280.113 +            from++;
 280.114 +        }
 280.115 +        currentCount--;
 280.116 +    }
 280.117 +}
   281.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   281.2 +++ b/javap/src/main/java/org/apidesign/javap/TypeArray.java	Sun Feb 03 07:48:42 2013 +0100
   281.3 @@ -0,0 +1,186 @@
   281.4 +/*
   281.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   281.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   281.7 + *
   281.8 + * This code is free software; you can redistribute it and/or modify it
   281.9 + * under the terms of the GNU General Public License version 2 only, as
  281.10 + * published by the Free Software Foundation.  Oracle designates this
  281.11 + * particular file as subject to the "Classpath" exception as provided
  281.12 + * by Oracle in the LICENSE file that accompanied this code.
  281.13 + *
  281.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  281.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  281.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  281.17 + * version 2 for more details (a copy is included in the LICENSE file that
  281.18 + * accompanied this code).
  281.19 + *
  281.20 + * You should have received a copy of the GNU General Public License version
  281.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  281.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  281.23 + *
  281.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  281.25 + * or visit www.oracle.com if you need additional information or have any
  281.26 + * questions.
  281.27 + */
  281.28 +
  281.29 +package org.apidesign.javap;
  281.30 +
  281.31 +import static org.apidesign.javap.RuntimeConstants.ITEM_Bogus;
  281.32 +import static org.apidesign.javap.RuntimeConstants.ITEM_Integer;
  281.33 +import static org.apidesign.javap.RuntimeConstants.ITEM_Float;
  281.34 +import static org.apidesign.javap.RuntimeConstants.ITEM_Double;
  281.35 +import static org.apidesign.javap.RuntimeConstants.ITEM_Long;
  281.36 +import static org.apidesign.javap.RuntimeConstants.ITEM_Null;
  281.37 +import static org.apidesign.javap.RuntimeConstants.ITEM_InitObject;
  281.38 +import static org.apidesign.javap.RuntimeConstants.ITEM_Object;
  281.39 +import static org.apidesign.javap.RuntimeConstants.ITEM_NewObject;
  281.40 +
  281.41 +public final class TypeArray {
  281.42 +    private static final int CAPACITY_INCREMENT = 16;
  281.43 +
  281.44 +    private int[] types;
  281.45 +    private int size;
  281.46 +
  281.47 +    public TypeArray() {
  281.48 +    }
  281.49 +    
  281.50 +    public TypeArray(final TypeArray initialTypes) {
  281.51 +        setAll(initialTypes);
  281.52 +    }
  281.53 +
  281.54 +    public void add(final int newType) {
  281.55 +        ensureCapacity(size + 1);
  281.56 +        types[size++] = newType;
  281.57 +    }
  281.58 +
  281.59 +    public void addAll(final TypeArray newTypes) {
  281.60 +        addAll(newTypes.types, 0, newTypes.size);
  281.61 +    }
  281.62 +
  281.63 +    public void addAll(final int[] newTypes) {
  281.64 +        addAll(newTypes, 0, newTypes.length);
  281.65 +    }
  281.66 +
  281.67 +    public void addAll(final int[] newTypes,
  281.68 +                       final int offset,
  281.69 +                       final int count) {
  281.70 +        if (count > 0) {
  281.71 +            ensureCapacity(size + count);
  281.72 +            arraycopy(newTypes, offset, types, size, count);
  281.73 +            size += count;
  281.74 +        }
  281.75 +    }
  281.76 +
  281.77 +    public void set(final int index, final int newType) {
  281.78 +        types[index] = newType;
  281.79 +    }
  281.80 +
  281.81 +    public void setAll(final TypeArray newTypes) {
  281.82 +        setAll(newTypes.types, 0, newTypes.size);
  281.83 +    }
  281.84 +
  281.85 +    public void setAll(final int[] newTypes) {
  281.86 +        setAll(newTypes, 0, newTypes.length);
  281.87 +    }
  281.88 +
  281.89 +    public void setAll(final int[] newTypes,
  281.90 +                       final int offset,
  281.91 +                       final int count) {
  281.92 +        if (count > 0) {
  281.93 +            ensureCapacity(count);
  281.94 +            arraycopy(newTypes, offset, types, 0, count);
  281.95 +            size = count;
  281.96 +        } else {
  281.97 +            clear();
  281.98 +        }
  281.99 +    }
 281.100 +
 281.101 +    public void setSize(final int newSize) {
 281.102 +        if (size != newSize) {
 281.103 +            ensureCapacity(newSize);
 281.104 +
 281.105 +            for (int i = size; i < newSize; ++i) {
 281.106 +                types[i] = 0;
 281.107 +            }
 281.108 +            size = newSize;
 281.109 +        }
 281.110 +    }
 281.111 +
 281.112 +    public void clear() {
 281.113 +        size = 0;
 281.114 +    }
 281.115 +
 281.116 +    public int getSize() {
 281.117 +        return size;
 281.118 +    }
 281.119 +
 281.120 +    public int get(final int index) {
 281.121 +        return types[index];
 281.122 +    }
 281.123 +
 281.124 +    public static String typeString(final int type) {
 281.125 +        switch (type & 0xff) {
 281.126 +            case ITEM_Bogus:
 281.127 +                return "_top_";
 281.128 +            case ITEM_Integer:
 281.129 +                return "_int_";
 281.130 +            case ITEM_Float:
 281.131 +                return "_float_";
 281.132 +            case ITEM_Double:
 281.133 +                return "_double_";
 281.134 +            case ITEM_Long:
 281.135 +                return "_long_";
 281.136 +            case ITEM_Null:
 281.137 +                return "_null_";
 281.138 +            case ITEM_InitObject: // UninitializedThis
 281.139 +                return "_init_";
 281.140 +            case ITEM_Object:
 281.141 +                return "_object_";
 281.142 +            case ITEM_NewObject: // Uninitialized
 281.143 +                return "_new_";
 281.144 +            default:
 281.145 +                throw new IllegalArgumentException("Unknown type");
 281.146 +        }
 281.147 +    }
 281.148 +
 281.149 +    @Override
 281.150 +    public String toString() {
 281.151 +        final StringBuilder sb = new StringBuilder("[");
 281.152 +        if (size > 0) {
 281.153 +            sb.append(typeString(types[0]));
 281.154 +            for (int i = 1; i < size; ++i) {
 281.155 +                sb.append(", ");
 281.156 +                sb.append(typeString(types[i]));
 281.157 +            }
 281.158 +        }
 281.159 +
 281.160 +        return sb.append(']').toString();
 281.161 +    }
 281.162 +
 281.163 +    private void ensureCapacity(final int minCapacity) {
 281.164 +        if ((minCapacity == 0)
 281.165 +                || (types != null) && (minCapacity <= types.length)) {
 281.166 +            return;
 281.167 +        }
 281.168 +
 281.169 +        final int newCapacity =
 281.170 +                ((minCapacity + CAPACITY_INCREMENT - 1) / CAPACITY_INCREMENT)
 281.171 +                    * CAPACITY_INCREMENT;
 281.172 +        final int[] newTypes = new int[newCapacity];
 281.173 +
 281.174 +        if (size > 0) {
 281.175 +            arraycopy(types, 0, newTypes, 0, size);
 281.176 +        }
 281.177 +
 281.178 +        types = newTypes;
 281.179 +    }
 281.180 +
 281.181 +    // no System.arraycopy
 281.182 +    private void arraycopy(final int[] src, final int srcPos,
 281.183 +                           final int[] dest, final int destPos,
 281.184 +                           final int length) {
 281.185 +        for (int i = 0; i < length; ++i) {
 281.186 +            dest[destPos + i] = src[srcPos + i];
 281.187 +        }
 281.188 +    }
 281.189 +}
   282.1 --- a/javap/src/main/java/org/apidesign/javap/Vector.java	Wed Dec 05 10:03:58 2012 +0100
   282.2 +++ b/javap/src/main/java/org/apidesign/javap/Vector.java	Sun Feb 03 07:48:42 2013 +0100
   282.3 @@ -1,13 +1,30 @@
   282.4 -/*
   282.5 - * To change this template, choose Tools | Templates
   282.6 - * and open the template in the editor.
   282.7 +/**
   282.8 + * Back 2 Browser Bytecode Translator
   282.9 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
  282.10 + *
  282.11 + * This program is free software: you can redistribute it and/or modify
  282.12 + * it under the terms of the GNU General Public License as published by
  282.13 + * the Free Software Foundation, version 2 of the License.
  282.14 + *
  282.15 + * This program is distributed in the hope that it will be useful,
  282.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  282.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  282.18 + * GNU General Public License for more details.
  282.19 + *
  282.20 + * You should have received a copy of the GNU General Public License
  282.21 + * along with this program. Look for COPYING file in the top folder.
  282.22 + * If not, see http://opensource.org/licenses/GPL-2.0.
  282.23   */
  282.24  package org.apidesign.javap;
  282.25  
  282.26 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  282.27 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  282.28 +
  282.29  /** A JavaScript ready replacement for java.util.Vector
  282.30   *
  282.31   * @author Jaroslav Tulach <jtulach@netbeans.org>
  282.32   */
  282.33 +@JavaScriptPrototype(prototype = "new Array" )
  282.34  final class Vector {
  282.35      private Object[] arr;
  282.36      
  282.37 @@ -15,22 +32,31 @@
  282.38      }
  282.39  
  282.40      Vector(int i) {
  282.41 -        this();
  282.42      }
  282.43  
  282.44      void add(Object objectType) {
  282.45          addElement(objectType);
  282.46      }
  282.47 +    @JavaScriptBody(args = { "obj" }, body = 
  282.48 +        "this.push(obj);"
  282.49 +    )
  282.50      void addElement(Object obj) {
  282.51          final int s = size();
  282.52          setSize(s + 1);
  282.53          setElementAt(obj, s);
  282.54      }
  282.55  
  282.56 +    @JavaScriptBody(args = { }, body = 
  282.57 +        "return this.length;"
  282.58 +    )
  282.59      int size() {
  282.60          return arr == null ? 0 : arr.length;
  282.61      }
  282.62  
  282.63 +    @JavaScriptBody(args = { "newArr" }, body =
  282.64 +        "for (var i = 0; i < this.length; i++) {\n"
  282.65 +      + "  newArr[i] = this[i];\n"
  282.66 +      + "}\n")
  282.67      void copyInto(Object[] newArr) {
  282.68          if (arr == null) {
  282.69              return;
  282.70 @@ -41,16 +67,22 @@
  282.71          }
  282.72      }
  282.73  
  282.74 +    @JavaScriptBody(args = { "index" }, body =
  282.75 +        "return this[index];"
  282.76 +    )
  282.77      Object elementAt(int index) {
  282.78          return arr[index];
  282.79      }
  282.80  
  282.81 -    void setSize(int len) {
  282.82 +    private void setSize(int len) {
  282.83          Object[] newArr = new Object[len];
  282.84          copyInto(newArr);
  282.85          arr = newArr;
  282.86      }
  282.87  
  282.88 +    @JavaScriptBody(args = { "val", "index" }, body = 
  282.89 +        "this[index] = val;"
  282.90 +    )
  282.91      void setElementAt(Object val, int index) {
  282.92          arr[index] = val;
  282.93      }
   283.1 --- a/javaquery/api/pom.xml	Wed Dec 05 10:03:58 2012 +0100
   283.2 +++ b/javaquery/api/pom.xml	Sun Feb 03 07:48:42 2013 +0100
   283.3 @@ -52,7 +52,7 @@
   283.4      </dependency>
   283.5      <dependency>
   283.6        <groupId>org.apidesign.bck2brwsr</groupId>
   283.7 -      <artifactId>emul</artifactId>
   283.8 +      <artifactId>emul.mini</artifactId>
   283.9        <version>0.3-SNAPSHOT</version>
  283.10        <type>jar</type>
  283.11        <scope>runtime</scope>
  283.12 @@ -64,5 +64,11 @@
  283.13        <type>jar</type>
  283.14        <scope>test</scope>
  283.15      </dependency>
  283.16 +    <dependency>
  283.17 +      <groupId>${project.groupId}</groupId>
  283.18 +      <artifactId>vmtest</artifactId>
  283.19 +      <version>${project.version}</version>
  283.20 +      <scope>test</scope>
  283.21 +    </dependency>
  283.22    </dependencies>
  283.23  </project>
   284.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   284.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/Knockout.java	Sun Feb 03 07:48:42 2013 +0100
   284.3 @@ -0,0 +1,93 @@
   284.4 +/**
   284.5 + * Back 2 Browser Bytecode Translator
   284.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   284.7 + *
   284.8 + * This program is free software: you can redistribute it and/or modify
   284.9 + * it under the terms of the GNU General Public License as published by
  284.10 + * the Free Software Foundation, version 2 of the License.
  284.11 + *
  284.12 + * This program is distributed in the hope that it will be useful,
  284.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  284.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  284.15 + * GNU General Public License for more details.
  284.16 + *
  284.17 + * You should have received a copy of the GNU General Public License
  284.18 + * along with this program. Look for COPYING file in the top folder.
  284.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  284.20 + */
  284.21 +package org.apidesign.bck2brwsr.htmlpage;
  284.22 +
  284.23 +import java.lang.reflect.Method;
  284.24 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
  284.25 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  284.26 +
  284.27 +/** Provides binding between models and 
  284.28 + *
  284.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  284.30 + */
  284.31 +@ExtraJavaScript(resource = "/org/apidesign/bck2brwsr/htmlpage/knockout-2.2.1.js")
  284.32 +public class Knockout {
  284.33 +    /** used by tests */
  284.34 +    static Knockout next;
  284.35 +    
  284.36 +    Knockout() {
  284.37 +    }
  284.38 +    
  284.39 +    public static <M> Knockout applyBindings(
  284.40 +        Class<M> modelClass, M model, String[] propsGettersAndSetters
  284.41 +    ) {
  284.42 +        Knockout bindings = next;
  284.43 +        next = null;
  284.44 +        if (bindings == null) {
  284.45 +            bindings = new Knockout();
  284.46 +        }
  284.47 +        for (int i = 0; i < propsGettersAndSetters.length; i += 4) {
  284.48 +            try {
  284.49 +                Method getter = modelClass.getMethod(propsGettersAndSetters[i + 3]);
  284.50 +                bind(bindings, model, propsGettersAndSetters[i],
  284.51 +                    propsGettersAndSetters[i + 1],
  284.52 +                    propsGettersAndSetters[i + 2],
  284.53 +                    getter.getReturnType().isPrimitive()
  284.54 +                );
  284.55 +            } catch (NoSuchMethodException ex) {
  284.56 +                throw new IllegalStateException(ex.getMessage());
  284.57 +            }
  284.58 +        }
  284.59 +        applyBindings(bindings);
  284.60 +        return bindings;
  284.61 +    }
  284.62 +
  284.63 +    @JavaScriptBody(args = { "prop" }, body =
  284.64 +        "this[prop].valueHasMutated();"
  284.65 +    )
  284.66 +    public void valueHasMutated(String prop) {
  284.67 +    }
  284.68 +    
  284.69 +
  284.70 +    @JavaScriptBody(args = { "id", "ev" }, body = "ko.utils.triggerEvent(window.document.getElementById(id), ev.substring(2));")
  284.71 +    public static void triggerEvent(String id, String ev) {
  284.72 +    }
  284.73 +    
  284.74 +    @JavaScriptBody(args = { "bindings", "model", "prop", "getter", "setter", "primitive" }, body =
  284.75 +          "var bnd = {\n"
  284.76 +        + "  read: function() {\n"
  284.77 +        + "    var v = model[getter]();\n"
  284.78 +        + "    return v;\n"
  284.79 +        + "  },\n"
  284.80 +        + "  owner: bindings\n"
  284.81 +        + "};\n"
  284.82 +        + "if (setter != null) {\n"
  284.83 +        + "  bnd.write = function(val) {\n"
  284.84 +        + "    model[setter](primitive ? new Number(val) : val);\n"
  284.85 +        + "  };\n"
  284.86 +        + "}\n"
  284.87 +        + "bindings[prop] = ko.computed(bnd);"
  284.88 +    )
  284.89 +    private static void bind(
  284.90 +        Object bindings, Object model, String prop, String getter, String setter, boolean primitive
  284.91 +    ) {
  284.92 +    }
  284.93 +    
  284.94 +    @JavaScriptBody(args = { "bindings" }, body = "ko.applyBindings(bindings);")
  284.95 +    private static void applyBindings(Object bindings) {}
  284.96 +}
   285.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java	Wed Dec 05 10:03:58 2012 +0100
   285.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java	Sun Feb 03 07:48:42 2013 +0100
   285.3 @@ -22,9 +22,13 @@
   285.4  import java.io.OutputStreamWriter;
   285.5  import java.io.Writer;
   285.6  import java.util.ArrayList;
   285.7 +import java.util.Collection;
   285.8  import java.util.Collections;
   285.9 +import java.util.HashMap;
  285.10 +import java.util.LinkedHashSet;
  285.11  import java.util.List;
  285.12  import java.util.Locale;
  285.13 +import java.util.Map;
  285.14  import java.util.Set;
  285.15  import javax.annotation.processing.AbstractProcessor;
  285.16  import javax.annotation.processing.Completion;
  285.17 @@ -39,12 +43,16 @@
  285.18  import javax.lang.model.element.Modifier;
  285.19  import javax.lang.model.element.PackageElement;
  285.20  import javax.lang.model.element.TypeElement;
  285.21 +import javax.lang.model.element.VariableElement;
  285.22 +import javax.lang.model.type.MirroredTypeException;
  285.23  import javax.lang.model.type.TypeMirror;
  285.24  import javax.tools.Diagnostic;
  285.25  import javax.tools.FileObject;
  285.26  import javax.tools.StandardLocation;
  285.27 -import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
  285.28 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
  285.29 +import org.apidesign.bck2brwsr.htmlpage.api.On;
  285.30  import org.apidesign.bck2brwsr.htmlpage.api.Page;
  285.31 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
  285.32  import org.openide.util.lookup.ServiceProvider;
  285.33  
  285.34  /** Annotation processor to process an XHTML page and generate appropriate 
  285.35 @@ -55,13 +63,16 @@
  285.36  @ServiceProvider(service=Processor.class)
  285.37  @SupportedAnnotationTypes({
  285.38      "org.apidesign.bck2brwsr.htmlpage.api.Page",
  285.39 -    "org.apidesign.bck2brwsr.htmlpage.api.OnClick"
  285.40 +    "org.apidesign.bck2brwsr.htmlpage.api.On"
  285.41  })
  285.42  public final class PageProcessor extends AbstractProcessor {
  285.43      @Override
  285.44      public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  285.45          for (Element e : roundEnv.getElementsAnnotatedWith(Page.class)) {
  285.46              Page p = e.getAnnotation(Page.class);
  285.47 +            if (p == null) {
  285.48 +                continue;
  285.49 +            }
  285.50              PackageElement pe = (PackageElement)e.getEnclosingElement();
  285.51              String pkg = pe.getQualifiedName().toString();
  285.52              
  285.53 @@ -86,19 +97,44 @@
  285.54                  try {
  285.55                      w.append("package " + pkg + ";\n");
  285.56                      w.append("import org.apidesign.bck2brwsr.htmlpage.api.*;\n");
  285.57 -                    w.append("class ").append(className).append(" {\n");
  285.58 +                    w.append("final class ").append(className).append(" {\n");
  285.59 +                    w.append("  private boolean locked;\n");
  285.60 +                    if (!initializeOnClick(className, (TypeElement) e, w, pp)) {
  285.61 +                        return false;
  285.62 +                    }
  285.63                      for (String id : pp.ids()) {
  285.64                          String tag = pp.tagNameForId(id);
  285.65                          String type = type(tag);
  285.66 -                        w.append("  ").append("public static final ").
  285.67 +                        w.append("  ").append("public final ").
  285.68                              append(type).append(' ').append(cnstnt(id)).append(" = new ").
  285.69                              append(type).append("(\"").append(id).append("\");\n");
  285.70                      }
  285.71 -                    w.append("  static {\n");
  285.72 -                    if (!initializeOnClick(pe, w, pp)) {
  285.73 -                        return false;
  285.74 +                    List<String> propsGetSet = new ArrayList<String>();
  285.75 +                    Map<String,Collection<String>> propsDeps = new HashMap<String, Collection<String>>();
  285.76 +                    generateComputedProperties(w, e.getEnclosedElements(), propsGetSet, propsDeps);
  285.77 +                    generateProperties(w, p.properties(), propsGetSet, propsDeps);
  285.78 +                    w.append("  private org.apidesign.bck2brwsr.htmlpage.Knockout ko;\n");
  285.79 +                    if (!propsGetSet.isEmpty()) {
  285.80 +                        w.write("public " + className + " applyBindings() {\n");
  285.81 +                        w.write("  ko = org.apidesign.bck2brwsr.htmlpage.Knockout.applyBindings(");
  285.82 +                        w.write(className + ".class, this, ");
  285.83 +                        w.write("new String[] {\n");
  285.84 +                        String sep = "";
  285.85 +                        for (String n : propsGetSet) {
  285.86 +                            w.write(sep);
  285.87 +                            if (n == null) {
  285.88 +                                w.write("    null");
  285.89 +                            } else {
  285.90 +                                w.write("    \"" + n + "\"");
  285.91 +                            }
  285.92 +                            sep = ",\n";
  285.93 +                        }
  285.94 +                        w.write("\n  });\n  return this;\n}\n");
  285.95 +                        
  285.96 +                        w.write("public void triggerEvent(Element e, OnEvent ev) {\n");
  285.97 +                        w.write("  org.apidesign.bck2brwsr.htmlpage.Knockout.triggerEvent(e.getId(), ev.getElementPropertyName());\n");
  285.98 +                        w.write("}\n");
  285.99                      }
 285.100 -                    w.append("  }\n");
 285.101                      w.append("}\n");
 285.102                  } finally {
 285.103                      w.close();
 285.104 @@ -131,59 +167,103 @@
 285.105          if (tag.equals("input")) {
 285.106              return "Input";
 285.107          }
 285.108 +        if (tag.equals("canvas")) {
 285.109 +            return "Canvas";
 285.110 +        }
 285.111 +        if (tag.equals("img")) {
 285.112 +            return "Image";
 285.113 +        }
 285.114          return "Element";
 285.115      }
 285.116  
 285.117      private static String cnstnt(String id) {
 285.118 -        return id.toUpperCase(Locale.ENGLISH).replace('.', '_');
 285.119 +        return id.toUpperCase(Locale.ENGLISH).replace('.', '_').replace('-', '_');
 285.120      }
 285.121  
 285.122 -    private boolean initializeOnClick(PackageElement pe, Writer w, ProcessPage pp) throws IOException {
 285.123 +    private boolean initializeOnClick(
 285.124 +        String className, TypeElement type, Writer w, ProcessPage pp
 285.125 +    ) throws IOException {
 285.126          TypeMirror stringType = processingEnv.getElementUtils().getTypeElement("java.lang.String").asType();
 285.127 -        for (Element clazz : pe.getEnclosedElements()) {
 285.128 -            if (clazz.getKind() != ElementKind.CLASS) {
 285.129 -                continue;
 285.130 -            }
 285.131 -            TypeElement type = (TypeElement)clazz;
 285.132 -            for (Element method : clazz.getEnclosedElements()) {
 285.133 -                OnClick oc = method.getAnnotation(OnClick.class);
 285.134 +        { //for (Element clazz : pe.getEnclosedElements()) {
 285.135 +          //  if (clazz.getKind() != ElementKind.CLASS) {
 285.136 +            //    continue;
 285.137 +           // }
 285.138 +            w.append("  public ").append(className).append("() {\n");
 285.139 +            StringBuilder dispatch = new StringBuilder();
 285.140 +            int dispatchCnt = 0;
 285.141 +            for (Element method : type.getEnclosedElements()) {
 285.142 +                On oc = method.getAnnotation(On.class);
 285.143                  if (oc != null) {
 285.144                      for (String id : oc.id()) {
 285.145                          if (pp.tagNameForId(id) == null) {
 285.146 -                            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "id = " + oc.id() + " does not exist in the HTML page. Found only " + pp.ids(), method);
 285.147 +                            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "id = " + id + " does not exist in the HTML page. Found only " + pp.ids(), method);
 285.148                              return false;
 285.149                          }
 285.150                          ExecutableElement ee = (ExecutableElement)method;
 285.151 -                        boolean hasParam;
 285.152 -                        if (ee.getParameters().isEmpty()) {
 285.153 -                            hasParam = false;
 285.154 -                        } else {
 285.155 -                            if (ee.getParameters().size() != 1 || ee.getParameters().get(0).asType() != stringType) {
 285.156 -                                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClick method should either have no arguments or one String argument", ee);
 285.157 +                        StringBuilder params = new StringBuilder();
 285.158 +                        {
 285.159 +                            boolean first = true;
 285.160 +                            for (VariableElement ve : ee.getParameters()) {
 285.161 +                                if (!first) {
 285.162 +                                    params.append(", ");
 285.163 +                                }
 285.164 +                                first = false;
 285.165 +                                if (ve.asType() == stringType) {
 285.166 +                                    params.append('"').append(id).append('"');
 285.167 +                                    continue;
 285.168 +                                }
 285.169 +                                String rn = ve.asType().toString();
 285.170 +                                int last = rn.lastIndexOf('.');
 285.171 +                                if (last >= 0) {
 285.172 +                                    rn = rn.substring(last + 1);
 285.173 +                                }
 285.174 +                                if (rn.equals(className)) {
 285.175 +                                    params.append(className).append(".this");
 285.176 +                                    continue;
 285.177 +                                }
 285.178 +                                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, 
 285.179 +                                    "@On method can only accept String or " + className + " arguments",
 285.180 +                                    ee
 285.181 +                                );
 285.182                                  return false;
 285.183                              }
 285.184 -                            hasParam = true;
 285.185                          }
 285.186                          if (!ee.getModifiers().contains(Modifier.STATIC)) {
 285.187 -                            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClick method has to be static", ee);
 285.188 +                            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@On method has to be static", ee);
 285.189                              return false;
 285.190                          }
 285.191                          if (ee.getModifiers().contains(Modifier.PRIVATE)) {
 285.192 -                            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClick method can't be private", ee);
 285.193 +                            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@On method can't be private", ee);
 285.194                              return false;
 285.195                          }
 285.196 -                        w.append("  ").append(cnstnt(id)).
 285.197 -                            append(".addOnClick(new Runnable() { public void run() {\n");
 285.198 -                        w.append("    ").append(type.getSimpleName().toString()).
 285.199 -                            append('.').append(ee.getSimpleName()).append("(");
 285.200 -                        if (hasParam) {
 285.201 -                            w.append("\"").append(id).append("\"");
 285.202 -                        }
 285.203 -                        w.append(");\n");
 285.204 -                        w.append("  }});\n");
 285.205 -                    }           
 285.206 +                        w.append("  OnEvent." + oc.event()).append(".of(").append(cnstnt(id)).
 285.207 +                            append(").perform(new OnDispatch(" + dispatchCnt + "));\n");
 285.208 +
 285.209 +                        dispatch.
 285.210 +                            append("      case ").append(dispatchCnt).append(": ").
 285.211 +                            append(type.getSimpleName().toString()).
 285.212 +                            append('.').append(ee.getSimpleName()).append("(").
 285.213 +                            append(params).
 285.214 +                            append("); break;\n");
 285.215 +                        
 285.216 +                        dispatchCnt++;
 285.217 +                    }
 285.218                  }
 285.219              }
 285.220 +            w.append("  }\n");
 285.221 +            if (dispatchCnt > 0) {
 285.222 +                w.append("class OnDispatch implements Runnable {\n");
 285.223 +                w.append("  private final int dispatch;\n");
 285.224 +                w.append("  OnDispatch(int d) { dispatch = d; }\n");
 285.225 +                w.append("  public void run() {\n");
 285.226 +                w.append("    switch (dispatch) {\n");
 285.227 +                w.append(dispatch);
 285.228 +                w.append("    }\n");
 285.229 +                w.append("  }\n");
 285.230 +                w.append("}\n");
 285.231 +            }
 285.232 +            
 285.233 +
 285.234          }
 285.235          return true;
 285.236      }
 285.237 @@ -230,4 +310,126 @@
 285.238          }
 285.239          return e.getEnclosingElement();
 285.240      }
 285.241 +
 285.242 +    private static void generateProperties(
 285.243 +        Writer w, Property[] properties, Collection<String> props,
 285.244 +        Map<String,Collection<String>> deps
 285.245 +    ) throws IOException {
 285.246 +        for (Property p : properties) {
 285.247 +            final String tn = typeName(p);
 285.248 +            String[] gs = toGetSet(p.name(), tn);
 285.249 +
 285.250 +            w.write("private " + tn + " prop_" + p.name() + ";\n");
 285.251 +            w.write("public " + tn + " " + gs[0] + "() {\n");
 285.252 +            w.write("  if (locked) throw new IllegalStateException();\n");
 285.253 +            w.write("  return prop_" + p.name() + ";\n");
 285.254 +            w.write("}\n");
 285.255 +            w.write("public void " + gs[1] + "(" + tn + " v) {\n");
 285.256 +            w.write("  if (locked) throw new IllegalStateException();\n");
 285.257 +            w.write("  prop_" + p.name() + " = v;\n");
 285.258 +            w.write("  if (ko != null) {\n");
 285.259 +            w.write("    ko.valueHasMutated(\"" + p.name() + "\");\n");
 285.260 +            final Collection<String> dependants = deps.get(p.name());
 285.261 +            if (dependants != null) {
 285.262 +                for (String depProp : dependants) {
 285.263 +                    w.write("    ko.valueHasMutated(\"" + depProp + "\");\n");
 285.264 +                }
 285.265 +            }
 285.266 +            w.write("  }\n");
 285.267 +            w.write("}\n");
 285.268 +            
 285.269 +            props.add(p.name());
 285.270 +            props.add(gs[2]);
 285.271 +            props.add(gs[3]);
 285.272 +            props.add(gs[0]);
 285.273 +        }
 285.274 +    }
 285.275 +
 285.276 +    private boolean generateComputedProperties(
 285.277 +        Writer w, Collection<? extends Element> arr, Collection<String> props,
 285.278 +        Map<String,Collection<String>> deps
 285.279 +    ) throws IOException {
 285.280 +        for (Element e : arr) {
 285.281 +            if (e.getKind() != ElementKind.METHOD) {
 285.282 +                continue;
 285.283 +            }
 285.284 +            if (e.getAnnotation(ComputedProperty.class) == null) {
 285.285 +                continue;
 285.286 +            }
 285.287 +            ExecutableElement ee = (ExecutableElement)e;
 285.288 +            final String tn = ee.getReturnType().toString();
 285.289 +            final String sn = ee.getSimpleName().toString();
 285.290 +            String[] gs = toGetSet(sn, tn);
 285.291 +            
 285.292 +            w.write("public " + tn + " " + gs[0] + "() {\n");
 285.293 +            w.write("  if (locked) throw new IllegalStateException();\n");
 285.294 +            int arg = 0;
 285.295 +            for (VariableElement pe : ee.getParameters()) {
 285.296 +                final String dn = pe.getSimpleName().toString();
 285.297 +                final String dt = pe.asType().toString();
 285.298 +                String[] call = toGetSet(dn, dt);
 285.299 +                w.write("  " + dt + " arg" + (++arg) + " = ");
 285.300 +                w.write(call[0] + "();\n");
 285.301 +                
 285.302 +                Collection<String> depends = deps.get(dn);
 285.303 +                if (depends == null) {
 285.304 +                    depends = new LinkedHashSet<String>();
 285.305 +                    deps.put(dn, depends);
 285.306 +                }
 285.307 +                depends.add(sn);
 285.308 +            }
 285.309 +            w.write("  try {\n");
 285.310 +            w.write("    locked = true;\n");
 285.311 +            w.write("    return " + e.getEnclosingElement().getSimpleName() + '.' + e.getSimpleName() + "(");
 285.312 +            String sep = "";
 285.313 +            for (int i = 1; i <= arg; i++) {
 285.314 +                w.write(sep);
 285.315 +                w.write("arg" + i);
 285.316 +                sep = ", ";
 285.317 +            }
 285.318 +            w.write(");\n");
 285.319 +            w.write("  } finally {\n");
 285.320 +            w.write("    locked = false;\n");
 285.321 +            w.write("  }\n");
 285.322 +            w.write("}\n");
 285.323 +            
 285.324 +            props.add(e.getSimpleName().toString());
 285.325 +            props.add(gs[2]);
 285.326 +            props.add(null);
 285.327 +            props.add(gs[0]);
 285.328 +        }
 285.329 +        
 285.330 +        return true;
 285.331 +    }
 285.332 +
 285.333 +    private static String[] toGetSet(String name, String type) {
 285.334 +        String n = Character.toUpperCase(name.charAt(0)) + name.substring(1);
 285.335 +        String bck2brwsrType = "L" + type.replace('.', '_') + "_2";
 285.336 +        if ("int".equals(type)) {
 285.337 +            bck2brwsrType = "I";
 285.338 +        }
 285.339 +        if ("double".equals(type)) {
 285.340 +            bck2brwsrType = "D";
 285.341 +        }
 285.342 +        String pref = "get";
 285.343 +        if ("boolean".equals(type)) {
 285.344 +            pref = "is";
 285.345 +            bck2brwsrType = "Z";
 285.346 +        }
 285.347 +        final String nu = n.replace('.', '_');
 285.348 +        return new String[]{
 285.349 +            pref + n, 
 285.350 +            "set" + n, 
 285.351 +            pref + nu + "__" + bck2brwsrType,
 285.352 +            "set" + nu + "__V" + bck2brwsrType
 285.353 +        };
 285.354 +    }
 285.355 +
 285.356 +    private static String typeName(Property p) {
 285.357 +        try {
 285.358 +            return p.type().getName();
 285.359 +        } catch (MirroredTypeException ex) {
 285.360 +            return ex.getTypeMirror().toString();
 285.361 +        }
 285.362 +    }
 285.363  }
   286.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   286.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java	Sun Feb 03 07:48:42 2013 +0100
   286.3 @@ -0,0 +1,61 @@
   286.4 +/**
   286.5 + * Back 2 Browser Bytecode Translator
   286.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   286.7 + *
   286.8 + * This program is free software: you can redistribute it and/or modify
   286.9 + * it under the terms of the GNU General Public License as published by
  286.10 + * the Free Software Foundation, version 2 of the License.
  286.11 + *
  286.12 + * This program is distributed in the hope that it will be useful,
  286.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  286.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  286.15 + * GNU General Public License for more details.
  286.16 + *
  286.17 + * You should have received a copy of the GNU General Public License
  286.18 + * along with this program. Look for COPYING file in the top folder.
  286.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  286.20 + */
  286.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  286.22 +
  286.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  286.24 +
  286.25 +/**
  286.26 + *
  286.27 + * @author Anton Epple <toni.epple@eppleton.de>
  286.28 + */
  286.29 +public class Canvas extends Element {
  286.30 +
  286.31 +    public Canvas(String id) {
  286.32 +        super(id);
  286.33 +    }
  286.34 +
  286.35 +    public void setHeight(int height) {
  286.36 +        setAttribute(this, "height", height);
  286.37 +    }
  286.38 +
  286.39 +    public int getHeight() {
  286.40 +        return (Integer) getAttribute(this, "height");
  286.41 +    }
  286.42 +    
  286.43 +    public void setWidth(int width) {
  286.44 +        setAttribute(this, "width", width);
  286.45 +    }
  286.46 +
  286.47 +    public int getWidth() {
  286.48 +        return (Integer) getAttribute(this, "width");
  286.49 +    }
  286.50 +
  286.51 +    @JavaScriptBody(
  286.52 +            args = {"el"},
  286.53 +            body = "var e = window.document.getElementById(el._id());\n"
  286.54 +            + "return e.getContext('2d');\n")
  286.55 +    private native static Object getContextImpl(Canvas el);
  286.56 +
  286.57 +    public GraphicsContext getContext() {
  286.58 +        return new GraphicsContext(getContextImpl(this));
  286.59 +    }
  286.60 +
  286.61 +    @Override
  286.62 +    void dontSubclass() {
  286.63 +    }
  286.64 +}
   287.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   287.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/ComputedProperty.java	Sun Feb 03 07:48:42 2013 +0100
   287.3 @@ -0,0 +1,38 @@
   287.4 +/**
   287.5 + * Back 2 Browser Bytecode Translator
   287.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   287.7 + *
   287.8 + * This program is free software: you can redistribute it and/or modify
   287.9 + * it under the terms of the GNU General Public License as published by
  287.10 + * the Free Software Foundation, version 2 of the License.
  287.11 + *
  287.12 + * This program is distributed in the hope that it will be useful,
  287.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  287.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  287.15 + * GNU General Public License for more details.
  287.16 + *
  287.17 + * You should have received a copy of the GNU General Public License
  287.18 + * along with this program. Look for COPYING file in the top folder.
  287.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  287.20 + */
  287.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  287.22 +
  287.23 +import java.lang.annotation.ElementType;
  287.24 +import java.lang.annotation.Retention;
  287.25 +import java.lang.annotation.RetentionPolicy;
  287.26 +import java.lang.annotation.Target;
  287.27 +
  287.28 +/** Can be used in classes annotated with {@link Page} annotation to
  287.29 + * define a derived property. Value of derived property is based on values
  287.30 + * of {@link Property} as enumerated by {@link Page#properties()}.
  287.31 + * <p>
  287.32 + * The name of the derived property is the name of the method. The arguments
  287.33 + * of the method define the property names (from {@link Page#properties()} list)
  287.34 + * the value of property depends on. 
  287.35 + *
  287.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  287.37 + */
  287.38 +@Retention(RetentionPolicy.SOURCE)
  287.39 +@Target(ElementType.METHOD)
  287.40 +public @interface ComputedProperty {
  287.41 +}
   288.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Wed Dec 05 10:03:58 2012 +0100
   288.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Sun Feb 03 07:48:42 2013 +0100
   288.3 @@ -30,36 +30,66 @@
   288.4          this.id = id;
   288.5      }
   288.6      
   288.7 +    /** Id of the element in the document.
   288.8 +     * @return the id for this element
   288.9 +     */
  288.10 +    public String getId() {
  288.11 +        return id;
  288.12 +    }
  288.13 +    
  288.14      abstract void dontSubclass();
  288.15      
  288.16      @JavaScriptBody(
  288.17          args={"el", "property", "value"},
  288.18 -        body="var e = window.document.getElementById(el.fld_id);\n"
  288.19 +        body="var e = window.document.getElementById(el._id());\n"
  288.20             + "e[property] = value;\n"
  288.21      )
  288.22 -    static void setAttribute(Element el, String property, Object value) {
  288.23 -        throw new UnsupportedOperationException("Needs JavaScript!");
  288.24 -    }
  288.25 +    static native void setAttribute(Element el, String property, Object value);
  288.26  
  288.27      @JavaScriptBody(
  288.28          args={"el", "property"},
  288.29 -        body="var e = window.document.getElementById(el.fld_id);\n"
  288.30 +        body="var e = window.document.getElementById(el._id());\n"
  288.31             + "return e[property];\n"
  288.32      )
  288.33 -    static Object getAttribute(Element el, String property) {
  288.34 -        throw new UnsupportedOperationException("Needs JavaScript!");
  288.35 -    }
  288.36 +    static native Object getAttribute(Element el, String property);
  288.37 +    
  288.38 +    @JavaScriptBody(
  288.39 +        args={"el"},
  288.40 +        body="return window.document.getElementById(el._id());"
  288.41 +    )
  288.42 +    static native Object getElementById(Element el);
  288.43      
  288.44      /** Executes given runnable when user performs a "click" on the given
  288.45       * element.
  288.46       * @param r the runnable to execute, never null
  288.47       */
  288.48      @JavaScriptBody(
  288.49 -        args={"el", "r"},
  288.50 -        body="var e = window.document.getElementById(el.fld_id);\n"
  288.51 -           + "e.onclick = function() { r.run__V(); };\n"
  288.52 +        args={ "ev", "r" },
  288.53 +        body="var e = window.document.getElementById(this._id());\n"
  288.54 +           + "e[ev._id()] = function() { r.run__V(); };\n"
  288.55      )
  288.56 -    public final void addOnClick(Runnable r) {
  288.57 -        throw new UnsupportedOperationException("Needs JavaScript!");
  288.58 +    final void on(OnEvent ev, Runnable r) {
  288.59 +    }
  288.60 +
  288.61 +    /** Shows alert message dialog in a browser.
  288.62 +     * @param msg the message to show
  288.63 +     */
  288.64 +    @JavaScriptBody(args = "msg", body = "alert(msg);")
  288.65 +    public static native void alert(String msg);
  288.66 +
  288.67 +    /** Generic way to query any attribute of this element.
  288.68 +     * @param property name of the attribute
  288.69 +     */
  288.70 +    public final Object getAttribute(String property) {
  288.71 +        return getAttribute(this, property);
  288.72 +    }
  288.73 +    
  288.74 +    /** Generic way to change an attribute of this element.
  288.75 +     * 
  288.76 +     * @param property name of the attribute
  288.77 +     * @param value value to associate with the attribute
  288.78 +     */
  288.79 +    public final void setAttribute(String property, Object value) {
  288.80 +        setAttribute(this, property, value);
  288.81      }
  288.82  }
   289.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   289.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java	Sun Feb 03 07:48:42 2013 +0100
   289.3 @@ -0,0 +1,335 @@
   289.4 +/**
   289.5 + * Back 2 Browser Bytecode Translator
   289.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   289.7 + *
   289.8 + * This program is free software: you can redistribute it and/or modify
   289.9 + * it under the terms of the GNU General Public License as published by
  289.10 + * the Free Software Foundation, version 2 of the License.
  289.11 + *
  289.12 + * This program is distributed in the hope that it will be useful,
  289.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  289.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  289.15 + * GNU General Public License for more details.
  289.16 + *
  289.17 + * You should have received a copy of the GNU General Public License
  289.18 + * along with this program. Look for COPYING file in the top folder.
  289.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  289.20 + */
  289.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  289.22 +
  289.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  289.24 +
  289.25 +/**
  289.26 + *
  289.27 + * @author Anton Epple <toni.epple@eppleton.de>
  289.28 + */
  289.29 +public class GraphicsContext {
  289.30 +
  289.31 +    Object context;
  289.32 +
  289.33 +    GraphicsContext(Object contextImpl) {
  289.34 +        this.context = contextImpl;
  289.35 +    }
  289.36 +
  289.37 +    @JavaScriptBody(args = {"centerx", "centery", "radius", "startangle", "endangle", "ccw"},
  289.38 +            body = "this._context().arc(centerx,centery, radius, startangle, endangle,ccw);")
  289.39 +    public native void arc(double centerX,
  289.40 +            double centerY,
  289.41 +            double startAngle,
  289.42 +            double radius,
  289.43 +            double endAngle,
  289.44 +            boolean ccw);
  289.45 +
  289.46 +    @JavaScriptBody(args = {"x1", "y1", "x2", "y2", "r"},
  289.47 +            body = "this._context().arcTo(x1,y1,x2,y2,r);")
  289.48 +    public native void arcTo(double x1,
  289.49 +            double y1,
  289.50 +            double x2,
  289.51 +            double y2,
  289.52 +            double r);
  289.53 +
  289.54 +    @JavaScriptBody(args = {"x", "y"},
  289.55 +            body = "return this._context().isPointInPath(x,y);")
  289.56 +    public native boolean isPointInPath(double x, double y);
  289.57 +
  289.58 +    @JavaScriptBody(args = {}, body = "this._context().fill();")
  289.59 +    public native void fill();
  289.60 +
  289.61 +    @JavaScriptBody(args = {}, body = "this._context().stroke();")
  289.62 +    public native void stroke();
  289.63 +
  289.64 +    @JavaScriptBody(args = {}, body = "this._context().beginPath();")
  289.65 +    public native void beginPath();
  289.66 +
  289.67 +    @JavaScriptBody(args = {}, body = "this._context().closePath();")
  289.68 +    public native void closePath();
  289.69 +
  289.70 +    @JavaScriptBody(args = {}, body = "this._context().clip();")
  289.71 +    public native void clip();
  289.72 +
  289.73 +    @JavaScriptBody(args = {"x", "y"}, body = "this._context().moveTo(x,y);")
  289.74 +    public native void moveTo(double x, double y);
  289.75 +
  289.76 +    @JavaScriptBody(args = {"x", "y"}, body = "this._context().lineTo(x,y);")
  289.77 +    public native void lineTo(double x, double y);
  289.78 +
  289.79 +    @JavaScriptBody(args = {"cpx", "cpy", "x", "y"}, body = "this._context().quadraticCurveTo(cpx,cpy,x,y);")
  289.80 +    public native void quadraticCurveTo(double cpx, double cpy, double x, double y);
  289.81 +
  289.82 +    @JavaScriptBody(args = {"cp1x", "cp1y", "cp2x", "cp2y", "x", "y"},
  289.83 +            body = "this._context().bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);")
  289.84 +    public native void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
  289.85 +
  289.86 +    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().fillRect(x,y,width,height);")
  289.87 +    public native void fillRect(double x, double y, double width, double height);
  289.88 +
  289.89 +    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().strokeRect(x,y,width,height);")
  289.90 +    public native void strokeRect(double x, double y, double width, double height);
  289.91 +
  289.92 +    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().clearRect(x,y,width,height);")
  289.93 +    public native void clearRect(double x, double y, double width, double height);
  289.94 +
  289.95 +    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().rectect(x,y,width,height);")
  289.96 +    public native void rect(double x, double y, double width, double height);
  289.97 +
  289.98 +    @JavaScriptBody(args = {}, body = "this._context().save();")
  289.99 +    public native void save();
 289.100 +
 289.101 +    @JavaScriptBody(args = {}, body = "this._context().restore();")
 289.102 +    public native void restore();
 289.103 +
 289.104 +    @JavaScriptBody(args = {"angle"}, body = "this._context().rotate(angle);")
 289.105 +    public native void rotate(double angle);
 289.106 +
 289.107 +    @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().transform(a,b,c,d,e,f);")
 289.108 +    public native void transform(double a, double b, double c, double d, double e, double f);
 289.109 +
 289.110 +    @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().setTransform(a,b,c,d,e,f);")
 289.111 +    public native void setTransform(double a, double b, double c, double d, double e, double f);
 289.112 +
 289.113 +    @JavaScriptBody(args = {"x", "y"}, body = "this._context().translate(x,y);")
 289.114 +    public native void translate(double x, double y);
 289.115 +
 289.116 +    @JavaScriptBody(args = {"x", "y"}, body = "this._context().scale(x,y);")
 289.117 +    public native void scale(double x, double y);
 289.118 +
 289.119 +    public void drawImage(Image image, double x, double y) {
 289.120 +        drawImageImpl(context, Element.getElementById(image), x, y);
 289.121 +    }
 289.122 +
 289.123 +    public void drawImage(Image image, double x, double y, double width, double height) {
 289.124 +        drawImageImpl(context, Element.getElementById(image), x, y, width, height);
 289.125 +    }
 289.126 +
 289.127 +    public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
 289.128 +        drawImageImpl(context, Element.getElementById(image), sx, sy, sWidth, sHeight, x, y, width, height);
 289.129 +    }
 289.130 +
 289.131 +    @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
 289.132 +    private native static void drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
 289.133 +
 289.134 +    @JavaScriptBody(args = {"ctx", "img", "sx", "sy", "swidth", "sheight", "x", "y", "width", "height"}, body = "ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);")
 289.135 +    private native static void drawImageImpl(Object ctx, Object img, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height);
 289.136 +
 289.137 +    @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
 289.138 +    private native static void drawImageImpl(Object ctx, Object img, double x, double y);
 289.139 +
 289.140 +    @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style;")
 289.141 +    public native void setFillStyle(String style);
 289.142 +
 289.143 +    @JavaScriptBody(args = {}, body = "return this._context().fillStyle;")
 289.144 +    public native String getFillStyle();
 289.145 +
 289.146 +    public void setFillStyle(LinearGradient style) {
 289.147 +        setFillStyleImpl(context, style.object());
 289.148 +    }
 289.149 +
 289.150 +    public void setFillStyle(RadialGradient style) {
 289.151 +        setFillStyleImpl(context, style.object());
 289.152 +    }
 289.153 +
 289.154 +    public void setFillStyle(Pattern style) {
 289.155 +        setFillStyleImpl(context, style.object());
 289.156 +    }
 289.157 +
 289.158 +    @JavaScriptBody(args = {"context","obj"}, body = "context.fillStyle=obj;")
 289.159 +    private native void setFillStyleImpl(Object context, Object obj);
 289.160 +
 289.161 +    @JavaScriptBody(args = {"style"}, body = "this._context().strokeStyle=style;")
 289.162 +    public native void setStrokeStyle(String style);
 289.163 +
 289.164 +    public void setStrokeStyle(LinearGradient style) {
 289.165 +        setStrokeStyleImpl(context, style.object());
 289.166 +    }
 289.167 +
 289.168 +    public void setStrokeStyle(RadialGradient style) {
 289.169 +        setStrokeStyleImpl(context, style.object());
 289.170 +    }
 289.171 +
 289.172 +    @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style;")
 289.173 +    public void setStrokeStyle(Pattern style) {
 289.174 +        setStrokeStyleImpl(context, style.object());
 289.175 +    }
 289.176 +
 289.177 +    @JavaScriptBody(args = {"context","obj"}, body = "context.strokeStyle=obj;")
 289.178 +    private native void setStrokeStyleImpl(Object context, Object obj);
 289.179 +
 289.180 +    @JavaScriptBody(args = {"color"}, body = "this._context().shadowColor=color;")
 289.181 +    public native void setShadowColor(String color);
 289.182 +
 289.183 +    @JavaScriptBody(args = {"blur"}, body = "this._context().shadowBlur=blur;")
 289.184 +    public native void setShadowBlur(double blur);
 289.185 +    
 289.186 +    @JavaScriptBody(args = {"x"}, body = "this._context().shadowOffsetX=x;")
 289.187 +    public native void setShadowOffsetX(double x);
 289.188 +
 289.189 +    @JavaScriptBody(args = {"y"}, body = "this._context().shadowOffsetY=y;")
 289.190 +    public native void setShadowOffsetY(double y);
 289.191 +
 289.192 +    @JavaScriptBody(args = {}, body = "return this._context().strokeStyle;")
 289.193 +    public native String getStrokeStyle();
 289.194 +
 289.195 +    @JavaScriptBody(args = {}, body = "return this._context().shadowColor;")
 289.196 +    public native String getShadowColor();
 289.197 +
 289.198 +    @JavaScriptBody(args = {}, body = "return this._context().shadowBlur;")
 289.199 +    public native double getShadowBlur();
 289.200 +
 289.201 +    @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetX;")
 289.202 +    public native double getShadowOffsetX();
 289.203 +
 289.204 +    @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetY;")
 289.205 +    public native double getShadowOffsetY();
 289.206 +
 289.207 +    @JavaScriptBody(args = {}, body = "return this._context().lineCap;")
 289.208 +    public native String getLineCap();
 289.209 +
 289.210 +    @JavaScriptBody(args = {"style"}, body = "this._context().lineCap=style;")
 289.211 +    public native void setLineCap(String style);
 289.212 +
 289.213 +    @JavaScriptBody(args = {}, body = "return this._context().lineJoin;")
 289.214 +    public native String getLineJoin();
 289.215 +
 289.216 +    @JavaScriptBody(args = {"style"}, body = "this._context().lineJoin=style;")
 289.217 +    public native void setLineJoin(String style) ;
 289.218 +
 289.219 +    @JavaScriptBody(args = {}, body = "return this._context().lineWidth;")
 289.220 +    public native double getLineWidth();
 289.221 +
 289.222 +    @JavaScriptBody(args = {"width"}, body = "this._context().lineJoin=width;")
 289.223 +    public native void setLineWidth(double width);
 289.224 +
 289.225 +    @JavaScriptBody(args = {}, body = "return this._context().miterLimit;")
 289.226 +    public native double getMiterLimit();
 289.227 +
 289.228 +    @JavaScriptBody(args = {"limit"}, body = "this._context().miterLimit=limit;")
 289.229 +    public native void setMiterLimit(double limit);
 289.230 +
 289.231 +    @JavaScriptBody(args = {}, body = "return this._context().font;")
 289.232 +    public native String getFont();
 289.233 +
 289.234 +    @JavaScriptBody(args = {"font"}, body = "this._context().font=font;")
 289.235 +    public native void setFont(String font);
 289.236 +
 289.237 +    @JavaScriptBody(args = {}, body = "return this._context().textAlign;")
 289.238 +    public native String getTextAlign();
 289.239 +
 289.240 +    @JavaScriptBody(args = {"textalign"}, body = "this._context().textAlign=textalign;")
 289.241 +    public native void setTextAlign(String textAlign);
 289.242 +
 289.243 +    @JavaScriptBody(args = {}, body = "return this._context().textBaseline;")
 289.244 +    public native String getTextBaseline();
 289.245 +
 289.246 +    @JavaScriptBody(args = {"textbaseline"}, body = "this._context().textBaseline=textbaseline;")
 289.247 +    public native void setTextBaseline(String textbaseline);
 289.248 +
 289.249 +    @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().fillText(text,x,y);")
 289.250 +    public native void fillText(String text, double x, double y);
 289.251 +
 289.252 +    @JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this._context().fillText(text,x,y,maxwidth);")
 289.253 +    public void fillText(String text, double x, double y, double maxWidth) {
 289.254 +    }
 289.255 +
 289.256 +    public TextMetrics measureText(String text) {
 289.257 +        return new TextMetrics(measureTextImpl(text));
 289.258 +    }
 289.259 +
 289.260 +    @JavaScriptBody(args = {"text"},
 289.261 +            body = "return this._context().measureText(text);")
 289.262 +    private native Object measureTextImpl(String text);
 289.263 +
 289.264 +    @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().strokeText(text,x,y);")
 289.265 +    public native void strokeText(String text, double x, double y);
 289.266 +
 289.267 +    @JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this._context().strokeText(text,x,y,maxWidth);")
 289.268 +    public native void strokeText(String text, double x, double y, double maxWidth) ;
 289.269 +
 289.270 +    public ImageData createImageData(double x, double y) {
 289.271 +        return new ImageData(createImageDataImpl(x, y));
 289.272 +    }
 289.273 +
 289.274 +    @JavaScriptBody(args = {"x", "y"},
 289.275 +            body = "return this._context().createImageData(x,y);")
 289.276 +    private native Object createImageDataImpl(double x, double y);
 289.277 +
 289.278 +    public ImageData createImageData(ImageData imageData) {
 289.279 +        return new ImageData(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
 289.280 +    }
 289.281 +
 289.282 +    public ImageData getImageData(double x, double y, double width, double height) {
 289.283 +        return new ImageData(getImageDataImpl(x, y, width, height));
 289.284 +    }
 289.285 +
 289.286 +    @JavaScriptBody(args = {"x", "y", "width", "height"},
 289.287 +            body = "return this._context().getImageData(x,y,width,height);")
 289.288 +    private native Object getImageDataImpl(double x, double y, double width, double height);
 289.289 +
 289.290 +    public void putImageData(ImageData imageData, double x, double y) {
 289.291 +        putImageDataImpl(imageData.object(), x, y);
 289.292 +    }
 289.293 +
 289.294 +    @JavaScriptBody(args = {"imageData", "x", "y"},
 289.295 +            body = "this._context().putImageData(imageData,x,y);")
 289.296 +    private native void putImageDataImpl(Object imageData, double x, double y);
 289.297 +
 289.298 +    public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
 289.299 +        putImageDataImpl(imageData.object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
 289.300 +    }
 289.301 +
 289.302 +    @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
 289.303 +            body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
 289.304 +    private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
 289.305 +
 289.306 +    @JavaScriptBody(args = {"alpha"}, body = "this._context().globalAlpha=alpha;")
 289.307 +    public native void setGlobalAlpha(double alpha) ;
 289.308 +
 289.309 +    @JavaScriptBody(args = {}, body = "return this._context().globalAlpha;")
 289.310 +    public native double getGlobalAlpha();
 289.311 +
 289.312 +    @JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation;")
 289.313 +    public native void setGlobalCompositeOperation(double alpha);
 289.314 +
 289.315 +    @JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;")
 289.316 +    public native double getGlobalCompositeOperation();
 289.317 +
 289.318 +    public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
 289.319 +        return new LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1));
 289.320 +    }
 289.321 +
 289.322 +    @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
 289.323 +    private  native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
 289.324 +
 289.325 +    public Pattern createPattern(Image image, String repeat) {
 289.326 +        return new Pattern(createPatternImpl(context, image, repeat));
 289.327 +    }
 289.328 +
 289.329 +    @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
 289.330 +    private static native Object createPatternImpl(Object context, Image image, String repeat);
 289.331 +
 289.332 +    public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
 289.333 +        return new RadialGradient(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
 289.334 +    }
 289.335 +
 289.336 +    @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
 289.337 +    private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);
 289.338 +}
   290.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   290.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Image.java	Sun Feb 03 07:48:42 2013 +0100
   290.3 @@ -0,0 +1,36 @@
   290.4 +/**
   290.5 + * Back 2 Browser Bytecode Translator
   290.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   290.7 + *
   290.8 + * This program is free software: you can redistribute it and/or modify
   290.9 + * it under the terms of the GNU General Public License as published by
  290.10 + * the Free Software Foundation, version 2 of the License.
  290.11 + *
  290.12 + * This program is distributed in the hope that it will be useful,
  290.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  290.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  290.15 + * GNU General Public License for more details.
  290.16 + *
  290.17 + * You should have received a copy of the GNU General Public License
  290.18 + * along with this program. Look for COPYING file in the top folder.
  290.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  290.20 + */
  290.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  290.22 +
  290.23 +/**
  290.24 + *
  290.25 + * @author Anton Epple <toni.epple@eppleton.de>
  290.26 + */
  290.27 +public class Image extends Element{
  290.28 +
  290.29 +    public Image(String id) {
  290.30 +        super(id);
  290.31 +    }
  290.32 +
  290.33 +    
  290.34 +    
  290.35 +    @Override
  290.36 +    void dontSubclass() {
  290.37 +    }
  290.38 +    
  290.39 +}
   291.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   291.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/ImageData.java	Sun Feb 03 07:48:42 2013 +0100
   291.3 @@ -0,0 +1,89 @@
   291.4 +/**
   291.5 + * Back 2 Browser Bytecode Translator
   291.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   291.7 + *
   291.8 + * This program is free software: you can redistribute it and/or modify
   291.9 + * it under the terms of the GNU General Public License as published by
  291.10 + * the Free Software Foundation, version 2 of the License.
  291.11 + *
  291.12 + * This program is distributed in the hope that it will be useful,
  291.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  291.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  291.15 + * GNU General Public License for more details.
  291.16 + *
  291.17 + * You should have received a copy of the GNU General Public License
  291.18 + * along with this program. Look for COPYING file in the top folder.
  291.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  291.20 + */
  291.21 +/*
  291.22 + * To change this template, choose Tools | Templates
  291.23 + * and open the template in the editor.
  291.24 + */
  291.25 +package org.apidesign.bck2brwsr.htmlpage.api;
  291.26 +
  291.27 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  291.28 +
  291.29 +/**
  291.30 + *
  291.31 + * @author Anton Epple <toni.epple@eppleton.de>
  291.32 + */
  291.33 +public class ImageData {
  291.34 +
  291.35 +    private Object imageData;
  291.36 +    private Data data;
  291.37 +
  291.38 +    public ImageData(Object imageData) {
  291.39 +        this.imageData = imageData;
  291.40 +    }
  291.41 +    
  291.42 +    public Data getData(){
  291.43 +        if (data == null){
  291.44 +            data = new Data(getDataImpl(imageData));
  291.45 +        }
  291.46 +        return data;
  291.47 +    }
  291.48 +    
  291.49 +    @JavaScriptBody(args = {"imageData"}, body = "return imageData.data")
  291.50 +    public native Object getDataImpl(Object imageData);
  291.51 +
  291.52 +    public double getWidth() {
  291.53 +        return getWidthImpl(imageData);
  291.54 +    }
  291.55 +
  291.56 +    @JavaScriptBody(args = {"imageData"}, body = "return imagedata.width;")
  291.57 +    private static native double getWidthImpl(Object imageData);
  291.58 +
  291.59 +    public double getHeight() {
  291.60 +        return getHeightImpl(imageData);
  291.61 +    }
  291.62 +
  291.63 +    @JavaScriptBody(args = {"imageData"}, body = "return imagedata.height;")
  291.64 +    private static native double getHeightImpl(Object imageData);
  291.65 +
  291.66 +    Object object() {
  291.67 +        return imageData;
  291.68 +    }
  291.69 +
  291.70 +    public static class Data {
  291.71 +
  291.72 +        Object data;
  291.73 +
  291.74 +        public Data(Object data) {
  291.75 +            this.data = data;
  291.76 +        }
  291.77 +
  291.78 +        public int get(int index) {
  291.79 +            return getImpl(data, index);
  291.80 +        }
  291.81 +
  291.82 +        public void set(int index, int value) {
  291.83 +            setImpl(data, index, value);
  291.84 +        }
  291.85 +
  291.86 +        @JavaScriptBody(args = {"data", "index", "value"}, body = "data[index]=value;")
  291.87 +        private static native void setImpl(Object data, int index, int value);
  291.88 +
  291.89 +        @JavaScriptBody(args = {"imagedata", "index"}, body = "return data[index];")
  291.90 +        private static native int getImpl(Object data, int index);
  291.91 +    }
  291.92 +}
   292.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   292.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/LinearGradient.java	Sun Feb 03 07:48:42 2013 +0100
   292.3 @@ -0,0 +1,45 @@
   292.4 +/**
   292.5 + * Back 2 Browser Bytecode Translator
   292.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   292.7 + *
   292.8 + * This program is free software: you can redistribute it and/or modify
   292.9 + * it under the terms of the GNU General Public License as published by
  292.10 + * the Free Software Foundation, version 2 of the License.
  292.11 + *
  292.12 + * This program is distributed in the hope that it will be useful,
  292.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  292.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  292.15 + * GNU General Public License for more details.
  292.16 + *
  292.17 + * You should have received a copy of the GNU General Public License
  292.18 + * along with this program. Look for COPYING file in the top folder.
  292.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  292.20 + */
  292.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  292.22 +
  292.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  292.24 +
  292.25 +/**
  292.26 + *
  292.27 + * @author Anton Epple <toni.epple@eppleton.de>
  292.28 + */
  292.29 +public class LinearGradient {
  292.30 +
  292.31 +    private final Object gradient;
  292.32 +
  292.33 +    LinearGradient(Object linearGradient) {
  292.34 +        this.gradient = linearGradient;
  292.35 +    }
  292.36 +
  292.37 +    Object object() {
  292.38 +        return gradient;
  292.39 +    }
  292.40 +
  292.41 +    public void addColorStop(double position, String color) {
  292.42 +        addColorStopImpl(gradient, position, color);
  292.43 +    }
  292.44 +
  292.45 +    @JavaScriptBody(args = {"gradient", "position", "color"}, body =
  292.46 +            "gradient.addColorStop(position,color)")
  292.47 +    private static native void addColorStopImpl(Object gradient, double position, String color);
  292.48 +}
   293.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   293.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/On.java	Sun Feb 03 07:48:42 2013 +0100
   293.3 @@ -0,0 +1,35 @@
   293.4 +/**
   293.5 + * Back 2 Browser Bytecode Translator
   293.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   293.7 + *
   293.8 + * This program is free software: you can redistribute it and/or modify
   293.9 + * it under the terms of the GNU General Public License as published by
  293.10 + * the Free Software Foundation, version 2 of the License.
  293.11 + *
  293.12 + * This program is distributed in the hope that it will be useful,
  293.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  293.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  293.15 + * GNU General Public License for more details.
  293.16 + *
  293.17 + * You should have received a copy of the GNU General Public License
  293.18 + * along with this program. Look for COPYING file in the top folder.
  293.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  293.20 + */
  293.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  293.22 +
  293.23 +import java.lang.annotation.ElementType;
  293.24 +import java.lang.annotation.Retention;
  293.25 +import java.lang.annotation.RetentionPolicy;
  293.26 +import java.lang.annotation.Target;
  293.27 +
  293.28 +/** Adds an onClick handler to an element identified by given <em>id</em>.
  293.29 + * Apply on a <code>public static void</code> method with no arguments.
  293.30 + *
  293.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  293.32 + */
  293.33 +@Retention(RetentionPolicy.SOURCE)
  293.34 +@Target(ElementType.METHOD)
  293.35 +public @interface On {
  293.36 +    OnEvent event();
  293.37 +    String[] id();
  293.38 +}
   294.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/OnClick.java	Wed Dec 05 10:03:58 2012 +0100
   294.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   294.3 @@ -1,34 +0,0 @@
   294.4 -/**
   294.5 - * Back 2 Browser Bytecode Translator
   294.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   294.7 - *
   294.8 - * This program is free software: you can redistribute it and/or modify
   294.9 - * it under the terms of the GNU General Public License as published by
  294.10 - * the Free Software Foundation, version 2 of the License.
  294.11 - *
  294.12 - * This program is distributed in the hope that it will be useful,
  294.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  294.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  294.15 - * GNU General Public License for more details.
  294.16 - *
  294.17 - * You should have received a copy of the GNU General Public License
  294.18 - * along with this program. Look for COPYING file in the top folder.
  294.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  294.20 - */
  294.21 -package org.apidesign.bck2brwsr.htmlpage.api;
  294.22 -
  294.23 -import java.lang.annotation.ElementType;
  294.24 -import java.lang.annotation.Retention;
  294.25 -import java.lang.annotation.RetentionPolicy;
  294.26 -import java.lang.annotation.Target;
  294.27 -
  294.28 -/** Adds an onClick handler to an element identified by given <em>id</em>.
  294.29 - * Apply on a <code>public static void</code> method with no arguments.
  294.30 - *
  294.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  294.32 - */
  294.33 -@Retention(RetentionPolicy.SOURCE)
  294.34 -@Target(ElementType.METHOD)
  294.35 -public @interface OnClick {
  294.36 -    String[] id();
  294.37 -}
   295.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   295.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/OnController.java	Sun Feb 03 07:48:42 2013 +0100
   295.3 @@ -0,0 +1,43 @@
   295.4 +/**
   295.5 + * Back 2 Browser Bytecode Translator
   295.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   295.7 + *
   295.8 + * This program is free software: you can redistribute it and/or modify
   295.9 + * it under the terms of the GNU General Public License as published by
  295.10 + * the Free Software Foundation, version 2 of the License.
  295.11 + *
  295.12 + * This program is distributed in the hope that it will be useful,
  295.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  295.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  295.15 + * GNU General Public License for more details.
  295.16 + *
  295.17 + * You should have received a copy of the GNU General Public License
  295.18 + * along with this program. Look for COPYING file in the top folder.
  295.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  295.20 + */
  295.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  295.22 +
  295.23 +/** Controller created via {@link OnEvent#of(org.apidesign.bck2brwsr.htmlpage.api.Element[])}.
  295.24 + *
  295.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  295.26 + */
  295.27 +public final class OnController {
  295.28 +    private final Element[] arr;
  295.29 +    private final OnEvent event;
  295.30 +    
  295.31 +    OnController(OnEvent event, Element[] arr) {
  295.32 +        this.event = event;
  295.33 +        this.arr = arr;
  295.34 +    }
  295.35 +    
  295.36 +    /** Registers a runnable to be performed on associated {@link OnEvent} 
  295.37 +     * and {@link Element}.
  295.38 +     * 
  295.39 +     * @see OnEvent#of
  295.40 +     */
  295.41 +    public void perform(Runnable r) {
  295.42 +        for (Element e : arr) {
  295.43 +            e.on(event, r);
  295.44 +        }
  295.45 +    }
  295.46 +}
   296.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   296.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/OnEvent.java	Sun Feb 03 07:48:42 2013 +0100
   296.3 @@ -0,0 +1,103 @@
   296.4 +/**
   296.5 + * Back 2 Browser Bytecode Translator
   296.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   296.7 + *
   296.8 + * This program is free software: you can redistribute it and/or modify
   296.9 + * it under the terms of the GNU General Public License as published by
  296.10 + * the Free Software Foundation, version 2 of the License.
  296.11 + *
  296.12 + * This program is distributed in the hope that it will be useful,
  296.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  296.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  296.15 + * GNU General Public License for more details.
  296.16 + *
  296.17 + * You should have received a copy of the GNU General Public License
  296.18 + * along with this program. Look for COPYING file in the top folder.
  296.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  296.20 + */
  296.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  296.22 +
  296.23 +/** Type of events to use in connection with {@link On} annotation.
  296.24 + *
  296.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  296.26 + */
  296.27 +public enum OnEvent {
  296.28 +    ABORT("onabort"),
  296.29 +    BLUR("onblur"),
  296.30 +    CAN_PLAY("oncanplay"),
  296.31 +    CAN_PLAY_THROUGH("oncanplaythrough"),
  296.32 +    CHANGE("onchange"),
  296.33 +    CLICK("onclick"),
  296.34 +    CONTEXT_MENU("oncontextmenu"),
  296.35 +    DBL_CLICK("ondblclick"),
  296.36 +    DRAG("ondrag"),
  296.37 +    DRAG_END("ondragend"),
  296.38 +    DRAG_ENTER("ondragenter"),
  296.39 +    DRAG_LEAVE("ondragleave"),
  296.40 +    DRAG_OVER("ondragover"),
  296.41 +    DRAG_START("ondragstart"),
  296.42 +    DROP("ondrop"),
  296.43 +    DURATION_CHANGE("ondurationchange"),
  296.44 +    EMPTIED("onemptied"),
  296.45 +    ENDED("onended"),
  296.46 +    ERROR("onerror"),
  296.47 +    FOCUS("onfocus"),
  296.48 +    FORM_CHANGE("onformchange"),
  296.49 +    FORM_INPUT("onforminput"),
  296.50 +    INPUT("oninput"),
  296.51 +    INVALID("oninvalid"),
  296.52 +    KEY_DOWN("onkeydown"),
  296.53 +    KEY_PRESS("onkeypress"),
  296.54 +    KEY_UP("onkeyup"),
  296.55 +    LOAD("onload"),
  296.56 +    LOADED_DATA("onloadeddata"),
  296.57 +    LOADED_META_DATA("onloadedmetadata"),
  296.58 +    LOAD_START("onloadstart"),
  296.59 +    MOUSE_DOWN("onmousedown"),
  296.60 +    MOUSE_MOVE("onmousemove"),
  296.61 +    MOUSE_OUT("onmouseout"),
  296.62 +    MOUSE_OVER("onmouseover"),
  296.63 +    MOUSE_UP("onmouseup"),
  296.64 +    MOUSE_WHEEL("onmousewheel"),
  296.65 +    PAUSE("onpause"),
  296.66 +    PLAY("onplay"),
  296.67 +    PLAYING("onplaying"),
  296.68 +    PROGRESS("onprogress"),
  296.69 +    RATE_CHANGE("onratechange"),
  296.70 +    READY_STATE_CHANGE("onreadystatechange"),
  296.71 +    SCROLL("onscroll"),
  296.72 +    SEEKED("onseeked"),
  296.73 +    SEEKING("onseeking"),
  296.74 +    SELECT("onselect"),
  296.75 +    SHOW("onshow"),
  296.76 +    STALLED("onstalled"),
  296.77 +    SUBMIT("onsubmit"),
  296.78 +    SUSPEND("onsuspend"),
  296.79 +    TIME_UPDATE("ontimeupdate"),
  296.80 +    VOLUME_CHANGE("onvolumechange"),
  296.81 +    WAITING("onwaiting");
  296.82 +    
  296.83 +    final String id;
  296.84 +    
  296.85 +    private OnEvent(String id) {
  296.86 +        this.id = id;
  296.87 +    }
  296.88 +    
  296.89 +    /** The name of property this event is referenced by from an {@link Element}.
  296.90 +     * For {@link OnEvent#CHANGE}, it is <code>onchange</code>.
  296.91 +     */
  296.92 +    public String getElementPropertyName() {
  296.93 +        return id;
  296.94 +    }
  296.95 +    
  296.96 +    /** What should happen when this even happen on one
  296.97 +     * of associated elements. Continue by calling {@link OnController#perform(java.lang.Runnable)}
  296.98 +     * method.
  296.99 +     * 
 296.100 +     * @param elmnts one or more elements
 296.101 +     * @return controller with <code>perform</code> method.
 296.102 +     */
 296.103 +    public OnController of(Element... elmnts) {
 296.104 +        return new OnController(this, elmnts);
 296.105 +    }
 296.106 +}
   297.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Page.java	Wed Dec 05 10:03:58 2012 +0100
   297.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Page.java	Sun Feb 03 07:48:42 2013 +0100
   297.3 @@ -36,4 +36,7 @@
   297.4       * found elements with IDs.
   297.5       */
   297.6      String className() default "";
   297.7 +    /** List of properties generated into the page.
   297.8 +     */
   297.9 +    Property[] properties() default {};
  297.10  }
   298.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   298.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Paint.java	Sun Feb 03 07:48:42 2013 +0100
   298.3 @@ -0,0 +1,30 @@
   298.4 +/**
   298.5 + * Back 2 Browser Bytecode Translator
   298.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   298.7 + *
   298.8 + * This program is free software: you can redistribute it and/or modify
   298.9 + * it under the terms of the GNU General Public License as published by
  298.10 + * the Free Software Foundation, version 2 of the License.
  298.11 + *
  298.12 + * This program is distributed in the hope that it will be useful,
  298.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  298.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  298.15 + * GNU General Public License for more details.
  298.16 + *
  298.17 + * You should have received a copy of the GNU General Public License
  298.18 + * along with this program. Look for COPYING file in the top folder.
  298.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  298.20 + */
  298.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  298.22 +
  298.23 +/**
  298.24 + *
  298.25 + * @author Anton Epple <toni.epple@eppleton.de>
  298.26 + */
  298.27 +public class Paint {
  298.28 +    
  298.29 +    
  298.30 +    String asString(){
  298.31 +       return "";
  298.32 +    }
  298.33 +}
   299.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   299.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Pattern.java	Sun Feb 03 07:48:42 2013 +0100
   299.3 @@ -0,0 +1,35 @@
   299.4 +/**
   299.5 + * Back 2 Browser Bytecode Translator
   299.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   299.7 + *
   299.8 + * This program is free software: you can redistribute it and/or modify
   299.9 + * it under the terms of the GNU General Public License as published by
  299.10 + * the Free Software Foundation, version 2 of the License.
  299.11 + *
  299.12 + * This program is distributed in the hope that it will be useful,
  299.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  299.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  299.15 + * GNU General Public License for more details.
  299.16 + *
  299.17 + * You should have received a copy of the GNU General Public License
  299.18 + * along with this program. Look for COPYING file in the top folder.
  299.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  299.20 + */
  299.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  299.22 +
  299.23 +/**
  299.24 + *
  299.25 + * @author Anton Epple <toni.epple@eppleton.de>
  299.26 + */
  299.27 +public class Pattern {
  299.28 +
  299.29 +    private Object pattern;
  299.30 +
  299.31 +    public Pattern(Object pattern) {
  299.32 +        this.pattern = pattern;
  299.33 +    }
  299.34 +
  299.35 +    Object object() {
  299.36 +        return pattern;
  299.37 +    }
  299.38 +}
   300.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   300.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Property.java	Sun Feb 03 07:48:42 2013 +0100
   300.3 @@ -0,0 +1,34 @@
   300.4 +/**
   300.5 + * Back 2 Browser Bytecode Translator
   300.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   300.7 + *
   300.8 + * This program is free software: you can redistribute it and/or modify
   300.9 + * it under the terms of the GNU General Public License as published by
  300.10 + * the Free Software Foundation, version 2 of the License.
  300.11 + *
  300.12 + * This program is distributed in the hope that it will be useful,
  300.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  300.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  300.15 + * GNU General Public License for more details.
  300.16 + *
  300.17 + * You should have received a copy of the GNU General Public License
  300.18 + * along with this program. Look for COPYING file in the top folder.
  300.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  300.20 + */
  300.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  300.22 +
  300.23 +import java.lang.annotation.Retention;
  300.24 +import java.lang.annotation.RetentionPolicy;
  300.25 +import java.lang.annotation.Target;
  300.26 +
  300.27 +/** Represents a property in a generated model of an HTML
  300.28 + * {@link Page}.
  300.29 + *
  300.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  300.31 + */
  300.32 +@Retention(RetentionPolicy.SOURCE)
  300.33 +@Target({})
  300.34 +public @interface Property {
  300.35 +    String name();
  300.36 +    Class<?> type();
  300.37 +}
   301.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   301.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/RadialGradient.java	Sun Feb 03 07:48:42 2013 +0100
   301.3 @@ -0,0 +1,45 @@
   301.4 +/**
   301.5 + * Back 2 Browser Bytecode Translator
   301.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   301.7 + *
   301.8 + * This program is free software: you can redistribute it and/or modify
   301.9 + * it under the terms of the GNU General Public License as published by
  301.10 + * the Free Software Foundation, version 2 of the License.
  301.11 + *
  301.12 + * This program is distributed in the hope that it will be useful,
  301.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  301.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  301.15 + * GNU General Public License for more details.
  301.16 + *
  301.17 + * You should have received a copy of the GNU General Public License
  301.18 + * along with this program. Look for COPYING file in the top folder.
  301.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  301.20 + */
  301.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  301.22 +
  301.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  301.24 +
  301.25 +/**
  301.26 + *
  301.27 + * @author Anton Epple <toni.epple@eppleton.de>
  301.28 + */
  301.29 +public class RadialGradient {
  301.30 +
  301.31 +    private Object gradient;
  301.32 +
  301.33 +    public RadialGradient(Object radialGradient) {
  301.34 +        this.gradient = radialGradient;
  301.35 +    }
  301.36 +
  301.37 +    public void addColorStop(double position, String color) {
  301.38 +        addColorStopImpl(gradient, position, color);
  301.39 +    }
  301.40 +
  301.41 +    @JavaScriptBody(args = {"gradient", "position", "color"}, body =
  301.42 +            "gradient.addColorStop(position,color)")
  301.43 +    private static native void addColorStopImpl(Object gradient, double position, String color);
  301.44 +
  301.45 +    Object object() {
  301.46 +        return gradient;
  301.47 +    }
  301.48 +}
   302.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   302.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/TextMetrics.java	Sun Feb 03 07:48:42 2013 +0100
   302.3 @@ -0,0 +1,48 @@
   302.4 +/**
   302.5 + * Back 2 Browser Bytecode Translator
   302.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   302.7 + *
   302.8 + * This program is free software: you can redistribute it and/or modify
   302.9 + * it under the terms of the GNU General Public License as published by
  302.10 + * the Free Software Foundation, version 2 of the License.
  302.11 + *
  302.12 + * This program is distributed in the hope that it will be useful,
  302.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  302.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  302.15 + * GNU General Public License for more details.
  302.16 + *
  302.17 + * You should have received a copy of the GNU General Public License
  302.18 + * along with this program. Look for COPYING file in the top folder.
  302.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  302.20 + */
  302.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  302.22 +
  302.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  302.24 +
  302.25 +/**
  302.26 + *
  302.27 + * @author Anton Epple <toni.epple@eppleton.de>
  302.28 + */
  302.29 +public class TextMetrics {
  302.30 +
  302.31 +    private Object textMetrics;
  302.32 +
  302.33 +    TextMetrics(Object measureTextImpl) {
  302.34 +        this.textMetrics = measureTextImpl;
  302.35 +    }
  302.36 +
  302.37 +    @JavaScriptBody(args = {"textMetrics"}, body = "return textMetrics.width;")
  302.38 +    private native double getWidth(Object textMetrics);
  302.39 +
  302.40 +    @JavaScriptBody(args = {"textMetrics"}, body = "return textMetrics.height;")
  302.41 +    private native double getHeight(Object textMetrics);
  302.42 +
  302.43 +    public double getWidth() {
  302.44 +        return getWidth(textMetrics);
  302.45 +    }
  302.46 +
  302.47 +    public double getHeight() {
  302.48 +        return getHeight(textMetrics);
  302.49 +
  302.50 +    }
  302.51 +}
   303.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   303.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Timer.java	Sun Feb 03 07:48:42 2013 +0100
   303.3 @@ -0,0 +1,59 @@
   303.4 +/**
   303.5 + * Back 2 Browser Bytecode Translator
   303.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   303.7 + *
   303.8 + * This program is free software: you can redistribute it and/or modify
   303.9 + * it under the terms of the GNU General Public License as published by
  303.10 + * the Free Software Foundation, version 2 of the License.
  303.11 + *
  303.12 + * This program is distributed in the hope that it will be useful,
  303.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  303.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  303.15 + * GNU General Public License for more details.
  303.16 + *
  303.17 + * You should have received a copy of the GNU General Public License
  303.18 + * along with this program. Look for COPYING file in the top folder.
  303.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  303.20 + */
  303.21 +package org.apidesign.bck2brwsr.htmlpage.api;
  303.22 +
  303.23 +import java.io.Closeable;
  303.24 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  303.25 +
  303.26 +/**
  303.27 + *
  303.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  303.29 + */
  303.30 +public class Timer implements Closeable {
  303.31 +    private final Object t;
  303.32 +    
  303.33 +    private Timer(Object t) {
  303.34 +        this.t = t;
  303.35 +    }
  303.36 +    
  303.37 +    /** Creates a timer that invokes provided runnable on a fixed interval
  303.38 +     * 
  303.39 +     * @param r the runnable to execute
  303.40 +     * @param time milliseconds to invoke the timer periodically
  303.41 +     */
  303.42 +    public static Timer create(Runnable r, int time) {
  303.43 +        return new Timer(interval(r, time));
  303.44 +    }
  303.45 +    
  303.46 +    @JavaScriptBody(args = { "r", "time" }, body = 
  303.47 +        "return window.setInterval(function() { r.run__V(); }, time);"
  303.48 +    )
  303.49 +    private static native Object interval(Runnable r, int time);
  303.50 +
  303.51 +    @JavaScriptBody(args = { "self" }, body = 
  303.52 +        "window.clearInterval(self);"
  303.53 +    )
  303.54 +    private static native void close(Object self);
  303.55 +    
  303.56 +    /** Cancels this timer.
  303.57 +     */
  303.58 +    @Override
  303.59 +    public void close() {
  303.60 +        close(t);
  303.61 +    }
  303.62 +}
   304.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   304.2 +++ b/javaquery/api/src/main/resources/org/apidesign/bck2brwsr/htmlpage/knockout-2.2.1.js	Sun Feb 03 07:48:42 2013 +0100
   304.3 @@ -0,0 +1,3587 @@
   304.4 +// Knockout JavaScript library v2.2.1
   304.5 +// (c) Steven Sanderson - http://knockoutjs.com/
   304.6 +// License: MIT (http://www.opensource.org/licenses/mit-license.php)
   304.7 +
   304.8 +(function(){
   304.9 +var DEBUG=true;
  304.10 +(function(window,document,navigator,jQuery,undefined){
  304.11 +!function(factory) {
  304.12 +    // Support three module loading scenarios
  304.13 +    if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
  304.14 +        // [1] CommonJS/Node.js
  304.15 +        var target = module['exports'] || exports; // module.exports is for Node.js
  304.16 +        factory(target);
  304.17 +    } else if (typeof define === 'function' && define['amd']) {
  304.18 +        // [2] AMD anonymous module
  304.19 +        define(['exports'], factory);
  304.20 +    } else {
  304.21 +        // [3] No module loader (plain <script> tag) - put directly in global namespace
  304.22 +        factory(window['ko'] = {});
  304.23 +    }
  304.24 +}(function(koExports){
  304.25 +// Internally, all KO objects are attached to koExports (even the non-exported ones whose names will be minified by the closure compiler).
  304.26 +// In the future, the following "ko" variable may be made distinct from "koExports" so that private objects are not externally reachable.
  304.27 +var ko = typeof koExports !== 'undefined' ? koExports : {};
  304.28 +// Google Closure Compiler helpers (used only to make the minified file smaller)
  304.29 +ko.exportSymbol = function(koPath, object) {
  304.30 +	var tokens = koPath.split(".");
  304.31 +
  304.32 +	// In the future, "ko" may become distinct from "koExports" (so that non-exported objects are not reachable)
  304.33 +	// At that point, "target" would be set to: (typeof koExports !== "undefined" ? koExports : ko)
  304.34 +	var target = ko;
  304.35 +
  304.36 +	for (var i = 0; i < tokens.length - 1; i++)
  304.37 +		target = target[tokens[i]];
  304.38 +	target[tokens[tokens.length - 1]] = object;
  304.39 +};
  304.40 +ko.exportProperty = function(owner, publicName, object) {
  304.41 +  owner[publicName] = object;
  304.42 +};
  304.43 +ko.version = "2.2.1";
  304.44 +
  304.45 +ko.exportSymbol('version', ko.version);
  304.46 +ko.utils = new (function () {
  304.47 +    var stringTrimRegex = /^(\s|\u00A0)+|(\s|\u00A0)+$/g;
  304.48 +
  304.49 +    // Represent the known event types in a compact way, then at runtime transform it into a hash with event name as key (for fast lookup)
  304.50 +    var knownEvents = {}, knownEventTypesByEventName = {};
  304.51 +    var keyEventTypeName = /Firefox\/2/i.test(navigator.userAgent) ? 'KeyboardEvent' : 'UIEvents';
  304.52 +    knownEvents[keyEventTypeName] = ['keyup', 'keydown', 'keypress'];
  304.53 +    knownEvents['MouseEvents'] = ['click', 'dblclick', 'mousedown', 'mouseup', 'mousemove', 'mouseover', 'mouseout', 'mouseenter', 'mouseleave'];
  304.54 +    for (var eventType in knownEvents) {
  304.55 +        var knownEventsForType = knownEvents[eventType];
  304.56 +        if (knownEventsForType.length) {
  304.57 +            for (var i = 0, j = knownEventsForType.length; i < j; i++)
  304.58 +                knownEventTypesByEventName[knownEventsForType[i]] = eventType;
  304.59 +        }
  304.60 +    }
  304.61 +    var eventsThatMustBeRegisteredUsingAttachEvent = { 'propertychange': true }; // Workaround for an IE9 issue - https://github.com/SteveSanderson/knockout/issues/406
  304.62 +
  304.63 +    // Detect IE versions for bug workarounds (uses IE conditionals, not UA string, for robustness)
  304.64 +    // Note that, since IE 10 does not support conditional comments, the following logic only detects IE < 10.
  304.65 +    // Currently this is by design, since IE 10+ behaves correctly when treated as a standard browser.
  304.66 +    // If there is a future need to detect specific versions of IE10+, we will amend this.
  304.67 +    var ieVersion = (function() {
  304.68 +        var version = 3, div = document.createElement('div'), iElems = div.getElementsByTagName('i');
  304.69 +
  304.70 +        // Keep constructing conditional HTML blocks until we hit one that resolves to an empty fragment
  304.71 +        while (
  304.72 +            div.innerHTML = '<!--[if gt IE ' + (++version) + ']><i></i><![endif]-->',
  304.73 +            iElems[0]
  304.74 +        );
  304.75 +        return version > 4 ? version : undefined;
  304.76 +    }());
  304.77 +    var isIe6 = ieVersion === 6,
  304.78 +        isIe7 = ieVersion === 7;
  304.79 +
  304.80 +    function isClickOnCheckableElement(element, eventType) {
  304.81 +        if ((ko.utils.tagNameLower(element) !== "input") || !element.type) return false;
  304.82 +        if (eventType.toLowerCase() != "click") return false;
  304.83 +        var inputType = element.type;
  304.84 +        return (inputType == "checkbox") || (inputType == "radio");
  304.85 +    }
  304.86 +
  304.87 +    return {
  304.88 +        fieldsIncludedWithJsonPost: ['authenticity_token', /^__RequestVerificationToken(_.*)?$/],
  304.89 +
  304.90 +        arrayForEach: function (array, action) {
  304.91 +            for (var i = 0, j = array.length; i < j; i++)
  304.92 +                action(array[i]);
  304.93 +        },
  304.94 +
  304.95 +        arrayIndexOf: function (array, item) {
  304.96 +            if (typeof Array.prototype.indexOf == "function")
  304.97 +                return Array.prototype.indexOf.call(array, item);
  304.98 +            for (var i = 0, j = array.length; i < j; i++)
  304.99 +                if (array[i] === item)
 304.100 +                    return i;
 304.101 +            return -1;
 304.102 +        },
 304.103 +
 304.104 +        arrayFirst: function (array, predicate, predicateOwner) {
 304.105 +            for (var i = 0, j = array.length; i < j; i++)
 304.106 +                if (predicate.call(predicateOwner, array[i]))
 304.107 +                    return array[i];
 304.108 +            return null;
 304.109 +        },
 304.110 +
 304.111 +        arrayRemoveItem: function (array, itemToRemove) {
 304.112 +            var index = ko.utils.arrayIndexOf(array, itemToRemove);
 304.113 +            if (index >= 0)
 304.114 +                array.splice(index, 1);
 304.115 +        },
 304.116 +
 304.117 +        arrayGetDistinctValues: function (array) {
 304.118 +            array = array || [];
 304.119 +            var result = [];
 304.120 +            for (var i = 0, j = array.length; i < j; i++) {
 304.121 +                if (ko.utils.arrayIndexOf(result, array[i]) < 0)
 304.122 +                    result.push(array[i]);
 304.123 +            }
 304.124 +            return result;
 304.125 +        },
 304.126 +
 304.127 +        arrayMap: function (array, mapping) {
 304.128 +            array = array || [];
 304.129 +            var result = [];
 304.130 +            for (var i = 0, j = array.length; i < j; i++)
 304.131 +                result.push(mapping(array[i]));
 304.132 +            return result;
 304.133 +        },
 304.134 +
 304.135 +        arrayFilter: function (array, predicate) {
 304.136 +            array = array || [];
 304.137 +            var result = [];
 304.138 +            for (var i = 0, j = array.length; i < j; i++)
 304.139 +                if (predicate(array[i]))
 304.140 +                    result.push(array[i]);
 304.141 +            return result;
 304.142 +        },
 304.143 +
 304.144 +        arrayPushAll: function (array, valuesToPush) {
 304.145 +            if (valuesToPush instanceof Array)
 304.146 +                array.push.apply(array, valuesToPush);
 304.147 +            else
 304.148 +                for (var i = 0, j = valuesToPush.length; i < j; i++)
 304.149 +                    array.push(valuesToPush[i]);
 304.150 +            return array;
 304.151 +        },
 304.152 +
 304.153 +        extend: function (target, source) {
 304.154 +            if (source) {
 304.155 +                for(var prop in source) {
 304.156 +                    if(source.hasOwnProperty(prop)) {
 304.157 +                        target[prop] = source[prop];
 304.158 +                    }
 304.159 +                }
 304.160 +            }
 304.161 +            return target;
 304.162 +        },
 304.163 +
 304.164 +        emptyDomNode: function (domNode) {
 304.165 +            while (domNode.firstChild) {
 304.166 +                ko.removeNode(domNode.firstChild);
 304.167 +            }
 304.168 +        },
 304.169 +
 304.170 +        moveCleanedNodesToContainerElement: function(nodes) {
 304.171 +            // Ensure it's a real array, as we're about to reparent the nodes and
 304.172 +            // we don't want the underlying collection to change while we're doing that.
 304.173 +            var nodesArray = ko.utils.makeArray(nodes);
 304.174 +
 304.175 +            var container = document.createElement('div');
 304.176 +            for (var i = 0, j = nodesArray.length; i < j; i++) {
 304.177 +                container.appendChild(ko.cleanNode(nodesArray[i]));
 304.178 +            }
 304.179 +            return container;
 304.180 +        },
 304.181 +
 304.182 +        cloneNodes: function (nodesArray, shouldCleanNodes) {
 304.183 +            for (var i = 0, j = nodesArray.length, newNodesArray = []; i < j; i++) {
 304.184 +                var clonedNode = nodesArray[i].cloneNode(true);
 304.185 +                newNodesArray.push(shouldCleanNodes ? ko.cleanNode(clonedNode) : clonedNode);
 304.186 +            }
 304.187 +            return newNodesArray;
 304.188 +        },
 304.189 +
 304.190 +        setDomNodeChildren: function (domNode, childNodes) {
 304.191 +            ko.utils.emptyDomNode(domNode);
 304.192 +            if (childNodes) {
 304.193 +                for (var i = 0, j = childNodes.length; i < j; i++)
 304.194 +                    domNode.appendChild(childNodes[i]);
 304.195 +            }
 304.196 +        },
 304.197 +
 304.198 +        replaceDomNodes: function (nodeToReplaceOrNodeArray, newNodesArray) {
 304.199 +            var nodesToReplaceArray = nodeToReplaceOrNodeArray.nodeType ? [nodeToReplaceOrNodeArray] : nodeToReplaceOrNodeArray;
 304.200 +            if (nodesToReplaceArray.length > 0) {
 304.201 +                var insertionPoint = nodesToReplaceArray[0];
 304.202 +                var parent = insertionPoint.parentNode;
 304.203 +                for (var i = 0, j = newNodesArray.length; i < j; i++)
 304.204 +                    parent.insertBefore(newNodesArray[i], insertionPoint);
 304.205 +                for (var i = 0, j = nodesToReplaceArray.length; i < j; i++) {
 304.206 +                    ko.removeNode(nodesToReplaceArray[i]);
 304.207 +                }
 304.208 +            }
 304.209 +        },
 304.210 +
 304.211 +        setOptionNodeSelectionState: function (optionNode, isSelected) {
 304.212 +            // IE6 sometimes throws "unknown error" if you try to write to .selected directly, whereas Firefox struggles with setAttribute. Pick one based on browser.
 304.213 +            if (ieVersion < 7)
 304.214 +                optionNode.setAttribute("selected", isSelected);
 304.215 +            else
 304.216 +                optionNode.selected = isSelected;
 304.217 +        },
 304.218 +
 304.219 +        stringTrim: function (string) {
 304.220 +            return (string || "").replace(stringTrimRegex, "");
 304.221 +        },
 304.222 +
 304.223 +        stringTokenize: function (string, delimiter) {
 304.224 +            var result = [];
 304.225 +            var tokens = (string || "").split(delimiter);
 304.226 +            for (var i = 0, j = tokens.length; i < j; i++) {
 304.227 +                var trimmed = ko.utils.stringTrim(tokens[i]);
 304.228 +                if (trimmed !== "")
 304.229 +                    result.push(trimmed);
 304.230 +            }
 304.231 +            return result;
 304.232 +        },
 304.233 +
 304.234 +        stringStartsWith: function (string, startsWith) {
 304.235 +            string = string || "";
 304.236 +            if (startsWith.length > string.length)
 304.237 +                return false;
 304.238 +            return string.substring(0, startsWith.length) === startsWith;
 304.239 +        },
 304.240 +
 304.241 +        domNodeIsContainedBy: function (node, containedByNode) {
 304.242 +            if (containedByNode.compareDocumentPosition)
 304.243 +                return (containedByNode.compareDocumentPosition(node) & 16) == 16;
 304.244 +            while (node != null) {
 304.245 +                if (node == containedByNode)
 304.246 +                    return true;
 304.247 +                node = node.parentNode;
 304.248 +            }
 304.249 +            return false;
 304.250 +        },
 304.251 +
 304.252 +        domNodeIsAttachedToDocument: function (node) {
 304.253 +            return ko.utils.domNodeIsContainedBy(node, node.ownerDocument);
 304.254 +        },
 304.255 +
 304.256 +        tagNameLower: function(element) {
 304.257 +            // For HTML elements, tagName will always be upper case; for XHTML elements, it'll be lower case.
 304.258 +            // Possible future optimization: If we know it's an element from an XHTML document (not HTML),
 304.259 +            // we don't need to do the .toLowerCase() as it will always be lower case anyway.
 304.260 +            return element && element.tagName && element.tagName.toLowerCase();
 304.261 +        },
 304.262 +
 304.263 +        registerEventHandler: function (element, eventType, handler) {
 304.264 +            var mustUseAttachEvent = ieVersion && eventsThatMustBeRegisteredUsingAttachEvent[eventType];
 304.265 +            if (!mustUseAttachEvent && typeof jQuery != "undefined") {
 304.266 +                if (isClickOnCheckableElement(element, eventType)) {
 304.267 +                    // For click events on checkboxes, jQuery interferes with the event handling in an awkward way:
 304.268 +                    // it toggles the element checked state *after* the click event handlers run, whereas native
 304.269 +                    // click events toggle the checked state *before* the event handler.
 304.270 +                    // Fix this by intecepting the handler and applying the correct checkedness before it runs.
 304.271 +                    var originalHandler = handler;
 304.272 +                    handler = function(event, eventData) {
 304.273 +                        var jQuerySuppliedCheckedState = this.checked;
 304.274 +                        if (eventData)
 304.275 +                            this.checked = eventData.checkedStateBeforeEvent !== true;
 304.276 +                        originalHandler.call(this, event);
 304.277 +                        this.checked = jQuerySuppliedCheckedState; // Restore the state jQuery applied
 304.278 +                    };
 304.279 +                }
 304.280 +                jQuery(element)['bind'](eventType, handler);
 304.281 +            } else if (!mustUseAttachEvent && typeof element.addEventListener == "function")
 304.282 +                element.addEventListener(eventType, handler, false);
 304.283 +            else if (typeof element.attachEvent != "undefined")
 304.284 +                element.attachEvent("on" + eventType, function (event) {
 304.285 +                    handler.call(element, event);
 304.286 +                });
 304.287 +            else
 304.288 +                throw new Error("Browser doesn't support addEventListener or attachEvent");
 304.289 +        },
 304.290 +
 304.291 +        triggerEvent: function (element, eventType) {
 304.292 +            if (!(element && element.nodeType))
 304.293 +                throw new Error("element must be a DOM node when calling triggerEvent");
 304.294 +
 304.295 +            if (typeof jQuery != "undefined") {
 304.296 +                var eventData = [];
 304.297 +                if (isClickOnCheckableElement(element, eventType)) {
 304.298 +                    // Work around the jQuery "click events on checkboxes" issue described above by storing the original checked state before triggering the handler
 304.299 +                    eventData.push({ checkedStateBeforeEvent: element.checked });
 304.300 +                }
 304.301 +                jQuery(element)['trigger'](eventType, eventData);
 304.302 +            } else if (typeof document.createEvent == "function") {
 304.303 +                if (typeof element.dispatchEvent == "function") {
 304.304 +                    var eventCategory = knownEventTypesByEventName[eventType] || "HTMLEvents";
 304.305 +                    var event = document.createEvent(eventCategory);
 304.306 +                    event.initEvent(eventType, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, element);
 304.307 +                    element.dispatchEvent(event);
 304.308 +                }
 304.309 +                else
 304.310 +                    throw new Error("The supplied element doesn't support dispatchEvent");
 304.311 +            } else if (typeof element.fireEvent != "undefined") {
 304.312 +                // Unlike other browsers, IE doesn't change the checked state of checkboxes/radiobuttons when you trigger their "click" event
 304.313 +                // so to make it consistent, we'll do it manually here
 304.314 +                if (isClickOnCheckableElement(element, eventType))
 304.315 +                    element.checked = element.checked !== true;
 304.316 +                element.fireEvent("on" + eventType);
 304.317 +            }
 304.318 +            else
 304.319 +                throw new Error("Browser doesn't support triggering events");
 304.320 +        },
 304.321 +
 304.322 +        unwrapObservable: function (value) {
 304.323 +            return ko.isObservable(value) ? value() : value;
 304.324 +        },
 304.325 +
 304.326 +        peekObservable: function (value) {
 304.327 +            return ko.isObservable(value) ? value.peek() : value;
 304.328 +        },
 304.329 +
 304.330 +        toggleDomNodeCssClass: function (node, classNames, shouldHaveClass) {
 304.331 +            if (classNames) {
 304.332 +                var cssClassNameRegex = /[\w-]+/g,
 304.333 +                    currentClassNames = node.className.match(cssClassNameRegex) || [];
 304.334 +                ko.utils.arrayForEach(classNames.match(cssClassNameRegex), function(className) {
 304.335 +                    var indexOfClass = ko.utils.arrayIndexOf(currentClassNames, className);
 304.336 +                    if (indexOfClass >= 0) {
 304.337 +                        if (!shouldHaveClass)
 304.338 +                            currentClassNames.splice(indexOfClass, 1);
 304.339 +                    } else {
 304.340 +                        if (shouldHaveClass)
 304.341 +                            currentClassNames.push(className);
 304.342 +                    }
 304.343 +                });
 304.344 +                node.className = currentClassNames.join(" ");
 304.345 +            }
 304.346 +        },
 304.347 +
 304.348 +        setTextContent: function(element, textContent) {
 304.349 +            var value = ko.utils.unwrapObservable(textContent);
 304.350 +            if ((value === null) || (value === undefined))
 304.351 +                value = "";
 304.352 +
 304.353 +            if (element.nodeType === 3) {
 304.354 +                element.data = value;
 304.355 +            } else {
 304.356 +                // We need there to be exactly one child: a text node.
 304.357 +                // If there are no children, more than one, or if it's not a text node,
 304.358 +                // we'll clear everything and create a single text node.
 304.359 +                var innerTextNode = ko.virtualElements.firstChild(element);
 304.360 +                if (!innerTextNode || innerTextNode.nodeType != 3 || ko.virtualElements.nextSibling(innerTextNode)) {
 304.361 +                    ko.virtualElements.setDomNodeChildren(element, [document.createTextNode(value)]);
 304.362 +                } else {
 304.363 +                    innerTextNode.data = value;
 304.364 +                }
 304.365 +
 304.366 +                ko.utils.forceRefresh(element);
 304.367 +            }
 304.368 +        },
 304.369 +
 304.370 +        setElementName: function(element, name) {
 304.371 +            element.name = name;
 304.372 +
 304.373 +            // Workaround IE 6/7 issue
 304.374 +            // - https://github.com/SteveSanderson/knockout/issues/197
 304.375 +            // - http://www.matts411.com/post/setting_the_name_attribute_in_ie_dom/
 304.376 +            if (ieVersion <= 7) {
 304.377 +                try {
 304.378 +                    element.mergeAttributes(document.createElement("<input name='" + element.name + "'/>"), false);
 304.379 +                }
 304.380 +                catch(e) {} // For IE9 with doc mode "IE9 Standards" and browser mode "IE9 Compatibility View"
 304.381 +            }
 304.382 +        },
 304.383 +
 304.384 +        forceRefresh: function(node) {
 304.385 +            // Workaround for an IE9 rendering bug - https://github.com/SteveSanderson/knockout/issues/209
 304.386 +            if (ieVersion >= 9) {
 304.387 +                // For text nodes and comment nodes (most likely virtual elements), we will have to refresh the container
 304.388 +                var elem = node.nodeType == 1 ? node : node.parentNode;
 304.389 +                if (elem.style)
 304.390 +                    elem.style.zoom = elem.style.zoom;
 304.391 +            }
 304.392 +        },
 304.393 +
 304.394 +        ensureSelectElementIsRenderedCorrectly: function(selectElement) {
 304.395 +            // Workaround for IE9 rendering bug - it doesn't reliably display all the text in dynamically-added select boxes unless you force it to re-render by updating the width.
 304.396 +            // (See https://github.com/SteveSanderson/knockout/issues/312, http://stackoverflow.com/questions/5908494/select-only-shows-first-char-of-selected-option)
 304.397 +            if (ieVersion >= 9) {
 304.398 +                var originalWidth = selectElement.style.width;
 304.399 +                selectElement.style.width = 0;
 304.400 +                selectElement.style.width = originalWidth;
 304.401 +            }
 304.402 +        },
 304.403 +
 304.404 +        range: function (min, max) {
 304.405 +            min = ko.utils.unwrapObservable(min);
 304.406 +            max = ko.utils.unwrapObservable(max);
 304.407 +            var result = [];
 304.408 +            for (var i = min; i <= max; i++)
 304.409 +                result.push(i);
 304.410 +            return result;
 304.411 +        },
 304.412 +
 304.413 +        makeArray: function(arrayLikeObject) {
 304.414 +            var result = [];
 304.415 +            for (var i = 0, j = arrayLikeObject.length; i < j; i++) {
 304.416 +                result.push(arrayLikeObject[i]);
 304.417 +            };
 304.418 +            return result;
 304.419 +        },
 304.420 +
 304.421 +        isIe6 : isIe6,
 304.422 +        isIe7 : isIe7,
 304.423 +        ieVersion : ieVersion,
 304.424 +
 304.425 +        getFormFields: function(form, fieldName) {
 304.426 +            var fields = ko.utils.makeArray(form.getElementsByTagName("input")).concat(ko.utils.makeArray(form.getElementsByTagName("textarea")));
 304.427 +            var isMatchingField = (typeof fieldName == 'string')
 304.428 +                ? function(field) { return field.name === fieldName }
 304.429 +                : function(field) { return fieldName.test(field.name) }; // Treat fieldName as regex or object containing predicate
 304.430 +            var matches = [];
 304.431 +            for (var i = fields.length - 1; i >= 0; i--) {
 304.432 +                if (isMatchingField(fields[i]))
 304.433 +                    matches.push(fields[i]);
 304.434 +            };
 304.435 +            return matches;
 304.436 +        },
 304.437 +
 304.438 +        parseJson: function (jsonString) {
 304.439 +            if (typeof jsonString == "string") {
 304.440 +                jsonString = ko.utils.stringTrim(jsonString);
 304.441 +                if (jsonString) {
 304.442 +                    if (window.JSON && window.JSON.parse) // Use native parsing where available
 304.443 +                        return window.JSON.parse(jsonString);
 304.444 +                    return (new Function("return " + jsonString))(); // Fallback on less safe parsing for older browsers
 304.445 +                }
 304.446 +            }
 304.447 +            return null;
 304.448 +        },
 304.449 +
 304.450 +        stringifyJson: function (data, replacer, space) {   // replacer and space are optional
 304.451 +            if ((typeof JSON == "undefined") || (typeof JSON.stringify == "undefined"))
 304.452 +                throw new Error("Cannot find JSON.stringify(). Some browsers (e.g., IE < 8) don't support it natively, but you can overcome this by adding a script reference to json2.js, downloadable from http://www.json.org/json2.js");
 304.453 +            return JSON.stringify(ko.utils.unwrapObservable(data), replacer, space);
 304.454 +        },
 304.455 +
 304.456 +        postJson: function (urlOrForm, data, options) {
 304.457 +            options = options || {};
 304.458 +            var params = options['params'] || {};
 304.459 +            var includeFields = options['includeFields'] || this.fieldsIncludedWithJsonPost;
 304.460 +            var url = urlOrForm;
 304.461 +
 304.462 +            // If we were given a form, use its 'action' URL and pick out any requested field values
 304.463 +            if((typeof urlOrForm == 'object') && (ko.utils.tagNameLower(urlOrForm) === "form")) {
 304.464 +                var originalForm = urlOrForm;
 304.465 +                url = originalForm.action;
 304.466 +                for (var i = includeFields.length - 1; i >= 0; i--) {
 304.467 +                    var fields = ko.utils.getFormFields(originalForm, includeFields[i]);
 304.468 +                    for (var j = fields.length - 1; j >= 0; j--)
 304.469 +                        params[fields[j].name] = fields[j].value;
 304.470 +                }
 304.471 +            }
 304.472 +
 304.473 +            data = ko.utils.unwrapObservable(data);
 304.474 +            var form = document.createElement("form");
 304.475 +            form.style.display = "none";
 304.476 +            form.action = url;
 304.477 +            form.method = "post";
 304.478 +            for (var key in data) {
 304.479 +                var input = document.createElement("input");
 304.480 +                input.name = key;
 304.481 +                input.value = ko.utils.stringifyJson(ko.utils.unwrapObservable(data[key]));
 304.482 +                form.appendChild(input);
 304.483 +            }
 304.484 +            for (var key in params) {
 304.485 +                var input = document.createElement("input");
 304.486 +                input.name = key;
 304.487 +                input.value = params[key];
 304.488 +                form.appendChild(input);
 304.489 +            }
 304.490 +            document.body.appendChild(form);
 304.491 +            options['submitter'] ? options['submitter'](form) : form.submit();
 304.492 +            setTimeout(function () { form.parentNode.removeChild(form); }, 0);
 304.493 +        }
 304.494 +    }
 304.495 +})();
 304.496 +
 304.497 +ko.exportSymbol('utils', ko.utils);
 304.498 +ko.exportSymbol('utils.arrayForEach', ko.utils.arrayForEach);
 304.499 +ko.exportSymbol('utils.arrayFirst', ko.utils.arrayFirst);
 304.500 +ko.exportSymbol('utils.arrayFilter', ko.utils.arrayFilter);
 304.501 +ko.exportSymbol('utils.arrayGetDistinctValues', ko.utils.arrayGetDistinctValues);
 304.502 +ko.exportSymbol('utils.arrayIndexOf', ko.utils.arrayIndexOf);
 304.503 +ko.exportSymbol('utils.arrayMap', ko.utils.arrayMap);
 304.504 +ko.exportSymbol('utils.arrayPushAll', ko.utils.arrayPushAll);
 304.505 +ko.exportSymbol('utils.arrayRemoveItem', ko.utils.arrayRemoveItem);
 304.506 +ko.exportSymbol('utils.extend', ko.utils.extend);
 304.507 +ko.exportSymbol('utils.fieldsIncludedWithJsonPost', ko.utils.fieldsIncludedWithJsonPost);
 304.508 +ko.exportSymbol('utils.getFormFields', ko.utils.getFormFields);
 304.509 +ko.exportSymbol('utils.peekObservable', ko.utils.peekObservable);
 304.510 +ko.exportSymbol('utils.postJson', ko.utils.postJson);
 304.511 +ko.exportSymbol('utils.parseJson', ko.utils.parseJson);
 304.512 +ko.exportSymbol('utils.registerEventHandler', ko.utils.registerEventHandler);
 304.513 +ko.exportSymbol('utils.stringifyJson', ko.utils.stringifyJson);
 304.514 +ko.exportSymbol('utils.range', ko.utils.range);
 304.515 +ko.exportSymbol('utils.toggleDomNodeCssClass', ko.utils.toggleDomNodeCssClass);
 304.516 +ko.exportSymbol('utils.triggerEvent', ko.utils.triggerEvent);
 304.517 +ko.exportSymbol('utils.unwrapObservable', ko.utils.unwrapObservable);
 304.518 +
 304.519 +if (!Function.prototype['bind']) {
 304.520 +    // Function.prototype.bind is a standard part of ECMAScript 5th Edition (December 2009, http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf)
 304.521 +    // In case the browser doesn't implement it natively, provide a JavaScript implementation. This implementation is based on the one in prototype.js
 304.522 +    Function.prototype['bind'] = function (object) {
 304.523 +        var originalFunction = this, args = Array.prototype.slice.call(arguments), object = args.shift();
 304.524 +        return function () {
 304.525 +            return originalFunction.apply(object, args.concat(Array.prototype.slice.call(arguments)));
 304.526 +        };
 304.527 +    };
 304.528 +}
 304.529 +
 304.530 +ko.utils.domData = new (function () {
 304.531 +    var uniqueId = 0;
 304.532 +    var dataStoreKeyExpandoPropertyName = "__ko__" + (new Date).getTime();
 304.533 +    var dataStore = {};
 304.534 +    return {
 304.535 +        get: function (node, key) {
 304.536 +            var allDataForNode = ko.utils.domData.getAll(node, false);
 304.537 +            return allDataForNode === undefined ? undefined : allDataForNode[key];
 304.538 +        },
 304.539 +        set: function (node, key, value) {
 304.540 +            if (value === undefined) {
 304.541 +                // Make sure we don't actually create a new domData key if we are actually deleting a value
 304.542 +                if (ko.utils.domData.getAll(node, false) === undefined)
 304.543 +                    return;
 304.544 +            }
 304.545 +            var allDataForNode = ko.utils.domData.getAll(node, true);
 304.546 +            allDataForNode[key] = value;
 304.547 +        },
 304.548 +        getAll: function (node, createIfNotFound) {
 304.549 +            var dataStoreKey = node[dataStoreKeyExpandoPropertyName];
 304.550 +            var hasExistingDataStore = dataStoreKey && (dataStoreKey !== "null") && dataStore[dataStoreKey];
 304.551 +            if (!hasExistingDataStore) {
 304.552 +                if (!createIfNotFound)
 304.553 +                    return undefined;
 304.554 +                dataStoreKey = node[dataStoreKeyExpandoPropertyName] = "ko" + uniqueId++;
 304.555 +                dataStore[dataStoreKey] = {};
 304.556 +            }
 304.557 +            return dataStore[dataStoreKey];
 304.558 +        },
 304.559 +        clear: function (node) {
 304.560 +            var dataStoreKey = node[dataStoreKeyExpandoPropertyName];
 304.561 +            if (dataStoreKey) {
 304.562 +                delete dataStore[dataStoreKey];
 304.563 +                node[dataStoreKeyExpandoPropertyName] = null;
 304.564 +                return true; // Exposing "did clean" flag purely so specs can infer whether things have been cleaned up as intended
 304.565 +            }
 304.566 +            return false;
 304.567 +        }
 304.568 +    }
 304.569 +})();
 304.570 +
 304.571 +ko.exportSymbol('utils.domData', ko.utils.domData);
 304.572 +ko.exportSymbol('utils.domData.clear', ko.utils.domData.clear); // Exporting only so specs can clear up after themselves fully
 304.573 +
 304.574 +ko.utils.domNodeDisposal = new (function () {
 304.575 +    var domDataKey = "__ko_domNodeDisposal__" + (new Date).getTime();
 304.576 +    var cleanableNodeTypes = { 1: true, 8: true, 9: true };       // Element, Comment, Document
 304.577 +    var cleanableNodeTypesWithDescendants = { 1: true, 9: true }; // Element, Document
 304.578 +
 304.579 +    function getDisposeCallbacksCollection(node, createIfNotFound) {
 304.580 +        var allDisposeCallbacks = ko.utils.domData.get(node, domDataKey);
 304.581 +        if ((allDisposeCallbacks === undefined) && createIfNotFound) {
 304.582 +            allDisposeCallbacks = [];
 304.583 +            ko.utils.domData.set(node, domDataKey, allDisposeCallbacks);
 304.584 +        }
 304.585 +        return allDisposeCallbacks;
 304.586 +    }
 304.587 +    function destroyCallbacksCollection(node) {
 304.588 +        ko.utils.domData.set(node, domDataKey, undefined);
 304.589 +    }
 304.590 +
 304.591 +    function cleanSingleNode(node) {
 304.592 +        // Run all the dispose callbacks
 304.593 +        var callbacks = getDisposeCallbacksCollection(node, false);
 304.594 +        if (callbacks) {
 304.595 +            callbacks = callbacks.slice(0); // Clone, as the array may be modified during iteration (typically, callbacks will remove themselves)
 304.596 +            for (var i = 0; i < callbacks.length; i++)
 304.597 +                callbacks[i](node);
 304.598 +        }
 304.599 +
 304.600 +        // Also erase the DOM data
 304.601 +        ko.utils.domData.clear(node);
 304.602 +
 304.603 +        // Special support for jQuery here because it's so commonly used.
 304.604 +        // Many jQuery plugins (including jquery.tmpl) store data using jQuery's equivalent of domData
 304.605 +        // so notify it to tear down any resources associated with the node & descendants here.
 304.606 +        if ((typeof jQuery == "function") && (typeof jQuery['cleanData'] == "function"))
 304.607 +            jQuery['cleanData']([node]);
 304.608 +
 304.609 +        // Also clear any immediate-child comment nodes, as these wouldn't have been found by
 304.610 +        // node.getElementsByTagName("*") in cleanNode() (comment nodes aren't elements)
 304.611 +        if (cleanableNodeTypesWithDescendants[node.nodeType])
 304.612 +            cleanImmediateCommentTypeChildren(node);
 304.613 +    }
 304.614 +
 304.615 +    function cleanImmediateCommentTypeChildren(nodeWithChildren) {
 304.616 +        var child, nextChild = nodeWithChildren.firstChild;
 304.617 +        while (child = nextChild) {
 304.618 +            nextChild = child.nextSibling;
 304.619 +            if (child.nodeType === 8)
 304.620 +                cleanSingleNode(child);
 304.621 +        }
 304.622 +    }
 304.623 +
 304.624 +    return {
 304.625 +        addDisposeCallback : function(node, callback) {
 304.626 +            if (typeof callback != "function")
 304.627 +                throw new Error("Callback must be a function");
 304.628 +            getDisposeCallbacksCollection(node, true).push(callback);
 304.629 +        },
 304.630 +
 304.631 +        removeDisposeCallback : function(node, callback) {
 304.632 +            var callbacksCollection = getDisposeCallbacksCollection(node, false);
 304.633 +            if (callbacksCollection) {
 304.634 +                ko.utils.arrayRemoveItem(callbacksCollection, callback);
 304.635 +                if (callbacksCollection.length == 0)
 304.636 +                    destroyCallbacksCollection(node);
 304.637 +            }
 304.638 +        },
 304.639 +
 304.640 +        cleanNode : function(node) {
 304.641 +            // First clean this node, where applicable
 304.642 +            if (cleanableNodeTypes[node.nodeType]) {
 304.643 +                cleanSingleNode(node);
 304.644 +
 304.645 +                // ... then its descendants, where applicable
 304.646 +                if (cleanableNodeTypesWithDescendants[node.nodeType]) {
 304.647 +                    // Clone the descendants list in case it changes during iteration
 304.648 +                    var descendants = [];
 304.649 +                    ko.utils.arrayPushAll(descendants, node.getElementsByTagName("*"));
 304.650 +                    for (var i = 0, j = descendants.length; i < j; i++)
 304.651 +                        cleanSingleNode(descendants[i]);
 304.652 +                }
 304.653 +            }
 304.654 +            return node;
 304.655 +        },
 304.656 +
 304.657 +        removeNode : function(node) {
 304.658 +            ko.cleanNode(node);
 304.659 +            if (node.parentNode)
 304.660 +                node.parentNode.removeChild(node);
 304.661 +        }
 304.662 +    }
 304.663 +})();
 304.664 +ko.cleanNode = ko.utils.domNodeDisposal.cleanNode; // Shorthand name for convenience
 304.665 +ko.removeNode = ko.utils.domNodeDisposal.removeNode; // Shorthand name for convenience
 304.666 +ko.exportSymbol('cleanNode', ko.cleanNode);
 304.667 +ko.exportSymbol('removeNode', ko.removeNode);
 304.668 +ko.exportSymbol('utils.domNodeDisposal', ko.utils.domNodeDisposal);
 304.669 +ko.exportSymbol('utils.domNodeDisposal.addDisposeCallback', ko.utils.domNodeDisposal.addDisposeCallback);
 304.670 +ko.exportSymbol('utils.domNodeDisposal.removeDisposeCallback', ko.utils.domNodeDisposal.removeDisposeCallback);
 304.671 +(function () {
 304.672 +    var leadingCommentRegex = /^(\s*)<!--(.*?)-->/;
 304.673 +
 304.674 +    function simpleHtmlParse(html) {
 304.675 +        // Based on jQuery's "clean" function, but only accounting for table-related elements.
 304.676 +        // If you have referenced jQuery, this won't be used anyway - KO will use jQuery's "clean" function directly
 304.677 +
 304.678 +        // Note that there's still an issue in IE < 9 whereby it will discard comment nodes that are the first child of
 304.679 +        // a descendant node. For example: "<div><!-- mycomment -->abc</div>" will get parsed as "<div>abc</div>"
 304.680 +        // This won't affect anyone who has referenced jQuery, and there's always the workaround of inserting a dummy node
 304.681 +        // (possibly a text node) in front of the comment. So, KO does not attempt to workaround this IE issue automatically at present.
 304.682 +
 304.683 +        // Trim whitespace, otherwise indexOf won't work as expected
 304.684 +        var tags = ko.utils.stringTrim(html).toLowerCase(), div = document.createElement("div");
 304.685 +
 304.686 +        // Finds the first match from the left column, and returns the corresponding "wrap" data from the right column
 304.687 +        var wrap = tags.match(/^<(thead|tbody|tfoot)/)              && [1, "<table>", "</table>"] ||
 304.688 +                   !tags.indexOf("<tr")                             && [2, "<table><tbody>", "</tbody></table>"] ||
 304.689 +                   (!tags.indexOf("<td") || !tags.indexOf("<th"))   && [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
 304.690 +                   /* anything else */                                 [0, "", ""];
 304.691 +
 304.692 +        // Go to html and back, then peel off extra wrappers
 304.693 +        // Note that we always prefix with some dummy text, because otherwise, IE<9 will strip out leading comment nodes in descendants. Total madness.
 304.694 +        var markup = "ignored<div>" + wrap[1] + html + wrap[2] + "</div>";
 304.695 +        if (typeof window['innerShiv'] == "function") {
 304.696 +            div.appendChild(window['innerShiv'](markup));
 304.697 +        } else {
 304.698 +            div.innerHTML = markup;
 304.699 +        }
 304.700 +
 304.701 +        // Move to the right depth
 304.702 +        while (wrap[0]--)
 304.703 +            div = div.lastChild;
 304.704 +
 304.705 +        return ko.utils.makeArray(div.lastChild.childNodes);
 304.706 +    }
 304.707 +
 304.708 +    function jQueryHtmlParse(html) {
 304.709 +        // jQuery's "parseHTML" function was introduced in jQuery 1.8.0 and is a documented public API.
 304.710 +        if (jQuery['parseHTML']) {
 304.711 +            return jQuery['parseHTML'](html);
 304.712 +        } else {
 304.713 +            // For jQuery < 1.8.0, we fall back on the undocumented internal "clean" function.
 304.714 +            var elems = jQuery['clean']([html]);
 304.715 +
 304.716 +            // As of jQuery 1.7.1, jQuery parses the HTML by appending it to some dummy parent nodes held in an in-memory document fragment.
 304.717 +            // Unfortunately, it never clears the dummy parent nodes from the document fragment, so it leaks memory over time.
 304.718 +            // Fix this by finding the top-most dummy parent element, and detaching it from its owner fragment.
 304.719 +            if (elems && elems[0]) {
 304.720 +                // Find the top-most parent element that's a direct child of a document fragment
 304.721 +                var elem = elems[0];
 304.722 +                while (elem.parentNode && elem.parentNode.nodeType !== 11 /* i.e., DocumentFragment */)
 304.723 +                    elem = elem.parentNode;
 304.724 +                // ... then detach it
 304.725 +                if (elem.parentNode)
 304.726 +                    elem.parentNode.removeChild(elem);
 304.727 +            }
 304.728 +
 304.729 +            return elems;
 304.730 +        }
 304.731 +    }
 304.732 +
 304.733 +    ko.utils.parseHtmlFragment = function(html) {
 304.734 +        return typeof jQuery != 'undefined' ? jQueryHtmlParse(html)   // As below, benefit from jQuery's optimisations where possible
 304.735 +                                            : simpleHtmlParse(html);  // ... otherwise, this simple logic will do in most common cases.
 304.736 +    };
 304.737 +
 304.738 +    ko.utils.setHtml = function(node, html) {
 304.739 +        ko.utils.emptyDomNode(node);
 304.740 +
 304.741 +        // There's no legitimate reason to display a stringified observable without unwrapping it, so we'll unwrap it
 304.742 +        html = ko.utils.unwrapObservable(html);
 304.743 +
 304.744 +        if ((html !== null) && (html !== undefined)) {
 304.745 +            if (typeof html != 'string')
 304.746 +                html = html.toString();
 304.747 +
 304.748 +            // jQuery contains a lot of sophisticated code to parse arbitrary HTML fragments,
 304.749 +            // for example <tr> elements which are not normally allowed to exist on their own.
 304.750 +            // If you've referenced jQuery we'll use that rather than duplicating its code.
 304.751 +            if (typeof jQuery != 'undefined') {
 304.752 +                jQuery(node)['html'](html);
 304.753 +            } else {
 304.754 +                // ... otherwise, use KO's own parsing logic.
 304.755 +                var parsedNodes = ko.utils.parseHtmlFragment(html);
 304.756 +                for (var i = 0; i < parsedNodes.length; i++)
 304.757 +                    node.appendChild(parsedNodes[i]);
 304.758 +            }
 304.759 +        }
 304.760 +    };
 304.761 +})();
 304.762 +
 304.763 +ko.exportSymbol('utils.parseHtmlFragment', ko.utils.parseHtmlFragment);
 304.764 +ko.exportSymbol('utils.setHtml', ko.utils.setHtml);
 304.765 +
 304.766 +ko.memoization = (function () {
 304.767 +    var memos = {};
 304.768 +
 304.769 +    function randomMax8HexChars() {
 304.770 +        return (((1 + Math.random()) * 0x100000000) | 0).toString(16).substring(1);
 304.771 +    }
 304.772 +    function generateRandomId() {
 304.773 +        return randomMax8HexChars() + randomMax8HexChars();
 304.774 +    }
 304.775 +    function findMemoNodes(rootNode, appendToArray) {
 304.776 +        if (!rootNode)
 304.777 +            return;
 304.778 +        if (rootNode.nodeType == 8) {
 304.779 +            var memoId = ko.memoization.parseMemoText(rootNode.nodeValue);
 304.780 +            if (memoId != null)
 304.781 +                appendToArray.push({ domNode: rootNode, memoId: memoId });
 304.782 +        } else if (rootNode.nodeType == 1) {
 304.783 +            for (var i = 0, childNodes = rootNode.childNodes, j = childNodes.length; i < j; i++)
 304.784 +                findMemoNodes(childNodes[i], appendToArray);
 304.785 +        }
 304.786 +    }
 304.787 +
 304.788 +    return {
 304.789 +        memoize: function (callback) {
 304.790 +            if (typeof callback != "function")
 304.791 +                throw new Error("You can only pass a function to ko.memoization.memoize()");
 304.792 +            var memoId = generateRandomId();
 304.793 +            memos[memoId] = callback;
 304.794 +            return "<!--[ko_memo:" + memoId + "]-->";
 304.795 +        },
 304.796 +
 304.797 +        unmemoize: function (memoId, callbackParams) {
 304.798 +            var callback = memos[memoId];
 304.799 +            if (callback === undefined)
 304.800 +                throw new Error("Couldn't find any memo with ID " + memoId + ". Perhaps it's already been unmemoized.");
 304.801 +            try {
 304.802 +                callback.apply(null, callbackParams || []);
 304.803 +                return true;
 304.804 +            }
 304.805 +            finally { delete memos[memoId]; }
 304.806 +        },
 304.807 +
 304.808 +        unmemoizeDomNodeAndDescendants: function (domNode, extraCallbackParamsArray) {
 304.809 +            var memos = [];
 304.810 +            findMemoNodes(domNode, memos);
 304.811 +            for (var i = 0, j = memos.length; i < j; i++) {
 304.812 +                var node = memos[i].domNode;
 304.813 +                var combinedParams = [node];
 304.814 +                if (extraCallbackParamsArray)
 304.815 +                    ko.utils.arrayPushAll(combinedParams, extraCallbackParamsArray);
 304.816 +                ko.memoization.unmemoize(memos[i].memoId, combinedParams);
 304.817 +                node.nodeValue = ""; // Neuter this node so we don't try to unmemoize it again
 304.818 +                if (node.parentNode)
 304.819 +                    node.parentNode.removeChild(node); // If possible, erase it totally (not always possible - someone else might just hold a reference to it then call unmemoizeDomNodeAndDescendants again)
 304.820 +            }
 304.821 +        },
 304.822 +
 304.823 +        parseMemoText: function (memoText) {
 304.824 +            var match = memoText.match(/^\[ko_memo\:(.*?)\]$/);
 304.825 +            return match ? match[1] : null;
 304.826 +        }
 304.827 +    };
 304.828 +})();
 304.829 +
 304.830 +ko.exportSymbol('memoization', ko.memoization);
 304.831 +ko.exportSymbol('memoization.memoize', ko.memoization.memoize);
 304.832 +ko.exportSymbol('memoization.unmemoize', ko.memoization.unmemoize);
 304.833 +ko.exportSymbol('memoization.parseMemoText', ko.memoization.parseMemoText);
 304.834 +ko.exportSymbol('memoization.unmemoizeDomNodeAndDescendants', ko.memoization.unmemoizeDomNodeAndDescendants);
 304.835 +ko.extenders = {
 304.836 +    'throttle': function(target, timeout) {
 304.837 +        // Throttling means two things:
 304.838 +
 304.839 +        // (1) For dependent observables, we throttle *evaluations* so that, no matter how fast its dependencies
 304.840 +        //     notify updates, the target doesn't re-evaluate (and hence doesn't notify) faster than a certain rate
 304.841 +        target['throttleEvaluation'] = timeout;
 304.842 +
 304.843 +        // (2) For writable targets (observables, or writable dependent observables), we throttle *writes*
 304.844 +        //     so the target cannot change value synchronously or faster than a certain rate
 304.845 +        var writeTimeoutInstance = null;
 304.846 +        return ko.dependentObservable({
 304.847 +            'read': target,
 304.848 +            'write': function(value) {
 304.849 +                clearTimeout(writeTimeoutInstance);
 304.850 +                writeTimeoutInstance = setTimeout(function() {
 304.851 +                    target(value);
 304.852 +                }, timeout);
 304.853 +            }
 304.854 +        });
 304.855 +    },
 304.856 +
 304.857 +    'notify': function(target, notifyWhen) {
 304.858 +        target["equalityComparer"] = notifyWhen == "always"
 304.859 +            ? function() { return false } // Treat all values as not equal
 304.860 +            : ko.observable["fn"]["equalityComparer"];
 304.861 +        return target;
 304.862 +    }
 304.863 +};
 304.864 +
 304.865 +function applyExtenders(requestedExtenders) {
 304.866 +    var target = this;
 304.867 +    if (requestedExtenders) {
 304.868 +        for (var key in requestedExtenders) {
 304.869 +            var extenderHandler = ko.extenders[key];
 304.870 +            if (typeof extenderHandler == 'function') {
 304.871 +                target = extenderHandler(target, requestedExtenders[key]);
 304.872 +            }
 304.873 +        }
 304.874 +    }
 304.875 +    return target;
 304.876 +}
 304.877 +
 304.878 +ko.exportSymbol('extenders', ko.extenders);
 304.879 +
 304.880 +ko.subscription = function (target, callback, disposeCallback) {
 304.881 +    this.target = target;
 304.882 +    this.callback = callback;
 304.883 +    this.disposeCallback = disposeCallback;
 304.884 +    ko.exportProperty(this, 'dispose', this.dispose);
 304.885 +};
 304.886 +ko.subscription.prototype.dispose = function () {
 304.887 +    this.isDisposed = true;
 304.888 +    this.disposeCallback();
 304.889 +};
 304.890 +
 304.891 +ko.subscribable = function () {
 304.892 +    this._subscriptions = {};
 304.893 +
 304.894 +    ko.utils.extend(this, ko.subscribable['fn']);
 304.895 +    ko.exportProperty(this, 'subscribe', this.subscribe);
 304.896 +    ko.exportProperty(this, 'extend', this.extend);
 304.897 +    ko.exportProperty(this, 'getSubscriptionsCount', this.getSubscriptionsCount);
 304.898 +}
 304.899 +
 304.900 +var defaultEvent = "change";
 304.901 +
 304.902 +ko.subscribable['fn'] = {
 304.903 +    subscribe: function (callback, callbackTarget, event) {
 304.904 +        event = event || defaultEvent;
 304.905 +        var boundCallback = callbackTarget ? callback.bind(callbackTarget) : callback;
 304.906 +
 304.907 +        var subscription = new ko.subscription(this, boundCallback, function () {
 304.908 +            ko.utils.arrayRemoveItem(this._subscriptions[event], subscription);
 304.909 +        }.bind(this));
 304.910 +
 304.911 +        if (!this._subscriptions[event])
 304.912 +            this._subscriptions[event] = [];
 304.913 +        this._subscriptions[event].push(subscription);
 304.914 +        return subscription;
 304.915 +    },
 304.916 +
 304.917 +    "notifySubscribers": function (valueToNotify, event) {
 304.918 +        event = event || defaultEvent;
 304.919 +        if (this._subscriptions[event]) {
 304.920 +            ko.dependencyDetection.ignore(function() {
 304.921 +                ko.utils.arrayForEach(this._subscriptions[event].slice(0), function (subscription) {
 304.922 +                    // In case a subscription was disposed during the arrayForEach cycle, check
 304.923 +                    // for isDisposed on each subscription before invoking its callback
 304.924 +                    if (subscription && (subscription.isDisposed !== true))
 304.925 +                        subscription.callback(valueToNotify);
 304.926 +                });
 304.927 +            }, this);
 304.928 +        }
 304.929 +    },
 304.930 +
 304.931 +    getSubscriptionsCount: function () {
 304.932 +        var total = 0;
 304.933 +        for (var eventName in this._subscriptions) {
 304.934 +            if (this._subscriptions.hasOwnProperty(eventName))
 304.935 +                total += this._subscriptions[eventName].length;
 304.936 +        }
 304.937 +        return total;
 304.938 +    },
 304.939 +
 304.940 +    extend: applyExtenders
 304.941 +};
 304.942 +
 304.943 +
 304.944 +ko.isSubscribable = function (instance) {
 304.945 +    return typeof instance.subscribe == "function" && typeof instance["notifySubscribers"] == "function";
 304.946 +};
 304.947 +
 304.948 +ko.exportSymbol('subscribable', ko.subscribable);
 304.949 +ko.exportSymbol('isSubscribable', ko.isSubscribable);
 304.950 +
 304.951 +ko.dependencyDetection = (function () {
 304.952 +    var _frames = [];
 304.953 +
 304.954 +    return {
 304.955 +        begin: function (callback) {
 304.956 +            _frames.push({ callback: callback, distinctDependencies:[] });
 304.957 +        },
 304.958 +
 304.959 +        end: function () {
 304.960 +            _frames.pop();
 304.961 +        },
 304.962 +
 304.963 +        registerDependency: function (subscribable) {
 304.964 +            if (!ko.isSubscribable(subscribable))
 304.965 +                throw new Error("Only subscribable things can act as dependencies");
 304.966 +            if (_frames.length > 0) {
 304.967 +                var topFrame = _frames[_frames.length - 1];
 304.968 +                if (!topFrame || ko.utils.arrayIndexOf(topFrame.distinctDependencies, subscribable) >= 0)
 304.969 +                    return;
 304.970 +                topFrame.distinctDependencies.push(subscribable);
 304.971 +                topFrame.callback(subscribable);
 304.972 +            }
 304.973 +        },
 304.974 +
 304.975 +        ignore: function(callback, callbackTarget, callbackArgs) {
 304.976 +            try {
 304.977 +                _frames.push(null);
 304.978 +                return callback.apply(callbackTarget, callbackArgs || []);
 304.979 +            } finally {
 304.980 +                _frames.pop();
 304.981 +            }
 304.982 +        }
 304.983 +    };
 304.984 +})();
 304.985 +var primitiveTypes = { 'undefined':true, 'boolean':true, 'number':true, 'string':true };
 304.986 +
 304.987 +ko.observable = function (initialValue) {
 304.988 +    var _latestValue = initialValue;
 304.989 +
 304.990 +    function observable() {
 304.991 +        if (arguments.length > 0) {
 304.992 +            // Write
 304.993 +
 304.994 +            // Ignore writes if the value hasn't changed
 304.995 +            if ((!observable['equalityComparer']) || !observable['equalityComparer'](_latestValue, arguments[0])) {
 304.996 +                observable.valueWillMutate();
 304.997 +                _latestValue = arguments[0];
 304.998 +                if (DEBUG) observable._latestValue = _latestValue;
 304.999 +                observable.valueHasMutated();
304.1000 +            }
304.1001 +            return this; // Permits chained assignments
304.1002 +        }
304.1003 +        else {
304.1004 +            // Read
304.1005 +            ko.dependencyDetection.registerDependency(observable); // The caller only needs to be notified of changes if they did a "read" operation
304.1006 +            return _latestValue;
304.1007 +        }
304.1008 +    }
304.1009 +    if (DEBUG) observable._latestValue = _latestValue;
304.1010 +    ko.subscribable.call(observable);
304.1011 +    observable.peek = function() { return _latestValue };
304.1012 +    observable.valueHasMutated = function () { observable["notifySubscribers"](_latestValue); }
304.1013 +    observable.valueWillMutate = function () { observable["notifySubscribers"](_latestValue, "beforeChange"); }
304.1014 +    ko.utils.extend(observable, ko.observable['fn']);
304.1015 +
304.1016 +    ko.exportProperty(observable, 'peek', observable.peek);
304.1017 +    ko.exportProperty(observable, "valueHasMutated", observable.valueHasMutated);
304.1018 +    ko.exportProperty(observable, "valueWillMutate", observable.valueWillMutate);
304.1019 +
304.1020 +    return observable;
304.1021 +}
304.1022 +
304.1023 +ko.observable['fn'] = {
304.1024 +    "equalityComparer": function valuesArePrimitiveAndEqual(a, b) {
304.1025 +        var oldValueIsPrimitive = (a === null) || (typeof(a) in primitiveTypes);
304.1026 +        return oldValueIsPrimitive ? (a === b) : false;
304.1027 +    }
304.1028 +};
304.1029 +
304.1030 +var protoProperty = ko.observable.protoProperty = "__ko_proto__";
304.1031 +ko.observable['fn'][protoProperty] = ko.observable;
304.1032 +
304.1033 +ko.hasPrototype = function(instance, prototype) {
304.1034 +    if ((instance === null) || (instance === undefined) || (instance[protoProperty] === undefined)) return false;
304.1035 +    if (instance[protoProperty] === prototype) return true;
304.1036 +    return ko.hasPrototype(instance[protoProperty], prototype); // Walk the prototype chain
304.1037 +};
304.1038 +
304.1039 +ko.isObservable = function (instance) {
304.1040 +    return ko.hasPrototype(instance, ko.observable);
304.1041 +}
304.1042 +ko.isWriteableObservable = function (instance) {
304.1043 +    // Observable
304.1044 +    if ((typeof instance == "function") && instance[protoProperty] === ko.observable)
304.1045 +        return true;
304.1046 +    // Writeable dependent observable
304.1047 +    if ((typeof instance == "function") && (instance[protoProperty] === ko.dependentObservable) && (instance.hasWriteFunction))
304.1048 +        return true;
304.1049 +    // Anything else
304.1050 +    return false;
304.1051 +}
304.1052 +
304.1053 +
304.1054 +ko.exportSymbol('observable', ko.observable);
304.1055 +ko.exportSymbol('isObservable', ko.isObservable);
304.1056 +ko.exportSymbol('isWriteableObservable', ko.isWriteableObservable);
304.1057 +ko.observableArray = function (initialValues) {
304.1058 +    if (arguments.length == 0) {
304.1059 +        // Zero-parameter constructor initializes to empty array
304.1060 +        initialValues = [];
304.1061 +    }
304.1062 +    if ((initialValues !== null) && (initialValues !== undefined) && !('length' in initialValues))
304.1063 +        throw new Error("The argument passed when initializing an observable array must be an array, or null, or undefined.");
304.1064 +
304.1065 +    var result = ko.observable(initialValues);
304.1066 +    ko.utils.extend(result, ko.observableArray['fn']);
304.1067 +    return result;
304.1068 +}
304.1069 +
304.1070 +ko.observableArray['fn'] = {
304.1071 +    'remove': function (valueOrPredicate) {
304.1072 +        var underlyingArray = this.peek();
304.1073 +        var removedValues = [];
304.1074 +        var predicate = typeof valueOrPredicate == "function" ? valueOrPredicate : function (value) { return value === valueOrPredicate; };
304.1075 +        for (var i = 0; i < underlyingArray.length; i++) {
304.1076 +            var value = underlyingArray[i];
304.1077 +            if (predicate(value)) {
304.1078 +                if (removedValues.length === 0) {
304.1079 +                    this.valueWillMutate();
304.1080 +                }
304.1081 +                removedValues.push(value);
304.1082 +                underlyingArray.splice(i, 1);
304.1083 +                i--;
304.1084 +            }
304.1085 +        }
304.1086 +        if (removedValues.length) {
304.1087 +            this.valueHasMutated();
304.1088 +        }
304.1089 +        return removedValues;
304.1090 +    },
304.1091 +
304.1092 +    'removeAll': function (arrayOfValues) {
304.1093 +        // If you passed zero args, we remove everything
304.1094 +        if (arrayOfValues === undefined) {
304.1095 +            var underlyingArray = this.peek();
304.1096 +            var allValues = underlyingArray.slice(0);
304.1097 +            this.valueWillMutate();
304.1098 +            underlyingArray.splice(0, underlyingArray.length);
304.1099 +            this.valueHasMutated();
304.1100 +            return allValues;
304.1101 +        }
304.1102 +        // If you passed an arg, we interpret it as an array of entries to remove
304.1103 +        if (!arrayOfValues)
304.1104 +            return [];
304.1105 +        return this['remove'](function (value) {
304.1106 +            return ko.utils.arrayIndexOf(arrayOfValues, value) >= 0;
304.1107 +        });
304.1108 +    },
304.1109 +
304.1110 +    'destroy': function (valueOrPredicate) {
304.1111 +        var underlyingArray = this.peek();
304.1112 +        var predicate = typeof valueOrPredicate == "function" ? valueOrPredicate : function (value) { return value === valueOrPredicate; };
304.1113 +        this.valueWillMutate();
304.1114 +        for (var i = underlyingArray.length - 1; i >= 0; i--) {
304.1115 +            var value = underlyingArray[i];
304.1116 +            if (predicate(value))
304.1117 +                underlyingArray[i]["_destroy"] = true;
304.1118 +        }
304.1119 +        this.valueHasMutated();
304.1120 +    },
304.1121 +
304.1122 +    'destroyAll': function (arrayOfValues) {
304.1123 +        // If you passed zero args, we destroy everything
304.1124 +        if (arrayOfValues === undefined)
304.1125 +            return this['destroy'](function() { return true });
304.1126 +
304.1127 +        // If you passed an arg, we interpret it as an array of entries to destroy
304.1128 +        if (!arrayOfValues)
304.1129 +            return [];
304.1130 +        return this['destroy'](function (value) {
304.1131 +            return ko.utils.arrayIndexOf(arrayOfValues, value) >= 0;
304.1132 +        });
304.1133 +    },
304.1134 +
304.1135 +    'indexOf': function (item) {
304.1136 +        var underlyingArray = this();
304.1137 +        return ko.utils.arrayIndexOf(underlyingArray, item);
304.1138 +    },
304.1139 +
304.1140 +    'replace': function(oldItem, newItem) {
304.1141 +        var index = this['indexOf'](oldItem);
304.1142 +        if (index >= 0) {
304.1143 +            this.valueWillMutate();
304.1144 +            this.peek()[index] = newItem;
304.1145 +            this.valueHasMutated();
304.1146 +        }
304.1147 +    }
304.1148 +}
304.1149 +
304.1150 +// Populate ko.observableArray.fn with read/write functions from native arrays
304.1151 +// Important: Do not add any additional functions here that may reasonably be used to *read* data from the array
304.1152 +// because we'll eval them without causing subscriptions, so ko.computed output could end up getting stale
304.1153 +ko.utils.arrayForEach(["pop", "push", "reverse", "shift", "sort", "splice", "unshift"], function (methodName) {
304.1154 +    ko.observableArray['fn'][methodName] = function () {
304.1155 +        // Use "peek" to avoid creating a subscription in any computed that we're executing in the context of
304.1156 +        // (for consistency with mutating regular observables)
304.1157 +        var underlyingArray = this.peek();
304.1158 +        this.valueWillMutate();
304.1159 +        var methodCallResult = underlyingArray[methodName].apply(underlyingArray, arguments);
304.1160 +        this.valueHasMutated();
304.1161 +        return methodCallResult;
304.1162 +    };
304.1163 +});
304.1164 +
304.1165 +// Populate ko.observableArray.fn with read-only functions from native arrays
304.1166 +ko.utils.arrayForEach(["slice"], function (methodName) {
304.1167 +    ko.observableArray['fn'][methodName] = function () {
304.1168 +        var underlyingArray = this();
304.1169 +        return underlyingArray[methodName].apply(underlyingArray, arguments);
304.1170 +    };
304.1171 +});
304.1172 +
304.1173 +ko.exportSymbol('observableArray', ko.observableArray);
304.1174 +ko.dependentObservable = function (evaluatorFunctionOrOptions, evaluatorFunctionTarget, options) {
304.1175 +    var _latestValue,
304.1176 +        _hasBeenEvaluated = false,
304.1177 +        _isBeingEvaluated = false,
304.1178 +        readFunction = evaluatorFunctionOrOptions;
304.1179 +
304.1180 +    if (readFunction && typeof readFunction == "object") {
304.1181 +        // Single-parameter syntax - everything is on this "options" param
304.1182 +        options = readFunction;
304.1183 +        readFunction = options["read"];
304.1184 +    } else {
304.1185 +        // Multi-parameter syntax - construct the options according to the params passed
304.1186 +        options = options || {};
304.1187 +        if (!readFunction)
304.1188 +            readFunction = options["read"];
304.1189 +    }
304.1190 +    if (typeof readFunction != "function")
304.1191 +        throw new Error("Pass a function that returns the value of the ko.computed");
304.1192 +
304.1193 +    function addSubscriptionToDependency(subscribable) {
304.1194 +        _subscriptionsToDependencies.push(subscribable.subscribe(evaluatePossiblyAsync));
304.1195 +    }
304.1196 +
304.1197 +    function disposeAllSubscriptionsToDependencies() {
304.1198 +        ko.utils.arrayForEach(_subscriptionsToDependencies, function (subscription) {
304.1199 +            subscription.dispose();
304.1200 +        });
304.1201 +        _subscriptionsToDependencies = [];
304.1202 +    }
304.1203 +
304.1204 +    function evaluatePossiblyAsync() {
304.1205 +        var throttleEvaluationTimeout = dependentObservable['throttleEvaluation'];
304.1206 +        if (throttleEvaluationTimeout && throttleEvaluationTimeout >= 0) {
304.1207 +            clearTimeout(evaluationTimeoutInstance);
304.1208 +            evaluationTimeoutInstance = setTimeout(evaluateImmediate, throttleEvaluationTimeout);
304.1209 +        } else
304.1210 +            evaluateImmediate();
304.1211 +    }
304.1212 +
304.1213 +    function evaluateImmediate() {
304.1214 +        if (_isBeingEvaluated) {
304.1215 +            // If the evaluation of a ko.computed causes side effects, it's possible that it will trigger its own re-evaluation.
304.1216 +            // This is not desirable (it's hard for a developer to realise a chain of dependencies might cause this, and they almost
304.1217 +            // certainly didn't intend infinite re-evaluations). So, for predictability, we simply prevent ko.computeds from causing
304.1218 +            // their own re-evaluation. Further discussion at https://github.com/SteveSanderson/knockout/pull/387
304.1219 +            return;
304.1220 +        }
304.1221 +
304.1222 +        // Don't dispose on first evaluation, because the "disposeWhen" callback might
304.1223 +        // e.g., dispose when the associated DOM element isn't in the doc, and it's not
304.1224 +        // going to be in the doc until *after* the first evaluation
304.1225 +        if (_hasBeenEvaluated && disposeWhen()) {
304.1226 +            dispose();
304.1227 +            return;
304.1228 +        }
304.1229 +
304.1230 +        _isBeingEvaluated = true;
304.1231 +        try {
304.1232 +            // Initially, we assume that none of the subscriptions are still being used (i.e., all are candidates for disposal).
304.1233 +            // Then, during evaluation, we cross off any that are in fact still being used.
304.1234 +            var disposalCandidates = ko.utils.arrayMap(_subscriptionsToDependencies, function(item) {return item.target;});
304.1235 +
304.1236 +            ko.dependencyDetection.begin(function(subscribable) {
304.1237 +                var inOld;
304.1238 +                if ((inOld = ko.utils.arrayIndexOf(disposalCandidates, subscribable)) >= 0)
304.1239 +                    disposalCandidates[inOld] = undefined; // Don't want to dispose this subscription, as it's still being used
304.1240 +                else
304.1241 +                    addSubscriptionToDependency(subscribable); // Brand new subscription - add it
304.1242 +            });
304.1243 +
304.1244 +            var newValue = readFunction.call(evaluatorFunctionTarget);
304.1245 +
304.1246 +            // For each subscription no longer being used, remove it from the active subscriptions list and dispose it
304.1247 +            for (var i = disposalCandidates.length - 1; i >= 0; i--) {
304.1248 +                if (disposalCandidates[i])
304.1249 +                    _subscriptionsToDependencies.splice(i, 1)[0].dispose();
304.1250 +            }
304.1251 +            _hasBeenEvaluated = true;
304.1252 +
304.1253 +            dependentObservable["notifySubscribers"](_latestValue, "beforeChange");
304.1254 +            _latestValue = newValue;
304.1255 +            if (DEBUG) dependentObservable._latestValue = _latestValue;
304.1256 +        } finally {
304.1257 +            ko.dependencyDetection.end();
304.1258 +        }
304.1259 +
304.1260 +        dependentObservable["notifySubscribers"](_latestValue);
304.1261 +        _isBeingEvaluated = false;
304.1262 +        if (!_subscriptionsToDependencies.length)
304.1263 +            dispose();
304.1264 +    }
304.1265 +
304.1266 +    function dependentObservable() {
304.1267 +        if (arguments.length > 0) {
304.1268 +            if (typeof writeFunction === "function") {
304.1269 +                // Writing a value
304.1270 +                writeFunction.apply(evaluatorFunctionTarget, arguments);
304.1271 +            } else {
304.1272 +                throw new Error("Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters.");
304.1273 +            }
304.1274 +            return this; // Permits chained assignments
304.1275 +        } else {
304.1276 +            // Reading the value
304.1277 +            if (!_hasBeenEvaluated)
304.1278 +                evaluateImmediate();
304.1279 +            ko.dependencyDetection.registerDependency(dependentObservable);
304.1280 +            return _latestValue;
304.1281 +        }
304.1282 +    }
304.1283 +
304.1284 +    function peek() {
304.1285 +        if (!_hasBeenEvaluated)
304.1286 +            evaluateImmediate();
304.1287 +        return _latestValue;
304.1288 +    }
304.1289 +
304.1290 +    function isActive() {
304.1291 +        return !_hasBeenEvaluated || _subscriptionsToDependencies.length > 0;
304.1292 +    }
304.1293 +
304.1294 +    // By here, "options" is always non-null
304.1295 +    var writeFunction = options["write"],
304.1296 +        disposeWhenNodeIsRemoved = options["disposeWhenNodeIsRemoved"] || options.disposeWhenNodeIsRemoved || null,
304.1297 +        disposeWhen = options["disposeWhen"] || options.disposeWhen || function() { return false; },
304.1298 +        dispose = disposeAllSubscriptionsToDependencies,
304.1299 +        _subscriptionsToDependencies = [],
304.1300 +        evaluationTimeoutInstance = null;
304.1301 +
304.1302 +    if (!evaluatorFunctionTarget)
304.1303 +        evaluatorFunctionTarget = options["owner"];
304.1304 +
304.1305 +    dependentObservable.peek = peek;
304.1306 +    dependentObservable.getDependenciesCount = function () { return _subscriptionsToDependencies.length; };
304.1307 +    dependentObservable.hasWriteFunction = typeof options["write"] === "function";
304.1308 +    dependentObservable.dispose = function () { dispose(); };
304.1309 +    dependentObservable.isActive = isActive;
304.1310 +    dependentObservable.valueHasMutated = function() {
304.1311 +        _hasBeenEvaluated = false;
304.1312 +        evaluateImmediate();
304.1313 +    };
304.1314 +
304.1315 +    ko.subscribable.call(dependentObservable);
304.1316 +    ko.utils.extend(dependentObservable, ko.dependentObservable['fn']);
304.1317 +
304.1318 +    ko.exportProperty(dependentObservable, 'peek', dependentObservable.peek);
304.1319 +    ko.exportProperty(dependentObservable, 'dispose', dependentObservable.dispose);
304.1320 +    ko.exportProperty(dependentObservable, 'isActive', dependentObservable.isActive);
304.1321 +    ko.exportProperty(dependentObservable, 'getDependenciesCount', dependentObservable.getDependenciesCount);
304.1322 +
304.1323 +    // Evaluate, unless deferEvaluation is true
304.1324 +    if (options['deferEvaluation'] !== true)
304.1325 +        evaluateImmediate();
304.1326 +
304.1327 +    // Build "disposeWhenNodeIsRemoved" and "disposeWhenNodeIsRemovedCallback" option values.
304.1328 +    // But skip if isActive is false (there will never be any dependencies to dispose).
304.1329 +    // (Note: "disposeWhenNodeIsRemoved" option both proactively disposes as soon as the node is removed using ko.removeNode(),
304.1330 +    // plus adds a "disposeWhen" callback that, on each evaluation, disposes if the node was removed by some other means.)
304.1331 +    if (disposeWhenNodeIsRemoved && isActive()) {
304.1332 +        dispose = function() {
304.1333 +            ko.utils.domNodeDisposal.removeDisposeCallback(disposeWhenNodeIsRemoved, arguments.callee);
304.1334 +            disposeAllSubscriptionsToDependencies();
304.1335 +        };
304.1336 +        ko.utils.domNodeDisposal.addDisposeCallback(disposeWhenNodeIsRemoved, dispose);
304.1337 +        var existingDisposeWhenFunction = disposeWhen;
304.1338 +        disposeWhen = function () {
304.1339 +            return !ko.utils.domNodeIsAttachedToDocument(disposeWhenNodeIsRemoved) || existingDisposeWhenFunction();
304.1340 +        }
304.1341 +    }
304.1342 +
304.1343 +    return dependentObservable;
304.1344 +};
304.1345 +
304.1346 +ko.isComputed = function(instance) {
304.1347 +    return ko.hasPrototype(instance, ko.dependentObservable);
304.1348 +};
304.1349 +
304.1350 +var protoProp = ko.observable.protoProperty; // == "__ko_proto__"
304.1351 +ko.dependentObservable[protoProp] = ko.observable;
304.1352 +
304.1353 +ko.dependentObservable['fn'] = {};
304.1354 +ko.dependentObservable['fn'][protoProp] = ko.dependentObservable;
304.1355 +
304.1356 +ko.exportSymbol('dependentObservable', ko.dependentObservable);
304.1357 +ko.exportSymbol('computed', ko.dependentObservable); // Make "ko.computed" an alias for "ko.dependentObservable"
304.1358 +ko.exportSymbol('isComputed', ko.isComputed);
304.1359 +
304.1360 +(function() {
304.1361 +    var maxNestedObservableDepth = 10; // Escape the (unlikely) pathalogical case where an observable's current value is itself (or similar reference cycle)
304.1362 +
304.1363 +    ko.toJS = function(rootObject) {
304.1364 +        if (arguments.length == 0)
304.1365 +            throw new Error("When calling ko.toJS, pass the object you want to convert.");
304.1366 +
304.1367 +        // We just unwrap everything at every level in the object graph
304.1368 +        return mapJsObjectGraph(rootObject, function(valueToMap) {
304.1369 +            // Loop because an observable's value might in turn be another observable wrapper
304.1370 +            for (var i = 0; ko.isObservable(valueToMap) && (i < maxNestedObservableDepth); i++)
304.1371 +                valueToMap = valueToMap();
304.1372 +            return valueToMap;
304.1373 +        });
304.1374 +    };
304.1375 +
304.1376 +    ko.toJSON = function(rootObject, replacer, space) {     // replacer and space are optional
304.1377 +        var plainJavaScriptObject = ko.toJS(rootObject);
304.1378 +        return ko.utils.stringifyJson(plainJavaScriptObject, replacer, space);
304.1379 +    };
304.1380 +
304.1381 +    function mapJsObjectGraph(rootObject, mapInputCallback, visitedObjects) {
304.1382 +        visitedObjects = visitedObjects || new objectLookup();
304.1383 +
304.1384 +        rootObject = mapInputCallback(rootObject);
304.1385 +        var canHaveProperties = (typeof rootObject == "object") && (rootObject !== null) && (rootObject !== undefined) && (!(rootObject instanceof Date));
304.1386 +        if (!canHaveProperties)
304.1387 +            return rootObject;
304.1388 +
304.1389 +        var outputProperties = rootObject instanceof Array ? [] : {};
304.1390 +        visitedObjects.save(rootObject, outputProperties);
304.1391 +
304.1392 +        visitPropertiesOrArrayEntries(rootObject, function(indexer) {
304.1393 +            var propertyValue = mapInputCallback(rootObject[indexer]);
304.1394 +
304.1395 +            switch (typeof propertyValue) {
304.1396 +                case "boolean":
304.1397 +                case "number":
304.1398 +                case "string":
304.1399 +                case "function":
304.1400 +                    outputProperties[indexer] = propertyValue;
304.1401 +                    break;
304.1402 +                case "object":
304.1403 +                case "undefined":
304.1404 +                    var previouslyMappedValue = visitedObjects.get(propertyValue);
304.1405 +                    outputProperties[indexer] = (previouslyMappedValue !== undefined)
304.1406 +                        ? previouslyMappedValue
304.1407 +                        : mapJsObjectGraph(propertyValue, mapInputCallback, visitedObjects);
304.1408 +                    break;
304.1409 +            }
304.1410 +        });
304.1411 +
304.1412 +        return outputProperties;
304.1413 +    }
304.1414 +
304.1415 +    function visitPropertiesOrArrayEntries(rootObject, visitorCallback) {
304.1416 +        if (rootObject instanceof Array) {
304.1417 +            for (var i = 0; i < rootObject.length; i++)
304.1418 +                visitorCallback(i);
304.1419 +
304.1420 +            // For arrays, also respect toJSON property for custom mappings (fixes #278)
304.1421 +            if (typeof rootObject['toJSON'] == 'function')
304.1422 +                visitorCallback('toJSON');
304.1423 +        } else {
304.1424 +            for (var propertyName in rootObject)
304.1425 +                visitorCallback(propertyName);
304.1426 +        }
304.1427 +    };
304.1428 +
304.1429 +    function objectLookup() {
304.1430 +        var keys = [];
304.1431 +        var values = [];
304.1432 +        this.save = function(key, value) {
304.1433 +            var existingIndex = ko.utils.arrayIndexOf(keys, key);
304.1434 +            if (existingIndex >= 0)
304.1435 +                values[existingIndex] = value;
304.1436 +            else {
304.1437 +                keys.push(key);
304.1438 +                values.push(value);
304.1439 +            }
304.1440 +        };
304.1441 +        this.get = function(key) {
304.1442 +            var existingIndex = ko.utils.arrayIndexOf(keys, key);
304.1443 +            return (existingIndex >= 0) ? values[existingIndex] : undefined;
304.1444 +        };
304.1445 +    };
304.1446 +})();
304.1447 +
304.1448 +ko.exportSymbol('toJS', ko.toJS);
304.1449 +ko.exportSymbol('toJSON', ko.toJSON);
304.1450 +(function () {
304.1451 +    var hasDomDataExpandoProperty = '__ko__hasDomDataOptionValue__';
304.1452 +
304.1453 +    // Normally, SELECT elements and their OPTIONs can only take value of type 'string' (because the values
304.1454 +    // are stored on DOM attributes). ko.selectExtensions provides a way for SELECTs/OPTIONs to have values
304.1455 +    // that are arbitrary objects. This is very convenient when implementing things like cascading dropdowns.
304.1456 +    ko.selectExtensions = {
304.1457 +        readValue : function(element) {
304.1458 +            switch (ko.utils.tagNameLower(element)) {
304.1459 +                case 'option':
304.1460 +                    if (element[hasDomDataExpandoProperty] === true)
304.1461 +                        return ko.utils.domData.get(element, ko.bindingHandlers.options.optionValueDomDataKey);
304.1462 +                    return ko.utils.ieVersion <= 7
304.1463 +                        ? (element.getAttributeNode('value').specified ? element.value : element.text)
304.1464 +                        : element.value;
304.1465 +                case 'select':
304.1466 +                    return element.selectedIndex >= 0 ? ko.selectExtensions.readValue(element.options[element.selectedIndex]) : undefined;
304.1467 +                default:
304.1468 +                    return element.value;
304.1469 +            }
304.1470 +        },
304.1471 +
304.1472 +        writeValue: function(element, value) {
304.1473 +            switch (ko.utils.tagNameLower(element)) {
304.1474 +                case 'option':
304.1475 +                    switch(typeof value) {
304.1476 +                        case "string":
304.1477 +                            ko.utils.domData.set(element, ko.bindingHandlers.options.optionValueDomDataKey, undefined);
304.1478 +                            if (hasDomDataExpandoProperty in element) { // IE <= 8 throws errors if you delete non-existent properties from a DOM node
304.1479 +                                delete element[hasDomDataExpandoProperty];
304.1480 +                            }
304.1481 +                            element.value = value;
304.1482 +                            break;
304.1483 +                        default:
304.1484 +                            // Store arbitrary object using DomData
304.1485 +                            ko.utils.domData.set(element, ko.bindingHandlers.options.optionValueDomDataKey, value);
304.1486 +                            element[hasDomDataExpandoProperty] = true;
304.1487 +
304.1488 +                            // Special treatment of numbers is just for backward compatibility. KO 1.2.1 wrote numerical values to element.value.
304.1489 +                            element.value = typeof value === "number" ? value : "";
304.1490 +                            break;
304.1491 +                    }
304.1492 +                    break;
304.1493 +                case 'select':
304.1494 +                    for (var i = element.options.length - 1; i >= 0; i--) {
304.1495 +                        if (ko.selectExtensions.readValue(element.options[i]) == value) {
304.1496 +                            element.selectedIndex = i;
304.1497 +                            break;
304.1498 +                        }
304.1499 +                    }
304.1500 +                    break;
304.1501 +                default:
304.1502 +                    if ((value === null) || (value === undefined))
304.1503 +                        value = "";
304.1504 +                    element.value = value;
304.1505 +                    break;
304.1506 +            }
304.1507 +        }
304.1508 +    };
304.1509 +})();
304.1510 +
304.1511 +ko.exportSymbol('selectExtensions', ko.selectExtensions);
304.1512 +ko.exportSymbol('selectExtensions.readValue', ko.selectExtensions.readValue);
304.1513 +ko.exportSymbol('selectExtensions.writeValue', ko.selectExtensions.writeValue);
304.1514 +ko.expressionRewriting = (function () {
304.1515 +    var restoreCapturedTokensRegex = /\@ko_token_(\d+)\@/g;
304.1516 +    var javaScriptReservedWords = ["true", "false"];
304.1517 +
304.1518 +    // Matches something that can be assigned to--either an isolated identifier or something ending with a property accessor
304.1519 +    // This is designed to be simple and avoid false negatives, but could produce false positives (e.g., a+b.c).
304.1520 +    var javaScriptAssignmentTarget = /^(?:[$_a-z][$\w]*|(.+)(\.\s*[$_a-z][$\w]*|\[.+\]))$/i;
304.1521 +
304.1522 +    function restoreTokens(string, tokens) {
304.1523 +        var prevValue = null;
304.1524 +        while (string != prevValue) { // Keep restoring tokens until it no longer makes a difference (they may be nested)
304.1525 +            prevValue = string;
304.1526 +            string = string.replace(restoreCapturedTokensRegex, function (match, tokenIndex) {
304.1527 +                return tokens[tokenIndex];
304.1528 +            });
304.1529 +        }
304.1530 +        return string;
304.1531 +    }
304.1532 +
304.1533 +    function getWriteableValue(expression) {
304.1534 +        if (ko.utils.arrayIndexOf(javaScriptReservedWords, ko.utils.stringTrim(expression).toLowerCase()) >= 0)
304.1535 +            return false;
304.1536 +        var match = expression.match(javaScriptAssignmentTarget);
304.1537 +        return match === null ? false : match[1] ? ('Object(' + match[1] + ')' + match[2]) : expression;
304.1538 +    }
304.1539 +
304.1540 +    function ensureQuoted(key) {
304.1541 +        var trimmedKey = ko.utils.stringTrim(key);
304.1542 +        switch (trimmedKey.length && trimmedKey.charAt(0)) {
304.1543 +            case "'":
304.1544 +            case '"':
304.1545 +                return key;
304.1546 +            default:
304.1547 +                return "'" + trimmedKey + "'";
304.1548 +        }
304.1549 +    }
304.1550 +
304.1551 +    return {
304.1552 +        bindingRewriteValidators: [],
304.1553 +
304.1554 +        parseObjectLiteral: function(objectLiteralString) {
304.1555 +            // A full tokeniser+lexer would add too much weight to this library, so here's a simple parser
304.1556 +            // that is sufficient just to split an object literal string into a set of top-level key-value pairs
304.1557 +
304.1558 +            var str = ko.utils.stringTrim(objectLiteralString);
304.1559 +            if (str.length < 3)
304.1560 +                return [];
304.1561 +            if (str.charAt(0) === "{")// Ignore any braces surrounding the whole object literal
304.1562 +                str = str.substring(1, str.length - 1);
304.1563 +
304.1564 +            // Pull out any string literals and regex literals
304.1565 +            var tokens = [];
304.1566 +            var tokenStart = null, tokenEndChar;
304.1567 +            for (var position = 0; position < str.length; position++) {
304.1568 +                var c = str.charAt(position);
304.1569 +                if (tokenStart === null) {
304.1570 +                    switch (c) {
304.1571 +                        case '"':
304.1572 +                        case "'":
304.1573 +                        case "/":
304.1574 +                            tokenStart = position;
304.1575 +                            tokenEndChar = c;
304.1576 +                            break;
304.1577 +                    }
304.1578 +                } else if ((c == tokenEndChar) && (str.charAt(position - 1) !== "\\")) {
304.1579 +                    var token = str.substring(tokenStart, position + 1);
304.1580 +                    tokens.push(token);
304.1581 +                    var replacement = "@ko_token_" + (tokens.length - 1) + "@";
304.1582 +                    str = str.substring(0, tokenStart) + replacement + str.substring(position + 1);
304.1583 +                    position -= (token.length - replacement.length);
304.1584 +                    tokenStart = null;
304.1585 +                }
304.1586 +            }
304.1587 +
304.1588 +            // Next pull out balanced paren, brace, and bracket blocks
304.1589 +            tokenStart = null;
304.1590 +            tokenEndChar = null;
304.1591 +            var tokenDepth = 0, tokenStartChar = null;
304.1592 +            for (var position = 0; position < str.length; position++) {
304.1593 +                var c = str.charAt(position);
304.1594 +                if (tokenStart === null) {
304.1595 +                    switch (c) {
304.1596 +                        case "{": tokenStart = position; tokenStartChar = c;
304.1597 +                                  tokenEndChar = "}";
304.1598 +                                  break;
304.1599 +                        case "(": tokenStart = position; tokenStartChar = c;
304.1600 +                                  tokenEndChar = ")";
304.1601 +                                  break;
304.1602 +                        case "[": tokenStart = position; tokenStartChar = c;
304.1603 +                                  tokenEndChar = "]";
304.1604 +                                  break;
304.1605 +                    }
304.1606 +                }
304.1607 +
304.1608 +                if (c === tokenStartChar)
304.1609 +                    tokenDepth++;
304.1610 +                else if (c === tokenEndChar) {
304.1611 +                    tokenDepth--;
304.1612 +                    if (tokenDepth === 0) {
304.1613 +                        var token = str.substring(tokenStart, position + 1);
304.1614 +                        tokens.push(token);
304.1615 +                        var replacement = "@ko_token_" + (tokens.length - 1) + "@";
304.1616 +                        str = str.substring(0, tokenStart) + replacement + str.substring(position + 1);
304.1617 +                        position -= (token.length - replacement.length);
304.1618 +                        tokenStart = null;
304.1619 +                    }
304.1620 +                }
304.1621 +            }
304.1622 +
304.1623 +            // Now we can safely split on commas to get the key/value pairs
304.1624 +            var result = [];
304.1625 +            var keyValuePairs = str.split(",");
304.1626 +            for (var i = 0, j = keyValuePairs.length; i < j; i++) {
304.1627 +                var pair = keyValuePairs[i];
304.1628 +                var colonPos = pair.indexOf(":");
304.1629 +                if ((colonPos > 0) && (colonPos < pair.length - 1)) {
304.1630 +                    var key = pair.substring(0, colonPos);
304.1631 +                    var value = pair.substring(colonPos + 1);
304.1632 +                    result.push({ 'key': restoreTokens(key, tokens), 'value': restoreTokens(value, tokens) });
304.1633 +                } else {
304.1634 +                    result.push({ 'unknown': restoreTokens(pair, tokens) });
304.1635 +                }
304.1636 +            }
304.1637 +            return result;
304.1638 +        },
304.1639 +
304.1640 +        preProcessBindings: function (objectLiteralStringOrKeyValueArray) {
304.1641 +            var keyValueArray = typeof objectLiteralStringOrKeyValueArray === "string"
304.1642 +                ? ko.expressionRewriting.parseObjectLiteral(objectLiteralStringOrKeyValueArray)
304.1643 +                : objectLiteralStringOrKeyValueArray;
304.1644 +            var resultStrings = [], propertyAccessorResultStrings = [];
304.1645 +
304.1646 +            var keyValueEntry;
304.1647 +            for (var i = 0; keyValueEntry = keyValueArray[i]; i++) {
304.1648 +                if (resultStrings.length > 0)
304.1649 +                    resultStrings.push(",");
304.1650 +
304.1651 +                if (keyValueEntry['key']) {
304.1652 +                    var quotedKey = ensureQuoted(keyValueEntry['key']), val = keyValueEntry['value'];
304.1653 +                    resultStrings.push(quotedKey);
304.1654 +                    resultStrings.push(":");
304.1655 +                    resultStrings.push(val);
304.1656 +
304.1657 +                    if (val = getWriteableValue(ko.utils.stringTrim(val))) {
304.1658 +                        if (propertyAccessorResultStrings.length > 0)
304.1659 +                            propertyAccessorResultStrings.push(", ");
304.1660 +                        propertyAccessorResultStrings.push(quotedKey + " : function(__ko_value) { " + val + " = __ko_value; }");
304.1661 +                    }
304.1662 +                } else if (keyValueEntry['unknown']) {
304.1663 +                    resultStrings.push(keyValueEntry['unknown']);
304.1664 +                }
304.1665 +            }
304.1666 +
304.1667 +            var combinedResult = resultStrings.join("");
304.1668 +            if (propertyAccessorResultStrings.length > 0) {
304.1669 +                var allPropertyAccessors = propertyAccessorResultStrings.join("");
304.1670 +                combinedResult = combinedResult + ", '_ko_property_writers' : { " + allPropertyAccessors + " } ";
304.1671 +            }
304.1672 +
304.1673 +            return combinedResult;
304.1674 +        },
304.1675 +
304.1676 +        keyValueArrayContainsKey: function(keyValueArray, key) {
304.1677 +            for (var i = 0; i < keyValueArray.length; i++)
304.1678 +                if (ko.utils.stringTrim(keyValueArray[i]['key']) == key)
304.1679 +                    return true;
304.1680 +            return false;
304.1681 +        },
304.1682 +
304.1683 +        // Internal, private KO utility for updating model properties from within bindings
304.1684 +        // property:            If the property being updated is (or might be) an observable, pass it here
304.1685 +        //                      If it turns out to be a writable observable, it will be written to directly
304.1686 +        // allBindingsAccessor: All bindings in the current execution context.
304.1687 +        //                      This will be searched for a '_ko_property_writers' property in case you're writing to a non-observable
304.1688 +        // key:                 The key identifying the property to be written. Example: for { hasFocus: myValue }, write to 'myValue' by specifying the key 'hasFocus'
304.1689 +        // value:               The value to be written
304.1690 +        // checkIfDifferent:    If true, and if the property being written is a writable observable, the value will only be written if
304.1691 +        //                      it is !== existing value on that writable observable
304.1692 +        writeValueToProperty: function(property, allBindingsAccessor, key, value, checkIfDifferent) {
304.1693 +            if (!property || !ko.isWriteableObservable(property)) {
304.1694 +                var propWriters = allBindingsAccessor()['_ko_property_writers'];
304.1695 +                if (propWriters && propWriters[key])
304.1696 +                    propWriters[key](value);
304.1697 +            } else if (!checkIfDifferent || property.peek() !== value) {
304.1698 +                property(value);
304.1699 +            }
304.1700 +        }
304.1701 +    };
304.1702 +})();
304.1703 +
304.1704 +ko.exportSymbol('expressionRewriting', ko.expressionRewriting);
304.1705 +ko.exportSymbol('expressionRewriting.bindingRewriteValidators', ko.expressionRewriting.bindingRewriteValidators);
304.1706 +ko.exportSymbol('expressionRewriting.parseObjectLiteral', ko.expressionRewriting.parseObjectLiteral);
304.1707 +ko.exportSymbol('expressionRewriting.preProcessBindings', ko.expressionRewriting.preProcessBindings);
304.1708 +
304.1709 +// For backward compatibility, define the following aliases. (Previously, these function names were misleading because
304.1710 +// they referred to JSON specifically, even though they actually work with arbitrary JavaScript object literal expressions.)
304.1711 +ko.exportSymbol('jsonExpressionRewriting', ko.expressionRewriting);
304.1712 +ko.exportSymbol('jsonExpressionRewriting.insertPropertyAccessorsIntoJson', ko.expressionRewriting.preProcessBindings);(function() {
304.1713 +    // "Virtual elements" is an abstraction on top of the usual DOM API which understands the notion that comment nodes
304.1714 +    // may be used to represent hierarchy (in addition to the DOM's natural hierarchy).
304.1715 +    // If you call the DOM-manipulating functions on ko.virtualElements, you will be able to read and write the state
304.1716 +    // of that virtual hierarchy
304.1717 +    //
304.1718 +    // The point of all this is to support containerless templates (e.g., <!-- ko foreach:someCollection -->blah<!-- /ko -->)
304.1719 +    // without having to scatter special cases all over the binding and templating code.
304.1720 +
304.1721 +    // IE 9 cannot reliably read the "nodeValue" property of a comment node (see https://github.com/SteveSanderson/knockout/issues/186)
304.1722 +    // but it does give them a nonstandard alternative property called "text" that it can read reliably. Other browsers don't have that property.
304.1723 +    // So, use node.text where available, and node.nodeValue elsewhere
304.1724 +    var commentNodesHaveTextProperty = document.createComment("test").text === "<!--test-->";
304.1725 +
304.1726 +    var startCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*ko(?:\s+(.+\s*\:[\s\S]*))?\s*-->$/ : /^\s*ko(?:\s+(.+\s*\:[\s\S]*))?\s*$/;
304.1727 +    var endCommentRegex =   commentNodesHaveTextProperty ? /^<!--\s*\/ko\s*-->$/ : /^\s*\/ko\s*$/;
304.1728 +    var htmlTagsWithOptionallyClosingChildren = { 'ul': true, 'ol': true };
304.1729 +
304.1730 +    function isStartComment(node) {
304.1731 +        return (node.nodeType == 8) && (commentNodesHaveTextProperty ? node.text : node.nodeValue).match(startCommentRegex);
304.1732 +    }
304.1733 +
304.1734 +    function isEndComment(node) {
304.1735 +        return (node.nodeType == 8) && (commentNodesHaveTextProperty ? node.text : node.nodeValue).match(endCommentRegex);
304.1736 +    }
304.1737 +
304.1738 +    function getVirtualChildren(startComment, allowUnbalanced) {
304.1739 +        var currentNode = startComment;
304.1740 +        var depth = 1;
304.1741 +        var children = [];
304.1742 +        while (currentNode = currentNode.nextSibling) {
304.1743 +            if (isEndComment(currentNode)) {
304.1744 +                depth--;
304.1745 +                if (depth === 0)
304.1746 +                    return children;
304.1747 +            }
304.1748 +
304.1749 +            children.push(currentNode);
304.1750 +
304.1751 +            if (isStartComment(currentNode))
304.1752 +                depth++;
304.1753 +        }
304.1754 +        if (!allowUnbalanced)
304.1755 +            throw new Error("Cannot find closing comment tag to match: " + startComment.nodeValue);
304.1756 +        return null;
304.1757 +    }
304.1758 +
304.1759 +    function getMatchingEndComment(startComment, allowUnbalanced) {
304.1760 +        var allVirtualChildren = getVirtualChildren(startComment, allowUnbalanced);
304.1761 +        if (allVirtualChildren) {
304.1762 +            if (allVirtualChildren.length > 0)
304.1763 +                return allVirtualChildren[allVirtualChildren.length - 1].nextSibling;
304.1764 +            return startComment.nextSibling;
304.1765 +        } else
304.1766 +            return null; // Must have no matching end comment, and allowUnbalanced is true
304.1767 +    }
304.1768 +
304.1769 +    function getUnbalancedChildTags(node) {
304.1770 +        // e.g., from <div>OK</div><!-- ko blah --><span>Another</span>, returns: <!-- ko blah --><span>Another</span>
304.1771 +        //       from <div>OK</div><!-- /ko --><!-- /ko -->,             returns: <!-- /ko --><!-- /ko -->
304.1772 +        var childNode = node.firstChild, captureRemaining = null;
304.1773 +        if (childNode) {
304.1774 +            do {
304.1775 +                if (captureRemaining)                   // We already hit an unbalanced node and are now just scooping up all subsequent nodes
304.1776 +                    captureRemaining.push(childNode);
304.1777 +                else if (isStartComment(childNode)) {
304.1778 +                    var matchingEndComment = getMatchingEndComment(childNode, /* allowUnbalanced: */ true);
304.1779 +                    if (matchingEndComment)             // It's a balanced tag, so skip immediately to the end of this virtual set
304.1780 +                        childNode = matchingEndComment;
304.1781 +                    else
304.1782 +                        captureRemaining = [childNode]; // It's unbalanced, so start capturing from this point
304.1783 +                } else if (isEndComment(childNode)) {
304.1784 +                    captureRemaining = [childNode];     // It's unbalanced (if it wasn't, we'd have skipped over it already), so start capturing
304.1785 +                }
304.1786 +            } while (childNode = childNode.nextSibling);
304.1787 +        }
304.1788 +        return captureRemaining;
304.1789 +    }
304.1790 +
304.1791 +    ko.virtualElements = {
304.1792 +        allowedBindings: {},
304.1793 +
304.1794 +        childNodes: function(node) {
304.1795 +            return isStartComment(node) ? getVirtualChildren(node) : node.childNodes;
304.1796 +        },
304.1797 +
304.1798 +        emptyNode: function(node) {
304.1799 +            if (!isStartComment(node))
304.1800 +                ko.utils.emptyDomNode(node);
304.1801 +            else {
304.1802 +                var virtualChildren = ko.virtualElements.childNodes(node);
304.1803 +                for (var i = 0, j = virtualChildren.length; i < j; i++)
304.1804 +                    ko.removeNode(virtualChildren[i]);
304.1805 +            }
304.1806 +        },
304.1807 +
304.1808 +        setDomNodeChildren: function(node, childNodes) {
304.1809 +            if (!isStartComment(node))
304.1810 +                ko.utils.setDomNodeChildren(node, childNodes);
304.1811 +            else {
304.1812 +                ko.virtualElements.emptyNode(node);
304.1813 +                var endCommentNode = node.nextSibling; // Must be the next sibling, as we just emptied the children
304.1814 +                for (var i = 0, j = childNodes.length; i < j; i++)
304.1815 +                    endCommentNode.parentNode.insertBefore(childNodes[i], endCommentNode);
304.1816 +            }
304.1817 +        },
304.1818 +
304.1819 +        prepend: function(containerNode, nodeToPrepend) {
304.1820 +            if (!isStartComment(containerNode)) {
304.1821 +                if (containerNode.firstChild)
304.1822 +                    containerNode.insertBefore(nodeToPrepend, containerNode.firstChild);
304.1823 +                else
304.1824 +                    containerNode.appendChild(nodeToPrepend);
304.1825 +            } else {
304.1826 +                // Start comments must always have a parent and at least one following sibling (the end comment)
304.1827 +                containerNode.parentNode.insertBefore(nodeToPrepend, containerNode.nextSibling);
304.1828 +            }
304.1829 +        },
304.1830 +
304.1831 +        insertAfter: function(containerNode, nodeToInsert, insertAfterNode) {
304.1832 +            if (!insertAfterNode) {
304.1833 +                ko.virtualElements.prepend(containerNode, nodeToInsert);
304.1834 +            } else if (!isStartComment(containerNode)) {
304.1835 +                // Insert after insertion point
304.1836 +                if (insertAfterNode.nextSibling)
304.1837 +                    containerNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling);
304.1838 +                else
304.1839 +                    containerNode.appendChild(nodeToInsert);
304.1840 +            } else {
304.1841 +                // Children of start comments must always have a parent and at least one following sibling (the end comment)
304.1842 +                containerNode.parentNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling);
304.1843 +            }
304.1844 +        },
304.1845 +
304.1846 +        firstChild: function(node) {
304.1847 +            if (!isStartComment(node))
304.1848 +                return node.firstChild;
304.1849 +            if (!node.nextSibling || isEndComment(node.nextSibling))
304.1850 +                return null;
304.1851 +            return node.nextSibling;
304.1852 +        },
304.1853 +
304.1854 +        nextSibling: function(node) {
304.1855 +            if (isStartComment(node))
304.1856 +                node = getMatchingEndComment(node);
304.1857 +            if (node.nextSibling && isEndComment(node.nextSibling))
304.1858 +                return null;
304.1859 +            return node.nextSibling;
304.1860 +        },
304.1861 +
304.1862 +        virtualNodeBindingValue: function(node) {
304.1863 +            var regexMatch = isStartComment(node);
304.1864 +            return regexMatch ? regexMatch[1] : null;
304.1865 +        },
304.1866 +
304.1867 +        normaliseVirtualElementDomStructure: function(elementVerified) {
304.1868 +            // Workaround for https://github.com/SteveSanderson/knockout/issues/155
304.1869 +            // (IE <= 8 or IE 9 quirks mode parses your HTML weirdly, treating closing </li> tags as if they don't exist, thereby moving comment nodes
304.1870 +            // that are direct descendants of <ul> into the preceding <li>)
304.1871 +            if (!htmlTagsWithOptionallyClosingChildren[ko.utils.tagNameLower(elementVerified)])
304.1872 +                return;
304.1873 +
304.1874 +            // Scan immediate children to see if they contain unbalanced comment tags. If they do, those comment tags
304.1875 +            // must be intended to appear *after* that child, so move them there.
304.1876 +            var childNode = elementVerified.firstChild;
304.1877 +            if (childNode) {
304.1878 +                do {
304.1879 +                    if (childNode.nodeType === 1) {
304.1880 +                        var unbalancedTags = getUnbalancedChildTags(childNode);
304.1881 +                        if (unbalancedTags) {
304.1882 +                            // Fix up the DOM by moving the unbalanced tags to where they most likely were intended to be placed - *after* the child
304.1883 +                            var nodeToInsertBefore = childNode.nextSibling;
304.1884 +                            for (var i = 0; i < unbalancedTags.length; i++) {
304.1885 +                                if (nodeToInsertBefore)
304.1886 +                                    elementVerified.insertBefore(unbalancedTags[i], nodeToInsertBefore);
304.1887 +                                else
304.1888 +                                    elementVerified.appendChild(unbalancedTags[i]);
304.1889 +                            }
304.1890 +                        }
304.1891 +                    }
304.1892 +                } while (childNode = childNode.nextSibling);
304.1893 +            }
304.1894 +        }
304.1895 +    };
304.1896 +})();
304.1897 +ko.exportSymbol('virtualElements', ko.virtualElements);
304.1898 +ko.exportSymbol('virtualElements.allowedBindings', ko.virtualElements.allowedBindings);
304.1899 +ko.exportSymbol('virtualElements.emptyNode', ko.virtualElements.emptyNode);
304.1900 +//ko.exportSymbol('virtualElements.firstChild', ko.virtualElements.firstChild);     // firstChild is not minified
304.1901 +ko.exportSymbol('virtualElements.insertAfter', ko.virtualElements.insertAfter);
304.1902 +//ko.exportSymbol('virtualElements.nextSibling', ko.virtualElements.nextSibling);   // nextSibling is not minified
304.1903 +ko.exportSymbol('virtualElements.prepend', ko.virtualElements.prepend);
304.1904 +ko.exportSymbol('virtualElements.setDomNodeChildren', ko.virtualElements.setDomNodeChildren);
304.1905 +(function() {
304.1906 +    var defaultBindingAttributeName = "data-bind";
304.1907 +
304.1908 +    ko.bindingProvider = function() {
304.1909 +        this.bindingCache = {};
304.1910 +    };
304.1911 +
304.1912 +    ko.utils.extend(ko.bindingProvider.prototype, {
304.1913 +        'nodeHasBindings': function(node) {
304.1914 +            switch (node.nodeType) {
304.1915 +                case 1: return node.getAttribute(defaultBindingAttributeName) != null;   // Element
304.1916 +                case 8: return ko.virtualElements.virtualNodeBindingValue(node) != null; // Comment node
304.1917 +                default: return false;
304.1918 +            }
304.1919 +        },
304.1920 +
304.1921 +        'getBindings': function(node, bindingContext) {
304.1922 +            var bindingsString = this['getBindingsString'](node, bindingContext);
304.1923 +            return bindingsString ? this['parseBindingsString'](bindingsString, bindingContext, node) : null;
304.1924 +        },
304.1925 +
304.1926 +        // The following function is only used internally by this default provider.
304.1927 +        // It's not part of the interface definition for a general binding provider.
304.1928 +        'getBindingsString': function(node, bindingContext) {
304.1929 +            switch (node.nodeType) {
304.1930 +                case 1: return node.getAttribute(defaultBindingAttributeName);   // Element
304.1931 +                case 8: return ko.virtualElements.virtualNodeBindingValue(node); // Comment node
304.1932 +                default: return null;
304.1933 +            }
304.1934 +        },
304.1935 +
304.1936 +        // The following function is only used internally by this default provider.
304.1937 +        // It's not part of the interface definition for a general binding provider.
304.1938 +        'parseBindingsString': function(bindingsString, bindingContext, node) {
304.1939 +            try {
304.1940 +                var bindingFunction = createBindingsStringEvaluatorViaCache(bindingsString, this.bindingCache);
304.1941 +                return bindingFunction(bindingContext, node);
304.1942 +            } catch (ex) {
304.1943 +                throw new Error("Unable to parse bindings.\nMessage: " + ex + ";\nBindings value: " + bindingsString);
304.1944 +            }
304.1945 +        }
304.1946 +    });
304.1947 +
304.1948 +    ko.bindingProvider['instance'] = new ko.bindingProvider();
304.1949 +
304.1950 +    function createBindingsStringEvaluatorViaCache(bindingsString, cache) {
304.1951 +        var cacheKey = bindingsString;
304.1952 +        return cache[cacheKey]
304.1953 +            || (cache[cacheKey] = createBindingsStringEvaluator(bindingsString));
304.1954 +    }
304.1955 +
304.1956 +    function createBindingsStringEvaluator(bindingsString) {
304.1957 +        // Build the source for a function that evaluates "expression"
304.1958 +        // For each scope variable, add an extra level of "with" nesting
304.1959 +        // Example result: with(sc1) { with(sc0) { return (expression) } }
304.1960 +        var rewrittenBindings = ko.expressionRewriting.preProcessBindings(bindingsString),
304.1961 +            functionBody = "with($context){with($data||{}){return{" + rewrittenBindings + "}}}";
304.1962 +        return new Function("$context", "$element", functionBody);
304.1963 +    }
304.1964 +})();
304.1965 +
304.1966 +ko.exportSymbol('bindingProvider', ko.bindingProvider);
304.1967 +(function () {
304.1968 +    ko.bindingHandlers = {};
304.1969 +
304.1970 +    ko.bindingContext = function(dataItem, parentBindingContext, dataItemAlias) {
304.1971 +        if (parentBindingContext) {
304.1972 +            ko.utils.extend(this, parentBindingContext); // Inherit $root and any custom properties
304.1973 +            this['$parentContext'] = parentBindingContext;
304.1974 +            this['$parent'] = parentBindingContext['$data'];
304.1975 +            this['$parents'] = (parentBindingContext['$parents'] || []).slice(0);
304.1976 +            this['$parents'].unshift(this['$parent']);
304.1977 +        } else {
304.1978 +            this['$parents'] = [];
304.1979 +            this['$root'] = dataItem;
304.1980 +            // Export 'ko' in the binding context so it will be available in bindings and templates
304.1981 +            // even if 'ko' isn't exported as a global, such as when using an AMD loader.
304.1982 +            // See https://github.com/SteveSanderson/knockout/issues/490
304.1983 +            this['ko'] = ko;
304.1984 +        }
304.1985 +        this['$data'] = dataItem;
304.1986 +        if (dataItemAlias)
304.1987 +            this[dataItemAlias] = dataItem;
304.1988 +    }
304.1989 +    ko.bindingContext.prototype['createChildContext'] = function (dataItem, dataItemAlias) {
304.1990 +        return new ko.bindingContext(dataItem, this, dataItemAlias);
304.1991 +    };
304.1992 +    ko.bindingContext.prototype['extend'] = function(properties) {
304.1993 +        var clone = ko.utils.extend(new ko.bindingContext(), this);
304.1994 +        return ko.utils.extend(clone, properties);
304.1995 +    };
304.1996 +
304.1997 +    function validateThatBindingIsAllowedForVirtualElements(bindingName) {
304.1998 +        var validator = ko.virtualElements.allowedBindings[bindingName];
304.1999 +        if (!validator)
304.2000 +            throw new Error("The binding '" + bindingName + "' cannot be used with virtual elements")
304.2001 +    }
304.2002 +
304.2003 +    function applyBindingsToDescendantsInternal (viewModel, elementOrVirtualElement, bindingContextsMayDifferFromDomParentElement) {
304.2004 +        var currentChild, nextInQueue = ko.virtualElements.firstChild(elementOrVirtualElement);
304.2005 +        while (currentChild = nextInQueue) {
304.2006 +            // Keep a record of the next child *before* applying bindings, in case the binding removes the current child from its position
304.2007 +            nextInQueue = ko.virtualElements.nextSibling(currentChild);
304.2008 +            applyBindingsToNodeAndDescendantsInternal(viewModel, currentChild, bindingContextsMayDifferFromDomParentElement);
304.2009 +        }
304.2010 +    }
304.2011 +
304.2012 +    function applyBindingsToNodeAndDescendantsInternal (viewModel, nodeVerified, bindingContextMayDifferFromDomParentElement) {
304.2013 +        var shouldBindDescendants = true;
304.2014 +
304.2015 +        // Perf optimisation: Apply bindings only if...
304.2016 +        // (1) We need to store the binding context on this node (because it may differ from the DOM parent node's binding context)
304.2017 +        //     Note that we can't store binding contexts on non-elements (e.g., text nodes), as IE doesn't allow expando properties for those
304.2018 +        // (2) It might have bindings (e.g., it has a data-bind attribute, or it's a marker for a containerless template)
304.2019 +        var isElement = (nodeVerified.nodeType === 1);
304.2020 +        if (isElement) // Workaround IE <= 8 HTML parsing weirdness
304.2021 +            ko.virtualElements.normaliseVirtualElementDomStructure(nodeVerified);
304.2022 +
304.2023 +        var shouldApplyBindings = (isElement && bindingContextMayDifferFromDomParentElement)             // Case (1)
304.2024 +                               || ko.bindingProvider['instance']['nodeHasBindings'](nodeVerified);       // Case (2)
304.2025 +        if (shouldApplyBindings)
304.2026 +            shouldBindDescendants = applyBindingsToNodeInternal(nodeVerified, null, viewModel, bindingContextMayDifferFromDomParentElement).shouldBindDescendants;
304.2027 +
304.2028 +        if (shouldBindDescendants) {
304.2029 +            // We're recursing automatically into (real or virtual) child nodes without changing binding contexts. So,
304.2030 +            //  * For children of a *real* element, the binding context is certainly the same as on their DOM .parentNode,
304.2031 +            //    hence bindingContextsMayDifferFromDomParentElement is false
304.2032 +            //  * For children of a *virtual* element, we can't be sure. Evaluating .parentNode on those children may
304.2033 +            //    skip over any number of intermediate virtual elements, any of which might define a custom binding context,
304.2034 +            //    hence bindingContextsMayDifferFromDomParentElement is true
304.2035 +            applyBindingsToDescendantsInternal(viewModel, nodeVerified, /* bindingContextsMayDifferFromDomParentElement: */ !isElement);
304.2036 +        }
304.2037 +    }
304.2038 +
304.2039 +    function applyBindingsToNodeInternal (node, bindings, viewModelOrBindingContext, bindingContextMayDifferFromDomParentElement) {
304.2040 +        // Need to be sure that inits are only run once, and updates never run until all the inits have been run
304.2041 +        var initPhase = 0; // 0 = before all inits, 1 = during inits, 2 = after all inits
304.2042 +
304.2043 +        // Each time the dependentObservable is evaluated (after data changes),
304.2044 +        // the binding attribute is reparsed so that it can pick out the correct
304.2045 +        // model properties in the context of the changed data.
304.2046 +        // DOM event callbacks need to be able to access this changed data,
304.2047 +        // so we need a single parsedBindings variable (shared by all callbacks
304.2048 +        // associated with this node's bindings) that all the closures can access.
304.2049 +        var parsedBindings;
304.2050 +        function makeValueAccessor(bindingKey) {
304.2051 +            return function () { return parsedBindings[bindingKey] }
304.2052 +        }
304.2053 +        function parsedBindingsAccessor() {
304.2054 +            return parsedBindings;
304.2055 +        }
304.2056 +
304.2057 +        var bindingHandlerThatControlsDescendantBindings;
304.2058 +        ko.dependentObservable(
304.2059 +            function () {
304.2060 +                // Ensure we have a nonnull binding context to work with
304.2061 +                var bindingContextInstance = viewModelOrBindingContext && (viewModelOrBindingContext instanceof ko.bindingContext)
304.2062 +                    ? viewModelOrBindingContext
304.2063 +                    : new ko.bindingContext(ko.utils.unwrapObservable(viewModelOrBindingContext));
304.2064 +                var viewModel = bindingContextInstance['$data'];
304.2065 +
304.2066 +                // Optimization: Don't store the binding context on this node if it's definitely the same as on node.parentNode, because
304.2067 +                // we can easily recover it just by scanning up the node's ancestors in the DOM
304.2068 +                // (note: here, parent node means "real DOM parent" not "virtual parent", as there's no O(1) way to find the virtual parent)
304.2069 +                if (bindingContextMayDifferFromDomParentElement)
304.2070 +                    ko.storedBindingContextForNode(node, bindingContextInstance);
304.2071 +
304.2072 +                // Use evaluatedBindings if given, otherwise fall back on asking the bindings provider to give us some bindings
304.2073 +                var evaluatedBindings = (typeof bindings == "function") ? bindings(bindingContextInstance, node) : bindings;
304.2074 +                parsedBindings = evaluatedBindings || ko.bindingProvider['instance']['getBindings'](node, bindingContextInstance);
304.2075 +
304.2076 +                if (parsedBindings) {
304.2077 +                    // First run all the inits, so bindings can register for notification on changes
304.2078 +                    if (initPhase === 0) {
304.2079 +                        initPhase = 1;
304.2080 +                        for (var bindingKey in parsedBindings) {
304.2081 +                            var binding = ko.bindingHandlers[bindingKey];
304.2082 +                            if (binding && node.nodeType === 8)
304.2083 +                                validateThatBindingIsAllowedForVirtualElements(bindingKey);
304.2084 +
304.2085 +                            if (binding && typeof binding["init"] == "function") {
304.2086 +                                var handlerInitFn = binding["init"];
304.2087 +                                var initResult = handlerInitFn(node, makeValueAccessor(bindingKey), parsedBindingsAccessor, viewModel, bindingContextInstance);
304.2088 +
304.2089 +                                // If this binding handler claims to control descendant bindings, make a note of this
304.2090 +                                if (initResult && initResult['controlsDescendantBindings']) {
304.2091 +                                    if (bindingHandlerThatControlsDescendantBindings !== undefined)
304.2092 +                                        throw new Error("Multiple bindings (" + bindingHandlerThatControlsDescendantBindings + " and " + bindingKey + ") are trying to control descendant bindings of the same element. You cannot use these bindings together on the same element.");
304.2093 +                                    bindingHandlerThatControlsDescendantBindings = bindingKey;
304.2094 +                                }
304.2095 +                            }
304.2096 +                        }
304.2097 +                        initPhase = 2;
304.2098 +                    }
304.2099 +
304.2100 +                    // ... then run all the updates, which might trigger changes even on the first evaluation
304.2101 +                    if (initPhase === 2) {
304.2102 +                        for (var bindingKey in parsedBindings) {
304.2103 +                            var binding = ko.bindingHandlers[bindingKey];
304.2104 +                            if (binding && typeof binding["update"] == "function") {
304.2105 +                                var handlerUpdateFn = binding["update"];
304.2106 +                                handlerUpdateFn(node, makeValueAccessor(bindingKey), parsedBindingsAccessor, viewModel, bindingContextInstance);
304.2107 +                            }
304.2108 +                        }
304.2109 +                    }
304.2110 +                }
304.2111 +            },
304.2112 +            null,
304.2113 +            { disposeWhenNodeIsRemoved : node }
304.2114 +        );
304.2115 +
304.2116 +        return {
304.2117 +            shouldBindDescendants: bindingHandlerThatControlsDescendantBindings === undefined
304.2118 +        };
304.2119 +    };
304.2120 +
304.2121 +    var storedBindingContextDomDataKey = "__ko_bindingContext__";
304.2122 +    ko.storedBindingContextForNode = function (node, bindingContext) {
304.2123 +        if (arguments.length == 2)
304.2124 +            ko.utils.domData.set(node, storedBindingContextDomDataKey, bindingContext);
304.2125 +        else
304.2126 +            return ko.utils.domData.get(node, storedBindingContextDomDataKey);
304.2127 +    }
304.2128 +
304.2129 +    ko.applyBindingsToNode = function (node, bindings, viewModel) {
304.2130 +        if (node.nodeType === 1) // If it's an element, workaround IE <= 8 HTML parsing weirdness
304.2131 +            ko.virtualElements.normaliseVirtualElementDomStructure(node);
304.2132 +        return applyBindingsToNodeInternal(node, bindings, viewModel, true);
304.2133 +    };
304.2134 +
304.2135 +    ko.applyBindingsToDescendants = function(viewModel, rootNode) {
304.2136 +        if (rootNode.nodeType === 1 || rootNode.nodeType === 8)
304.2137 +            applyBindingsToDescendantsInternal(viewModel, rootNode, true);
304.2138 +    };
304.2139 +
304.2140 +    ko.applyBindings = function (viewModel, rootNode) {
304.2141 +        if (rootNode && (rootNode.nodeType !== 1) && (rootNode.nodeType !== 8))
304.2142 +            throw new Error("ko.applyBindings: first parameter should be your view model; second parameter should be a DOM node");
304.2143 +        rootNode = rootNode || window.document.body; // Make "rootNode" parameter optional
304.2144 +
304.2145 +        applyBindingsToNodeAndDescendantsInternal(viewModel, rootNode, true);
304.2146 +    };
304.2147 +
304.2148 +    // Retrieving binding context from arbitrary nodes
304.2149 +    ko.contextFor = function(node) {
304.2150 +        // We can only do something meaningful for elements and comment nodes (in particular, not text nodes, as IE can't store domdata for them)
304.2151 +        switch (node.nodeType) {
304.2152 +            case 1:
304.2153 +            case 8:
304.2154 +                var context = ko.storedBindingContextForNode(node);
304.2155 +                if (context) return context;
304.2156 +                if (node.parentNode) return ko.contextFor(node.parentNode);
304.2157 +                break;
304.2158 +        }
304.2159 +        return undefined;
304.2160 +    };
304.2161 +    ko.dataFor = function(node) {
304.2162 +        var context = ko.contextFor(node);
304.2163 +        return context ? context['$data'] : undefined;
304.2164 +    };
304.2165 +
304.2166 +    ko.exportSymbol('bindingHandlers', ko.bindingHandlers);
304.2167 +    ko.exportSymbol('applyBindings', ko.applyBindings);
304.2168 +    ko.exportSymbol('applyBindingsToDescendants', ko.applyBindingsToDescendants);
304.2169 +    ko.exportSymbol('applyBindingsToNode', ko.applyBindingsToNode);
304.2170 +    ko.exportSymbol('contextFor', ko.contextFor);
304.2171 +    ko.exportSymbol('dataFor', ko.dataFor);
304.2172 +})();
304.2173 +var attrHtmlToJavascriptMap = { 'class': 'className', 'for': 'htmlFor' };
304.2174 +ko.bindingHandlers['attr'] = {
304.2175 +    'update': function(element, valueAccessor, allBindingsAccessor) {
304.2176 +        var value = ko.utils.unwrapObservable(valueAccessor()) || {};
304.2177 +        for (var attrName in value) {
304.2178 +            if (typeof attrName == "string") {
304.2179 +                var attrValue = ko.utils.unwrapObservable(value[attrName]);
304.2180 +
304.2181 +                // To cover cases like "attr: { checked:someProp }", we want to remove the attribute entirely
304.2182 +                // when someProp is a "no value"-like value (strictly null, false, or undefined)
304.2183 +                // (because the absence of the "checked" attr is how to mark an element as not checked, etc.)
304.2184 +                var toRemove = (attrValue === false) || (attrValue === null) || (attrValue === undefined);
304.2185 +                if (toRemove)
304.2186 +                    element.removeAttribute(attrName);
304.2187 +
304.2188 +                // In IE <= 7 and IE8 Quirks Mode, you have to use the Javascript property name instead of the
304.2189 +                // HTML attribute name for certain attributes. IE8 Standards Mode supports the correct behavior,
304.2190 +                // but instead of figuring out the mode, we'll just set the attribute through the Javascript
304.2191 +                // property for IE <= 8.
304.2192 +                if (ko.utils.ieVersion <= 8 && attrName in attrHtmlToJavascriptMap) {
304.2193 +                    attrName = attrHtmlToJavascriptMap[attrName];
304.2194 +                    if (toRemove)
304.2195 +                        element.removeAttribute(attrName);
304.2196 +                    else
304.2197 +                        element[attrName] = attrValue;
304.2198 +                } else if (!toRemove) {
304.2199 +                    element.setAttribute(attrName, attrValue.toString());
304.2200 +                }
304.2201 +
304.2202 +                // Treat "name" specially - although you can think of it as an attribute, it also needs
304.2203 +                // special handling on older versions of IE (https://github.com/SteveSanderson/knockout/pull/333)
304.2204 +                // Deliberately being case-sensitive here because XHTML would regard "Name" as a different thing
304.2205 +                // entirely, and there's no strong reason to allow for such casing in HTML.
304.2206 +                if (attrName === "name") {
304.2207 +                    ko.utils.setElementName(element, toRemove ? "" : attrValue.toString());
304.2208 +                }
304.2209 +            }
304.2210 +        }
304.2211 +    }
304.2212 +};
304.2213 +ko.bindingHandlers['checked'] = {
304.2214 +    'init': function (element, valueAccessor, allBindingsAccessor) {
304.2215 +        var updateHandler = function() {
304.2216 +            var valueToWrite;
304.2217 +            if (element.type == "checkbox") {
304.2218 +                valueToWrite = element.checked;
304.2219 +            } else if ((element.type == "radio") && (element.checked)) {
304.2220 +                valueToWrite = element.value;
304.2221 +            } else {
304.2222 +                return; // "checked" binding only responds to checkboxes and selected radio buttons
304.2223 +            }
304.2224 +
304.2225 +            var modelValue = valueAccessor(), unwrappedValue = ko.utils.unwrapObservable(modelValue);
304.2226 +            if ((element.type == "checkbox") && (unwrappedValue instanceof Array)) {
304.2227 +                // For checkboxes bound to an array, we add/remove the checkbox value to that array
304.2228 +                // This works for both observable and non-observable arrays
304.2229 +                var existingEntryIndex = ko.utils.arrayIndexOf(unwrappedValue, element.value);
304.2230 +                if (element.checked && (existingEntryIndex < 0))
304.2231 +                    modelValue.push(element.value);
304.2232 +                else if ((!element.checked) && (existingEntryIndex >= 0))
304.2233 +                    modelValue.splice(existingEntryIndex, 1);
304.2234 +            } else {
304.2235 +                ko.expressionRewriting.writeValueToProperty(modelValue, allBindingsAccessor, 'checked', valueToWrite, true);
304.2236 +            }
304.2237 +        };
304.2238 +        ko.utils.registerEventHandler(element, "click", updateHandler);
304.2239 +
304.2240 +        // IE 6 won't allow radio buttons to be selected unless they have a name
304.2241 +        if ((element.type == "radio") && !element.name)
304.2242 +            ko.bindingHandlers['uniqueName']['init'](element, function() { return true });
304.2243 +    },
304.2244 +    'update': function (element, valueAccessor) {
304.2245 +        var value = ko.utils.unwrapObservable(valueAccessor());
304.2246 +
304.2247 +        if (element.type == "checkbox") {
304.2248 +            if (value instanceof Array) {
304.2249 +                // When bound to an array, the checkbox being checked represents its value being present in that array
304.2250 +                element.checked = ko.utils.arrayIndexOf(value, element.value) >= 0;
304.2251 +            } else {
304.2252 +                // When bound to anything other value (not an array), the checkbox being checked represents the value being trueish
304.2253 +                element.checked = value;
304.2254 +            }
304.2255 +        } else if (element.type == "radio") {
304.2256 +            element.checked = (element.value == value);
304.2257 +        }
304.2258 +    }
304.2259 +};
304.2260 +var classesWrittenByBindingKey = '__ko__cssValue';
304.2261 +ko.bindingHandlers['css'] = {
304.2262 +    'update': function (element, valueAccessor) {
304.2263 +        var value = ko.utils.unwrapObservable(valueAccessor());
304.2264 +        if (typeof value == "object") {
304.2265 +            for (var className in value) {
304.2266 +                var shouldHaveClass = ko.utils.unwrapObservable(value[className]);
304.2267 +                ko.utils.toggleDomNodeCssClass(element, className, shouldHaveClass);
304.2268 +            }
304.2269 +        } else {
304.2270 +            value = String(value || ''); // Make sure we don't try to store or set a non-string value
304.2271 +            ko.utils.toggleDomNodeCssClass(element, element[classesWrittenByBindingKey], false);
304.2272 +            element[classesWrittenByBindingKey] = value;
304.2273 +            ko.utils.toggleDomNodeCssClass(element, value, true);
304.2274 +        }
304.2275 +    }
304.2276 +};
304.2277 +ko.bindingHandlers['enable'] = {
304.2278 +    'update': function (element, valueAccessor) {
304.2279 +        var value = ko.utils.unwrapObservable(valueAccessor());
304.2280 +        if (value && element.disabled)
304.2281 +            element.removeAttribute("disabled");
304.2282 +        else if ((!value) && (!element.disabled))
304.2283 +            element.disabled = true;
304.2284 +    }
304.2285 +};
304.2286 +
304.2287 +ko.bindingHandlers['disable'] = {
304.2288 +    'update': function (element, valueAccessor) {
304.2289 +        ko.bindingHandlers['enable']['update'](element, function() { return !ko.utils.unwrapObservable(valueAccessor()) });
304.2290 +    }
304.2291 +};
304.2292 +// For certain common events (currently just 'click'), allow a simplified data-binding syntax
304.2293 +// e.g. click:handler instead of the usual full-length event:{click:handler}
304.2294 +function makeEventHandlerShortcut(eventName) {
304.2295 +    ko.bindingHandlers[eventName] = {
304.2296 +        'init': function(element, valueAccessor, allBindingsAccessor, viewModel) {
304.2297 +            var newValueAccessor = function () {
304.2298 +                var result = {};
304.2299 +                result[eventName] = valueAccessor();
304.2300 +                return result;
304.2301 +            };
304.2302 +            return ko.bindingHandlers['event']['init'].call(this, element, newValueAccessor, allBindingsAccessor, viewModel);
304.2303 +        }
304.2304 +    }
304.2305 +}
304.2306 +
304.2307 +ko.bindingHandlers['event'] = {
304.2308 +    'init' : function (element, valueAccessor, allBindingsAccessor, viewModel) {
304.2309 +        var eventsToHandle = valueAccessor() || {};
304.2310 +        for(var eventNameOutsideClosure in eventsToHandle) {
304.2311 +            (function() {
304.2312 +                var eventName = eventNameOutsideClosure; // Separate variable to be captured by event handler closure
304.2313 +                if (typeof eventName == "string") {
304.2314 +                    ko.utils.registerEventHandler(element, eventName, function (event) {
304.2315 +                        var handlerReturnValue;
304.2316 +                        var handlerFunction = valueAccessor()[eventName];
304.2317 +                        if (!handlerFunction)
304.2318 +                            return;
304.2319 +                        var allBindings = allBindingsAccessor();
304.2320 +
304.2321 +                        try {
304.2322 +                            // Take all the event args, and prefix with the viewmodel
304.2323 +                            var argsForHandler = ko.utils.makeArray(arguments);
304.2324 +                            argsForHandler.unshift(viewModel);
304.2325 +                            handlerReturnValue = handlerFunction.apply(viewModel, argsForHandler);
304.2326 +                        } finally {
304.2327 +                            if (handlerReturnValue !== true) { // Normally we want to prevent default action. Developer can override this be explicitly returning true.
304.2328 +                                if (event.preventDefault)
304.2329 +                                    event.preventDefault();
304.2330 +                                else
304.2331 +                                    event.returnValue = false;
304.2332 +                            }
304.2333 +                        }
304.2334 +
304.2335 +                        var bubble = allBindings[eventName + 'Bubble'] !== false;
304.2336 +                        if (!bubble) {
304.2337 +                            event.cancelBubble = true;
304.2338 +                            if (event.stopPropagation)
304.2339 +                                event.stopPropagation();
304.2340 +                        }
304.2341 +                    });
304.2342 +                }
304.2343 +            })();
304.2344 +        }
304.2345 +    }
304.2346 +};
304.2347 +// "foreach: someExpression" is equivalent to "template: { foreach: someExpression }"
304.2348 +// "foreach: { data: someExpression, afterAdd: myfn }" is equivalent to "template: { foreach: someExpression, afterAdd: myfn }"
304.2349 +ko.bindingHandlers['foreach'] = {
304.2350 +    makeTemplateValueAccessor: function(valueAccessor) {
304.2351 +        return function() {
304.2352 +            var modelValue = valueAccessor(),
304.2353 +                unwrappedValue = ko.utils.peekObservable(modelValue);    // Unwrap without setting a dependency here
304.2354 +
304.2355 +            // If unwrappedValue is the array, pass in the wrapped value on its own
304.2356 +            // The value will be unwrapped and tracked within the template binding
304.2357 +            // (See https://github.com/SteveSanderson/knockout/issues/523)
304.2358 +            if ((!unwrappedValue) || typeof unwrappedValue.length == "number")
304.2359 +                return { 'foreach': modelValue, 'templateEngine': ko.nativeTemplateEngine.instance };
304.2360 +
304.2361 +            // If unwrappedValue.data is the array, preserve all relevant options and unwrap again value so we get updates
304.2362 +            ko.utils.unwrapObservable(modelValue);
304.2363 +            return {
304.2364 +                'foreach': unwrappedValue['data'],
304.2365 +                'as': unwrappedValue['as'],
304.2366 +                'includeDestroyed': unwrappedValue['includeDestroyed'],
304.2367 +                'afterAdd': unwrappedValue['afterAdd'],
304.2368 +                'beforeRemove': unwrappedValue['beforeRemove'],
304.2369 +                'afterRender': unwrappedValue['afterRender'],
304.2370 +                'beforeMove': unwrappedValue['beforeMove'],
304.2371 +                'afterMove': unwrappedValue['afterMove'],
304.2372 +                'templateEngine': ko.nativeTemplateEngine.instance
304.2373 +            };
304.2374 +        };
304.2375 +    },
304.2376 +    'init': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
304.2377 +        return ko.bindingHandlers['template']['init'](element, ko.bindingHandlers['foreach'].makeTemplateValueAccessor(valueAccessor));
304.2378 +    },
304.2379 +    'update': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
304.2380 +        return ko.bindingHandlers['template']['update'](element, ko.bindingHandlers['foreach'].makeTemplateValueAccessor(valueAccessor), allBindingsAccessor, viewModel, bindingContext);
304.2381 +    }
304.2382 +};
304.2383 +ko.expressionRewriting.bindingRewriteValidators['foreach'] = false; // Can't rewrite control flow bindings
304.2384 +ko.virtualElements.allowedBindings['foreach'] = true;
304.2385 +var hasfocusUpdatingProperty = '__ko_hasfocusUpdating';
304.2386 +ko.bindingHandlers['hasfocus'] = {
304.2387 +    'init': function(element, valueAccessor, allBindingsAccessor) {
304.2388 +        var handleElementFocusChange = function(isFocused) {
304.2389 +            // Where possible, ignore which event was raised and determine focus state using activeElement,
304.2390 +            // as this avoids phantom focus/blur events raised when changing tabs in modern browsers.
304.2391 +            // However, not all KO-targeted browsers (Firefox 2) support activeElement. For those browsers,
304.2392 +            // prevent a loss of focus when changing tabs/windows by setting a flag that prevents hasfocus
304.2393 +            // from calling 'blur()' on the element when it loses focus.
304.2394 +            // Discussion at https://github.com/SteveSanderson/knockout/pull/352
304.2395 +            element[hasfocusUpdatingProperty] = true;
304.2396 +            var ownerDoc = element.ownerDocument;
304.2397 +            if ("activeElement" in ownerDoc) {
304.2398 +                isFocused = (ownerDoc.activeElement === element);
304.2399 +            }
304.2400 +            var modelValue = valueAccessor();
304.2401 +            ko.expressionRewriting.writeValueToProperty(modelValue, allBindingsAccessor, 'hasfocus', isFocused, true);
304.2402 +            element[hasfocusUpdatingProperty] = false;
304.2403 +        };
304.2404 +        var handleElementFocusIn = handleElementFocusChange.bind(null, true);
304.2405 +        var handleElementFocusOut = handleElementFocusChange.bind(null, false);
304.2406 +
304.2407 +        ko.utils.registerEventHandler(element, "focus", handleElementFocusIn);
304.2408 +        ko.utils.registerEventHandler(element, "focusin", handleElementFocusIn); // For IE
304.2409 +        ko.utils.registerEventHandler(element, "blur",  handleElementFocusOut);
304.2410 +        ko.utils.registerEventHandler(element, "focusout",  handleElementFocusOut); // For IE
304.2411 +    },
304.2412 +    'update': function(element, valueAccessor) {
304.2413 +        var value = ko.utils.unwrapObservable(valueAccessor());
304.2414 +        if (!element[hasfocusUpdatingProperty]) {
304.2415 +            value ? element.focus() : element.blur();
304.2416 +            ko.dependencyDetection.ignore(ko.utils.triggerEvent, null, [element, value ? "focusin" : "focusout"]); // For IE, which doesn't reliably fire "focus" or "blur" events synchronously
304.2417 +        }
304.2418 +    }
304.2419 +};
304.2420 +ko.bindingHandlers['html'] = {
304.2421 +    'init': function() {
304.2422 +        // Prevent binding on the dynamically-injected HTML (as developers are unlikely to expect that, and it has security implications)
304.2423 +        return { 'controlsDescendantBindings': true };
304.2424 +    },
304.2425 +    'update': function (element, valueAccessor) {
304.2426 +        // setHtml will unwrap the value if needed
304.2427 +        ko.utils.setHtml(element, valueAccessor());
304.2428 +    }
304.2429 +};
304.2430 +var withIfDomDataKey = '__ko_withIfBindingData';
304.2431 +// Makes a binding like with or if
304.2432 +function makeWithIfBinding(bindingKey, isWith, isNot, makeContextCallback) {
304.2433 +    ko.bindingHandlers[bindingKey] = {
304.2434 +        'init': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
304.2435 +            ko.utils.domData.set(element, withIfDomDataKey, {});
304.2436 +            return { 'controlsDescendantBindings': true };
304.2437 +        },
304.2438 +        'update': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
304.2439 +            var withIfData = ko.utils.domData.get(element, withIfDomDataKey),
304.2440 +                dataValue = ko.utils.unwrapObservable(valueAccessor()),
304.2441 +                shouldDisplay = !isNot !== !dataValue, // equivalent to isNot ? !dataValue : !!dataValue
304.2442 +                isFirstRender = !withIfData.savedNodes,
304.2443 +                needsRefresh = isFirstRender || isWith || (shouldDisplay !== withIfData.didDisplayOnLastUpdate);
304.2444 +
304.2445 +            if (needsRefresh) {
304.2446 +                if (isFirstRender) {
304.2447 +                    withIfData.savedNodes = ko.utils.cloneNodes(ko.virtualElements.childNodes(element), true /* shouldCleanNodes */);
304.2448 +                }
304.2449 +
304.2450 +                if (shouldDisplay) {
304.2451 +                    if (!isFirstRender) {
304.2452 +                        ko.virtualElements.setDomNodeChildren(element, ko.utils.cloneNodes(withIfData.savedNodes));
304.2453 +                    }
304.2454 +                    ko.applyBindingsToDescendants(makeContextCallback ? makeContextCallback(bindingContext, dataValue) : bindingContext, element);
304.2455 +                } else {
304.2456 +                    ko.virtualElements.emptyNode(element);
304.2457 +                }
304.2458 +
304.2459 +                withIfData.didDisplayOnLastUpdate = shouldDisplay;
304.2460 +            }
304.2461 +        }
304.2462 +    };
304.2463 +    ko.expressionRewriting.bindingRewriteValidators[bindingKey] = false; // Can't rewrite control flow bindings
304.2464 +    ko.virtualElements.allowedBindings[bindingKey] = true;
304.2465 +}
304.2466 +
304.2467 +// Construct the actual binding handlers
304.2468 +makeWithIfBinding('if');
304.2469 +makeWithIfBinding('ifnot', false /* isWith */, true /* isNot */);
304.2470 +makeWithIfBinding('with', true /* isWith */, false /* isNot */,
304.2471 +    function(bindingContext, dataValue) {
304.2472 +        return bindingContext['createChildContext'](dataValue);
304.2473 +    }
304.2474 +);
304.2475 +function ensureDropdownSelectionIsConsistentWithModelValue(element, modelValue, preferModelValue) {
304.2476 +    if (preferModelValue) {
304.2477 +        if (modelValue !== ko.selectExtensions.readValue(element))
304.2478 +            ko.selectExtensions.writeValue(element, modelValue);
304.2479 +    }
304.2480 +
304.2481 +    // No matter which direction we're syncing in, we want the end result to be equality between dropdown value and model value.
304.2482 +    // If they aren't equal, either we prefer the dropdown value, or the model value couldn't be represented, so either way,
304.2483 +    // change the model value to match the dropdown.
304.2484 +    if (modelValue !== ko.selectExtensions.readValue(element))
304.2485 +        ko.dependencyDetection.ignore(ko.utils.triggerEvent, null, [element, "change"]);
304.2486 +};
304.2487 +
304.2488 +ko.bindingHandlers['options'] = {
304.2489 +    'update': function (element, valueAccessor, allBindingsAccessor) {
304.2490 +        if (ko.utils.tagNameLower(element) !== "select")
304.2491 +            throw new Error("options binding applies only to SELECT elements");
304.2492 +
304.2493 +        var selectWasPreviouslyEmpty = element.length == 0;
304.2494 +        var previousSelectedValues = ko.utils.arrayMap(ko.utils.arrayFilter(element.childNodes, function (node) {
304.2495 +            return node.tagName && (ko.utils.tagNameLower(node) === "option") && node.selected;
304.2496 +        }), function (node) {
304.2497 +            return ko.selectExtensions.readValue(node) || node.innerText || node.textContent;
304.2498 +        });
304.2499 +        var previousScrollTop = element.scrollTop;
304.2500 +
304.2501 +        var value = ko.utils.unwrapObservable(valueAccessor());
304.2502 +        var selectedValue = element.value;
304.2503 +
304.2504 +        // Remove all existing <option>s.
304.2505 +        // Need to use .remove() rather than .removeChild() for <option>s otherwise IE behaves oddly (https://github.com/SteveSanderson/knockout/issues/134)
304.2506 +        while (element.length > 0) {
304.2507 +            ko.cleanNode(element.options[0]);
304.2508 +            element.remove(0);
304.2509 +        }
304.2510 +
304.2511 +        if (value) {
304.2512 +            var allBindings = allBindingsAccessor(),
304.2513 +                includeDestroyed = allBindings['optionsIncludeDestroyed'];
304.2514 +
304.2515 +            if (typeof value.length != "number")
304.2516 +                value = [value];
304.2517 +            if (allBindings['optionsCaption']) {
304.2518 +                var option = document.createElement("option");
304.2519 +                ko.utils.setHtml(option, allBindings['optionsCaption']);
304.2520 +                ko.selectExtensions.writeValue(option, undefined);
304.2521 +                element.appendChild(option);
304.2522 +            }
304.2523 +
304.2524 +            for (var i = 0, j = value.length; i < j; i++) {
304.2525 +                // Skip destroyed items
304.2526 +                var arrayEntry = value[i];
304.2527 +                if (arrayEntry && arrayEntry['_destroy'] && !includeDestroyed)
304.2528 +                    continue;
304.2529 +
304.2530 +                var option = document.createElement("option");
304.2531 +
304.2532 +                function applyToObject(object, predicate, defaultValue) {
304.2533 +                    var predicateType = typeof predicate;
304.2534 +                    if (predicateType == "function")    // Given a function; run it against the data value
304.2535 +                        return predicate(object);
304.2536 +                    else if (predicateType == "string") // Given a string; treat it as a property name on the data value
304.2537 +                        return object[predicate];
304.2538 +                    else                                // Given no optionsText arg; use the data value itself
304.2539 +                        return defaultValue;
304.2540 +                }
304.2541 +
304.2542 +                // Apply a value to the option element
304.2543 +                var optionValue = applyToObject(arrayEntry, allBindings['optionsValue'], arrayEntry);
304.2544 +                ko.selectExtensions.writeValue(option, ko.utils.unwrapObservable(optionValue));
304.2545 +
304.2546 +                // Apply some text to the option element
304.2547 +                var optionText = applyToObject(arrayEntry, allBindings['optionsText'], optionValue);
304.2548 +                ko.utils.setTextContent(option, optionText);
304.2549 +
304.2550 +                element.appendChild(option);
304.2551 +            }
304.2552 +
304.2553 +            // IE6 doesn't like us to assign selection to OPTION nodes before they're added to the document.
304.2554 +            // That's why we first added them without selection. Now it's time to set the selection.
304.2555 +            var newOptions = element.getElementsByTagName("option");
304.2556 +            var countSelectionsRetained = 0;
304.2557 +            for (var i = 0, j = newOptions.length; i < j; i++) {
304.2558 +                if (ko.utils.arrayIndexOf(previousSelectedValues, ko.selectExtensions.readValue(newOptions[i])) >= 0) {
304.2559 +                    ko.utils.setOptionNodeSelectionState(newOptions[i], true);
304.2560 +                    countSelectionsRetained++;
304.2561 +                }
304.2562 +            }
304.2563 +
304.2564 +            element.scrollTop = previousScrollTop;
304.2565 +
304.2566 +            if (selectWasPreviouslyEmpty && ('value' in allBindings)) {
304.2567 +                // Ensure consistency between model value and selected option.
304.2568 +                // If the dropdown is being populated for the first time here (or was otherwise previously empty),
304.2569 +                // the dropdown selection state is meaningless, so we preserve the model value.
304.2570 +                ensureDropdownSelectionIsConsistentWithModelValue(element, ko.utils.peekObservable(allBindings['value']), /* preferModelValue */ true);
304.2571 +            }
304.2572 +
304.2573 +            // Workaround for IE9 bug
304.2574 +            ko.utils.ensureSelectElementIsRenderedCorrectly(element);
304.2575 +        }
304.2576 +    }
304.2577 +};
304.2578 +ko.bindingHandlers['options'].optionValueDomDataKey = '__ko.optionValueDomData__';
304.2579 +ko.bindingHandlers['selectedOptions'] = {
304.2580 +    'init': function (element, valueAccessor, allBindingsAccessor) {
304.2581 +        ko.utils.registerEventHandler(element, "change", function () {
304.2582 +            var value = valueAccessor(), valueToWrite = [];
304.2583 +            ko.utils.arrayForEach(element.getElementsByTagName("option"), function(node) {
304.2584 +                if (node.selected)
304.2585 +                    valueToWrite.push(ko.selectExtensions.readValue(node));
304.2586 +            });
304.2587 +            ko.expressionRewriting.writeValueToProperty(value, allBindingsAccessor, 'value', valueToWrite);
304.2588 +        });
304.2589 +    },
304.2590 +    'update': function (element, valueAccessor) {
304.2591 +        if (ko.utils.tagNameLower(element) != "select")
304.2592 +            throw new Error("values binding applies only to SELECT elements");
304.2593 +
304.2594 +        var newValue = ko.utils.unwrapObservable(valueAccessor());
304.2595 +        if (newValue && typeof newValue.length == "number") {
304.2596 +            ko.utils.arrayForEach(element.getElementsByTagName("option"), function(node) {
304.2597 +                var isSelected = ko.utils.arrayIndexOf(newValue, ko.selectExtensions.readValue(node)) >= 0;
304.2598 +                ko.utils.setOptionNodeSelectionState(node, isSelected);
304.2599 +            });
304.2600 +        }
304.2601 +    }
304.2602 +};
304.2603 +ko.bindingHandlers['style'] = {
304.2604 +    'update': function (element, valueAccessor) {
304.2605 +        var value = ko.utils.unwrapObservable(valueAccessor() || {});
304.2606 +        for (var styleName in value) {
304.2607 +            if (typeof styleName == "string") {
304.2608 +                var styleValue = ko.utils.unwrapObservable(value[styleName]);
304.2609 +                element.style[styleName] = styleValue || ""; // Empty string removes the value, whereas null/undefined have no effect
304.2610 +            }
304.2611 +        }
304.2612 +    }
304.2613 +};
304.2614 +ko.bindingHandlers['submit'] = {
304.2615 +    'init': function (element, valueAccessor, allBindingsAccessor, viewModel) {
304.2616 +        if (typeof valueAccessor() != "function")
304.2617 +            throw new Error("The value for a submit binding must be a function");
304.2618 +        ko.utils.registerEventHandler(element, "submit", function (event) {
304.2619 +            var handlerReturnValue;
304.2620 +            var value = valueAccessor();
304.2621 +            try { handlerReturnValue = value.call(viewModel, element); }
304.2622 +            finally {
304.2623 +                if (handlerReturnValue !== true) { // Normally we want to prevent default action. Developer can override this be explicitly returning true.
304.2624 +                    if (event.preventDefault)
304.2625 +                        event.preventDefault();
304.2626 +                    else
304.2627 +                        event.returnValue = false;
304.2628 +                }
304.2629 +            }
304.2630 +        });
304.2631 +    }
304.2632 +};
304.2633 +ko.bindingHandlers['text'] = {
304.2634 +    'update': function (element, valueAccessor) {
304.2635 +        ko.utils.setTextContent(element, valueAccessor());
304.2636 +    }
304.2637 +};
304.2638 +ko.virtualElements.allowedBindings['text'] = true;
304.2639 +ko.bindingHandlers['uniqueName'] = {
304.2640 +    'init': function (element, valueAccessor) {
304.2641 +        if (valueAccessor()) {
304.2642 +            var name = "ko_unique_" + (++ko.bindingHandlers['uniqueName'].currentIndex);
304.2643 +            ko.utils.setElementName(element, name);
304.2644 +        }
304.2645 +    }
304.2646 +};
304.2647 +ko.bindingHandlers['uniqueName'].currentIndex = 0;
304.2648 +ko.bindingHandlers['value'] = {
304.2649 +    'init': function (element, valueAccessor, allBindingsAccessor) {
304.2650 +        // Always catch "change" event; possibly other events too if asked
304.2651 +        var eventsToCatch = ["change"];
304.2652 +        var requestedEventsToCatch = allBindingsAccessor()["valueUpdate"];
304.2653 +        var propertyChangedFired = false;
304.2654 +        if (requestedEventsToCatch) {
304.2655 +            if (typeof requestedEventsToCatch == "string") // Allow both individual event names, and arrays of event names
304.2656 +                requestedEventsToCatch = [requestedEventsToCatch];
304.2657 +            ko.utils.arrayPushAll(eventsToCatch, requestedEventsToCatch);
304.2658 +            eventsToCatch = ko.utils.arrayGetDistinctValues(eventsToCatch);
304.2659 +        }
304.2660 +
304.2661 +        var valueUpdateHandler = function() {
304.2662 +            propertyChangedFired = false;
304.2663 +            var modelValue = valueAccessor();
304.2664 +            var elementValue = ko.selectExtensions.readValue(element);
304.2665 +            ko.expressionRewriting.writeValueToProperty(modelValue, allBindingsAccessor, 'value', elementValue);
304.2666 +        }
304.2667 +
304.2668 +        // Workaround for https://github.com/SteveSanderson/knockout/issues/122
304.2669 +        // IE doesn't fire "change" events on textboxes if the user selects a value from its autocomplete list
304.2670 +        var ieAutoCompleteHackNeeded = ko.utils.ieVersion && element.tagName.toLowerCase() == "input" && element.type == "text"
304.2671 +                                       && element.autocomplete != "off" && (!element.form || element.form.autocomplete != "off");
304.2672 +        if (ieAutoCompleteHackNeeded && ko.utils.arrayIndexOf(eventsToCatch, "propertychange") == -1) {
304.2673 +            ko.utils.registerEventHandler(element, "propertychange", function () { propertyChangedFired = true });
304.2674 +            ko.utils.registerEventHandler(element, "blur", function() {
304.2675 +                if (propertyChangedFired) {
304.2676 +                    valueUpdateHandler();
304.2677 +                }
304.2678 +            });
304.2679 +        }
304.2680 +
304.2681 +        ko.utils.arrayForEach(eventsToCatch, function(eventName) {
304.2682 +            // The syntax "after<eventname>" means "run the handler asynchronously after the event"
304.2683 +            // This is useful, for example, to catch "keydown" events after the browser has updated the control
304.2684 +            // (otherwise, ko.selectExtensions.readValue(this) will receive the control's value *before* the key event)
304.2685 +            var handler = valueUpdateHandler;
304.2686 +            if (ko.utils.stringStartsWith(eventName, "after")) {
304.2687 +                handler = function() { setTimeout(valueUpdateHandler, 0) };
304.2688 +                eventName = eventName.substring("after".length);
304.2689 +            }
304.2690 +            ko.utils.registerEventHandler(element, eventName, handler);
304.2691 +        });
304.2692 +    },
304.2693 +    'update': function (element, valueAccessor) {
304.2694 +        var valueIsSelectOption = ko.utils.tagNameLower(element) === "select";
304.2695 +        var newValue = ko.utils.unwrapObservable(valueAccessor());
304.2696 +        var elementValue = ko.selectExtensions.readValue(element);
304.2697 +        var valueHasChanged = (newValue != elementValue);
304.2698 +
304.2699 +        // JavaScript's 0 == "" behavious is unfortunate here as it prevents writing 0 to an empty text box (loose equality suggests the values are the same).
304.2700 +        // We don't want to do a strict equality comparison as that is more confusing for developers in certain cases, so we specifically special case 0 != "" here.
304.2701 +        if ((newValue === 0) && (elementValue !== 0) && (elementValue !== "0"))
304.2702 +            valueHasChanged = true;
304.2703 +
304.2704 +        if (valueHasChanged) {
304.2705 +            var applyValueAction = function () { ko.selectExtensions.writeValue(element, newValue); };
304.2706 +            applyValueAction();
304.2707 +
304.2708 +            // Workaround for IE6 bug: It won't reliably apply values to SELECT nodes during the same execution thread
304.2709 +            // right after you've changed the set of OPTION nodes on it. So for that node type, we'll schedule a second thread
304.2710 +            // to apply the value as well.
304.2711 +            var alsoApplyAsynchronously = valueIsSelectOption;
304.2712 +            if (alsoApplyAsynchronously)
304.2713 +                setTimeout(applyValueAction, 0);
304.2714 +        }
304.2715 +
304.2716 +        // If you try to set a model value that can't be represented in an already-populated dropdown, reject that change,
304.2717 +        // because you're not allowed to have a model value that disagrees with a visible UI selection.
304.2718 +        if (valueIsSelectOption && (element.length > 0))
304.2719 +            ensureDropdownSelectionIsConsistentWithModelValue(element, newValue, /* preferModelValue */ false);
304.2720 +    }
304.2721 +};
304.2722 +ko.bindingHandlers['visible'] = {
304.2723 +    'update': function (element, valueAccessor) {
304.2724 +        var value = ko.utils.unwrapObservable(valueAccessor());
304.2725 +        var isCurrentlyVisible = !(element.style.display == "none");
304.2726 +        if (value && !isCurrentlyVisible)
304.2727 +            element.style.display = "";
304.2728 +        else if ((!value) && isCurrentlyVisible)
304.2729 +            element.style.display = "none";
304.2730 +    }
304.2731 +};
304.2732 +// 'click' is just a shorthand for the usual full-length event:{click:handler}
304.2733 +makeEventHandlerShortcut('click');
304.2734 +// If you want to make a custom template engine,
304.2735 +//
304.2736 +// [1] Inherit from this class (like ko.nativeTemplateEngine does)
304.2737 +// [2] Override 'renderTemplateSource', supplying a function with this signature:
304.2738 +//
304.2739 +//        function (templateSource, bindingContext, options) {
304.2740 +//            // - templateSource.text() is the text of the template you should render
304.2741 +//            // - bindingContext.$data is the data you should pass into the template
304.2742 +//            //   - you might also want to make bindingContext.$parent, bindingContext.$parents,
304.2743 +//            //     and bindingContext.$root available in the template too
304.2744 +//            // - options gives you access to any other properties set on "data-bind: { template: options }"
304.2745 +//            //
304.2746 +//            // Return value: an array of DOM nodes
304.2747 +//        }
304.2748 +//
304.2749 +// [3] Override 'createJavaScriptEvaluatorBlock', supplying a function with this signature:
304.2750 +//
304.2751 +//        function (script) {
304.2752 +//            // Return value: Whatever syntax means "Evaluate the JavaScript statement 'script' and output the result"
304.2753 +//            //               For example, the jquery.tmpl template engine converts 'someScript' to '${ someScript }'
304.2754 +//        }
304.2755 +//
304.2756 +//     This is only necessary if you want to allow data-bind attributes to reference arbitrary template variables.
304.2757 +//     If you don't want to allow that, you can set the property 'allowTemplateRewriting' to false (like ko.nativeTemplateEngine does)
304.2758 +//     and then you don't need to override 'createJavaScriptEvaluatorBlock'.
304.2759 +
304.2760 +ko.templateEngine = function () { };
304.2761 +
304.2762 +ko.templateEngine.prototype['renderTemplateSource'] = function (templateSource, bindingContext, options) {
304.2763 +    throw new Error("Override renderTemplateSource");
304.2764 +};
304.2765 +
304.2766 +ko.templateEngine.prototype['createJavaScriptEvaluatorBlock'] = function (script) {
304.2767 +    throw new Error("Override createJavaScriptEvaluatorBlock");
304.2768 +};
304.2769 +
304.2770 +ko.templateEngine.prototype['makeTemplateSource'] = function(template, templateDocument) {
304.2771 +    // Named template
304.2772 +    if (typeof template == "string") {
304.2773 +        templateDocument = templateDocument || document;
304.2774 +        var elem = templateDocument.getElementById(template);
304.2775 +        if (!elem)
304.2776 +            throw new Error("Cannot find template with ID " + template);
304.2777 +        return new ko.templateSources.domElement(elem);
304.2778 +    } else if ((template.nodeType == 1) || (template.nodeType == 8)) {
304.2779 +        // Anonymous template
304.2780 +        return new ko.templateSources.anonymousTemplate(template);
304.2781 +    } else
304.2782 +        throw new Error("Unknown template type: " + template);
304.2783 +};
304.2784 +
304.2785 +ko.templateEngine.prototype['renderTemplate'] = function (template, bindingContext, options, templateDocument) {
304.2786 +    var templateSource = this['makeTemplateSource'](template, templateDocument);
304.2787 +    return this['renderTemplateSource'](templateSource, bindingContext, options);
304.2788 +};
304.2789 +
304.2790 +ko.templateEngine.prototype['isTemplateRewritten'] = function (template, templateDocument) {
304.2791 +    // Skip rewriting if requested
304.2792 +    if (this['allowTemplateRewriting'] === false)
304.2793 +        return true;
304.2794 +    return this['makeTemplateSource'](template, templateDocument)['data']("isRewritten");
304.2795 +};
304.2796 +
304.2797 +ko.templateEngine.prototype['rewriteTemplate'] = function (template, rewriterCallback, templateDocument) {
304.2798 +    var templateSource = this['makeTemplateSource'](template, templateDocument);
304.2799 +    var rewritten = rewriterCallback(templateSource['text']());
304.2800 +    templateSource['text'](rewritten);
304.2801 +    templateSource['data']("isRewritten", true);
304.2802 +};
304.2803 +
304.2804 +ko.exportSymbol('templateEngine', ko.templateEngine);
304.2805 +
304.2806 +ko.templateRewriting = (function () {
304.2807 +    var memoizeDataBindingAttributeSyntaxRegex = /(<[a-z]+\d*(\s+(?!data-bind=)[a-z0-9\-]+(=(\"[^\"]*\"|\'[^\']*\'))?)*\s+)data-bind=(["'])([\s\S]*?)\5/gi;
304.2808 +    var memoizeVirtualContainerBindingSyntaxRegex = /<!--\s*ko\b\s*([\s\S]*?)\s*-->/g;
304.2809 +
304.2810 +    function validateDataBindValuesForRewriting(keyValueArray) {
304.2811 +        var allValidators = ko.expressionRewriting.bindingRewriteValidators;
304.2812 +        for (var i = 0; i < keyValueArray.length; i++) {
304.2813 +            var key = keyValueArray[i]['key'];
304.2814 +            if (allValidators.hasOwnProperty(key)) {
304.2815 +                var validator = allValidators[key];
304.2816 +
304.2817 +                if (typeof validator === "function") {
304.2818 +                    var possibleErrorMessage = validator(keyValueArray[i]['value']);
304.2819 +                    if (possibleErrorMessage)
304.2820 +                        throw new Error(possibleErrorMessage);
304.2821 +                } else if (!validator) {
304.2822 +                    throw new Error("This template engine does not support the '" + key + "' binding within its templates");
304.2823 +                }
304.2824 +            }
304.2825 +        }
304.2826 +    }
304.2827 +
304.2828 +    function constructMemoizedTagReplacement(dataBindAttributeValue, tagToRetain, templateEngine) {
304.2829 +        var dataBindKeyValueArray = ko.expressionRewriting.parseObjectLiteral(dataBindAttributeValue);
304.2830 +        validateDataBindValuesForRewriting(dataBindKeyValueArray);
304.2831 +        var rewrittenDataBindAttributeValue = ko.expressionRewriting.preProcessBindings(dataBindKeyValueArray);
304.2832 +
304.2833 +        // For no obvious reason, Opera fails to evaluate rewrittenDataBindAttributeValue unless it's wrapped in an additional
304.2834 +        // anonymous function, even though Opera's built-in debugger can evaluate it anyway. No other browser requires this
304.2835 +        // extra indirection.
304.2836 +        var applyBindingsToNextSiblingScript =
304.2837 +            "ko.__tr_ambtns(function($context,$element){return(function(){return{ " + rewrittenDataBindAttributeValue + " } })()})";
304.2838 +        return templateEngine['createJavaScriptEvaluatorBlock'](applyBindingsToNextSiblingScript) + tagToRetain;
304.2839 +    }
304.2840 +
304.2841 +    return {
304.2842 +        ensureTemplateIsRewritten: function (template, templateEngine, templateDocument) {
304.2843 +            if (!templateEngine['isTemplateRewritten'](template, templateDocument))
304.2844 +                templateEngine['rewriteTemplate'](template, function (htmlString) {
304.2845 +                    return ko.templateRewriting.memoizeBindingAttributeSyntax(htmlString, templateEngine);
304.2846 +                }, templateDocument);
304.2847 +        },
304.2848 +
304.2849 +        memoizeBindingAttributeSyntax: function (htmlString, templateEngine) {
304.2850 +            return htmlString.replace(memoizeDataBindingAttributeSyntaxRegex, function () {
304.2851 +                return constructMemoizedTagReplacement(/* dataBindAttributeValue: */ arguments[6], /* tagToRetain: */ arguments[1], templateEngine);
304.2852 +            }).replace(memoizeVirtualContainerBindingSyntaxRegex, function() {
304.2853 +                return constructMemoizedTagReplacement(/* dataBindAttributeValue: */ arguments[1], /* tagToRetain: */ "<!-- ko -->", templateEngine);
304.2854 +            });
304.2855 +        },
304.2856 +
304.2857 +        applyMemoizedBindingsToNextSibling: function (bindings) {
304.2858 +            return ko.memoization.memoize(function (domNode, bindingContext) {
304.2859 +                if (domNode.nextSibling)
304.2860 +                    ko.applyBindingsToNode(domNode.nextSibling, bindings, bindingContext);
304.2861 +            });
304.2862 +        }
304.2863 +    }
304.2864 +})();
304.2865 +
304.2866 +
304.2867 +// Exported only because it has to be referenced by string lookup from within rewritten template
304.2868 +ko.exportSymbol('__tr_ambtns', ko.templateRewriting.applyMemoizedBindingsToNextSibling);
304.2869 +(function() {
304.2870 +    // A template source represents a read/write way of accessing a template. This is to eliminate the need for template loading/saving
304.2871 +    // logic to be duplicated in every template engine (and means they can all work with anonymous templates, etc.)
304.2872 +    //
304.2873 +    // Two are provided by default:
304.2874 +    //  1. ko.templateSources.domElement       - reads/writes the text content of an arbitrary DOM element
304.2875 +    //  2. ko.templateSources.anonymousElement - uses ko.utils.domData to read/write text *associated* with the DOM element, but
304.2876 +    //                                           without reading/writing the actual element text content, since it will be overwritten
304.2877 +    //                                           with the rendered template output.
304.2878 +    // You can implement your own template source if you want to fetch/store templates somewhere other than in DOM elements.
304.2879 +    // Template sources need to have the following functions:
304.2880 +    //   text() 			- returns the template text from your storage location
304.2881 +    //   text(value)		- writes the supplied template text to your storage location
304.2882 +    //   data(key)			- reads values stored using data(key, value) - see below
304.2883 +    //   data(key, value)	- associates "value" with this template and the key "key". Is used to store information like "isRewritten".
304.2884 +    //
304.2885 +    // Optionally, template sources can also have the following functions:
304.2886 +    //   nodes()            - returns a DOM element containing the nodes of this template, where available
304.2887 +    //   nodes(value)       - writes the given DOM element to your storage location
304.2888 +    // If a DOM element is available for a given template source, template engines are encouraged to use it in preference over text()
304.2889 +    // for improved speed. However, all templateSources must supply text() even if they don't supply nodes().
304.2890 +    //
304.2891 +    // Once you've implemented a templateSource, make your template engine use it by subclassing whatever template engine you were
304.2892 +    // using and overriding "makeTemplateSource" to return an instance of your custom template source.
304.2893 +
304.2894 +    ko.templateSources = {};
304.2895 +
304.2896 +    // ---- ko.templateSources.domElement -----
304.2897 +
304.2898 +    ko.templateSources.domElement = function(element) {
304.2899 +        this.domElement = element;
304.2900 +    }
304.2901 +
304.2902 +    ko.templateSources.domElement.prototype['text'] = function(/* valueToWrite */) {
304.2903 +        var tagNameLower = ko.utils.tagNameLower(this.domElement),
304.2904 +            elemContentsProperty = tagNameLower === "script" ? "text"
304.2905 +                                 : tagNameLower === "textarea" ? "value"
304.2906 +                                 : "innerHTML";
304.2907 +
304.2908 +        if (arguments.length == 0) {
304.2909 +            return this.domElement[elemContentsProperty];
304.2910 +        } else {
304.2911 +            var valueToWrite = arguments[0];
304.2912 +            if (elemContentsProperty === "innerHTML")
304.2913 +                ko.utils.setHtml(this.domElement, valueToWrite);
304.2914 +            else
304.2915 +                this.domElement[elemContentsProperty] = valueToWrite;
304.2916 +        }
304.2917 +    };
304.2918 +
304.2919 +    ko.templateSources.domElement.prototype['data'] = function(key /*, valueToWrite */) {
304.2920 +        if (arguments.length === 1) {
304.2921 +            return ko.utils.domData.get(this.domElement, "templateSourceData_" + key);
304.2922 +        } else {
304.2923 +            ko.utils.domData.set(this.domElement, "templateSourceData_" + key, arguments[1]);
304.2924 +        }
304.2925 +    };
304.2926 +
304.2927 +    // ---- ko.templateSources.anonymousTemplate -----
304.2928 +    // Anonymous templates are normally saved/retrieved as DOM nodes through "nodes".
304.2929 +    // For compatibility, you can also read "text"; it will be serialized from the nodes on demand.
304.2930 +    // Writing to "text" is still supported, but then the template data will not be available as DOM nodes.
304.2931 +
304.2932 +    var anonymousTemplatesDomDataKey = "__ko_anon_template__";
304.2933 +    ko.templateSources.anonymousTemplate = function(element) {
304.2934 +        this.domElement = element;
304.2935 +    }
304.2936 +    ko.templateSources.anonymousTemplate.prototype = new ko.templateSources.domElement();
304.2937 +    ko.templateSources.anonymousTemplate.prototype['text'] = function(/* valueToWrite */) {
304.2938 +        if (arguments.length == 0) {
304.2939 +            var templateData = ko.utils.domData.get(this.domElement, anonymousTemplatesDomDataKey) || {};
304.2940 +            if (templateData.textData === undefined && templateData.containerData)
304.2941 +                templateData.textData = templateData.containerData.innerHTML;
304.2942 +            return templateData.textData;
304.2943 +        } else {
304.2944 +            var valueToWrite = arguments[0];
304.2945 +            ko.utils.domData.set(this.domElement, anonymousTemplatesDomDataKey, {textData: valueToWrite});
304.2946 +        }
304.2947 +    };
304.2948 +    ko.templateSources.domElement.prototype['nodes'] = function(/* valueToWrite */) {
304.2949 +        if (arguments.length == 0) {
304.2950 +            var templateData = ko.utils.domData.get(this.domElement, anonymousTemplatesDomDataKey) || {};
304.2951 +            return templateData.containerData;
304.2952 +        } else {
304.2953 +            var valueToWrite = arguments[0];
304.2954 +            ko.utils.domData.set(this.domElement, anonymousTemplatesDomDataKey, {containerData: valueToWrite});
304.2955 +        }
304.2956 +    };
304.2957 +
304.2958 +    ko.exportSymbol('templateSources', ko.templateSources);
304.2959 +    ko.exportSymbol('templateSources.domElement', ko.templateSources.domElement);
304.2960 +    ko.exportSymbol('templateSources.anonymousTemplate', ko.templateSources.anonymousTemplate);
304.2961 +})();
304.2962 +(function () {
304.2963 +    var _templateEngine;
304.2964 +    ko.setTemplateEngine = function (templateEngine) {
304.2965 +        if ((templateEngine != undefined) && !(templateEngine instanceof ko.templateEngine))
304.2966 +            throw new Error("templateEngine must inherit from ko.templateEngine");
304.2967 +        _templateEngine = templateEngine;
304.2968 +    }
304.2969 +
304.2970 +    function invokeForEachNodeOrCommentInContinuousRange(firstNode, lastNode, action) {
304.2971 +        var node, nextInQueue = firstNode, firstOutOfRangeNode = ko.virtualElements.nextSibling(lastNode);
304.2972 +        while (nextInQueue && ((node = nextInQueue) !== firstOutOfRangeNode)) {
304.2973 +            nextInQueue = ko.virtualElements.nextSibling(node);
304.2974 +            if (node.nodeType === 1 || node.nodeType === 8)
304.2975 +                action(node);
304.2976 +        }
304.2977 +    }
304.2978 +
304.2979 +    function activateBindingsOnContinuousNodeArray(continuousNodeArray, bindingContext) {
304.2980 +        // To be used on any nodes that have been rendered by a template and have been inserted into some parent element
304.2981 +        // Walks through continuousNodeArray (which *must* be continuous, i.e., an uninterrupted sequence of sibling nodes, because
304.2982 +        // the algorithm for walking them relies on this), and for each top-level item in the virtual-element sense,
304.2983 +        // (1) Does a regular "applyBindings" to associate bindingContext with this node and to activate any non-memoized bindings
304.2984 +        // (2) Unmemoizes any memos in the DOM subtree (e.g., to activate bindings that had been memoized during template rewriting)
304.2985 +
304.2986 +        if (continuousNodeArray.length) {
304.2987 +            var firstNode = continuousNodeArray[0], lastNode = continuousNodeArray[continuousNodeArray.length - 1];
304.2988 +
304.2989 +            // Need to applyBindings *before* unmemoziation, because unmemoization might introduce extra nodes (that we don't want to re-bind)
304.2990 +            // whereas a regular applyBindings won't introduce new memoized nodes
304.2991 +            invokeForEachNodeOrCommentInContinuousRange(firstNode, lastNode, function(node) {
304.2992 +                ko.applyBindings(bindingContext, node);
304.2993 +            });
304.2994 +            invokeForEachNodeOrCommentInContinuousRange(firstNode, lastNode, function(node) {
304.2995 +                ko.memoization.unmemoizeDomNodeAndDescendants(node, [bindingContext]);
304.2996 +            });
304.2997 +        }
304.2998 +    }
304.2999 +
304.3000 +    function getFirstNodeFromPossibleArray(nodeOrNodeArray) {
304.3001 +        return nodeOrNodeArray.nodeType ? nodeOrNodeArray
304.3002 +                                        : nodeOrNodeArray.length > 0 ? nodeOrNodeArray[0]
304.3003 +                                        : null;
304.3004 +    }
304.3005 +
304.3006 +    function executeTemplate(targetNodeOrNodeArray, renderMode, template, bindingContext, options) {
304.3007 +        options = options || {};
304.3008 +        var firstTargetNode = targetNodeOrNodeArray && getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
304.3009 +        var templateDocument = firstTargetNode && firstTargetNode.ownerDocument;
304.3010 +        var templateEngineToUse = (options['templateEngine'] || _templateEngine);
304.3011 +        ko.templateRewriting.ensureTemplateIsRewritten(template, templateEngineToUse, templateDocument);
304.3012 +        var renderedNodesArray = templateEngineToUse['renderTemplate'](template, bindingContext, options, templateDocument);
304.3013 +
304.3014 +        // Loosely check result is an array of DOM nodes
304.3015 +        if ((typeof renderedNodesArray.length != "number") || (renderedNodesArray.length > 0 && typeof renderedNodesArray[0].nodeType != "number"))
304.3016 +            throw new Error("Template engine must return an array of DOM nodes");
304.3017 +
304.3018 +        var haveAddedNodesToParent = false;
304.3019 +        switch (renderMode) {
304.3020 +            case "replaceChildren":
304.3021 +                ko.virtualElements.setDomNodeChildren(targetNodeOrNodeArray, renderedNodesArray);
304.3022 +                haveAddedNodesToParent = true;
304.3023 +                break;
304.3024 +            case "replaceNode":
304.3025 +                ko.utils.replaceDomNodes(targetNodeOrNodeArray, renderedNodesArray);
304.3026 +                haveAddedNodesToParent = true;
304.3027 +                break;
304.3028 +            case "ignoreTargetNode": break;
304.3029 +            default:
304.3030 +                throw new Error("Unknown renderMode: " + renderMode);
304.3031 +        }
304.3032 +
304.3033 +        if (haveAddedNodesToParent) {
304.3034 +            activateBindingsOnContinuousNodeArray(renderedNodesArray, bindingContext);
304.3035 +            if (options['afterRender'])
304.3036 +                ko.dependencyDetection.ignore(options['afterRender'], null, [renderedNodesArray, bindingContext['$data']]);
304.3037 +        }
304.3038 +
304.3039 +        return renderedNodesArray;
304.3040 +    }
304.3041 +
304.3042 +    ko.renderTemplate = function (template, dataOrBindingContext, options, targetNodeOrNodeArray, renderMode) {
304.3043 +        options = options || {};
304.3044 +        if ((options['templateEngine'] || _templateEngine) == undefined)
304.3045 +            throw new Error("Set a template engine before calling renderTemplate");
304.3046 +        renderMode = renderMode || "replaceChildren";
304.3047 +
304.3048 +        if (targetNodeOrNodeArray) {
304.3049 +            var firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
304.3050 +
304.3051 +            var whenToDispose = function () { return (!firstTargetNode) || !ko.utils.domNodeIsAttachedToDocument(firstTargetNode); }; // Passive disposal (on next evaluation)
304.3052 +            var activelyDisposeWhenNodeIsRemoved = (firstTargetNode && renderMode == "replaceNode") ? firstTargetNode.parentNode : firstTargetNode;
304.3053 +
304.3054 +            return ko.dependentObservable( // So the DOM is automatically updated when any dependency changes
304.3055 +                function () {
304.3056 +                    // Ensure we've got a proper binding context to work with
304.3057 +                    var bindingContext = (dataOrBindingContext && (dataOrBindingContext instanceof ko.bindingContext))
304.3058 +                        ? dataOrBindingContext
304.3059 +                        : new ko.bindingContext(ko.utils.unwrapObservable(dataOrBindingContext));
304.3060 +
304.3061 +                    // Support selecting template as a function of the data being rendered
304.3062 +                    var templateName = typeof(template) == 'function' ? template(bindingContext['$data'], bindingContext) : template;
304.3063 +
304.3064 +                    var renderedNodesArray = executeTemplate(targetNodeOrNodeArray, renderMode, templateName, bindingContext, options);
304.3065 +                    if (renderMode == "replaceNode") {
304.3066 +                        targetNodeOrNodeArray = renderedNodesArray;
304.3067 +                        firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
304.3068 +                    }
304.3069 +                },
304.3070 +                null,
304.3071 +                { disposeWhen: whenToDispose, disposeWhenNodeIsRemoved: activelyDisposeWhenNodeIsRemoved }
304.3072 +            );
304.3073 +        } else {
304.3074 +            // We don't yet have a DOM node to evaluate, so use a memo and render the template later when there is a DOM node
304.3075 +            return ko.memoization.memoize(function (domNode) {
304.3076 +                ko.renderTemplate(template, dataOrBindingContext, options, domNode, "replaceNode");
304.3077 +            });
304.3078 +        }
304.3079 +    };
304.3080 +
304.3081 +    ko.renderTemplateForEach = function (template, arrayOrObservableArray, options, targetNode, parentBindingContext) {
304.3082 +        // Since setDomNodeChildrenFromArrayMapping always calls executeTemplateForArrayItem and then
304.3083 +        // activateBindingsCallback for added items, we can store the binding context in the former to use in the latter.
304.3084 +        var arrayItemContext;
304.3085 +
304.3086 +        // This will be called by setDomNodeChildrenFromArrayMapping to get the nodes to add to targetNode
304.3087 +        var executeTemplateForArrayItem = function (arrayValue, index) {
304.3088 +            // Support selecting template as a function of the data being rendered
304.3089 +            arrayItemContext = parentBindingContext['createChildContext'](ko.utils.unwrapObservable(arrayValue), options['as']);
304.3090 +            arrayItemContext['$index'] = index;
304.3091 +            var templateName = typeof(template) == 'function' ? template(arrayValue, arrayItemContext) : template;
304.3092 +            return executeTemplate(null, "ignoreTargetNode", templateName, arrayItemContext, options);
304.3093 +        }
304.3094 +
304.3095 +        // This will be called whenever setDomNodeChildrenFromArrayMapping has added nodes to targetNode
304.3096 +        var activateBindingsCallback = function(arrayValue, addedNodesArray, index) {
304.3097 +            activateBindingsOnContinuousNodeArray(addedNodesArray, arrayItemContext);
304.3098 +            if (options['afterRender'])
304.3099 +                options['afterRender'](addedNodesArray, arrayValue);
304.3100 +        };
304.3101 +
304.3102 +        return ko.dependentObservable(function () {
304.3103 +            var unwrappedArray = ko.utils.unwrapObservable(arrayOrObservableArray) || [];
304.3104 +            if (typeof unwrappedArray.length == "undefined") // Coerce single value into array
304.3105 +                unwrappedArray = [unwrappedArray];
304.3106 +
304.3107 +            // Filter out any entries marked as destroyed
304.3108 +            var filteredArray = ko.utils.arrayFilter(unwrappedArray, function(item) {
304.3109 +                return options['includeDestroyed'] || item === undefined || item === null || !ko.utils.unwrapObservable(item['_destroy']);
304.3110 +            });
304.3111 +
304.3112 +            // Call setDomNodeChildrenFromArrayMapping, ignoring any observables unwrapped within (most likely from a callback function).
304.3113 +            // If the array items are observables, though, they will be unwrapped in executeTemplateForArrayItem and managed within setDomNodeChildrenFromArrayMapping.
304.3114 +            ko.dependencyDetection.ignore(ko.utils.setDomNodeChildrenFromArrayMapping, null, [targetNode, filteredArray, executeTemplateForArrayItem, options, activateBindingsCallback]);
304.3115 +
304.3116 +        }, null, { disposeWhenNodeIsRemoved: targetNode });
304.3117 +    };
304.3118 +
304.3119 +    var templateComputedDomDataKey = '__ko__templateComputedDomDataKey__';
304.3120 +    function disposeOldComputedAndStoreNewOne(element, newComputed) {
304.3121 +        var oldComputed = ko.utils.domData.get(element, templateComputedDomDataKey);
304.3122 +        if (oldComputed && (typeof(oldComputed.dispose) == 'function'))
304.3123 +            oldComputed.dispose();
304.3124 +        ko.utils.domData.set(element, templateComputedDomDataKey, (newComputed && newComputed.isActive()) ? newComputed : undefined);
304.3125 +    }
304.3126 +
304.3127 +    ko.bindingHandlers['template'] = {
304.3128 +        'init': function(element, valueAccessor) {
304.3129 +            // Support anonymous templates
304.3130 +            var bindingValue = ko.utils.unwrapObservable(valueAccessor());
304.3131 +            if ((typeof bindingValue != "string") && (!bindingValue['name']) && (element.nodeType == 1 || element.nodeType == 8)) {
304.3132 +                // It's an anonymous template - store the element contents, then clear the element
304.3133 +                var templateNodes = element.nodeType == 1 ? element.childNodes : ko.virtualElements.childNodes(element),
304.3134 +                    container = ko.utils.moveCleanedNodesToContainerElement(templateNodes); // This also removes the nodes from their current parent
304.3135 +                new ko.templateSources.anonymousTemplate(element)['nodes'](container);
304.3136 +            }
304.3137 +            return { 'controlsDescendantBindings': true };
304.3138 +        },
304.3139 +        'update': function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
304.3140 +            var templateName = ko.utils.unwrapObservable(valueAccessor()),
304.3141 +                options = {},
304.3142 +                shouldDisplay = true,
304.3143 +                dataValue,
304.3144 +                templateComputed = null;
304.3145 +
304.3146 +            if (typeof templateName != "string") {
304.3147 +                options = templateName;
304.3148 +                templateName = options['name'];
304.3149 +
304.3150 +                // Support "if"/"ifnot" conditions
304.3151 +                if ('if' in options)
304.3152 +                    shouldDisplay = ko.utils.unwrapObservable(options['if']);
304.3153 +                if (shouldDisplay && 'ifnot' in options)
304.3154 +                    shouldDisplay = !ko.utils.unwrapObservable(options['ifnot']);
304.3155 +
304.3156 +                dataValue = ko.utils.unwrapObservable(options['data']);
304.3157 +            }
304.3158 +
304.3159 +            if ('foreach' in options) {
304.3160 +                // Render once for each data point (treating data set as empty if shouldDisplay==false)
304.3161 +                var dataArray = (shouldDisplay && options['foreach']) || [];
304.3162 +                templateComputed = ko.renderTemplateForEach(templateName || element, dataArray, options, element, bindingContext);
304.3163 +            } else if (!shouldDisplay) {
304.3164 +                ko.virtualElements.emptyNode(element);
304.3165 +            } else {
304.3166 +                // Render once for this single data point (or use the viewModel if no data was provided)
304.3167 +                var innerBindingContext = ('data' in options) ?
304.3168 +                    bindingContext['createChildContext'](dataValue, options['as']) :  // Given an explitit 'data' value, we create a child binding context for it
304.3169 +                    bindingContext;                                                        // Given no explicit 'data' value, we retain the same binding context
304.3170 +                templateComputed = ko.renderTemplate(templateName || element, innerBindingContext, options, element);
304.3171 +            }
304.3172 +
304.3173 +            // It only makes sense to have a single template computed per element (otherwise which one should have its output displayed?)
304.3174 +            disposeOldComputedAndStoreNewOne(element, templateComputed);
304.3175 +        }
304.3176 +    };
304.3177 +
304.3178 +    // Anonymous templates can't be rewritten. Give a nice error message if you try to do it.
304.3179 +    ko.expressionRewriting.bindingRewriteValidators['template'] = function(bindingValue) {
304.3180 +        var parsedBindingValue = ko.expressionRewriting.parseObjectLiteral(bindingValue);
304.3181 +
304.3182 +        if ((parsedBindingValue.length == 1) && parsedBindingValue[0]['unknown'])
304.3183 +            return null; // It looks like a string literal, not an object literal, so treat it as a named template (which is allowed for rewriting)
304.3184 +
304.3185 +        if (ko.expressionRewriting.keyValueArrayContainsKey(parsedBindingValue, "name"))
304.3186 +            return null; // Named templates can be rewritten, so return "no error"
304.3187 +        return "This template engine does not support anonymous templates nested within its templates";
304.3188 +    };
304.3189 +
304.3190 +    ko.virtualElements.allowedBindings['template'] = true;
304.3191 +})();
304.3192 +
304.3193 +ko.exportSymbol('setTemplateEngine', ko.setTemplateEngine);
304.3194 +ko.exportSymbol('renderTemplate', ko.renderTemplate);
304.3195 +
304.3196 +ko.utils.compareArrays = (function () {
304.3197 +    var statusNotInOld = 'added', statusNotInNew = 'deleted';
304.3198 +
304.3199 +    // Simple calculation based on Levenshtein distance.
304.3200 +    function compareArrays(oldArray, newArray, dontLimitMoves) {
304.3201 +        oldArray = oldArray || [];
304.3202 +        newArray = newArray || [];
304.3203 +
304.3204 +        if (oldArray.length <= newArray.length)
304.3205 +            return compareSmallArrayToBigArray(oldArray, newArray, statusNotInOld, statusNotInNew, dontLimitMoves);
304.3206 +        else
304.3207 +            return compareSmallArrayToBigArray(newArray, oldArray, statusNotInNew, statusNotInOld, dontLimitMoves);
304.3208 +    }
304.3209 +
304.3210 +    function compareSmallArrayToBigArray(smlArray, bigArray, statusNotInSml, statusNotInBig, dontLimitMoves) {
304.3211 +        var myMin = Math.min,
304.3212 +            myMax = Math.max,
304.3213 +            editDistanceMatrix = [],
304.3214 +            smlIndex, smlIndexMax = smlArray.length,
304.3215 +            bigIndex, bigIndexMax = bigArray.length,
304.3216 +            compareRange = (bigIndexMax - smlIndexMax) || 1,
304.3217 +            maxDistance = smlIndexMax + bigIndexMax + 1,
304.3218 +            thisRow, lastRow,
304.3219 +            bigIndexMaxForRow, bigIndexMinForRow;
304.3220 +
304.3221 +        for (smlIndex = 0; smlIndex <= smlIndexMax; smlIndex++) {
304.3222 +            lastRow = thisRow;
304.3223 +            editDistanceMatrix.push(thisRow = []);
304.3224 +            bigIndexMaxForRow = myMin(bigIndexMax, smlIndex + compareRange);
304.3225 +            bigIndexMinForRow = myMax(0, smlIndex - 1);
304.3226 +            for (bigIndex = bigIndexMinForRow; bigIndex <= bigIndexMaxForRow; bigIndex++) {
304.3227 +                if (!bigIndex)
304.3228 +                    thisRow[bigIndex] = smlIndex + 1;
304.3229 +                else if (!smlIndex)  // Top row - transform empty array into new array via additions
304.3230 +                    thisRow[bigIndex] = bigIndex + 1;
304.3231 +                else if (smlArray[smlIndex - 1] === bigArray[bigIndex - 1])
304.3232 +                    thisRow[bigIndex] = lastRow[bigIndex - 1];                  // copy value (no edit)
304.3233 +                else {
304.3234 +                    var northDistance = lastRow[bigIndex] || maxDistance;       // not in big (deletion)
304.3235 +                    var westDistance = thisRow[bigIndex - 1] || maxDistance;    // not in small (addition)
304.3236 +                    thisRow[bigIndex] = myMin(northDistance, westDistance) + 1;
304.3237 +                }
304.3238 +            }
304.3239 +        }
304.3240 +
304.3241 +        var editScript = [], meMinusOne, notInSml = [], notInBig = [];
304.3242 +        for (smlIndex = smlIndexMax, bigIndex = bigIndexMax; smlIndex || bigIndex;) {
304.3243 +            meMinusOne = editDistanceMatrix[smlIndex][bigIndex] - 1;
304.3244 +            if (bigIndex && meMinusOne === editDistanceMatrix[smlIndex][bigIndex-1]) {
304.3245 +                notInSml.push(editScript[editScript.length] = {     // added
304.3246 +                    'status': statusNotInSml,
304.3247 +                    'value': bigArray[--bigIndex],
304.3248 +                    'index': bigIndex });
304.3249 +            } else if (smlIndex && meMinusOne === editDistanceMatrix[smlIndex - 1][bigIndex]) {
304.3250 +                notInBig.push(editScript[editScript.length] = {     // deleted
304.3251 +                    'status': statusNotInBig,
304.3252 +                    'value': smlArray[--smlIndex],
304.3253 +                    'index': smlIndex });
304.3254 +            } else {
304.3255 +                editScript.push({
304.3256 +                    'status': "retained",
304.3257 +                    'value': bigArray[--bigIndex] });
304.3258 +                --smlIndex;
304.3259 +            }
304.3260 +        }
304.3261 +
304.3262 +        if (notInSml.length && notInBig.length) {
304.3263 +            // Set a limit on the number of consecutive non-matching comparisons; having it a multiple of
304.3264 +            // smlIndexMax keeps the time complexity of this algorithm linear.
304.3265 +            var limitFailedCompares = smlIndexMax * 10, failedCompares,
304.3266 +                a, d, notInSmlItem, notInBigItem;
304.3267 +            // Go through the items that have been added and deleted and try to find matches between them.
304.3268 +            for (failedCompares = a = 0; (dontLimitMoves || failedCompares < limitFailedCompares) && (notInSmlItem = notInSml[a]); a++) {
304.3269 +                for (d = 0; notInBigItem = notInBig[d]; d++) {
304.3270 +                    if (notInSmlItem['value'] === notInBigItem['value']) {
304.3271 +                        notInSmlItem['moved'] = notInBigItem['index'];
304.3272 +                        notInBigItem['moved'] = notInSmlItem['index'];
304.3273 +                        notInBig.splice(d,1);       // This item is marked as moved; so remove it from notInBig list
304.3274 +                        failedCompares = d = 0;     // Reset failed compares count because we're checking for consecutive failures
304.3275 +                        break;
304.3276 +                    }
304.3277 +                }
304.3278 +                failedCompares += d;
304.3279 +            }
304.3280 +        }
304.3281 +        return editScript.reverse();
304.3282 +    }
304.3283 +
304.3284 +    return compareArrays;
304.3285 +})();
304.3286 +
304.3287 +ko.exportSymbol('utils.compareArrays', ko.utils.compareArrays);
304.3288 +
304.3289 +(function () {
304.3290 +    // Objective:
304.3291 +    // * Given an input array, a container DOM node, and a function from array elements to arrays of DOM nodes,
304.3292 +    //   map the array elements to arrays of DOM nodes, concatenate together all these arrays, and use them to populate the container DOM node
304.3293 +    // * Next time we're given the same combination of things (with the array possibly having mutated), update the container DOM node
304.3294 +    //   so that its children is again the concatenation of the mappings of the array elements, but don't re-map any array elements that we
304.3295 +    //   previously mapped - retain those nodes, and just insert/delete other ones
304.3296 +
304.3297 +    // "callbackAfterAddingNodes" will be invoked after any "mapping"-generated nodes are inserted into the container node
304.3298 +    // You can use this, for example, to activate bindings on those nodes.
304.3299 +
304.3300 +    function fixUpNodesToBeMovedOrRemoved(contiguousNodeArray) {
304.3301 +        // Before moving, deleting, or replacing a set of nodes that were previously outputted by the "map" function, we have to reconcile
304.3302 +        // them against what is in the DOM right now. It may be that some of the nodes have already been removed from the document,
304.3303 +        // or that new nodes might have been inserted in the middle, for example by a binding. Also, there may previously have been
304.3304 +        // leading comment nodes (created by rewritten string-based templates) that have since been removed during binding.
304.3305 +        // So, this function translates the old "map" output array into its best guess of what set of current DOM nodes should be removed.
304.3306 +        //
304.3307 +        // Rules:
304.3308 +        //   [A] Any leading nodes that aren't in the document any more should be ignored
304.3309 +        //       These most likely correspond to memoization nodes that were already removed during binding
304.3310 +        //       See https://github.com/SteveSanderson/knockout/pull/440
304.3311 +        //   [B] We want to output a contiguous series of nodes that are still in the document. So, ignore any nodes that
304.3312 +        //       have already been removed, and include any nodes that have been inserted among the previous collection
304.3313 +
304.3314 +        // Rule [A]
304.3315 +        while (contiguousNodeArray.length && !ko.utils.domNodeIsAttachedToDocument(contiguousNodeArray[0]))
304.3316 +            contiguousNodeArray.splice(0, 1);
304.3317 +
304.3318 +        // Rule [B]
304.3319 +        if (contiguousNodeArray.length > 1) {
304.3320 +            // Build up the actual new contiguous node set
304.3321 +            var current = contiguousNodeArray[0], last = contiguousNodeArray[contiguousNodeArray.length - 1], newContiguousSet = [current];
304.3322 +            while (current !== last) {
304.3323 +                current = current.nextSibling;
304.3324 +                if (!current) // Won't happen, except if the developer has manually removed some DOM elements (then we're in an undefined scenario)
304.3325 +                    return;
304.3326 +                newContiguousSet.push(current);
304.3327 +            }
304.3328 +
304.3329 +            // ... then mutate the input array to match this.
304.3330 +            // (The following line replaces the contents of contiguousNodeArray with newContiguousSet)
304.3331 +            Array.prototype.splice.apply(contiguousNodeArray, [0, contiguousNodeArray.length].concat(newContiguousSet));
304.3332 +        }
304.3333 +        return contiguousNodeArray;
304.3334 +    }
304.3335 +
304.3336 +    function mapNodeAndRefreshWhenChanged(containerNode, mapping, valueToMap, callbackAfterAddingNodes, index) {
304.3337 +        // Map this array value inside a dependentObservable so we re-map when any dependency changes
304.3338 +        var mappedNodes = [];
304.3339 +        var dependentObservable = ko.dependentObservable(function() {
304.3340 +            var newMappedNodes = mapping(valueToMap, index) || [];
304.3341 +
304.3342 +            // On subsequent evaluations, just replace the previously-inserted DOM nodes
304.3343 +            if (mappedNodes.length > 0) {
304.3344 +                ko.utils.replaceDomNodes(fixUpNodesToBeMovedOrRemoved(mappedNodes), newMappedNodes);
304.3345 +                if (callbackAfterAddingNodes)
304.3346 +                    ko.dependencyDetection.ignore(callbackAfterAddingNodes, null, [valueToMap, newMappedNodes, index]);
304.3347 +            }
304.3348 +
304.3349 +            // Replace the contents of the mappedNodes array, thereby updating the record
304.3350 +            // of which nodes would be deleted if valueToMap was itself later removed
304.3351 +            mappedNodes.splice(0, mappedNodes.length);
304.3352 +            ko.utils.arrayPushAll(mappedNodes, newMappedNodes);
304.3353 +        }, null, { disposeWhenNodeIsRemoved: containerNode, disposeWhen: function() { return (mappedNodes.length == 0) || !ko.utils.domNodeIsAttachedToDocument(mappedNodes[0]) } });
304.3354 +        return { mappedNodes : mappedNodes, dependentObservable : (dependentObservable.isActive() ? dependentObservable : undefined) };
304.3355 +    }
304.3356 +
304.3357 +    var lastMappingResultDomDataKey = "setDomNodeChildrenFromArrayMapping_lastMappingResult";
304.3358 +
304.3359 +    ko.utils.setDomNodeChildrenFromArrayMapping = function (domNode, array, mapping, options, callbackAfterAddingNodes) {
304.3360 +        // Compare the provided array against the previous one
304.3361 +        array = array || [];
304.3362 +        options = options || {};
304.3363 +        var isFirstExecution = ko.utils.domData.get(domNode, lastMappingResultDomDataKey) === undefined;
304.3364 +        var lastMappingResult = ko.utils.domData.get(domNode, lastMappingResultDomDataKey) || [];
304.3365 +        var lastArray = ko.utils.arrayMap(lastMappingResult, function (x) { return x.arrayEntry; });
304.3366 +        var editScript = ko.utils.compareArrays(lastArray, array);
304.3367 +
304.3368 +        // Build the new mapping result
304.3369 +        var newMappingResult = [];
304.3370 +        var lastMappingResultIndex = 0;
304.3371 +        var newMappingResultIndex = 0;
304.3372 +
304.3373 +        var nodesToDelete = [];
304.3374 +        var itemsToProcess = [];
304.3375 +        var itemsForBeforeRemoveCallbacks = [];
304.3376 +        var itemsForMoveCallbacks = [];
304.3377 +        var itemsForAfterAddCallbacks = [];
304.3378 +        var mapData;
304.3379 +
304.3380 +        function itemMovedOrRetained(editScriptIndex, oldPosition) {
304.3381 +            mapData = lastMappingResult[oldPosition];
304.3382 +            if (newMappingResultIndex !== oldPosition)
304.3383 +                itemsForMoveCallbacks[editScriptIndex] = mapData;
304.3384 +            // Since updating the index might change the nodes, do so before calling fixUpNodesToBeMovedOrRemoved
304.3385 +            mapData.indexObservable(newMappingResultIndex++);
304.3386 +            fixUpNodesToBeMovedOrRemoved(mapData.mappedNodes);
304.3387 +            newMappingResult.push(mapData);
304.3388 +            itemsToProcess.push(mapData);
304.3389 +        }
304.3390 +
304.3391 +        function callCallback(callback, items) {
304.3392 +            if (callback) {
304.3393 +                for (var i = 0, n = items.length; i < n; i++) {
304.3394 +                    if (items[i]) {
304.3395 +                        ko.utils.arrayForEach(items[i].mappedNodes, function(node) {
304.3396 +                            callback(node, i, items[i].arrayEntry);
304.3397 +                        });
304.3398 +                    }
304.3399 +                }
304.3400 +            }
304.3401 +        }
304.3402 +
304.3403 +        for (var i = 0, editScriptItem, movedIndex; editScriptItem = editScript[i]; i++) {
304.3404 +            movedIndex = editScriptItem['moved'];
304.3405 +            switch (editScriptItem['status']) {
304.3406 +                case "deleted":
304.3407 +                    if (movedIndex === undefined) {
304.3408 +                        mapData = lastMappingResult[lastMappingResultIndex];
304.3409 +
304.3410 +                        // Stop tracking changes to the mapping for these nodes
304.3411 +                        if (mapData.dependentObservable)
304.3412 +                            mapData.dependentObservable.dispose();
304.3413 +
304.3414 +                        // Queue these nodes for later removal
304.3415 +                        nodesToDelete.push.apply(nodesToDelete, fixUpNodesToBeMovedOrRemoved(mapData.mappedNodes));
304.3416 +                        if (options['beforeRemove']) {
304.3417 +                            itemsForBeforeRemoveCallbacks[i] = mapData;
304.3418 +                            itemsToProcess.push(mapData);
304.3419 +                        }
304.3420 +                    }
304.3421 +                    lastMappingResultIndex++;
304.3422 +                    break;
304.3423 +
304.3424 +                case "retained":
304.3425 +                    itemMovedOrRetained(i, lastMappingResultIndex++);
304.3426 +                    break;
304.3427 +
304.3428 +                case "added":
304.3429 +                    if (movedIndex !== undefined) {
304.3430 +                        itemMovedOrRetained(i, movedIndex);
304.3431 +                    } else {
304.3432 +                        mapData = { arrayEntry: editScriptItem['value'], indexObservable: ko.observable(newMappingResultIndex++) };
304.3433 +                        newMappingResult.push(mapData);
304.3434 +                        itemsToProcess.push(mapData);
304.3435 +                        if (!isFirstExecution)
304.3436 +                            itemsForAfterAddCallbacks[i] = mapData;
304.3437 +                    }
304.3438 +                    break;
304.3439 +            }
304.3440 +        }
304.3441 +
304.3442 +        // Call beforeMove first before any changes have been made to the DOM
304.3443 +        callCallback(options['beforeMove'], itemsForMoveCallbacks);
304.3444 +
304.3445 +        // Next remove nodes for deleted items (or just clean if there's a beforeRemove callback)
304.3446 +        ko.utils.arrayForEach(nodesToDelete, options['beforeRemove'] ? ko.cleanNode : ko.removeNode);
304.3447 +
304.3448 +        // Next add/reorder the remaining items (will include deleted items if there's a beforeRemove callback)
304.3449 +        for (var i = 0, nextNode = ko.virtualElements.firstChild(domNode), lastNode, node; mapData = itemsToProcess[i]; i++) {
304.3450 +            // Get nodes for newly added items
304.3451 +            if (!mapData.mappedNodes)
304.3452 +                ko.utils.extend(mapData, mapNodeAndRefreshWhenChanged(domNode, mapping, mapData.arrayEntry, callbackAfterAddingNodes, mapData.indexObservable));
304.3453 +
304.3454 +            // Put nodes in the right place if they aren't there already
304.3455 +            for (var j = 0; node = mapData.mappedNodes[j]; nextNode = node.nextSibling, lastNode = node, j++) {
304.3456 +                if (node !== nextNode)
304.3457 +                    ko.virtualElements.insertAfter(domNode, node, lastNode);
304.3458 +            }
304.3459 +
304.3460 +            // Run the callbacks for newly added nodes (for example, to apply bindings, etc.)
304.3461 +            if (!mapData.initialized && callbackAfterAddingNodes) {
304.3462 +                callbackAfterAddingNodes(mapData.arrayEntry, mapData.mappedNodes, mapData.indexObservable);
304.3463 +                mapData.initialized = true;
304.3464 +            }
304.3465 +        }
304.3466 +
304.3467 +        // If there's a beforeRemove callback, call it after reordering.
304.3468 +        // Note that we assume that the beforeRemove callback will usually be used to remove the nodes using
304.3469 +        // some sort of animation, which is why we first reorder the nodes that will be removed. If the
304.3470 +        // callback instead removes the nodes right away, it would be more efficient to skip reordering them.
304.3471 +        // Perhaps we'll make that change in the future if this scenario becomes more common.
304.3472 +        callCallback(options['beforeRemove'], itemsForBeforeRemoveCallbacks);
304.3473 +
304.3474 +        // Finally call afterMove and afterAdd callbacks
304.3475 +        callCallback(options['afterMove'], itemsForMoveCallbacks);
304.3476 +        callCallback(options['afterAdd'], itemsForAfterAddCallbacks);
304.3477 +
304.3478 +        // Store a copy of the array items we just considered so we can difference it next time
304.3479 +        ko.utils.domData.set(domNode, lastMappingResultDomDataKey, newMappingResult);
304.3480 +    }
304.3481 +})();
304.3482 +
304.3483 +ko.exportSymbol('utils.setDomNodeChildrenFromArrayMapping', ko.utils.setDomNodeChildrenFromArrayMapping);
304.3484 +ko.nativeTemplateEngine = function () {
304.3485 +    this['allowTemplateRewriting'] = false;
304.3486 +}
304.3487 +
304.3488 +ko.nativeTemplateEngine.prototype = new ko.templateEngine();
304.3489 +ko.nativeTemplateEngine.prototype['renderTemplateSource'] = function (templateSource, bindingContext, options) {
304.3490 +    var useNodesIfAvailable = !(ko.utils.ieVersion < 9), // IE<9 cloneNode doesn't work properly
304.3491 +        templateNodesFunc = useNodesIfAvailable ? templateSource['nodes'] : null,
304.3492 +        templateNodes = templateNodesFunc ? templateSource['nodes']() : null;
304.3493 +
304.3494 +    if (templateNodes) {
304.3495 +        return ko.utils.makeArray(templateNodes.cloneNode(true).childNodes);
304.3496 +    } else {
304.3497 +        var templateText = templateSource['text']();
304.3498 +        return ko.utils.parseHtmlFragment(templateText);
304.3499 +    }
304.3500 +};
304.3501 +
304.3502 +ko.nativeTemplateEngine.instance = new ko.nativeTemplateEngine();
304.3503 +ko.setTemplateEngine(ko.nativeTemplateEngine.instance);
304.3504 +
304.3505 +ko.exportSymbol('nativeTemplateEngine', ko.nativeTemplateEngine);
304.3506 +(function() {
304.3507 +    ko.jqueryTmplTemplateEngine = function () {
304.3508 +        // Detect which version of jquery-tmpl you're using. Unfortunately jquery-tmpl
304.3509 +        // doesn't expose a version number, so we have to infer it.
304.3510 +        // Note that as of Knockout 1.3, we only support jQuery.tmpl 1.0.0pre and later,
304.3511 +        // which KO internally refers to as version "2", so older versions are no longer detected.
304.3512 +        var jQueryTmplVersion = this.jQueryTmplVersion = (function() {
304.3513 +            if ((typeof(jQuery) == "undefined") || !(jQuery['tmpl']))
304.3514 +                return 0;
304.3515 +            // Since it exposes no official version number, we use our own numbering system. To be updated as jquery-tmpl evolves.
304.3516 +            try {
304.3517 +                if (jQuery['tmpl']['tag']['tmpl']['open'].toString().indexOf('__') >= 0) {
304.3518 +                    // Since 1.0.0pre, custom tags should append markup to an array called "__"
304.3519 +                    return 2; // Final version of jquery.tmpl
304.3520 +                }
304.3521 +            } catch(ex) { /* Apparently not the version we were looking for */ }
304.3522 +
304.3523 +            return 1; // Any older version that we don't support
304.3524 +        })();
304.3525 +
304.3526 +        function ensureHasReferencedJQueryTemplates() {
304.3527 +            if (jQueryTmplVersion < 2)
304.3528 +                throw new Error("Your version of jQuery.tmpl is too old. Please upgrade to jQuery.tmpl 1.0.0pre or later.");
304.3529 +        }
304.3530 +
304.3531 +        function executeTemplate(compiledTemplate, data, jQueryTemplateOptions) {
304.3532 +            return jQuery['tmpl'](compiledTemplate, data, jQueryTemplateOptions);
304.3533 +        }
304.3534 +
304.3535 +        this['renderTemplateSource'] = function(templateSource, bindingContext, options) {
304.3536 +            options = options || {};
304.3537 +            ensureHasReferencedJQueryTemplates();
304.3538 +
304.3539 +            // Ensure we have stored a precompiled version of this template (don't want to reparse on every render)
304.3540 +            var precompiled = templateSource['data']('precompiled');
304.3541 +            if (!precompiled) {
304.3542 +                var templateText = templateSource['text']() || "";
304.3543 +                // Wrap in "with($whatever.koBindingContext) { ... }"
304.3544 +                templateText = "{{ko_with $item.koBindingContext}}" + templateText + "{{/ko_with}}";
304.3545 +
304.3546 +                precompiled = jQuery['template'](null, templateText);
304.3547 +                templateSource['data']('precompiled', precompiled);
304.3548 +            }
304.3549 +
304.3550 +            var data = [bindingContext['$data']]; // Prewrap the data in an array to stop jquery.tmpl from trying to unwrap any arrays
304.3551 +            var jQueryTemplateOptions = jQuery['extend']({ 'koBindingContext': bindingContext }, options['templateOptions']);
304.3552 +
304.3553 +            var resultNodes = executeTemplate(precompiled, data, jQueryTemplateOptions);
304.3554 +            resultNodes['appendTo'](document.createElement("div")); // Using "appendTo" forces jQuery/jQuery.tmpl to perform necessary cleanup work
304.3555 +
304.3556 +            jQuery['fragments'] = {}; // Clear jQuery's fragment cache to avoid a memory leak after a large number of template renders
304.3557 +            return resultNodes;
304.3558 +        };
304.3559 +
304.3560 +        this['createJavaScriptEvaluatorBlock'] = function(script) {
304.3561 +            return "{{ko_code ((function() { return " + script + " })()) }}";
304.3562 +        };
304.3563 +
304.3564 +        this['addTemplate'] = function(templateName, templateMarkup) {
304.3565 +            document.write("<script type='text/html' id='" + templateName + "'>" + templateMarkup + "</script>");
304.3566 +        };
304.3567 +
304.3568 +        if (jQueryTmplVersion > 0) {
304.3569 +            jQuery['tmpl']['tag']['ko_code'] = {
304.3570 +                open: "__.push($1 || '');"
304.3571 +            };
304.3572 +            jQuery['tmpl']['tag']['ko_with'] = {
304.3573 +                open: "with($1) {",
304.3574 +                close: "} "
304.3575 +            };
304.3576 +        }
304.3577 +    };
304.3578 +
304.3579 +    ko.jqueryTmplTemplateEngine.prototype = new ko.templateEngine();
304.3580 +
304.3581 +    // Use this one by default *only if jquery.tmpl is referenced*
304.3582 +    var jqueryTmplTemplateEngineInstance = new ko.jqueryTmplTemplateEngine();
304.3583 +    if (jqueryTmplTemplateEngineInstance.jQueryTmplVersion > 0)
304.3584 +        ko.setTemplateEngine(jqueryTmplTemplateEngineInstance);
304.3585 +
304.3586 +    ko.exportSymbol('jqueryTmplTemplateEngine', ko.jqueryTmplTemplateEngine);
304.3587 +})();
304.3588 +});
304.3589 +})(window,document,navigator,window["jQuery"]);
304.3590 +})();
304.3591 \ No newline at end of file
   305.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   305.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/KnockoutTest.java	Sun Feb 03 07:48:42 2013 +0100
   305.3 @@ -0,0 +1,62 @@
   305.4 +/**
   305.5 + * Back 2 Browser Bytecode Translator
   305.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   305.7 + *
   305.8 + * This program is free software: you can redistribute it and/or modify
   305.9 + * it under the terms of the GNU General Public License as published by
  305.10 + * the Free Software Foundation, version 2 of the License.
  305.11 + *
  305.12 + * This program is distributed in the hope that it will be useful,
  305.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  305.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  305.15 + * GNU General Public License for more details.
  305.16 + *
  305.17 + * You should have received a copy of the GNU General Public License
  305.18 + * along with this program. Look for COPYING file in the top folder.
  305.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  305.20 + */
  305.21 +package org.apidesign.bck2brwsr.htmlpage;
  305.22 +
  305.23 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
  305.24 +import org.apidesign.bck2brwsr.htmlpage.api.OnEvent;
  305.25 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
  305.26 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
  305.27 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
  305.28 +import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
  305.29 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  305.30 +import org.testng.annotations.Factory;
  305.31 +
  305.32 +/**
  305.33 + *
  305.34 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  305.35 + */
  305.36 +@Page(xhtml="Knockout.xhtml", className="KnockoutModel", properties={
  305.37 +    @Property(name="name", type=String.class)
  305.38 +}) 
  305.39 +public class KnockoutTest {
  305.40 +    
  305.41 +    @HtmlFragment(
  305.42 +        "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
  305.43 +        "Your name: <input id='input' data-bind=\"value: name\"></input>\n" +
  305.44 +        "<button id=\"hello\">Say Hello!</button>\n"
  305.45 +    )
  305.46 +    @BrwsrTest public void modifyValueAssertChangeInModel() {
  305.47 +        KnockoutModel m = new KnockoutModel();
  305.48 +        m.setName("Kukuc");
  305.49 +        m.applyBindings();
  305.50 +        assert "Kukuc".equals(m.INPUT.getValue()) : "Value is really kukuc: " + m.INPUT.getValue();
  305.51 +        m.INPUT.setValue("Jardo");
  305.52 +        m.triggerEvent(m.INPUT, OnEvent.CHANGE);
  305.53 +        assert "Jardo".equals(m.getName()) : "Name property updated: " + m.getName();
  305.54 +    }
  305.55 +    
  305.56 +    @ComputedProperty
  305.57 +    static String helloMessage(String name) {
  305.58 +        return "Hello " + name + "!";
  305.59 +    }
  305.60 +    
  305.61 +    @Factory
  305.62 +    public static Object[] create() {
  305.63 +        return VMTest.create(KnockoutTest.class);
  305.64 +    }
  305.65 +}
   306.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   306.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ModelTest.java	Sun Feb 03 07:48:42 2013 +0100
   306.3 @@ -0,0 +1,119 @@
   306.4 +/**
   306.5 + * Back 2 Browser Bytecode Translator
   306.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   306.7 + *
   306.8 + * This program is free software: you can redistribute it and/or modify
   306.9 + * it under the terms of the GNU General Public License as published by
  306.10 + * the Free Software Foundation, version 2 of the License.
  306.11 + *
  306.12 + * This program is distributed in the hope that it will be useful,
  306.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  306.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  306.15 + * GNU General Public License for more details.
  306.16 + *
  306.17 + * You should have received a copy of the GNU General Public License
  306.18 + * along with this program. Look for COPYING file in the top folder.
  306.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  306.20 + */
  306.21 +package org.apidesign.bck2brwsr.htmlpage;
  306.22 +
  306.23 +import java.util.ArrayList;
  306.24 +import java.util.List;
  306.25 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
  306.26 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
  306.27 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
  306.28 +import static org.testng.Assert.*;
  306.29 +import org.testng.annotations.BeforeMethod;
  306.30 +import org.testng.annotations.Test;
  306.31 +
  306.32 +/**
  306.33 + *
  306.34 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  306.35 + */
  306.36 +@Page(xhtml = "Empty.html", className = "Model", properties = {
  306.37 +    @Property(name = "value", type = int.class),
  306.38 +    @Property(name = "unrelated", type = long.class)
  306.39 +})
  306.40 +public class ModelTest {
  306.41 +    private Model model;
  306.42 +    private static Model leakedModel;
  306.43 +    
  306.44 +    @BeforeMethod
  306.45 +    public void createModel() {
  306.46 +        model = new Model();
  306.47 +    }
  306.48 +    
  306.49 +    @Test public void classGeneratedWithSetterGetter() {
  306.50 +        model.setValue(10);
  306.51 +        assertEquals(10, model.getValue(), "Value changed");
  306.52 +    }
  306.53 +    
  306.54 +    @Test public void computedMethod() {
  306.55 +        model.setValue(4);
  306.56 +        assertEquals(16, model.getPowerValue());
  306.57 +    }
  306.58 +    
  306.59 +    @Test public void derivedPropertiesAreNotified() {
  306.60 +        MockKnockout my = new MockKnockout();
  306.61 +        MockKnockout.next = my;
  306.62 +        
  306.63 +        model.applyBindings();
  306.64 +        
  306.65 +        model.setValue(33);
  306.66 +        
  306.67 +        assertEquals(my.mutated.size(), 2, "Two properties changed: " + my.mutated);
  306.68 +        assertTrue(my.mutated.contains("powerValue"), "Power value is in there: " + my.mutated);
  306.69 +        assertTrue(my.mutated.contains("value"), "Simple value is in there: " + my.mutated);
  306.70 +        
  306.71 +        my.mutated.clear();
  306.72 +        
  306.73 +        model.setUnrelated(44);
  306.74 +        assertEquals(my.mutated.size(), 1, "One property changed");
  306.75 +        assertTrue(my.mutated.contains("unrelated"), "Its name is unrelated");
  306.76 +    }
  306.77 +    
  306.78 +    @Test public void computedPropertyCannotWriteToModel() {
  306.79 +        leakedModel = model;
  306.80 +        try {
  306.81 +            String res = model.getNotAllowedWrite();
  306.82 +            fail("We should not be allowed to write to the model: " + res);
  306.83 +        } catch (IllegalStateException ex) {
  306.84 +            // OK, we can't read
  306.85 +        }
  306.86 +    }
  306.87 +
  306.88 +    @Test public void computedPropertyCannotReadToModel() {
  306.89 +        leakedModel = model;
  306.90 +        try {
  306.91 +            String res = model.getNotAllowedRead();
  306.92 +            fail("We should not be allowed to read from the model: " + res);
  306.93 +        } catch (IllegalStateException ex) {
  306.94 +            // OK, we can't read
  306.95 +        }
  306.96 +    }
  306.97 +    
  306.98 +    @ComputedProperty
  306.99 +    static int powerValue(int value) {
 306.100 +        return value * value;
 306.101 +    }
 306.102 +    
 306.103 +    @ComputedProperty
 306.104 +    static String notAllowedRead() {
 306.105 +        return "Not allowed callback: " + leakedModel.getUnrelated();
 306.106 +    }
 306.107 +
 306.108 +    @ComputedProperty
 306.109 +    static String notAllowedWrite() {
 306.110 +        leakedModel.setUnrelated(11);
 306.111 +        return "Not allowed callback!";
 306.112 +    }
 306.113 +    
 306.114 +    static class MockKnockout extends Knockout {
 306.115 +        List<String> mutated = new ArrayList<String>();
 306.116 +        
 306.117 +        @Override
 306.118 +        public void valueHasMutated(String prop) {
 306.119 +            mutated.add(prop);
 306.120 +        }
 306.121 +    }
 306.122 +}
   307.1 --- a/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageController.java	Wed Dec 05 10:03:58 2012 +0100
   307.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageController.java	Sun Feb 03 07:48:42 2013 +0100
   307.3 @@ -17,7 +17,8 @@
   307.4   */
   307.5  package org.apidesign.bck2brwsr.htmlpage;
   307.6  
   307.7 -import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
   307.8 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
   307.9 +import org.apidesign.bck2brwsr.htmlpage.api.On;
  307.10  import org.apidesign.bck2brwsr.htmlpage.api.Page;
  307.11  
  307.12  /** Trivial demo for the bck2brwsr project. First of all start
  307.13 @@ -42,16 +43,21 @@
  307.14   */
  307.15  @Page(xhtml="TestPage.html")
  307.16  public class PageController {
  307.17 -    @OnClick(id="pg.button")
  307.18 -    static void updateTitle() {
  307.19 -        TestPage.PG_TITLE.setText("You want this window to be named " + TestPage.PG_TEXT.getValue());
  307.20 +    private static final TestPage PAGE = new TestPage();
  307.21 +    
  307.22 +    @On(event = CLICK, id="pg.button")
  307.23 +    static void updateTitle(TestPage ref) {
  307.24 +        if (PAGE != ref) {
  307.25 +            throw new IllegalStateException("Both references should be the same. " + ref + " != " + PAGE);
  307.26 +        }
  307.27 +        ref.PG_TITLE.setText("You want this window to be named " + ref.PG_TEXT.getValue());
  307.28      }
  307.29      
  307.30 -    @OnClick(id={ "pg.title", "pg.text" })
  307.31 +    @On(event = CLICK, id={ "pg.title", "pg.text" })
  307.32      static void click(String id) {
  307.33          if (!id.equals("pg.title")) {
  307.34              throw new IllegalStateException();
  307.35          }
  307.36 -        TestPage.PG_TITLE.setText(id);
  307.37 +        PAGE.PG_TITLE.setText(id);
  307.38      }
  307.39  }
   308.1 --- a/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java	Wed Dec 05 10:03:58 2012 +0100
   308.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java	Sun Feb 03 07:48:42 2013 +0100
   308.3 @@ -19,12 +19,12 @@
   308.4  
   308.5  import java.io.IOException;
   308.6  import java.io.InputStream;
   308.7 -import java.lang.reflect.Method;
   308.8  import java.util.Set;
   308.9  import javax.script.Invocable;
  308.10  import javax.script.ScriptEngine;
  308.11  import javax.script.ScriptEngineManager;
  308.12  import javax.script.ScriptException;
  308.13 +import org.apidesign.vm4brwsr.Bck2Brwsr;
  308.14  import org.testng.annotations.Test;
  308.15  import static org.testng.Assert.*;
  308.16  
  308.17 @@ -108,7 +108,9 @@
  308.18              + "\n"
  308.19              + "window.document = doc;\n"
  308.20          );
  308.21 -        Invocable i = compileClass(sb, "org/apidesign/bck2brwsr/htmlpage/PageController");
  308.22 +        Invocable i = compileClass(sb, 
  308.23 +            "org/apidesign/bck2brwsr/htmlpage/PageController"
  308.24 +        );
  308.25  
  308.26          Object ret = null;
  308.27          try {
  308.28 @@ -125,15 +127,7 @@
  308.29          if (sb == null) {
  308.30              sb = new StringBuilder();
  308.31          }
  308.32 -        try {
  308.33 -            Method m;
  308.34 -            Class<?> genJS = Class.forName("org.apidesign.vm4brwsr.GenJS");
  308.35 -            m = genJS.getDeclaredMethod("compile", Appendable.class, String[].class);
  308.36 -            m.setAccessible(true);
  308.37 -            m.invoke(null, sb, names);
  308.38 -        } catch (Exception exception) {
  308.39 -            throw new IOException(exception);
  308.40 -        }
  308.41 +        Bck2Brwsr.generate(sb, ProcessPageTest.class.getClassLoader(), names);
  308.42          ScriptEngineManager sem = new ScriptEngineManager();
  308.43          ScriptEngine js = sem.getEngineByExtension("js");
  308.44          try {
   309.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   309.2 +++ b/javaquery/api/src/test/resources/org/apidesign/bck2brwsr/htmlpage/Empty.html	Sun Feb 03 07:48:42 2013 +0100
   309.3 @@ -0,0 +1,29 @@
   309.4 +<?xml version="1.0" encoding="UTF-8"?>
   309.5 +<!--
   309.6 +
   309.7 +    Back 2 Browser Bytecode Translator
   309.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   309.9 +
  309.10 +    This program is free software: you can redistribute it and/or modify
  309.11 +    it under the terms of the GNU General Public License as published by
  309.12 +    the Free Software Foundation, version 2 of the License.
  309.13 +
  309.14 +    This program is distributed in the hope that it will be useful,
  309.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  309.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  309.17 +    GNU General Public License for more details.
  309.18 +
  309.19 +    You should have received a copy of the GNU General Public License
  309.20 +    along with this program. Look for COPYING file in the top folder.
  309.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
  309.22 +
  309.23 +-->
  309.24 +<!DOCTYPE html>
  309.25 +<html xmlns="http://www.w3.org/1999/xhtml">
  309.26 +    <head>
  309.27 +        <title>Empty</title>
  309.28 +    </head>
  309.29 +    <body>
  309.30 +        Empty page
  309.31 +    </body>
  309.32 +</html>
   310.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   310.2 +++ b/javaquery/api/src/test/resources/org/apidesign/bck2brwsr/htmlpage/Knockout.xhtml	Sun Feb 03 07:48:42 2013 +0100
   310.3 @@ -0,0 +1,25 @@
   310.4 +<?xml version="1.0" encoding="UTF-8"?>
   310.5 +<!--
   310.6 +
   310.7 +    Back 2 Browser Bytecode Translator
   310.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   310.9 +
  310.10 +    This program is free software: you can redistribute it and/or modify
  310.11 +    it under the terms of the GNU General Public License as published by
  310.12 +    the Free Software Foundation, version 2 of the License.
  310.13 +
  310.14 +    This program is distributed in the hope that it will be useful,
  310.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  310.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  310.17 +    GNU General Public License for more details.
  310.18 +
  310.19 +    You should have received a copy of the GNU General Public License
  310.20 +    along with this program. Look for COPYING file in the top folder.
  310.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
  310.22 +
  310.23 +-->
  310.24 +<p>
  310.25 +    <h1 data-bind="text: helloMessage">Loading Bck2Brwsr's Hello World...</h1>
  310.26 +    Your name: <input id="input" data-bind="value: name, valueUpdate: 'afterkeydown'"></input>
  310.27 +    <button id="hello">Say Hello!</button>
  310.28 +</p>
   311.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   311.2 +++ b/javaquery/demo-calculator-dynamic/nbactions.xml	Sun Feb 03 07:48:42 2013 +0100
   311.3 @@ -0,0 +1,29 @@
   311.4 +<?xml version="1.0" encoding="UTF-8"?>
   311.5 +<!--
   311.6 +
   311.7 +    Back 2 Browser Bytecode Translator
   311.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   311.9 +
  311.10 +    This program is free software: you can redistribute it and/or modify
  311.11 +    it under the terms of the GNU General Public License as published by
  311.12 +    the Free Software Foundation, version 2 of the License.
  311.13 +
  311.14 +    This program is distributed in the hope that it will be useful,
  311.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  311.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  311.17 +    GNU General Public License for more details.
  311.18 +
  311.19 +    You should have received a copy of the GNU General Public License
  311.20 +    along with this program. Look for COPYING file in the top folder.
  311.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
  311.22 +
  311.23 +-->
  311.24 +<actions>
  311.25 +        <action>
  311.26 +            <actionName>run</actionName>
  311.27 +            <goals>
  311.28 +                <goal>process-classes</goal>
  311.29 +                <goal>org.apidesign.bck2brwsr:mojo:0.3-SNAPSHOT:brwsr</goal>
  311.30 +            </goals>
  311.31 +        </action>
  311.32 +    </actions>
   312.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   312.2 +++ b/javaquery/demo-calculator-dynamic/pom.xml	Sun Feb 03 07:48:42 2013 +0100
   312.3 @@ -0,0 +1,64 @@
   312.4 +<?xml version="1.0"?>
   312.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   312.6 +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   312.7 +  <modelVersion>4.0.0</modelVersion>
   312.8 +
   312.9 +  <groupId>org.apidesign.bck2brwsr</groupId>
  312.10 +  <artifactId>demo.calculator</artifactId>
  312.11 +  <version>0.3-SNAPSHOT</version>
  312.12 +  <packaging>jar</packaging>
  312.13 +
  312.14 +  <name>JavaQuery Demo - Calculator</name>
  312.15 +  <url>http://maven.apache.org</url>
  312.16 +
  312.17 +  <properties>
  312.18 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  312.19 +  </properties>
  312.20 +  <build>
  312.21 +      <plugins>
  312.22 +            <plugin>
  312.23 +                <groupId>org.apidesign.bck2brwsr</groupId>
  312.24 +                <artifactId>mojo</artifactId>
  312.25 +                <version>0.3-SNAPSHOT</version>
  312.26 +                <executions>
  312.27 +                    <execution>
  312.28 +                        <goals>
  312.29 +                            <goal>brwsr</goal>
  312.30 +                        </goals>
  312.31 +                    </execution>
  312.32 +                </executions>
  312.33 +                <configuration>
  312.34 +                    <startpage>org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml</startpage>
  312.35 +                </configuration>
  312.36 +            </plugin>
  312.37 +         <plugin>
  312.38 +            <groupId>org.apache.maven.plugins</groupId>
  312.39 +            <artifactId>maven-compiler-plugin</artifactId>
  312.40 +            <version>2.3.2</version>
  312.41 +            <configuration>
  312.42 +               <source>1.7</source>
  312.43 +               <target>1.7</target>
  312.44 +            </configuration>
  312.45 +         </plugin>
  312.46 +      </plugins>
  312.47 +  </build>
  312.48 +
  312.49 +  <dependencies>
  312.50 +    <dependency>
  312.51 +      <groupId>org.apidesign.bck2brwsr</groupId>
  312.52 +      <artifactId>emul.mini</artifactId>
  312.53 +      <version>0.3-SNAPSHOT</version>
  312.54 +    </dependency>
  312.55 +    <dependency>
  312.56 +      <groupId>org.apidesign.bck2brwsr</groupId>
  312.57 +      <artifactId>javaquery.api</artifactId>
  312.58 +      <version>0.3-SNAPSHOT</version>
  312.59 +    </dependency>
  312.60 +    <dependency>
  312.61 +      <groupId>org.testng</groupId>
  312.62 +      <artifactId>testng</artifactId>
  312.63 +      <version>6.5.2</version>
  312.64 +      <scope>test</scope>
  312.65 +    </dependency>
  312.66 +  </dependencies>
  312.67 +</project>
   313.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   313.2 +++ b/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java	Sun Feb 03 07:48:42 2013 +0100
   313.3 @@ -0,0 +1,112 @@
   313.4 +/**
   313.5 + * Back 2 Browser Bytecode Translator
   313.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   313.7 + *
   313.8 + * This program is free software: you can redistribute it and/or modify
   313.9 + * it under the terms of the GNU General Public License as published by
  313.10 + * the Free Software Foundation, version 2 of the License.
  313.11 + *
  313.12 + * This program is distributed in the hope that it will be useful,
  313.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  313.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  313.15 + * GNU General Public License for more details.
  313.16 + *
  313.17 + * You should have received a copy of the GNU General Public License
  313.18 + * along with this program. Look for COPYING file in the top folder.
  313.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  313.20 + */
  313.21 +package org.apidesign.bck2brwsr.demo.calc;
  313.22 +
  313.23 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
  313.24 +import org.apidesign.bck2brwsr.htmlpage.api.On;
  313.25 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
  313.26 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
  313.27 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
  313.28 +
  313.29 +/** HTML5 & Java demo showing the power of 
  313.30 + * <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
  313.31 + * as well as other goodies.
  313.32 + * 
  313.33 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
  313.34 + */
  313.35 +@Page(xhtml="Calculator.xhtml", properties = {
  313.36 +    @Property(name = "memory", type = double.class),
  313.37 +    @Property(name = "display", type = double.class),
  313.38 +    @Property(name = "operation", type = String.class),
  313.39 +    @Property(name = "hover", type = boolean.class)
  313.40 +})
  313.41 +public class Calc {
  313.42 +    static {
  313.43 +        new Calculator().applyBindings();
  313.44 +    }
  313.45 +    
  313.46 +    @On(event = CLICK, id="clear")
  313.47 +    static void clear(Calculator c) {
  313.48 +        c.setMemory(0);
  313.49 +        c.setOperation(null);
  313.50 +        c.setDisplay(0);
  313.51 +    }
  313.52 +    
  313.53 +    @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
  313.54 +    static void applyOp(Calculator c, String op) {
  313.55 +        c.setMemory(c.getDisplay());
  313.56 +        c.setOperation(op);
  313.57 +        c.setDisplay(0);
  313.58 +    }
  313.59 +
  313.60 +    @On(event = MOUSE_OVER, id= { "result" })
  313.61 +    static void attemptingIn(Calculator c, String op) {
  313.62 +        c.setHover(true);
  313.63 +    }
  313.64 +    @On(event = MOUSE_OUT, id= { "result" })
  313.65 +    static void attemptingOut(Calculator c, String op) {
  313.66 +        c.setHover(false);
  313.67 +    }
  313.68 +    
  313.69 +    @On(event = CLICK, id="result")
  313.70 +    static void computeTheValue(Calculator c) {
  313.71 +        c.setDisplay(compute(
  313.72 +            c.getOperation(), 
  313.73 +            c.getMemory(), 
  313.74 +            c.getDisplay()
  313.75 +        ));
  313.76 +        c.setMemory(0);
  313.77 +    }
  313.78 +    
  313.79 +    private static double compute(String op, double memory, double display) {
  313.80 +        switch (op) {
  313.81 +            case "plus": return memory + display;
  313.82 +            case "minus": return memory - display;
  313.83 +            case "mul": return memory * display;
  313.84 +            case "div": return memory / display;
  313.85 +            default: throw new IllegalStateException(op);
  313.86 +        }
  313.87 +    }
  313.88 +    
  313.89 +    @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"}) 
  313.90 +    static void addDigit(String digit, Calculator c) {
  313.91 +        digit = digit.substring(1);
  313.92 +        
  313.93 +        double v = c.getDisplay();
  313.94 +        if (v == 0.0) {
  313.95 +            c.setDisplay(Integer.parseInt(digit));
  313.96 +        } else {
  313.97 +            String txt = Double.toString(v);
  313.98 +            if (txt.endsWith(".0")) {
  313.99 +                txt = txt.substring(0, txt.length() - 2);
 313.100 +            }
 313.101 +            txt = txt + digit;
 313.102 +            c.setDisplay(Double.parseDouble(txt));
 313.103 +        }
 313.104 +    }
 313.105 +
 313.106 +    @ComputedProperty
 313.107 +    public static String displayPreview(
 313.108 +        double display, boolean hover, double memory, String operation
 313.109 +    ) {
 313.110 +        if (!hover) {
 313.111 +            return "Type numbers and perform simple operations! Press '=' to get result.";
 313.112 +        }
 313.113 +        return "Attempt to compute " + memory + " " + operation + " " + display + " = " + compute(operation, memory, display);
 313.114 +    }
 313.115 +}
   314.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   314.2 +++ b/javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml	Sun Feb 03 07:48:42 2013 +0100
   314.3 @@ -0,0 +1,159 @@
   314.4 +<?xml version="1.0" encoding="UTF-8"?>
   314.5 +<!--
   314.6 +
   314.7 +    Back 2 Browser Bytecode Translator
   314.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   314.9 +
  314.10 +    This program is free software: you can redistribute it and/or modify
  314.11 +    it under the terms of the GNU General Public License as published by
  314.12 +    the Free Software Foundation, version 2 of the License.
  314.13 +
  314.14 +    This program is distributed in the hope that it will be useful,
  314.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  314.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  314.17 +    GNU General Public License for more details.
  314.18 +
  314.19 +    You should have received a copy of the GNU General Public License
  314.20 +    along with this program. Look for COPYING file in the top folder.
  314.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
  314.22 +
  314.23 +-->
  314.24 +<!DOCTYPE html>
  314.25 +<html xmlns="http://www.w3.org/1999/xhtml">
  314.26 +    <head>
  314.27 +        <title>Simple Calculator in HTML5 and Java</title>
  314.28 +
  314.29 +        <style type="text/css">
  314.30 +        body {color: #ffffff; background-color: #121e31; font-family: Monospaced}
  314.31 +        pre {color: #ffffff; background-color: #121e31; font-family: Monospaced}
  314.32 +        table {color: #ffffff; background-color: #121e31; font-family: Monospaced}
  314.33 +        .string {color: #e2ce00}
  314.34 +        a {color: #e2ce00}
  314.35 +        .ST1 {color: #0000cc; font-family: Monospaced; font-weight: bold}
  314.36 +        .ST0 {color: #0000ff}
  314.37 +        .comment {color: #428bdd}
  314.38 +        .keyword-directive {color: #f8bb00}
  314.39 +        .tag {color: #f8bb00}
  314.40 +        .ST0 {color: #628fb5; background-color: #1b3450}
  314.41 +        .sgml-comment {color: #808080}
  314.42 +        .value {color: #99006b}
  314.43 +        .argument {color: #007c00}
  314.44 +        .sgml-declaration {color: #bf9221}
  314.45 +        </style>    
  314.46 +        </head>
  314.47 +    <body>
  314.48 +        <h1>Java and HTML5 - Together at Last!</h1>
  314.49 +        <table border="0" cellspacing="2">
  314.50 +            <tbody>
  314.51 +                <tr>
  314.52 +                    <td colspan="4"><input data-bind="value: display" value="0" 
  314.53 +                            style="text-align: right"/>
  314.54 +                </td>
  314.55 +                </tr>
  314.56 +                <tr>
  314.57 +                    <td><button id="n1">1</button></td>
  314.58 +                    <td><button id="n2">2</button></td>
  314.59 +                    <td><button id="n3">3</button></td>
  314.60 +                    <td><button id="plus">+</button></td>
  314.61 +                </tr>
  314.62 +                <tr>
  314.63 +                    <td><button id="n4">4</button></td>
  314.64 +                    <td><button id="n5">5</button></td>
  314.65 +                    <td><button id="n6">6</button></td>
  314.66 +                    <td><button id="minus">-</button></td>
  314.67 +                </tr>
  314.68 +                <tr>
  314.69 +                    <td><button id="n7">7</button></td>
  314.70 +                    <td><button id="n8">8</button></td>
  314.71 +                    <td><button id="n9">9</button></td>
  314.72 +                    <td><button id="mul">*</button></td>
  314.73 +                </tr>
  314.74 +                <tr>
  314.75 +                    <td><button id="clear">C</button></td>
  314.76 +                    <td><button id="n0">0</button></td>
  314.77 +                    <td><button id="result">=</button></td>
  314.78 +                    <td><button id="div">/</button></td>
  314.79 +                </tr>
  314.80 +            </tbody>
  314.81 +        </table>
  314.82 +        <div data-bind="text: displayPreview"></div>
  314.83 +        
  314.84 +        <script src="/bck2brwsr.js"></script>
  314.85 +        <script src="/vm.js"></script>
  314.86 +        <script type="text/javascript">
  314.87 +            vm.loadClass('org.apidesign.bck2brwsr.demo.calc.Calc');
  314.88 +        </script>
  314.89 +        
  314.90 +        <hr/>
  314.91 +    <pre>
  314.92 +    <span class="keyword-directive">package</span> org.apidesign.bck2brwsr.mavenhtml;
  314.93 +
  314.94 +    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.OnClick;
  314.95 +    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.Page;
  314.96 +
  314.97 +    <span class="comment">/**</span> <span class="comment">HTML5</span><span class="comment"> &amp; </span><span class="comment">Java</span> <span class="comment">demo</span> <span class="comment">showing</span> <span class="comment">the</span> <span class="comment">power</span> <span class="comment">of</span> <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
  314.98 +    <span class="comment"> * </span><span class="comment">as</span> <span class="comment">well</span> <span class="comment">as</span> <span class="comment">other</span> <span class="comment">goodies</span><span class="comment">, including type-safe association between</span>
  314.99 +    <span class="comment"> * </span><span class="comment">an XHTML page and Java.</span>
 314.100 +    <span class="comment"> * </span>
 314.101 +    <span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">Jaroslav</span> <span class="comment">Tulach</span> <span class="ST0">&lt;jaroslav.tulach@apidesign.org&gt;</span>
 314.102 +     <span class="comment">*/</span>
 314.103 +    @Page(xhtml=<span class="string">&quot;</span><span class="string">Calculator.xhtml</span><span class="string">&quot;</span>)
 314.104 +    <span class="keyword-directive">public</span> <span class="keyword-directive">class</span> App {
 314.105 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> memory;
 314.106 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> String operation;
 314.107 +
 314.108 +        @OnClick(id=<span class="string">&quot;</span><span class="string">clear</span><span class="string">&quot;</span>)
 314.109 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> clear() {
 314.110 +            memory = <span class="number">0</span>;
 314.111 +            operation = <span class="keyword-directive">null</span>;
 314.112 +            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
 314.113 +        }
 314.114 +
 314.115 +        @OnClick(id= { <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span> })
 314.116 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> applyOp(String op) {
 314.117 +            memory = getValue();
 314.118 +            operation = op;
 314.119 +            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
 314.120 +        }
 314.121 +
 314.122 +        @OnClick(id=<span class="string">&quot;</span><span class="string">result</span><span class="string">&quot;</span>)
 314.123 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> computeTheValue() {
 314.124 +            <span class="keyword-directive">switch</span> (operation) {
 314.125 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>: setValue(memory + getValue()); <span class="keyword-directive">break</span>;
 314.126 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>: setValue(memory - getValue()); <span class="keyword-directive">break</span>;
 314.127 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>: setValue(memory * getValue()); <span class="keyword-directive">break</span>;
 314.128 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span>: setValue(memory / getValue()); <span class="keyword-directive">break</span>;
 314.129 +                <span class="keyword-directive">default</span>: <span class="keyword-directive">throw</span> <span class="keyword-directive">new</span> IllegalStateException(operation);
 314.130 +            }
 314.131 +        }
 314.132 +
 314.133 +        @OnClick(id={<span class="string">&quot;</span><span class="string">n0</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n1</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n2</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n3</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n4</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n5</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n6</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n7</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n8</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n9</span><span class="string">&quot;</span>}) 
 314.134 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> addDigit(String digit) {
 314.135 +            digit = digit.substring(<span class="number">1</span>);
 314.136 +            String v = Calculator.DISPLAY.getValue();
 314.137 +            <span class="keyword-directive">if</span> (getValue() == <span class="number">0.0</span>) {
 314.138 +                Calculator.DISPLAY.setValue(digit);
 314.139 +            } <span class="keyword-directive">else</span> {
 314.140 +                Calculator.DISPLAY.setValue(v + digit);
 314.141 +            }
 314.142 +        }
 314.143 +
 314.144 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> setValue(<span class="keyword-directive">double</span> v) {
 314.145 +            StringBuilder sb = <span class="keyword-directive">new</span> StringBuilder();
 314.146 +            sb.append(v);
 314.147 +            Calculator.DISPLAY.setValue(sb.toString());
 314.148 +        }
 314.149 +
 314.150 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> getValue() {
 314.151 +            <span class="keyword-directive">try</span> {
 314.152 +                <span class="keyword-directive">return</span> Double.parseDouble(Calculator.DISPLAY.getValue());
 314.153 +            } <span class="keyword-directive">catch</span> (NumberFormatException ex) {
 314.154 +                Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">err</span><span class="string">&quot;</span>);
 314.155 +                <span class="keyword-directive">return</span> <span class="number">0.0</span>;
 314.156 +            }
 314.157 +        }
 314.158 +    }
 314.159 +
 314.160 +    </pre>
 314.161 +    </body>
 314.162 +</html>
   315.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   315.2 +++ b/javaquery/demo-calculator-dynamic/src/test/java/org/apidesign/bck2brwsr/demo/calc/CalcTest.java	Sun Feb 03 07:48:42 2013 +0100
   315.3 @@ -0,0 +1,46 @@
   315.4 +/**
   315.5 + * Back 2 Browser Bytecode Translator
   315.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   315.7 + *
   315.8 + * This program is free software: you can redistribute it and/or modify
   315.9 + * it under the terms of the GNU General Public License as published by
  315.10 + * the Free Software Foundation, version 2 of the License.
  315.11 + *
  315.12 + * This program is distributed in the hope that it will be useful,
  315.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  315.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  315.15 + * GNU General Public License for more details.
  315.16 + *
  315.17 + * You should have received a copy of the GNU General Public License
  315.18 + * along with this program. Look for COPYING file in the top folder.
  315.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  315.20 + */
  315.21 +package org.apidesign.bck2brwsr.demo.calc;
  315.22 +
  315.23 +import static org.testng.Assert.*;
  315.24 +import org.testng.annotations.BeforeMethod;
  315.25 +import org.testng.annotations.Test;
  315.26 +
  315.27 +/** Demonstrating POJO testing of HTML page model.
  315.28 + *
  315.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  315.30 + */
  315.31 +public class CalcTest {
  315.32 +    private Calculator model;
  315.33 +    
  315.34 +
  315.35 +    @BeforeMethod
  315.36 +    public void initModel() {
  315.37 +        model = new Calculator().applyBindings();
  315.38 +    }
  315.39 +
  315.40 +    @Test
  315.41 +    public void testSomeMethod() {
  315.42 +        model.setDisplay(10);
  315.43 +        Calc.applyOp(model, "plus");
  315.44 +        assertEquals(0.0, model.getDisplay(), "Cleared after pressing +");
  315.45 +        model.setDisplay(5);
  315.46 +        Calc.computeTheValue(model);
  315.47 +        assertEquals(15.0, model.getDisplay(), "Shows fifteen");
  315.48 +    }
  315.49 +}
   316.1 --- a/javaquery/demo-calculator/pom.xml	Wed Dec 05 10:03:58 2012 +0100
   316.2 +++ b/javaquery/demo-calculator/pom.xml	Sun Feb 03 07:48:42 2013 +0100
   316.3 @@ -4,11 +4,11 @@
   316.4    <modelVersion>4.0.0</modelVersion>
   316.5  
   316.6    <groupId>org.apidesign.bck2brwsr</groupId>
   316.7 -  <artifactId>demo.calculator</artifactId>
   316.8 +  <artifactId>demo.static.calculator</artifactId>
   316.9    <version>0.3-SNAPSHOT</version>
  316.10    <packaging>jar</packaging>
  316.11  
  316.12 -  <name>JavaQuery Demo - Calculator</name>
  316.13 +  <name>JavaQuery Demo - Calculator - Static Compilation</name>
  316.14    <url>http://maven.apache.org</url>
  316.15  
  316.16    <properties>
  316.17 @@ -42,7 +42,7 @@
  316.18                  <configuration>
  316.19                      <executable>xdg-open</executable>
  316.20                      <arguments>
  316.21 -                        <argument>${project.build.directory}/classes/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml</argument>
  316.22 +                        <argument>${project.build.directory}/classes/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calculator.xhtml</argument>
  316.23                      </arguments>
  316.24                  </configuration>
  316.25              </plugin>
  316.26 @@ -61,7 +61,7 @@
  316.27    <dependencies>
  316.28      <dependency>
  316.29        <groupId>org.apidesign.bck2brwsr</groupId>
  316.30 -      <artifactId>emul</artifactId>
  316.31 +      <artifactId>emul.mini</artifactId>
  316.32        <version>0.3-SNAPSHOT</version>
  316.33      </dependency>
  316.34      <dependency>
   317.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   317.2 +++ b/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calc.java	Sun Feb 03 07:48:42 2013 +0100
   317.3 @@ -0,0 +1,112 @@
   317.4 +/**
   317.5 + * Back 2 Browser Bytecode Translator
   317.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   317.7 + *
   317.8 + * This program is free software: you can redistribute it and/or modify
   317.9 + * it under the terms of the GNU General Public License as published by
  317.10 + * the Free Software Foundation, version 2 of the License.
  317.11 + *
  317.12 + * This program is distributed in the hope that it will be useful,
  317.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  317.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  317.15 + * GNU General Public License for more details.
  317.16 + *
  317.17 + * You should have received a copy of the GNU General Public License
  317.18 + * along with this program. Look for COPYING file in the top folder.
  317.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  317.20 + */
  317.21 +package org.apidesign.bck2brwsr.demo.calc.staticcompilation;
  317.22 +
  317.23 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
  317.24 +import org.apidesign.bck2brwsr.htmlpage.api.On;
  317.25 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
  317.26 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
  317.27 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
  317.28 +
  317.29 +/** HTML5 & Java demo showing the power of 
  317.30 + * <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
  317.31 + * as well as other goodies.
  317.32 + * 
  317.33 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
  317.34 + */
  317.35 +@Page(xhtml="Calculator.xhtml", properties = {
  317.36 +    @Property(name = "memory", type = double.class),
  317.37 +    @Property(name = "display", type = double.class),
  317.38 +    @Property(name = "operation", type = String.class),
  317.39 +    @Property(name = "hover", type = boolean.class)
  317.40 +})
  317.41 +public class Calc {
  317.42 +    static {
  317.43 +        new Calculator().applyBindings();
  317.44 +    }
  317.45 +    
  317.46 +    @On(event = CLICK, id="clear")
  317.47 +    static void clear(Calculator c) {
  317.48 +        c.setMemory(0);
  317.49 +        c.setOperation(null);
  317.50 +        c.setDisplay(0);
  317.51 +    }
  317.52 +    
  317.53 +    @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
  317.54 +    static void applyOp(Calculator c, String op) {
  317.55 +        c.setMemory(c.getDisplay());
  317.56 +        c.setOperation(op);
  317.57 +        c.setDisplay(0);
  317.58 +    }
  317.59 +
  317.60 +    @On(event = MOUSE_OVER, id= { "result" })
  317.61 +    static void attemptingIn(Calculator c, String op) {
  317.62 +        c.setHover(true);
  317.63 +    }
  317.64 +    @On(event = MOUSE_OUT, id= { "result" })
  317.65 +    static void attemptingOut(Calculator c, String op) {
  317.66 +        c.setHover(false);
  317.67 +    }
  317.68 +    
  317.69 +    @On(event = CLICK, id="result")
  317.70 +    static void computeTheValue(Calculator c) {
  317.71 +        c.setDisplay(compute(
  317.72 +            c.getOperation(), 
  317.73 +            c.getMemory(), 
  317.74 +            c.getDisplay()
  317.75 +        ));
  317.76 +        c.setMemory(0);
  317.77 +    }
  317.78 +    
  317.79 +    private static double compute(String op, double memory, double display) {
  317.80 +        switch (op) {
  317.81 +            case "plus": return memory + display;
  317.82 +            case "minus": return memory - display;
  317.83 +            case "mul": return memory * display;
  317.84 +            case "div": return memory / display;
  317.85 +            default: throw new IllegalStateException(op);
  317.86 +        }
  317.87 +    }
  317.88 +    
  317.89 +    @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"}) 
  317.90 +    static void addDigit(String digit, Calculator c) {
  317.91 +        digit = digit.substring(1);
  317.92 +        
  317.93 +        double v = c.getDisplay();
  317.94 +        if (v == 0.0) {
  317.95 +            c.setDisplay(Integer.parseInt(digit));
  317.96 +        } else {
  317.97 +            String txt = Double.toString(v);
  317.98 +            if (txt.endsWith(".0")) {
  317.99 +                txt = txt.substring(0, txt.length() - 2);
 317.100 +            }
 317.101 +            txt = txt + digit;
 317.102 +            c.setDisplay(Double.parseDouble(txt));
 317.103 +        }
 317.104 +    }
 317.105 +
 317.106 +    @ComputedProperty
 317.107 +    public static String displayPreview(
 317.108 +        double display, boolean hover, double memory, String operation
 317.109 +    ) {
 317.110 +        if (!hover) {
 317.111 +            return "Type numbers and perform simple operations! Press '=' to get result.";
 317.112 +        }
 317.113 +        return "Attempt to compute " + memory + " " + operation + " " + display + " = " + compute(operation, memory, display);
 317.114 +    }
 317.115 +}
   318.1 --- a/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java	Wed Dec 05 10:03:58 2012 +0100
   318.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   318.3 @@ -1,84 +0,0 @@
   318.4 -/**
   318.5 - * Back 2 Browser Bytecode Translator
   318.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   318.7 - *
   318.8 - * This program is free software: you can redistribute it and/or modify
   318.9 - * it under the terms of the GNU General Public License as published by
  318.10 - * the Free Software Foundation, version 2 of the License.
  318.11 - *
  318.12 - * This program is distributed in the hope that it will be useful,
  318.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  318.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  318.15 - * GNU General Public License for more details.
  318.16 - *
  318.17 - * You should have received a copy of the GNU General Public License
  318.18 - * along with this program. Look for COPYING file in the top folder.
  318.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  318.20 - */
  318.21 -package org.apidesign.bck2brwsr.mavenhtml;
  318.22 -
  318.23 -import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
  318.24 -import org.apidesign.bck2brwsr.htmlpage.api.Page;
  318.25 -
  318.26 -/** HTML5 & Java demo showing the power of 
  318.27 - * <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
  318.28 - * as well as other goodies.
  318.29 - * 
  318.30 - * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
  318.31 - */
  318.32 -@Page(xhtml="Calculator.xhtml")
  318.33 -public class App {
  318.34 -    private static double memory;
  318.35 -    private static String operation;
  318.36 -    
  318.37 -    @OnClick(id="clear")
  318.38 -    static void clear() {
  318.39 -        memory = 0;
  318.40 -        operation = null;
  318.41 -        Calculator.DISPLAY.setValue("0");
  318.42 -    }
  318.43 -    
  318.44 -    @OnClick(id= { "plus", "minus", "mul", "div" })
  318.45 -    static void applyOp(String op) {
  318.46 -        memory = getValue();
  318.47 -        operation = op;
  318.48 -        Calculator.DISPLAY.setValue("0");
  318.49 -    }
  318.50 -    
  318.51 -    @OnClick(id="result")
  318.52 -    static void computeTheValue() {
  318.53 -        switch (operation) {
  318.54 -            case "plus": setValue(memory + getValue()); break;
  318.55 -            case "minus": setValue(memory - getValue()); break;
  318.56 -            case "mul": setValue(memory * getValue()); break;
  318.57 -            case "div": setValue(memory / getValue()); break;
  318.58 -            default: throw new IllegalStateException(operation);
  318.59 -        }
  318.60 -    }
  318.61 -    
  318.62 -    @OnClick(id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"}) 
  318.63 -    static void addDigit(String digit) {
  318.64 -        digit = digit.substring(1);
  318.65 -        String v = Calculator.DISPLAY.getValue();
  318.66 -        if (getValue() == 0.0) {
  318.67 -            Calculator.DISPLAY.setValue(digit);
  318.68 -        } else {
  318.69 -            Calculator.DISPLAY.setValue(v + digit);
  318.70 -        }
  318.71 -    }
  318.72 -    
  318.73 -    private static void setValue(double v) {
  318.74 -        StringBuilder sb = new StringBuilder();
  318.75 -        sb.append(v);
  318.76 -        Calculator.DISPLAY.setValue(sb.toString());
  318.77 -    }
  318.78 -
  318.79 -    private static double getValue() {
  318.80 -        try {
  318.81 -            return Double.parseDouble(Calculator.DISPLAY.getValue());
  318.82 -        } catch (NumberFormatException ex) {
  318.83 -            Calculator.DISPLAY.setValue("err");
  318.84 -            return 0.0;
  318.85 -        }
  318.86 -    }
  318.87 -}
   319.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   319.2 +++ b/javaquery/demo-calculator/src/main/resources/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calculator.xhtml	Sun Feb 03 07:48:42 2013 +0100
   319.3 @@ -0,0 +1,154 @@
   319.4 +<?xml version="1.0" encoding="UTF-8"?>
   319.5 +<!--
   319.6 +
   319.7 +    Back 2 Browser Bytecode Translator
   319.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   319.9 +
  319.10 +    This program is free software: you can redistribute it and/or modify
  319.11 +    it under the terms of the GNU General Public License as published by
  319.12 +    the Free Software Foundation, version 2 of the License.
  319.13 +
  319.14 +    This program is distributed in the hope that it will be useful,
  319.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  319.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  319.17 +    GNU General Public License for more details.
  319.18 +
  319.19 +    You should have received a copy of the GNU General Public License
  319.20 +    along with this program. Look for COPYING file in the top folder.
  319.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
  319.22 +
  319.23 +-->
  319.24 +<!DOCTYPE html>
  319.25 +<html xmlns="http://www.w3.org/1999/xhtml">
  319.26 +    <head>
  319.27 +        <title>Simple Calculator in HTML5 and Java</title>
  319.28 +
  319.29 +        <style type="text/css">
  319.30 +        body {color: #ffffff; background-color: #121e31; font-family: Monospaced}
  319.31 +        pre {color: #ffffff; background-color: #121e31; font-family: Monospaced}
  319.32 +        table {color: #ffffff; background-color: #121e31; font-family: Monospaced}
  319.33 +        .string {color: #e2ce00}
  319.34 +        a {color: #e2ce00}
  319.35 +        .ST1 {color: #0000cc; font-family: Monospaced; font-weight: bold}
  319.36 +        .ST0 {color: #0000ff}
  319.37 +        .comment {color: #428bdd}
  319.38 +        .keyword-directive {color: #f8bb00}
  319.39 +        .tag {color: #f8bb00}
  319.40 +        .ST0 {color: #628fb5; background-color: #1b3450}
  319.41 +        .sgml-comment {color: #808080}
  319.42 +        .value {color: #99006b}
  319.43 +        .argument {color: #007c00}
  319.44 +        .sgml-declaration {color: #bf9221}
  319.45 +        </style>    
  319.46 +        </head>
  319.47 +    <body>
  319.48 +        <h1>Java and HTML5 - Together at Last!</h1>
  319.49 +        <table border="0" cellspacing="2">
  319.50 +            <tbody>
  319.51 +                <tr>
  319.52 +                    <td colspan="4"><input data-bind="value: display" value="0" 
  319.53 +                            style="text-align: right"/>
  319.54 +                </td>
  319.55 +                </tr>
  319.56 +                <tr>
  319.57 +                    <td><button id="n1">1</button></td>
  319.58 +                    <td><button id="n2">2</button></td>
  319.59 +                    <td><button id="n3">3</button></td>
  319.60 +                    <td><button id="plus">+</button></td>
  319.61 +                </tr>
  319.62 +                <tr>
  319.63 +                    <td><button id="n4">4</button></td>
  319.64 +                    <td><button id="n5">5</button></td>
  319.65 +                    <td><button id="n6">6</button></td>
  319.66 +                    <td><button id="minus">-</button></td>
  319.67 +                </tr>
  319.68 +                <tr>
  319.69 +                    <td><button id="n7">7</button></td>
  319.70 +                    <td><button id="n8">8</button></td>
  319.71 +                    <td><button id="n9">9</button></td>
  319.72 +                    <td><button id="mul">*</button></td>
  319.73 +                </tr>
  319.74 +                <tr>
  319.75 +                    <td><button id="clear">C</button></td>
  319.76 +                    <td><button id="n0">0</button></td>
  319.77 +                    <td><button id="result">=</button></td>
  319.78 +                    <td><button id="div">/</button></td>
  319.79 +                </tr>
  319.80 +            </tbody>
  319.81 +        </table>
  319.82 +        <div data-bind="text: displayPreview"></div>
  319.83 +        <script src="bootjava.js"/>
  319.84 +        
  319.85 +        <hr/>
  319.86 +    <pre>
  319.87 +    <span class="keyword-directive">package</span> org.apidesign.bck2brwsr.mavenhtml;
  319.88 +
  319.89 +    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.OnClick;
  319.90 +    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.Page;
  319.91 +
  319.92 +    <span class="comment">/**</span> <span class="comment">HTML5</span><span class="comment"> &amp; </span><span class="comment">Java</span> <span class="comment">demo</span> <span class="comment">showing</span> <span class="comment">the</span> <span class="comment">power</span> <span class="comment">of</span> <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
  319.93 +    <span class="comment"> * </span><span class="comment">as</span> <span class="comment">well</span> <span class="comment">as</span> <span class="comment">other</span> <span class="comment">goodies</span><span class="comment">, including type-safe association between</span>
  319.94 +    <span class="comment"> * </span><span class="comment">an XHTML page and Java.</span>
  319.95 +    <span class="comment"> * </span>
  319.96 +    <span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">Jaroslav</span> <span class="comment">Tulach</span> <span class="ST0">&lt;jaroslav.tulach@apidesign.org&gt;</span>
  319.97 +     <span class="comment">*/</span>
  319.98 +    @Page(xhtml=<span class="string">&quot;</span><span class="string">Calculator.xhtml</span><span class="string">&quot;</span>)
  319.99 +    <span class="keyword-directive">public</span> <span class="keyword-directive">class</span> App {
 319.100 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> memory;
 319.101 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> String operation;
 319.102 +
 319.103 +        @OnClick(id=<span class="string">&quot;</span><span class="string">clear</span><span class="string">&quot;</span>)
 319.104 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> clear() {
 319.105 +            memory = <span class="number">0</span>;
 319.106 +            operation = <span class="keyword-directive">null</span>;
 319.107 +            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
 319.108 +        }
 319.109 +
 319.110 +        @OnClick(id= { <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span> })
 319.111 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> applyOp(String op) {
 319.112 +            memory = getValue();
 319.113 +            operation = op;
 319.114 +            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
 319.115 +        }
 319.116 +
 319.117 +        @OnClick(id=<span class="string">&quot;</span><span class="string">result</span><span class="string">&quot;</span>)
 319.118 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> computeTheValue() {
 319.119 +            <span class="keyword-directive">switch</span> (operation) {
 319.120 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>: setValue(memory + getValue()); <span class="keyword-directive">break</span>;
 319.121 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>: setValue(memory - getValue()); <span class="keyword-directive">break</span>;
 319.122 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>: setValue(memory * getValue()); <span class="keyword-directive">break</span>;
 319.123 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span>: setValue(memory / getValue()); <span class="keyword-directive">break</span>;
 319.124 +                <span class="keyword-directive">default</span>: <span class="keyword-directive">throw</span> <span class="keyword-directive">new</span> IllegalStateException(operation);
 319.125 +            }
 319.126 +        }
 319.127 +
 319.128 +        @OnClick(id={<span class="string">&quot;</span><span class="string">n0</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n1</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n2</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n3</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n4</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n5</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n6</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n7</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n8</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n9</span><span class="string">&quot;</span>}) 
 319.129 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> addDigit(String digit) {
 319.130 +            digit = digit.substring(<span class="number">1</span>);
 319.131 +            String v = Calculator.DISPLAY.getValue();
 319.132 +            <span class="keyword-directive">if</span> (getValue() == <span class="number">0.0</span>) {
 319.133 +                Calculator.DISPLAY.setValue(digit);
 319.134 +            } <span class="keyword-directive">else</span> {
 319.135 +                Calculator.DISPLAY.setValue(v + digit);
 319.136 +            }
 319.137 +        }
 319.138 +
 319.139 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> setValue(<span class="keyword-directive">double</span> v) {
 319.140 +            StringBuilder sb = <span class="keyword-directive">new</span> StringBuilder();
 319.141 +            sb.append(v);
 319.142 +            Calculator.DISPLAY.setValue(sb.toString());
 319.143 +        }
 319.144 +
 319.145 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> getValue() {
 319.146 +            <span class="keyword-directive">try</span> {
 319.147 +                <span class="keyword-directive">return</span> Double.parseDouble(Calculator.DISPLAY.getValue());
 319.148 +            } <span class="keyword-directive">catch</span> (NumberFormatException ex) {
 319.149 +                Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">err</span><span class="string">&quot;</span>);
 319.150 +                <span class="keyword-directive">return</span> <span class="number">0.0</span>;
 319.151 +            }
 319.152 +        }
 319.153 +    }
 319.154 +
 319.155 +    </pre>
 319.156 +    </body>
 319.157 +</html>
   320.1 --- a/javaquery/demo-calculator/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml	Wed Dec 05 10:03:58 2012 +0100
   320.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   320.3 @@ -1,154 +0,0 @@
   320.4 -<?xml version="1.0" encoding="UTF-8"?>
   320.5 -<!--
   320.6 -
   320.7 -    Back 2 Browser Bytecode Translator
   320.8 -    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   320.9 -
  320.10 -    This program is free software: you can redistribute it and/or modify
  320.11 -    it under the terms of the GNU General Public License as published by
  320.12 -    the Free Software Foundation, version 2 of the License.
  320.13 -
  320.14 -    This program is distributed in the hope that it will be useful,
  320.15 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
  320.16 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  320.17 -    GNU General Public License for more details.
  320.18 -
  320.19 -    You should have received a copy of the GNU General Public License
  320.20 -    along with this program. Look for COPYING file in the top folder.
  320.21 -    If not, see http://opensource.org/licenses/GPL-2.0.
  320.22 -
  320.23 --->
  320.24 -<!DOCTYPE html>
  320.25 -<html xmlns="http://www.w3.org/1999/xhtml">
  320.26 -    <head>
  320.27 -        <title>Simple Calculator in HTML5 and Java</title>
  320.28 -
  320.29 -        <style type="text/css">
  320.30 -        body {color: #ffffff; background-color: #121e31; font-family: Monospaced}
  320.31 -        pre {color: #ffffff; background-color: #121e31; font-family: Monospaced}
  320.32 -        table {color: #ffffff; background-color: #121e31; font-family: Monospaced}
  320.33 -        .string {color: #e2ce00}
  320.34 -        a {color: #e2ce00}
  320.35 -        .ST1 {color: #0000cc; font-family: Monospaced; font-weight: bold}
  320.36 -        .ST0 {color: #0000ff}
  320.37 -        .comment {color: #428bdd}
  320.38 -        .keyword-directive {color: #f8bb00}
  320.39 -        .tag {color: #f8bb00}
  320.40 -        .ST0 {color: #628fb5; background-color: #1b3450}
  320.41 -        .sgml-comment {color: #808080}
  320.42 -        .value {color: #99006b}
  320.43 -        .argument {color: #007c00}
  320.44 -        .sgml-declaration {color: #bf9221}
  320.45 -        </style>    
  320.46 -        </head>
  320.47 -    <body>
  320.48 -        <h1>Java and HTML5 - Together at Last!</h1>
  320.49 -        <table border="0" cellspacing="2">
  320.50 -            <tbody>
  320.51 -                <tr>
  320.52 -                    <td colspan="4"><input id="display" value="0" 
  320.53 -                            style="text-align: right"/>
  320.54 -                </td>
  320.55 -                </tr>
  320.56 -                <tr>
  320.57 -                    <td><button id="n1">1</button></td>
  320.58 -                    <td><button id="n2">2</button></td>
  320.59 -                    <td><button id="n3">3</button></td>
  320.60 -                    <td><button id="plus">+</button></td>
  320.61 -                </tr>
  320.62 -                <tr>
  320.63 -                    <td><button id="n4">4</button></td>
  320.64 -                    <td><button id="n5">5</button></td>
  320.65 -                    <td><button id="n6">6</button></td>
  320.66 -                    <td><button id="minus">-</button></td>
  320.67 -                </tr>
  320.68 -                <tr>
  320.69 -                    <td><button id="n7">7</button></td>
  320.70 -                    <td><button id="n8">8</button></td>
  320.71 -                    <td><button id="n9">9</button></td>
  320.72 -                    <td><button id="mul">*</button></td>
  320.73 -                </tr>
  320.74 -                <tr>
  320.75 -                    <td><button id="clear">C</button></td>
  320.76 -                    <td><button id="n0">0</button></td>
  320.77 -                    <td><button id="result">=</button></td>
  320.78 -                    <td><button id="div">/</button></td>
  320.79 -                </tr>
  320.80 -            </tbody>
  320.81 -        </table>
  320.82 -
  320.83 -        <script src="bootjava.js"/>
  320.84 -        
  320.85 -        <hr/>
  320.86 -    <pre>
  320.87 -    <span class="keyword-directive">package</span> org.apidesign.bck2brwsr.mavenhtml;
  320.88 -
  320.89 -    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.OnClick;
  320.90 -    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.Page;
  320.91 -
  320.92 -    <span class="comment">/**</span> <span class="comment">HTML5</span><span class="comment"> &amp; </span><span class="comment">Java</span> <span class="comment">demo</span> <span class="comment">showing</span> <span class="comment">the</span> <span class="comment">power</span> <span class="comment">of</span> <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
  320.93 -    <span class="comment"> * </span><span class="comment">as</span> <span class="comment">well</span> <span class="comment">as</span> <span class="comment">other</span> <span class="comment">goodies</span><span class="comment">, including type-safe association between</span>
  320.94 -    <span class="comment"> * </span><span class="comment">an XHTML page and Java.</span>
  320.95 -    <span class="comment"> * </span>
  320.96 -    <span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">Jaroslav</span> <span class="comment">Tulach</span> <span class="ST0">&lt;jaroslav.tulach@apidesign.org&gt;</span>
  320.97 -     <span class="comment">*/</span>
  320.98 -    @Page(xhtml=<span class="string">&quot;</span><span class="string">Calculator.xhtml</span><span class="string">&quot;</span>)
  320.99 -    <span class="keyword-directive">public</span> <span class="keyword-directive">class</span> App {
 320.100 -        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> memory;
 320.101 -        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> String operation;
 320.102 -
 320.103 -        @OnClick(id=<span class="string">&quot;</span><span class="string">clear</span><span class="string">&quot;</span>)
 320.104 -        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> clear() {
 320.105 -            memory = <span class="number">0</span>;
 320.106 -            operation = <span class="keyword-directive">null</span>;
 320.107 -            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
 320.108 -        }
 320.109 -
 320.110 -        @OnClick(id= { <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span> })
 320.111 -        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> applyOp(String op) {
 320.112 -            memory = getValue();
 320.113 -            operation = op;
 320.114 -            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
 320.115 -        }
 320.116 -
 320.117 -        @OnClick(id=<span class="string">&quot;</span><span class="string">result</span><span class="string">&quot;</span>)
 320.118 -        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> computeTheValue() {
 320.119 -            <span class="keyword-directive">switch</span> (operation) {
 320.120 -                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>: setValue(memory + getValue()); <span class="keyword-directive">break</span>;
 320.121 -                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>: setValue(memory - getValue()); <span class="keyword-directive">break</span>;
 320.122 -                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>: setValue(memory * getValue()); <span class="keyword-directive">break</span>;
 320.123 -                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span>: setValue(memory / getValue()); <span class="keyword-directive">break</span>;
 320.124 -                <span class="keyword-directive">default</span>: <span class="keyword-directive">throw</span> <span class="keyword-directive">new</span> IllegalStateException(operation);
 320.125 -            }
 320.126 -        }
 320.127 -
 320.128 -        @OnClick(id={<span class="string">&quot;</span><span class="string">n0</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n1</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n2</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n3</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n4</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n5</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n6</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n7</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n8</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n9</span><span class="string">&quot;</span>}) 
 320.129 -        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> addDigit(String digit) {
 320.130 -            digit = digit.substring(<span class="number">1</span>);
 320.131 -            String v = Calculator.DISPLAY.getValue();
 320.132 -            <span class="keyword-directive">if</span> (getValue() == <span class="number">0.0</span>) {
 320.133 -                Calculator.DISPLAY.setValue(digit);
 320.134 -            } <span class="keyword-directive">else</span> {
 320.135 -                Calculator.DISPLAY.setValue(v + digit);
 320.136 -            }
 320.137 -        }
 320.138 -
 320.139 -        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> setValue(<span class="keyword-directive">double</span> v) {
 320.140 -            StringBuilder sb = <span class="keyword-directive">new</span> StringBuilder();
 320.141 -            sb.append(v);
 320.142 -            Calculator.DISPLAY.setValue(sb.toString());
 320.143 -        }
 320.144 -
 320.145 -        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> getValue() {
 320.146 -            <span class="keyword-directive">try</span> {
 320.147 -                <span class="keyword-directive">return</span> Double.parseDouble(Calculator.DISPLAY.getValue());
 320.148 -            } <span class="keyword-directive">catch</span> (NumberFormatException ex) {
 320.149 -                Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">err</span><span class="string">&quot;</span>);
 320.150 -                <span class="keyword-directive">return</span> <span class="number">0.0</span>;
 320.151 -            }
 320.152 -        }
 320.153 -    }
 320.154 -
 320.155 -    </pre>
 320.156 -    </body>
 320.157 -</html>
   321.1 --- a/javaquery/pom.xml	Wed Dec 05 10:03:58 2012 +0100
   321.2 +++ b/javaquery/pom.xml	Sun Feb 03 07:48:42 2013 +0100
   321.3 @@ -14,5 +14,6 @@
   321.4      <modules>
   321.5          <module>api</module>
   321.6          <module>demo-calculator</module>
   321.7 +        <module>demo-calculator-dynamic</module>
   321.8      </modules>
   321.9  </project>
   322.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   322.2 +++ b/launcher/pom.xml	Sun Feb 03 07:48:42 2013 +0100
   322.3 @@ -0,0 +1,49 @@
   322.4 +<?xml version="1.0"?>
   322.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"
   322.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   322.7 +  <modelVersion>4.0.0</modelVersion>
   322.8 +  <parent>
   322.9 +    <groupId>org.apidesign</groupId>
  322.10 +    <artifactId>bck2brwsr</artifactId>
  322.11 +    <version>0.3-SNAPSHOT</version>
  322.12 +  </parent>
  322.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
  322.14 +  <artifactId>launcher</artifactId>
  322.15 +  <version>0.3-SNAPSHOT</version>
  322.16 +  <name>Bck2Brwsr Launcher</name>
  322.17 +  <url>http://maven.apache.org</url>
  322.18 +    <build>
  322.19 +        <plugins>
  322.20 +            <plugin>
  322.21 +                <groupId>org.apache.maven.plugins</groupId>
  322.22 +                <artifactId>maven-compiler-plugin</artifactId>
  322.23 +                <version>2.3.2</version>
  322.24 +                <configuration>
  322.25 +                    <source>1.7</source>
  322.26 +                    <target>1.7</target>
  322.27 +                </configuration>
  322.28 +            </plugin>
  322.29 +        </plugins>
  322.30 +    </build>
  322.31 +    <properties>
  322.32 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  322.33 +  </properties>
  322.34 +  <dependencies>
  322.35 +    <dependency>
  322.36 +      <groupId>junit</groupId>
  322.37 +      <artifactId>junit</artifactId>
  322.38 +      <version>3.8.1</version>
  322.39 +      <scope>test</scope>
  322.40 +    </dependency>
  322.41 +    <dependency>
  322.42 +      <groupId>org.glassfish.grizzly</groupId>
  322.43 +      <artifactId>grizzly-http-server</artifactId>
  322.44 +      <version>2.2.19</version>
  322.45 +    </dependency>
  322.46 +    <dependency>
  322.47 +      <groupId>${project.groupId}</groupId>
  322.48 +      <artifactId>vm4brwsr</artifactId>
  322.49 +      <version>${project.version}</version>
  322.50 +    </dependency>
  322.51 +  </dependencies>
  322.52 +</project>
   323.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   323.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Sun Feb 03 07:48:42 2013 +0100
   323.3 @@ -0,0 +1,474 @@
   323.4 +/**
   323.5 + * Back 2 Browser Bytecode Translator
   323.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   323.7 + *
   323.8 + * This program is free software: you can redistribute it and/or modify
   323.9 + * it under the terms of the GNU General Public License as published by
  323.10 + * the Free Software Foundation, version 2 of the License.
  323.11 + *
  323.12 + * This program is distributed in the hope that it will be useful,
  323.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  323.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  323.15 + * GNU General Public License for more details.
  323.16 + *
  323.17 + * You should have received a copy of the GNU General Public License
  323.18 + * along with this program. Look for COPYING file in the top folder.
  323.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  323.20 + */
  323.21 +package org.apidesign.bck2brwsr.launcher;
  323.22 +
  323.23 +import java.io.Closeable;
  323.24 +import java.io.File;
  323.25 +import java.io.IOException;
  323.26 +import java.io.InputStream;
  323.27 +import java.io.InterruptedIOException;
  323.28 +import java.io.OutputStream;
  323.29 +import java.io.Writer;
  323.30 +import java.net.URI;
  323.31 +import java.net.URISyntaxException;
  323.32 +import java.net.URL;
  323.33 +import java.util.ArrayList;
  323.34 +import java.util.Arrays;
  323.35 +import java.util.Enumeration;
  323.36 +import java.util.LinkedHashSet;
  323.37 +import java.util.List;
  323.38 +import java.util.Set;
  323.39 +import java.util.concurrent.BlockingQueue;
  323.40 +import java.util.concurrent.CountDownLatch;
  323.41 +import java.util.concurrent.LinkedBlockingQueue;
  323.42 +import java.util.concurrent.TimeUnit;
  323.43 +import java.util.logging.Level;
  323.44 +import java.util.logging.Logger;
  323.45 +import org.apidesign.vm4brwsr.Bck2Brwsr;
  323.46 +import org.glassfish.grizzly.PortRange;
  323.47 +import org.glassfish.grizzly.http.server.HttpHandler;
  323.48 +import org.glassfish.grizzly.http.server.HttpServer;
  323.49 +import org.glassfish.grizzly.http.server.NetworkListener;
  323.50 +import org.glassfish.grizzly.http.server.Request;
  323.51 +import org.glassfish.grizzly.http.server.Response;
  323.52 +import org.glassfish.grizzly.http.server.ServerConfiguration;
  323.53 +
  323.54 +/**
  323.55 + * Lightweight server to launch Bck2Brwsr applications and tests.
  323.56 + * Supports execution in native browser as well as Java's internal 
  323.57 + * execution engine.
  323.58 + */
  323.59 +final class Bck2BrwsrLauncher extends Launcher implements Closeable {
  323.60 +    private static final Logger LOG = Logger.getLogger(Bck2BrwsrLauncher.class.getName());
  323.61 +    private static final MethodInvocation END = new MethodInvocation(null, null, null);
  323.62 +    private Set<ClassLoader> loaders = new LinkedHashSet<>();
  323.63 +    private BlockingQueue<MethodInvocation> methods = new LinkedBlockingQueue<>();
  323.64 +    private long timeOut;
  323.65 +    private final Res resources = new Res();
  323.66 +    private final String cmd;
  323.67 +    private Object[] brwsr;
  323.68 +    private HttpServer server;
  323.69 +    private CountDownLatch wait;
  323.70 +
  323.71 +    public Bck2BrwsrLauncher(String cmd) {
  323.72 +        this.cmd = cmd;
  323.73 +    }
  323.74 +    
  323.75 +    @Override
  323.76 +     MethodInvocation addMethod(Class<?> clazz, String method, String html) throws IOException {
  323.77 +        loaders.add(clazz.getClassLoader());
  323.78 +        MethodInvocation c = new MethodInvocation(clazz.getName(), method, html);
  323.79 +        methods.add(c);
  323.80 +        try {
  323.81 +            c.await(timeOut);
  323.82 +        } catch (InterruptedException ex) {
  323.83 +            throw new IOException(ex);
  323.84 +        }
  323.85 +        return c;
  323.86 +    }
  323.87 +    
  323.88 +    public void setTimeout(long ms) {
  323.89 +        timeOut = ms;
  323.90 +    }
  323.91 +    
  323.92 +    public void addClassLoader(ClassLoader url) {
  323.93 +        this.loaders.add(url);
  323.94 +    }
  323.95 +
  323.96 +    public void showURL(String startpage) throws IOException {
  323.97 +        if (!startpage.startsWith("/")) {
  323.98 +            startpage = "/" + startpage;
  323.99 +        }
 323.100 +        HttpServer s = initServer();
 323.101 +        s.getServerConfiguration().addHttpHandler(new Page(resources, null), "/");
 323.102 +        try {
 323.103 +            launchServerAndBrwsr(s, startpage);
 323.104 +        } catch (URISyntaxException | InterruptedException ex) {
 323.105 +            throw new IOException(ex);
 323.106 +        }
 323.107 +    }
 323.108 +
 323.109 +    @Override
 323.110 +    public void initialize() throws IOException {
 323.111 +        try {
 323.112 +            executeInBrowser();
 323.113 +        } catch (InterruptedException ex) {
 323.114 +            final InterruptedIOException iio = new InterruptedIOException(ex.getMessage());
 323.115 +            iio.initCause(ex);
 323.116 +            throw iio;
 323.117 +        } catch (Exception ex) {
 323.118 +            if (ex instanceof IOException) {
 323.119 +                throw (IOException)ex;
 323.120 +            }
 323.121 +            if (ex instanceof RuntimeException) {
 323.122 +                throw (RuntimeException)ex;
 323.123 +            }
 323.124 +            throw new IOException(ex);
 323.125 +        }
 323.126 +    }
 323.127 +    
 323.128 +    private HttpServer initServer() throws IOException {
 323.129 +        HttpServer s = HttpServer.createSimpleServer(".", new PortRange(8080, 65535));
 323.130 +
 323.131 +        final ServerConfiguration conf = s.getServerConfiguration();
 323.132 +        conf.addHttpHandler(new VM(resources), "/vm.js");
 323.133 +        conf.addHttpHandler(new Classes(resources), "/classes/");
 323.134 +        return s;
 323.135 +    }
 323.136 +    
 323.137 +    private void executeInBrowser() throws InterruptedException, URISyntaxException, IOException {
 323.138 +        wait = new CountDownLatch(1);
 323.139 +        server = initServer();
 323.140 +        ServerConfiguration conf = server.getServerConfiguration();
 323.141 +        conf.addHttpHandler(new Page(resources, 
 323.142 +            "org/apidesign/bck2brwsr/launcher/harness.xhtml"
 323.143 +        ), "/execute");
 323.144 +        conf.addHttpHandler(new HttpHandler() {
 323.145 +            int cnt;
 323.146 +            List<MethodInvocation> cases = new ArrayList<>();
 323.147 +            @Override
 323.148 +            public void service(Request request, Response response) throws Exception {
 323.149 +                String id = request.getParameter("request");
 323.150 +                String value = request.getParameter("result");
 323.151 +                
 323.152 +                if (id != null && value != null) {
 323.153 +                    LOG.log(Level.INFO, "Received result for case {0} = {1}", new Object[]{id, value});
 323.154 +                    value = decodeURL(value);
 323.155 +                    cases.get(Integer.parseInt(id)).result(value, null);
 323.156 +                }
 323.157 +                
 323.158 +                MethodInvocation mi = methods.take();
 323.159 +                if (mi == END) {
 323.160 +                    response.getWriter().write("");
 323.161 +                    wait.countDown();
 323.162 +                    cnt = 0;
 323.163 +                    LOG.log(Level.INFO, "End of data reached. Exiting.");
 323.164 +                    return;
 323.165 +                }
 323.166 +                
 323.167 +                cases.add(mi);
 323.168 +                final String cn = mi.className;
 323.169 +                final String mn = mi.methodName;
 323.170 +                LOG.log(Level.INFO, "Request for {0} case. Sending {1}.{2}", new Object[]{cnt, cn, mn});
 323.171 +                response.getWriter().write("{"
 323.172 +                    + "className: '" + cn + "', "
 323.173 +                    + "methodName: '" + mn + "', "
 323.174 +                    + "request: " + cnt
 323.175 +                );
 323.176 +                if (mi.html != null) {
 323.177 +                    response.getWriter().write(", html: '");
 323.178 +                    response.getWriter().write(encodeJSON(mi.html));
 323.179 +                    response.getWriter().write("'");
 323.180 +                }
 323.181 +                response.getWriter().write("}");
 323.182 +                cnt++;
 323.183 +            }
 323.184 +        }, "/data");
 323.185 +
 323.186 +        this.brwsr = launchServerAndBrwsr(server, "/execute");
 323.187 +    }
 323.188 +    
 323.189 +    private static String encodeJSON(String in) {
 323.190 +        StringBuilder sb = new StringBuilder();
 323.191 +        for (int i = 0; i < in.length(); i++) {
 323.192 +            char ch = in.charAt(i);
 323.193 +            if (ch < 32 || ch == '\'' || ch == '"') {
 323.194 +                sb.append("\\u");
 323.195 +                String hs = "0000" + Integer.toHexString(ch);
 323.196 +                hs = hs.substring(hs.length() - 4);
 323.197 +                sb.append(hs);
 323.198 +            } else {
 323.199 +                sb.append(ch);
 323.200 +            }
 323.201 +        }
 323.202 +        return sb.toString();
 323.203 +    }
 323.204 +    
 323.205 +    @Override
 323.206 +    public void shutdown() throws IOException {
 323.207 +        methods.offer(END);
 323.208 +        for (;;) {
 323.209 +            int prev = methods.size();
 323.210 +            try {
 323.211 +                if (wait != null && wait.await(timeOut, TimeUnit.MILLISECONDS)) {
 323.212 +                    break;
 323.213 +                }
 323.214 +            } catch (InterruptedException ex) {
 323.215 +                throw new IOException(ex);
 323.216 +            }
 323.217 +            if (prev == methods.size()) {
 323.218 +                LOG.log(
 323.219 +                    Level.WARNING, 
 323.220 +                    "Timeout and no test has been executed meanwhile (at {0}). Giving up.", 
 323.221 +                    methods.size()
 323.222 +                );
 323.223 +                break;
 323.224 +            }
 323.225 +            LOG.log(Level.INFO, 
 323.226 +                "Timeout, but tests got from {0} to {1}. Trying again.", 
 323.227 +                new Object[]{prev, methods.size()}
 323.228 +            );
 323.229 +        }
 323.230 +        stopServerAndBrwsr(server, brwsr);
 323.231 +    }
 323.232 +    
 323.233 +    static void copyStream(InputStream is, OutputStream os, String baseURL, String... params) throws IOException {
 323.234 +        for (;;) {
 323.235 +            int ch = is.read();
 323.236 +            if (ch == -1) {
 323.237 +                break;
 323.238 +            }
 323.239 +            if (ch == '$' && params.length > 0) {
 323.240 +                int cnt = is.read() - '0';
 323.241 +                if (cnt == 'U' - '0') {
 323.242 +                    os.write(baseURL.getBytes());
 323.243 +                }
 323.244 +                if (cnt >= 0 && cnt < params.length) {
 323.245 +                    os.write(params[cnt].getBytes());
 323.246 +                }
 323.247 +            } else {
 323.248 +                os.write(ch);
 323.249 +            }
 323.250 +        }
 323.251 +    }
 323.252 +
 323.253 +    private Object[] launchServerAndBrwsr(HttpServer server, final String page) throws IOException, URISyntaxException, InterruptedException {
 323.254 +        server.start();
 323.255 +        NetworkListener listener = server.getListeners().iterator().next();
 323.256 +        int port = listener.getPort();
 323.257 +        
 323.258 +        URI uri = new URI("http://localhost:" + port + page);
 323.259 +        LOG.log(Level.INFO, "Showing {0}", uri);
 323.260 +        if (cmd == null) {
 323.261 +            try {
 323.262 +                LOG.log(Level.INFO, "Trying Desktop.browse on {0} {2} by {1}", new Object[] {
 323.263 +                    System.getProperty("java.vm.name"),
 323.264 +                    System.getProperty("java.vm.vendor"),
 323.265 +                    System.getProperty("java.vm.version"),
 323.266 +                });
 323.267 +                java.awt.Desktop.getDesktop().browse(uri);
 323.268 +                LOG.log(Level.INFO, "Desktop.browse successfully finished");
 323.269 +                return null;
 323.270 +            } catch (UnsupportedOperationException ex) {
 323.271 +                LOG.log(Level.INFO, "Desktop.browse not supported: {0}", ex.getMessage());
 323.272 +                LOG.log(Level.FINE, null, ex);
 323.273 +            }
 323.274 +        }
 323.275 +        {
 323.276 +            String cmdName = cmd == null ? "xdg-open" : cmd;
 323.277 +            String[] cmdArr = { 
 323.278 +                cmdName, uri.toString()
 323.279 +            };
 323.280 +            LOG.log(Level.INFO, "Launching {0}", Arrays.toString(cmdArr));
 323.281 +            final Process process = Runtime.getRuntime().exec(cmdArr);
 323.282 +            return new Object[] { process, null };
 323.283 +        }
 323.284 +    }
 323.285 +    
 323.286 +    private static String decodeURL(String s) {
 323.287 +        for (;;) {
 323.288 +            int pos = s.indexOf('%');
 323.289 +            if (pos == -1) {
 323.290 +                return s;
 323.291 +            }
 323.292 +            int i = Integer.parseInt(s.substring(pos + 1, pos + 2), 16);
 323.293 +            s = s.substring(0, pos) + (char)i + s.substring(pos + 2);
 323.294 +        }
 323.295 +    }
 323.296 +    
 323.297 +    private void stopServerAndBrwsr(HttpServer server, Object[] brwsr) throws IOException {
 323.298 +        if (brwsr == null) {
 323.299 +            return;
 323.300 +        }
 323.301 +        Process process = (Process)brwsr[0];
 323.302 +        
 323.303 +        server.stop();
 323.304 +        InputStream stdout = process.getInputStream();
 323.305 +        InputStream stderr = process.getErrorStream();
 323.306 +        drain("StdOut", stdout);
 323.307 +        drain("StdErr", stderr);
 323.308 +        process.destroy();
 323.309 +        int res;
 323.310 +        try {
 323.311 +            res = process.waitFor();
 323.312 +        } catch (InterruptedException ex) {
 323.313 +            throw new IOException(ex);
 323.314 +        }
 323.315 +        LOG.log(Level.INFO, "Exit code: {0}", res);
 323.316 +
 323.317 +        deleteTree((File)brwsr[1]);
 323.318 +    }
 323.319 +    
 323.320 +    private static void drain(String name, InputStream is) throws IOException {
 323.321 +        int av = is.available();
 323.322 +        if (av > 0) {
 323.323 +            StringBuilder sb = new StringBuilder();
 323.324 +            sb.append("v== ").append(name).append(" ==v\n");
 323.325 +            while (av-- > 0) {
 323.326 +                sb.append((char)is.read());
 323.327 +            }
 323.328 +            sb.append("\n^== ").append(name).append(" ==^");
 323.329 +            LOG.log(Level.INFO, sb.toString());
 323.330 +        }
 323.331 +    }
 323.332 +
 323.333 +    private void deleteTree(File file) {
 323.334 +        if (file == null) {
 323.335 +            return;
 323.336 +        }
 323.337 +        File[] arr = file.listFiles();
 323.338 +        if (arr != null) {
 323.339 +            for (File s : arr) {
 323.340 +                deleteTree(s);
 323.341 +            }
 323.342 +        }
 323.343 +        file.delete();
 323.344 +    }
 323.345 +
 323.346 +    @Override
 323.347 +    public void close() throws IOException {
 323.348 +        shutdown();
 323.349 +    }
 323.350 +
 323.351 +    private class Res implements Bck2Brwsr.Resources {
 323.352 +        @Override
 323.353 +        public InputStream get(String resource) throws IOException {
 323.354 +            for (ClassLoader l : loaders) {
 323.355 +                URL u = null;
 323.356 +                Enumeration<URL> en = l.getResources(resource);
 323.357 +                while (en.hasMoreElements()) {
 323.358 +                    u = en.nextElement();
 323.359 +                }
 323.360 +                if (u != null) {
 323.361 +                    return u.openStream();
 323.362 +                }
 323.363 +            }
 323.364 +            throw new IOException("Can't find " + resource);
 323.365 +        }
 323.366 +    }
 323.367 +
 323.368 +    private static class Page extends HttpHandler {
 323.369 +        private final String resource;
 323.370 +        private final String[] args;
 323.371 +        private final Res res;
 323.372 +        
 323.373 +        public Page(Res res, String resource, String... args) {
 323.374 +            this.res = res;
 323.375 +            this.resource = resource;
 323.376 +            this.args = args.length == 0 ? new String[] { "$0" } : args;
 323.377 +        }
 323.378 +
 323.379 +        @Override
 323.380 +        public void service(Request request, Response response) throws Exception {
 323.381 +            String r = resource;
 323.382 +            if (r == null) {
 323.383 +                r = request.getHttpHandlerPath();
 323.384 +                if (r.startsWith("/")) {
 323.385 +                    r = r.substring(1);
 323.386 +                }
 323.387 +            }
 323.388 +            String[] replace = {};
 323.389 +            if (r.endsWith(".html")) {
 323.390 +                response.setContentType("text/html");
 323.391 +                LOG.info("Content type text/html");
 323.392 +                replace = args;
 323.393 +            }
 323.394 +            if (r.endsWith(".xhtml")) {
 323.395 +                response.setContentType("application/xhtml+xml");
 323.396 +                LOG.info("Content type application/xhtml+xml");
 323.397 +                replace = args;
 323.398 +            }
 323.399 +            OutputStream os = response.getOutputStream();
 323.400 +            try (InputStream is = res.get(r)) {
 323.401 +                copyStream(is, os, request.getRequestURL().toString(), replace);
 323.402 +            } catch (IOException ex) {
 323.403 +                response.setDetailMessage(ex.getLocalizedMessage());
 323.404 +                response.setError();
 323.405 +                response.setStatus(404);
 323.406 +            }
 323.407 +        }
 323.408 +    }
 323.409 +
 323.410 +    private static class VM extends HttpHandler {
 323.411 +        private final String bck2brwsr;
 323.412 +
 323.413 +        public VM(Res loader) throws IOException {
 323.414 +            StringBuilder sb = new StringBuilder();
 323.415 +            Bck2Brwsr.generate(sb, loader);
 323.416 +            sb.append(
 323.417 +                "function ldCls(res) {\n"
 323.418 +                + "  var request = new XMLHttpRequest();\n"
 323.419 +                + "  request.open('GET', '/classes/' + res, false);\n"
 323.420 +                + "  request.send();\n"
 323.421 +                + "  var arr = eval('(' + request.responseText + ')');\n"
 323.422 +                + "  return arr;\n"
 323.423 +                + "}\n"
 323.424 +                + "var vm = new bck2brwsr(ldCls);\n"
 323.425 +            );
 323.426 +            this.bck2brwsr = sb.toString();
 323.427 +        }
 323.428 +
 323.429 +        @Override
 323.430 +        public void service(Request request, Response response) throws Exception {
 323.431 +            response.setCharacterEncoding("UTF-8");
 323.432 +            response.setContentType("text/javascript");
 323.433 +            response.getWriter().write(bck2brwsr);
 323.434 +        }
 323.435 +    }
 323.436 +
 323.437 +    private static class Classes extends HttpHandler {
 323.438 +        private final Res loader;
 323.439 +
 323.440 +        public Classes(Res loader) {
 323.441 +            this.loader = loader;
 323.442 +        }
 323.443 +
 323.444 +        @Override
 323.445 +        public void service(Request request, Response response) throws Exception {
 323.446 +            String res = request.getHttpHandlerPath();
 323.447 +            if (res.startsWith("/")) {
 323.448 +                res = res.substring(1);
 323.449 +            }
 323.450 +            try (InputStream is = loader.get(res)) {
 323.451 +                response.setContentType("text/javascript");
 323.452 +                Writer w = response.getWriter();
 323.453 +                w.append("[");
 323.454 +                for (int i = 0;; i++) {
 323.455 +                    int b = is.read();
 323.456 +                    if (b == -1) {
 323.457 +                        break;
 323.458 +                    }
 323.459 +                    if (i > 0) {
 323.460 +                        w.append(", ");
 323.461 +                    }
 323.462 +                    if (i % 20 == 0) {
 323.463 +                        w.write("\n");
 323.464 +                    }
 323.465 +                    if (b > 127) {
 323.466 +                        b = b - 256;
 323.467 +                    }
 323.468 +                    w.append(Integer.toString(b));
 323.469 +                }
 323.470 +                w.append("\n]");
 323.471 +            } catch (IOException ex) {
 323.472 +                response.setError();
 323.473 +                response.setDetailMessage(ex.getMessage());
 323.474 +            }
 323.475 +        }
 323.476 +    }
 323.477 +}
   324.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   324.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java	Sun Feb 03 07:48:42 2013 +0100
   324.3 @@ -0,0 +1,253 @@
   324.4 +/**
   324.5 + * Back 2 Browser Bytecode Translator
   324.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   324.7 + *
   324.8 + * This program is free software: you can redistribute it and/or modify
   324.9 + * it under the terms of the GNU General Public License as published by
  324.10 + * the Free Software Foundation, version 2 of the License.
  324.11 + *
  324.12 + * This program is distributed in the hope that it will be useful,
  324.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  324.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  324.15 + * GNU General Public License for more details.
  324.16 + *
  324.17 + * You should have received a copy of the GNU General Public License
  324.18 + * along with this program. Look for COPYING file in the top folder.
  324.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  324.20 + */
  324.21 +package org.apidesign.bck2brwsr.launcher;
  324.22 +
  324.23 +import java.io.IOException;
  324.24 +import java.io.InputStream;
  324.25 +import java.lang.reflect.InvocationTargetException;
  324.26 +import java.lang.reflect.Method;
  324.27 +import java.lang.reflect.Modifier;
  324.28 +import java.net.URL;
  324.29 +import java.util.Enumeration;
  324.30 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  324.31 +
  324.32 +/**
  324.33 + *
  324.34 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  324.35 + */
  324.36 +public class Console {
  324.37 +    static {
  324.38 +        turnAssetionStatusOn();
  324.39 +    }
  324.40 +    
  324.41 +    @JavaScriptBody(args = {"id", "attr"}, body = 
  324.42 +        "return window.document.getElementById(id)[attr].toString();")
  324.43 +    private static native Object getAttr(String id, String attr);
  324.44 +
  324.45 +    @JavaScriptBody(args = {"id", "attr", "value"}, body = 
  324.46 +        "window.document.getElementById(id)[attr] = value;")
  324.47 +    private static native void setAttr(String id, String attr, Object value);
  324.48 +    
  324.49 +    @JavaScriptBody(args = {}, body = "return; window.close();")
  324.50 +    private static native void closeWindow();
  324.51 +
  324.52 +    private static void log(String newText) {
  324.53 +        String id = "bck2brwsr.result";
  324.54 +        String attr = "value";
  324.55 +        setAttr(id, attr, getAttr(id, attr) + "\n" + newText);
  324.56 +        setAttr(id, "scrollTop", getAttr(id, "scrollHeight"));
  324.57 +    }
  324.58 +    
  324.59 +    public static void execute() throws Exception {
  324.60 +        String clazz = (String) getAttr("clazz", "value");
  324.61 +        String method = (String) getAttr("method", "value");
  324.62 +        Object res = invokeMethod(clazz, method);
  324.63 +        setAttr("bck2brwsr.result", "value", res);
  324.64 +    }
  324.65 +
  324.66 +    @JavaScriptBody(args = { "url", "callback", "arr" }, body = ""
  324.67 +        + "var request = new XMLHttpRequest();\n"
  324.68 +        + "request.open('GET', url, true);\n"
  324.69 +        + "request.onreadystatechange = function() {\n"
  324.70 +        + "  if (this.readyState!==4) return;\n"
  324.71 +        + "  arr[0] = this.responseText;\n"
  324.72 +        + "  callback.run__V();\n"
  324.73 +        + "};"
  324.74 +        + "request.send();"
  324.75 +    )
  324.76 +    private static native void loadText(String url, Runnable callback, String[] arr) throws IOException;
  324.77 +    
  324.78 +    public static void harness(String url) throws IOException {
  324.79 +        log("Connecting to " + url);
  324.80 +        Request r = new Request(url);
  324.81 +    }
  324.82 +    
  324.83 +    private static class Request implements Runnable {
  324.84 +        private final String[] arr = { null };
  324.85 +        private final String url;
  324.86 +
  324.87 +        private Request(String url) throws IOException {
  324.88 +            this.url = url;
  324.89 +            loadText(url, this, arr);
  324.90 +        }
  324.91 +        
  324.92 +        @Override
  324.93 +        public void run() {
  324.94 +            try {
  324.95 +                String data = arr[0];
  324.96 +                log("\nGot \"" + data + "\"");
  324.97 +                
  324.98 +                if (data == null) {
  324.99 +                    log("Some error exiting");
 324.100 +                    closeWindow();
 324.101 +                    return;
 324.102 +                }
 324.103 +                
 324.104 +                if (data.isEmpty()) {
 324.105 +                    log("No data, exiting");
 324.106 +                    closeWindow();
 324.107 +                    return;
 324.108 +                }
 324.109 +                
 324.110 +                Case c = Case.parseData(data);
 324.111 +                if (c.getHtmlFragment() != null) {
 324.112 +                    setAttr("bck2brwsr.fragment", "innerHTML", c.getHtmlFragment());
 324.113 +                }
 324.114 +                log("Invoking " + c.getClassName() + '.' + c.getMethodName() + " as request: " + c.getRequestId());
 324.115 +
 324.116 +                Object result = invokeMethod(c.getClassName(), c.getMethodName());
 324.117 +                
 324.118 +                setAttr("bck2brwsr.fragment", "innerHTML", "");
 324.119 +                log("Result: " + result);
 324.120 +                
 324.121 +                result = encodeURL("" + result);
 324.122 +                
 324.123 +                log("Sending back: " + url + "?request=" + c.getRequestId() + "&result=" + result);
 324.124 +                String u = url + "?request=" + c.getRequestId() + "&result=" + result;
 324.125 +                
 324.126 +                loadText(u, this, arr);
 324.127 +                
 324.128 +            } catch (Exception ex) {
 324.129 +                log(ex.getMessage());
 324.130 +            }
 324.131 +        }
 324.132 +    }
 324.133 +    
 324.134 +    private static String encodeURL(String r) {
 324.135 +        StringBuilder sb = new StringBuilder();
 324.136 +        for (int i = 0; i < r.length(); i++) {
 324.137 +            int ch = r.charAt(i);
 324.138 +            if (ch < 32 || ch == '%' || ch == '+') {
 324.139 +                sb.append("%").append(("0" + Integer.toHexString(ch)).substring(0, 2));
 324.140 +            } else {
 324.141 +                if (ch == 32) {
 324.142 +                    sb.append("+");
 324.143 +                } else {
 324.144 +                    sb.append((char)ch);
 324.145 +                }
 324.146 +            }
 324.147 +        }
 324.148 +        return sb.toString();
 324.149 +    }
 324.150 +    
 324.151 +    static String invoke(String clazz, String method) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, InstantiationException {
 324.152 +        final Object r = invokeMethod(clazz, method);
 324.153 +        return r == null ? "null" : r.toString().toString();
 324.154 +    }
 324.155 +
 324.156 +    /** Helper method that inspects the classpath and loads given resource
 324.157 +     * (usually a class file). Used while running tests in Rhino.
 324.158 +     * 
 324.159 +     * @param name resource name to find
 324.160 +     * @return the array of bytes in the given resource
 324.161 +     * @throws IOException I/O in case something goes wrong
 324.162 +     */
 324.163 +    public static byte[] read(String name) throws IOException {
 324.164 +        URL u = null;
 324.165 +        Enumeration<URL> en = Console.class.getClassLoader().getResources(name);
 324.166 +        while (en.hasMoreElements()) {
 324.167 +            u = en.nextElement();
 324.168 +        }
 324.169 +        if (u == null) {
 324.170 +            throw new IOException("Can't find " + name);
 324.171 +        }
 324.172 +        try (InputStream is = u.openStream()) {
 324.173 +            byte[] arr;
 324.174 +            arr = new byte[is.available()];
 324.175 +            int offset = 0;
 324.176 +            while (offset < arr.length) {
 324.177 +                int len = is.read(arr, offset, arr.length - offset);
 324.178 +                if (len == -1) {
 324.179 +                    throw new IOException("Can't read " + name);
 324.180 +                }
 324.181 +                offset += len;
 324.182 +            }
 324.183 +            return arr;
 324.184 +        }
 324.185 +    }
 324.186 +   
 324.187 +    private static Object invokeMethod(String clazz, String method) 
 324.188 +    throws ClassNotFoundException, InvocationTargetException, 
 324.189 +    SecurityException, IllegalAccessException, IllegalArgumentException,
 324.190 +    InstantiationException {
 324.191 +        Method found = null;
 324.192 +        Class<?> c = Class.forName(clazz);
 324.193 +        for (Method m : c.getMethods()) {
 324.194 +            if (m.getName().equals(method)) {
 324.195 +                found = m;
 324.196 +            }
 324.197 +        }
 324.198 +        Object res;
 324.199 +        if (found != null) {
 324.200 +            try {
 324.201 +                if ((found.getModifiers() & Modifier.STATIC) != 0) {
 324.202 +                    res = found.invoke(null);
 324.203 +                } else {
 324.204 +                    res = found.invoke(c.newInstance());
 324.205 +                }
 324.206 +            } catch (Throwable ex) {
 324.207 +                res = ex.getClass().getName() + ":" + ex.getMessage();
 324.208 +            }
 324.209 +        } else {
 324.210 +            res = "Can't find method " + method + " in " + clazz;
 324.211 +        }
 324.212 +        return res;
 324.213 +    }
 324.214 +
 324.215 +    @JavaScriptBody(args = {}, body = "vm.desiredAssertionStatus = true;")
 324.216 +    private static void turnAssetionStatusOn() {
 324.217 +    }
 324.218 +    
 324.219 +    private static final class Case {
 324.220 +        private final Object data;
 324.221 +
 324.222 +        private Case(Object data) {
 324.223 +            this.data = data;
 324.224 +        }
 324.225 +        
 324.226 +        public static Case parseData(String s) {
 324.227 +            return new Case(toJSON(s));
 324.228 +        }
 324.229 +        
 324.230 +        public String getMethodName() {
 324.231 +            return value("methodName", data);
 324.232 +        }
 324.233 +
 324.234 +        public String getClassName() {
 324.235 +            return value("className", data);
 324.236 +        }
 324.237 +        
 324.238 +        public String getRequestId() {
 324.239 +            return value("request", data);
 324.240 +        }
 324.241 +
 324.242 +        public String getHtmlFragment() {
 324.243 +            return value("html", data);
 324.244 +        }
 324.245 +        
 324.246 +        @JavaScriptBody(args = "s", body = "return eval('(' + s + ')');")
 324.247 +        private static native Object toJSON(String s);
 324.248 +        
 324.249 +        @JavaScriptBody(args = {"p", "d"}, body = 
 324.250 +              "var v = d[p];\n"
 324.251 +            + "if (typeof v === 'undefined') return null;\n"
 324.252 +            + "return v.toString();"
 324.253 +        )
 324.254 +        private static native String value(String p, Object d);
 324.255 +    }
 324.256 +}
   325.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   325.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/JSLauncher.java	Sun Feb 03 07:48:42 2013 +0100
   325.3 @@ -0,0 +1,132 @@
   325.4 +/**
   325.5 + * Back 2 Browser Bytecode Translator
   325.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   325.7 + *
   325.8 + * This program is free software: you can redistribute it and/or modify
   325.9 + * it under the terms of the GNU General Public License as published by
  325.10 + * the Free Software Foundation, version 2 of the License.
  325.11 + *
  325.12 + * This program is distributed in the hope that it will be useful,
  325.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  325.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  325.15 + * GNU General Public License for more details.
  325.16 + *
  325.17 + * You should have received a copy of the GNU General Public License
  325.18 + * along with this program. Look for COPYING file in the top folder.
  325.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  325.20 + */
  325.21 +package org.apidesign.bck2brwsr.launcher;
  325.22 +
  325.23 +import java.io.IOException;
  325.24 +import java.io.InputStream;
  325.25 +import java.net.URL;
  325.26 +import java.util.Enumeration;
  325.27 +import java.util.LinkedHashSet;
  325.28 +import java.util.Set;
  325.29 +import java.util.logging.Level;
  325.30 +import java.util.logging.Logger;
  325.31 +import javax.script.Invocable;
  325.32 +import javax.script.ScriptEngine;
  325.33 +import javax.script.ScriptEngineManager;
  325.34 +import javax.script.ScriptException;
  325.35 +import org.apidesign.vm4brwsr.Bck2Brwsr;
  325.36 +
  325.37 +/**
  325.38 + * Tests execution in Java's internal scripting engine.
  325.39 + */
  325.40 +final class JSLauncher extends Launcher {
  325.41 +    private static final Logger LOG = Logger.getLogger(JSLauncher.class.getName());
  325.42 +    private Set<ClassLoader> loaders = new LinkedHashSet<>();
  325.43 +    private final Res resources = new Res();
  325.44 +    private Invocable code;
  325.45 +    private StringBuilder codeSeq;
  325.46 +    private Object console;
  325.47 +    
  325.48 +    
  325.49 +    @Override MethodInvocation addMethod(Class<?> clazz, String method, String html) {
  325.50 +        loaders.add(clazz.getClassLoader());
  325.51 +        MethodInvocation mi = new MethodInvocation(clazz.getName(), method, html);
  325.52 +        try {
  325.53 +            long time = System.currentTimeMillis();
  325.54 +            LOG.log(Level.FINE, "Invoking {0}.{1}", new Object[]{mi.className, mi.methodName});
  325.55 +            String res = code.invokeMethod(
  325.56 +                console,
  325.57 +                "invoke__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2",
  325.58 +                mi.className, mi.methodName).toString();
  325.59 +            time = System.currentTimeMillis() - time;
  325.60 +            LOG.log(Level.FINE, "Resut of {0}.{1} = {2} in {3} ms", new Object[]{mi.className, mi.methodName, res, time});
  325.61 +            mi.result(res, null);
  325.62 +        } catch (ScriptException | NoSuchMethodException ex) {
  325.63 +            mi.result(null, ex);
  325.64 +        }
  325.65 +        return mi;
  325.66 +    }
  325.67 +    
  325.68 +    public void addClassLoader(ClassLoader url) {
  325.69 +        this.loaders.add(url);
  325.70 +    }
  325.71 +
  325.72 +    @Override
  325.73 +    public void initialize() throws IOException {
  325.74 +        try {
  325.75 +            initRhino();
  325.76 +        } catch (Exception ex) {
  325.77 +            if (ex instanceof IOException) {
  325.78 +                throw (IOException)ex;
  325.79 +            }
  325.80 +            if (ex instanceof RuntimeException) {
  325.81 +                throw (RuntimeException)ex;
  325.82 +            }
  325.83 +            throw new IOException(ex);
  325.84 +        }
  325.85 +    }
  325.86 +    
  325.87 +    private void initRhino() throws IOException, ScriptException, NoSuchMethodException {
  325.88 +        StringBuilder sb = new StringBuilder();
  325.89 +        Bck2Brwsr.generate(sb, new Res());
  325.90 +
  325.91 +        ScriptEngineManager sem = new ScriptEngineManager();
  325.92 +        ScriptEngine mach = sem.getEngineByExtension("js");
  325.93 +
  325.94 +        sb.append(
  325.95 +              "\nvar vm = new bck2brwsr(org.apidesign.bck2brwsr.launcher.Console.read);"
  325.96 +            + "\nfunction initVM() { return vm; };"
  325.97 +            + "\n");
  325.98 +
  325.99 +        Object res = mach.eval(sb.toString());
 325.100 +        if (!(mach instanceof Invocable)) {
 325.101 +            throw new IOException("It is invocable object: " + res);
 325.102 +        }
 325.103 +        code = (Invocable) mach;
 325.104 +        codeSeq = sb;
 325.105 +        
 325.106 +        Object vm = code.invokeFunction("initVM");
 325.107 +        console = code.invokeMethod(vm, "loadClass", Console.class.getName());
 325.108 +    }
 325.109 +
 325.110 +    @Override
 325.111 +    public void shutdown() throws IOException {
 325.112 +    }
 325.113 +
 325.114 +    @Override
 325.115 +    public String toString() {
 325.116 +        return codeSeq.toString();
 325.117 +    }
 325.118 +    
 325.119 +    private class Res implements Bck2Brwsr.Resources {
 325.120 +        @Override
 325.121 +        public InputStream get(String resource) throws IOException {
 325.122 +            for (ClassLoader l : loaders) {
 325.123 +                URL u = null;
 325.124 +                Enumeration<URL> en = l.getResources(resource);
 325.125 +                while (en.hasMoreElements()) {
 325.126 +                    u = en.nextElement();
 325.127 +                }
 325.128 +                if (u != null) {
 325.129 +                    return u.openStream();
 325.130 +                }
 325.131 +            }
 325.132 +            throw new IOException("Can't find " + resource);
 325.133 +        }
 325.134 +    }
 325.135 +}
   326.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   326.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java	Sun Feb 03 07:48:42 2013 +0100
   326.3 @@ -0,0 +1,63 @@
   326.4 +/**
   326.5 + * Back 2 Browser Bytecode Translator
   326.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   326.7 + *
   326.8 + * This program is free software: you can redistribute it and/or modify
   326.9 + * it under the terms of the GNU General Public License as published by
  326.10 + * the Free Software Foundation, version 2 of the License.
  326.11 + *
  326.12 + * This program is distributed in the hope that it will be useful,
  326.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  326.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  326.15 + * GNU General Public License for more details.
  326.16 + *
  326.17 + * You should have received a copy of the GNU General Public License
  326.18 + * along with this program. Look for COPYING file in the top folder.
  326.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  326.20 + */
  326.21 +package org.apidesign.bck2brwsr.launcher;
  326.22 +
  326.23 +import java.io.Closeable;
  326.24 +import java.io.IOException;
  326.25 +import java.net.URLClassLoader;
  326.26 +import org.apidesign.vm4brwsr.Bck2Brwsr;
  326.27 +
  326.28 +/** An abstraction for executing tests in a Bck2Brwsr virtual machine.
  326.29 + * Either in JavaScript engine, or in external browser.
  326.30 + *
  326.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  326.32 + */
  326.33 +public abstract class Launcher {
  326.34 +
  326.35 +    Launcher() {
  326.36 +    }
  326.37 +    
  326.38 +    abstract MethodInvocation addMethod(Class<?> clazz, String method, String html) throws IOException; 
  326.39 +
  326.40 +    public abstract void initialize() throws IOException;
  326.41 +    public abstract void shutdown() throws IOException;
  326.42 +    public MethodInvocation invokeMethod(Class<?> clazz, String method, String html) throws IOException {
  326.43 +        return addMethod(clazz, method, html);
  326.44 +    }
  326.45 +    
  326.46 +    
  326.47 +
  326.48 +    public static Launcher createJavaScript() {
  326.49 +        final JSLauncher l = new JSLauncher();
  326.50 +        l.addClassLoader(Bck2Brwsr.class.getClassLoader());
  326.51 +        return l;
  326.52 +    }
  326.53 +    
  326.54 +    public static Launcher createBrowser(String cmd) {
  326.55 +        final Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(cmd);
  326.56 +        l.addClassLoader(Bck2Brwsr.class.getClassLoader());
  326.57 +        l.setTimeout(180000);
  326.58 +        return l;
  326.59 +    }
  326.60 +    public static Closeable showURL(URLClassLoader classes, String startpage) throws IOException {
  326.61 +        Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null);
  326.62 +        l.addClassLoader(classes);
  326.63 +        l.showURL(startpage);
  326.64 +        return l;
  326.65 +    }
  326.66 +}
   327.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   327.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/MethodInvocation.java	Sun Feb 03 07:48:42 2013 +0100
   327.3 @@ -0,0 +1,59 @@
   327.4 +/**
   327.5 + * Back 2 Browser Bytecode Translator
   327.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   327.7 + *
   327.8 + * This program is free software: you can redistribute it and/or modify
   327.9 + * it under the terms of the GNU General Public License as published by
  327.10 + * the Free Software Foundation, version 2 of the License.
  327.11 + *
  327.12 + * This program is distributed in the hope that it will be useful,
  327.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  327.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  327.15 + * GNU General Public License for more details.
  327.16 + *
  327.17 + * You should have received a copy of the GNU General Public License
  327.18 + * along with this program. Look for COPYING file in the top folder.
  327.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  327.20 + */
  327.21 +package org.apidesign.bck2brwsr.launcher;
  327.22 +
  327.23 +import java.util.concurrent.CountDownLatch;
  327.24 +import java.util.concurrent.TimeUnit;
  327.25 +
  327.26 +/**
  327.27 + *
  327.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  327.29 + */
  327.30 +public final class MethodInvocation {
  327.31 +    final CountDownLatch wait = new CountDownLatch(1);
  327.32 +    final String className;
  327.33 +    final String methodName;
  327.34 +    final String html;
  327.35 +    private String result;
  327.36 +    private Throwable exception;
  327.37 +
  327.38 +    MethodInvocation(String className, String methodName, String html) {
  327.39 +        this.className = className;
  327.40 +        this.methodName = methodName;
  327.41 +        this.html = html;
  327.42 +    }
  327.43 +    
  327.44 +    void await(long timeOut) throws InterruptedException {
  327.45 +        wait.await(timeOut, TimeUnit.MILLISECONDS);
  327.46 +    }
  327.47 +    
  327.48 +    void result(String r, Throwable e) {
  327.49 +        this.result = r;
  327.50 +        this.exception = e;
  327.51 +        wait.countDown();
  327.52 +    }
  327.53 +
  327.54 +    @Override
  327.55 +    public String toString() {
  327.56 +        if (exception != null) {
  327.57 +            return exception.toString();
  327.58 +        }
  327.59 +        return result;
  327.60 +    }
  327.61 +    
  327.62 +}
   328.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   328.2 +++ b/launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/harness.xhtml	Sun Feb 03 07:48:42 2013 +0100
   328.3 @@ -0,0 +1,40 @@
   328.4 +<?xml version="1.0" encoding="UTF-8"?>
   328.5 +<!--
   328.6 +
   328.7 +    Back 2 Browser Bytecode Translator
   328.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   328.9 +
  328.10 +    This program is free software: you can redistribute it and/or modify
  328.11 +    it under the terms of the GNU General Public License as published by
  328.12 +    the Free Software Foundation, version 2 of the License.
  328.13 +
  328.14 +    This program is distributed in the hope that it will be useful,
  328.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  328.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  328.17 +    GNU General Public License for more details.
  328.18 +
  328.19 +    You should have received a copy of the GNU General Public License
  328.20 +    along with this program. Look for COPYING file in the top folder.
  328.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
  328.22 +
  328.23 +-->
  328.24 +<!DOCTYPE html>
  328.25 +<html xmlns="http://www.w3.org/1999/xhtml">
  328.26 +    <head>
  328.27 +        <title>Bck2Brwsr Harness</title>
  328.28 +    </head>
  328.29 +    <body>
  328.30 +        <script src="/vm.js"></script>
  328.31 +        
  328.32 +        <h1>Bck2Brwsr Execution Harness</h1>
  328.33 +        
  328.34 +        <textarea id="bck2brwsr.result" rows="25" style="width: 100%;" disabled="">
  328.35 +        </textarea>
  328.36 +
  328.37 +        <div id="bck2brwsr.fragment"/>
  328.38 +        
  328.39 +        <script type="text/javascript">
  328.40 +            vm.loadClass('org.apidesign.bck2brwsr.launcher.Console').harness__VLjava_lang_String_2('$U/../data');
  328.41 +        </script>
  328.42 +    </body>
  328.43 +</html>
   329.1 --- a/mojo/pom.xml	Wed Dec 05 10:03:58 2012 +0100
   329.2 +++ b/mojo/pom.xml	Sun Feb 03 07:48:42 2013 +0100
   329.3 @@ -11,7 +11,7 @@
   329.4    <artifactId>mojo</artifactId>
   329.5    <version>0.3-SNAPSHOT</version>
   329.6    <packaging>maven-plugin</packaging>
   329.7 -  <name>Maven Mojo to Compile to JavaScript</name>
   329.8 +  <name>Bck2Brwsr Maven Project</name>
   329.9    <url>http://maven.apache.org</url>
  329.10        <build>
  329.11          <plugins>
  329.12 @@ -66,7 +66,7 @@
  329.13        <version>0.3-SNAPSHOT</version>
  329.14        <exclusions>
  329.15          <exclusion>
  329.16 -          <artifactId>emul</artifactId>
  329.17 +          <artifactId>emul.mini</artifactId>
  329.18            <groupId>org.apidesign.bck2brwsr</groupId>
  329.19          </exclusion>
  329.20        </exclusions>
  329.21 @@ -77,5 +77,10 @@
  329.22        <version>3.0.2</version>
  329.23        <type>jar</type>
  329.24      </dependency>
  329.25 +    <dependency>
  329.26 +        <groupId>${project.groupId}</groupId>
  329.27 +        <artifactId>launcher</artifactId>
  329.28 +      <version>${project.version}</version>
  329.29 +    </dependency>
  329.30  </dependencies>
  329.31  </project>
   330.1 --- a/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Bck2BrswrMojo.java	Wed Dec 05 10:03:58 2012 +0100
   330.2 +++ b/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Bck2BrswrMojo.java	Sun Feb 03 07:48:42 2013 +0100
   330.3 @@ -21,7 +21,7 @@
   330.4  
   330.5  import java.io.File;
   330.6  import java.io.FileWriter;
   330.7 -import java.lang.reflect.Method;
   330.8 +import java.io.IOException;
   330.9  import java.net.MalformedURLException;
  330.10  import java.net.URL;
  330.11  import java.net.URLClassLoader;
  330.12 @@ -34,6 +34,7 @@
  330.13  import org.apache.maven.plugins.annotations.Mojo;
  330.14  import org.apache.maven.plugins.annotations.Parameter;
  330.15  import org.apache.maven.project.MavenProject;
  330.16 +import org.apidesign.vm4brwsr.Bck2Brwsr;
  330.17  
  330.18  /** Compiles classes into JavaScript. */
  330.19  @Mojo(name="j2js", defaultPhase=LifecyclePhase.PROCESS_CLASSES)
  330.20 @@ -72,14 +73,10 @@
  330.21  
  330.22          try {
  330.23              URLClassLoader url = buildClassLoader(classes, prj.getDependencyArtifacts());
  330.24 -            
  330.25 -            Class<?> c = Class.forName("org.apidesign.vm4brwsr.GenJS");
  330.26 -            Method m = c.getDeclaredMethod("compile", ClassLoader.class, Appendable.class, String[].class);
  330.27 -            m.setAccessible(true);
  330.28              FileWriter w = new FileWriter(javascript);
  330.29 -            m.invoke(null, url, w, arr.toArray(new String[0]));
  330.30 +            Bck2Brwsr.generate(w, url, arr.toArray(new String[0]));
  330.31              w.close();
  330.32 -        } catch (Exception ex) {
  330.33 +        } catch (IOException ex) {
  330.34              throw new MojoExecutionException("Can't compile", ex);
  330.35          }
  330.36      }
   331.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   331.2 +++ b/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java	Sun Feb 03 07:48:42 2013 +0100
   331.3 @@ -0,0 +1,92 @@
   331.4 +/**
   331.5 + * Back 2 Browser Bytecode Translator
   331.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   331.7 + *
   331.8 + * This program is free software: you can redistribute it and/or modify
   331.9 + * it under the terms of the GNU General Public License as published by
  331.10 + * the Free Software Foundation, version 2 of the License.
  331.11 + *
  331.12 + * This program is distributed in the hope that it will be useful,
  331.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  331.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  331.15 + * GNU General Public License for more details.
  331.16 + *
  331.17 + * You should have received a copy of the GNU General Public License
  331.18 + * along with this program. Look for COPYING file in the top folder.
  331.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  331.20 + */
  331.21 +package org.apidesign.bck2brwsr.mojo;
  331.22 +
  331.23 +import java.io.Closeable;
  331.24 +import org.apache.maven.plugin.AbstractMojo;
  331.25 +
  331.26 +import java.io.File;
  331.27 +import java.io.IOException;
  331.28 +import java.net.MalformedURLException;
  331.29 +import java.net.URL;
  331.30 +import java.net.URLClassLoader;
  331.31 +import java.util.ArrayList;
  331.32 +import java.util.Collection;
  331.33 +import java.util.List;
  331.34 +import org.apache.maven.artifact.Artifact;
  331.35 +import org.apache.maven.plugin.MojoExecutionException;
  331.36 +import org.apache.maven.plugins.annotations.LifecyclePhase;
  331.37 +import org.apache.maven.plugins.annotations.Mojo;
  331.38 +import org.apache.maven.plugins.annotations.Parameter;
  331.39 +import org.apache.maven.project.MavenProject;
  331.40 +import org.apidesign.bck2brwsr.launcher.Launcher;
  331.41 +
  331.42 +/** Executes given HTML page in a browser. */
  331.43 +@Mojo(name="brwsr", defaultPhase=LifecyclePhase.DEPLOY)
  331.44 +public class BrswrMojo extends AbstractMojo {
  331.45 +    public BrswrMojo() {
  331.46 +    }
  331.47 +    /** Resource to show as initial page */
  331.48 +    @Parameter
  331.49 +    private String startpage;
  331.50 +
  331.51 +    @Parameter(defaultValue="${project}")
  331.52 +    private MavenProject prj;
  331.53 +    
  331.54 +    /** Root of the class files */
  331.55 +    @Parameter(defaultValue="${project.build.directory}/classes")
  331.56 +    private File classes;
  331.57 +
  331.58 +    @Override
  331.59 +    public void execute() throws MojoExecutionException {
  331.60 +        if (startpage == null) {
  331.61 +            throw new MojoExecutionException("You have to provide a start page");
  331.62 +        }
  331.63 +
  331.64 +        try {
  331.65 +            URLClassLoader url = buildClassLoader(classes, prj.getDependencyArtifacts());
  331.66 +            
  331.67 +            Closeable httpServer;
  331.68 +            try {
  331.69 +                httpServer = Launcher.showURL(url, startpage());
  331.70 +            } catch (Exception ex) {
  331.71 +                throw new MojoExecutionException("Can't open " + startpage(), ex);
  331.72 +            }
  331.73 +            System.in.read();
  331.74 +            httpServer.close();
  331.75 +        } catch (IOException ex) {
  331.76 +            throw new MojoExecutionException("Can't show the browser", ex);
  331.77 +        }
  331.78 +    }
  331.79 +    
  331.80 +    private String startpage() {
  331.81 +        return startpage;
  331.82 +    }
  331.83 +
  331.84 +    private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
  331.85 +        List<URL> arr = new ArrayList<URL>();
  331.86 +        arr.add(root.toURI().toURL());
  331.87 +        for (Artifact a : deps) {
  331.88 +            final File f = a.getFile();
  331.89 +            if (f != null) {
  331.90 +                arr.add(f.toURI().toURL());
  331.91 +            }
  331.92 +        }
  331.93 +        return new URLClassLoader(arr.toArray(new URL[0]), BrswrMojo.class.getClassLoader());
  331.94 +    }
  331.95 +}
   332.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   332.2 +++ b/mojo/src/main/resources/META-INF/maven/archetype-metadata.xml	Sun Feb 03 07:48:42 2013 +0100
   332.3 @@ -0,0 +1,48 @@
   332.4 +<?xml version="1.0" encoding="UTF-8"?>
   332.5 +<!--
   332.6 +
   332.7 +    Back 2 Browser Bytecode Translator
   332.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   332.9 +
  332.10 +    This program is free software: you can redistribute it and/or modify
  332.11 +    it under the terms of the GNU General Public License as published by
  332.12 +    the Free Software Foundation, version 2 of the License.
  332.13 +
  332.14 +    This program is distributed in the hope that it will be useful,
  332.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  332.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  332.17 +    GNU General Public License for more details.
  332.18 +
  332.19 +    You should have received a copy of the GNU General Public License
  332.20 +    along with this program. Look for COPYING file in the top folder.
  332.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
  332.22 +
  332.23 +-->
  332.24 +<archetype-descriptor name="bck2brwsr">
  332.25 +  <fileSets>
  332.26 +    <fileSet filtered="true" packaged="true">
  332.27 +      <directory>src/main/java</directory>
  332.28 +      <includes>
  332.29 +        <include>**/App.java</include>
  332.30 +      </includes>
  332.31 +    </fileSet>
  332.32 +    <fileSet filtered="true" packaged="true">
  332.33 +      <directory>src/main/resources</directory>
  332.34 +      <includes>
  332.35 +        <include>**/*.xhtml</include>
  332.36 +      </includes>
  332.37 +    </fileSet>
  332.38 +    <fileSet filtered="true" packaged="true">
  332.39 +      <directory>src/test/java</directory>
  332.40 +      <includes>
  332.41 +        <include>**/*Test.java</include>
  332.42 +      </includes>
  332.43 +    </fileSet>
  332.44 +    <fileSet filtered="false" packaged="false">
  332.45 +      <directory></directory>
  332.46 +      <includes>
  332.47 +        <include>nbactions.xml</include>
  332.48 +      </includes>
  332.49 +    </fileSet>
  332.50 +  </fileSets>    
  332.51 +</archetype-descriptor>
  332.52 \ No newline at end of file
   333.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   333.2 +++ b/mojo/src/main/resources/archetype-resources/nbactions.xml	Sun Feb 03 07:48:42 2013 +0100
   333.3 @@ -0,0 +1,10 @@
   333.4 +<?xml version="1.0" encoding="UTF-8"?>
   333.5 +<actions>
   333.6 +    <action>
   333.7 +        <actionName>run</actionName>
   333.8 +        <goals>
   333.9 +            <goal>process-classes</goal>
  333.10 +            <goal>org.apidesign.bck2brwsr:mojo:0.3-SNAPSHOT:brwsr</goal>
  333.11 +        </goals>
  333.12 +    </action>
  333.13 +</actions>
   334.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   334.2 +++ b/mojo/src/main/resources/archetype-resources/pom.xml	Sun Feb 03 07:48:42 2013 +0100
   334.3 @@ -0,0 +1,69 @@
   334.4 +<?xml version="1.0"?>
   334.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   334.6 +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   334.7 +  <modelVersion>4.0.0</modelVersion>
   334.8 +
   334.9 +  <groupId>${groupId}</groupId>
  334.10 +  <artifactId>${artifactId}</artifactId>
  334.11 +  <version>${version}</version>
  334.12 +  <packaging>jar</packaging>
  334.13 +
  334.14 +  <name>${artifactId}</name>
  334.15 +
  334.16 +  <properties>
  334.17 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  334.18 +  </properties>
  334.19 +  <build>
  334.20 +      <plugins>
  334.21 +            <plugin>
  334.22 +                <groupId>org.apidesign.bck2brwsr</groupId>
  334.23 +                <artifactId>mojo</artifactId>
  334.24 +                <version>0.3-SNAPSHOT</version>
  334.25 +                <executions>
  334.26 +                    <execution>
  334.27 +                        <goals>
  334.28 +                            <goal>brwsr</goal>
  334.29 +                        </goals>
  334.30 +                    </execution>
  334.31 +                </executions>
  334.32 +                <configuration>
  334.33 +                    <startpage>${package.replace('.','/')}/index.xhtml</startpage>
  334.34 +                </configuration>
  334.35 +            </plugin>
  334.36 +         <plugin>
  334.37 +            <groupId>org.apache.maven.plugins</groupId>
  334.38 +            <artifactId>maven-compiler-plugin</artifactId>
  334.39 +            <version>2.3.2</version>
  334.40 +            <configuration>
  334.41 +               <source>1.7</source>
  334.42 +               <target>1.7</target>
  334.43 +            </configuration>
  334.44 +         </plugin>
  334.45 +      </plugins>
  334.46 +  </build>
  334.47 +
  334.48 +  <dependencies>
  334.49 +    <dependency>
  334.50 +      <groupId>org.apidesign.bck2brwsr</groupId>
  334.51 +      <artifactId>emul.mini</artifactId>
  334.52 +      <version>0.3-SNAPSHOT</version>
  334.53 +    </dependency>
  334.54 +    <dependency>
  334.55 +      <groupId>org.apidesign.bck2brwsr</groupId>
  334.56 +      <artifactId>javaquery.api</artifactId>
  334.57 +      <version>0.3-SNAPSHOT</version>
  334.58 +    </dependency>
  334.59 +    <dependency>
  334.60 +      <groupId>org.testng</groupId>
  334.61 +      <artifactId>testng</artifactId>
  334.62 +      <version>6.5.2</version>
  334.63 +      <scope>test</scope>
  334.64 +    </dependency>
  334.65 +    <dependency>
  334.66 +      <groupId>org.apidesign.bck2brwsr</groupId>
  334.67 +      <artifactId>vmtest</artifactId>
  334.68 +      <version>0.3-SNAPSHOT</version>
  334.69 +      <scope>test</scope>
  334.70 +    </dependency>
  334.71 +  </dependencies>
  334.72 +</project>
   335.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   335.2 +++ b/mojo/src/main/resources/archetype-resources/src/main/java/App.java	Sun Feb 03 07:48:42 2013 +0100
   335.3 @@ -0,0 +1,34 @@
   335.4 +package ${package};
   335.5 +
   335.6 +import org.apidesign.bck2brwsr.htmlpage.api.*;
   335.7 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
   335.8 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
   335.9 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
  335.10 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
  335.11 +
  335.12 +/** Edit the index.xhtml file. Use 'id' to name certain HTML elements.
  335.13 + * Use this class to define behavior of the elements.
  335.14 + */
  335.15 +@Page(xhtml="index.xhtml", className="Index", properties={
  335.16 +    @Property(name="name", type=String.class)
  335.17 +})
  335.18 +public class App {
  335.19 +    static {
  335.20 +        Index model = new Index();
  335.21 +        model.setName("World");
  335.22 +        model.applyBindings();
  335.23 +    }
  335.24 +    
  335.25 +    @On(event = CLICK, id="hello")
  335.26 +    static void hello(Index m) {
  335.27 +        GraphicsContext g = m.CANVAS.getContext();
  335.28 +        g.clearRect(0, 0, 1000, 1000);
  335.29 +        g.setFont("italic 40px Calibri");
  335.30 +        g.fillText(m.getHelloMessage(), 10, 40);
  335.31 +    }
  335.32 +    
  335.33 +    @ComputedProperty
  335.34 +    static String helloMessage(String name) {
  335.35 +        return "Hello " + name + "!";
  335.36 +    }
  335.37 +}
   336.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   336.2 +++ b/mojo/src/main/resources/archetype-resources/src/main/resources/index.xhtml	Sun Feb 03 07:48:42 2013 +0100
   336.3 @@ -0,0 +1,22 @@
   336.4 +<?xml version="1.0" encoding="UTF-8"?>
   336.5 +<!DOCTYPE html>
   336.6 +<html xmlns="http://www.w3.org/1999/xhtml">
   336.7 +    <head>
   336.8 +        <title>Bck2Brwsr's Hello World</title>
   336.9 +    </head>
  336.10 +    <body>
  336.11 +        <h1 data-bind="text: helloMessage">Loading Bck2Brwsr's Hello World...</h1>
  336.12 +        Your name: <input id='input' data-bind="value: name, valueUpdate: 'afterkeydown'"></input>
  336.13 +        <button id="hello">Say Hello!</button>
  336.14 +        <p>
  336.15 +            <canvas id="canvas" width="300" height="50">
  336.16 +            </canvas>
  336.17 +        </p>
  336.18 +
  336.19 +        <script src="/bck2brwsr.js"></script>
  336.20 +        <script src="/vm.js"></script>
  336.21 +        <script type="text/javascript">
  336.22 +            vm.loadClass('${package}.App');
  336.23 +        </script>
  336.24 +    </body>
  336.25 +</html>
   337.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   337.2 +++ b/mojo/src/main/resources/archetype-resources/src/test/java/AppTest.java	Sun Feb 03 07:48:42 2013 +0100
   337.3 @@ -0,0 +1,26 @@
   337.4 +package ${package};
   337.5 +
   337.6 +import static org.testng.Assert.*;
   337.7 +import org.testng.annotations.BeforeMethod;
   337.8 +import org.testng.annotations.Test;
   337.9 +
  337.10 +/** Demonstrating POJO testing of HTML page model. Runs in good old HotSpot
  337.11 + * as it does not reference any HTML elements or browser functionality. Just
  337.12 + * operates on the page model.
  337.13 + *
  337.14 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  337.15 + */
  337.16 +public class AppTest {
  337.17 +    private Index model;
  337.18 +    
  337.19 +
  337.20 +    @BeforeMethod
  337.21 +    public void initModel() {
  337.22 +        model = new Index().applyBindings();
  337.23 +    }
  337.24 +
  337.25 +    @Test public void testHelloMessage() {
  337.26 +        model.setName("Joe");
  337.27 +        assertEquals(model.getHelloMessage(), "Hello Joe!", "Cleared after pressing +");
  337.28 +    }
  337.29 +}
   338.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   338.2 +++ b/mojo/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java	Sun Feb 03 07:48:42 2013 +0100
   338.3 @@ -0,0 +1,40 @@
   338.4 +package ${package};
   338.5 +
   338.6 +import org.apidesign.bck2brwsr.vmtest.Compare;
   338.7 +import org.apidesign.bck2brwsr.vmtest.VMTest;
   338.8 +import org.testng.annotations.Factory;
   338.9 +
  338.10 +/** Bck2brwsr cares about compatibility with real Java. Whatever API is
  338.11 + * supported by bck2brwsr, it needs to behave the same way as when running
  338.12 + * in HotSpot VM. 
  338.13 + * <p>
  338.14 + * There can be bugs, however. To help us fix them, we kindly ask you to 
  338.15 + * write an "inconsistency" test. A test that compares behavior of the API
  338.16 + * between real VM and bck2brwsr VM. This class is skeleton of such test.
  338.17 + *
  338.18 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  338.19 + */
  338.20 +public class InconsistencyTest {
  338.21 +    /** A method to demonstrate inconsistency between bck2brwsr and HotSpot.
  338.22 +     * Make calls to an API that behaves strangely, return some result at
  338.23 +     * the end. No need to use any <code>assert</code>.
  338.24 +     * 
  338.25 +     * @return value to compare between HotSpot and bck2brwsr
  338.26 +     */
  338.27 +    @Compare
  338.28 +    public int checkStringHashCode() throws Exception {
  338.29 +        return "Is string hashCode the same?".hashCode();
  338.30 +    }
  338.31 +
  338.32 +    /** Factory method that creates a three tests for each method annotated with
  338.33 +     * {@link org.apidesign.bck2brwsr.vmtest.Compare}. One executes the code in
  338.34 +     * HotSpot, one in Rhino and the last one compares the results.
  338.35 +     * 
  338.36 +     * @see org.apidesign.bck2brwsr.vmtest.VMTest
  338.37 +     */
  338.38 +    @Factory
  338.39 +    public static Object[] create() {
  338.40 +        return VMTest.create(InconsistencyTest.class);
  338.41 +    }
  338.42 +    
  338.43 +}
   339.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   339.2 +++ b/mojo/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java	Sun Feb 03 07:48:42 2013 +0100
   339.3 @@ -0,0 +1,46 @@
   339.4 +package ${package};
   339.5 +
   339.6 +import org.apidesign.bck2brwsr.htmlpage.api.OnEvent;
   339.7 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
   339.8 +import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
   339.9 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  339.10 +import org.testng.annotations.Factory;
  339.11 +
  339.12 +/** Sometimes it is useful to run tests inside of the real browser. 
  339.13 + * To do that just annotate your method with {@link org.apidesign.bck2brwsr.vmtest.BrwsrTest}
  339.14 + * and that is it. If your code references elements on the HTML page,
  339.15 + * you can pass in an {@link org.apidesign.bck2brwsr.vmtest.HtmlFragment} which
  339.16 + * will be made available on the page before your test starts.
  339.17 + *
  339.18 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  339.19 + */
  339.20 +public class IntegrationTest {
  339.21 +    
  339.22 +    /** Write to testing code here. Use <code>assert</code> (but not TestNG's
  339.23 +     * Assert, as TestNG is not compiled with target 1.6 yet).
  339.24 +     */
  339.25 +    @HtmlFragment(
  339.26 +        "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
  339.27 +        "Your name: <input id='input' data-bind=\"value: name, valueUpdate: 'afterkeydown'\"></input>\n" +
  339.28 +        "<button id=\"hello\">Say Hello!</button>\n" +
  339.29 +        "<p>\n" +
  339.30 +        "    <canvas id=\"canvas\" width=\"300\" height=\"50\"></canvas>\n" +
  339.31 +        "</p>\n"
  339.32 +    )
  339.33 +    @BrwsrTest
  339.34 +    public void modifyValueAssertChangeInModel() {
  339.35 +        Index m = new Index();
  339.36 +        m.setName("Joe Hacker");
  339.37 +        m.applyBindings();
  339.38 +        assert "Joe Hacker".equals(m.INPUT.getValue()) : "Value is really Joe Hacker: " + m.INPUT.getValue();
  339.39 +        m.INPUT.setValue("Happy Joe");
  339.40 +        m.triggerEvent(m.INPUT, OnEvent.CHANGE);
  339.41 +        assert "Happy Joe".equals(m.getName()) : "Name property updated to Happy Joe: " + m.getName();
  339.42 +    }
  339.43 +
  339.44 +    @Factory
  339.45 +    public static Object[] create() {
  339.46 +        return VMTest.create(IntegrationTest.class);
  339.47 +    }
  339.48 +    
  339.49 +}
   340.1 --- a/pom.xml	Wed Dec 05 10:03:58 2012 +0100
   340.2 +++ b/pom.xml	Sun Feb 03 07:48:42 2013 +0100
   340.3 @@ -10,9 +10,13 @@
   340.4      <module>vm</module>
   340.5      <module>emul</module>
   340.6      <module>core</module>
   340.7 +    <module>dew</module>
   340.8      <module>mojo</module>
   340.9      <module>javaquery</module>
  340.10      <module>javap</module>
  340.11 +    <module>benchmarks</module>
  340.12 +    <module>launcher</module>
  340.13 +    <module>vmtest</module>
  340.14    </modules>
  340.15    <licenses>
  340.16        <license>
  340.17 @@ -66,10 +70,14 @@
  340.18                    <header>COPYING</header>
  340.19                    <strictCheck>true</strictCheck>
  340.20                    <excludes>
  340.21 -                       <exclude>emul/**</exclude>
  340.22 +                       <exclude>emul/*/src/main/**</exclude>
  340.23                         <exclude>javap/**</exclude>
  340.24                         <exclude>*</exclude>
  340.25                         <exclude>.*/**</exclude>
  340.26 +                       <exclude>mojo/src/main/resources/archetype-resources/**</exclude>
  340.27 +                       <exclude>dew/src/main/resources/org/apidesign/bck2brwsr/dew/**</exclude>
  340.28 +                       <exclude>vmtest/src/test/resources/**</exclude>
  340.29 +                       <exclude>javaquery/api/src/main/resources/org/apidesign/bck2brwsr/htmlpage/knockout*.js</exclude>
  340.30                    </excludes>
  340.31                </configuration>
  340.32            </plugin>
  340.33 @@ -107,4 +115,4 @@
  340.34    <properties>
  340.35        <license>COPYING</license>
  340.36    </properties>
  340.37 -</project>
  340.38 +</project>
  340.39 \ No newline at end of file
   341.1 --- a/vm/pom.xml	Wed Dec 05 10:03:58 2012 +0100
   341.2 +++ b/vm/pom.xml	Sun Feb 03 07:48:42 2013 +0100
   341.3 @@ -90,7 +90,7 @@
   341.4      </dependency>
   341.5      <dependency>
   341.6        <groupId>${project.groupId}</groupId>
   341.7 -      <artifactId>emul</artifactId>
   341.8 +      <artifactId>emul.mini</artifactId>
   341.9        <version>0.3-SNAPSHOT</version>
  341.10        <scope>test</scope>
  341.11      </dependency>
   342.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   342.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/Bck2Brwsr.java	Sun Feb 03 07:48:42 2013 +0100
   342.3 @@ -0,0 +1,106 @@
   342.4 +/**
   342.5 + * Back 2 Browser Bytecode Translator
   342.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   342.7 + *
   342.8 + * This program is free software: you can redistribute it and/or modify
   342.9 + * it under the terms of the GNU General Public License as published by
  342.10 + * the Free Software Foundation, version 2 of the License.
  342.11 + *
  342.12 + * This program is distributed in the hope that it will be useful,
  342.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  342.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  342.15 + * GNU General Public License for more details.
  342.16 + *
  342.17 + * You should have received a copy of the GNU General Public License
  342.18 + * along with this program. Look for COPYING file in the top folder.
  342.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  342.20 + */
  342.21 +package org.apidesign.vm4brwsr;
  342.22 +
  342.23 +import java.io.IOException;
  342.24 +import java.io.InputStream;
  342.25 +import java.net.URL;
  342.26 +import java.util.Enumeration;
  342.27 +
  342.28 +/** Build your own virtual machine! Use methods in this class to generate
  342.29 + * a skeleton JVM in JavaScript that contains pre-compiled classes of your
  342.30 + * choice. The generated script defines one JavaScript method that can
  342.31 + * be used to bootstrap and load the virtual machine: <pre>
  342.32 + * var vm = bck2brwsr();
  342.33 + * var main = vm.loadClass('org.your.pkg.Main');
  342.34 + * main.main__V_3Ljava_lang_String_2(null);
  342.35 + * </pre>
  342.36 + * In case one wants to initialize the virtual machine with ability to
  342.37 + * load classes lazily when needed, one can provide a loader function to
  342.38 + * when creating the virtual machine: <pre>
  342.39 + * var vm = bck2brwsr(function(resource) { 
  342.40 + *   return null; // byte[] for the resource
  342.41 + * });
  342.42 + * </pre>
  342.43 + * In this scenario, when a request for an unknown class is made, the loader
  342.44 + * function is asked for its byte code and the system dynamically transforms
  342.45 + * it to JavaScript.
  342.46 + *
  342.47 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  342.48 + */
  342.49 +public final class Bck2Brwsr {
  342.50 +    private Bck2Brwsr() {
  342.51 +    }
  342.52 +    
  342.53 +    /** Generates virtual machine from bytes served by a <code>resources</code>
  342.54 +     * provider.
  342.55 +     * 
  342.56 +     * @param out the output to write the generated JavaScript to
  342.57 +     * @param resources provider of class files to use
  342.58 +     * @param classes additional classes to include in the generated script
  342.59 +     * @throws IOException I/O exception can be thrown when something goes wrong
  342.60 +     */
  342.61 +    public static void generate(Appendable out, Resources resources, String... classes) throws IOException {
  342.62 +        StringArray arr = StringArray.asList(classes);
  342.63 +        arr.add(VM.class.getName().replace('.', '/'));
  342.64 +        VM.compile(resources, out, arr);
  342.65 +    }
  342.66 +    
  342.67 +    /** Generates virtual machine from bytes served by a class loader.
  342.68 +     * 
  342.69 +     * @param out the output to write the generated JavaScript to
  342.70 +     * @param loader class loader to load needed classes from
  342.71 +     * @param classes additional classes to include in the generated script
  342.72 +     * @throws IOException I/O exception can be thrown when something goes wrong
  342.73 +     */
  342.74 +    public static void generate(Appendable out, final ClassLoader loader, String... classes) throws IOException {
  342.75 +        class R implements Resources {
  342.76 +            @Override
  342.77 +            public InputStream get(String name) throws IOException {
  342.78 +                Enumeration<URL> en = loader.getResources(name);
  342.79 +                URL u = null;
  342.80 +                while (en.hasMoreElements()) {
  342.81 +                    u = en.nextElement();
  342.82 +                }
  342.83 +                if (u == null) {
  342.84 +                    throw new IOException("Can't find " + name);
  342.85 +                }
  342.86 +                return u.openStream();
  342.87 +            }
  342.88 +        }
  342.89 +        generate(out, new R(), classes);
  342.90 +    }
  342.91 +    
  342.92 +    /** Provider of resources (classes and other files). The 
  342.93 +     * {@link #generate(java.lang.Appendable, org.apidesign.vm4brwsr.Bck2Brwsr.Resources, java.lang.String[]) 
  342.94 +     * generator method} will call back here for all classes needed during
  342.95 +     * translation to JavaScript.
  342.96 +     */
  342.97 +    public interface Resources {
  342.98 +        /** Loads given resource (class or other file like image). The 
  342.99 +         * resource name to load bytes for the {@link String} class
 342.100 +         * would be <code>"java/lang/String.class"</code>.
 342.101 +         * 
 342.102 +         * @param resource path to resource to load
 342.103 +         * @return the input stream for the resource 
 342.104 +         * @throws IOException can be thrown if the loading fails on some error
 342.105 +         *   or the file cannot be found
 342.106 +         */
 342.107 +        public InputStream get(String resource) throws IOException;
 342.108 +    }
 342.109 +}
   343.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Wed Dec 05 10:03:58 2012 +0100
   343.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Sun Feb 03 07:48:42 2013 +0100
   343.3 @@ -19,19 +19,23 @@
   343.4  
   343.5  import java.io.IOException;
   343.6  import java.io.InputStream;
   343.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
   343.8  import org.apidesign.javap.AnnotationParser;
   343.9  import org.apidesign.javap.ClassData;
  343.10  import org.apidesign.javap.FieldData;
  343.11  import org.apidesign.javap.MethodData;
  343.12 +import org.apidesign.javap.StackMapIterator;
  343.13  import static org.apidesign.javap.RuntimeConstants.*;
  343.14 +import org.apidesign.javap.TrapData;
  343.15 +import org.apidesign.javap.TrapDataIterator;
  343.16  
  343.17  /** Translator of the code inside class files to JavaScript.
  343.18   *
  343.19   * @author Jaroslav Tulach <jtulach@netbeans.org>
  343.20   */
  343.21 -public abstract class ByteCodeToJavaScript {
  343.22 +abstract class ByteCodeToJavaScript {
  343.23      private ClassData jc;
  343.24 -    private final Appendable out;
  343.25 +    final Appendable out;
  343.26  
  343.27      protected ByteCodeToJavaScript(Appendable out) {
  343.28          this.out = out;
  343.29 @@ -48,7 +52,7 @@
  343.30      /*
  343.31       * @param resourcePath name of resources to read
  343.32       */
  343.33 -    protected abstract void requireScript(String resourcePath);
  343.34 +    protected abstract void requireScript(String resourcePath) throws IOException;
  343.35      
  343.36      /** Allows subclasses to redefine what field a function representing a
  343.37       * class gets assigned. By default it returns the suggested name followed
  343.38 @@ -56,9 +60,23 @@
  343.39       * 
  343.40       * @param className suggested name of the class
  343.41       */
  343.42 -    protected String assignClass(String className) {
  343.43 +    /* protected */ String assignClass(String className) {
  343.44          return className + " = ";
  343.45      }
  343.46 +    /* protected */ String accessClass(String classOperation) {
  343.47 +        return classOperation;
  343.48 +    }
  343.49 +    
  343.50 +    /** Prints out a debug message. 
  343.51 +     * 
  343.52 +     * @param msg the message
  343.53 +     * @return true if the message has been printed
  343.54 +     * @throws IOException 
  343.55 +     */
  343.56 +    boolean debug(String msg) throws IOException {
  343.57 +        out.append(msg);
  343.58 +        return true;
  343.59 +    }
  343.60  
  343.61      /**
  343.62       * Converts a given class file to a JavaScript version.
  343.63 @@ -71,6 +89,11 @@
  343.64      
  343.65      public String compile(InputStream classFile) throws IOException {
  343.66          this.jc = new ClassData(classFile);
  343.67 +        if (jc.getMajor_version() < 50) {
  343.68 +            throw new IOException("Can't compile " + jc.getClassName() + ". Class file version " + jc.getMajor_version() + "."
  343.69 +                + jc.getMinor_version() + " - recompile with -target 1.6 (at least)."
  343.70 +            );
  343.71 +        }
  343.72          byte[] arrData = jc.findAnnotationData(true);
  343.73          String[] arr = findAnnotation(arrData, jc, 
  343.74              "org.apidesign.bck2brwsr.core.ExtraJavaScript", 
  343.75 @@ -91,23 +114,33 @@
  343.76          out.append("\n\n").append(assignClass(className));
  343.77          out.append("function CLS() {");
  343.78          out.append("\n  if (!CLS.prototype.$instOf_").append(className).append(") {");
  343.79 -        for (FieldData v : jc.getFields()) {
  343.80 -            if (v.isStatic()) {
  343.81 -                out.append("\n  CLS.").append(v.getName()).append(initField(v));
  343.82 -            }
  343.83 -        }
  343.84          if (proto == null) {
  343.85              String sc = jc.getSuperClassName(); // with _
  343.86              out.append("\n    var pp = ").
  343.87 -                append(sc.replace('/', '_')).append("(true);");
  343.88 +                append(accessClass(sc.replace('/', '_'))).append("(true);");
  343.89              out.append("\n    var p = CLS.prototype = pp;");
  343.90              out.append("\n    var c = p;");
  343.91              out.append("\n    var sprcls = pp.constructor.$class;");
  343.92          } else {
  343.93              out.append("\n    var p = CLS.prototype = ").append(proto[1]).append(";");
  343.94 +            if (proto[0] == null) {
  343.95 +                proto[0] = "p";
  343.96 +            }
  343.97              out.append("\n    var c = ").append(proto[0]).append(";");
  343.98              out.append("\n    var sprcls = null;");
  343.99          }
 343.100 +        for (FieldData v : jc.getFields()) {
 343.101 +            if (v.isStatic()) {
 343.102 +                out.append("\n  CLS.").append(v.getName()).append(initField(v));
 343.103 +            } else {
 343.104 +                out.append("\n  c._").append(v.getName()).append(" = function (v) {")
 343.105 +                   .append("  if (arguments.length == 1) this.fld_").
 343.106 +                    append(className).append('_').append(v.getName())
 343.107 +                   .append(" = v; return this.fld_").
 343.108 +                    append(className).append('_').append(v.getName())
 343.109 +                   .append("; };");
 343.110 +            }
 343.111 +        }
 343.112          for (MethodData m : jc.getMethods()) {
 343.113              byte[] onlyArr = m.findAnnotationData(true);
 343.114              String[] only = findAnnotation(onlyArr, jc, 
 343.115 @@ -121,27 +154,38 @@
 343.116                  }
 343.117                  continue;
 343.118              }
 343.119 +            String prefix;
 343.120              String mn;
 343.121              if (m.isStatic()) {
 343.122 -                mn = generateStaticMethod("\n    c.", m, toInitilize);
 343.123 +                prefix = "\n    c.";
 343.124 +                mn = generateStaticMethod(prefix, m, toInitilize);
 343.125              } else {
 343.126 -                mn = generateInstanceMethod("\n    c.", m);
 343.127 +                if (m.isConstructor()) {
 343.128 +                    prefix = "\n    CLS.";
 343.129 +                    mn = generateInstanceMethod(prefix, m);
 343.130 +                } else {
 343.131 +                    prefix = "\n    c.";
 343.132 +                    mn = generateInstanceMethod(prefix, m);
 343.133 +                }
 343.134              }
 343.135              byte[] runAnno = m.findAnnotationData(false);
 343.136              if (runAnno != null) {
 343.137 -                out.append("\n    c.").append(mn).append(".anno = {");
 343.138 +                out.append(prefix).append(mn).append(".anno = {");
 343.139                  generateAnno(jc, out, runAnno);
 343.140                  out.append("\n    };");
 343.141              }
 343.142 +            out.append(prefix).append(mn).append(".access = " + m.getAccess()).append(";");
 343.143          }
 343.144          out.append("\n    c.constructor = CLS;");
 343.145          out.append("\n    c.$instOf_").append(className).append(" = true;");
 343.146          for (String superInterface : jc.getSuperInterfaces()) {
 343.147              out.append("\n    c.$instOf_").append(superInterface.replace('/', '_')).append(" = true;");
 343.148          }
 343.149 -        out.append("\n    CLS.$class = java_lang_Class(true);");
 343.150 +        out.append("\n    CLS.$class = ");
 343.151 +        out.append(accessClass("java_lang_Class(true);"));
 343.152          out.append("\n    CLS.$class.jvmName = '").append(jc.getClassName()).append("';");
 343.153          out.append("\n    CLS.$class.superclass = sprcls;");
 343.154 +        out.append("\n    CLS.$class.access = ").append(jc.getAccessFlags()+";");
 343.155          out.append("\n    CLS.$class.cnstr = CLS;");
 343.156          byte[] classAnno = jc.findAnnotationData(false);
 343.157          if (classAnno != null) {
 343.158 @@ -169,13 +213,14 @@
 343.159              }
 343.160              if (!v.isStatic()) {
 343.161                  out.append("\n    this.fld_").
 343.162 +                    append(className).append('_').
 343.163                      append(v.getName()).append(initField(v));
 343.164              }
 343.165          }
 343.166          out.append("\n    return this;");
 343.167          out.append("\n  }");
 343.168          out.append("\n  return arguments[0] ? new CLS() : CLS.prototype;");
 343.169 -        out.append("\n}");
 343.170 +        out.append("\n};");
 343.171          StringBuilder sb = new StringBuilder();
 343.172          for (String init : toInitilize.toArray()) {
 343.173              sb.append("\n").append(init).append("();");
 343.174 @@ -187,298 +232,535 @@
 343.175          if (jsb != null) {
 343.176              return jsb;
 343.177          }
 343.178 -        StringBuilder argsCnt = new StringBuilder();
 343.179 -        final String mn = findMethodName(m, argsCnt);
 343.180 -        out.append(prefix).append(mn).append(" = function");
 343.181 +        final String mn = findMethodName(m, new StringBuilder());
 343.182          if (mn.equals("class__V")) {
 343.183 -            toInitilize.add(className(jc) + "(false)." + mn);
 343.184 +            toInitilize.add(accessClass(className(jc)) + "(false)." + mn);
 343.185          }
 343.186 -        out.append('(');
 343.187 -        String space = "";
 343.188 -        for (int index = 0, i = 0; i < argsCnt.length(); i++) {
 343.189 -            out.append(space);
 343.190 -            out.append("arg").append(String.valueOf(index));
 343.191 -            space = ",";
 343.192 -            final String desc = null;// XXX findDescriptor(args.get(i).getDescriptor());
 343.193 -            if (argsCnt.charAt(i) == '1') {
 343.194 -                index += 2;
 343.195 -            } else {
 343.196 -                index++;
 343.197 -            }
 343.198 -        }
 343.199 -        out.append(") {").append("\n");
 343.200 -        final byte[] code = m.getCode();
 343.201 -        if (code != null) {
 343.202 -            int len = m.getMaxLocals();
 343.203 -            for (int index = argsCnt.length(), i = argsCnt.length(); i < len; i++) {
 343.204 -                out.append("  var ");
 343.205 -                out.append("arg").append(String.valueOf(i)).append(";\n");
 343.206 -            }
 343.207 -            out.append("  var s = new Array();\n");
 343.208 -            produceCode(code);
 343.209 -        } else {
 343.210 -            out.append("  throw 'no code found for ").append(m.getInternalSig()).append("';\n");
 343.211 -        }
 343.212 -        out.append("};");
 343.213 +        generateMethod(prefix, mn, m);
 343.214          return mn;
 343.215      }
 343.216 -    
 343.217 +
 343.218      private String generateInstanceMethod(String prefix, MethodData m) throws IOException {
 343.219          String jsb = javaScriptBody(prefix, m, false);
 343.220          if (jsb != null) {
 343.221              return jsb;
 343.222          }
 343.223 -        StringBuilder argsCnt = new StringBuilder();
 343.224 -        final String mn = findMethodName(m, argsCnt);
 343.225 -        out.append(prefix).append(mn).append(" = function");
 343.226 -        out.append("(arg0");
 343.227 -        String space = ",";
 343.228 -        for (int index = 1, i = 0; i < argsCnt.length(); i++) {
 343.229 -            out.append(space);
 343.230 -            out.append("arg").append(String.valueOf(index));
 343.231 -            if (argsCnt.charAt(i) == '1') {
 343.232 -                index += 2;
 343.233 -            } else {
 343.234 -                index++;
 343.235 -            }
 343.236 -        }
 343.237 -        out.append(") {").append("\n");
 343.238 -        final byte[] code = m.getCode();
 343.239 -        if (code != null) {
 343.240 -            int len = m.getMaxLocals();
 343.241 -            for (int index = argsCnt.length(), i = argsCnt.length(); i < len; i++) {
 343.242 -                out.append("  var ");
 343.243 -                out.append("arg").append(String.valueOf(i + 1)).append(";\n");
 343.244 -            }
 343.245 -            out.append(";\n  var s = new Array();\n");
 343.246 -            produceCode(code);
 343.247 -        } else {
 343.248 -            out.append("  throw 'no code found for ").append(m.getInternalSig()).append("';\n");
 343.249 -        }
 343.250 -        out.append("};");
 343.251 +        final String mn = findMethodName(m, new StringBuilder());
 343.252 +        generateMethod(prefix, mn, m);
 343.253          return mn;
 343.254      }
 343.255  
 343.256 -    private void produceCode(byte[] byteCodes) throws IOException {
 343.257 +    private void generateMethod(String prefix, String name, MethodData m)
 343.258 +            throws IOException {
 343.259 +        final StackMapIterator stackMapIterator = m.createStackMapIterator();
 343.260 +        TrapDataIterator trap = m.getTrapDataIterator();
 343.261 +        final LocalsMapper lmapper =
 343.262 +                new LocalsMapper(stackMapIterator.getArguments());
 343.263 +
 343.264 +        out.append(prefix).append(name).append(" = function(");
 343.265 +        lmapper.outputArguments(out, m.isStatic());
 343.266 +        out.append(") {").append("\n");
 343.267 +
 343.268 +        final byte[] byteCodes = m.getCode();
 343.269 +        if (byteCodes == null) {
 343.270 +            out.append("  throw 'no code found for ")
 343.271 +               .append(jc.getClassName()).append('.')
 343.272 +               .append(m.getName()).append("';\n");
 343.273 +            out.append("};");
 343.274 +            return;
 343.275 +        }
 343.276 +
 343.277 +        final StackMapper smapper = new StackMapper();
 343.278 +
 343.279 +        if (!m.isStatic()) {
 343.280 +            out.append("  var ").append(" lcA0 = this;\n");
 343.281 +        }
 343.282 +
 343.283 +        int lastStackFrame = -1;
 343.284 +        TrapData[] previousTrap = null;
 343.285 +        boolean wide = false;
 343.286 +        
 343.287          out.append("\n  var gt = 0;\n  for(;;) switch(gt) {\n");
 343.288          for (int i = 0; i < byteCodes.length; i++) {
 343.289              int prev = i;
 343.290 -            out.append("    case " + i).append(": ");
 343.291 -            final int c = readByte(byteCodes, i);
 343.292 +            stackMapIterator.advanceTo(i);
 343.293 +            boolean changeInCatch = trap.advanceTo(i);
 343.294 +            if (changeInCatch || lastStackFrame != stackMapIterator.getFrameIndex()) {
 343.295 +                if (previousTrap != null) {
 343.296 +                    generateCatch(previousTrap);
 343.297 +                    previousTrap = null;
 343.298 +                }
 343.299 +            }
 343.300 +            if (lastStackFrame != stackMapIterator.getFrameIndex()) {
 343.301 +                lastStackFrame = stackMapIterator.getFrameIndex();
 343.302 +                lmapper.syncWithFrameLocals(stackMapIterator.getFrameLocals());
 343.303 +                smapper.syncWithFrameStack(stackMapIterator.getFrameStack());
 343.304 +                out.append("    case " + i).append(": ");            
 343.305 +                changeInCatch = true;
 343.306 +            } else {
 343.307 +                debug("    /* " + i + " */ ");
 343.308 +            }
 343.309 +            if (changeInCatch && trap.useTry()) {
 343.310 +                out.append("try {");
 343.311 +                previousTrap = trap.current();
 343.312 +            }
 343.313 +            final int c = readUByte(byteCodes, i);
 343.314              switch (c) {
 343.315                  case opc_aload_0:
 343.316 +                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(0));
 343.317 +                    break;
 343.318                  case opc_iload_0:
 343.319 +                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(0));
 343.320 +                    break;
 343.321                  case opc_lload_0:
 343.322 +                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(0));
 343.323 +                    break;
 343.324                  case opc_fload_0:
 343.325 +                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(0));
 343.326 +                    break;
 343.327                  case opc_dload_0:
 343.328 -                    out.append("s.push(arg0);");
 343.329 +                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(0));
 343.330                      break;
 343.331                  case opc_aload_1:
 343.332 +                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(1));
 343.333 +                    break;
 343.334                  case opc_iload_1:
 343.335 +                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(1));
 343.336 +                    break;
 343.337                  case opc_lload_1:
 343.338 +                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(1));
 343.339 +                    break;
 343.340                  case opc_fload_1:
 343.341 +                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(1));
 343.342 +                    break;
 343.343                  case opc_dload_1:
 343.344 -                    out.append("s.push(arg1);");
 343.345 +                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(1));
 343.346                      break;
 343.347                  case opc_aload_2:
 343.348 +                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(2));
 343.349 +                    break;
 343.350                  case opc_iload_2:
 343.351 +                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(2));
 343.352 +                    break;
 343.353                  case opc_lload_2:
 343.354 +                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(2));
 343.355 +                    break;
 343.356                  case opc_fload_2:
 343.357 +                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(2));
 343.358 +                    break;
 343.359                  case opc_dload_2:
 343.360 -                    out.append("s.push(arg2);");
 343.361 +                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(2));
 343.362                      break;
 343.363                  case opc_aload_3:
 343.364 +                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(3));
 343.365 +                    break;
 343.366                  case opc_iload_3:
 343.367 +                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(3));
 343.368 +                    break;
 343.369                  case opc_lload_3:
 343.370 +                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(3));
 343.371 +                    break;
 343.372                  case opc_fload_3:
 343.373 +                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(3));
 343.374 +                    break;
 343.375                  case opc_dload_3:
 343.376 -                    out.append("s.push(arg3);");
 343.377 +                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(3));
 343.378                      break;
 343.379 -                case opc_iload:
 343.380 -                case opc_lload:
 343.381 -                case opc_fload:
 343.382 -                case opc_dload:
 343.383 -                case opc_aload: {
 343.384 -                    final int indx = readByte(byteCodes, ++i);
 343.385 -                    out.append("s.push(arg").append(indx + ");");
 343.386 +                case opc_iload: {
 343.387 +                    ++i;
 343.388 +                    final int indx = wide ? readUShort(byteCodes, i++)
 343.389 +                                          : readUByte(byteCodes, i);
 343.390 +                    wide = false;
 343.391 +                    emit(out, "var @1 = @2;",
 343.392 +                         smapper.pushI(), lmapper.getI(indx));
 343.393                      break;
 343.394                  }
 343.395 -                case opc_istore:
 343.396 -                case opc_lstore:
 343.397 -                case opc_fstore:
 343.398 -                case opc_dstore:
 343.399 +                case opc_lload: {
 343.400 +                    ++i;
 343.401 +                    final int indx = wide ? readUShort(byteCodes, i++)
 343.402 +                                          : readUByte(byteCodes, i);
 343.403 +                    wide = false;
 343.404 +                    emit(out, "var @1 = @2;",
 343.405 +                         smapper.pushL(), lmapper.getL(indx));
 343.406 +                    break;
 343.407 +                }
 343.408 +                case opc_fload: {
 343.409 +                    ++i;
 343.410 +                    final int indx = wide ? readUShort(byteCodes, i++)
 343.411 +                                          : readUByte(byteCodes, i);
 343.412 +                    wide = false;
 343.413 +                    emit(out, "var @1 = @2;",
 343.414 +                         smapper.pushF(), lmapper.getF(indx));
 343.415 +                    break;
 343.416 +                }
 343.417 +                case opc_dload: {
 343.418 +                    ++i;
 343.419 +                    final int indx = wide ? readUShort(byteCodes, i++)
 343.420 +                                          : readUByte(byteCodes, i);
 343.421 +                    wide = false;
 343.422 +                    emit(out, "var @1 = @2;",
 343.423 +                         smapper.pushD(), lmapper.getD(indx));
 343.424 +                    break;
 343.425 +                }
 343.426 +                case opc_aload: {
 343.427 +                    ++i;
 343.428 +                    final int indx = wide ? readUShort(byteCodes, i++)
 343.429 +                                          : readUByte(byteCodes, i);
 343.430 +                    wide = false;
 343.431 +                    emit(out, "var @1 = @2;",
 343.432 +                         smapper.pushA(), lmapper.getA(indx));
 343.433 +                    break;
 343.434 +                }
 343.435 +                case opc_istore: {
 343.436 +                    ++i;
 343.437 +                    final int indx = wide ? readUShort(byteCodes, i++)
 343.438 +                                          : readUByte(byteCodes, i);
 343.439 +                    wide = false;
 343.440 +                    emit(out, "var @1 = @2;",
 343.441 +                         lmapper.setI(indx), smapper.popI());
 343.442 +                    break;
 343.443 +                }
 343.444 +                case opc_lstore: {
 343.445 +                    ++i;
 343.446 +                    final int indx = wide ? readUShort(byteCodes, i++)
 343.447 +                                          : readUByte(byteCodes, i);
 343.448 +                    wide = false;
 343.449 +                    emit(out, "var @1 = @2;",
 343.450 +                         lmapper.setL(indx), smapper.popL());
 343.451 +                    break;
 343.452 +                }
 343.453 +                case opc_fstore: {
 343.454 +                    ++i;
 343.455 +                    final int indx = wide ? readUShort(byteCodes, i++)
 343.456 +                                          : readUByte(byteCodes, i);
 343.457 +                    wide = false;
 343.458 +                    emit(out, "var @1 = @2;",
 343.459 +                         lmapper.setF(indx), smapper.popF());
 343.460 +                    break;
 343.461 +                }
 343.462 +                case opc_dstore: {
 343.463 +                    ++i;
 343.464 +                    final int indx = wide ? readUShort(byteCodes, i++)
 343.465 +                                          : readUByte(byteCodes, i);
 343.466 +                    wide = false;
 343.467 +                    emit(out, "var @1 = @2;",
 343.468 +                         lmapper.setD(indx), smapper.popD());
 343.469 +                    break;
 343.470 +                }
 343.471                  case opc_astore: {
 343.472 -                    final int indx = readByte(byteCodes, ++i);
 343.473 -                    out.append("arg" + indx).append(" = s.pop();");
 343.474 +                    ++i;
 343.475 +                    final int indx = wide ? readUShort(byteCodes, i++)
 343.476 +                                          : readUByte(byteCodes, i);
 343.477 +                    wide = false;
 343.478 +                    emit(out, "var @1 = @2;",
 343.479 +                         lmapper.setA(indx), smapper.popA());
 343.480                      break;
 343.481                  }
 343.482                  case opc_astore_0:
 343.483 +                    emit(out, "var @1 = @2;", lmapper.setA(0), smapper.popA());
 343.484 +                    break;
 343.485                  case opc_istore_0:
 343.486 +                    emit(out, "var @1 = @2;", lmapper.setI(0), smapper.popI());
 343.487 +                    break;
 343.488                  case opc_lstore_0:
 343.489 +                    emit(out, "var @1 = @2;", lmapper.setL(0), smapper.popL());
 343.490 +                    break;
 343.491                  case opc_fstore_0:
 343.492 +                    emit(out, "var @1 = @2;", lmapper.setF(0), smapper.popF());
 343.493 +                    break;
 343.494                  case opc_dstore_0:
 343.495 -                    out.append("arg0 = s.pop();");
 343.496 +                    emit(out, "var @1 = @2;", lmapper.setD(0), smapper.popD());
 343.497                      break;
 343.498                  case opc_astore_1:
 343.499 +                    emit(out, "var @1 = @2;", lmapper.setA(1), smapper.popA());
 343.500 +                    break;
 343.501                  case opc_istore_1:
 343.502 +                    emit(out, "var @1 = @2;", lmapper.setI(1), smapper.popI());
 343.503 +                    break;
 343.504                  case opc_lstore_1:
 343.505 +                    emit(out, "var @1 = @2;", lmapper.setL(1), smapper.popL());
 343.506 +                    break;
 343.507                  case opc_fstore_1:
 343.508 +                    emit(out, "var @1 = @2;", lmapper.setF(1), smapper.popF());
 343.509 +                    break;
 343.510                  case opc_dstore_1:
 343.511 -                    out.append("arg1 = s.pop();");
 343.512 +                    emit(out, "var @1 = @2;", lmapper.setD(1), smapper.popD());
 343.513                      break;
 343.514                  case opc_astore_2:
 343.515 +                    emit(out, "var @1 = @2;", lmapper.setA(2), smapper.popA());
 343.516 +                    break;
 343.517                  case opc_istore_2:
 343.518 +                    emit(out, "var @1 = @2;", lmapper.setI(2), smapper.popI());
 343.519 +                    break;
 343.520                  case opc_lstore_2:
 343.521 +                    emit(out, "var @1 = @2;", lmapper.setL(2), smapper.popL());
 343.522 +                    break;
 343.523                  case opc_fstore_2:
 343.524 +                    emit(out, "var @1 = @2;", lmapper.setF(2), smapper.popF());
 343.525 +                    break;
 343.526                  case opc_dstore_2:
 343.527 -                    out.append("arg2 = s.pop();");
 343.528 +                    emit(out, "var @1 = @2;", lmapper.setD(2), smapper.popD());
 343.529                      break;
 343.530                  case opc_astore_3:
 343.531 +                    emit(out, "var @1 = @2;", lmapper.setA(3), smapper.popA());
 343.532 +                    break;
 343.533                  case opc_istore_3:
 343.534 +                    emit(out, "var @1 = @2;", lmapper.setI(3), smapper.popI());
 343.535 +                    break;
 343.536                  case opc_lstore_3:
 343.537 +                    emit(out, "var @1 = @2;", lmapper.setL(3), smapper.popL());
 343.538 +                    break;
 343.539                  case opc_fstore_3:
 343.540 +                    emit(out, "var @1 = @2;", lmapper.setF(3), smapper.popF());
 343.541 +                    break;
 343.542                  case opc_dstore_3:
 343.543 -                    out.append("arg3 = s.pop();");
 343.544 +                    emit(out, "var @1 = @2;", lmapper.setD(3), smapper.popD());
 343.545                      break;
 343.546                  case opc_iadd:
 343.547 +                    emit(out, "@1 = @1.add32(@2);", smapper.getI(1), smapper.popI());
 343.548 +                    break;
 343.549                  case opc_ladd:
 343.550 +                    emit(out, "@1 += @2;", smapper.getL(1), smapper.popL());
 343.551 +                    break;
 343.552                  case opc_fadd:
 343.553 +                    emit(out, "@1 += @2;", smapper.getF(1), smapper.popF());
 343.554 +                    break;
 343.555                  case opc_dadd:
 343.556 -                    out.append("s.push(s.pop() + s.pop());");
 343.557 +                    emit(out, "@1 += @2;", smapper.getD(1), smapper.popD());
 343.558                      break;
 343.559                  case opc_isub:
 343.560 +                    emit(out, "@1 = @1.sub32(@2);", smapper.getI(1), smapper.popI());
 343.561 +                    break;
 343.562                  case opc_lsub:
 343.563 +                    emit(out, "@1 -= @2;", smapper.getL(1), smapper.popL());
 343.564 +                    break;
 343.565                  case opc_fsub:
 343.566 +                    emit(out, "@1 -= @2;", smapper.getF(1), smapper.popF());
 343.567 +                    break;
 343.568                  case opc_dsub:
 343.569 -                    out.append("{ var tmp = s.pop(); s.push(s.pop() - tmp); }");
 343.570 +                    emit(out, "@1 -= @2;", smapper.getD(1), smapper.popD());
 343.571                      break;
 343.572                  case opc_imul:
 343.573 +                    emit(out, "@1 = @1.mul32(@2);", smapper.getI(1), smapper.popI());
 343.574 +                    break;
 343.575                  case opc_lmul:
 343.576 +                    emit(out, "@1 *= @2;", smapper.getL(1), smapper.popL());
 343.577 +                    break;
 343.578                  case opc_fmul:
 343.579 +                    emit(out, "@1 *= @2;", smapper.getF(1), smapper.popF());
 343.580 +                    break;
 343.581                  case opc_dmul:
 343.582 -                    out.append("s.push(s.pop() * s.pop());");
 343.583 +                    emit(out, "@1 *= @2;", smapper.getD(1), smapper.popD());
 343.584                      break;
 343.585                  case opc_idiv:
 343.586 +                    emit(out, "@1 = Math.floor(@1 / @2);",
 343.587 +                         smapper.getI(1), smapper.popI());
 343.588 +                    break;
 343.589                  case opc_ldiv:
 343.590 -                    out.append("{ var tmp = s.pop(); s.push(Math.floor(s.pop() / tmp)); }");
 343.591 +                    emit(out, "@1 = Math.floor(@1 / @2);",
 343.592 +                         smapper.getL(1), smapper.popL());
 343.593                      break;
 343.594                  case opc_fdiv:
 343.595 +                    emit(out, "@1 /= @2;", smapper.getF(1), smapper.popF());
 343.596 +                    break;
 343.597                  case opc_ddiv:
 343.598 -                    out.append("{ var tmp = s.pop(); s.push(s.pop() / tmp); }");
 343.599 +                    emit(out, "@1 /= @2;", smapper.getD(1), smapper.popD());
 343.600                      break;
 343.601                  case opc_irem:
 343.602 +                    emit(out, "@1 %= @2;", smapper.getI(1), smapper.popI());
 343.603 +                    break;
 343.604                  case opc_lrem:
 343.605 +                    emit(out, "@1 %= @2;", smapper.getL(1), smapper.popL());
 343.606 +                    break;
 343.607                  case opc_frem:
 343.608 +                    emit(out, "@1 %= @2;", smapper.getF(1), smapper.popF());
 343.609 +                    break;
 343.610                  case opc_drem:
 343.611 -                    out.append("{ var d = s.pop(); s.push(s.pop() % d); }");
 343.612 +                    emit(out, "@1 %= @2;", smapper.getD(1), smapper.popD());
 343.613                      break;
 343.614                  case opc_iand:
 343.615 +                    emit(out, "@1 &= @2;", smapper.getI(1), smapper.popI());
 343.616 +                    break;
 343.617                  case opc_land:
 343.618 -                    out.append("s.push(s.pop() & s.pop());");
 343.619 +                    emit(out, "@1 &= @2;", smapper.getL(1), smapper.popL());
 343.620                      break;
 343.621                  case opc_ior:
 343.622 +                    emit(out, "@1 |= @2;", smapper.getI(1), smapper.popI());
 343.623 +                    break;
 343.624                  case opc_lor:
 343.625 -                    out.append("s.push(s.pop() | s.pop());");
 343.626 +                    emit(out, "@1 |= @2;", smapper.getL(1), smapper.popL());
 343.627                      break;
 343.628                  case opc_ixor:
 343.629 +                    emit(out, "@1 ^= @2;", smapper.getI(1), smapper.popI());
 343.630 +                    break;
 343.631                  case opc_lxor:
 343.632 -                    out.append("s.push(s.pop() ^ s.pop());");
 343.633 +                    emit(out, "@1 ^= @2;", smapper.getL(1), smapper.popL());
 343.634                      break;
 343.635                  case opc_ineg:
 343.636 +                    emit(out, "@1 = -@1;", smapper.getI(0));
 343.637 +                    break;
 343.638                  case opc_lneg:
 343.639 +                    emit(out, "@1 = -@1;", smapper.getL(0));
 343.640 +                    break;
 343.641                  case opc_fneg:
 343.642 +                    emit(out, "@1 = -@1;", smapper.getF(0));
 343.643 +                    break;
 343.644                  case opc_dneg:
 343.645 -                    out.append("s.push(- s.pop());");
 343.646 +                    emit(out, "@1 = -@1;", smapper.getD(0));
 343.647                      break;
 343.648                  case opc_ishl:
 343.649 +                    emit(out, "@1 <<= @2;", smapper.getI(1), smapper.popI());
 343.650 +                    break;
 343.651                  case opc_lshl:
 343.652 -                    out.append("{ var v = s.pop(); s.push(s.pop() << v); }");
 343.653 +                    emit(out, "@1 <<= @2;", smapper.getL(1), smapper.popI());
 343.654                      break;
 343.655                  case opc_ishr:
 343.656 +                    emit(out, "@1 >>= @2;", smapper.getI(1), smapper.popI());
 343.657 +                    break;
 343.658                  case opc_lshr:
 343.659 -                    out.append("{ var v = s.pop(); s.push(s.pop() >> v); }");
 343.660 +                    emit(out, "@1 >>= @2;", smapper.getL(1), smapper.popI());
 343.661                      break;
 343.662                  case opc_iushr:
 343.663 +                    emit(out, "@1 >>>= @2;", smapper.getI(1), smapper.popI());
 343.664 +                    break;
 343.665                  case opc_lushr:
 343.666 -                    out.append("{ var v = s.pop(); s.push(s.pop() >>> v); }");
 343.667 +                    emit(out, "@1 >>>= @2;", smapper.getL(1), smapper.popI());
 343.668                      break;
 343.669                  case opc_iinc: {
 343.670 -                    final int varIndx = readByte(byteCodes, ++i);
 343.671 -                    final int incrBy = byteCodes[++i];
 343.672 +                    ++i;
 343.673 +                    final int varIndx = wide ? readUShort(byteCodes, i++)
 343.674 +                                             : readUByte(byteCodes, i);
 343.675 +                    ++i;
 343.676 +                    final int incrBy = wide ? readIntArg(byteCodes, i++)
 343.677 +                                            : byteCodes[i];
 343.678 +                    wide = false;
 343.679                      if (incrBy == 1) {
 343.680 -                        out.append("arg" + varIndx).append("++;");
 343.681 +                        emit(out, "@1++;", lmapper.getI(varIndx));
 343.682                      } else {
 343.683 -                        out.append("arg" + varIndx).append(" += " + incrBy).append(";");
 343.684 +                        emit(out, "@1 += @2;",
 343.685 +                             lmapper.getI(varIndx),
 343.686 +                             Integer.toString(incrBy));
 343.687                      }
 343.688                      break;
 343.689                  }
 343.690                  case opc_return:
 343.691 -                    out.append("return;");
 343.692 +                    emit(out, "return;");
 343.693                      break;
 343.694                  case opc_ireturn:
 343.695 +                    emit(out, "return @1;", smapper.popI());
 343.696 +                    break;
 343.697                  case opc_lreturn:
 343.698 +                    emit(out, "return @1;", smapper.popL());
 343.699 +                    break;
 343.700                  case opc_freturn:
 343.701 +                    emit(out, "return @1;", smapper.popF());
 343.702 +                    break;
 343.703                  case opc_dreturn:
 343.704 +                    emit(out, "return @1;", smapper.popD());
 343.705 +                    break;
 343.706                  case opc_areturn:
 343.707 -                    out.append("return s.pop();");
 343.708 +                    emit(out, "return @1;", smapper.popA());
 343.709                      break;
 343.710                  case opc_i2l:
 343.711 +                    emit(out, "var @2 = @1;", smapper.popI(), smapper.pushL());
 343.712 +                    break;
 343.713                  case opc_i2f:
 343.714 +                    emit(out, "var @2 = @1;", smapper.popI(), smapper.pushF());
 343.715 +                    break;
 343.716                  case opc_i2d:
 343.717 +                    emit(out, "var @2 = @1;", smapper.popI(), smapper.pushD());
 343.718 +                    break;
 343.719                  case opc_l2i:
 343.720 +                    emit(out, "var @2 = @1;", smapper.popL(), smapper.pushI());
 343.721 +                    break;
 343.722                      // max int check?
 343.723                  case opc_l2f:
 343.724 +                    emit(out, "var @2 = @1;", smapper.popL(), smapper.pushF());
 343.725 +                    break;
 343.726                  case opc_l2d:
 343.727 +                    emit(out, "var @2 = @1;", smapper.popL(), smapper.pushD());
 343.728 +                    break;
 343.729                  case opc_f2d:
 343.730 +                    emit(out, "var @2 = @1;", smapper.popF(), smapper.pushD());
 343.731 +                    break;
 343.732                  case opc_d2f:
 343.733 -                    out.append("/* number conversion */");
 343.734 +                    emit(out, "var @2 = @1;", smapper.popD(), smapper.pushF());
 343.735                      break;
 343.736                  case opc_f2i:
 343.737 +                    emit(out, "var @2 = Math.floor(@1);",
 343.738 +                         smapper.popF(), smapper.pushI());
 343.739 +                    break;
 343.740                  case opc_f2l:
 343.741 +                    emit(out, "var @2 = Math.floor(@1);",
 343.742 +                         smapper.popF(), smapper.pushL());
 343.743 +                    break;
 343.744                  case opc_d2i:
 343.745 +                    emit(out, "var @2 = Math.floor(@1);",
 343.746 +                         smapper.popD(), smapper.pushI());
 343.747 +                    break;
 343.748                  case opc_d2l:
 343.749 -                    out.append("s.push(Math.floor(s.pop()));");
 343.750 +                    emit(out, "var @2 = Math.floor(@1);",
 343.751 +                         smapper.popD(), smapper.pushL());
 343.752                      break;
 343.753                  case opc_i2b:
 343.754 +                    emit(out, "var @1 = @1.toInt8();", smapper.getI(0));
 343.755 +                    break;
 343.756                  case opc_i2c:
 343.757 +                    out.append("{ /* number conversion */ }");
 343.758 +                    break;
 343.759                  case opc_i2s:
 343.760 -                    out.append("/* number conversion */");
 343.761 +                    emit(out, "var @1 = @1.toInt16();", smapper.getI(0));
 343.762                      break;
 343.763                  case opc_aconst_null:
 343.764 -                    out.append("s.push(null);");
 343.765 +                    emit(out, "var @1 = null;", smapper.pushA());
 343.766                      break;
 343.767                  case opc_iconst_m1:
 343.768 -                    out.append("s.push(-1);");
 343.769 +                    emit(out, "var @1 = -1;", smapper.pushI());
 343.770                      break;
 343.771                  case opc_iconst_0:
 343.772 +                    emit(out, "var @1 = 0;", smapper.pushI());
 343.773 +                    break;
 343.774                  case opc_dconst_0:
 343.775 +                    emit(out, "var @1 = 0;", smapper.pushD());
 343.776 +                    break;
 343.777                  case opc_lconst_0:
 343.778 +                    emit(out, "var @1 = 0;", smapper.pushL());
 343.779 +                    break;
 343.780                  case opc_fconst_0:
 343.781 -                    out.append("s.push(0);");
 343.782 +                    emit(out, "var @1 = 0;", smapper.pushF());
 343.783                      break;
 343.784                  case opc_iconst_1:
 343.785 +                    emit(out, "var @1 = 1;", smapper.pushI());
 343.786 +                    break;
 343.787                  case opc_lconst_1:
 343.788 +                    emit(out, "var @1 = 1;", smapper.pushL());
 343.789 +                    break;
 343.790                  case opc_fconst_1:
 343.791 +                    emit(out, "var @1 = 1;", smapper.pushF());
 343.792 +                    break;
 343.793                  case opc_dconst_1:
 343.794 -                    out.append("s.push(1);");
 343.795 +                    emit(out, "var @1 = 1;", smapper.pushD());
 343.796                      break;
 343.797                  case opc_iconst_2:
 343.798 +                    emit(out, "var @1 = 2;", smapper.pushI());
 343.799 +                    break;
 343.800                  case opc_fconst_2:
 343.801 -                    out.append("s.push(2);");
 343.802 +                    emit(out, "var @1 = 2;", smapper.pushF());
 343.803                      break;
 343.804                  case opc_iconst_3:
 343.805 -                    out.append("s.push(3);");
 343.806 +                    emit(out, "var @1 = 3;", smapper.pushI());
 343.807                      break;
 343.808                  case opc_iconst_4:
 343.809 -                    out.append("s.push(4);");
 343.810 +                    emit(out, "var @1 = 4;", smapper.pushI());
 343.811                      break;
 343.812                  case opc_iconst_5:
 343.813 -                    out.append("s.push(5);");
 343.814 +                    emit(out, "var @1 = 5;", smapper.pushI());
 343.815                      break;
 343.816                  case opc_ldc: {
 343.817 -                    int indx = readByte(byteCodes, ++i);
 343.818 +                    int indx = readUByte(byteCodes, ++i);
 343.819                      String v = encodeConstant(indx);
 343.820 -                    out.append("s.push(").append(v).append(");");
 343.821 +                    int type = VarType.fromConstantType(jc.getTag(indx));
 343.822 +                    emit(out, "var @1 = @2;", smapper.pushT(type), v);
 343.823                      break;
 343.824                  }
 343.825                  case opc_ldc_w:
 343.826 @@ -486,101 +768,115 @@
 343.827                      int indx = readIntArg(byteCodes, i);
 343.828                      i += 2;
 343.829                      String v = encodeConstant(indx);
 343.830 -                    out.append("s.push(").append(v).append(");");
 343.831 +                    int type = VarType.fromConstantType(jc.getTag(indx));
 343.832 +                    emit(out, "var @1 = @2;", smapper.pushT(type), v);
 343.833                      break;
 343.834                  }
 343.835                  case opc_lcmp:
 343.836 +                    emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
 343.837 +                         smapper.popL(), smapper.popL(), smapper.pushI());
 343.838 +                    break;
 343.839                  case opc_fcmpl:
 343.840                  case opc_fcmpg:
 343.841 +                    emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
 343.842 +                         smapper.popF(), smapper.popF(), smapper.pushI());
 343.843 +                    break;
 343.844                  case opc_dcmpl:
 343.845 -                case opc_dcmpg: {
 343.846 -                    out.append("{ var delta = s.pop() - s.pop(); s.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); }");
 343.847 +                case opc_dcmpg:
 343.848 +                    emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
 343.849 +                         smapper.popD(), smapper.popD(), smapper.pushI());
 343.850                      break;
 343.851 -                }
 343.852                  case opc_if_acmpeq:
 343.853 -                    i = generateIf(byteCodes, i, "===");
 343.854 +                    i = generateIf(byteCodes, i, smapper.popA(), smapper.popA(),
 343.855 +                                   "===");
 343.856                      break;
 343.857                  case opc_if_acmpne:
 343.858 -                    i = generateIf(byteCodes, i, "!=");
 343.859 +                    i = generateIf(byteCodes, i, smapper.popA(), smapper.popA(),
 343.860 +                                   "!=");
 343.861                      break;
 343.862 -                case opc_if_icmpeq: {
 343.863 -                    i = generateIf(byteCodes, i, "==");
 343.864 +                case opc_if_icmpeq:
 343.865 +                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 343.866 +                                   "==");
 343.867                      break;
 343.868 -                }
 343.869                  case opc_ifeq: {
 343.870                      int indx = i + readIntArg(byteCodes, i);
 343.871 -                    out.append("if (s.pop() == 0) { gt = " + indx);
 343.872 -                    out.append("; continue; }");
 343.873 +                    emit(out, "if (@1 == 0) { gt = @2; continue; }",
 343.874 +                         smapper.popI(), Integer.toString(indx));
 343.875                      i += 2;
 343.876                      break;
 343.877                  }
 343.878                  case opc_ifne: {
 343.879                      int indx = i + readIntArg(byteCodes, i);
 343.880 -                    out.append("if (s.pop() != 0) { gt = " + indx);
 343.881 -                    out.append("; continue; }");
 343.882 +                    emit(out, "if (@1 != 0) { gt = @2; continue; }",
 343.883 +                         smapper.popI(), Integer.toString(indx));
 343.884                      i += 2;
 343.885                      break;
 343.886                  }
 343.887                  case opc_iflt: {
 343.888                      int indx = i + readIntArg(byteCodes, i);
 343.889 -                    out.append("if (s.pop() < 0) { gt = " + indx);
 343.890 -                    out.append("; continue; }");
 343.891 +                    emit(out, "if (@1 < 0) { gt = @2; continue; }",
 343.892 +                         smapper.popI(), Integer.toString(indx));
 343.893                      i += 2;
 343.894                      break;
 343.895                  }
 343.896                  case opc_ifle: {
 343.897                      int indx = i + readIntArg(byteCodes, i);
 343.898 -                    out.append("if (s.pop() <= 0) { gt = " + indx);
 343.899 -                    out.append("; continue; }");
 343.900 +                    emit(out, "if (@1 <= 0) { gt = @2; continue; }",
 343.901 +                         smapper.popI(), Integer.toString(indx));
 343.902                      i += 2;
 343.903                      break;
 343.904                  }
 343.905                  case opc_ifgt: {
 343.906                      int indx = i + readIntArg(byteCodes, i);
 343.907 -                    out.append("if (s.pop() > 0) { gt = " + indx);
 343.908 -                    out.append("; continue; }");
 343.909 +                    emit(out, "if (@1 > 0) { gt = @2; continue; }",
 343.910 +                         smapper.popI(), Integer.toString(indx));
 343.911                      i += 2;
 343.912                      break;
 343.913                  }
 343.914                  case opc_ifge: {
 343.915                      int indx = i + readIntArg(byteCodes, i);
 343.916 -                    out.append("if (s.pop() >= 0) { gt = " + indx);
 343.917 -                    out.append("; continue; }");
 343.918 +                    emit(out, "if (@1 >= 0) { gt = @2; continue; }",
 343.919 +                         smapper.popI(), Integer.toString(indx));
 343.920                      i += 2;
 343.921                      break;
 343.922                  }
 343.923                  case opc_ifnonnull: {
 343.924                      int indx = i + readIntArg(byteCodes, i);
 343.925 -                    out.append("if (s.pop() !== null) { gt = " + indx);
 343.926 -                    out.append("; continue; }");
 343.927 +                    emit(out, "if (@1 !== null) { gt = @2; continue; }",
 343.928 +                         smapper.popA(), Integer.toString(indx));
 343.929                      i += 2;
 343.930                      break;
 343.931                  }
 343.932                  case opc_ifnull: {
 343.933                      int indx = i + readIntArg(byteCodes, i);
 343.934 -                    out.append("if (s.pop() === null) { gt = " + indx);
 343.935 -                    out.append("; continue; }");
 343.936 +                    emit(out, "if (@1 === null) { gt = @2; continue; }",
 343.937 +                         smapper.popA(), Integer.toString(indx));
 343.938                      i += 2;
 343.939                      break;
 343.940                  }
 343.941                  case opc_if_icmpne:
 343.942 -                    i = generateIf(byteCodes, i, "!=");
 343.943 +                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 343.944 +                                   "!=");
 343.945                      break;
 343.946                  case opc_if_icmplt:
 343.947 -                    i = generateIf(byteCodes, i, ">");
 343.948 +                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 343.949 +                                   "<");
 343.950                      break;
 343.951                  case opc_if_icmple:
 343.952 -                    i = generateIf(byteCodes, i, ">=");
 343.953 +                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 343.954 +                                   "<=");
 343.955                      break;
 343.956                  case opc_if_icmpgt:
 343.957 -                    i = generateIf(byteCodes, i, "<");
 343.958 +                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 343.959 +                                   ">");
 343.960                      break;
 343.961                  case opc_if_icmpge:
 343.962 -                    i = generateIf(byteCodes, i, "<=");
 343.963 +                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 343.964 +                                   ">=");
 343.965                      break;
 343.966                  case opc_goto: {
 343.967                      int indx = i + readIntArg(byteCodes, i);
 343.968 -                    out.append("gt = " + indx).append("; continue;");
 343.969 +                    emit(out, "gt = @1; continue;", Integer.toString(indx));
 343.970                      i += 2;
 343.971                      break;
 343.972                  }
 343.973 @@ -590,7 +886,7 @@
 343.974                      table += 4;
 343.975                      int n = readInt4(byteCodes, table);
 343.976                      table += 4;
 343.977 -                    out.append("switch (s.pop()) {\n");
 343.978 +                    out.append("switch (").append(smapper.popI()).append(") {\n");
 343.979                      while (n-- > 0) {
 343.980                          int cnstnt = readInt4(byteCodes, table);
 343.981                          table += 4;
 343.982 @@ -610,7 +906,7 @@
 343.983                      table += 4;
 343.984                      int high = readInt4(byteCodes, table);
 343.985                      table += 4;
 343.986 -                    out.append("switch (s.pop()) {\n");
 343.987 +                    out.append("switch (").append(smapper.popI()).append(") {\n");
 343.988                      while (low <= high) {
 343.989                          int offset = i + readInt4(byteCodes, table);
 343.990                          table += 4;
 343.991 @@ -622,117 +918,323 @@
 343.992                      break;
 343.993                  }
 343.994                  case opc_invokeinterface: {
 343.995 -                    i = invokeVirtualMethod(byteCodes, i) + 2;
 343.996 +                    i = invokeVirtualMethod(byteCodes, i, smapper) + 2;
 343.997                      break;
 343.998                  }
 343.999                  case opc_invokevirtual:
343.1000 -                    i = invokeVirtualMethod(byteCodes, i);
343.1001 +                    i = invokeVirtualMethod(byteCodes, i, smapper);
343.1002                      break;
343.1003                  case opc_invokespecial:
343.1004 -                    i = invokeStaticMethod(byteCodes, i, false);
343.1005 +                    i = invokeStaticMethod(byteCodes, i, smapper, false);
343.1006                      break;
343.1007                  case opc_invokestatic:
343.1008 -                    i = invokeStaticMethod(byteCodes, i, true);
343.1009 +                    i = invokeStaticMethod(byteCodes, i, smapper, true);
343.1010                      break;
343.1011                  case opc_new: {
343.1012                      int indx = readIntArg(byteCodes, i);
343.1013                      String ci = jc.getClassName(indx);
343.1014 -                    out.append("s.push(new ");
343.1015 -                    out.append(ci.replace('/','_'));
343.1016 -                    out.append("());");
343.1017 +                    emit(out, "var @1 = new @2;",
343.1018 +                         smapper.pushA(), accessClass(ci.replace('/', '_')));
343.1019                      addReference(ci);
343.1020                      i += 2;
343.1021                      break;
343.1022                  }
343.1023 -                case opc_newarray: {
343.1024 -                    int type = byteCodes[i++];
343.1025 -                    out.append("s.push(new Array(s.pop()).fillNulls());");
343.1026 +                case opc_newarray:
343.1027 +                    int atype = readUByte(byteCodes, ++i);
343.1028 +                    String jvmType;
343.1029 +                    switch (atype) {
343.1030 +                        case 4: jvmType = "[Z"; break;
343.1031 +                        case 5: jvmType = "[C"; break;
343.1032 +                        case 6: jvmType = "[F"; break;
343.1033 +                        case 7: jvmType = "[D"; break;
343.1034 +                        case 8: jvmType = "[B"; break;
343.1035 +                        case 9: jvmType = "[S"; break;
343.1036 +                        case 10: jvmType = "[I"; break;
343.1037 +                        case 11: jvmType = "[J"; break;
343.1038 +                        default: throw new IllegalStateException("Array type: " + atype);
343.1039 +                    }
343.1040 +                    emit(out, "var @2 = Array.prototype.newArray__Ljava_lang_Object_2ZLjava_lang_String_2I(true, '@3', @1);",
343.1041 +                         smapper.popI(), smapper.pushA(), jvmType);
343.1042                      break;
343.1043 -                }
343.1044                  case opc_anewarray: {
343.1045 -                    i += 2; // skip type of array
343.1046 -                    out.append("s.push(new Array(s.pop()).fillNulls());");
343.1047 +                    int type = readIntArg(byteCodes, i);
343.1048 +                    i += 2;
343.1049 +                    String typeName = jc.getClassName(type);
343.1050 +                    if (typeName.startsWith("[")) {
343.1051 +                        typeName = "[" + typeName;
343.1052 +                    } else {
343.1053 +                        typeName = "[L" + typeName + ";";
343.1054 +                    }
343.1055 +                    emit(out, "var @2 = Array.prototype.newArray__Ljava_lang_Object_2ZLjava_lang_String_2I(false, '@3', @1);",
343.1056 +                         smapper.popI(), smapper.pushA(), typeName);
343.1057                      break;
343.1058                  }
343.1059                  case opc_multianewarray: {
343.1060 +                    int type = readIntArg(byteCodes, i);
343.1061                      i += 2;
343.1062 -                    int dim = readByte(byteCodes, ++i);
343.1063 -                    out.append("{ var a0 = new Array(s.pop()).fillNulls();");
343.1064 -                    for (int d = 1; d < dim; d++) {
343.1065 -                        out.append("\n  var l" + d).append(" = s.pop();");
343.1066 -                        out.append("\n  for (var i" + d).append (" = 0; i" + d).
343.1067 -                            append(" < a" + (d - 1)).
343.1068 -                            append(".length; i" + d).append("++) {");
343.1069 -                        out.append("\n    var a" + d).
343.1070 -                            append (" = new Array(l" + d).append(").fillNulls();");
343.1071 -                        out.append("\n    a" + (d - 1)).append("[i" + d).append("] = a" + d).
343.1072 -                            append(";");
343.1073 +                    String typeName = jc.getClassName(type);
343.1074 +                    int dim = readUByte(byteCodes, ++i);
343.1075 +                    StringBuilder dims = new StringBuilder();
343.1076 +                    dims.append('[');
343.1077 +                    for (int d = 0; d < dim; d++) {
343.1078 +                        if (d != 0) {
343.1079 +                            dims.append(",");
343.1080 +                        }
343.1081 +                        dims.append(smapper.popI());
343.1082                      }
343.1083 -                    for (int d = 1; d < dim; d++) {
343.1084 -                        out.append("\n  }");
343.1085 -                    }
343.1086 -                    out.append("\ns.push(a0); }");
343.1087 +                    dims.append(']');
343.1088 +                    emit(out, "var @2 = Array.prototype.multiNewArray__Ljava_lang_Object_2Ljava_lang_String_2_3II('@3', @1, 0);",
343.1089 +                         dims.toString(), smapper.pushA(), typeName);
343.1090                      break;
343.1091                  }
343.1092                  case opc_arraylength:
343.1093 -                    out.append("s.push(s.pop().length);");
343.1094 +                    emit(out, "var @2 = @1.length;",
343.1095 +                         smapper.popA(), smapper.pushI());
343.1096 +                    break;
343.1097 +                case opc_lastore:
343.1098 +                    emit(out, "@3.at(@2, @1);",
343.1099 +                         smapper.popL(), smapper.popI(), smapper.popA());
343.1100 +                    break;
343.1101 +                case opc_fastore:
343.1102 +                    emit(out, "@3.at(@2, @1);",
343.1103 +                         smapper.popF(), smapper.popI(), smapper.popA());
343.1104 +                    break;
343.1105 +                case opc_dastore:
343.1106 +                    emit(out, "@3.at(@2, @1);",
343.1107 +                         smapper.popD(), smapper.popI(), smapper.popA());
343.1108 +                    break;
343.1109 +                case opc_aastore:
343.1110 +                    emit(out, "@3.at(@2, @1);",
343.1111 +                         smapper.popA(), smapper.popI(), smapper.popA());
343.1112                      break;
343.1113                  case opc_iastore:
343.1114 -                case opc_lastore:
343.1115 -                case opc_fastore:
343.1116 -                case opc_dastore:
343.1117 -                case opc_aastore:
343.1118                  case opc_bastore:
343.1119                  case opc_castore:
343.1120 -                case opc_sastore: {
343.1121 -                    out.append("{ var value = s.pop(); var indx = s.pop(); s.pop()[indx] = value; }");
343.1122 +                case opc_sastore:
343.1123 +                    emit(out, "@3.at(@2, @1);",
343.1124 +                         smapper.popI(), smapper.popI(), smapper.popA());
343.1125 +                    break;
343.1126 +                case opc_laload:
343.1127 +                    emit(out, "var @3 = @2.at(@1);",
343.1128 +                         smapper.popI(), smapper.popA(), smapper.pushL());
343.1129 +                    break;
343.1130 +                case opc_faload:
343.1131 +                    emit(out, "var @3 = @2.at(@1);",
343.1132 +                         smapper.popI(), smapper.popA(), smapper.pushF());
343.1133 +                    break;
343.1134 +                case opc_daload:
343.1135 +                    emit(out, "var @3 = @2.at(@1);",
343.1136 +                         smapper.popI(), smapper.popA(), smapper.pushD());
343.1137 +                    break;
343.1138 +                case opc_aaload:
343.1139 +                    emit(out, "var @3 = @2.at(@1);",
343.1140 +                         smapper.popI(), smapper.popA(), smapper.pushA());
343.1141 +                    break;
343.1142 +                case opc_iaload:
343.1143 +                case opc_baload:
343.1144 +                case opc_caload:
343.1145 +                case opc_saload:
343.1146 +                    emit(out, "var @3 = @2.at(@1);",
343.1147 +                         smapper.popI(), smapper.popA(), smapper.pushI());
343.1148 +                    break;
343.1149 +                case opc_pop:
343.1150 +                case opc_pop2:
343.1151 +                    smapper.pop(1);
343.1152 +                    debug("/* pop */");
343.1153 +                    break;
343.1154 +                case opc_dup: {
343.1155 +                    final Variable v = smapper.get(0);
343.1156 +                    emit(out, "var @1 = @2;", smapper.pushT(v.getType()), v);
343.1157                      break;
343.1158                  }
343.1159 -                case opc_iaload:
343.1160 -                case opc_laload:
343.1161 -                case opc_faload:
343.1162 -                case opc_daload:
343.1163 -                case opc_aaload:
343.1164 -                case opc_baload:
343.1165 -                case opc_caload:
343.1166 -                case opc_saload: {
343.1167 -                    out.append("{ var indx = s.pop(); s.push(s.pop()[indx]); }");
343.1168 +                case opc_dup2: {
343.1169 +                    final Variable vi1 = smapper.get(0);
343.1170 +
343.1171 +                    if (vi1.isCategory2()) {
343.1172 +                        emit(out, "var @1 = @2;",
343.1173 +                             smapper.pushT(vi1.getType()), vi1);
343.1174 +                    } else {
343.1175 +                        final Variable vi2 = smapper.get(1);
343.1176 +                        emit(out, "var @1 = @2, @3 = @4;",
343.1177 +                             smapper.pushT(vi2.getType()), vi2,
343.1178 +                             smapper.pushT(vi1.getType()), vi1);
343.1179 +                    }
343.1180                      break;
343.1181                  }
343.1182 -                case opc_pop2:
343.1183 -                    out.append("s.pop();");
343.1184 -                case opc_pop:
343.1185 -                    out.append("s.pop();");
343.1186 +                case opc_dup_x1: {
343.1187 +                    final Variable vi1 = smapper.pop();
343.1188 +                    final Variable vi2 = smapper.pop();
343.1189 +                    final Variable vo3 = smapper.pushT(vi1.getType());
343.1190 +                    final Variable vo2 = smapper.pushT(vi2.getType());
343.1191 +                    final Variable vo1 = smapper.pushT(vi1.getType());
343.1192 +
343.1193 +                    emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
343.1194 +                         vo1, vi1, vo2, vi2, vo3, vo1);
343.1195                      break;
343.1196 -                case opc_dup:
343.1197 -                    out.append("s.push(s[s.length - 1]);");
343.1198 +                }
343.1199 +                case opc_dup2_x1: {
343.1200 +                    final Variable vi1 = smapper.pop();
343.1201 +                    final Variable vi2 = smapper.pop();
343.1202 +
343.1203 +                    if (vi1.isCategory2()) {
343.1204 +                        final Variable vo3 = smapper.pushT(vi1.getType());
343.1205 +                        final Variable vo2 = smapper.pushT(vi2.getType());
343.1206 +                        final Variable vo1 = smapper.pushT(vi1.getType());
343.1207 +
343.1208 +                        emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
343.1209 +                             vo1, vi1, vo2, vi2, vo3, vo1);
343.1210 +                    } else {
343.1211 +                        final Variable vi3 = smapper.pop();
343.1212 +                        final Variable vo5 = smapper.pushT(vi2.getType());
343.1213 +                        final Variable vo4 = smapper.pushT(vi1.getType());
343.1214 +                        final Variable vo3 = smapper.pushT(vi3.getType());
343.1215 +                        final Variable vo2 = smapper.pushT(vi2.getType());
343.1216 +                        final Variable vo1 = smapper.pushT(vi1.getType());
343.1217 +
343.1218 +                        emit(out, "var @1 = @2, @3 = @4, @5 = @6,",
343.1219 +                             vo1, vi1, vo2, vi2, vo3, vi3);
343.1220 +                        emit(out, " @1 = @2, @3 = @4;",
343.1221 +                             vo4, vo1, vo5, vo2);
343.1222 +                    }
343.1223                      break;
343.1224 -                case opc_dup_x1:
343.1225 -                    out.append("{ var v1 = s.pop(); var v2 = s.pop(); s.push(v1); s.push(v2); s.push(v1); }");
343.1226 +                }
343.1227 +                case opc_dup_x2: {
343.1228 +                    final Variable vi1 = smapper.pop();
343.1229 +                    final Variable vi2 = smapper.pop();
343.1230 +
343.1231 +                    if (vi2.isCategory2()) {
343.1232 +                        final Variable vo3 = smapper.pushT(vi1.getType());
343.1233 +                        final Variable vo2 = smapper.pushT(vi2.getType());
343.1234 +                        final Variable vo1 = smapper.pushT(vi1.getType());
343.1235 +
343.1236 +                        emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
343.1237 +                             vo1, vi1, vo2, vi2, vo3, vo1);
343.1238 +                    } else {
343.1239 +                        final Variable vi3 = smapper.pop();
343.1240 +                        final Variable vo4 = smapper.pushT(vi1.getType());
343.1241 +                        final Variable vo3 = smapper.pushT(vi3.getType());
343.1242 +                        final Variable vo2 = smapper.pushT(vi2.getType());
343.1243 +                        final Variable vo1 = smapper.pushT(vi1.getType());
343.1244 +
343.1245 +                        emit(out, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8;",
343.1246 +                             vo1, vi1, vo2, vi2, vo3, vi3, vo4, vo1);
343.1247 +                    }
343.1248                      break;
343.1249 -                case opc_dup_x2:
343.1250 -                    out.append("{ var v1 = s.pop(); var v2 = s.pop(); var v3 = s.pop(); s.push(v1); s.push(v3); s.push(v2); s.push(v1); }");
343.1251 +                }
343.1252 +                case opc_dup2_x2: {
343.1253 +                    final Variable vi1 = smapper.pop();
343.1254 +                    final Variable vi2 = smapper.pop();
343.1255 +
343.1256 +                    if (vi1.isCategory2()) {
343.1257 +                        if (vi2.isCategory2()) {
343.1258 +                            final Variable vo3 = smapper.pushT(vi1.getType());
343.1259 +                            final Variable vo2 = smapper.pushT(vi2.getType());
343.1260 +                            final Variable vo1 = smapper.pushT(vi1.getType());
343.1261 +
343.1262 +                            emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
343.1263 +                                 vo1, vi1, vo2, vi2, vo3, vo1);
343.1264 +                        } else {
343.1265 +                            final Variable vi3 = smapper.pop();
343.1266 +                            final Variable vo4 = smapper.pushT(vi1.getType());
343.1267 +                            final Variable vo3 = smapper.pushT(vi3.getType());
343.1268 +                            final Variable vo2 = smapper.pushT(vi2.getType());
343.1269 +                            final Variable vo1 = smapper.pushT(vi1.getType());
343.1270 +
343.1271 +                            emit(out, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8;",
343.1272 +                                 vo1, vi1, vo2, vi2, vo3, vi3, vo4, vo1);
343.1273 +                        }
343.1274 +                    } else {
343.1275 +                        final Variable vi3 = smapper.pop();
343.1276 +
343.1277 +                        if (vi3.isCategory2()) {
343.1278 +                            final Variable vo5 = smapper.pushT(vi2.getType());
343.1279 +                            final Variable vo4 = smapper.pushT(vi1.getType());
343.1280 +                            final Variable vo3 = smapper.pushT(vi3.getType());
343.1281 +                            final Variable vo2 = smapper.pushT(vi2.getType());
343.1282 +                            final Variable vo1 = smapper.pushT(vi1.getType());
343.1283 +
343.1284 +                            emit(out, "var @1 = @2, @3 = @4, @5 = @6,",
343.1285 +                                 vo1, vi1, vo2, vi2, vo3, vi3);
343.1286 +                            emit(out, " @1 = @2, @3 = @4;",
343.1287 +                                 vo4, vo1, vo5, vo2);
343.1288 +                        } else {
343.1289 +                            final Variable vi4 = smapper.pop();
343.1290 +                            final Variable vo6 = smapper.pushT(vi2.getType());
343.1291 +                            final Variable vo5 = smapper.pushT(vi1.getType());
343.1292 +                            final Variable vo4 = smapper.pushT(vi4.getType());
343.1293 +                            final Variable vo3 = smapper.pushT(vi3.getType());
343.1294 +                            final Variable vo2 = smapper.pushT(vi2.getType());
343.1295 +                            final Variable vo1 = smapper.pushT(vi1.getType());
343.1296 +                            
343.1297 +                            emit(out, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8,",
343.1298 +                                 vo1, vi1, vo2, vi2, vo3, vi3, vo4, vi4);
343.1299 +                            emit(out, " @1 = @2, @3 = @4;",
343.1300 +                                 vo5, vo1, vo6, vo2);
343.1301 +                        }
343.1302 +                    }
343.1303                      break;
343.1304 +                }
343.1305 +                case opc_swap: {
343.1306 +                    final Variable vi1 = smapper.get(0);
343.1307 +                    final Variable vi2 = smapper.get(1);
343.1308 +
343.1309 +                    if (vi1.getType() == vi2.getType()) {
343.1310 +                        final Variable tmp = smapper.pushT(vi1.getType());
343.1311 +
343.1312 +                        emit(out, "var @1 = @2, @2 = @3, @3 = @1;",
343.1313 +                             tmp, vi1, vi2);
343.1314 +                        smapper.pop(1);
343.1315 +                    } else {
343.1316 +                        smapper.pop(2);
343.1317 +                        smapper.pushT(vi1.getType());
343.1318 +                        smapper.pushT(vi2.getType());
343.1319 +                    }
343.1320 +                    break;
343.1321 +                }
343.1322                  case opc_bipush:
343.1323 -                    out.append("s.push(" + byteCodes[++i] + ");");
343.1324 +                    emit(out, "var @1 = @2;",
343.1325 +                         smapper.pushI(), Integer.toString(byteCodes[++i]));
343.1326                      break;
343.1327                  case opc_sipush:
343.1328 -                    out.append("s.push(" + readIntArg(byteCodes, i) + ");");
343.1329 +                    emit(out, "var @1 = @2;",
343.1330 +                         smapper.pushI(),
343.1331 +                         Integer.toString(readIntArg(byteCodes, i)));
343.1332                      i += 2;
343.1333                      break;
343.1334                  case opc_getfield: {
343.1335                      int indx = readIntArg(byteCodes, i);
343.1336                      String[] fi = jc.getFieldInfoName(indx);
343.1337 -                    out.append("s.push(s.pop().fld_").
343.1338 -                        append(fi[1]).append(");");
343.1339 +                    final int type = VarType.fromFieldType(fi[2].charAt(0));
343.1340 +                    final String mangleClass = mangleSig(fi[0]);
343.1341 +                    final String mangleClassAccess = accessClass(mangleClass);
343.1342 +                    emit(out, "var @2 = @4(false)._@3.call(@1);",
343.1343 +                         smapper.popA(),
343.1344 +                         smapper.pushT(type), fi[1], mangleClassAccess
343.1345 +                    );
343.1346 +                    i += 2;
343.1347 +                    break;
343.1348 +                }
343.1349 +                case opc_putfield: {
343.1350 +                    int indx = readIntArg(byteCodes, i);
343.1351 +                    String[] fi = jc.getFieldInfoName(indx);
343.1352 +                    final int type = VarType.fromFieldType(fi[2].charAt(0));
343.1353 +                    final String mangleClass = mangleSig(fi[0]);
343.1354 +                    final String mangleClassAccess = accessClass(mangleClass);
343.1355 +                    emit(out, "@4(false)._@3.call(@2, @1);",
343.1356 +                         smapper.popT(type),
343.1357 +                         smapper.popA(), fi[1], 
343.1358 +                         mangleClassAccess
343.1359 +                    );
343.1360                      i += 2;
343.1361                      break;
343.1362                  }
343.1363                  case opc_getstatic: {
343.1364                      int indx = readIntArg(byteCodes, i);
343.1365                      String[] fi = jc.getFieldInfoName(indx);
343.1366 -                    out.append("s.push(").append(fi[0].replace('/', '_'));
343.1367 -                    out.append('.').append(fi[1]).append(");");
343.1368 +                    final int type = VarType.fromFieldType(fi[2].charAt(0));
343.1369 +                    emit(out, "var @1 = @2(false).constructor.@3;",
343.1370 +                         smapper.pushT(type),
343.1371 +                         accessClass(fi[0].replace('/', '_')), fi[1]);
343.1372                      i += 2;
343.1373                      addReference(fi[0]);
343.1374                      break;
343.1375 @@ -740,28 +1242,25 @@
343.1376                  case opc_putstatic: {
343.1377                      int indx = readIntArg(byteCodes, i);
343.1378                      String[] fi = jc.getFieldInfoName(indx);
343.1379 -                    out.append(fi[0].replace('/', '_'));
343.1380 -                    out.append('.').append(fi[1]).append(" = s.pop();");
343.1381 +                    final int type = VarType.fromFieldType(fi[2].charAt(0));
343.1382 +                    emit(out, "@1(false).constructor.@2 = @3;",
343.1383 +                         accessClass(fi[0].replace('/', '_')), fi[1],
343.1384 +                         smapper.popT(type));
343.1385                      i += 2;
343.1386                      addReference(fi[0]);
343.1387                      break;
343.1388                  }
343.1389 -                case opc_putfield: {
343.1390 -                    int indx = readIntArg(byteCodes, i);
343.1391 -                    String[] fi = jc.getFieldInfoName(indx);
343.1392 -                    out.append("{ var v = s.pop(); s.pop().fld_")
343.1393 -                       .append(fi[1]).append(" = v; }");
343.1394 -                    i += 2;
343.1395 -                    break;
343.1396 -                }
343.1397                  case opc_checkcast: {
343.1398                      int indx = readIntArg(byteCodes, i);
343.1399                      final String type = jc.getClassName(indx);
343.1400                      if (!type.startsWith("[")) {
343.1401 -                        // no way to check arrays right now
343.1402 -                        out.append("if(s[s.length - 1].$instOf_")
343.1403 -                           .append(type.replace('/', '_'))
343.1404 -                           .append(" != 1) throw {};"); // XXX proper exception
343.1405 +                        emit(out,
343.1406 +                             "if (@1 !== null && !@1.$instOf_@2) throw {};",
343.1407 +                             smapper.getA(0), type.replace('/', '_'));
343.1408 +                    } else {
343.1409 +                        emit(out, "vm.java_lang_Class(false).forName__Ljava_lang_Class_2Ljava_lang_String_2('@2').cast__Ljava_lang_Object_2Ljava_lang_Object_2(@1);",
343.1410 +                             smapper.getA(0), type
343.1411 +                        );
343.1412                      }
343.1413                      i += 2;
343.1414                      break;
343.1415 @@ -769,36 +1268,74 @@
343.1416                  case opc_instanceof: {
343.1417                      int indx = readIntArg(byteCodes, i);
343.1418                      final String type = jc.getClassName(indx);
343.1419 -                    out.append("s.push(s.pop().$instOf_")
343.1420 -                       .append(type.replace('/', '_'))
343.1421 -                       .append(" ? 1 : 0);");
343.1422 +                    if (!type.startsWith("[")) {
343.1423 +                        emit(out, "var @2 = @1.$instOf_@3 ? 1 : 0;",
343.1424 +                             smapper.popA(), smapper.pushI(),
343.1425 +                             type.replace('/', '_'));
343.1426 +                    } else {
343.1427 +                        emit(out, "var @2 = vm.java_lang_Class(false).forName__Ljava_lang_Class_2Ljava_lang_String_2('@3').isInstance__ZLjava_lang_Object_2(@1);",
343.1428 +                            smapper.popA(), smapper.pushI(),
343.1429 +                            type
343.1430 +                        );
343.1431 +                    }
343.1432                      i += 2;
343.1433                      break;
343.1434                  }
343.1435                  case opc_athrow: {
343.1436 -                    out.append("{ var t = s.pop(); s = new Array(1); s[0] = t; throw t; }");
343.1437 +                    final Variable v = smapper.popA();
343.1438 +                    smapper.clear();
343.1439 +
343.1440 +                    emit(out, "{ var @1 = @2; throw @2; }",
343.1441 +                         smapper.pushA(), v);
343.1442                      break;
343.1443                  }
343.1444 +
343.1445 +                case opc_monitorenter: {
343.1446 +                    out.append("/* monitor enter */");
343.1447 +                    smapper.popA();
343.1448 +                    break;
343.1449 +                }
343.1450 +
343.1451 +                case opc_monitorexit: {
343.1452 +                    out.append("/* monitor exit */");
343.1453 +                    smapper.popA();
343.1454 +                    break;
343.1455 +                }
343.1456 +
343.1457 +                case opc_wide:
343.1458 +                    wide = true;
343.1459 +                    break;
343.1460 +
343.1461                  default: {
343.1462 -                    out.append("throw 'unknown bytecode " + c + "';");
343.1463 +                    wide = false;
343.1464 +                    emit(out, "throw 'unknown bytecode @1';",
343.1465 +                         Integer.toString(c));
343.1466                  }
343.1467 -                    
343.1468              }
343.1469 -            out.append(" //");
343.1470 -            for (int j = prev; j <= i; j++) {
343.1471 -                out.append(" ");
343.1472 -                final int cc = readByte(byteCodes, j);
343.1473 -                out.append(Integer.toString(cc));
343.1474 +            if (debug(" //")) {
343.1475 +                for (int j = prev; j <= i; j++) {
343.1476 +                    out.append(" ");
343.1477 +                    final int cc = readUByte(byteCodes, j);
343.1478 +                    out.append(Integer.toString(cc));
343.1479 +                }
343.1480              }
343.1481 -            out.append("\n");
343.1482 +            out.append("\n");            
343.1483 +        }
343.1484 +        if (previousTrap != null) {
343.1485 +            generateCatch(previousTrap);
343.1486          }
343.1487          out.append("  }\n");
343.1488 +        out.append("};");
343.1489      }
343.1490  
343.1491 -    private int generateIf(byte[] byteCodes, int i, final String test) throws IOException {
343.1492 +    private int generateIf(byte[] byteCodes, int i,
343.1493 +                           final Variable v2, final Variable v1,
343.1494 +                           final String test) throws IOException {
343.1495          int indx = i + readIntArg(byteCodes, i);
343.1496 -        out.append("if (s.pop() ").append(test).append(" s.pop()) { gt = " + indx);
343.1497 -        out.append("; continue; }");
343.1498 +        out.append("if (").append(v1)
343.1499 +           .append(' ').append(test).append(' ')
343.1500 +           .append(v2).append(") { gt = " + indx)
343.1501 +           .append("; continue; }");
343.1502          return i + 2;
343.1503      }
343.1504  
343.1505 @@ -814,11 +1351,16 @@
343.1506          final int a = byteCodes[offsetInstruction + 3];
343.1507          return (d & 0xff000000) | (c & 0xff0000) | (b & 0xff00) | (a & 0xff);
343.1508      }
343.1509 -    private int readByte(byte[] byteCodes, int offsetInstruction) {
343.1510 -        return (byteCodes[offsetInstruction] + 256) % 256;
343.1511 +    private int readUByte(byte[] byteCodes, int offsetInstruction) {
343.1512 +        return byteCodes[offsetInstruction] & 0xff;
343.1513      }
343.1514 -    
343.1515 -    private static void countArgs(String descriptor, boolean[] hasReturnType, StringBuilder sig, StringBuilder cnt) {
343.1516 +
343.1517 +    private int readUShort(byte[] byteCodes, int offsetInstruction) {
343.1518 +        return ((byteCodes[offsetInstruction] & 0xff) << 8)
343.1519 +                    | (byteCodes[offsetInstruction + 1] & 0xff);
343.1520 +    }
343.1521 +
343.1522 +    private static void countArgs(String descriptor, char[] returnType, StringBuilder sig, StringBuilder cnt) {
343.1523          int i = 0;
343.1524          Boolean count = null;
343.1525          boolean array = false;
343.1526 @@ -852,17 +1394,19 @@
343.1527                              cnt.append('0');
343.1528                          }
343.1529                      } else {
343.1530 -                        hasReturnType[0] = true;
343.1531                          sig.insert(firstPos, ch);
343.1532                          if (array) {
343.1533 +                            returnType[0] = '[';
343.1534                              sig.insert(firstPos, "_3");
343.1535 +                        } else {
343.1536 +                            returnType[0] = ch;
343.1537                          }
343.1538                      }
343.1539                      array = false;
343.1540                      continue;
343.1541                  case 'V': 
343.1542                      assert !count;
343.1543 -                    hasReturnType[0] = false;
343.1544 +                    returnType[0] = 'V';
343.1545                      sig.insert(firstPos, 'V');
343.1546                      continue;
343.1547                  case 'L':
343.1548 @@ -879,9 +1423,10 @@
343.1549                          if (array) {
343.1550                              sig.insert(firstPos, "_3");
343.1551                          }
343.1552 -                        hasReturnType[0] = true;
343.1553 +                        returnType[0] = 'L';
343.1554                      }
343.1555                      i = next + 1;
343.1556 +                    array = false;
343.1557                      continue;
343.1558                  case '[':
343.1559                      array = true;
343.1560 @@ -892,6 +1437,10 @@
343.1561          }
343.1562      }
343.1563      
343.1564 +    static String mangleSig(String sig) {
343.1565 +        return mangleSig(sig, 0, sig.length());
343.1566 +    }
343.1567 +    
343.1568      private static String mangleSig(String txt, int first, int last) {
343.1569          StringBuilder sb = new StringBuilder();
343.1570          for (int i = first; i < last; i++) {
343.1571 @@ -917,12 +1466,11 @@
343.1572              name.append(m.getName());
343.1573          } 
343.1574          
343.1575 -        boolean hasReturn[] = { false };
343.1576 -        countArgs(m.getInternalSig(), hasReturn, name, cnt);
343.1577 +        countArgs(m.getInternalSig(), new char[1], name, cnt);
343.1578          return name.toString();
343.1579      }
343.1580  
343.1581 -    static String findMethodName(String[] mi, StringBuilder cnt, boolean[] hasReturn) {
343.1582 +    static String findMethodName(String[] mi, StringBuilder cnt, char[] returnType) {
343.1583          StringBuilder name = new StringBuilder();
343.1584          String descr = mi[2];//mi.getDescriptor();
343.1585          String nm= mi[1];
343.1586 @@ -931,84 +1479,93 @@
343.1587          } else {
343.1588              name.append(nm);
343.1589          }
343.1590 -        countArgs(descr, hasReturn, name, cnt);
343.1591 +        countArgs(descr, returnType, name, cnt);
343.1592          return name.toString();
343.1593      }
343.1594  
343.1595 -    private int invokeStaticMethod(byte[] byteCodes, int i, boolean isStatic)
343.1596 +    private int invokeStaticMethod(byte[] byteCodes, int i, final StackMapper mapper, boolean isStatic)
343.1597      throws IOException {
343.1598          int methodIndex = readIntArg(byteCodes, i);
343.1599          String[] mi = jc.getFieldInfoName(methodIndex);
343.1600 -        boolean[] hasReturn = { false };
343.1601 +        char[] returnType = { 'V' };
343.1602          StringBuilder cnt = new StringBuilder();
343.1603 -        String mn = findMethodName(mi, cnt, hasReturn);
343.1604 -        out.append("{ ");
343.1605 -        for (int j = cnt.length() - 1; j >= 0; j--) {
343.1606 -            out.append("var v" + j).append(" = s.pop(); ");
343.1607 +        String mn = findMethodName(mi, cnt, returnType);
343.1608 +
343.1609 +        final int numArguments = isStatic ? cnt.length() : cnt.length() + 1;
343.1610 +        final Variable[] vars = new Variable[numArguments];
343.1611 +
343.1612 +        for (int j = numArguments - 1; j >= 0; --j) {
343.1613 +            vars[j] = mapper.pop();
343.1614          }
343.1615 -        
343.1616 -        if (hasReturn[0]) {
343.1617 -            out.append("s.push(");
343.1618 +
343.1619 +        if (returnType[0] != 'V') {
343.1620 +            out.append("var ")
343.1621 +               .append(mapper.pushT(VarType.fromFieldType(returnType[0])))
343.1622 +               .append(" = ");
343.1623          }
343.1624 +
343.1625          final String in = mi[0];
343.1626 -        out.append(in.replace('/', '_'));
343.1627 +        out.append(accessClass(in.replace('/', '_')));
343.1628          out.append("(false).");
343.1629 +        if (mn.startsWith("cons_")) {
343.1630 +            out.append("constructor.");
343.1631 +        }
343.1632          out.append(mn);
343.1633 -        out.append('(');
343.1634 -        String sep = "";
343.1635 -        if (!isStatic) {
343.1636 -            out.append("s.pop()");
343.1637 -            sep = ", ";
343.1638 +        if (isStatic) {
343.1639 +            out.append('(');
343.1640 +        } else {
343.1641 +            out.append(".call(");
343.1642          }
343.1643 -        for (int j = 0; j < cnt.length(); j++) {
343.1644 -            out.append(sep);
343.1645 -            out.append("v" + j);
343.1646 -            sep = ", ";
343.1647 +        if (numArguments > 0) {
343.1648 +            out.append(vars[0]);
343.1649 +            for (int j = 1; j < numArguments; ++j) {
343.1650 +                out.append(", ");
343.1651 +                out.append(vars[j]);
343.1652 +            }
343.1653          }
343.1654 -        out.append(")");
343.1655 -        if (hasReturn[0]) {
343.1656 -            out.append(")");
343.1657 -        }
343.1658 -        out.append("; }");
343.1659 +        out.append(");");
343.1660          i += 2;
343.1661          addReference(in);
343.1662          return i;
343.1663      }
343.1664 -    private int invokeVirtualMethod(byte[] byteCodes, int i)
343.1665 +    private int invokeVirtualMethod(byte[] byteCodes, int i, final StackMapper mapper)
343.1666      throws IOException {
343.1667          int methodIndex = readIntArg(byteCodes, i);
343.1668          String[] mi = jc.getFieldInfoName(methodIndex);
343.1669 -        boolean[] hasReturn = { false };
343.1670 +        char[] returnType = { 'V' };
343.1671          StringBuilder cnt = new StringBuilder();
343.1672 -        String mn = findMethodName(mi, cnt, hasReturn);
343.1673 -        out.append("{ ");
343.1674 -        for (int j = cnt.length() - 1; j >= 0; j--) {
343.1675 -            out.append("var v" + j).append(" = s.pop(); ");
343.1676 +        String mn = findMethodName(mi, cnt, returnType);
343.1677 +
343.1678 +        final int numArguments = cnt.length() + 1;
343.1679 +        final Variable[] vars = new Variable[numArguments];
343.1680 +
343.1681 +        for (int j = numArguments - 1; j >= 0; --j) {
343.1682 +            vars[j] = mapper.pop();
343.1683          }
343.1684 -        out.append("var self = s.pop(); ");
343.1685 -        if (hasReturn[0]) {
343.1686 -            out.append("s.push(");
343.1687 +
343.1688 +        if (returnType[0] != 'V') {
343.1689 +            out.append("var ")
343.1690 +               .append(mapper.pushT(VarType.fromFieldType(returnType[0])))
343.1691 +               .append(" = ");
343.1692          }
343.1693 -        out.append("self.");
343.1694 +
343.1695 +        out.append(vars[0]).append('.');
343.1696          out.append(mn);
343.1697          out.append('(');
343.1698 -        out.append("self");
343.1699 -        for (int j = 0; j < cnt.length(); j++) {
343.1700 -            out.append(", ");
343.1701 -            out.append("v" + j);
343.1702 +        String sep = "";
343.1703 +        for (int j = 1; j < numArguments; ++j) {
343.1704 +            out.append(sep);
343.1705 +            out.append(vars[j]);
343.1706 +            sep = ", ";
343.1707          }
343.1708 -        out.append(")");
343.1709 -        if (hasReturn[0]) {
343.1710 -            out.append(")");
343.1711 -        }
343.1712 -        out.append("; }");
343.1713 +        out.append(");");
343.1714          i += 2;
343.1715          return i;
343.1716      }
343.1717 -    
343.1718 +
343.1719      private void addReference(String cn) throws IOException {
343.1720          if (requireReference(cn)) {
343.1721 -            out.append(" /* needs ").append(cn).append(" */");
343.1722 +            debug(" /* needs " + cn + " */");
343.1723          }
343.1724      }
343.1725  
343.1726 @@ -1030,7 +1587,12 @@
343.1727          String[] classRef = { null };
343.1728          String s = jc.stringValue(entryIndex, classRef);
343.1729          if (classRef[0] != null) {
343.1730 -            addReference(classRef[0]);
343.1731 +            if (classRef[0].startsWith("[")) {
343.1732 +                s = accessClass("java_lang_Class") + "(false).forName__Ljava_lang_Class_2Ljava_lang_String_2('" + classRef[0] + "');";
343.1733 +            } else {
343.1734 +                addReference(classRef[0]);
343.1735 +                s = accessClass(s.replace('/', '_')) + "(false).constructor.$class";
343.1736 +            }
343.1737          }
343.1738          return s;
343.1739      }
343.1740 @@ -1072,21 +1634,12 @@
343.1741          final String mn = findMethodName(m, cnt);
343.1742          out.append(prefix).append(mn);
343.1743          out.append(" = function(");
343.1744 -        String space;
343.1745 -        int index;
343.1746 -        if (!isStatic) {                
343.1747 -            out.append(p.args[0]);
343.1748 -            space = ",";
343.1749 -            index = 1;
343.1750 -        } else {
343.1751 -            space = "";
343.1752 -            index = 0;
343.1753 -        }
343.1754 +        String space = "";
343.1755 +        int index = 0;
343.1756          for (int i = 0; i < cnt.length(); i++) {
343.1757              out.append(space);
343.1758 -            out.append(p.args[index]);
343.1759 +            space = outputArg(out, p.args, index);
343.1760              index++;
343.1761 -            space = ",";
343.1762          }
343.1763          out.append(") {").append("\n");
343.1764          out.append(p.body);
343.1765 @@ -1178,4 +1731,76 @@
343.1766          };
343.1767          ap.parse(data, cd);
343.1768      }
343.1769 +
343.1770 +    private static String outputArg(Appendable out, String[] args, int indx) throws IOException {
343.1771 +        final String name = args[indx];
343.1772 +        if (name == null) {
343.1773 +            return "";
343.1774 +        }
343.1775 +        if (name.contains(",")) {
343.1776 +            throw new IOException("Wrong parameter with ',': " + name);
343.1777 +        }
343.1778 +        out.append(name);
343.1779 +        return ",";
343.1780 +    }
343.1781 +
343.1782 +    private static void emit(final Appendable out,
343.1783 +                             final String format,
343.1784 +                             final CharSequence... params) throws IOException {
343.1785 +        final int length = format.length();
343.1786 +
343.1787 +        int processed = 0;
343.1788 +        int paramOffset = format.indexOf('@');
343.1789 +        while ((paramOffset != -1) && (paramOffset < (length - 1))) {
343.1790 +            final char paramChar = format.charAt(paramOffset + 1);
343.1791 +            if ((paramChar >= '1') && (paramChar <= '9')) {
343.1792 +                final int paramIndex = paramChar - '0' - 1;
343.1793 +
343.1794 +                out.append(format, processed, paramOffset);
343.1795 +                out.append(params[paramIndex]);
343.1796 +
343.1797 +                ++paramOffset;
343.1798 +                processed = paramOffset + 1;
343.1799 +            }
343.1800 +
343.1801 +            paramOffset = format.indexOf('@', paramOffset + 1);
343.1802 +        }
343.1803 +
343.1804 +        out.append(format, processed, length);
343.1805 +    }
343.1806 +
343.1807 +    private void generateCatch(TrapData[] traps) throws IOException {
343.1808 +        out.append("} catch (e) {\n");
343.1809 +        int finallyPC = -1;
343.1810 +        for (TrapData e : traps) {
343.1811 +            if (e == null) {
343.1812 +                break;
343.1813 +            }
343.1814 +            if (e.catch_cpx != 0) { //not finally
343.1815 +                final String classInternalName = jc.getClassName(e.catch_cpx);
343.1816 +                addReference(classInternalName);
343.1817 +                if ("java/lang/Throwable".equals(classInternalName)) {
343.1818 +                    out.append("if (e.$instOf_java_lang_Throwable) {");
343.1819 +                    out.append("  var stA0 = e;");
343.1820 +                    out.append("} else {");
343.1821 +                    out.append("  var stA0 = vm.java_lang_Throwable(true);");
343.1822 +                    out.append("  vm.java_lang_Throwable.cons__VLjava_lang_String_2.call(stA0, e.toString());");
343.1823 +                    out.append("}");
343.1824 +                    out.append("gt=" + e.handler_pc + "; continue;");
343.1825 +                } else {
343.1826 +                    out.append("if (e.$instOf_" + classInternalName.replace('/', '_') + ") {");
343.1827 +                    out.append("gt=" + e.handler_pc + "; var stA0 = e; continue;");
343.1828 +                    out.append("}\n");
343.1829 +                }
343.1830 +            } else {
343.1831 +                finallyPC = e.handler_pc;
343.1832 +            }
343.1833 +        }
343.1834 +        if (finallyPC == -1) {
343.1835 +            out.append("throw e;");
343.1836 +        } else {
343.1837 +            out.append("gt=" + finallyPC + "; var stA0 = e; continue;");
343.1838 +        }
343.1839 +        out.append("\n}");
343.1840 +    }
343.1841  }
   344.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java	Wed Dec 05 10:03:58 2012 +0100
   344.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   344.3 @@ -1,204 +0,0 @@
   344.4 -/**
   344.5 - * Back 2 Browser Bytecode Translator
   344.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   344.7 - *
   344.8 - * This program is free software: you can redistribute it and/or modify
   344.9 - * it under the terms of the GNU General Public License as published by
  344.10 - * the Free Software Foundation, version 2 of the License.
  344.11 - *
  344.12 - * This program is distributed in the hope that it will be useful,
  344.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  344.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  344.15 - * GNU General Public License for more details.
  344.16 - *
  344.17 - * You should have received a copy of the GNU General Public License
  344.18 - * along with this program. Look for COPYING file in the top folder.
  344.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  344.20 - */
  344.21 -package org.apidesign.vm4brwsr;
  344.22 -
  344.23 -import java.io.IOException;
  344.24 -import java.io.InputStream;
  344.25 -import java.net.URL;
  344.26 -import java.util.Enumeration;
  344.27 -
  344.28 -/** Generator of JavaScript from bytecode of classes on classpath of the VM.
  344.29 - *
  344.30 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  344.31 - */
  344.32 -final class GenJS extends ByteCodeToJavaScript {
  344.33 -    public GenJS(Appendable out) {
  344.34 -        super(out);
  344.35 -    }
  344.36 -    
  344.37 -    static void compile(Appendable out, String... names) throws IOException {
  344.38 -        compile(out, StringArray.asList(names));
  344.39 -    }
  344.40 -    static void compile(ClassLoader l, Appendable out, String... names) throws IOException {
  344.41 -        compile(l, out, StringArray.asList(names));
  344.42 -    }
  344.43 -    static void compile(Appendable out, StringArray names) throws IOException {
  344.44 -        compile(GenJS.class.getClassLoader(), out, names);
  344.45 -    }
  344.46 -    static void compile(ClassLoader l, Appendable out, StringArray names) throws IOException {
  344.47 -        out.append("Array.prototype.fillNulls = function() {\n" +
  344.48 -             "  for(var i = 0; i < this.length; i++) {\n" +
  344.49 -             "    this[i] = null;\n" +
  344.50 -             "  }\n" +
  344.51 -             "  return this;\n" +
  344.52 -             "};");
  344.53 -        
  344.54 -        
  344.55 -        StringArray processed = new StringArray();
  344.56 -        StringArray initCode = new StringArray();
  344.57 -        for (String baseClass : names.toArray()) {
  344.58 -            GenJS js = new GenJS(out);
  344.59 -            js.references.add(baseClass);
  344.60 -            for (;;) {
  344.61 -                String name = null;
  344.62 -                for (String n : js.references.toArray()) {
  344.63 -                    if (processed.contains(n)) {
  344.64 -                        continue;
  344.65 -                    }
  344.66 -                    name = n;
  344.67 -                }
  344.68 -                if (name == null) {
  344.69 -                    break;
  344.70 -                }
  344.71 -                InputStream is = loadClass(l, name);
  344.72 -                if (is == null) {
  344.73 -                    throw new IOException("Can't find class " + name); 
  344.74 -                }
  344.75 -                try {
  344.76 -                    String ic = js.compile(is);
  344.77 -                    processed.add(name);
  344.78 -                    initCode.add(ic == null ? "" : ic);
  344.79 -                } catch (RuntimeException ex) {
  344.80 -                    if (out instanceof CharSequence) {
  344.81 -                        CharSequence seq = (CharSequence)out;
  344.82 -                        int lastBlock = seq.length();
  344.83 -                        while (lastBlock-- > 0) {
  344.84 -                            if (seq.charAt(lastBlock) == '{') {
  344.85 -                                break;
  344.86 -                            }
  344.87 -                        }
  344.88 -                        throw new IOException("Error while compiling " + name + "\n" 
  344.89 -                            + seq.subSequence(lastBlock + 1, seq.length()), ex
  344.90 -                        );
  344.91 -                    } else {
  344.92 -                        throw new IOException("Error while compiling " + name + "\n" 
  344.93 -                            + out, ex
  344.94 -                        );
  344.95 -                    }
  344.96 -                }
  344.97 -            }
  344.98 -
  344.99 -            for (String resource : js.scripts.toArray()) {
 344.100 -                while (resource.startsWith("/")) {
 344.101 -                    resource = resource.substring(1);
 344.102 -                }
 344.103 -                InputStream emul = l.getResourceAsStream(resource);
 344.104 -                if (emul == null) {
 344.105 -                    throw new IOException("Can't find " + resource);
 344.106 -                }
 344.107 -                readResource(emul, out);
 344.108 -            }
 344.109 -            js.scripts = new StringArray();
 344.110 -            
 344.111 -            StringArray toInit = StringArray.asList(js.references.toArray());
 344.112 -            toInit.reverse();
 344.113 -
 344.114 -            for (String ic : toInit.toArray()) {
 344.115 -                int indx = processed.indexOf(ic);
 344.116 -                if (indx >= 0) {
 344.117 -                    out.append(initCode.toArray()[indx]).append("\n");
 344.118 -                    initCode.toArray()[indx] = "";
 344.119 -                }
 344.120 -            }
 344.121 -
 344.122 -        }
 344.123 -    }
 344.124 -    private static void readResource(InputStream emul, Appendable out) throws IOException {
 344.125 -        try {
 344.126 -            int state = 0;
 344.127 -            for (;;) {
 344.128 -                int ch = emul.read();
 344.129 -                if (ch == -1) {
 344.130 -                    break;
 344.131 -                }
 344.132 -                if (ch < 0 || ch > 255) {
 344.133 -                    throw new IOException("Invalid char in emulation " + ch);
 344.134 -                }
 344.135 -                switch (state) {
 344.136 -                    case 0: 
 344.137 -                        if (ch == '/') {
 344.138 -                            state = 1;
 344.139 -                        } else {
 344.140 -                            out.append((char)ch);
 344.141 -                        }
 344.142 -                        break;
 344.143 -                    case 1:
 344.144 -                        if (ch == '*') {
 344.145 -                            state = 2;
 344.146 -                        } else {
 344.147 -                            out.append('/').append((char)ch);
 344.148 -                            state = 0;
 344.149 -                        }
 344.150 -                        break;
 344.151 -                    case 2:
 344.152 -                        if (ch == '*') {
 344.153 -                            state = 3;
 344.154 -                        }
 344.155 -                        break;
 344.156 -                    case 3:
 344.157 -                        if (ch == '/') {
 344.158 -                            state = 0;
 344.159 -                        } else {
 344.160 -                            state = 2;
 344.161 -                        }
 344.162 -                        break;
 344.163 -                }
 344.164 -            }
 344.165 -        } finally {
 344.166 -            emul.close();
 344.167 -        }
 344.168 -    }
 344.169 -
 344.170 -    private static InputStream loadClass(ClassLoader l, String name) throws IOException {
 344.171 -        Enumeration<URL> en = l.getResources(name + ".class");
 344.172 -        URL u = null;
 344.173 -        while (en.hasMoreElements()) {
 344.174 -            u = en.nextElement();
 344.175 -        }
 344.176 -        if (u == null) {
 344.177 -            throw new IOException("Can't find " + name);
 344.178 -        }
 344.179 -        if (u.toExternalForm().contains("rt.jar!")) {
 344.180 -            throw new IOException("No emulation for " + u);
 344.181 -        }
 344.182 -        return u.openStream();
 344.183 -    }
 344.184 -
 344.185 -    static String toString(String name) throws IOException {
 344.186 -        StringBuilder sb = new StringBuilder();
 344.187 -        compile(sb, name);
 344.188 -        return sb.toString().toString();
 344.189 -    }
 344.190 -
 344.191 -    private StringArray scripts = new StringArray();
 344.192 -    private StringArray references = new StringArray();
 344.193 -    
 344.194 -    @Override
 344.195 -    protected boolean requireReference(String cn) {
 344.196 -        if (references.contains(cn)) {
 344.197 -            return false;
 344.198 -        }
 344.199 -        references.add(cn);
 344.200 -        return true;
 344.201 -    }
 344.202 -
 344.203 -    @Override
 344.204 -    protected void requireScript(String resourcePath) {
 344.205 -        scripts.add(resourcePath);
 344.206 -    }
 344.207 -}
   345.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   345.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/LocalsMapper.java	Sun Feb 03 07:48:42 2013 +0100
   345.3 @@ -0,0 +1,142 @@
   345.4 +/**
   345.5 + * Back 2 Browser Bytecode Translator
   345.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   345.7 + *
   345.8 + * This program is free software: you can redistribute it and/or modify
   345.9 + * it under the terms of the GNU General Public License as published by
  345.10 + * the Free Software Foundation, version 2 of the License.
  345.11 + *
  345.12 + * This program is distributed in the hope that it will be useful,
  345.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  345.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  345.15 + * GNU General Public License for more details.
  345.16 + *
  345.17 + * You should have received a copy of the GNU General Public License
  345.18 + * along with this program. Look for COPYING file in the top folder.
  345.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  345.20 + */
  345.21 +package org.apidesign.vm4brwsr;
  345.22 +
  345.23 +import java.io.IOException;
  345.24 +import org.apidesign.javap.RuntimeConstants;
  345.25 +import org.apidesign.javap.TypeArray;
  345.26 +
  345.27 +final class LocalsMapper {
  345.28 +    private final TypeArray argTypeRecords;
  345.29 +    private final TypeArray localTypeRecords;
  345.30 +
  345.31 +    public LocalsMapper(final TypeArray stackMapArgs) {
  345.32 +        final TypeArray initTypeRecords = new TypeArray();
  345.33 +        updateRecords(initTypeRecords, stackMapArgs);
  345.34 +
  345.35 +        argTypeRecords = initTypeRecords;
  345.36 +        localTypeRecords = new TypeArray(initTypeRecords);
  345.37 +    }
  345.38 +
  345.39 +    public void outputArguments(final Appendable out, boolean isStatic) throws IOException {
  345.40 +        final int argRecordCount = argTypeRecords.getSize();
  345.41 +        int first = isStatic ? 0 : 1;
  345.42 +        if (argRecordCount > first) {
  345.43 +            Variable variable = getVariable(argTypeRecords, first);
  345.44 +            out.append(variable);
  345.45 +
  345.46 +            int i = first + (variable.isCategory2() ? 2 : 1);
  345.47 +            while (i < argRecordCount) {
  345.48 +                variable = getVariable(argTypeRecords, i);
  345.49 +                out.append(", ");
  345.50 +                out.append(variable);
  345.51 +                i += variable.isCategory2() ? 2 : 1;
  345.52 +            }
  345.53 +        }
  345.54 +    }
  345.55 +
  345.56 +    public void syncWithFrameLocals(final TypeArray frameLocals) {
  345.57 +        updateRecords(localTypeRecords, frameLocals);
  345.58 +    }
  345.59 +
  345.60 +    public Variable setI(final int index) {
  345.61 +        return setT(index, VarType.INTEGER);
  345.62 +    }
  345.63 +
  345.64 +    public Variable setL(final int index) {
  345.65 +        return setT(index, VarType.LONG);
  345.66 +    }
  345.67 +
  345.68 +    public Variable setF(final int index) {
  345.69 +        return setT(index, VarType.FLOAT);
  345.70 +    }
  345.71 +
  345.72 +    public Variable setD(final int index) {
  345.73 +        return setT(index, VarType.DOUBLE);
  345.74 +    }
  345.75 +
  345.76 +    public Variable setA(final int index) {
  345.77 +        return setT(index, VarType.REFERENCE);
  345.78 +    }
  345.79 +
  345.80 +    public Variable setT(final int index, final int type) {
  345.81 +        updateRecord(localTypeRecords, index, type);
  345.82 +        return Variable.getLocalVariable(type, index);
  345.83 +    }
  345.84 +
  345.85 +    public Variable getI(final int index) {
  345.86 +        return getT(index, VarType.INTEGER);
  345.87 +    }
  345.88 +
  345.89 +    public Variable getL(final int index) {
  345.90 +        return getT(index, VarType.LONG);
  345.91 +    }
  345.92 +
  345.93 +    public Variable getF(final int index) {
  345.94 +        return getT(index, VarType.FLOAT);
  345.95 +    }
  345.96 +
  345.97 +    public Variable getD(final int index) {
  345.98 +        return getT(index, VarType.DOUBLE);
  345.99 +    }
 345.100 +
 345.101 +    public Variable getA(final int index) {
 345.102 +        return getT(index, VarType.REFERENCE);
 345.103 +    }
 345.104 +
 345.105 +    public Variable getT(final int index, final int type) {
 345.106 +        final int oldRecordValue = localTypeRecords.get(index);
 345.107 +        if ((oldRecordValue & 0xff) != type) {
 345.108 +            throw new IllegalStateException("Type mismatch");
 345.109 +        }
 345.110 +
 345.111 +        return Variable.getLocalVariable(type, index);
 345.112 +    }
 345.113 +
 345.114 +    private static void updateRecords(final TypeArray typeRecords,
 345.115 +                                      final TypeArray stackMapTypes) {
 345.116 +        final int srcSize = stackMapTypes.getSize();
 345.117 +        for (int i = 0, dstIndex = 0; i < srcSize; ++i) {
 345.118 +            final int smType = stackMapTypes.get(i);
 345.119 +            if (smType == RuntimeConstants.ITEM_Bogus) {
 345.120 +                ++dstIndex;
 345.121 +                continue;
 345.122 +            }
 345.123 +            final int varType = VarType.fromStackMapType(smType);
 345.124 +            updateRecord(typeRecords, dstIndex, varType);
 345.125 +            dstIndex += VarType.isCategory2(varType) ? 2 : 1;
 345.126 +        }
 345.127 +    }
 345.128 +
 345.129 +    private static void updateRecord(final TypeArray typeRecords,
 345.130 +                                     final int index, final int type) {
 345.131 +        if (typeRecords.getSize() < (index + 1)) {
 345.132 +            typeRecords.setSize(index + 1);
 345.133 +        }
 345.134 +
 345.135 +        final int oldRecordValue = typeRecords.get(index);
 345.136 +        final int usedTypesMask =
 345.137 +                (oldRecordValue >> 8) | (1 << type);
 345.138 +        typeRecords.set(index, (usedTypesMask << 8) | type);
 345.139 +    }
 345.140 +
 345.141 +    private static Variable getVariable(final TypeArray typeRecords,
 345.142 +                                        final int index) {
 345.143 +        return Variable.getLocalVariable(typeRecords.get(index) & 0xff, index);
 345.144 +    }
 345.145 +}
   346.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/Main.java	Wed Dec 05 10:03:58 2012 +0100
   346.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/Main.java	Sun Feb 03 07:48:42 2013 +0100
   346.3 @@ -32,6 +32,7 @@
   346.4      
   346.5      public static void main(String... args) throws IOException {
   346.6          if (args.length < 2) {
   346.7 +            System.err.println("Bck2Brwsr Translator from Java(tm) to JavaScript, (c) Jaroslav Tulach 2012");
   346.8              System.err.println("Usage: java -cp ... -jar ... <file_to_generate_js_code_to> java/lang/Class org/your/App ...");
   346.9              return;
  346.10          }
  346.11 @@ -39,7 +40,11 @@
  346.12          Writer w = new BufferedWriter(new FileWriter(args[0]));
  346.13          StringArray classes = StringArray.asList(args);
  346.14          classes.delete(0);
  346.15 -        GenJS.compile(w, classes);
  346.16 -        w.close();
  346.17 +        try {
  346.18 +            Bck2Brwsr.generate(w, Main.class.getClassLoader(),
  346.19 +                               classes.toArray());
  346.20 +        } finally {
  346.21 +            w.close();
  346.22 +        }
  346.23      }
  346.24  }
   347.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   347.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/StackMapper.java	Sun Feb 03 07:48:42 2013 +0100
   347.3 @@ -0,0 +1,194 @@
   347.4 +/**
   347.5 + * Back 2 Browser Bytecode Translator
   347.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   347.7 + *
   347.8 + * This program is free software: you can redistribute it and/or modify
   347.9 + * it under the terms of the GNU General Public License as published by
  347.10 + * the Free Software Foundation, version 2 of the License.
  347.11 + *
  347.12 + * This program is distributed in the hope that it will be useful,
  347.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  347.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  347.15 + * GNU General Public License for more details.
  347.16 + *
  347.17 + * You should have received a copy of the GNU General Public License
  347.18 + * along with this program. Look for COPYING file in the top folder.
  347.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  347.20 + */
  347.21 +package org.apidesign.vm4brwsr;
  347.22 +
  347.23 +import org.apidesign.javap.TypeArray;
  347.24 +
  347.25 +final class StackMapper {
  347.26 +    private final TypeArray stackTypeIndexPairs;
  347.27 +    private int[] typeCounters;
  347.28 +    private int[] typeMaxCounters;
  347.29 +
  347.30 +    public StackMapper() {
  347.31 +        stackTypeIndexPairs = new TypeArray();
  347.32 +        typeCounters = new int[VarType.LAST + 1];
  347.33 +        typeMaxCounters = new int[VarType.LAST + 1];
  347.34 +    }
  347.35 +
  347.36 +    public void clear() {
  347.37 +        for (int type = 0; type <= VarType.LAST; ++type) {
  347.38 +            typeCounters[type] = 0;
  347.39 +        }
  347.40 +        stackTypeIndexPairs.clear();
  347.41 +    }
  347.42 +
  347.43 +    public void syncWithFrameStack(final TypeArray frameStack) {
  347.44 +        clear();
  347.45 +
  347.46 +        final int size = frameStack.getSize();
  347.47 +        for (int i = 0; i < size; ++i) {
  347.48 +            pushTypeImpl(VarType.fromStackMapType(frameStack.get(i)));
  347.49 +        }
  347.50 +    }
  347.51 +
  347.52 +    public Variable pushI() {
  347.53 +        return pushT(VarType.INTEGER);
  347.54 +    }
  347.55 +
  347.56 +    public Variable pushL() {
  347.57 +        return pushT(VarType.LONG);
  347.58 +    }
  347.59 +
  347.60 +    public Variable pushF() {
  347.61 +        return pushT(VarType.FLOAT);
  347.62 +    }
  347.63 +
  347.64 +    public Variable pushD() {
  347.65 +        return pushT(VarType.DOUBLE);
  347.66 +    }
  347.67 +
  347.68 +    public Variable pushA() {
  347.69 +        return pushT(VarType.REFERENCE);
  347.70 +    }
  347.71 +
  347.72 +    public Variable pushT(final int type) {
  347.73 +        return getVariable(pushTypeImpl(type));
  347.74 +    }
  347.75 +
  347.76 +    public Variable popI() {
  347.77 +        return popT(VarType.INTEGER);
  347.78 +    }
  347.79 +
  347.80 +    public Variable popL() {
  347.81 +        return popT(VarType.LONG);
  347.82 +    }
  347.83 +
  347.84 +    public Variable popF() {
  347.85 +        return popT(VarType.FLOAT);
  347.86 +    }
  347.87 +
  347.88 +    public Variable popD() {
  347.89 +        return popT(VarType.DOUBLE);
  347.90 +    }
  347.91 +
  347.92 +    public Variable popA() {
  347.93 +        return popT(VarType.REFERENCE);
  347.94 +    }
  347.95 +
  347.96 +    public Variable popT(final int type) {
  347.97 +        final Variable variable = getT(0, type);
  347.98 +        popImpl(1);
  347.99 +        return variable;
 347.100 +    }
 347.101 +
 347.102 +    public Variable pop() {
 347.103 +        final Variable variable = get(0);
 347.104 +        popImpl(1);
 347.105 +        return variable;
 347.106 +    }
 347.107 +
 347.108 +    public void pop(final int count) {
 347.109 +        final int stackSize = stackTypeIndexPairs.getSize();
 347.110 +        if (count > stackSize) {
 347.111 +            throw new IllegalStateException("Stack underflow");
 347.112 +        }
 347.113 +        popImpl(count);
 347.114 +    }
 347.115 +
 347.116 +    public Variable getI(final int indexFromTop) {
 347.117 +        return getT(indexFromTop, VarType.INTEGER);
 347.118 +    }
 347.119 +
 347.120 +    public Variable getL(final int indexFromTop) {
 347.121 +        return getT(indexFromTop, VarType.LONG);
 347.122 +    }
 347.123 +
 347.124 +    public Variable getF(final int indexFromTop) {
 347.125 +        return getT(indexFromTop, VarType.FLOAT);
 347.126 +    }
 347.127 +
 347.128 +    public Variable getD(final int indexFromTop) {
 347.129 +        return getT(indexFromTop, VarType.DOUBLE);
 347.130 +    }
 347.131 +
 347.132 +    public Variable getA(final int indexFromTop) {
 347.133 +        return getT(indexFromTop, VarType.REFERENCE);
 347.134 +    }
 347.135 +
 347.136 +    public Variable getT(final int indexFromTop, final int type) {
 347.137 +        final int stackSize = stackTypeIndexPairs.getSize();
 347.138 +        if (indexFromTop >= stackSize) {
 347.139 +            throw new IllegalStateException("Stack underflow");
 347.140 +        }
 347.141 +        final int stackValue =
 347.142 +                stackTypeIndexPairs.get(stackSize - indexFromTop - 1);
 347.143 +        if ((stackValue & 0xff) != type) {
 347.144 +            throw new IllegalStateException("Type mismatch");
 347.145 +        }
 347.146 +
 347.147 +        return getVariable(stackValue);
 347.148 +    }
 347.149 +
 347.150 +    public Variable get(final int indexFromTop) {
 347.151 +        final int stackSize = stackTypeIndexPairs.getSize();
 347.152 +        if (indexFromTop >= stackSize) {
 347.153 +            throw new IllegalStateException("Stack underflow");
 347.154 +        }
 347.155 +        final int stackValue =
 347.156 +                stackTypeIndexPairs.get(stackSize - indexFromTop - 1);
 347.157 +
 347.158 +        return getVariable(stackValue);
 347.159 +    }
 347.160 +
 347.161 +    private int pushTypeImpl(final int type) {
 347.162 +        final int count = typeCounters[type];
 347.163 +        final int value = (count << 8) | (type & 0xff);
 347.164 +        incCounter(type);
 347.165 +        stackTypeIndexPairs.add(value);
 347.166 +
 347.167 +        return value;
 347.168 +    }
 347.169 +
 347.170 +    private void popImpl(final int count) {
 347.171 +        final int stackSize = stackTypeIndexPairs.getSize();
 347.172 +        for (int i = stackSize - count; i < stackSize; ++i) {
 347.173 +            final int value = stackTypeIndexPairs.get(i);
 347.174 +            decCounter(value & 0xff);
 347.175 +        }
 347.176 +
 347.177 +        stackTypeIndexPairs.setSize(stackSize - count);
 347.178 +    }
 347.179 +
 347.180 +    private void incCounter(final int type) {
 347.181 +        final int newValue = ++typeCounters[type];
 347.182 +        if (typeMaxCounters[type] < newValue) {
 347.183 +            typeMaxCounters[type] = newValue;
 347.184 +        }
 347.185 +    }
 347.186 +
 347.187 +    private void decCounter(final int type) {
 347.188 +        --typeCounters[type];
 347.189 +    }
 347.190 +
 347.191 +    public Variable getVariable(final int typeAndIndex) {
 347.192 +        final int type = typeAndIndex & 0xff;
 347.193 +        final int index = typeAndIndex >> 8;
 347.194 +
 347.195 +        return Variable.getStackVariable(type, index);
 347.196 +    }
 347.197 +}
   348.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/StringArray.java	Wed Dec 05 10:03:58 2012 +0100
   348.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/StringArray.java	Sun Feb 03 07:48:42 2013 +0100
   348.3 @@ -48,7 +48,7 @@
   348.4          return arr == null ? new String[0] : arr;
   348.5      }
   348.6      
   348.7 -    static StringArray asList(String[] names) {
   348.8 +    static StringArray asList(String... names) {
   348.9          return new StringArray(names);
  348.10      }
  348.11  
   349.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   349.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Sun Feb 03 07:48:42 2013 +0100
   349.3 @@ -0,0 +1,220 @@
   349.4 +/**
   349.5 + * Back 2 Browser Bytecode Translator
   349.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   349.7 + *
   349.8 + * This program is free software: you can redistribute it and/or modify
   349.9 + * it under the terms of the GNU General Public License as published by
  349.10 + * the Free Software Foundation, version 2 of the License.
  349.11 + *
  349.12 + * This program is distributed in the hope that it will be useful,
  349.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  349.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  349.15 + * GNU General Public License for more details.
  349.16 + *
  349.17 + * You should have received a copy of the GNU General Public License
  349.18 + * along with this program. Look for COPYING file in the top folder.
  349.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  349.20 + */
  349.21 +package org.apidesign.vm4brwsr;
  349.22 +
  349.23 +import java.io.IOException;
  349.24 +import java.io.InputStream;
  349.25 +
  349.26 +/** Generator of JavaScript from bytecode of classes on classpath of the VM.
  349.27 + *
  349.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  349.29 + */
  349.30 +class VM extends ByteCodeToJavaScript {
  349.31 +    public VM(Appendable out) {
  349.32 +        super(out);
  349.33 +    }
  349.34 +    
  349.35 +    static {
  349.36 +        // uses VMLazy to load dynamic classes
  349.37 +        VMLazy.init();
  349.38 +    }
  349.39 +
  349.40 +    @Override
  349.41 +    boolean debug(String msg) throws IOException {
  349.42 +        return false;
  349.43 +    }
  349.44 +    
  349.45 +    static void compile(Bck2Brwsr.Resources l, Appendable out, StringArray names) throws IOException {
  349.46 +        new VM(out).doCompile(l, names);
  349.47 +    }
  349.48 +    protected void doCompile(Bck2Brwsr.Resources l, StringArray names) throws IOException {
  349.49 +        out.append("(function VM(global) {");
  349.50 +        out.append("\n  var vm = {};");
  349.51 +        StringArray processed = new StringArray();
  349.52 +        StringArray initCode = new StringArray();
  349.53 +        for (String baseClass : names.toArray()) {
  349.54 +            references.add(baseClass);
  349.55 +            for (;;) {
  349.56 +                String name = null;
  349.57 +                for (String n : references.toArray()) {
  349.58 +                    if (processed.contains(n)) {
  349.59 +                        continue;
  349.60 +                    }
  349.61 +                    name = n;
  349.62 +                }
  349.63 +                if (name == null) {
  349.64 +                    break;
  349.65 +                }
  349.66 +                InputStream is = loadClass(l, name);
  349.67 +                if (is == null) {
  349.68 +                    throw new IOException("Can't find class " + name); 
  349.69 +                }
  349.70 +                try {
  349.71 +                    String ic = compile(is);
  349.72 +                    processed.add(name);
  349.73 +                    initCode.add(ic == null ? "" : ic);
  349.74 +                } catch (RuntimeException ex) {
  349.75 +                    if (out instanceof CharSequence) {
  349.76 +                        CharSequence seq = (CharSequence)out;
  349.77 +                        int lastBlock = seq.length();
  349.78 +                        while (lastBlock-- > 0) {
  349.79 +                            if (seq.charAt(lastBlock) == '{') {
  349.80 +                                break;
  349.81 +                            }
  349.82 +                        }
  349.83 +                        throw new IOException("Error while compiling " + name + "\n" 
  349.84 +                            + seq.subSequence(lastBlock + 1, seq.length()), ex
  349.85 +                        );
  349.86 +                    } else {
  349.87 +                        throw new IOException("Error while compiling " + name + "\n" 
  349.88 +                            + out, ex
  349.89 +                        );
  349.90 +                    }
  349.91 +                }
  349.92 +            }
  349.93 +
  349.94 +            for (String resource : scripts.toArray()) {
  349.95 +                while (resource.startsWith("/")) {
  349.96 +                    resource = resource.substring(1);
  349.97 +                }
  349.98 +                InputStream emul = l.get(resource);
  349.99 +                if (emul == null) {
 349.100 +                    throw new IOException("Can't find " + resource);
 349.101 +                }
 349.102 +                readResource(emul, out);
 349.103 +            }
 349.104 +            scripts = new StringArray();
 349.105 +            
 349.106 +            StringArray toInit = StringArray.asList(references.toArray());
 349.107 +            toInit.reverse();
 349.108 +
 349.109 +            for (String ic : toInit.toArray()) {
 349.110 +                int indx = processed.indexOf(ic);
 349.111 +                if (indx >= 0) {
 349.112 +                    out.append(initCode.toArray()[indx]).append("\n");
 349.113 +                    initCode.toArray()[indx] = "";
 349.114 +                }
 349.115 +            }
 349.116 +        }
 349.117 +        out.append(
 349.118 +              "  global.bck2brwsr = function() {\n"
 349.119 +            + "    var args = arguments;\n"
 349.120 +            + "    var loader = {};\n"
 349.121 +            + "    loader.vm = vm;\n"
 349.122 +            + "    loader.loadClass = function(name) {\n"
 349.123 +            + "      var attr = name.replace__Ljava_lang_String_2CC('.','_');\n"
 349.124 +            + "      var fn = vm[attr];\n"
 349.125 +            + "      if (fn) return fn(false);\n"
 349.126 +            + "      if (!args[0]) throw 'bck2brwsr initialized without loader function, cannot load ' + name;\n"
 349.127 +            + "      return vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
 349.128 +            + "        load__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2(loader, name, args);\n"
 349.129 +            + "    }\n"
 349.130 +            + "    if (args[0]) {\n"
 349.131 +            + "      vm.loadClass = loader.loadClass;\n"
 349.132 +            + "      vm.loadBytes = function(name) {\n"
 349.133 +            + "        if (!args[0]) throw 'bck2brwsr initialized without loader function, cannot load ' + name;\n"
 349.134 +            + "        return args[0](name);\n"
 349.135 +            + "      }\n"
 349.136 +            + "    }\n"
 349.137 +            + "    return loader;\n"
 349.138 +            + "  };\n");
 349.139 +        out.append("}(this));");
 349.140 +    }
 349.141 +    private static void readResource(InputStream emul, Appendable out) throws IOException {
 349.142 +        try {
 349.143 +            int state = 0;
 349.144 +            for (;;) {
 349.145 +                int ch = emul.read();
 349.146 +                if (ch == -1) {
 349.147 +                    break;
 349.148 +                }
 349.149 +                if (ch < 0 || ch > 255) {
 349.150 +                    throw new IOException("Invalid char in emulation " + ch);
 349.151 +                }
 349.152 +                switch (state) {
 349.153 +                    case 0: 
 349.154 +                        if (ch == '/') {
 349.155 +                            state = 1;
 349.156 +                        } else {
 349.157 +                            out.append((char)ch);
 349.158 +                        }
 349.159 +                        break;
 349.160 +                    case 1:
 349.161 +                        if (ch == '*') {
 349.162 +                            state = 2;
 349.163 +                        } else {
 349.164 +                            out.append('/').append((char)ch);
 349.165 +                            state = 0;
 349.166 +                        }
 349.167 +                        break;
 349.168 +                    case 2:
 349.169 +                        if (ch == '*') {
 349.170 +                            state = 3;
 349.171 +                        }
 349.172 +                        break;
 349.173 +                    case 3:
 349.174 +                        if (ch == '/') {
 349.175 +                            state = 0;
 349.176 +                        } else {
 349.177 +                            state = 2;
 349.178 +                        }
 349.179 +                        break;
 349.180 +                }
 349.181 +            }
 349.182 +        } finally {
 349.183 +            emul.close();
 349.184 +        }
 349.185 +    }
 349.186 +
 349.187 +    private static InputStream loadClass(Bck2Brwsr.Resources l, String name) throws IOException {
 349.188 +        return l.get(name + ".class"); // NOI18N
 349.189 +    }
 349.190 +
 349.191 +    static String toString(String name) throws IOException {
 349.192 +        StringBuilder sb = new StringBuilder();
 349.193 +//        compile(sb, name);
 349.194 +        return sb.toString().toString();
 349.195 +    }
 349.196 +
 349.197 +    private StringArray scripts = new StringArray();
 349.198 +    private StringArray references = new StringArray();
 349.199 +    
 349.200 +    @Override
 349.201 +    protected boolean requireReference(String cn) {
 349.202 +        if (references.contains(cn)) {
 349.203 +            return false;
 349.204 +        }
 349.205 +        references.add(cn);
 349.206 +        return true;
 349.207 +    }
 349.208 +
 349.209 +    @Override
 349.210 +    protected void requireScript(String resourcePath) {
 349.211 +        scripts.add(resourcePath);
 349.212 +    }
 349.213 +
 349.214 +    @Override
 349.215 +    String assignClass(String className) {
 349.216 +        return "vm." + className + " = ";
 349.217 +    }
 349.218 +    
 349.219 +    @Override
 349.220 +    String accessClass(String className) {
 349.221 +        return "vm." + className;
 349.222 +    }
 349.223 +}
   350.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   350.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java	Sun Feb 03 07:48:42 2013 +0100
   350.3 @@ -0,0 +1,158 @@
   350.4 +/**
   350.5 + * Back 2 Browser Bytecode Translator
   350.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   350.7 + *
   350.8 + * This program is free software: you can redistribute it and/or modify
   350.9 + * it under the terms of the GNU General Public License as published by
  350.10 + * the Free Software Foundation, version 2 of the License.
  350.11 + *
  350.12 + * This program is distributed in the hope that it will be useful,
  350.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  350.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  350.15 + * GNU General Public License for more details.
  350.16 + *
  350.17 + * You should have received a copy of the GNU General Public License
  350.18 + * along with this program. Look for COPYING file in the top folder.
  350.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  350.20 + */
  350.21 +package org.apidesign.vm4brwsr;
  350.22 +
  350.23 +import java.io.ByteArrayInputStream;
  350.24 +import java.io.IOException;
  350.25 +import java.io.InputStream;
  350.26 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  350.27 +
  350.28 +/**
  350.29 + *
  350.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  350.31 + */
  350.32 +final class VMLazy {
  350.33 +    private final Object loader;
  350.34 +    private final Object[] args;
  350.35 +    
  350.36 +    private VMLazy(Object loader, Object[] args) {
  350.37 +        this.loader = loader;
  350.38 +        this.args = args;
  350.39 +    }
  350.40 +    
  350.41 +    static void init() {
  350.42 +    }
  350.43 +    
  350.44 +    @JavaScriptBody(args={"l", "res", "args" }, body = ""
  350.45 +        + "\ntry {"
  350.46 +        + "\n  return args[0](res.toString());"
  350.47 +        + "\n} catch (x) {"
  350.48 +        + "\n  throw Object.getOwnPropertyNames(l.vm).toString() + x.toString();"
  350.49 +        + "\n}")
  350.50 +    private static native byte[] read(Object l, String res, Object[] args);
  350.51 +    
  350.52 +    static Object load(Object loader, String name, Object[] arguments) 
  350.53 +    throws IOException, ClassNotFoundException {
  350.54 +        return new VMLazy(loader, arguments).load(name, false);
  350.55 +    }
  350.56 +    
  350.57 +    private Object load(String name, boolean instance)
  350.58 +    throws IOException, ClassNotFoundException {
  350.59 +        String res = name.replace('.', '/') + ".class";
  350.60 +        byte[] arr = read(loader, res, args);
  350.61 +        if (arr == null) {
  350.62 +            throw new ClassNotFoundException(name);
  350.63 +        }
  350.64 +//        beingDefined(loader, name);
  350.65 +        StringBuilder out = new StringBuilder();
  350.66 +        out.append("var loader = arguments[0];\n");
  350.67 +        out.append("var vm = loader.vm;\n");
  350.68 +        int prelude = out.length();
  350.69 +        String initCode = new Gen(this, out).compile(new ByteArrayInputStream(arr));
  350.70 +        String code = out.toString().toString();
  350.71 +//        dump("Loading " + name);
  350.72 +        dump(code);
  350.73 +        String under = name.replace('.', '_');
  350.74 +        Object fn = applyCode(loader, under, code, instance);
  350.75 +        
  350.76 +        if (!initCode.isEmpty()) {
  350.77 +            out.setLength(prelude);
  350.78 +            out.append(initCode);
  350.79 +            code = out.toString().toString();
  350.80 +            dump(code);
  350.81 +            applyCode(loader, null, code, false);
  350.82 +        }            
  350.83 +        
  350.84 +        return fn;
  350.85 +    }
  350.86 +
  350.87 +//    @JavaScriptBody(args = "s", body = "java.lang.System.out.println(s.toString());")
  350.88 +    static void dump(String s) {
  350.89 +    }
  350.90 +
  350.91 +/* possibly not needed:
  350.92 +    @JavaScriptBody(args = {"loader", "n" }, body =
  350.93 +        "var cls = n.replace__Ljava_lang_String_2CC(n, '.','_').toString();" +
  350.94 +        "loader.vm[cls] = true;\n"
  350.95 +    )
  350.96 +    private static native void beingDefined(Object loader, String name);
  350.97 +*/
  350.98 +    
  350.99 +
 350.100 +    @JavaScriptBody(args = {"loader", "name", "script", "instance" }, body =
 350.101 +        "try {\n" +
 350.102 +        "  new Function(script)(loader, name);\n" +
 350.103 +        "} catch (ex) {\n" +
 350.104 +        "  throw 'Cannot compile ' + name + ' ' + ex + ' line: ' + ex.lineNumber + ' script:\\n' + script;\n" +
 350.105 +        "}\n" +
 350.106 +        "return name != null ? vm[name](instance) : null;\n"
 350.107 +    )
 350.108 +    private static native Object applyCode(Object loader, String name, String script, boolean instance);
 350.109 +    
 350.110 +    
 350.111 +    private static final class Gen extends ByteCodeToJavaScript {
 350.112 +        private final VMLazy lazy;
 350.113 +
 350.114 +        public Gen(VMLazy vm, Appendable out) {
 350.115 +            super(out);
 350.116 +            this.lazy = vm;
 350.117 +        }
 350.118 +        
 350.119 +        @JavaScriptBody(args = {"n"},
 350.120 +        body =
 350.121 +        "var cls = n.replace__Ljava_lang_String_2CC('/','_').toString();"
 350.122 +        + "\nvar dot = n.replace__Ljava_lang_String_2CC('/','.').toString();"
 350.123 +        + "\nvar lazy = this._lazy();"
 350.124 +        + "\nvar loader = lazy._loader();"
 350.125 +        + "\nvar vm = loader.vm;"
 350.126 +        + "\nif (vm[cls]) return false;"
 350.127 +        + "\nvm[cls] = function() {"
 350.128 +        + "\n  var instance = arguments.length == 0 || arguments[0] === true;"
 350.129 +        + "\n  return lazy.load__Ljava_lang_Object_2Ljava_lang_String_2Z(dot, instance);"
 350.130 +        + "\n};"
 350.131 +        + "\nreturn true;")
 350.132 +        @Override
 350.133 +        protected boolean requireReference(String internalClassName) {
 350.134 +            throw new UnsupportedOperationException();
 350.135 +        }
 350.136 +
 350.137 +        @Override
 350.138 +        protected void requireScript(String resourcePath) throws IOException {
 350.139 +            InputStream is = getClass().getResourceAsStream(resourcePath);
 350.140 +            StringBuilder sb = new StringBuilder();
 350.141 +            for (;;) {
 350.142 +                int ch = is.read();
 350.143 +                if (ch == -1) {
 350.144 +                    break;
 350.145 +                }
 350.146 +                sb.append((char)ch);
 350.147 +            }
 350.148 +            applyCode(lazy.loader, null, sb.toString(), false);
 350.149 +        }
 350.150 +
 350.151 +        @Override
 350.152 +        String assignClass(String className) {
 350.153 +            return "vm[arguments[1]]=";
 350.154 +        }
 350.155 +
 350.156 +        @Override
 350.157 +        String accessClass(String classOperation) {
 350.158 +            return "vm." + classOperation;
 350.159 +        }
 350.160 +    }
 350.161 +}
   351.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   351.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/VarType.java	Sun Feb 03 07:48:42 2013 +0100
   351.3 @@ -0,0 +1,110 @@
   351.4 +/**
   351.5 + * Back 2 Browser Bytecode Translator
   351.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   351.7 + *
   351.8 + * This program is free software: you can redistribute it and/or modify
   351.9 + * it under the terms of the GNU General Public License as published by
  351.10 + * the Free Software Foundation, version 2 of the License.
  351.11 + *
  351.12 + * This program is distributed in the hope that it will be useful,
  351.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  351.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  351.15 + * GNU General Public License for more details.
  351.16 + *
  351.17 + * You should have received a copy of the GNU General Public License
  351.18 + * along with this program. Look for COPYING file in the top folder.
  351.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  351.20 + */
  351.21 +package org.apidesign.vm4brwsr;
  351.22 +
  351.23 +import org.apidesign.javap.RuntimeConstants;
  351.24 +
  351.25 +final class VarType {
  351.26 +    public static final int INTEGER = 0;
  351.27 +    public static final int LONG = 1;
  351.28 +    public static final int FLOAT = 2;
  351.29 +    public static final int DOUBLE = 3;
  351.30 +    public static final int REFERENCE = 4;
  351.31 +
  351.32 +    public static final int LAST = REFERENCE;
  351.33 +
  351.34 +    private VarType() {
  351.35 +    }
  351.36 +
  351.37 +    public static boolean isCategory2(final int varType) {
  351.38 +        return (varType == LONG) || (varType == DOUBLE);
  351.39 +    }
  351.40 +
  351.41 +    public static int fromStackMapType(final int smType) {
  351.42 +        switch (smType & 0xff) {
  351.43 +            case RuntimeConstants.ITEM_Integer:
  351.44 +                return VarType.INTEGER;
  351.45 +            case RuntimeConstants.ITEM_Float:
  351.46 +                return VarType.FLOAT;
  351.47 +            case RuntimeConstants.ITEM_Double:
  351.48 +                return VarType.DOUBLE;
  351.49 +            case RuntimeConstants.ITEM_Long:
  351.50 +                return VarType.LONG;
  351.51 +            case RuntimeConstants.ITEM_Null:
  351.52 +            case RuntimeConstants.ITEM_InitObject:
  351.53 +            case RuntimeConstants.ITEM_Object:
  351.54 +            case RuntimeConstants.ITEM_NewObject:
  351.55 +                return VarType.REFERENCE;
  351.56 +
  351.57 +            case RuntimeConstants.ITEM_Bogus:
  351.58 +                /* unclear how to handle for now */
  351.59 +            default:
  351.60 +                throw new IllegalStateException("Unhandled stack map type");
  351.61 +        }
  351.62 +    }
  351.63 +
  351.64 +    public static int fromConstantType(final byte constantTag) {
  351.65 +        switch (constantTag) {
  351.66 +            case RuntimeConstants.CONSTANT_INTEGER:
  351.67 +                return VarType.INTEGER;
  351.68 +            case RuntimeConstants.CONSTANT_FLOAT:
  351.69 +                return VarType.FLOAT;
  351.70 +            case RuntimeConstants.CONSTANT_LONG:
  351.71 +                return VarType.LONG;
  351.72 +            case RuntimeConstants.CONSTANT_DOUBLE:
  351.73 +                return VarType.DOUBLE;
  351.74 +
  351.75 +            case RuntimeConstants.CONSTANT_CLASS:
  351.76 +            case RuntimeConstants.CONSTANT_UTF8:
  351.77 +            case RuntimeConstants.CONSTANT_UNICODE:
  351.78 +            case RuntimeConstants.CONSTANT_STRING:
  351.79 +                return VarType.REFERENCE;
  351.80 +
  351.81 +            case RuntimeConstants.CONSTANT_FIELD:
  351.82 +            case RuntimeConstants.CONSTANT_METHOD:
  351.83 +            case RuntimeConstants.CONSTANT_INTERFACEMETHOD:
  351.84 +            case RuntimeConstants.CONSTANT_NAMEANDTYPE:
  351.85 +                /* unclear how to handle for now */
  351.86 +            default:
  351.87 +                throw new IllegalStateException("Unhandled constant tag");
  351.88 +        }
  351.89 +    }
  351.90 +
  351.91 +    public static int fromFieldType(final char fieldType) {
  351.92 +        switch (fieldType) {
  351.93 +            case 'B':
  351.94 +            case 'C':
  351.95 +            case 'S':
  351.96 +            case 'Z':
  351.97 +            case 'I':
  351.98 +                return VarType.INTEGER;
  351.99 +            case 'J':
 351.100 +                return VarType.LONG;
 351.101 +            case 'F':
 351.102 +                return VarType.FLOAT;
 351.103 +            case 'D':
 351.104 +                return VarType.DOUBLE;
 351.105 +            case 'L':
 351.106 +            case '[':
 351.107 +                return VarType.REFERENCE;
 351.108 +
 351.109 +            default:
 351.110 +                throw new IllegalStateException("Unhandled field type");
 351.111 +        }
 351.112 +    }
 351.113 +}
   352.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   352.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/Variable.java	Sun Feb 03 07:48:42 2013 +0100
   352.3 @@ -0,0 +1,100 @@
   352.4 +/**
   352.5 + * Back 2 Browser Bytecode Translator
   352.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   352.7 + *
   352.8 + * This program is free software: you can redistribute it and/or modify
   352.9 + * it under the terms of the GNU General Public License as published by
  352.10 + * the Free Software Foundation, version 2 of the License.
  352.11 + *
  352.12 + * This program is distributed in the hope that it will be useful,
  352.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  352.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  352.15 + * GNU General Public License for more details.
  352.16 + *
  352.17 + * You should have received a copy of the GNU General Public License
  352.18 + * along with this program. Look for COPYING file in the top folder.
  352.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  352.20 + */
  352.21 +package org.apidesign.vm4brwsr;
  352.22 +
  352.23 +final class Variable implements CharSequence {
  352.24 +    private static final String STACK_VAR_PREFIX = "st";
  352.25 +    private static final String LOCAL_VAR_PREFIX = "lc";
  352.26 +
  352.27 +    private final String name;
  352.28 +    private final int type;
  352.29 +    private final int index;
  352.30 +
  352.31 +    private static final char[] TYPE_IDS = { 'I', 'L', 'F', 'D', 'A' };
  352.32 +
  352.33 +    private Variable(final String prefix, final int type, final int index) {
  352.34 +        this.name = prefix + TYPE_IDS[type] + index;
  352.35 +        this.type = type;
  352.36 +        this.index = index;
  352.37 +    }
  352.38 +
  352.39 +    public static Variable getStackVariable(
  352.40 +            final int type, final int index) {
  352.41 +        // TODO: precreate frequently used variables
  352.42 +        return new Variable(STACK_VAR_PREFIX, type, index);
  352.43 +    }
  352.44 +
  352.45 +    public static Variable getLocalVariable(
  352.46 +            final int type, final int index) {
  352.47 +        // TODO: precreate frequently used variables
  352.48 +        return new Variable(LOCAL_VAR_PREFIX, type, index);
  352.49 +    }
  352.50 +
  352.51 +    public String getName() {
  352.52 +        return name;
  352.53 +    }
  352.54 +
  352.55 +    public int getType() {
  352.56 +        return type;
  352.57 +    }
  352.58 +
  352.59 +    public int getIndex() {
  352.60 +        return index;
  352.61 +    }
  352.62 +
  352.63 +    public boolean isCategory2() {
  352.64 +        return VarType.isCategory2(type);
  352.65 +    }
  352.66 +
  352.67 +    @Override
  352.68 +    public int length() {
  352.69 +        return name.length();
  352.70 +    }
  352.71 +
  352.72 +    @Override
  352.73 +    public char charAt(final int index) {
  352.74 +        return name.charAt(index);
  352.75 +    }
  352.76 +
  352.77 +    @Override
  352.78 +    public CharSequence subSequence(final int start, final int end) {
  352.79 +        return name.subSequence(start, end);
  352.80 +    }
  352.81 +
  352.82 +    @Override
  352.83 +    public int hashCode() {
  352.84 +        return name.hashCode();
  352.85 +    }
  352.86 +
  352.87 +    @Override
  352.88 +    public boolean equals(final Object other) {
  352.89 +        if (this == other) {
  352.90 +            return true;
  352.91 +        }
  352.92 +        if (!(other instanceof Variable)) {
  352.93 +            return false;
  352.94 +        }
  352.95 +
  352.96 +        return name.equals(((Variable) other).name);
  352.97 +    }
  352.98 +
  352.99 +    @Override
 352.100 +    public String toString() {
 352.101 +        return name;
 352.102 +    }
 352.103 +}
   353.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Array.java	Wed Dec 05 10:03:58 2012 +0100
   353.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Array.java	Sun Feb 03 07:48:42 2013 +0100
   353.3 @@ -51,6 +51,16 @@
   353.4          return doubles[4][0];
   353.5      }
   353.6      
   353.7 +    static double[][] dbls = new double[1][2];
   353.8 +    public static double twoDoubles() {
   353.9 +        return dbls[0][0] + dbls[0][0];
  353.10 +    }
  353.11 +
  353.12 +    static int[][] tints = new int[1][2];
  353.13 +    public static int twoInts() {
  353.14 +        return tints[0][0] + tints[0][0];
  353.15 +    }
  353.16 +    
  353.17      private static final Array[] ARR = { new Array(), new Array(), new Array() };
  353.18      
  353.19      private static Array[][] arr() {
  353.20 @@ -82,16 +92,35 @@
  353.21          }
  353.22          return sum;
  353.23      }
  353.24 -    public static int simple() {
  353.25 -        int[] arr = { 0, 1, 2, 3, 4, 5 };
  353.26 +    private static final int[] arr = { 0, 1, 2, 3, 4, 5 };
  353.27 +    public static int simple(boolean clone) {
  353.28 +        int[] ar;
  353.29 +        if (clone) {
  353.30 +            ar = arr.clone();
  353.31 +        } else {
  353.32 +            ar = arr;
  353.33 +        }
  353.34          
  353.35          int sum = 0;
  353.36 -        for (int a : arr) {
  353.37 +        for (int a : ar) {
  353.38              sum += a;
  353.39          }
  353.40          return sum;
  353.41      }
  353.42      
  353.43 +    public static String objectArrayClass() {
  353.44 +        return Object[].class.getName();
  353.45 +    }
  353.46 +    
  353.47 +    public static boolean instanceOfArray(Object obj) {
  353.48 +        return obj instanceof Object[];
  353.49 +    }
  353.50 +    
  353.51 +    public static int sum(int size) {
  353.52 +        int[] arr = new int[size];
  353.53 +        return arr[0] + arr[1];
  353.54 +    }
  353.55 +    
  353.56      static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
  353.57          while (count-- > 0) {
  353.58              dst[dstBegin++] = value[srcBegin++];
   354.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java	Wed Dec 05 10:03:58 2012 +0100
   354.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java	Sun Feb 03 07:48:42 2013 +0100
   354.3 @@ -18,7 +18,6 @@
   354.4  package org.apidesign.vm4brwsr;
   354.5  
   354.6  import javax.script.Invocable;
   354.7 -import javax.script.ScriptException;
   354.8  import static org.testng.Assert.*;
   354.9  import org.testng.annotations.BeforeClass;
  354.10  import org.testng.annotations.Test;
  354.11 @@ -28,9 +27,20 @@
  354.12   * @author Jaroslav Tulach <jtulach@netbeans.org>
  354.13   */
  354.14  public class ArrayTest {
  354.15 +    @Test public void intArrayShouldBeFilledWithZeroes() throws Exception {
  354.16 +            assertExec("0 + 0", Array.class, "sum__II", 
  354.17 +            Double.valueOf(0), 2
  354.18 +        );
  354.19 +    }
  354.20      @Test public void verifySimpleIntOperation() throws Exception {
  354.21 -            assertExec("CheckTheSum", Array.class, "simple__I", 
  354.22 -            Double.valueOf(15)
  354.23 +            assertExec("CheckTheSum", Array.class, "simple__IZ", 
  354.24 +            Double.valueOf(15), false
  354.25 +        );
  354.26 +    }
  354.27 +    
  354.28 +    @Test public void cloneOnArray() throws Exception {
  354.29 +            assertExec("CheckTheSum on clone", Array.class, "simple__IZ", 
  354.30 +            Double.valueOf(15), true
  354.31          );
  354.32      }
  354.33      
  354.34 @@ -43,10 +53,28 @@
  354.35              Double.valueOf(105)
  354.36          );
  354.37      }
  354.38 +
  354.39 +    @Test public void twoDoubles() throws Exception {
  354.40 +        assertExec("Elements are initialized", Array.class, "twoDoubles__D", 
  354.41 +            Double.valueOf(0)
  354.42 +        );
  354.43 +    }
  354.44 +    @Test public void twoInts() throws Exception {
  354.45 +        assertExec("Elements are initialized", Array.class, "twoInts__I", 
  354.46 +            Double.valueOf(0)
  354.47 +        );
  354.48 +    }
  354.49      
  354.50      @Test public void doesCopyArrayWork() throws Exception {
  354.51          assertExec("Returns 'a'", Array.class, "copyArray__C", Double.valueOf('a'));
  354.52      }
  354.53 +
  354.54 +    @Test public void verifyObjectArrayClass() throws Exception {
  354.55 +        assertExec("Returns 'Object[]'", Array.class, "objectArrayClass__Ljava_lang_String_2", Array.objectArrayClass());
  354.56 +    }
  354.57 +    @Test public void verifyInstanceOfArray() throws Exception {
  354.58 +        assertExec("Returns 'false'", Array.class, "instanceOfArray__ZLjava_lang_Object_2", Double.valueOf(0), "non-array");
  354.59 +    }
  354.60      
  354.61      private static CharSequence codeSeq;
  354.62      private static Invocable code;
   355.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ByteCodeToJavaScriptTest.java	Wed Dec 05 10:03:58 2012 +0100
   355.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ByteCodeToJavaScriptTest.java	Sun Feb 03 07:48:42 2013 +0100
   355.3 @@ -32,24 +32,24 @@
   355.4      @Test
   355.5      public void findMethodNameManglesObjectsCorrectly() {
   355.6          StringBuilder cnt = new StringBuilder();
   355.7 -        boolean[] hasReturn = { false };
   355.8 +        char[] returnType = { 'V' };
   355.9          String ret = ByteCodeToJavaScript.findMethodName(new String[] { 
  355.10              "StringTest", "replace", "(Ljava/lang/String;CC)Ljava/lang/String;"
  355.11 -        }, cnt, hasReturn);
  355.12 +        }, cnt, returnType);
  355.13          assertEquals(cnt.toString(), "000", "No doubles or longs");
  355.14 -        assertTrue(hasReturn[0], "Returns string");
  355.15 +        assertTrue(returnType[0] != 'V', "Returns string");
  355.16          assertEquals(ret, "replace__Ljava_lang_String_2Ljava_lang_String_2CC");
  355.17      }
  355.18  
  355.19      @Test
  355.20      public void manglingArrays() {
  355.21          StringBuilder cnt = new StringBuilder();
  355.22 -        boolean[] hasReturn = { false };
  355.23 +        char[] returnType = { 'V' };
  355.24          String ret = ByteCodeToJavaScript.findMethodName(new String[] { 
  355.25              "VMinVM", "toJavaScript", "([B)Ljava/lang/String;"
  355.26 -        }, cnt, hasReturn);
  355.27 +        }, cnt, returnType);
  355.28          assertEquals(cnt.toString(), "0", "No doubles or longs");
  355.29 -        assertTrue(hasReturn[0], "Returns string");
  355.30 +        assertTrue(returnType[0] != 'V', "Returns string");
  355.31          assertEquals(ret, "toJavaScript__Ljava_lang_String_2_3B");
  355.32      }
  355.33  }
   356.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   356.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/BytesLoader.java	Sun Feb 03 07:48:42 2013 +0100
   356.3 @@ -0,0 +1,76 @@
   356.4 +/**
   356.5 + * Back 2 Browser Bytecode Translator
   356.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   356.7 + *
   356.8 + * This program is free software: you can redistribute it and/or modify
   356.9 + * it under the terms of the GNU General Public License as published by
  356.10 + * the Free Software Foundation, version 2 of the License.
  356.11 + *
  356.12 + * This program is distributed in the hope that it will be useful,
  356.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  356.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  356.15 + * GNU General Public License for more details.
  356.16 + *
  356.17 + * You should have received a copy of the GNU General Public License
  356.18 + * along with this program. Look for COPYING file in the top folder.
  356.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  356.20 + */
  356.21 +package org.apidesign.vm4brwsr;
  356.22 +
  356.23 +import java.io.IOException;
  356.24 +import java.io.InputStream;
  356.25 +import java.net.URL;
  356.26 +import java.util.Enumeration;
  356.27 +import java.util.Set;
  356.28 +import java.util.TreeSet;
  356.29 +
  356.30 +/**
  356.31 + *
  356.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  356.33 + */
  356.34 +public final class BytesLoader {
  356.35 +    private static Set<String> requested = new TreeSet<String>();
  356.36 +
  356.37 +    public byte[] get(String name) throws IOException {
  356.38 +        if (!requested.add(name)) {
  356.39 +            throw new IllegalStateException("Requested for second time: " + name);
  356.40 +        }
  356.41 +        byte[] arr = readClass(name);
  356.42 +        /*
  356.43 +        System.err.print("loader['" + name + "'] = [");
  356.44 +        for (int i = 0; i < arr.length; i++) {
  356.45 +        if (i > 0) {
  356.46 +        System.err.print(", ");
  356.47 +        }
  356.48 +        System.err.print(arr[i]);
  356.49 +        }
  356.50 +        System.err.println("]");
  356.51 +         */
  356.52 +        return arr;
  356.53 +    }
  356.54 +
  356.55 +    static byte[] readClass(String name) throws IOException {
  356.56 +        URL u = null;
  356.57 +        Enumeration<URL> en = BytesLoader.class.getClassLoader().getResources(name);
  356.58 +        while (en.hasMoreElements()) {
  356.59 +            u = en.nextElement();
  356.60 +        }
  356.61 +        if (u == null) {
  356.62 +            throw new IOException("Can't find " + name);
  356.63 +        }
  356.64 +        try (InputStream is = u.openStream()) {
  356.65 +            byte[] arr;
  356.66 +            arr = new byte[is.available()];
  356.67 +            int offset = 0;
  356.68 +            while (offset < arr.length) {
  356.69 +                int len = is.read(arr, offset, arr.length - offset);
  356.70 +                if (len == -1) {
  356.71 +                    throw new IOException("Can't read " + name);
  356.72 +                }
  356.73 +                offset += len;
  356.74 +            }
  356.75 +            return arr;
  356.76 +        }
  356.77 +    }
  356.78 +    
  356.79 +}
   357.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java	Wed Dec 05 10:03:58 2012 +0100
   357.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java	Sun Feb 03 07:48:42 2013 +0100
   357.3 @@ -74,6 +74,16 @@
   357.4      @Test public void jsNewInstance() throws Exception {
   357.5          assertExec("Check new instance", Classes.class, "newInstance__Z", Double.valueOf(1));
   357.6      }
   357.7 +    @Test public void javaNoNewInstance() throws Exception {
   357.8 +        assertEquals("java.lang.InstantiationException:java.lang.Float", 
   357.9 +            Classes.newInstanceNoPubConstructor()
  357.10 +        );
  357.11 +    }
  357.12 +    @Test public void jsNoNewInstance() throws Exception {
  357.13 +        assertExec("Check problems with new instance", Classes.class, "newInstanceNoPubConstructor__Ljava_lang_String_2", 
  357.14 +            "java.lang.InstantiationException:java.lang.Float"
  357.15 +        );
  357.16 +    }
  357.17      @Test public void jsAnnotation() throws Exception {
  357.18          assertExec("Check class annotation", Classes.class, "getMarker__I", Double.valueOf(10));
  357.19      }
  357.20 @@ -92,6 +102,11 @@
  357.21              "java.io.IOException", true, "name"
  357.22          );
  357.23      }
  357.24 +    @Test public void jsInvokeParamMethod() throws Exception {
  357.25 +        assertExec("sums two numbers via reflection", Classes.class, 
  357.26 +            "reflectiveSum__III", Double.valueOf(5), 2, 3
  357.27 +        );
  357.28 +    }
  357.29      @Test public void javaFindMethod() throws Exception {
  357.30          assertEquals(Classes.reflectiveMethodCall(false, "name"), "java.io.IOException", "Calls the name() method via reflection");
  357.31      }
  357.32 @@ -101,6 +116,18 @@
  357.33              "java.io.IOException", false, "name"
  357.34          );
  357.35      }
  357.36 +    @Test public void primitiveReturnType() throws Exception {
  357.37 +        assertExec("Tries to get an integer via reflection", Classes.class, 
  357.38 +            "primitiveType__Ljava_lang_String_2Ljava_lang_String_2", 
  357.39 +            Classes.primitiveType("primitive"), "primitive"
  357.40 +        );
  357.41 +    }
  357.42 +    @Test public void primitiveBoolReturnType() throws Exception {
  357.43 +        assertExec("Tries to get an integer via reflection", Classes.class, 
  357.44 +            "primitiveType__Ljava_lang_String_2Ljava_lang_String_2", 
  357.45 +            Classes.primitiveType("primitiveB"), "primitiveB"
  357.46 +        );
  357.47 +    }
  357.48      @Test public void javaAnnotatedMethod() throws Exception {
  357.49          assertEquals(Classes.reflectiveMethodCall(false, null), "java.io.IOException", "Calls the name() method via reflection");
  357.50      }
  357.51 @@ -110,6 +137,32 @@
  357.52              "java.io.IOException", false, null
  357.53          );
  357.54      }
  357.55 +    @Test public void jsClassParam() throws Exception {
  357.56 +        assertExec("Calls the nameOfIO()", Classes.class, 
  357.57 +            "nameOfIO__Ljava_lang_String_2", 
  357.58 +            "java.io.IOException"
  357.59 +        );
  357.60 +    }
  357.61 +    @Test public void noInterface() throws Exception {
  357.62 +        assertExec("Calls Class.isInterface", Classes.class, 
  357.63 +            "isInterface__ZLjava_lang_String_2", 
  357.64 +            0.0, "java.lang.String"
  357.65 +        );
  357.66 +    }
  357.67 +    /*
  357.68 +    @Test public void isInterface() throws Exception {
  357.69 +        assertExec("Calls Class.isInterface", Classes.class, 
  357.70 +            "isInterface__ZLjava_lang_String_2", 
  357.71 +            1.0, "java.lang.Runnable"
  357.72 +        );
  357.73 +    }
  357.74 +    */
  357.75 +    @Test public void integerType() throws Exception {
  357.76 +        assertExec("Computes the type", Classes.class, 
  357.77 +            "intType__Ljava_lang_String_2", 
  357.78 +            Classes.intType()
  357.79 +        );
  357.80 +    }
  357.81      
  357.82      private static CharSequence codeSeq;
  357.83      private static Invocable code;
   358.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java	Wed Dec 05 10:03:58 2012 +0100
   358.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java	Sun Feb 03 07:48:42 2013 +0100
   358.3 @@ -30,6 +30,18 @@
   358.4  @ClassesMarker(number = 10)
   358.5  @ClassesNamer(name = "my text")
   358.6  public class Classes {
   358.7 +    public static String nameOfIO() {
   358.8 +        return nameFor(IOException.class);
   358.9 +    }
  358.10 +    
  358.11 +    private static String nameFor(Class<?> c) {
  358.12 +        return c.getName();
  358.13 +    }
  358.14 +    
  358.15 +    public static boolean isInterface(String s) throws ClassNotFoundException {
  358.16 +        return Class.forName(s).isInterface();
  358.17 +    }
  358.18 +    
  358.19      public static boolean equalsClassesOfExceptions() {
  358.20          return MalformedURLException.class.getSuperclass() == IOException.class;
  358.21      }
  358.22 @@ -60,6 +72,14 @@
  358.23          }
  358.24          throw new IllegalStateException("Not a subtype: " + ioe);
  358.25      }
  358.26 +    public static String newInstanceNoPubConstructor() throws Exception {
  358.27 +        try {
  358.28 +            Float f = Float.class.newInstance();
  358.29 +            return "wrong, can't instantiate: " + f;
  358.30 +        } catch (Exception ex) {
  358.31 +            return (ex.getClass().getName() + ":" + ex.getMessage()).toString().toString();
  358.32 +        }
  358.33 +    }
  358.34      public static int getMarker() {
  358.35          if (!Classes.class.isAnnotationPresent(ClassesMarker.class)) {
  358.36              return -2;
  358.37 @@ -80,6 +100,21 @@
  358.38          return null;
  358.39      }
  358.40      
  358.41 +    public static String intType() {
  358.42 +        return Integer.TYPE.getName();
  358.43 +    }
  358.44 +    
  358.45 +    public static int primitive() {
  358.46 +        return 1;
  358.47 +    }
  358.48 +    public static boolean primitiveB() {
  358.49 +        return true;
  358.50 +    }
  358.51 +    
  358.52 +    public static String primitiveType(String method) throws Exception {
  358.53 +        return reflectiveMethodCall(false, method).getClass().getName();
  358.54 +    }
  358.55 +    
  358.56      @JavaScriptBody(args = "msg", body = "throw msg;")
  358.57      private static native void thrw(String msg);
  358.58      
  358.59 @@ -111,4 +146,9 @@
  358.60          }
  358.61          return find.invoke(null);
  358.62      }
  358.63 +    
  358.64 +    public static int reflectiveSum(int a, int b) throws Exception {
  358.65 +        Method m = StaticMethod.class.getMethod("sum", int.class, int.class);
  358.66 +        return (int) m.invoke(null, a, b);
  358.67 +    }
  358.68  }
   359.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   359.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Exceptions.java	Sun Feb 03 07:48:42 2013 +0100
   359.3 @@ -0,0 +1,88 @@
   359.4 +/**
   359.5 + * Back 2 Browser Bytecode Translator
   359.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   359.7 + *
   359.8 + * This program is free software: you can redistribute it and/or modify
   359.9 + * it under the terms of the GNU General Public License as published by
  359.10 + * the Free Software Foundation, version 2 of the License.
  359.11 + *
  359.12 + * This program is distributed in the hope that it will be useful,
  359.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  359.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  359.15 + * GNU General Public License for more details.
  359.16 + *
  359.17 + * You should have received a copy of the GNU General Public License
  359.18 + * along with this program. Look for COPYING file in the top folder.
  359.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  359.20 + */
  359.21 +package org.apidesign.vm4brwsr;
  359.22 +
  359.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  359.24 +
  359.25 +/**
  359.26 + *
  359.27 + * @author tom
  359.28 + */
  359.29 +public class Exceptions {
  359.30 +    private Exceptions() {
  359.31 +    }
  359.32 +
  359.33 +    public static int methodWithTryCatchNoThrow() {
  359.34 +        int res = 0;
  359.35 +        try {
  359.36 +            res = 1;
  359.37 +        } catch (IllegalArgumentException e) {
  359.38 +            res = 2;
  359.39 +        }
  359.40 +        //join point
  359.41 +        return res;
  359.42 +    }
  359.43 +
  359.44 +    public static int methodWithTryCatchThrow() {
  359.45 +        int res = 0;
  359.46 +        try {
  359.47 +            res = 1;
  359.48 +            throw new IllegalArgumentException();
  359.49 +        } catch (IllegalArgumentException e) {
  359.50 +            res = 2;
  359.51 +        }
  359.52 +        //join point
  359.53 +        return res;
  359.54 +    }
  359.55 +    
  359.56 +    @JavaScriptBody(args = "msg", body = "throw msg;")
  359.57 +    public static void thrw(String msg) {}
  359.58 +    
  359.59 +    public static String catchThrowableCatchesAll() {
  359.60 +        try {
  359.61 +            thrw("Hello!");
  359.62 +            return "Not here!";
  359.63 +        } catch (Throwable ex) {
  359.64 +            return ex.getMessage();
  359.65 +        }
  359.66 +    }
  359.67 +
  359.68 +    public static String newInstance(String n) {
  359.69 +        try {
  359.70 +            Class c;
  359.71 +            try {
  359.72 +                c = Class.forName(n);
  359.73 +            } catch (ClassNotFoundException ex) {
  359.74 +                return ("CNFE:" + ex.getMessage()).toString();
  359.75 +            }
  359.76 +            return c.newInstance().getClass().getName();
  359.77 +        } catch (InstantiationException | IllegalAccessException ex) {
  359.78 +            return ex.getMessage();
  359.79 +        }
  359.80 +    }
  359.81 +    
  359.82 +    private static int counter;
  359.83 +    public static int readCounter(String n) throws ClassNotFoundException {
  359.84 +        try {
  359.85 +            Class.forName(n);
  359.86 +        } finally {
  359.87 +            counter++;
  359.88 +        }
  359.89 +        return counter;
  359.90 +    }
  359.91 +}
   360.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   360.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ExceptionsTest.java	Sun Feb 03 07:48:42 2013 +0100
   360.3 @@ -0,0 +1,121 @@
   360.4 +/**
   360.5 + * Back 2 Browser Bytecode Translator
   360.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   360.7 + *
   360.8 + * This program is free software: you can redistribute it and/or modify
   360.9 + * it under the terms of the GNU General Public License as published by
  360.10 + * the Free Software Foundation, version 2 of the License.
  360.11 + *
  360.12 + * This program is distributed in the hope that it will be useful,
  360.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  360.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  360.15 + * GNU General Public License for more details.
  360.16 + *
  360.17 + * You should have received a copy of the GNU General Public License
  360.18 + * along with this program. Look for COPYING file in the top folder.
  360.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  360.20 + */
  360.21 +package org.apidesign.vm4brwsr;
  360.22 +
  360.23 +import javax.script.Invocable;
  360.24 +import javax.script.ScriptException;
  360.25 +import static org.testng.Assert.*;
  360.26 +import org.testng.annotations.BeforeClass;
  360.27 +import org.testng.annotations.Test;
  360.28 +
  360.29 +/**
  360.30 + *
  360.31 + * @author Tomas Zezula <tzezula@netbeans.org>
  360.32 + */
  360.33 +public class ExceptionsTest {
  360.34 +    @Test
  360.35 +    public void verifyMethodWithTryCatchNoThrow() throws Exception {
  360.36 +            assertExec(
  360.37 +                    "No throw",
  360.38 +                    Exceptions.class,
  360.39 +                    "methodWithTryCatchNoThrow__I",
  360.40 +                    new Double(1.0));
  360.41 +    }
  360.42 +
  360.43 +    @Test
  360.44 +    public void catchJavaScriptStringAsThrowable() throws Exception {
  360.45 +        assertExec(
  360.46 +            "Throw hello!",
  360.47 +            Exceptions.class,
  360.48 +            "catchThrowableCatchesAll__Ljava_lang_String_2",
  360.49 +            "Hello!"
  360.50 +        );
  360.51 +    }
  360.52 +
  360.53 +    @Test
  360.54 +    public void verifyMethodWithTryCatchThrow() throws Exception {
  360.55 +            assertExec(
  360.56 +                    "Throw",
  360.57 +                    Exceptions.class,
  360.58 +                    "methodWithTryCatchThrow__I",
  360.59 +                    new Double(2.0));
  360.60 +    }
  360.61 +    
  360.62 +    @Test public void createObject() throws Exception {
  360.63 +        assertExec("Object created", Exceptions.class, 
  360.64 +            "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
  360.65 +            "java.lang.Object",
  360.66 +            "java.lang.Object"
  360.67 +        );
  360.68 +    }
  360.69 +
  360.70 +    @Test public void createFloatFails() throws Exception {
  360.71 +        assertExec("Float not created", Exceptions.class, 
  360.72 +            "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
  360.73 +            "java.lang.Float",
  360.74 +            "java.lang.Float"
  360.75 +        );
  360.76 +    }
  360.77 +
  360.78 +    @Test public void createUnknownFails() throws Exception {
  360.79 +        assertExec("Object created", Exceptions.class, 
  360.80 +            "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
  360.81 +            "CNFE:org.apidesign.Unknown",
  360.82 +            "org.apidesign.Unknown"
  360.83 +        );
  360.84 +    }
  360.85 +    
  360.86 +    @Test public void testThreeCalls() throws Exception {
  360.87 +        Object vm = code.invokeFunction("bck2brwsr");
  360.88 +        Object clazz = code.invokeMethod(vm, "loadClass", Exceptions.class.getName());
  360.89 +        
  360.90 +        String method = "readCounter__ILjava_lang_String_2";
  360.91 +        
  360.92 +        try {
  360.93 +            Object ret = code.invokeMethod(clazz, method, "org.apidesign.Unknown");
  360.94 +            fail("We expect an CNFE!");
  360.95 +        } catch (ScriptException scriptException) {
  360.96 +            // script exception should be OK
  360.97 +        }
  360.98 +        {
  360.99 +            // 2nd invocation
 360.100 +            Object ret = code.invokeMethod(clazz, method, "java.lang.String");
 360.101 +            assertEquals(ret, Double.valueOf(2));
 360.102 +        }
 360.103 +        {
 360.104 +            // 3rd invocation
 360.105 +            Object ret = code.invokeMethod(clazz, method, "java.lang.Integer");
 360.106 +            assertEquals(ret, Double.valueOf(3));
 360.107 +        }
 360.108 +    }
 360.109 +    
 360.110 +    private static CharSequence codeSeq;
 360.111 +    private static Invocable code;
 360.112 +    
 360.113 +    @BeforeClass 
 360.114 +    public void compileTheCode() throws Exception {
 360.115 +        StringBuilder sb = new StringBuilder();
 360.116 +        code = StaticMethodTest.compileClass(sb, 
 360.117 +            "org/apidesign/vm4brwsr/Exceptions"
 360.118 +        );
 360.119 +        codeSeq = sb;
 360.120 +    }
 360.121 +    private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception {
 360.122 +        StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
 360.123 +    }
 360.124 +}
   361.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Instance.java	Wed Dec 05 10:03:58 2012 +0100
   361.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Instance.java	Sun Feb 03 07:48:42 2013 +0100
   361.3 @@ -125,4 +125,11 @@
   361.4      public static boolean iofObject() {
   361.5          return jsObj() instanceof Object;
   361.6      }
   361.7 +    
   361.8 +    public static int jscall() {
   361.9 +        return jsgetbytes(new Instance());
  361.10 +    }
  361.11 +    
  361.12 +    @JavaScriptBody(args = { "instance" }, body = "return instance.getByte__B();")
  361.13 +    private static native int jsgetbytes(Instance instance);
  361.14  }
   362.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java	Wed Dec 05 10:03:58 2012 +0100
   362.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java	Sun Feb 03 07:48:42 2013 +0100
   362.3 @@ -131,6 +131,14 @@
   362.4              Double.valueOf(1)
   362.5          );
   362.6      }
   362.7 +
   362.8 +    @Test public void jsCallingConvention() throws Exception {
   362.9 +        assertExec(
  362.10 +            "Pointer to 'this' is passed automatically (and not as a first argument)",
  362.11 +            Instance.class, "jscall__I",
  362.12 +            Double.valueOf(31)
  362.13 +        );
  362.14 +    }
  362.15      
  362.16      protected String startCompilationWith() {
  362.17          return "org/apidesign/vm4brwsr/Instance";
   363.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Wed Dec 05 10:03:58 2012 +0100
   363.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Sun Feb 03 07:48:42 2013 +0100
   363.3 @@ -161,7 +161,8 @@
   363.4  
   363.5          Object ret = null;
   363.6          try {
   363.7 -            ret = code.invokeFunction(clazz.getName().replace('.', '_'), true);
   363.8 +            ret = code.invokeFunction("bck2brwsr");
   363.9 +            ret = code.invokeMethod(ret, "loadClass", clazz.getName());
  363.10              ret = code.invokeMethod(ret, method, args);
  363.11          } catch (ScriptException ex) {
  363.12              fail("Execution failed in\n" + StaticMethodTest.dumpJS(codeSeq), ex);
   364.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   364.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Script.java	Sun Feb 03 07:48:42 2013 +0100
   364.3 @@ -0,0 +1,31 @@
   364.4 +/**
   364.5 + * Back 2 Browser Bytecode Translator
   364.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   364.7 + *
   364.8 + * This program is free software: you can redistribute it and/or modify
   364.9 + * it under the terms of the GNU General Public License as published by
  364.10 + * the Free Software Foundation, version 2 of the License.
  364.11 + *
  364.12 + * This program is distributed in the hope that it will be useful,
  364.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  364.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  364.15 + * GNU General Public License for more details.
  364.16 + *
  364.17 + * You should have received a copy of the GNU General Public License
  364.18 + * along with this program. Look for COPYING file in the top folder.
  364.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  364.20 + */
  364.21 +package org.apidesign.vm4brwsr;
  364.22 +
  364.23 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
  364.24 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  364.25 +
  364.26 +/** Test to verify external scripts are processed in lazy mode.
  364.27 + *
  364.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  364.29 + */
  364.30 +@ExtraJavaScript(resource = "/org/apidesign/vm4brwsr/ko.js")
  364.31 +public class Script {
  364.32 +    @JavaScriptBody(args = {  }, body = "return ko !== null;")
  364.33 +    public static native boolean checkNotNull();
  364.34 +}
   365.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java	Wed Dec 05 10:03:58 2012 +0100
   365.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java	Sun Feb 03 07:48:42 2013 +0100
   365.3 @@ -106,6 +106,11 @@
   365.4          throw new IllegalStateException();
   365.5      }
   365.6      
   365.7 +    public static String castNull(boolean n) {
   365.8 +        Object value = n ? null : "Ahoj";
   365.9 +        return (String)value;
  365.10 +    }
  365.11 +    
  365.12      public static String swtch(int what) {
  365.13          switch (what) {
  365.14              case 0: return "Jarda";
   366.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java	Wed Dec 05 10:03:58 2012 +0100
   366.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java	Sun Feb 03 07:48:42 2013 +0100
   366.3 @@ -20,6 +20,9 @@
   366.4  import java.io.File;
   366.5  import java.io.FileWriter;
   366.6  import java.io.IOException;
   366.7 +import java.io.InputStream;
   366.8 +import java.net.URL;
   366.9 +import java.util.Enumeration;
  366.10  import javax.script.Invocable;
  366.11  import javax.script.ScriptEngine;
  366.12  import javax.script.ScriptEngineManager;
  366.13 @@ -75,6 +78,89 @@
  366.14              3.0d, 1l
  366.15          );
  366.16      }
  366.17 +    
  366.18 +    @Test public void rintNegativeUp() throws Exception {
  366.19 +        final double cnts = -453904.634;
  366.20 +        assertExec(
  366.21 +            "Should round up to end with 5",
  366.22 +            Math.class, "rint__DD", 
  366.23 +            -453905.0, cnts
  366.24 +        );
  366.25 +    }
  366.26 +
  366.27 +    @Test public void rintNegativeDown() throws Exception {
  366.28 +        final double cnts = -453904.434;
  366.29 +        assertExec(
  366.30 +            "Should round up to end with 4",
  366.31 +            Math.class, "rint__DD", 
  366.32 +            -453904.0, cnts
  366.33 +        );
  366.34 +    }
  366.35 +
  366.36 +    @Test public void rintPositiveUp() throws Exception {
  366.37 +        final double cnts = 453904.634;
  366.38 +        assertExec(
  366.39 +            "Should round up to end with 5",
  366.40 +            Math.class, "rint__DD", 
  366.41 +            453905.0, cnts
  366.42 +        );
  366.43 +    }
  366.44 +    @Test public void rintPositiveDown() throws Exception {
  366.45 +        final double cnts = 453904.434;
  366.46 +        assertExec(
  366.47 +            "Should round up to end with 4",
  366.48 +            Math.class, "rint__DD", 
  366.49 +            453904.0, cnts
  366.50 +        );
  366.51 +    }
  366.52 +    @Test public void rintOneHalf() throws Exception {
  366.53 +        final double cnts = 1.5;
  366.54 +        assertExec(
  366.55 +            "Should round up to end with 2",
  366.56 +            Math.class, "rint__DD", 
  366.57 +            2.0, cnts
  366.58 +        );
  366.59 +    }
  366.60 +    @Test public void rintNegativeOneHalf() throws Exception {
  366.61 +        final double cnts = -1.5;
  366.62 +        assertExec(
  366.63 +            "Should round up to end with 2",
  366.64 +            Math.class, "rint__DD", 
  366.65 +            -2.0, cnts
  366.66 +        );
  366.67 +    }
  366.68 +    @Test public void rintTwoAndHalf() throws Exception {
  366.69 +        final double cnts = 2.5;
  366.70 +        assertExec(
  366.71 +            "Should round up to end with 2",
  366.72 +            Math.class, "rint__DD", 
  366.73 +            2.0, cnts
  366.74 +        );
  366.75 +    }
  366.76 +    @Test public void rintNegativeTwoOneHalf() throws Exception {
  366.77 +        final double cnts = -2.5;
  366.78 +        assertExec(
  366.79 +            "Should round up to end with 2",
  366.80 +            Math.class, "rint__DD", 
  366.81 +            -2.0, cnts
  366.82 +        );
  366.83 +    }
  366.84 +
  366.85 +    @Test public void ieeeReminder1() throws Exception {
  366.86 +        assertExec(
  366.87 +            "Same result 1",
  366.88 +            Math.class, "IEEEremainder__DDD", 
  366.89 +            Math.IEEEremainder(10.0, 4.5), 10.0, 4.5
  366.90 +        );
  366.91 +    }
  366.92 +
  366.93 +    @Test public void ieeeReminder2() throws Exception {
  366.94 +        assertExec(
  366.95 +            "Same result 1",
  366.96 +            Math.class, "IEEEremainder__DDD", 
  366.97 +            Math.IEEEremainder(Integer.MAX_VALUE, -4.5), Integer.MAX_VALUE, -4.5
  366.98 +        );
  366.99 +    }
 366.100  
 366.101      @Test public void divAndRound() throws Exception {
 366.102          assertExec(
 366.103 @@ -238,6 +324,13 @@
 366.104          );
 366.105      }
 366.106      
 366.107 +    @Test public void checkNullCast() throws Exception {
 366.108 +        assertExec("Null can be cast to any type",
 366.109 +            StaticMethod.class, "castNull__Ljava_lang_String_2Z", 
 366.110 +            null, true
 366.111 +        );
 366.112 +    }
 366.113 +    
 366.114      private static CharSequence codeSeq;
 366.115      private static Invocable code;
 366.116      
 366.117 @@ -262,7 +355,8 @@
 366.118      ) throws Exception {
 366.119          Object ret = null;
 366.120          try {
 366.121 -            ret = toRun.invokeFunction(clazz.getName().replace('.', '_'), true);
 366.122 +            ret = toRun.invokeFunction("bck2brwsr");
 366.123 +            ret = toRun.invokeMethod(ret, "loadClass", clazz.getName());
 366.124              ret = toRun.invokeMethod(ret, method, args);
 366.125          } catch (ScriptException ex) {
 366.126              fail("Execution failed in\n" + dumpJS(theCode), ex);
 366.127 @@ -288,7 +382,7 @@
 366.128          if (sb == null) {
 366.129              sb = new StringBuilder();
 366.130          }
 366.131 -        GenJS.compile(sb, names);
 366.132 +        Bck2Brwsr.generate(sb, new EmulationResources(), names);
 366.133          ScriptEngineManager sem = new ScriptEngineManager();
 366.134          ScriptEngine js = sem.getEngineByExtension("js");
 366.135          if (eng != null) {
 366.136 @@ -313,4 +407,21 @@
 366.137          w.close();
 366.138          return new StringBuilder(f.getPath());
 366.139      }
 366.140 +    private static class EmulationResources implements Bck2Brwsr.Resources {
 366.141 +        @Override
 366.142 +        public InputStream get(String name) throws IOException {
 366.143 +            Enumeration<URL> en = StaticMethodTest.class.getClassLoader().getResources(name);
 366.144 +            URL u = null;
 366.145 +            while (en.hasMoreElements()) {
 366.146 +                u = en.nextElement();
 366.147 +            }
 366.148 +            if (u == null) {
 366.149 +                throw new IOException("Can't find " + name);
 366.150 +            }
 366.151 +            if (u.toExternalForm().contains("rt.jar!")) {
 366.152 +                throw new IOException("No emulation for " + u);
 366.153 +            }
 366.154 +            return u.openStream();
 366.155 +        }
 366.156 +    }
 366.157  }
   367.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java	Wed Dec 05 10:03:58 2012 +0100
   367.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java	Sun Feb 03 07:48:42 2013 +0100
   367.3 @@ -68,6 +68,15 @@
   367.4          return chars('a', (char)30, 'b') instanceof String;
   367.5      }
   367.6      
   367.7 +    public static String getBytes(String s) {
   367.8 +        byte[] arr = s.getBytes();
   367.9 +        StringBuilder sb = new StringBuilder();
  367.10 +        for (int i = 0; i < arr.length; i++) {
  367.11 +            sb.append(arr[i]).append(" ");
  367.12 +        }
  367.13 +        return sb.toString().toString();
  367.14 +    }
  367.15 +    
  367.16      public static String insertBuffer() {
  367.17          StringBuilder sb = new StringBuilder();
  367.18          sb.append("Jardo!");
  367.19 @@ -109,6 +118,10 @@
  367.20      public static String concatStrings() {
  367.21          return (toStringTest(1) + "\\\n\r\t").toString();
  367.22      }
  367.23 +    
  367.24 +    public static int compare(String a, String b) {
  367.25 +        return a.compareTo(b);
  367.26 +    }
  367.27  
  367.28      @Override
  367.29      public String toString() {
   368.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java	Wed Dec 05 10:03:58 2012 +0100
   368.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java	Sun Feb 03 07:48:42 2013 +0100
   368.3 @@ -75,6 +75,16 @@
   368.4          );
   368.5      }
   368.6  
   368.7 +    @Test public void getBytes() throws Exception {
   368.8 +        final String horse = "Žluťoučký kůň";
   368.9 +        final String expected = StringSample.getBytes(horse);
  368.10 +        assertExec(
  368.11 +            "Bytes look simplar",
  368.12 +            StringSample.class, "getBytes__Ljava_lang_String_2Ljava_lang_String_2",
  368.13 +            expected, horse
  368.14 +        );
  368.15 +    }
  368.16 +
  368.17      @Test(timeOut=10000) public void toStringConcatenation() throws Exception {
  368.18          assertExec(
  368.19              "Five executions should generate 5Hello World!",
  368.20 @@ -173,6 +183,16 @@
  368.21          );
  368.22          
  368.23      }
  368.24 +
  368.25 +    @Test public void compareStrings() throws Exception {
  368.26 +        int res = StringSample.compare("Saab", "Volvo");
  368.27 +        assertExec(
  368.28 +            "Saab finished sooner than Volvo",
  368.29 +            StringSample.class, "compare__ILjava_lang_String_2Ljava_lang_String_2",
  368.30 +            Double.valueOf(res), "Saab", "Volvo"
  368.31 +        );
  368.32 +        
  368.33 +    }
  368.34      
  368.35      private static CharSequence codeSeq;
  368.36      private static Invocable code;
   369.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMLazy.java	Wed Dec 05 10:03:58 2012 +0100
   369.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   369.3 @@ -1,68 +0,0 @@
   369.4 -/**
   369.5 - * Back 2 Browser Bytecode Translator
   369.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   369.7 - *
   369.8 - * This program is free software: you can redistribute it and/or modify
   369.9 - * it under the terms of the GNU General Public License as published by
  369.10 - * the Free Software Foundation, version 2 of the License.
  369.11 - *
  369.12 - * This program is distributed in the hope that it will be useful,
  369.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  369.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  369.15 - * GNU General Public License for more details.
  369.16 - *
  369.17 - * You should have received a copy of the GNU General Public License
  369.18 - * along with this program. Look for COPYING file in the top folder.
  369.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  369.20 - */
  369.21 -package org.apidesign.vm4brwsr;
  369.22 -
  369.23 -import java.io.ByteArrayInputStream;
  369.24 -import java.io.IOException;
  369.25 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  369.26 -
  369.27 -/**
  369.28 - *
  369.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  369.30 - */
  369.31 -class VMLazy extends ByteCodeToJavaScript {
  369.32 -    private final Object vm;
  369.33 -    private final Object global;
  369.34 -    
  369.35 -    private VMLazy(Object global, Object vm, Appendable out) {
  369.36 -        super(out);
  369.37 -        this.vm = vm;
  369.38 -        this.global = global;
  369.39 -    }
  369.40 -    
  369.41 -    static String toJavaScript(Object global, Object vm, byte[] is) throws IOException {
  369.42 -        StringBuilder sb = new StringBuilder();
  369.43 -        new VMLazy(global, vm, sb).compile(new ByteArrayInputStream(is));
  369.44 -        return sb.toString().toString();
  369.45 -    }
  369.46 -
  369.47 -    @JavaScriptBody(args = { "self", "n" }, 
  369.48 -        body=
  369.49 -          "var cls = n.replace__Ljava_lang_String_2CC(n,'/','_').toString();"
  369.50 -        + "var glb = self.fld_global;"
  369.51 -        + "var vm = self.fld_vm;"
  369.52 -        + "if (glb[cls]) return false;"
  369.53 -        + "glb[cls] = function() {"
  369.54 -        + "  return vm.loadClass(n,cls);"
  369.55 -        + "};"
  369.56 -        + "return true;"
  369.57 -    )
  369.58 -    @Override
  369.59 -    protected boolean requireReference(String internalClassName) {
  369.60 -        throw new UnsupportedOperationException();
  369.61 -    }
  369.62 -
  369.63 -    @Override
  369.64 -    protected void requireScript(String resourcePath) {
  369.65 -    }
  369.66 -
  369.67 -    @Override
  369.68 -    protected String assignClass(String className) {
  369.69 -        return "arguments[0][arguments[1]]=";
  369.70 -    }
  369.71 -}
   370.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java	Wed Dec 05 10:03:58 2012 +0100
   370.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java	Sun Feb 03 07:48:42 2013 +0100
   370.3 @@ -17,8 +17,6 @@
   370.4   */
   370.5  package org.apidesign.vm4brwsr;
   370.6  
   370.7 -import java.io.IOException;
   370.8 -import java.io.InputStream;
   370.9  import javax.script.Invocable;
  370.10  import javax.script.ScriptContext;
  370.11  import javax.script.ScriptEngine;
  370.12 @@ -40,53 +38,46 @@
  370.13      @BeforeClass
  370.14      public void compileTheCode() throws Exception {
  370.15          StringBuilder sb = new StringBuilder();
  370.16 -        
  370.17 -        sb.append("\nfunction test(clazz, as, method) {");
  370.18 -        sb.append("\n  var l = new lazyVM(this);");
  370.19 -        sb.append("\n  var c = l.loadClass(clazz, as);");
  370.20 +        sb.append("\nvar data = {};");
  370.21 +        sb.append("\nfunction test(clazz, method) {");
  370.22 +        sb.append("\n  if (!data.bck2brwsr) data.bck2brwsr = bck2brwsr(function(name) { return loader.get(name); });");
  370.23 +        sb.append("\n  var c = data.bck2brwsr.loadClass(clazz);");
  370.24          sb.append("\n  return c[method]();");
  370.25          sb.append("\n}");
  370.26          
  370.27 -        
  370.28 -        sb.append("\nfunction lazyVM(global) {");
  370.29 -        sb.append("\n  var self = this;");
  370.30 -        sb.append("\n  var glb = global;");
  370.31 -        sb.append("\n  lazyVM.prototype.loadClass = function(res, name) {");
  370.32 -        sb.append("\n    var script = org_apidesign_vm4brwsr_VMLazy(true)."
  370.33 -            + "toJavaScript__Ljava_lang_String_2Ljava_lang_Object_2Ljava_lang_Object_2_3B("
  370.34 -            + "  glb, self,"
  370.35 -            + "  loader.get(res + '.class')"
  370.36 -            + ");");
  370.37 -        sb.append("\n    try {");
  370.38 -        sb.append("\n      new Function(script)(glb, name);");
  370.39 -        sb.append("\n    } catch (ex) {");
  370.40 -        sb.append("\n      throw 'Cannot compile ' + res + ' error: ' + ex + ' script:\\n' + script;");
  370.41 -        sb.append("\n    };");
  370.42 -        sb.append("\n    return glb[name](true);");
  370.43 -        sb.append("\n  };");
  370.44 -        sb.append("\n");
  370.45 -        sb.append("\n}\n");
  370.46 -        
  370.47 +        sb.append("\nfunction checkKO() {");
  370.48 +        sb.append("\n  return ko !== null;");
  370.49 +        sb.append("\n}");
  370.50 +       
  370.51          ScriptEngine[] arr = { null };
  370.52          code = StaticMethodTest.compileClass(sb, arr,
  370.53 -            "org/apidesign/vm4brwsr/VMLazy"
  370.54 +            "org/apidesign/vm4brwsr/VM"
  370.55          );
  370.56 -        arr[0].getContext().setAttribute("loader", new FindBytes(), ScriptContext.ENGINE_SCOPE);
  370.57 +        arr[0].getContext().setAttribute("loader", new BytesLoader(), ScriptContext.ENGINE_SCOPE);
  370.58          codeSeq = sb;
  370.59      }
  370.60      
  370.61      @Test public void invokeStaticMethod() throws Exception {
  370.62          assertExec("Trying to get -1", "test", Double.valueOf(-1),
  370.63 -            "org/apidesign/vm4brwsr/StaticMethod", "org_apidesign_vm4brwsr_StaticMethod", "minusOne__I"
  370.64 +            StaticMethod.class.getName(), "minusOne__I"
  370.65          );
  370.66      }
  370.67  
  370.68      @Test public void loadDependantClass() throws Exception {
  370.69 -        assertExec("Trying to get zero", "test", Double.valueOf(0),
  370.70 -            "org/apidesign/vm4brwsr/InstanceSub", "org_apidesign_vm4brwsr_InstanceSub", "recallDbl__D"
  370.71 +        assertExec("Expecting zero", "test", Double.valueOf(0),
  370.72 +            InstanceSub.class.getName(), "recallDbl__D"
  370.73          );
  370.74      }
  370.75  
  370.76 +    @Test public void loadClassWithAssociatedScript() throws Exception {
  370.77 +        assertExec("ko is defined", "test", true,
  370.78 +            Script.class.getName(), "checkNotNull__Z"
  370.79 +        );
  370.80 +        
  370.81 +        Object res = code.invokeFunction("checkKO");
  370.82 +        assertEquals(res, true, "KO is defined on a global level");
  370.83 +    }
  370.84 +
  370.85      private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
  370.86          Object ret = null;
  370.87          try {
  370.88 @@ -104,29 +95,4 @@
  370.89          }
  370.90          assertEquals(ret, expRes, msg + "was: " + ret + "\n" + StaticMethodTest.dumpJS(codeSeq));
  370.91      }
  370.92 -
  370.93 -    public static final class FindBytes {
  370.94 -        public byte[] get(String name) throws IOException {
  370.95 -            InputStream is = VMLazyTest.class.getClassLoader().getResourceAsStream(name);
  370.96 -            if (is == null) {
  370.97 -                throw new IOException("Can't find " + name);
  370.98 -            }
  370.99 -            byte[] arr = new byte[is.available()];
 370.100 -            int len = is.read(arr);
 370.101 -            if (len != arr.length) {
 370.102 -                throw new IOException("Read only " + len + " wanting " + arr.length);
 370.103 -            }
 370.104 -            /*
 370.105 -            System.err.print("loader['" + name + "'] = [");
 370.106 -            for (int i = 0; i < arr.length; i++) {
 370.107 -                if (i > 0) {
 370.108 -                    System.err.print(", ");
 370.109 -                }
 370.110 -                System.err.print(arr[i]);
 370.111 -            }
 370.112 -            System.err.println("]");
 370.113 -            */
 370.114 -            return arr;
 370.115 -        }
 370.116 -    }
 370.117  }
   371.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java	Wed Dec 05 10:03:58 2012 +0100
   371.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java	Sun Feb 03 07:48:42 2013 +0100
   371.3 @@ -20,7 +20,6 @@
   371.4  import java.io.File;
   371.5  import java.io.FileWriter;
   371.6  import java.io.IOException;
   371.7 -import java.io.InputStream;
   371.8  import static org.testng.Assert.*;
   371.9  import javax.script.Invocable;
  371.10  import org.testng.annotations.BeforeClass;
  371.11 @@ -35,13 +34,31 @@
  371.12      private static CharSequence codeSeq;
  371.13      private static Invocable code;
  371.14      
  371.15 -    @Test public void compareTheGeneratedCode() throws Exception {
  371.16 -        byte[] arr = readClass("/org/apidesign/vm4brwsr/Array.class");
  371.17 +    @Test public void compareGeneratedCodeForArrayClass() throws Exception {
  371.18 +        compareCode("org/apidesign/vm4brwsr/Array.class");
  371.19 +    }
  371.20 +
  371.21 +    @Test public void compareGeneratedCodeForClassesClass() throws Exception {
  371.22 +        compareCode("org/apidesign/vm4brwsr/Classes.class");
  371.23 +    }
  371.24 +
  371.25 +    @BeforeClass
  371.26 +    public void compileTheCode() throws Exception {
  371.27 +        StringBuilder sb = new StringBuilder();
  371.28 +        code = StaticMethodTest.compileClass(sb, 
  371.29 +            "org/apidesign/vm4brwsr/VMinVM"
  371.30 +        );
  371.31 +        codeSeq = sb;
  371.32 +    }
  371.33 +    
  371.34 +    private void compareCode(final String nm) throws Exception, IOException {
  371.35 +        byte[] arr = BytesLoader.readClass(nm);
  371.36          String ret1 = VMinVM.toJavaScript(arr);
  371.37          
  371.38          Object ret;
  371.39          try {
  371.40 -            ret = code.invokeFunction(VMinVM.class.getName().replace('.', '_'), true);
  371.41 +            ret = code.invokeFunction("bck2brwsr");
  371.42 +            ret = code.invokeMethod(ret, "loadClass", VMinVM.class.getName());
  371.43              ret = code.invokeMethod(ret, "toJavaScript__Ljava_lang_String_2_3B", arr);
  371.44          } catch (Exception ex) {
  371.45              File f = File.createTempFile("execution", ".js");
  371.46 @@ -64,27 +81,14 @@
  371.47          
  371.48          assertTrue(ret instanceof String, "It is string: " + ret);
  371.49          
  371.50 -        assertEquals((String)ret, ret1.toString(), "The code is the same");
  371.51 -    }
  371.52 -    
  371.53 -    @BeforeClass
  371.54 -    public void compileTheCode() throws Exception {
  371.55 -        StringBuilder sb = new StringBuilder();
  371.56 -        code = StaticMethodTest.compileClass(sb, 
  371.57 -            "org/apidesign/vm4brwsr/VMinVM"
  371.58 -        );
  371.59 -        codeSeq = sb;
  371.60 -    }
  371.61 -    
  371.62 -    private static byte[] readClass(String res) throws IOException {
  371.63 -        InputStream is1 = VMinVMTest.class.getResourceAsStream(res);
  371.64 -        assertNotNull(is1, "Stream found");
  371.65 -        byte[] arr = new byte[is1.available()];
  371.66 -        int len = is1.read(arr);
  371.67 -        is1.close();
  371.68 -        if (len != arr.length) {
  371.69 -            throw new IOException("Wrong len " + len + " for arr: " + arr.length);
  371.70 +        if (!ret1.toString().equals(ret)) {
  371.71 +            StringBuilder msg = new StringBuilder("Difference found between ");
  371.72 +            msg.append(StaticMethodTest.dumpJS(ret1));
  371.73 +            msg.append(" ");
  371.74 +            msg.append(StaticMethodTest.dumpJS((CharSequence) ret));
  371.75 +            msg.append(" compiled by ");
  371.76 +            msg.append(StaticMethodTest.dumpJS(codeSeq));
  371.77 +            fail(msg.toString());
  371.78          }
  371.79 -        return arr;
  371.80      }
  371.81  }
   372.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   372.2 +++ b/vm/src/test/resources/org/apidesign/vm4brwsr/ko.js	Sun Feb 03 07:48:42 2013 +0100
   372.3 @@ -0,0 +1,20 @@
   372.4 +/*
   372.5 + * Back 2 Browser Bytecode Translator
   372.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   372.7 + *
   372.8 + * This program is free software: you can redistribute it and/or modify
   372.9 + * it under the terms of the GNU General Public License as published by
  372.10 + * the Free Software Foundation, version 2 of the License.
  372.11 + *
  372.12 + * This program is distributed in the hope that it will be useful,
  372.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  372.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  372.15 + * GNU General Public License for more details.
  372.16 + *
  372.17 + * You should have received a copy of the GNU General Public License
  372.18 + * along with this program. Look for COPYING file in the top folder.
  372.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  372.20 + */
  372.21 +this.ko = {};
  372.22 +
  372.23 +
   373.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   373.2 +++ b/vmtest/pom.xml	Sun Feb 03 07:48:42 2013 +0100
   373.3 @@ -0,0 +1,62 @@
   373.4 +<?xml version="1.0"?>
   373.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"
   373.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   373.7 +  <modelVersion>4.0.0</modelVersion>
   373.8 +  <parent>
   373.9 +    <groupId>org.apidesign</groupId>
  373.10 +    <artifactId>bck2brwsr</artifactId>
  373.11 +    <version>0.3-SNAPSHOT</version>
  373.12 +  </parent>
  373.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
  373.14 +  <artifactId>vmtest</artifactId>
  373.15 +  <version>0.3-SNAPSHOT</version>
  373.16 +  
  373.17 +  <name>VM Testing APIs</name>
  373.18 +  <url>http://bck2brwsr.apidesign.org</url>
  373.19 +    <build>
  373.20 +        <plugins>
  373.21 +            <plugin>
  373.22 +                <groupId>org.apache.maven.plugins</groupId>
  373.23 +                <artifactId>maven-compiler-plugin</artifactId>
  373.24 +                <version>2.3.2</version>
  373.25 +                <configuration>
  373.26 +                    <source>1.7</source>
  373.27 +                    <target>1.7</target>
  373.28 +                </configuration>
  373.29 +            </plugin>
  373.30 +        </plugins>
  373.31 +    </build>
  373.32 +    <properties>
  373.33 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  373.34 +  </properties>
  373.35 +  <dependencies>
  373.36 +    <dependency>
  373.37 +      <groupId>org.testng</groupId>
  373.38 +      <artifactId>testng</artifactId>
  373.39 +      <scope>compile</scope>
  373.40 +      <exclusions>
  373.41 +        <exclusion>
  373.42 +          <artifactId>junit</artifactId>
  373.43 +          <groupId>junit</groupId>
  373.44 +        </exclusion>
  373.45 +      </exclusions>
  373.46 +    </dependency>
  373.47 +    <dependency>
  373.48 +      <groupId>${project.groupId}</groupId>
  373.49 +      <artifactId>vm4brwsr</artifactId>
  373.50 +      <version>${project.version}</version>
  373.51 +      <type>jar</type>
  373.52 +    </dependency>
  373.53 +    <dependency>
  373.54 +      <groupId>${project.groupId}</groupId>
  373.55 +      <artifactId>emul.mini</artifactId>
  373.56 +      <version>${project.version}</version>
  373.57 +      <scope>test</scope>
  373.58 +    </dependency>
  373.59 +    <dependency>
  373.60 +      <groupId>${project.groupId}</groupId>
  373.61 +      <artifactId>launcher</artifactId>
  373.62 +      <version>${project.version}</version>
  373.63 +    </dependency>
  373.64 +  </dependencies>
  373.65 +</project>
   374.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   374.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/BrwsrTest.java	Sun Feb 03 07:48:42 2013 +0100
   374.3 @@ -0,0 +1,38 @@
   374.4 +/**
   374.5 + * Back 2 Browser Bytecode Translator
   374.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   374.7 + *
   374.8 + * This program is free software: you can redistribute it and/or modify
   374.9 + * it under the terms of the GNU General Public License as published by
  374.10 + * the Free Software Foundation, version 2 of the License.
  374.11 + *
  374.12 + * This program is distributed in the hope that it will be useful,
  374.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  374.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  374.15 + * GNU General Public License for more details.
  374.16 + *
  374.17 + * You should have received a copy of the GNU General Public License
  374.18 + * along with this program. Look for COPYING file in the top folder.
  374.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  374.20 + */
  374.21 +package org.apidesign.bck2brwsr.vmtest;
  374.22 +
  374.23 +import java.lang.annotation.ElementType;
  374.24 +import java.lang.annotation.Retention;
  374.25 +import java.lang.annotation.RetentionPolicy;
  374.26 +import java.lang.annotation.Target;
  374.27 +
  374.28 +/** Annotation to indicate that given method should be executed
  374.29 + * in a browser environment. Has to be used in conjunction with {@link VMTest#create(java.lang.Class)}
  374.30 + * factory method. 
  374.31 + * <p>
  374.32 + * The browser to is by default executed via {@link java.awt.Desktop#browse(java.net.URI)},
  374.33 + * but one can change that by specifying <code>-Dvmtest.brwsrs=firefox,google-chrome</code>
  374.34 + * property.
  374.35 + *
  374.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  374.37 + */
  374.38 +@Retention(RetentionPolicy.RUNTIME)
  374.39 +@Target(ElementType.METHOD)
  374.40 +public @interface BrwsrTest {
  374.41 +}
   375.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   375.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Compare.java	Sun Feb 03 07:48:42 2013 +0100
   375.3 @@ -0,0 +1,45 @@
   375.4 +/**
   375.5 + * Back 2 Browser Bytecode Translator
   375.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   375.7 + *
   375.8 + * This program is free software: you can redistribute it and/or modify
   375.9 + * it under the terms of the GNU General Public License as published by
  375.10 + * the Free Software Foundation, version 2 of the License.
  375.11 + *
  375.12 + * This program is distributed in the hope that it will be useful,
  375.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  375.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  375.15 + * GNU General Public License for more details.
  375.16 + *
  375.17 + * You should have received a copy of the GNU General Public License
  375.18 + * along with this program. Look for COPYING file in the top folder.
  375.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  375.20 + */
  375.21 +package org.apidesign.bck2brwsr.vmtest;
  375.22 +
  375.23 +import java.lang.annotation.ElementType;
  375.24 +import java.lang.annotation.Retention;
  375.25 +import java.lang.annotation.RetentionPolicy;
  375.26 +import java.lang.annotation.Target;
  375.27 +
  375.28 +/** Can be applied on a method that yields a return value. 
  375.29 + * Together with {@link VMTest#create} it can be used to write
  375.30 + * methods which are executed in real VM as well as JavaScript VMs and
  375.31 + * their results are compared.
  375.32 + *
  375.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  375.34 + */
  375.35 +@Retention(RetentionPolicy.RUNTIME)
  375.36 +@Target(ElementType.METHOD)
  375.37 +public @interface Compare {
  375.38 +    /** Specifies whether the system should internal JavaScript interpreter
  375.39 +     * as available via {@link javax.script.ScriptEngine}. Defaults to true,
  375.40 +     * but in some situations (benchmarking comes to my mind), one may set this
  375.41 +     * to <code>false</code>. In such case only browsers provided via
  375.42 +     * <code>vmtest.brwsrs</code> property are used. For example
  375.43 +     * <code>"vmtest.brwsrs=firefox,google-chrome"</code> would run the test
  375.44 +     * in HotSpot VM, firefox and chrome and would compare the results.
  375.45 +     * @return 
  375.46 +     */
  375.47 +    boolean scripting() default true;
  375.48 +}
   376.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   376.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/HtmlFragment.java	Sun Feb 03 07:48:42 2013 +0100
   376.3 @@ -0,0 +1,38 @@
   376.4 +/**
   376.5 + * Back 2 Browser Bytecode Translator
   376.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   376.7 + *
   376.8 + * This program is free software: you can redistribute it and/or modify
   376.9 + * it under the terms of the GNU General Public License as published by
  376.10 + * the Free Software Foundation, version 2 of the License.
  376.11 + *
  376.12 + * This program is distributed in the hope that it will be useful,
  376.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  376.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  376.15 + * GNU General Public License for more details.
  376.16 + *
  376.17 + * You should have received a copy of the GNU General Public License
  376.18 + * along with this program. Look for COPYING file in the top folder.
  376.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  376.20 + */
  376.21 +package org.apidesign.bck2brwsr.vmtest;
  376.22 +
  376.23 +import java.lang.annotation.ElementType;
  376.24 +import java.lang.annotation.Retention;
  376.25 +import java.lang.annotation.RetentionPolicy;
  376.26 +import java.lang.annotation.Target;
  376.27 +
  376.28 +/** Allows to specify an HTML fragment for a given {@link BrwsrTest}. 
  376.29 + * Apply either to the method or to enclosing class. The fragment will be
  376.30 + * made available in the page that executes given test. Its elements shall
  376.31 + * be regularly accessible from the test.
  376.32 + *
  376.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  376.34 + */
  376.35 +@Retention(RetentionPolicy.RUNTIME)
  376.36 +@Target({ ElementType.METHOD, ElementType.TYPE})
  376.37 +public @interface HtmlFragment {
  376.38 +    /** HTML code fragment to be exposed on the testing page.
  376.39 +     */
  376.40 +    String value();
  376.41 +}
   377.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   377.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java	Sun Feb 03 07:48:42 2013 +0100
   377.3 @@ -0,0 +1,43 @@
   377.4 +/**
   377.5 + * Back 2 Browser Bytecode Translator
   377.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   377.7 + *
   377.8 + * This program is free software: you can redistribute it and/or modify
   377.9 + * it under the terms of the GNU General Public License as published by
  377.10 + * the Free Software Foundation, version 2 of the License.
  377.11 + *
  377.12 + * This program is distributed in the hope that it will be useful,
  377.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  377.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  377.15 + * GNU General Public License for more details.
  377.16 + *
  377.17 + * You should have received a copy of the GNU General Public License
  377.18 + * along with this program. Look for COPYING file in the top folder.
  377.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  377.20 + */
  377.21 +package org.apidesign.bck2brwsr.vmtest;
  377.22 +
  377.23 +import org.apidesign.bck2brwsr.vmtest.impl.CompareCase;
  377.24 +import org.testng.annotations.Factory;
  377.25 +
  377.26 +/** A TestNG {@link Factory} that seeks for {@link Compare} annotations
  377.27 + * in provided class and builds set of tests that compare the computations
  377.28 + * in real as well as JavaScript virtual machines. Use as:<pre>
  377.29 + * {@code @}{@link Factory} public static create() {
  377.30 + *   return @{link VMTest}.{@link #create(YourClass.class);
  377.31 + * }</pre>
  377.32 + *
  377.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  377.34 + */
  377.35 +public final class VMTest {
  377.36 +    /** Inspects <code>clazz</code> and for each {@lik Compare} method creates
  377.37 +     * instances of tests. Each instance runs the test in different virtual
  377.38 +     * machine and at the end they compare the results.
  377.39 +     * 
  377.40 +     * @param clazz the class to inspect
  377.41 +     * @return the set of created tests
  377.42 +     */
  377.43 +    public static Object[] create(Class<?> clazz) {
  377.44 +        return CompareCase.create(clazz);
  377.45 +    }
  377.46 +}
   378.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   378.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java	Sun Feb 03 07:48:42 2013 +0100
   378.3 @@ -0,0 +1,114 @@
   378.4 +/**
   378.5 + * Back 2 Browser Bytecode Translator
   378.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   378.7 + *
   378.8 + * This program is free software: you can redistribute it and/or modify
   378.9 + * it under the terms of the GNU General Public License as published by
  378.10 + * the Free Software Foundation, version 2 of the License.
  378.11 + *
  378.12 + * This program is distributed in the hope that it will be useful,
  378.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  378.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  378.15 + * GNU General Public License for more details.
  378.16 + *
  378.17 + * You should have received a copy of the GNU General Public License
  378.18 + * along with this program. Look for COPYING file in the top folder.
  378.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  378.20 + */
  378.21 +package org.apidesign.bck2brwsr.vmtest.impl;
  378.22 +
  378.23 +import java.io.File;
  378.24 +import java.io.FileWriter;
  378.25 +import java.io.IOException;
  378.26 +import java.lang.reflect.Constructor;
  378.27 +import java.lang.reflect.InvocationTargetException;
  378.28 +import java.lang.reflect.Method;
  378.29 +import org.apidesign.bck2brwsr.launcher.Launcher;
  378.30 +import org.apidesign.bck2brwsr.launcher.MethodInvocation;
  378.31 +import org.testng.ITest;
  378.32 +import org.testng.annotations.Test;
  378.33 +
  378.34 +/**
  378.35 + *
  378.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  378.37 + */
  378.38 +public final class Bck2BrwsrCase implements ITest {
  378.39 +    private final Method m;
  378.40 +    private final Launcher l;
  378.41 +    private final String type;
  378.42 +    private final boolean fail;
  378.43 +    Object value;
  378.44 +    private final String html;
  378.45 +
  378.46 +    Bck2BrwsrCase(Method m, String type, Launcher l, boolean fail, String html) {
  378.47 +        this.l = l;
  378.48 +        this.m = m;
  378.49 +        this.type = type;
  378.50 +        this.fail = fail;
  378.51 +        this.html = html;
  378.52 +    }
  378.53 +
  378.54 +    @Test(groups = "run")
  378.55 +    public void executeCode() throws Throwable {
  378.56 +        if (l != null) {
  378.57 +            MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName(), html);
  378.58 +            String res = c.toString();
  378.59 +            value = res;
  378.60 +            if (fail) {
  378.61 +                int idx = res.indexOf(':');
  378.62 +                if (idx >= 0) {
  378.63 +                    Class<? extends Throwable> thrwbl = null;
  378.64 +                    try {
  378.65 +                        Class<?> exCls = Class.forName(res.substring(0, idx));
  378.66 +                        if (Throwable.class.isAssignableFrom(exCls)) {
  378.67 +                            thrwbl = exCls.asSubclass(Throwable.class);
  378.68 +                        }
  378.69 +                    } catch (Exception ex) {
  378.70 +                        // ignore
  378.71 +                    }
  378.72 +                    if (thrwbl != null) {
  378.73 +                        Throwable t = null;
  378.74 +                        try {
  378.75 +                            for (Constructor<?> cnstr : thrwbl.getConstructors()) {
  378.76 +                                if (cnstr.getParameterTypes().length == 1 && cnstr.getParameterTypes()[0].isAssignableFrom(String.class)) {
  378.77 +                                    t = (Throwable) cnstr.newInstance(res.substring(idx + 1));
  378.78 +                                    break;
  378.79 +                                }
  378.80 +                            }
  378.81 +                        } catch (Throwable ex) {
  378.82 +                            t = thrwbl.newInstance().initCause(ex);
  378.83 +                        }
  378.84 +                        if (t == null) {
  378.85 +                            t = thrwbl.newInstance().initCause(new Exception(res.substring(idx)));
  378.86 +                        }
  378.87 +                        throw t;
  378.88 +                    }
  378.89 +                    throw new AssertionError(res);
  378.90 +                }
  378.91 +            }
  378.92 +        } else {
  378.93 +            try {
  378.94 +                value = m.invoke(m.getDeclaringClass().newInstance());
  378.95 +            } catch (InvocationTargetException ex) {
  378.96 +                Throwable t = ex.getTargetException();
  378.97 +                value = t.getClass().getName() + ":" + t.getMessage();
  378.98 +            }
  378.99 +        }
 378.100 +    }
 378.101 +
 378.102 +    @Override
 378.103 +    public String getTestName() {
 378.104 +        return m.getName() + "[" + typeName() + "]";
 378.105 +    }
 378.106 +
 378.107 +    final String typeName() {
 378.108 +        return type;
 378.109 +    }
 378.110 +    static void dumpJS(StringBuilder sb, Bck2BrwsrCase c) throws IOException {
 378.111 +        File f = File.createTempFile(c.m.getName(), ".js");
 378.112 +        try (final FileWriter w = new FileWriter(f)) {
 378.113 +            w.append(c.l.toString());
 378.114 +        }
 378.115 +        sb.append("Path: ").append(f.getPath());
 378.116 +    }
 378.117 +}
   379.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   379.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java	Sun Feb 03 07:48:42 2013 +0100
   379.3 @@ -0,0 +1,151 @@
   379.4 +/**
   379.5 + * Back 2 Browser Bytecode Translator
   379.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   379.7 + *
   379.8 + * This program is free software: you can redistribute it and/or modify
   379.9 + * it under the terms of the GNU General Public License as published by
  379.10 + * the Free Software Foundation, version 2 of the License.
  379.11 + *
  379.12 + * This program is distributed in the hope that it will be useful,
  379.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  379.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  379.15 + * GNU General Public License for more details.
  379.16 + *
  379.17 + * You should have received a copy of the GNU General Public License
  379.18 + * along with this program. Look for COPYING file in the top folder.
  379.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  379.20 + */
  379.21 +package org.apidesign.bck2brwsr.vmtest.impl;
  379.22 +
  379.23 +import org.apidesign.bck2brwsr.vmtest.*;
  379.24 +import java.lang.reflect.Method;
  379.25 +import java.util.ArrayList;
  379.26 +import java.util.List;
  379.27 +import org.apidesign.bck2brwsr.launcher.Launcher;
  379.28 +import org.testng.Assert;
  379.29 +import org.testng.ITest;
  379.30 +import org.testng.annotations.Factory;
  379.31 +import org.testng.annotations.Test;
  379.32 +
  379.33 +/** A TestNG {@link Factory} that seeks for {@link Compare} annotations
  379.34 + * in provided class and builds set of tests that compare the computations
  379.35 + * in real as well as JavaScript virtual machines. Use as:<pre>
  379.36 + * {@code @}{@link Factory} public static create() {
  379.37 + *   return @{link VMTest}.{@link #create(YourClass.class);
  379.38 + * }</pre>
  379.39 + *
  379.40 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  379.41 + */
  379.42 +public final class CompareCase implements ITest {
  379.43 +    private final Bck2BrwsrCase first, second;
  379.44 +    private final Method m;
  379.45 +    
  379.46 +    private CompareCase(Method m, Bck2BrwsrCase first, Bck2BrwsrCase second) {
  379.47 +        this.first = first;
  379.48 +        this.second = second;
  379.49 +        this.m = m;
  379.50 +    }
  379.51 +
  379.52 +    /** Inspects <code>clazz</code> and for each {@lik Compare} method creates
  379.53 +     * instances of tests. Each instance runs the test in different virtual
  379.54 +     * machine and at the end they compare the results.
  379.55 +     * 
  379.56 +     * @param clazz the class to inspect
  379.57 +     * @return the set of created tests
  379.58 +     */
  379.59 +    public static Object[] create(Class<?> clazz) {
  379.60 +        Method[] arr = clazz.getMethods();
  379.61 +        List<Object> ret = new ArrayList<>();
  379.62 +        
  379.63 +        final LaunchSetup l = LaunchSetup.INSTANCE;
  379.64 +        ret.add(l);
  379.65 +        
  379.66 +        String[] brwsr;
  379.67 +        {
  379.68 +            String p = System.getProperty("vmtest.brwsrs");
  379.69 +            if (p != null) {
  379.70 +                brwsr = p.split(",");
  379.71 +            } else {
  379.72 +                brwsr = new String[0];
  379.73 +            }
  379.74 +        }
  379.75 +        
  379.76 +        for (Method m : arr) {
  379.77 +            registerCompareCases(m, l, ret, brwsr);
  379.78 +            registerBrwsrCases(m, l, ret, brwsr);
  379.79 +        }
  379.80 +        return ret.toArray();
  379.81 +    }
  379.82 +
  379.83 +    /** Test that compares the previous results.
  379.84 +     * @throws Throwable 
  379.85 +     */
  379.86 +    @Test(dependsOnGroups = "run") public void compareResults() throws Throwable {
  379.87 +        Object v1 = first.value;
  379.88 +        Object v2 = second.value;
  379.89 +        if (v1 != null) {
  379.90 +            v1 = v1.toString();
  379.91 +        } else {
  379.92 +            v1 = "null";
  379.93 +        }
  379.94 +        try {
  379.95 +            Assert.assertEquals(v2, v1, "Comparing results");
  379.96 +        } catch (AssertionError e) {
  379.97 +            StringBuilder sb = new StringBuilder();
  379.98 +            sb.append(e.getMessage());
  379.99 +            Bck2BrwsrCase.dumpJS(sb, second);
 379.100 +            throw new AssertionError(sb.toString());
 379.101 +        }
 379.102 +    }
 379.103 +    
 379.104 +    /** Test name.
 379.105 +     * @return name of the tested method followed by a suffix
 379.106 +     */
 379.107 +    @Override
 379.108 +    public String getTestName() {
 379.109 +        return m.getName() + "[Compare " + second.typeName() + "]";
 379.110 +    }
 379.111 +    
 379.112 +    private static void registerCompareCases(Method m, final LaunchSetup l, List<Object> ret, String[] brwsr) {
 379.113 +        Compare c = m.getAnnotation(Compare.class);
 379.114 +        if (c == null) {
 379.115 +            return;
 379.116 +        }
 379.117 +        final Bck2BrwsrCase real = new Bck2BrwsrCase(m, "Java", null, false, null);
 379.118 +        ret.add(real);
 379.119 +        if (c.scripting()) {
 379.120 +            final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l.javaScript(), false, null);
 379.121 +            ret.add(js);
 379.122 +            ret.add(new CompareCase(m, real, js));
 379.123 +        }
 379.124 +        for (String b : brwsr) {
 379.125 +            final Launcher s = l.brwsr(b);
 379.126 +            ret.add(s);
 379.127 +            final Bck2BrwsrCase cse = new Bck2BrwsrCase(m, b, s, false, null);
 379.128 +            ret.add(cse);
 379.129 +            ret.add(new CompareCase(m, real, cse));
 379.130 +        }
 379.131 +    }
 379.132 +    private static void registerBrwsrCases(Method m, final LaunchSetup l, List<Object> ret, String[] brwsr) {
 379.133 +        BrwsrTest c = m.getAnnotation(BrwsrTest.class);
 379.134 +        if (c == null) {
 379.135 +            return;
 379.136 +        }
 379.137 +        HtmlFragment f = m.getAnnotation(HtmlFragment.class);
 379.138 +        if (f == null) {
 379.139 +            f = m.getDeclaringClass().getAnnotation(HtmlFragment.class);
 379.140 +        }
 379.141 +        String html = f == null ? null : f.value();
 379.142 +        if (brwsr.length == 0) {
 379.143 +            final Launcher s = l.brwsr(null);
 379.144 +            ret.add(s);
 379.145 +            ret.add(new Bck2BrwsrCase(m, "Brwsr", s, true, html));
 379.146 +        } else {
 379.147 +            for (String b : brwsr) {
 379.148 +                final Launcher s = l.brwsr(b);
 379.149 +                ret.add(s);
 379.150 +                ret.add(new Bck2BrwsrCase(m, b, s, true, html));
 379.151 +            }
 379.152 +        }
 379.153 +    }
 379.154 +}
   380.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   380.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java	Sun Feb 03 07:48:42 2013 +0100
   380.3 @@ -0,0 +1,68 @@
   380.4 +/**
   380.5 + * Back 2 Browser Bytecode Translator
   380.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   380.7 + *
   380.8 + * This program is free software: you can redistribute it and/or modify
   380.9 + * it under the terms of the GNU General Public License as published by
  380.10 + * the Free Software Foundation, version 2 of the License.
  380.11 + *
  380.12 + * This program is distributed in the hope that it will be useful,
  380.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  380.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  380.15 + * GNU General Public License for more details.
  380.16 + *
  380.17 + * You should have received a copy of the GNU General Public License
  380.18 + * along with this program. Look for COPYING file in the top folder.
  380.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  380.20 + */
  380.21 +package org.apidesign.bck2brwsr.vmtest.impl;
  380.22 +
  380.23 +import java.io.IOException;
  380.24 +import java.util.LinkedHashMap;
  380.25 +import java.util.Map;
  380.26 +import org.apidesign.bck2brwsr.launcher.Launcher;
  380.27 +import org.testng.annotations.AfterGroups;
  380.28 +import org.testng.annotations.BeforeGroups;
  380.29 +
  380.30 +/**
  380.31 + *
  380.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  380.33 + */
  380.34 +public final class LaunchSetup {
  380.35 +    static LaunchSetup INSTANCE = new LaunchSetup();
  380.36 +    
  380.37 +    private final Launcher js = Launcher.createJavaScript();
  380.38 +    private final Map<String,Launcher> brwsrs = new LinkedHashMap<>();
  380.39 +    
  380.40 +    private LaunchSetup() {
  380.41 +    }
  380.42 +    
  380.43 +    public  Launcher javaScript() {
  380.44 +        return js;
  380.45 +    } 
  380.46 +    
  380.47 +    public synchronized Launcher brwsr(String cmd) {
  380.48 +        Launcher s = brwsrs.get(cmd);
  380.49 +        if (s == null) {
  380.50 +            s = Launcher.createBrowser(cmd);
  380.51 +            brwsrs.put(cmd, s);
  380.52 +        }
  380.53 +        return s;
  380.54 +    }
  380.55 +
  380.56 +    @BeforeGroups("run")
  380.57 +    public void initializeLauncher() throws IOException {
  380.58 +        js.initialize();
  380.59 +        for (Launcher launcher : brwsrs.values()) {
  380.60 +            launcher.initialize();
  380.61 +        }
  380.62 +    }
  380.63 +
  380.64 +    @AfterGroups("run")
  380.65 +    public void shutDownLauncher() throws IOException, InterruptedException {
  380.66 +        js.shutdown();
  380.67 +        for (Launcher launcher : brwsrs.values()) {
  380.68 +            launcher.shutdown();
  380.69 +        }
  380.70 +    }
  380.71 +}
   381.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   381.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/AssertionTest.java	Sun Feb 03 07:48:42 2013 +0100
   381.3 @@ -0,0 +1,39 @@
   381.4 +/**
   381.5 + * Back 2 Browser Bytecode Translator
   381.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   381.7 + *
   381.8 + * This program is free software: you can redistribute it and/or modify
   381.9 + * it under the terms of the GNU General Public License as published by
  381.10 + * the Free Software Foundation, version 2 of the License.
  381.11 + *
  381.12 + * This program is distributed in the hope that it will be useful,
  381.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  381.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  381.15 + * GNU General Public License for more details.
  381.16 + *
  381.17 + * You should have received a copy of the GNU General Public License
  381.18 + * along with this program. Look for COPYING file in the top folder.
  381.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  381.20 + */
  381.21 +package org.apidesign.bck2brwsr.tck;
  381.22 +
  381.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  381.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  381.25 +import org.testng.annotations.Factory;
  381.26 +
  381.27 +/**
  381.28 + *
  381.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  381.30 + */
  381.31 +public class AssertionTest {
  381.32 +
  381.33 +    @Compare public Object checkAssert() throws ClassNotFoundException {
  381.34 +        assert false : "Is assertion status on?";
  381.35 +        return null;
  381.36 +    }
  381.37 +    
  381.38 +    @Factory
  381.39 +    public static Object[] create() {
  381.40 +        return VMTest.create(AssertionTest.class);
  381.41 +    }
  381.42 +}
   382.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   382.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/BrwsrCheckTest.java	Sun Feb 03 07:48:42 2013 +0100
   382.3 @@ -0,0 +1,57 @@
   382.4 +/**
   382.5 + * Back 2 Browser Bytecode Translator
   382.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   382.7 + *
   382.8 + * This program is free software: you can redistribute it and/or modify
   382.9 + * it under the terms of the GNU General Public License as published by
  382.10 + * the Free Software Foundation, version 2 of the License.
  382.11 + *
  382.12 + * This program is distributed in the hope that it will be useful,
  382.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  382.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  382.15 + * GNU General Public License for more details.
  382.16 + *
  382.17 + * You should have received a copy of the GNU General Public License
  382.18 + * along with this program. Look for COPYING file in the top folder.
  382.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  382.20 + */
  382.21 +package org.apidesign.bck2brwsr.tck;
  382.22 +
  382.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  382.24 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
  382.25 +import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
  382.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  382.27 +import org.testng.annotations.Factory;
  382.28 +
  382.29 +/**
  382.30 + *
  382.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  382.32 + */
  382.33 +public class BrwsrCheckTest {
  382.34 +
  382.35 +    @BrwsrTest public void assertWindowObjectIsDefined() {
  382.36 +        assert window() != null : "No window object found!";
  382.37 +    }
  382.38 +
  382.39 +    
  382.40 +    
  382.41 +    
  382.42 +    @HtmlFragment("<h1 id='hello'>\n"
  382.43 +        + "Hello!\n"
  382.44 +        + "</h1>\n")
  382.45 +    @BrwsrTest public void accessProvidedFragment() {
  382.46 +        assert getElementById("hello") != null : "Element with 'hello' ID found";
  382.47 +    }
  382.48 +    
  382.49 +    @Factory
  382.50 +    public static Object[] create() {
  382.51 +        return VMTest.create(BrwsrCheckTest.class);
  382.52 +    }
  382.53 +    
  382.54 +
  382.55 +    @JavaScriptBody(args = {}, body = "return window;")
  382.56 +    private static native Object window();
  382.57 +
  382.58 +    @JavaScriptBody(args = { "id" }, body = "return window.document.getElementById(id);")
  382.59 +    private static native Object getElementById(String id);
  382.60 +}
   383.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   383.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ByteArithmeticTest.java	Sun Feb 03 07:48:42 2013 +0100
   383.3 @@ -0,0 +1,102 @@
   383.4 +/**
   383.5 + * Back 2 Browser Bytecode Translator
   383.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   383.7 + *
   383.8 + * This program is free software: you can redistribute it and/or modify
   383.9 + * it under the terms of the GNU General Public License as published by
  383.10 + * the Free Software Foundation, version 2 of the License.
  383.11 + *
  383.12 + * This program is distributed in the hope that it will be useful,
  383.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  383.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  383.15 + * GNU General Public License for more details.
  383.16 + *
  383.17 + * You should have received a copy of the GNU General Public License
  383.18 + * along with this program. Look for COPYING file in the top folder.
  383.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  383.20 + */
  383.21 +package org.apidesign.bck2brwsr.tck;
  383.22 +
  383.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  383.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  383.25 +import org.testng.annotations.Factory;
  383.26 +
  383.27 +/**
  383.28 + *
  383.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  383.30 + */
  383.31 +public class ByteArithmeticTest {
  383.32 +    
  383.33 +    private static byte add(byte x, byte y) {
  383.34 +        return (byte)(x + y);
  383.35 +    }
  383.36 +    
  383.37 +    private static byte sub(byte x, byte y) {
  383.38 +        return (byte)(x - y);
  383.39 +    }
  383.40 +    
  383.41 +    private static byte mul(byte x, byte y) {
  383.42 +        return (byte)(x * y);
  383.43 +    }
  383.44 +    
  383.45 +    private static byte div(byte x, byte y) {
  383.46 +        return (byte)(x / y);
  383.47 +    }
  383.48 +    
  383.49 +    private static byte mod(byte x, byte y) {
  383.50 +        return (byte)(x % y);
  383.51 +    }
  383.52 +    
  383.53 +    @Compare public byte conversion() {
  383.54 +        return (byte)123456;
  383.55 +    }
  383.56 +    
  383.57 +    @Compare public byte addOverflow() {
  383.58 +        return add(Byte.MAX_VALUE, (byte)1);
  383.59 +    }
  383.60 +    
  383.61 +    @Compare public byte subUnderflow() {
  383.62 +        return sub(Byte.MIN_VALUE, (byte)1);
  383.63 +    }
  383.64 +    
  383.65 +    @Compare public byte addMaxByteAndMaxByte() {
  383.66 +        return add(Byte.MAX_VALUE, Byte.MAX_VALUE);
  383.67 +    }
  383.68 +    
  383.69 +    @Compare public byte subMinByteAndMinByte() {
  383.70 +        return sub(Byte.MIN_VALUE, Byte.MIN_VALUE);
  383.71 +    }
  383.72 +    
  383.73 +    @Compare public byte multiplyMaxByte() {
  383.74 +        return mul(Byte.MAX_VALUE, (byte)2);
  383.75 +    }
  383.76 +    
  383.77 +    @Compare public byte multiplyMaxByteAndMaxByte() {
  383.78 +        return mul(Byte.MAX_VALUE, Byte.MAX_VALUE);
  383.79 +    }
  383.80 +    
  383.81 +    @Compare public byte multiplyMinByte() {
  383.82 +        return mul(Byte.MIN_VALUE, (byte)2);
  383.83 +    }
  383.84 +    
  383.85 +    @Compare public byte multiplyMinByteAndMinByte() {
  383.86 +        return mul(Byte.MIN_VALUE, Byte.MIN_VALUE);
  383.87 +    }
  383.88 +    
  383.89 +    @Compare public byte multiplyPrecision() {
  383.90 +        return mul((byte)17638, (byte)1103);
  383.91 +    }
  383.92 +    
  383.93 +    @Compare public byte division() {
  383.94 +        return div((byte)1, (byte)2);
  383.95 +    }
  383.96 +    
  383.97 +    @Compare public byte divisionReminder() {
  383.98 +        return mod((byte)1, (byte)2);
  383.99 +    }
 383.100 +    
 383.101 +    @Factory
 383.102 +    public static Object[] create() {
 383.103 +        return VMTest.create(ByteArithmeticTest.class);
 383.104 +    }
 383.105 +}
   384.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   384.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CloneTest.java	Sun Feb 03 07:48:42 2013 +0100
   384.3 @@ -0,0 +1,73 @@
   384.4 +/**
   384.5 + * Back 2 Browser Bytecode Translator
   384.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   384.7 + *
   384.8 + * This program is free software: you can redistribute it and/or modify
   384.9 + * it under the terms of the GNU General Public License as published by
  384.10 + * the Free Software Foundation, version 2 of the License.
  384.11 + *
  384.12 + * This program is distributed in the hope that it will be useful,
  384.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  384.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  384.15 + * GNU General Public License for more details.
  384.16 + *
  384.17 + * You should have received a copy of the GNU General Public License
  384.18 + * along with this program. Look for COPYING file in the top folder.
  384.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  384.20 + */
  384.21 +package org.apidesign.bck2brwsr.tck;
  384.22 +
  384.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  384.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  384.25 +import org.testng.annotations.Factory;
  384.26 +
  384.27 +/**
  384.28 + *
  384.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  384.30 + */
  384.31 +public class CloneTest {
  384.32 +    private int value;
  384.33 +    
  384.34 +    @Compare
  384.35 +    public Object notSupported() throws CloneNotSupportedException {
  384.36 +        return this.clone();
  384.37 +    }
  384.38 +
  384.39 +    @Compare public String sameClass() throws CloneNotSupportedException {
  384.40 +        return new Clnbl().clone().getClass().getName();
  384.41 +    }
  384.42 +
  384.43 +    @Compare public boolean differentInstance() throws CloneNotSupportedException {
  384.44 +        Clnbl orig = new Clnbl();
  384.45 +        return orig == orig.clone();
  384.46 +    }
  384.47 +
  384.48 +    @Compare public int sameReference() throws CloneNotSupportedException {
  384.49 +        CloneTest self = this;
  384.50 +        Clnbl orig = new Clnbl();
  384.51 +        self.value = 33;
  384.52 +        orig.ref = self;
  384.53 +        return ((Clnbl)orig.clone()).ref.value;
  384.54 +    }
  384.55 +
  384.56 +    @Compare public int sameValue() throws CloneNotSupportedException {
  384.57 +        Clnbl orig = new Clnbl();
  384.58 +        orig.value = 10;
  384.59 +        return ((Clnbl)orig.clone()).value;
  384.60 +    }
  384.61 +    
  384.62 +    @Factory
  384.63 +    public static Object[] create() {
  384.64 +        return VMTest.create(CloneTest.class);
  384.65 +    }
  384.66 +    
  384.67 +    public static final class Clnbl implements Cloneable {
  384.68 +        public CloneTest ref;
  384.69 +        private int value;
  384.70 +
  384.71 +        @Override
  384.72 +        public Object clone() throws CloneNotSupportedException {
  384.73 +            return super.clone();
  384.74 +        }
  384.75 +    }
  384.76 +}
   385.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   385.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareByteArrayTest.java	Sun Feb 03 07:48:42 2013 +0100
   385.3 @@ -0,0 +1,93 @@
   385.4 +/**
   385.5 + * Back 2 Browser Bytecode Translator
   385.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   385.7 + *
   385.8 + * This program is free software: you can redistribute it and/or modify
   385.9 + * it under the terms of the GNU General Public License as published by
  385.10 + * the Free Software Foundation, version 2 of the License.
  385.11 + *
  385.12 + * This program is distributed in the hope that it will be useful,
  385.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  385.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  385.15 + * GNU General Public License for more details.
  385.16 + *
  385.17 + * You should have received a copy of the GNU General Public License
  385.18 + * along with this program. Look for COPYING file in the top folder.
  385.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  385.20 + */
  385.21 +package org.apidesign.bck2brwsr.tck;
  385.22 +
  385.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  385.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  385.25 +import org.testng.annotations.Factory;
  385.26 +
  385.27 +/**
  385.28 + *
  385.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  385.30 + */
  385.31 +public class CompareByteArrayTest {
  385.32 +    @Compare public int byteArraySum() {
  385.33 +        byte[] arr = createArray();
  385.34 +        return sumByteArr(arr);
  385.35 +    }
  385.36 +    
  385.37 +    @Compare public int countZeros() {
  385.38 +        int zeros = 0;
  385.39 +        for (Byte b : createArray()) {
  385.40 +            if (b == 0) {
  385.41 +                zeros++;
  385.42 +            }
  385.43 +        }
  385.44 +        return zeros;
  385.45 +    }
  385.46 +    
  385.47 +    private static int sumByteArr(byte[] arr) {
  385.48 +        int sum = 0;
  385.49 +        for (int i = 0; i < arr.length; i++) {
  385.50 +            sum += arr[i];
  385.51 +        }
  385.52 +        return sum;
  385.53 +    }
  385.54 +    
  385.55 +    @Compare public String noOutOfBounds() {
  385.56 +        return atIndex(1);
  385.57 +    }
  385.58 +
  385.59 +    @Compare public String outOfBounds() {
  385.60 +        return atIndex(5);
  385.61 +    }
  385.62 +
  385.63 +    @Compare public String outOfBoundsMinus() {
  385.64 +        return atIndex(-1);
  385.65 +    }
  385.66 +
  385.67 +    @Compare public String toOfBounds() {
  385.68 +        return toIndex(5);
  385.69 +    }
  385.70 +
  385.71 +    @Compare public String toOfBoundsMinus() {
  385.72 +        return toIndex(-1);
  385.73 +    }
  385.74 +
  385.75 +    private static final int[] arr = { 0, 1, 2 };
  385.76 +    public static String atIndex(int at) {
  385.77 +        return "at@" + arr[at];
  385.78 +    }
  385.79 +    public static String toIndex(int at) {
  385.80 +        arr[at] = 10;
  385.81 +        return "ok";
  385.82 +    }
  385.83 +    
  385.84 +    
  385.85 +    @Factory
  385.86 +    public static Object[] create() {
  385.87 +        return VMTest.create(CompareByteArrayTest.class);
  385.88 +    }
  385.89 +
  385.90 +    private byte[] createArray() {
  385.91 +        byte[] arr = new byte[10];
  385.92 +        arr[5] = 3;
  385.93 +        arr[7] = 8;
  385.94 +        return arr;
  385.95 +    }
  385.96 +}
   386.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   386.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareHashTest.java	Sun Feb 03 07:48:42 2013 +0100
   386.3 @@ -0,0 +1,50 @@
   386.4 +/**
   386.5 + * Back 2 Browser Bytecode Translator
   386.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   386.7 + *
   386.8 + * This program is free software: you can redistribute it and/or modify
   386.9 + * it under the terms of the GNU General Public License as published by
  386.10 + * the Free Software Foundation, version 2 of the License.
  386.11 + *
  386.12 + * This program is distributed in the hope that it will be useful,
  386.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  386.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  386.15 + * GNU General Public License for more details.
  386.16 + *
  386.17 + * You should have received a copy of the GNU General Public License
  386.18 + * along with this program. Look for COPYING file in the top folder.
  386.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  386.20 + */
  386.21 +package org.apidesign.bck2brwsr.tck;
  386.22 +
  386.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  386.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  386.25 +import org.testng.annotations.Factory;
  386.26 +
  386.27 +/**
  386.28 + *
  386.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  386.30 + */
  386.31 +public class CompareHashTest {
  386.32 +    @Compare public int hashOfString() {
  386.33 +        return "Ahoj".hashCode();
  386.34 +    }
  386.35 +    
  386.36 +    @Compare public int hashRemainsYieldsZero() {
  386.37 +        Object o = new Object();
  386.38 +        return o.hashCode() - o.hashCode();
  386.39 +    }
  386.40 +    
  386.41 +    @Compare public int initializeInStatic() {
  386.42 +        return StaticUse.NON_NULL.hashCode() - StaticUse.NON_NULL.hashCode();
  386.43 +    }
  386.44 +    
  386.45 +    @Compare public int hashOfInt() {
  386.46 +        return Integer.valueOf(Integer.MAX_VALUE).hashCode();
  386.47 +    }
  386.48 +    
  386.49 +    @Factory
  386.50 +    public static Object[] create() {
  386.51 +        return VMTest.create(CompareHashTest.class);
  386.52 +    }
  386.53 +}
   387.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   387.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareIntArrayTest.java	Sun Feb 03 07:48:42 2013 +0100
   387.3 @@ -0,0 +1,63 @@
   387.4 +/**
   387.5 + * Back 2 Browser Bytecode Translator
   387.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   387.7 + *
   387.8 + * This program is free software: you can redistribute it and/or modify
   387.9 + * it under the terms of the GNU General Public License as published by
  387.10 + * the Free Software Foundation, version 2 of the License.
  387.11 + *
  387.12 + * This program is distributed in the hope that it will be useful,
  387.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  387.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  387.15 + * GNU General Public License for more details.
  387.16 + *
  387.17 + * You should have received a copy of the GNU General Public License
  387.18 + * along with this program. Look for COPYING file in the top folder.
  387.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  387.20 + */
  387.21 +package org.apidesign.bck2brwsr.tck;
  387.22 +
  387.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  387.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  387.25 +import org.testng.annotations.Factory;
  387.26 +
  387.27 +/**
  387.28 + *
  387.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  387.30 + */
  387.31 +public class CompareIntArrayTest {
  387.32 +    @Compare public int integerArraySum() {
  387.33 +        int[] arr = createArray();
  387.34 +        return sumIntArr(arr);
  387.35 +    }
  387.36 +    
  387.37 +    @Compare public int countZeros() {
  387.38 +        int zeros = 0;
  387.39 +        for (Integer i : createArray()) {
  387.40 +            if (i == 0) {
  387.41 +                zeros++;
  387.42 +            }
  387.43 +        }
  387.44 +        return zeros;
  387.45 +    }
  387.46 +    
  387.47 +    private static int sumIntArr(int[] arr) {
  387.48 +        int sum = 0;
  387.49 +        for (int i = 0; i < arr.length; i++) {
  387.50 +            sum += arr[i];
  387.51 +        }
  387.52 +        return sum;
  387.53 +    }
  387.54 +    
  387.55 +    @Factory
  387.56 +    public static Object[] create() {
  387.57 +        return VMTest.create(CompareIntArrayTest.class);
  387.58 +    }
  387.59 +
  387.60 +    private int[] createArray() {
  387.61 +        int[] arr = new int[10];
  387.62 +        arr[5] = 3;
  387.63 +        arr[7] = 8;
  387.64 +        return arr;
  387.65 +    }
  387.66 +}
   388.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   388.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java	Sun Feb 03 07:48:42 2013 +0100
   388.3 @@ -0,0 +1,133 @@
   388.4 +/**
   388.5 + * Back 2 Browser Bytecode Translator
   388.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   388.7 + *
   388.8 + * This program is free software: you can redistribute it and/or modify
   388.9 + * it under the terms of the GNU General Public License as published by
  388.10 + * the Free Software Foundation, version 2 of the License.
  388.11 + *
  388.12 + * This program is distributed in the hope that it will be useful,
  388.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  388.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  388.15 + * GNU General Public License for more details.
  388.16 + *
  388.17 + * You should have received a copy of the GNU General Public License
  388.18 + * along with this program. Look for COPYING file in the top folder.
  388.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  388.20 + */
  388.21 +package org.apidesign.bck2brwsr.tck;
  388.22 +
  388.23 +import java.net.MalformedURLException;
  388.24 +import java.net.URL;
  388.25 +import org.apidesign.bck2brwsr.vmtest.Compare;
  388.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  388.27 +import org.testng.annotations.Factory;
  388.28 +
  388.29 +/**
  388.30 + *
  388.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  388.32 + */
  388.33 +public class CompareStringsTest {
  388.34 +    @Compare public String firstChar() {
  388.35 +        return "" + ("Hello".toCharArray()[0]);
  388.36 +    }
  388.37 +    
  388.38 +    @Compare public String classCast() {
  388.39 +        Object o = firstChar();
  388.40 +        return String.class.cast(o);
  388.41 +    }
  388.42 +
  388.43 +    @Compare public String classCastThrown() {
  388.44 +        Object o = null;
  388.45 +        return String.class.cast(o);
  388.46 +    }
  388.47 +    
  388.48 +    @Compare public boolean equalToNull() {
  388.49 +        return "Ahoj".equals(null);
  388.50 +    }
  388.51 +    
  388.52 +    @Compare public static Object compareURLs() throws MalformedURLException {
  388.53 +        return new URL("http://apidesign.org:8080/wiki/").toExternalForm().toString();
  388.54 +    }
  388.55 +    
  388.56 +    @Compare public String deleteLastTwoCharacters() {
  388.57 +        StringBuilder sb = new StringBuilder();
  388.58 +        sb.append("453.0");
  388.59 +        if (sb.toString().endsWith(".0")) {
  388.60 +            final int l = sb.length();
  388.61 +            sb.delete(l - 2, l);
  388.62 +        }
  388.63 +        return sb.toString().toString();
  388.64 +    }
  388.65 +    
  388.66 +    @Compare public String nameOfStringClass() throws Exception {
  388.67 +        return Class.forName("java.lang.String").getName();
  388.68 +    }
  388.69 +    @Compare public String nameOfArrayClass() throws Exception {
  388.70 +        return Class.forName("org.apidesign.bck2brwsr.tck.CompareHashTest").getName();
  388.71 +    }
  388.72 +    
  388.73 +    @Compare public String lowerHello() {
  388.74 +        return "HeLlO".toLowerCase();
  388.75 +    }
  388.76 +    
  388.77 +    @Compare public String lowerA() {
  388.78 +        return String.valueOf(Character.toLowerCase('A')).toString();
  388.79 +    }
  388.80 +    @Compare public String upperHello() {
  388.81 +        return "hello".toUpperCase();
  388.82 +    }
  388.83 +    
  388.84 +    @Compare public String upperA() {
  388.85 +        return String.valueOf(Character.toUpperCase('a')).toString();
  388.86 +    }
  388.87 +    
  388.88 +    @Compare public boolean matchRegExp() throws Exception {
  388.89 +        return "58038503".matches("\\d*");
  388.90 +    }
  388.91 +
  388.92 +    @Compare public boolean doesNotMatchRegExp() throws Exception {
  388.93 +        return "58038503GH".matches("\\d*");
  388.94 +    }
  388.95 +
  388.96 +    @Compare public boolean doesNotMatchRegExpFully() throws Exception {
  388.97 +        return "Hello".matches("Hell");
  388.98 +    }
  388.99 +    
 388.100 +    @Compare public String emptyCharArray() {
 388.101 +        char[] arr = new char[10];
 388.102 +        return new String(arr);
 388.103 +    }
 388.104 +    
 388.105 +    @Compare public String variousCharacterTests() throws Exception {
 388.106 +        StringBuilder sb = new StringBuilder();
 388.107 +        
 388.108 +        sb.append(Character.isUpperCase('a'));
 388.109 +        sb.append(Character.isUpperCase('A'));
 388.110 +        sb.append(Character.isLowerCase('a'));
 388.111 +        sb.append(Character.isLowerCase('A'));
 388.112 +        
 388.113 +        sb.append(Character.isLetter('A'));
 388.114 +        sb.append(Character.isLetterOrDigit('9'));
 388.115 +        sb.append(Character.isLetterOrDigit('A'));
 388.116 +        sb.append(Character.isLetter('0'));
 388.117 +        
 388.118 +        return sb.toString().toString();
 388.119 +    }
 388.120 +        
 388.121 +    @Compare
 388.122 +    public String nullFieldInitialized() {
 388.123 +        NullField nf = new NullField();
 388.124 +        return ("" + nf.name).toString();
 388.125 +    }
 388.126 +
 388.127 +    @Factory
 388.128 +    public static Object[] create() {
 388.129 +        return VMTest.create(CompareStringsTest.class);
 388.130 +    }
 388.131 +
 388.132 +    private static final class NullField {
 388.133 +
 388.134 +        String name;
 388.135 +    }
 388.136 +}
   389.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   389.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceA.java	Sun Feb 03 07:48:42 2013 +0100
   389.3 @@ -0,0 +1,34 @@
   389.4 +/**
   389.5 + * Back 2 Browser Bytecode Translator
   389.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   389.7 + *
   389.8 + * This program is free software: you can redistribute it and/or modify
   389.9 + * it under the terms of the GNU General Public License as published by
  389.10 + * the Free Software Foundation, version 2 of the License.
  389.11 + *
  389.12 + * This program is distributed in the hope that it will be useful,
  389.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  389.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  389.15 + * GNU General Public License for more details.
  389.16 + *
  389.17 + * You should have received a copy of the GNU General Public License
  389.18 + * along with this program. Look for COPYING file in the top folder.
  389.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  389.20 + */
  389.21 +package org.apidesign.bck2brwsr.tck;
  389.22 +
  389.23 +/**
  389.24 + *
  389.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  389.26 + */
  389.27 +public class InheritanceA {
  389.28 +    private String name;
  389.29 +    
  389.30 +    public void setA(String n) {
  389.31 +        this.name = n;
  389.32 +    }
  389.33 +    
  389.34 +    public String getA() {
  389.35 +        return name;
  389.36 +    }
  389.37 +}
   390.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   390.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceB.java	Sun Feb 03 07:48:42 2013 +0100
   390.3 @@ -0,0 +1,34 @@
   390.4 +/**
   390.5 + * Back 2 Browser Bytecode Translator
   390.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   390.7 + *
   390.8 + * This program is free software: you can redistribute it and/or modify
   390.9 + * it under the terms of the GNU General Public License as published by
  390.10 + * the Free Software Foundation, version 2 of the License.
  390.11 + *
  390.12 + * This program is distributed in the hope that it will be useful,
  390.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  390.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  390.15 + * GNU General Public License for more details.
  390.16 + *
  390.17 + * You should have received a copy of the GNU General Public License
  390.18 + * along with this program. Look for COPYING file in the top folder.
  390.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  390.20 + */
  390.21 +package org.apidesign.bck2brwsr.tck;
  390.22 +
  390.23 +/**
  390.24 + *
  390.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  390.26 + */
  390.27 +public class InheritanceB extends InheritanceA {
  390.28 +    private String name;
  390.29 +    
  390.30 +    public void setB(String n) {
  390.31 +        this.name = n;
  390.32 +    }
  390.33 +    
  390.34 +    public String getB() {
  390.35 +        return name;
  390.36 +    }
  390.37 +}
   391.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   391.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceTest.java	Sun Feb 03 07:48:42 2013 +0100
   391.3 @@ -0,0 +1,41 @@
   391.4 +/**
   391.5 + * Back 2 Browser Bytecode Translator
   391.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   391.7 + *
   391.8 + * This program is free software: you can redistribute it and/or modify
   391.9 + * it under the terms of the GNU General Public License as published by
  391.10 + * the Free Software Foundation, version 2 of the License.
  391.11 + *
  391.12 + * This program is distributed in the hope that it will be useful,
  391.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  391.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  391.15 + * GNU General Public License for more details.
  391.16 + *
  391.17 + * You should have received a copy of the GNU General Public License
  391.18 + * along with this program. Look for COPYING file in the top folder.
  391.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  391.20 + */
  391.21 +package org.apidesign.bck2brwsr.tck;
  391.22 +
  391.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  391.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  391.25 +import org.testng.annotations.Factory;
  391.26 +
  391.27 +/**
  391.28 + *
  391.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  391.30 + */
  391.31 +public class InheritanceTest {
  391.32 +
  391.33 +    @Compare public String checkFieldsIndependent() throws ClassNotFoundException {
  391.34 +        InheritanceB ib = new InheritanceB();
  391.35 +        ib.setA("A");
  391.36 +        ib.setB("B");
  391.37 +        return "A: " + ib.getA() + " B: " + ib.getB();
  391.38 +    }
  391.39 +    
  391.40 +    @Factory
  391.41 +    public static Object[] create() {
  391.42 +        return VMTest.create(InheritanceTest.class);
  391.43 +    }
  391.44 +}
   392.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   392.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java	Sun Feb 03 07:48:42 2013 +0100
   392.3 @@ -0,0 +1,108 @@
   392.4 +/**
   392.5 + * Back 2 Browser Bytecode Translator
   392.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   392.7 + *
   392.8 + * This program is free software: you can redistribute it and/or modify
   392.9 + * it under the terms of the GNU General Public License as published by
  392.10 + * the Free Software Foundation, version 2 of the License.
  392.11 + *
  392.12 + * This program is distributed in the hope that it will be useful,
  392.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  392.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  392.15 + * GNU General Public License for more details.
  392.16 + *
  392.17 + * You should have received a copy of the GNU General Public License
  392.18 + * along with this program. Look for COPYING file in the top folder.
  392.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  392.20 + */
  392.21 +package org.apidesign.bck2brwsr.tck;
  392.22 +
  392.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  392.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  392.25 +import org.testng.annotations.Factory;
  392.26 +
  392.27 +/**
  392.28 + *
  392.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  392.30 + */
  392.31 +public class IntegerArithmeticTest {
  392.32 +    
  392.33 +    private static int add(int x, int y) {
  392.34 +        return x + y;
  392.35 +    }
  392.36 +    
  392.37 +    private static int sub(int x, int y) {
  392.38 +        return x - y;
  392.39 +    }
  392.40 +    
  392.41 +    private static int mul(int x, int y) {
  392.42 +        return x * y;
  392.43 +    }
  392.44 +    
  392.45 +    private static int div(int x, int y) {
  392.46 +        return x / y;
  392.47 +    }
  392.48 +    
  392.49 +    private static int mod(int x, int y) {
  392.50 +        return x % y;
  392.51 +    }
  392.52 +    
  392.53 +    @Compare public int addOverflow() {
  392.54 +        return add(Integer.MAX_VALUE, 1);
  392.55 +    }
  392.56 +    
  392.57 +    @Compare public int subUnderflow() {
  392.58 +        return sub(Integer.MIN_VALUE, 1);
  392.59 +    }
  392.60 +    
  392.61 +    @Compare public int addMaxIntAndMaxInt() {
  392.62 +        return add(Integer.MAX_VALUE, Integer.MAX_VALUE);
  392.63 +    }
  392.64 +    
  392.65 +    @Compare public int subMinIntAndMinInt() {
  392.66 +        return sub(Integer.MIN_VALUE, Integer.MIN_VALUE);
  392.67 +    }
  392.68 +    
  392.69 +    @Compare public int multiplyMaxInt() {
  392.70 +        return mul(Integer.MAX_VALUE, 2);
  392.71 +    }
  392.72 +    
  392.73 +    @Compare public int multiplyMaxIntAndMaxInt() {
  392.74 +        return mul(Integer.MAX_VALUE, Integer.MAX_VALUE);
  392.75 +    }
  392.76 +    
  392.77 +    @Compare public int multiplyMinInt() {
  392.78 +        return mul(Integer.MIN_VALUE, 2);
  392.79 +    }
  392.80 +    
  392.81 +    @Compare public int multiplyMinIntAndMinInt() {
  392.82 +        return mul(Integer.MIN_VALUE, Integer.MIN_VALUE);
  392.83 +    }
  392.84 +    
  392.85 +    @Compare public int multiplyPrecision() {
  392.86 +        return mul(119106029, 1103515245);
  392.87 +    }
  392.88 +    
  392.89 +    @Compare public int division() {
  392.90 +        return div(1, 2);
  392.91 +    }
  392.92 +    
  392.93 +    @Compare public int divisionReminder() {
  392.94 +        return mod(1, 2);
  392.95 +    }
  392.96 +    
  392.97 +    @Compare public int sumTwoDimensions() {
  392.98 +        int[][] matrix = createMatrix(4, 3);
  392.99 +        matrix[0][0] += 10;
 392.100 +        return matrix[0][0];
 392.101 +    }
 392.102 +    
 392.103 +    static int[][] createMatrix(int x, int y) {
 392.104 +        return new int[x][y];
 392.105 +    }
 392.106 +    
 392.107 +    @Factory
 392.108 +    public static Object[] create() {
 392.109 +        return VMTest.create(IntegerArithmeticTest.class);
 392.110 +    }
 392.111 +}
   393.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   393.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java	Sun Feb 03 07:48:42 2013 +0100
   393.3 @@ -0,0 +1,135 @@
   393.4 +/**
   393.5 + * Back 2 Browser Bytecode Translator
   393.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   393.7 + *
   393.8 + * This program is free software: you can redistribute it and/or modify
   393.9 + * it under the terms of the GNU General Public License as published by
  393.10 + * the Free Software Foundation, version 2 of the License.
  393.11 + *
  393.12 + * This program is distributed in the hope that it will be useful,
  393.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  393.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  393.15 + * GNU General Public License for more details.
  393.16 + *
  393.17 + * You should have received a copy of the GNU General Public License
  393.18 + * along with this program. Look for COPYING file in the top folder.
  393.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  393.20 + */
  393.21 +package org.apidesign.bck2brwsr.tck;
  393.22 +
  393.23 +import java.lang.reflect.Array;
  393.24 +import org.apidesign.bck2brwsr.vmtest.Compare;
  393.25 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  393.26 +import org.testng.annotations.Factory;
  393.27 +
  393.28 +/**
  393.29 + *
  393.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  393.31 + */
  393.32 +public class ReflectionArrayTest {
  393.33 +    @Compare public int lengthOfStringArray() {
  393.34 +        String[] arr = (String[]) Array.newInstance(String.class, 10);
  393.35 +        return arr.length;
  393.36 +    }
  393.37 +    
  393.38 +    @Compare public int reflectiveLengthOfStringArray() {
  393.39 +        Object arr = Array.newInstance(String.class, 10);
  393.40 +        return Array.getLength(arr);
  393.41 +    }
  393.42 +
  393.43 +    @Compare public int reflectiveLengthOneNonArray() {
  393.44 +        Object arr = "non-array";
  393.45 +        return Array.getLength(arr);
  393.46 +    }
  393.47 +
  393.48 +    @Compare public String compTypeOfStringArray() {
  393.49 +        String[] arr = (String[]) Array.newInstance(String.class, 10);
  393.50 +        return arr.getClass().getComponentType().getName();
  393.51 +    }
  393.52 +
  393.53 +    @Compare public Object negativeArrayExcp() {
  393.54 +        return Array.newInstance(String.class, -5);
  393.55 +    }
  393.56 +    
  393.57 +    @Compare public int lengthOfIntArray() {
  393.58 +        int[] arr = (int[]) Array.newInstance(Integer.TYPE, 10);
  393.59 +        return arr.length;
  393.60 +    }
  393.61 +
  393.62 +    @Compare public int reflectiveLengthOfIntArray() {
  393.63 +        Object arr = Array.newInstance(Integer.TYPE, 10);
  393.64 +        return Array.getLength(arr);
  393.65 +    }
  393.66 +
  393.67 +    @Compare public String compTypeOfIntArray() {
  393.68 +        int[] arr = (int[]) Array.newInstance(int.class, 10);
  393.69 +        return arr.getClass().getComponentType().getName();
  393.70 +    }
  393.71 +
  393.72 +    @Compare public Object intNegativeArrayExcp() {
  393.73 +        return Array.newInstance(int.class, -5);
  393.74 +    }
  393.75 +
  393.76 +    @Compare public Integer verifyAutobox() {
  393.77 +        int[] arr = (int[]) Array.newInstance(int.class, 5);
  393.78 +        return (Integer) Array.get(arr, 0);
  393.79 +    }
  393.80 +    @Compare public String verifyObjectArray() {
  393.81 +        String[] arr = (String[]) Array.newInstance(String.class, 5);
  393.82 +        Array.set(arr, 0, "Hello");
  393.83 +        return (String) Array.get(arr, 0);
  393.84 +    }
  393.85 +    @Compare public int verifyInt() {
  393.86 +        int[] arr = (int[]) Array.newInstance(int.class, 5);
  393.87 +        return Array.getInt(arr, 0);
  393.88 +    }
  393.89 +    @Compare public long verifyConvertToLong() {
  393.90 +        int[] arr = (int[]) Array.newInstance(int.class, 5);
  393.91 +        return Array.getLong(arr, 0);
  393.92 +    }
  393.93 +
  393.94 +    @Compare public Object verifySetIntToObject() {
  393.95 +        try {
  393.96 +            Object[] arr = (Object[]) Array.newInstance(Object.class, 5);
  393.97 +            Array.setInt(arr, 0, 10);
  393.98 +            return Array.get(arr, 0);
  393.99 +        } catch (Exception exception) {
 393.100 +            return exception.getClass().getName();
 393.101 +        }
 393.102 +    }
 393.103 +    @Compare public long verifySetShort() {
 393.104 +        int[] arr = (int[]) Array.newInstance(int.class, 5);
 393.105 +        Array.setShort(arr, 0, (short)10);
 393.106 +        return Array.getLong(arr, 0);
 393.107 +    }
 393.108 +    @Compare public long verifyCantSetLong() {
 393.109 +        int[] arr = (int[]) Array.newInstance(int.class, 5);
 393.110 +        Array.setLong(arr, 0, 10);
 393.111 +        return Array.getLong(arr, 0);
 393.112 +    }
 393.113 +    @Compare public float verifyLongToFloat() {
 393.114 +        Object arr = Array.newInstance(float.class, 5);
 393.115 +        Array.setLong(arr, 0, 10);
 393.116 +        return Array.getFloat(arr, 0);
 393.117 +    }
 393.118 +
 393.119 +    @Compare public double verifyConvertToDouble() {
 393.120 +        int[] arr = (int[]) Array.newInstance(int.class, 5);
 393.121 +        return Array.getDouble(arr, 0);
 393.122 +    }
 393.123 +    
 393.124 +    @Compare public int multiIntArray() {
 393.125 +        int[][][] arr = (int[][][]) Array.newInstance(int.class, 3, 3, 3);
 393.126 +        return arr[0][1][2] + 5 + arr[2][2][0];
 393.127 +    }
 393.128 +
 393.129 +    @Compare public String multiIntArrayCompType() {
 393.130 +        return Array.newInstance(int.class, 3, 3, 3).getClass().getName();
 393.131 +    }
 393.132 +    
 393.133 +    
 393.134 +    @Factory
 393.135 +    public static Object[] create() {
 393.136 +        return VMTest.create(ReflectionArrayTest.class);
 393.137 +    }
 393.138 +}
   394.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   394.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java	Sun Feb 03 07:48:42 2013 +0100
   394.3 @@ -0,0 +1,199 @@
   394.4 +/**
   394.5 + * Back 2 Browser Bytecode Translator
   394.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   394.7 + *
   394.8 + * This program is free software: you can redistribute it and/or modify
   394.9 + * it under the terms of the GNU General Public License as published by
  394.10 + * the Free Software Foundation, version 2 of the License.
  394.11 + *
  394.12 + * This program is distributed in the hope that it will be useful,
  394.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  394.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  394.15 + * GNU General Public License for more details.
  394.16 + *
  394.17 + * You should have received a copy of the GNU General Public License
  394.18 + * along with this program. Look for COPYING file in the top folder.
  394.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  394.20 + */
  394.21 +package org.apidesign.bck2brwsr.tck;
  394.22 +
  394.23 +import java.lang.reflect.Method;
  394.24 +import java.util.Arrays;
  394.25 +import java.util.Collections;
  394.26 +import java.util.List;
  394.27 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  394.28 +import org.apidesign.bck2brwsr.vmtest.Compare;
  394.29 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  394.30 +import org.testng.annotations.Factory;
  394.31 +
  394.32 +/**
  394.33 + *
  394.34 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  394.35 + */
  394.36 +public class ReflectionTest {
  394.37 +    @Compare public boolean nonNullThis() {
  394.38 +        return this == null;
  394.39 +    }
  394.40 +    
  394.41 +    @Compare public String intType() {
  394.42 +        return Integer.TYPE.toString();
  394.43 +    }
  394.44 +
  394.45 +    @Compare public String voidType() throws Exception {
  394.46 +        return void.class.toString();
  394.47 +    }
  394.48 +
  394.49 +    @Compare public String longClass() {
  394.50 +        return long.class.toString();
  394.51 +    }
  394.52 +    
  394.53 +    @Compare public String namesOfMethods() {
  394.54 +        StringBuilder sb = new StringBuilder();
  394.55 +        String[] arr = new String[20];
  394.56 +        int i = 0;
  394.57 +        for (Method m : StaticUse.class.getMethods()) {
  394.58 +            arr[i++] = m.getName();
  394.59 +        }
  394.60 +        for (String s : sort(arr, i)) {
  394.61 +            sb.append(s).append("\n");
  394.62 +        }
  394.63 +        return sb.toString();
  394.64 +    }
  394.65 +    
  394.66 +    @Compare public String cannotCallNonStaticMethodWithNull() throws Exception {
  394.67 +        StaticUse.class.getMethod("instanceMethod").invoke(null);
  394.68 +        return "should not happen";
  394.69 +    }
  394.70 +
  394.71 +    @Compare public Object voidReturnType() throws Exception {
  394.72 +        return StaticUse.class.getMethod("instanceMethod").getReturnType();
  394.73 +    }
  394.74 +    
  394.75 +    enum E { A, B };
  394.76 +    @Compare public boolean isEnum() {
  394.77 +        return E.A.getClass().isEnum();
  394.78 +    }
  394.79 +
  394.80 +    @Compare public boolean isNotEnum() {
  394.81 +        return "".getClass().isEnum();
  394.82 +    }
  394.83 +    
  394.84 +    @Compare public String newInstanceFails() throws InstantiationException {
  394.85 +        try {
  394.86 +            return "success: " + StaticUse.class.newInstance();
  394.87 +        } catch (IllegalAccessException ex) {
  394.88 +            return ex.getClass().getName();
  394.89 +        }
  394.90 +    }
  394.91 +    
  394.92 +    @Compare public String paramTypes() throws Exception {
  394.93 +        Method plus = StaticUse.class.getMethod("plus", int.class, Integer.TYPE);
  394.94 +        final Class[] pt = plus.getParameterTypes();
  394.95 +        return pt[0].getName();
  394.96 +    }
  394.97 +    @Compare public String paramTypesNotFound() throws Exception {
  394.98 +        return StaticUse.class.getMethod("plus", int.class, double.class).toString();
  394.99 +    }
 394.100 +    @Compare public int methodWithArgs() throws Exception {
 394.101 +        Method plus = StaticUse.class.getMethod("plus", int.class, Integer.TYPE);
 394.102 +        return (Integer)plus.invoke(null, 2, 3);
 394.103 +    }
 394.104 +    
 394.105 +    @Compare public String classGetNameForByte() {
 394.106 +         return byte.class.getName();
 394.107 +    }
 394.108 +    @Compare public String classGetNameForBaseObject() {
 394.109 +        return newObject().getClass().getName();
 394.110 +    }
 394.111 +    @Compare public String classGetNameForJavaObject() {
 394.112 +        return new Object().getClass().getName();
 394.113 +    }
 394.114 +    @Compare public String classGetNameForObjectArray() {
 394.115 +        return (new Object[3]).getClass().getName();
 394.116 +    }
 394.117 +    @Compare public String classGetNameForSimpleIntArray() {
 394.118 +        return (new int[3]).getClass().getName();
 394.119 +    }
 394.120 +    @Compare public boolean sameClassGetNameForSimpleCharArray() {
 394.121 +        return (new char[3]).getClass() == (new char[34]).getClass();
 394.122 +    }
 394.123 +    @Compare public String classGetNameForMultiIntArray() {
 394.124 +        return (new int[3][4][5][6][7][8][9]).getClass().getName();
 394.125 +    }
 394.126 +    @Compare public String classGetNameForMultiIntArrayInner() {
 394.127 +        final int[][][][][][][] arr = new int[3][4][5][6][7][8][9];
 394.128 +        int[][][][][][] subarr = arr[0];
 394.129 +        int[][][][][] subsubarr = subarr[0];
 394.130 +        return subsubarr.getClass().getName();
 394.131 +    }
 394.132 +    @Compare public String classGetNameForMultiStringArray() {
 394.133 +        return (new String[3][4][5][6][7][8][9]).getClass().getName();
 394.134 +    }
 394.135 +    
 394.136 +    @Compare public String classForByte() throws Exception {
 394.137 +        return Class.forName("[Z").getName();
 394.138 +    }
 394.139 +
 394.140 +    @Compare public String classForUnknownArray() {
 394.141 +        try {
 394.142 +            return Class.forName("[W").getName();
 394.143 +        } catch (Exception ex) {
 394.144 +            return ex.getClass().getName();
 394.145 +        }
 394.146 +    }
 394.147 +    
 394.148 +    @Compare public String classForUnknownDeepArray() {
 394.149 +        try {
 394.150 +            return Class.forName("[[[[[W").getName();
 394.151 +        } catch (Exception ex) {
 394.152 +            return ex.getClass().getName();
 394.153 +        }
 394.154 +    }
 394.155 +    
 394.156 +    @Compare public String componentGetNameForObjectArray() {
 394.157 +        return (new Object[3]).getClass().getComponentType().getName();
 394.158 +    }
 394.159 +    @Compare public boolean sameComponentGetNameForObjectArray() {
 394.160 +        return (new Object[3]).getClass().getComponentType() == Object.class;
 394.161 +    }
 394.162 +    @Compare public String componentGetNameForSimpleIntArray() {
 394.163 +        return (new int[3]).getClass().getComponentType().getName();
 394.164 +    }
 394.165 +    @Compare public String componentGetNameForMultiIntArray() {
 394.166 +        return (new int[3][4][5][6][7][8][9]).getClass().getComponentType().getName();
 394.167 +    }
 394.168 +    @Compare public String componentGetNameForMultiStringArray() {
 394.169 +        Class<?> c = (new String[3][4][5][6][7][8][9]).getClass();
 394.170 +        StringBuilder sb = new StringBuilder();
 394.171 +        for (;;) {
 394.172 +            sb.append(c.getName()).append("\n");
 394.173 +            c = c.getComponentType();
 394.174 +            if (c == null) {
 394.175 +                break;
 394.176 +            }
 394.177 +        }
 394.178 +        return sb.toString();
 394.179 +    }
 394.180 +    
 394.181 +    @Compare public boolean isArray() {
 394.182 +        return new Object[0].getClass().isArray();
 394.183 +    }
 394.184 +    
 394.185 +    @JavaScriptBody(args = { "arr", "len" }, body="var a = arr.slice(0, len); a.sort(); return a;")
 394.186 +    private static String[] sort(String[] arr, int len) {
 394.187 +        List<String> list = Arrays.asList(arr).subList(0, len);
 394.188 +        Collections.sort(list);
 394.189 +        return list.toArray(new String[0]);
 394.190 +    }
 394.191 +    
 394.192 +    @JavaScriptBody(args = {}, body = "return new Object();")
 394.193 +    private static Object newObject() {
 394.194 +        return new Object();
 394.195 +    }
 394.196 +    
 394.197 +    @Factory
 394.198 +    public static Object[] create() {
 394.199 +        return VMTest.create(ReflectionTest.class);
 394.200 +    }
 394.201 +    
 394.202 +}
   395.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   395.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ResourcesTest.java	Sun Feb 03 07:48:42 2013 +0100
   395.3 @@ -0,0 +1,45 @@
   395.4 +/**
   395.5 + * Back 2 Browser Bytecode Translator
   395.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   395.7 + *
   395.8 + * This program is free software: you can redistribute it and/or modify
   395.9 + * it under the terms of the GNU General Public License as published by
  395.10 + * the Free Software Foundation, version 2 of the License.
  395.11 + *
  395.12 + * This program is distributed in the hope that it will be useful,
  395.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  395.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  395.15 + * GNU General Public License for more details.
  395.16 + *
  395.17 + * You should have received a copy of the GNU General Public License
  395.18 + * along with this program. Look for COPYING file in the top folder.
  395.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  395.20 + */
  395.21 +package org.apidesign.bck2brwsr.tck;
  395.22 +
  395.23 +import java.io.InputStream;
  395.24 +import org.apidesign.bck2brwsr.vmtest.Compare;
  395.25 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  395.26 +import org.testng.annotations.Factory;
  395.27 +
  395.28 +/**
  395.29 + *
  395.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  395.31 + */
  395.32 +public class ResourcesTest {
  395.33 +    
  395.34 +    @Compare public String readResourceAsStream() throws Exception {
  395.35 +        InputStream is = getClass().getResourceAsStream("Resources.txt");
  395.36 +        byte[] b = new byte[30];
  395.37 +        int len = is.read(b);
  395.38 +        StringBuilder sb = new StringBuilder();
  395.39 +        for (int i = 0; i < len; i++) {
  395.40 +            sb.append((char)b[i]);
  395.41 +        }
  395.42 +        return sb.toString();
  395.43 +    }
  395.44 +    
  395.45 +    @Factory public static Object[] create() {
  395.46 +        return VMTest.create(ResourcesTest.class);
  395.47 +    }
  395.48 +}
   396.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   396.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ShortArithmeticTest.java	Sun Feb 03 07:48:42 2013 +0100
   396.3 @@ -0,0 +1,102 @@
   396.4 +/**
   396.5 + * Back 2 Browser Bytecode Translator
   396.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   396.7 + *
   396.8 + * This program is free software: you can redistribute it and/or modify
   396.9 + * it under the terms of the GNU General Public License as published by
  396.10 + * the Free Software Foundation, version 2 of the License.
  396.11 + *
  396.12 + * This program is distributed in the hope that it will be useful,
  396.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  396.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  396.15 + * GNU General Public License for more details.
  396.16 + *
  396.17 + * You should have received a copy of the GNU General Public License
  396.18 + * along with this program. Look for COPYING file in the top folder.
  396.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  396.20 + */
  396.21 +package org.apidesign.bck2brwsr.tck;
  396.22 +
  396.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  396.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  396.25 +import org.testng.annotations.Factory;
  396.26 +
  396.27 +/**
  396.28 + *
  396.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  396.30 + */
  396.31 +public class ShortArithmeticTest {
  396.32 +    
  396.33 +    private static short add(short x, short y) {
  396.34 +        return (short)(x + y);
  396.35 +    }
  396.36 +    
  396.37 +    private static short sub(short x, short y) {
  396.38 +        return (short)(x - y);
  396.39 +    }
  396.40 +    
  396.41 +    private static short mul(short x, short y) {
  396.42 +        return (short)(x * y);
  396.43 +    }
  396.44 +    
  396.45 +    private static short div(short x, short y) {
  396.46 +        return (short)(x / y);
  396.47 +    }
  396.48 +    
  396.49 +    private static short mod(short x, short y) {
  396.50 +        return (short)(x % y);
  396.51 +    }
  396.52 +    
  396.53 +    @Compare public short conversion() {
  396.54 +        return (short)123456;
  396.55 +    }
  396.56 +    
  396.57 +    @Compare public short addOverflow() {
  396.58 +        return add(Short.MAX_VALUE, (short)1);
  396.59 +    }
  396.60 +    
  396.61 +    @Compare public short subUnderflow() {
  396.62 +        return sub(Short.MIN_VALUE, (short)1);
  396.63 +    }
  396.64 +    
  396.65 +    @Compare public short addMaxShortAndMaxShort() {
  396.66 +        return add(Short.MAX_VALUE, Short.MAX_VALUE);
  396.67 +    }
  396.68 +    
  396.69 +    @Compare public short subMinShortAndMinShort() {
  396.70 +        return sub(Short.MIN_VALUE, Short.MIN_VALUE);
  396.71 +    }
  396.72 +    
  396.73 +    @Compare public short multiplyMaxShort() {
  396.74 +        return mul(Short.MAX_VALUE, (short)2);
  396.75 +    }
  396.76 +    
  396.77 +    @Compare public short multiplyMaxShortAndMaxShort() {
  396.78 +        return mul(Short.MAX_VALUE, Short.MAX_VALUE);
  396.79 +    }
  396.80 +    
  396.81 +    @Compare public short multiplyMinShort() {
  396.82 +        return mul(Short.MIN_VALUE, (short)2);
  396.83 +    }
  396.84 +    
  396.85 +    @Compare public short multiplyMinShortAndMinShort() {
  396.86 +        return mul(Short.MIN_VALUE, Short.MIN_VALUE);
  396.87 +    }
  396.88 +    
  396.89 +    @Compare public short multiplyPrecision() {
  396.90 +        return mul((short)17638, (short)1103);
  396.91 +    }
  396.92 +    
  396.93 +    @Compare public short division() {
  396.94 +        return div((short)1, (short)2);
  396.95 +    }
  396.96 +    
  396.97 +    @Compare public short divisionReminder() {
  396.98 +        return mod((short)1, (short)2);
  396.99 +    }
 396.100 +    
 396.101 +    @Factory
 396.102 +    public static Object[] create() {
 396.103 +        return VMTest.create(ShortArithmeticTest.class);
 396.104 +    }
 396.105 +}
   397.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   397.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/StaticUse.java	Sun Feb 03 07:48:42 2013 +0100
   397.3 @@ -0,0 +1,31 @@
   397.4 +/**
   397.5 + * Back 2 Browser Bytecode Translator
   397.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   397.7 + *
   397.8 + * This program is free software: you can redistribute it and/or modify
   397.9 + * it under the terms of the GNU General Public License as published by
  397.10 + * the Free Software Foundation, version 2 of the License.
  397.11 + *
  397.12 + * This program is distributed in the hope that it will be useful,
  397.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  397.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  397.15 + * GNU General Public License for more details.
  397.16 + *
  397.17 + * You should have received a copy of the GNU General Public License
  397.18 + * along with this program. Look for COPYING file in the top folder.
  397.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  397.20 + */
  397.21 +package org.apidesign.bck2brwsr.tck;
  397.22 +
  397.23 +class StaticUse {
  397.24 +    public static final Object NON_NULL = new Object();
  397.25 +    private StaticUse() {
  397.26 +    }
  397.27 +    
  397.28 +    public void instanceMethod() {
  397.29 +    }
  397.30 +
  397.31 +    public static int plus(int a, int b) {
  397.32 +        return a + b;
  397.33 +    }
  397.34 +}
   398.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   398.2 +++ b/vmtest/src/test/resources/org/apidesign/bck2brwsr/tck/Resources.txt	Sun Feb 03 07:48:42 2013 +0100
   398.3 @@ -0,0 +1,1 @@
   398.4 +Ahoj